1 /*
   2  * Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include <new>
  27 #include "cds/cdsConstants.hpp"
  28 #include "cds/filemap.hpp"
  29 #include "cds/heapShared.inline.hpp"
  30 #include "cds/metaspaceShared.hpp"
  31 #include "classfile/classLoaderDataGraph.hpp"
  32 #include "classfile/javaClasses.inline.hpp"
  33 #include "classfile/modules.hpp"
  34 #include "classfile/protectionDomainCache.hpp"
  35 #include "classfile/stringTable.hpp"
  36 #include "classfile/symbolTable.hpp"
  37 #include "classfile/systemDictionary.hpp"
  38 #include "classfile/vmSymbols.hpp"
  39 #include "code/codeCache.hpp"
  40 #include "compiler/compilationPolicy.hpp"
  41 #include "compiler/directivesParser.hpp"
  42 #include "compiler/methodMatcher.hpp"
  43 #include "gc/shared/concurrentGCBreakpoints.hpp"
  44 #include "gc/shared/gcConfig.hpp"
  45 #include "gc/shared/gcLocker.inline.hpp"
  46 #include "gc/shared/genArguments.hpp"
  47 #include "gc/shared/genCollectedHeap.hpp"
  48 #include "jvmtifiles/jvmtiEnv.hpp"
  49 #include "logging/log.hpp"
  50 #include "memory/iterator.hpp"
  51 #include "memory/metadataFactory.hpp"
  52 #include "memory/metaspace/testHelpers.hpp"
  53 #include "memory/metaspaceUtils.hpp"
  54 #include "memory/oopFactory.hpp"
  55 #include "memory/resourceArea.hpp"
  56 #include "memory/universe.hpp"
  57 #include "oops/array.hpp"
  58 #include "oops/compressedOops.hpp"
  59 #include "oops/constantPool.inline.hpp"
  60 #include "oops/klass.inline.hpp"
  61 #include "oops/method.inline.hpp"
  62 #include "oops/objArrayKlass.hpp"
  63 #include "oops/objArrayOop.inline.hpp"
  64 #include "oops/oop.inline.hpp"
  65 #include "oops/typeArrayOop.inline.hpp"
  66 #include "prims/resolvedMethodTable.hpp"
  67 #include "prims/wbtestmethods/parserTests.hpp"
  68 #include "prims/whitebox.inline.hpp"
  69 #include "runtime/arguments.hpp"
  70 #include "runtime/atomic.hpp"
  71 #include "runtime/deoptimization.hpp"
  72 #include "runtime/fieldDescriptor.inline.hpp"
  73 #include "runtime/flags/jvmFlag.hpp"
  74 #include "runtime/flags/jvmFlagAccess.hpp"
  75 #include "runtime/frame.inline.hpp"
  76 #include "runtime/handles.inline.hpp"
  77 #include "runtime/handshake.hpp"
  78 #include "runtime/interfaceSupport.inline.hpp"
  79 #include "runtime/javaCalls.hpp"
  80 #include "runtime/jniHandles.inline.hpp"
  81 #include "runtime/os.hpp"
  82 #include "runtime/stackFrameStream.inline.hpp"
  83 #include "runtime/sweeper.hpp"
  84 #include "runtime/synchronizer.hpp"
  85 #include "runtime/thread.hpp"
  86 #include "runtime/threadSMR.hpp"
  87 #include "runtime/vframe.hpp"
  88 #include "runtime/vm_version.hpp"
  89 #include "services/memoryService.hpp"
  90 #include "utilities/align.hpp"
  91 #include "utilities/debug.hpp"
  92 #include "utilities/elfFile.hpp"
  93 #include "utilities/exceptions.hpp"
  94 #include "utilities/macros.hpp"
  95 #include "utilities/ostream.hpp"
  96 #if INCLUDE_G1GC
  97 #include "gc/g1/g1Arguments.hpp"
  98 #include "gc/g1/g1CollectedHeap.inline.hpp"
  99 #include "gc/g1/g1ConcurrentMark.hpp"
 100 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp"
 101 #include "gc/g1/heapRegionManager.hpp"
 102 #include "gc/g1/heapRegionRemSet.inline.hpp"
 103 #endif // INCLUDE_G1GC
 104 #if INCLUDE_PARALLELGC
 105 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
 106 #endif // INCLUDE_PARALLELGC
 107 #if INCLUDE_NMT
 108 #include "services/mallocSiteTable.hpp"
 109 #include "services/memTracker.hpp"
 110 #include "utilities/nativeCallStack.hpp"
 111 #endif // INCLUDE_NMT
 112 #if INCLUDE_JVMCI
 113 #include "jvmci/jvmciEnv.hpp"
 114 #include "jvmci/jvmciRuntime.hpp"
 115 #endif
 116 
 117 #ifdef LINUX
 118 #include "osContainer_linux.hpp"
 119 #include "cgroupSubsystem_linux.hpp"
 120 #endif
 121 
 122 #define SIZE_T_MAX_VALUE ((size_t) -1)
 123 
 124 #define CHECK_JNI_EXCEPTION_(env, value)                               \
 125   do {                                                                 \
 126     JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \
 127     THREAD->clear_pending_jni_exception_check();                       \
 128     if (HAS_PENDING_EXCEPTION) {                                       \
 129       return(value);                                                   \
 130     }                                                                  \
 131   } while (0)
 132 
 133 #define CHECK_JNI_EXCEPTION(env)                                       \
 134   do {                                                                 \
 135     JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \
 136     THREAD->clear_pending_jni_exception_check();                       \
 137     if (HAS_PENDING_EXCEPTION) {                                       \
 138       return;                                                          \
 139     }                                                                  \
 140   } while (0)
 141 
 142 bool WhiteBox::_used = false;
 143 volatile bool WhiteBox::compilation_locked = false;
 144 
 145 class VM_WhiteBoxOperation : public VM_Operation {
 146  public:
 147   VM_WhiteBoxOperation()                         { }
 148   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
 149   bool allow_nested_vm_operations() const        { return true; }
 150 };
 151 
 152 
 153 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
 154   return (jlong)(void*)JNIHandles::resolve(obj);
 155 WB_END
 156 
 157 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
 158   return heapOopSize;
 159 WB_END
 160 
 161 WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o))
 162   return os::vm_page_size();
 163 WB_END
 164 
 165 WB_ENTRY(jlong, WB_GetVMAllocationGranularity(JNIEnv* env, jobject o))
 166   return os::vm_allocation_granularity();
 167 WB_END
 168 
 169 WB_ENTRY(jlong, WB_GetVMLargePageSize(JNIEnv* env, jobject o))
 170   return os::large_page_size();
 171 WB_END
 172 
 173 class WBIsKlassAliveClosure : public LockedClassesDo {
 174     Symbol* _name;
 175     int _count;
 176 public:
 177     WBIsKlassAliveClosure(Symbol* name) : _name(name), _count(0) {}
 178 
 179     void do_klass(Klass* k) {
 180       Symbol* ksym = k->name();
 181       if (ksym->fast_compare(_name) == 0) {
 182         _count++;
 183       } else if (k->is_instance_klass()) {
 184         // Need special handling for hidden classes because the JVM
 185         // appends "+<hex-address>" to hidden class names.
 186         InstanceKlass *ik = InstanceKlass::cast(k);
 187         if (ik->is_hidden()) {
 188           ResourceMark rm;
 189           char* k_name = ksym->as_C_string();
 190           // Find the first '+' char and truncate the string at that point.
 191           // NOTE: This will not work correctly if the original hidden class
 192           // name contains a '+'.
 193           char* plus_char = strchr(k_name, '+');
 194           if (plus_char != NULL) {
 195             *plus_char = 0;
 196             char* c_name = _name->as_C_string();
 197             if (strcmp(c_name, k_name) == 0) {
 198               _count++;
 199             }
 200           }
 201         }
 202       }
 203     }
 204 
 205     int count() const {
 206         return _count;
 207     }
 208 };
 209 
 210 WB_ENTRY(jint, WB_CountAliveClasses(JNIEnv* env, jobject target, jstring name))
 211   oop h_name = JNIHandles::resolve(name);
 212   if (h_name == NULL) return false;
 213   Symbol* sym = java_lang_String::as_symbol(h_name);
 214   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 215 
 216   WBIsKlassAliveClosure closure(sym);
 217   ClassLoaderDataGraph::classes_do(&closure);
 218 
 219   // Return the count of alive classes with this name.
 220   return closure.count();
 221 WB_END
 222 
 223 WB_ENTRY(jint, WB_GetSymbolRefcount(JNIEnv* env, jobject unused, jstring name))
 224   oop h_name = JNIHandles::resolve(name);
 225   if (h_name == NULL) return false;
 226   Symbol* sym = java_lang_String::as_symbol(h_name);
 227   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 228   return (jint)sym->refcount();
 229 WB_END
 230 
 231 
 232 WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 233 #if INCLUDE_JVMTI
 234   ResourceMark rm;
 235   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 236   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 237   jvmtiError err = jvmti_env->AddToBootstrapClassLoaderSearch(seg);
 238   assert(err == JVMTI_ERROR_NONE, "must not fail");
 239 #endif
 240 }
 241 WB_END
 242 
 243 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 244 #if INCLUDE_JVMTI
 245   ResourceMark rm;
 246   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 247   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 248   jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg);
 249   assert(err == JVMTI_ERROR_NONE, "must not fail");
 250 #endif
 251 }
 252 WB_END
 253 
 254 
 255 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
 256   return (jlong)Arguments::max_heap_for_compressed_oops();
 257 }
 258 WB_END
 259 
 260 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
 261   tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " SIZE_FORMAT " "
 262                 "Maximum heap " SIZE_FORMAT " Space alignment " SIZE_FORMAT " Heap alignment " SIZE_FORMAT,
 263                 MinHeapSize,
 264                 InitialHeapSize,
 265                 MaxHeapSize,
 266                 SpaceAlignment,
 267                 HeapAlignment);
 268 }
 269 WB_END
 270 
 271 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
 272   size_t granularity = os::vm_allocation_granularity();
 273   ReservedHeapSpace rhs(100 * granularity, granularity, os::vm_page_size());
 274   VirtualSpace vs;
 275   vs.initialize(rhs, 50 * granularity);
 276 
 277   // Check if constraints are complied
 278   if (!( UseCompressedOops && rhs.base() != NULL &&
 279          CompressedOops::base() != NULL &&
 280          CompressedOops::use_implicit_null_checks() )) {
 281     tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
 282                   "\tUseCompressedOops is %d\n"
 283                   "\trhs.base() is " PTR_FORMAT "\n"
 284                   "\tCompressedOops::base() is " PTR_FORMAT "\n"
 285                   "\tCompressedOops::use_implicit_null_checks() is %d",
 286                   UseCompressedOops,
 287                   p2i(rhs.base()),
 288                   p2i(CompressedOops::base()),
 289                   CompressedOops::use_implicit_null_checks());
 290     return;
 291   }
 292   tty->print_cr("Reading from no access area... ");
 293   tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
 294                 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
 295 WB_END
 296 
 297 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
 298                                            size_t magnitude, size_t iterations) {
 299   size_t granularity = os::vm_allocation_granularity();
 300   ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, os::vm_page_size());
 301   VirtualSpace vs;
 302   if (!vs.initialize(rhs, 0)) {
 303     tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
 304     return 3;
 305   }
 306 
 307   int seed = os::random();
 308   tty->print_cr("Random seed is %d", seed);
 309 
 310   for (size_t i = 0; i < iterations; i++) {
 311 
 312     // Whether we will shrink or grow
 313     bool shrink = os::random() % 2L == 0;
 314 
 315     // Get random delta to resize virtual space
 316     size_t delta = (size_t)os::random() % magnitude;
 317 
 318     // If we are about to shrink virtual space below zero, then expand instead
 319     if (shrink && vs.committed_size() < delta) {
 320       shrink = false;
 321     }
 322 
 323     // Resizing by delta
 324     if (shrink) {
 325       vs.shrink_by(delta);
 326     } else {
 327       // If expanding fails expand_by will silently return false
 328       vs.expand_by(delta, true);
 329     }
 330   }
 331   return 0;
 332 }
 333 
 334 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
 335         jlong reserved_space_size, jlong magnitude, jlong iterations))
 336   tty->print_cr("reservedSpaceSize=" JLONG_FORMAT ", magnitude=" JLONG_FORMAT ", "
 337                 "iterations=" JLONG_FORMAT "\n", reserved_space_size, magnitude,
 338                 iterations);
 339   if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
 340     tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
 341     return 1;
 342   }
 343 
 344   // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
 345   // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
 346   if (sizeof(size_t) < sizeof(jlong)) {
 347     jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
 348     if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
 349         || iterations > size_t_max_value) {
 350       tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
 351       return 2;
 352     }
 353   }
 354 
 355   return wb_stress_virtual_space_resize((size_t) reserved_space_size,
 356                                         (size_t) magnitude, (size_t) iterations);
 357 WB_END
 358 
 359 WB_ENTRY(jboolean, WB_IsGCSupported(JNIEnv* env, jobject o, jint name))
 360   return GCConfig::is_gc_supported((CollectedHeap::Name)name);
 361 WB_END
 362 
 363 WB_ENTRY(jboolean, WB_IsGCSupportedByJVMCICompiler(JNIEnv* env, jobject o, jint name))
 364 #if INCLUDE_JVMCI
 365   if (EnableJVMCI) {
 366     JVMCIEnv jvmciEnv(thread, env, __FILE__, __LINE__);
 367     return jvmciEnv.runtime()->is_gc_supported(&jvmciEnv, (CollectedHeap::Name)name);
 368   }
 369 #endif
 370   return false;
 371 WB_END
 372 
 373 WB_ENTRY(jboolean, WB_IsGCSelected(JNIEnv* env, jobject o, jint name))
 374   return GCConfig::is_gc_selected((CollectedHeap::Name)name);
 375 WB_END
 376 
 377 WB_ENTRY(jboolean, WB_IsGCSelectedErgonomically(JNIEnv* env, jobject o))
 378   return GCConfig::is_gc_selected_ergonomically();
 379 WB_END
 380 
 381 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj))
 382   oop p = JNIHandles::resolve(obj);
 383 #if INCLUDE_G1GC
 384   if (UseG1GC) {
 385     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 386     const HeapRegion* hr = g1h->heap_region_containing(p);
 387     if (hr == NULL) {
 388       return false;
 389     }
 390     return !(hr->is_young());
 391   }
 392 #endif
 393 #if INCLUDE_PARALLELGC
 394   if (UseParallelGC) {
 395     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 396     return !psh->is_in_young(p);
 397   }
 398 #endif
 399 #if INCLUDE_ZGC
 400   if (UseZGC) {
 401     return Universe::heap()->is_in(p);
 402   }
 403 #endif
 404 #if INCLUDE_SHENANDOAHGC
 405   if (UseShenandoahGC) {
 406     return Universe::heap()->is_in(p);
 407   }
 408 #endif
 409   GenCollectedHeap* gch = GenCollectedHeap::heap();
 410   return !gch->is_in_young(p);
 411 WB_END
 412 
 413 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
 414   oop p = JNIHandles::resolve(obj);
 415   return p->size() * HeapWordSize;
 416 WB_END
 417 
 418 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))
 419   return (jlong)SpaceAlignment;
 420 WB_END
 421 
 422 WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o))
 423   return (jlong)HeapAlignment;
 424 WB_END
 425 
 426 WB_ENTRY(jboolean, WB_SupportsConcurrentGCBreakpoints(JNIEnv* env, jobject o))
 427   return Universe::heap()->supports_concurrent_gc_breakpoints();
 428 WB_END
 429 
 430 WB_ENTRY(void, WB_ConcurrentGCAcquireControl(JNIEnv* env, jobject o))
 431   ConcurrentGCBreakpoints::acquire_control();
 432 WB_END
 433 
 434 WB_ENTRY(void, WB_ConcurrentGCReleaseControl(JNIEnv* env, jobject o))
 435   ConcurrentGCBreakpoints::release_control();
 436 WB_END
 437 
 438 WB_ENTRY(void, WB_ConcurrentGCRunToIdle(JNIEnv* env, jobject o))
 439   ConcurrentGCBreakpoints::run_to_idle();
 440 WB_END
 441 
 442 WB_ENTRY(jboolean, WB_ConcurrentGCRunTo(JNIEnv* env, jobject o, jobject at))
 443   Handle h_name(THREAD, JNIHandles::resolve(at));
 444   ResourceMark rm;
 445   const char* c_name = java_lang_String::as_utf8_string(h_name());
 446   return ConcurrentGCBreakpoints::run_to(c_name);
 447 WB_END
 448 
 449 #if INCLUDE_G1GC
 450 
 451 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
 452   if (UseG1GC) {
 453     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 454     oop result = JNIHandles::resolve(obj);
 455     const HeapRegion* hr = g1h->heap_region_containing(result);
 456     return hr->is_humongous();
 457   }
 458   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1IsHumongous: G1 GC is not enabled");
 459 WB_END
 460 
 461 WB_ENTRY(jboolean, WB_G1BelongsToHumongousRegion(JNIEnv* env, jobject o, jlong addr))
 462   if (UseG1GC) {
 463     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 464     const HeapRegion* hr = g1h->heap_region_containing((void*) addr);
 465     return hr->is_humongous();
 466   }
 467   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToHumongousRegion: G1 GC is not enabled");
 468 WB_END
 469 
 470 WB_ENTRY(jboolean, WB_G1BelongsToFreeRegion(JNIEnv* env, jobject o, jlong addr))
 471   if (UseG1GC) {
 472     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 473     const HeapRegion* hr = g1h->heap_region_containing((void*) addr);
 474     return hr->is_free();
 475   }
 476   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToFreeRegion: G1 GC is not enabled");
 477 WB_END
 478 
 479 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o))
 480   if (UseG1GC) {
 481     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 482     size_t nr = g1h->max_regions();
 483     return (jlong)nr;
 484   }
 485   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumMaxRegions: G1 GC is not enabled");
 486 WB_END
 487 
 488 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
 489   if (UseG1GC) {
 490     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 491     size_t nr = g1h->num_free_regions();
 492     return (jlong)nr;
 493   }
 494   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumFreeRegions: G1 GC is not enabled");
 495 WB_END
 496 
 497 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
 498   if (UseG1GC) {
 499     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 500     return g1h->concurrent_mark()->cm_thread()->in_progress();
 501   }
 502   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1InConcurrentMark: G1 GC is not enabled");
 503 WB_END
 504 
 505 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
 506   if (UseG1GC) {
 507     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 508     if (!g1h->concurrent_mark()->cm_thread()->in_progress()) {
 509       g1h->collect(GCCause::_wb_conc_mark);
 510       return true;
 511     }
 512     return false;
 513   }
 514   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1StartMarkCycle: G1 GC is not enabled");
 515 WB_END
 516 
 517 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
 518   if (UseG1GC) {
 519     return (jint)HeapRegion::GrainBytes;
 520   }
 521   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1RegionSize: G1 GC is not enabled");
 522 WB_END
 523 
 524 WB_ENTRY(jboolean, WB_G1HasRegionsToUncommit(JNIEnv* env, jobject o))
 525   if (UseG1GC) {
 526     return G1CollectedHeap::heap()->has_uncommittable_regions();
 527   }
 528   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1HasRegionsToUncommit: G1 GC is not enabled");
 529 WB_END
 530 
 531 #endif // INCLUDE_G1GC
 532 
 533 #if INCLUDE_PARALLELGC
 534 
 535 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o))
 536   if (UseParallelGC) {
 537     return GenAlignment;
 538   }
 539   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSVirtualSpaceAlignment: Parallel GC is not enabled");
 540 WB_END
 541 
 542 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o))
 543   if (UseParallelGC) {
 544     return GenAlignment;
 545   }
 546   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSHeapGenerationAlignment: Parallel GC is not enabled");
 547 WB_END
 548 
 549 #endif // INCLUDE_PARALLELGC
 550 
 551 #if INCLUDE_G1GC
 552 
 553 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env))
 554   if (UseG1GC) {
 555     ResourceMark rm(THREAD);
 556     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 557     MemoryUsage usage = g1h->get_auxiliary_data_memory_usage();
 558     Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
 559     return JNIHandles::make_local(THREAD, h());
 560   }
 561   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1AuxiliaryMemoryUsage: G1 GC is not enabled");
 562 WB_END
 563 
 564 WB_ENTRY(jint, WB_G1ActiveMemoryNodeCount(JNIEnv* env, jobject o))
 565   if (UseG1GC) {
 566     G1NUMA* numa = G1NUMA::numa();
 567     return (jint)numa->num_active_nodes();
 568   }
 569   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1ActiveMemoryNodeCount: G1 GC is not enabled");
 570 WB_END
 571 
 572 WB_ENTRY(jintArray, WB_G1MemoryNodeIds(JNIEnv* env, jobject o))
 573   if (UseG1GC) {
 574     G1NUMA* numa = G1NUMA::numa();
 575     int num_node_ids = (int)numa->num_active_nodes();
 576     const int* node_ids = numa->node_ids();
 577 
 578     typeArrayOop result = oopFactory::new_intArray(num_node_ids, CHECK_NULL);
 579     for (int i = 0; i < num_node_ids; i++) {
 580       result->int_at_put(i, (jint)node_ids[i]);
 581     }
 582     return (jintArray) JNIHandles::make_local(THREAD, result);
 583   }
 584   THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1MemoryNodeIds: G1 GC is not enabled");
 585 WB_END
 586 
 587 class OldRegionsLivenessClosure: public HeapRegionClosure {
 588 
 589  private:
 590   const int _liveness;
 591   size_t _total_count;
 592   size_t _total_memory;
 593   size_t _total_memory_to_free;
 594 
 595  public:
 596   OldRegionsLivenessClosure(int liveness) :
 597     _liveness(liveness),
 598     _total_count(0),
 599     _total_memory(0),
 600     _total_memory_to_free(0) { }
 601 
 602     size_t total_count() { return _total_count; }
 603     size_t total_memory() { return _total_memory; }
 604     size_t total_memory_to_free() { return _total_memory_to_free; }
 605 
 606   bool do_heap_region(HeapRegion* r) {
 607     if (r->is_old()) {
 608       size_t prev_live = r->marked_bytes();
 609       size_t live = r->live_bytes();
 610       size_t size = r->used();
 611       size_t reg_size = HeapRegion::GrainBytes;
 612       if (size > 0 && ((int)(live * 100 / size) < _liveness)) {
 613         _total_memory += size;
 614         ++_total_count;
 615         if (size == reg_size) {
 616         // we don't include non-full regions since they are unlikely included in mixed gc
 617         // for testing purposes it's enough to have lowest estimation of total memory that is expected to be freed
 618           _total_memory_to_free += size - prev_live;
 619         }
 620       }
 621     }
 622     return false;
 623   }
 624 };
 625 
 626 
 627 WB_ENTRY(jlongArray, WB_G1GetMixedGCInfo(JNIEnv* env, jobject o, jint liveness))
 628   if (!UseG1GC) {
 629     THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1GetMixedGCInfo: G1 GC is not enabled");
 630   }
 631   if (liveness < 0) {
 632     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "liveness value should be non-negative");
 633   }
 634 
 635   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 636   OldRegionsLivenessClosure rli(liveness);
 637   g1h->heap_region_iterate(&rli);
 638 
 639   typeArrayOop result = oopFactory::new_longArray(3, CHECK_NULL);
 640   result->long_at_put(0, rli.total_count());
 641   result->long_at_put(1, rli.total_memory());
 642   result->long_at_put(2, rli.total_memory_to_free());
 643   return (jlongArray) JNIHandles::make_local(THREAD, result);
 644 WB_END
 645 
 646 #endif // INCLUDE_G1GC
 647 
 648 #if INCLUDE_NMT
 649 // Alloc memory using the test memory type so that we can use that to see if
 650 // NMT picks it up correctly
 651 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
 652   jlong addr = 0;
 653   addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
 654   return addr;
 655 WB_END
 656 
 657 // Alloc memory with pseudo call stack. The test can create psudo malloc
 658 // allocation site to stress the malloc tracking.
 659 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
 660   address pc = (address)(size_t)pseudo_stack;
 661   NativeCallStack stack(&pc, 1);
 662   return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
 663 WB_END
 664 
 665 // Alloc memory with pseudo call stack and specific memory type.
 666 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStackAndType(JNIEnv* env, jobject o, jlong size, jint pseudo_stack, jint type))
 667   address pc = (address)(size_t)pseudo_stack;
 668   NativeCallStack stack(&pc, 1);
 669   return (jlong)(uintptr_t)os::malloc(size, (MEMFLAGS)type, stack);
 670 WB_END
 671 
 672 // Free the memory allocated by NMTAllocTest
 673 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
 674   os::free((void*)(uintptr_t)mem);
 675 WB_END
 676 
 677 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
 678   jlong addr = 0;
 679 
 680   addr = (jlong)(uintptr_t)os::reserve_memory(size);
 681   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 682 
 683   return addr;
 684 WB_END
 685 
 686 WB_ENTRY(jlong, WB_NMTAttemptReserveMemoryAt(JNIEnv* env, jobject o, jlong addr, jlong size))
 687   addr = (jlong)(uintptr_t)os::attempt_reserve_memory_at((char*)(uintptr_t)addr, (size_t)size);
 688   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 689 
 690   return addr;
 691 WB_END
 692 
 693 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 694   os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
 695   MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
 696 WB_END
 697 
 698 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 699   os::uncommit_memory((char *)(uintptr_t)addr, size);
 700 WB_END
 701 
 702 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 703   os::release_memory((char *)(uintptr_t)addr, size);
 704 WB_END
 705 
 706 WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
 707   // Test that we can downgrade NMT levels but not upgrade them.
 708   if (MemTracker::tracking_level() == NMT_off) {
 709     MemTracker::transition_to(NMT_off);
 710     return MemTracker::tracking_level() == NMT_off;
 711   } else {
 712     assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
 713     MemTracker::transition_to(NMT_summary);
 714     assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
 715 
 716     // Can't go to detail once NMT is set to summary.
 717     MemTracker::transition_to(NMT_detail);
 718     assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now");
 719 
 720     // Shutdown sets tracking level to minimal.
 721     MemTracker::shutdown();
 722     assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now");
 723 
 724     // Once the tracking level is minimal, we cannot increase to summary.
 725     // The code ignores this request instead of asserting because if the malloc site
 726     // table overflows in another thread, it tries to change the code to summary.
 727     MemTracker::transition_to(NMT_summary);
 728     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 729 
 730     // Really can never go up to detail, verify that the code would never do this.
 731     MemTracker::transition_to(NMT_detail);
 732     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 733     return MemTracker::tracking_level() == NMT_minimal;
 734   }
 735 WB_END
 736 
 737 WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
 738   int hash_size = MallocSiteTable::hash_buckets();
 739   assert(hash_size > 0, "NMT hash_size should be > 0");
 740   return (jint)hash_size;
 741 WB_END
 742 
 743 WB_ENTRY(jlong, WB_NMTNewArena(JNIEnv* env, jobject o, jlong init_size))
 744   Arena* arena =  new (mtTest) Arena(mtTest, size_t(init_size));
 745   return (jlong)arena;
 746 WB_END
 747 
 748 WB_ENTRY(void, WB_NMTFreeArena(JNIEnv* env, jobject o, jlong arena))
 749   Arena* a = (Arena*)arena;
 750   delete a;
 751 WB_END
 752 
 753 WB_ENTRY(void, WB_NMTArenaMalloc(JNIEnv* env, jobject o, jlong arena, jlong size))
 754   Arena* a = (Arena*)arena;
 755   a->Amalloc(size_t(size));
 756 WB_END
 757 #endif // INCLUDE_NMT
 758 
 759 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
 760   assert(method != NULL, "method should not be null");
 761   ThreadToNativeFromVM ttn(thread);
 762   return env->FromReflectedMethod(method);
 763 }
 764 
 765 // Deoptimizes all compiled frames and makes nmethods not entrant if it's requested
 766 class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation {
 767  private:
 768   int _result;
 769   const bool _make_not_entrant;
 770  public:
 771   VM_WhiteBoxDeoptimizeFrames(bool make_not_entrant) :
 772         _result(0), _make_not_entrant(make_not_entrant) { }
 773   int  result() const { return _result; }
 774 
 775   void doit() {
 776     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
 777       if (t->has_last_Java_frame()) {
 778         for (StackFrameStream fst(t, false /* update */, true /* process_frames */); !fst.is_done(); fst.next()) {
 779           frame* f = fst.current();
 780           if (f->can_be_deoptimized() && !f->is_deoptimized_frame()) {
 781             Deoptimization::deoptimize(t, *f);
 782             if (_make_not_entrant) {
 783                 CompiledMethod* cm = CodeCache::find_compiled(f->pc());
 784                 assert(cm != NULL, "sanity check");
 785                 cm->make_not_entrant();
 786             }
 787             ++_result;
 788           }
 789         }
 790       }
 791     }
 792   }
 793 };
 794 
 795 WB_ENTRY(jint, WB_DeoptimizeFrames(JNIEnv* env, jobject o, jboolean make_not_entrant))
 796   VM_WhiteBoxDeoptimizeFrames op(make_not_entrant == JNI_TRUE);
 797   VMThread::execute(&op);
 798   return op.result();
 799 WB_END
 800 
 801 WB_ENTRY(jboolean, WB_IsFrameDeoptimized(JNIEnv* env, jobject o, jint depth))
 802   bool result = false;
 803   if (thread->has_last_Java_frame()) {
 804     RegisterMap reg_map(thread);
 805     javaVFrame *jvf = thread->last_java_vframe(&reg_map);
 806     for (jint d = 0; d < depth && jvf != NULL; d++) {
 807       jvf = jvf->java_sender();
 808     }
 809     result = jvf != NULL && jvf->fr().is_deoptimized_frame();
 810   }
 811   return result;
 812 WB_END
 813 
 814 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
 815   CodeCache::mark_all_nmethods_for_deoptimization();
 816   Deoptimization::deoptimize_all_marked();
 817 WB_END
 818 
 819 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 820   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 821   int result = 0;
 822   CHECK_JNI_EXCEPTION_(env, result);
 823   MutexLocker mu(Compile_lock);
 824   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 825   if (is_osr) {
 826     result += mh->mark_osr_nmethods();
 827   } else if (mh->code() != NULL) {
 828     mh->code()->mark_for_deoptimization();
 829     ++result;
 830   }
 831   result += CodeCache::mark_for_deoptimization(mh());
 832   if (result > 0) {
 833     Deoptimization::deoptimize_all_marked();
 834   }
 835   return result;
 836 WB_END
 837 
 838 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 839   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 840   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 841   MutexLocker mu(Compile_lock);
 842   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 843   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 844   if (code == NULL) {
 845     return JNI_FALSE;
 846   }
 847   return (code->is_alive() && !code->is_marked_for_deoptimization());
 848 WB_END
 849 
 850 static bool is_excluded_for_compiler(AbstractCompiler* comp, methodHandle& mh) {
 851   if (comp == NULL) {
 852     return true;
 853   }
 854   DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, comp);
 855   if (directive->ExcludeOption) {
 856     return true;
 857   }
 858   return false;
 859 }
 860 
 861 static bool can_be_compiled_at_level(methodHandle& mh, jboolean is_osr, int level) {
 862   if (is_osr) {
 863     return CompilationPolicy::can_be_osr_compiled(mh, level);
 864   } else {
 865     return CompilationPolicy::can_be_compiled(mh, level);
 866   }
 867 }
 868 
 869 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 870   if (method == NULL || comp_level > CompilationPolicy::highest_compile_level()) {
 871     return false;
 872   }
 873   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 874   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 875   MutexLocker mu(Compile_lock);
 876   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 877 
 878   // The ExcludeOption directive is evaluated lazily upon compilation attempt. If a method was not tried to be compiled by
 879   // a compiler, yet, the method object is not set to be not compilable by that compiler. Thus, evaluate the compiler directive
 880   // to exclude a compilation of 'method'.
 881   if (comp_level == CompLevel_any) {
 882     // Both compilers could have ExcludeOption set. Check all combinations.
 883     bool excluded_c1 = is_excluded_for_compiler(CompileBroker::compiler1(), mh);
 884     bool excluded_c2 = is_excluded_for_compiler(CompileBroker::compiler2(), mh);
 885     if (excluded_c1 && excluded_c2) {
 886       // Compilation of 'method' excluded by both compilers.
 887       return false;
 888     }
 889 
 890     if (excluded_c1) {
 891       // C1 only has ExcludeOption set: Check if compilable with C2.
 892       return can_be_compiled_at_level(mh, is_osr, CompLevel_full_optimization);
 893     } else if (excluded_c2) {
 894       // C2 only has ExcludeOption set: Check if compilable with C1.
 895       return can_be_compiled_at_level(mh, is_osr, CompLevel_simple);
 896     }
 897   } else if (comp_level > CompLevel_none && is_excluded_for_compiler(CompileBroker::compiler((int)comp_level), mh)) {
 898     // Compilation of 'method' excluded by compiler used for 'comp_level'.
 899     return false;
 900   }
 901 
 902   return can_be_compiled_at_level(mh, is_osr, (int)comp_level);
 903 WB_END
 904 
 905 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method))
 906   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 907   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 908   MutexLocker mu(Compile_lock);
 909   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 910   return mh->queued_for_compilation();
 911 WB_END
 912 
 913 WB_ENTRY(jboolean, WB_IsIntrinsicAvailable(JNIEnv* env, jobject o, jobject method, jobject compilation_context, jint compLevel))
 914   if (compLevel < CompLevel_none || compLevel > CompilationPolicy::highest_compile_level()) {
 915     return false; // Intrinsic is not available on a non-existent compilation level.
 916   }
 917   jmethodID method_id, compilation_context_id;
 918   method_id = reflected_method_to_jmid(thread, env, method);
 919   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 920   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(method_id));
 921 
 922   DirectiveSet* directive;
 923   AbstractCompiler* comp = CompileBroker::compiler((int)compLevel);
 924   assert(comp != NULL, "compiler not available");
 925   if (compilation_context != NULL) {
 926     compilation_context_id = reflected_method_to_jmid(thread, env, compilation_context);
 927     CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 928     methodHandle cch(THREAD, Method::checked_resolve_jmethod_id(compilation_context_id));
 929     directive = DirectivesStack::getMatchingDirective(cch, comp);
 930   } else {
 931     // Calling with NULL matches default directive
 932     directive = DirectivesStack::getDefaultDirective(comp);
 933   }
 934   bool result = comp->is_intrinsic_available(mh, directive);
 935   DirectivesStack::release(directive);
 936   return result;
 937 WB_END
 938 
 939 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 940   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 941   CHECK_JNI_EXCEPTION_(env, CompLevel_none);
 942   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 943   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 944   return (code != NULL ? code->comp_level() : CompLevel_none);
 945 WB_END
 946 
 947 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 948   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 949   CHECK_JNI_EXCEPTION(env);
 950   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 951   if (is_osr) {
 952     mh->set_not_osr_compilable("WhiteBox", comp_level);
 953   } else {
 954     mh->set_not_compilable("WhiteBox", comp_level);
 955   }
 956 WB_END
 957 
 958 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
 959   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 960   CHECK_JNI_EXCEPTION_(env, InvocationEntryBci);
 961   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 962   CompiledMethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
 963   return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
 964 WB_END
 965 
 966 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 967   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 968   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 969   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 970   bool result = mh->dont_inline();
 971   mh->set_dont_inline(value == JNI_TRUE);
 972   return result;
 973 WB_END
 974 
 975 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
 976   if (comp_level == CompLevel_any) {
 977     return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
 978         CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
 979   } else {
 980     return CompileBroker::queue_size(comp_level);
 981   }
 982 WB_END
 983 
 984 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 985   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 986   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 987   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 988   bool result = mh->force_inline();
 989   mh->set_force_inline(value == JNI_TRUE);
 990   return result;
 991 WB_END
 992 
 993 #ifdef LINUX
 994 bool WhiteBox::validate_cgroup(const char* proc_cgroups,
 995                                const char* proc_self_cgroup,
 996                                const char* proc_self_mountinfo,
 997                                u1* cg_flags) {
 998   CgroupInfo cg_infos[CG_INFO_LENGTH];
 999   return CgroupSubsystemFactory::determine_type(cg_infos, proc_cgroups,
1000                                                     proc_self_cgroup,
1001                                                     proc_self_mountinfo, cg_flags);
1002 }
1003 #endif
1004 
1005 bool WhiteBox::compile_method(Method* method, int comp_level, int bci, JavaThread* THREAD) {
1006   // Screen for unavailable/bad comp level or null method
1007   AbstractCompiler* comp = CompileBroker::compiler(comp_level);
1008   if (method == NULL) {
1009     tty->print_cr("WB error: request to compile NULL method");
1010     return false;
1011   }
1012   if (comp_level > CompilationPolicy::highest_compile_level()) {
1013     tty->print_cr("WB error: invalid compilation level %d", comp_level);
1014     return false;
1015   }
1016   if (comp == NULL) {
1017     tty->print_cr("WB error: no compiler for requested compilation level %d", comp_level);
1018     return false;
1019   }
1020 
1021   // Check if compilation is blocking
1022   methodHandle mh(THREAD, method);
1023   DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, comp);
1024   bool is_blocking = !directive->BackgroundCompilationOption;
1025   DirectivesStack::release(directive);
1026 
1027   // Compile method and check result
1028   nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), CompileTask::Reason_Whitebox, CHECK_false);
1029   MutexLocker mu(THREAD, Compile_lock);
1030   bool is_queued = mh->queued_for_compilation();
1031   if ((!is_blocking && is_queued) || nm != NULL) {
1032     return true;
1033   }
1034   // Check code again because compilation may be finished before Compile_lock is acquired.
1035   if (bci == InvocationEntryBci) {
1036     CompiledMethod* code = mh->code();
1037     if (code != NULL && code->as_nmethod_or_null() != NULL) {
1038       return true;
1039     }
1040   } else if (mh->lookup_osr_nmethod_for(bci, comp_level, false) != NULL) {
1041     return true;
1042   }
1043   tty->print("WB error: failed to %s compile at level %d method ", is_blocking ? "blocking" : "", comp_level);
1044   mh->print_short_name(tty);
1045   tty->cr();
1046   if (is_blocking && is_queued) {
1047     tty->print_cr("WB error: blocking compilation is still in queue!");
1048   }
1049   return false;
1050 }
1051 
1052 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
1053   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1054   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
1055   return WhiteBox::compile_method(Method::checked_resolve_jmethod_id(jmid), comp_level, bci, THREAD);
1056 WB_END
1057 
1058 WB_ENTRY(jboolean, WB_EnqueueInitializerForCompilation(JNIEnv* env, jobject o, jclass klass, jint comp_level))
1059   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1060   Method* clinit = ik->class_initializer();
1061   if (clinit == NULL || clinit->method_holder()->is_not_initialized()) {
1062     return false;
1063   }
1064   return WhiteBox::compile_method(clinit, comp_level, InvocationEntryBci, THREAD);
1065 WB_END
1066 
1067 WB_ENTRY(jboolean, WB_ShouldPrintAssembly(JNIEnv* env, jobject o, jobject method, jint comp_level))
1068   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1069   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
1070 
1071   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1072   DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, CompileBroker::compiler(comp_level));
1073   bool result = directive->PrintAssemblyOption;
1074   DirectivesStack::release(directive);
1075 
1076   return result;
1077 WB_END
1078 
1079 WB_ENTRY(jint, WB_MatchesInline(JNIEnv* env, jobject o, jobject method, jstring pattern))
1080   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1081   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
1082 
1083   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1084 
1085   ResourceMark rm(THREAD);
1086   const char* error_msg = NULL;
1087   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
1088   InlineMatcher* m = InlineMatcher::parse_inline_pattern(method_str, error_msg);
1089 
1090   if (m == NULL) {
1091     assert(error_msg != NULL, "Always have an error message");
1092     tty->print_cr("Got error: %s", error_msg);
1093     return -1; // Pattern failed
1094   }
1095 
1096   // Pattern works - now check if it matches
1097   int result;
1098   if (m->match(mh, InlineMatcher::force_inline)) {
1099     result = 2; // Force inline match
1100   } else if (m->match(mh, InlineMatcher::dont_inline)) {
1101     result = 1; // Dont inline match
1102   } else {
1103     result = 0; // No match
1104   }
1105   delete m;
1106   return result;
1107 WB_END
1108 
1109 WB_ENTRY(jint, WB_MatchesMethod(JNIEnv* env, jobject o, jobject method, jstring pattern))
1110   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1111   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
1112 
1113   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1114 
1115   ResourceMark rm;
1116   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
1117 
1118   const char* error_msg = NULL;
1119 
1120   BasicMatcher* m = BasicMatcher::parse_method_pattern(method_str, error_msg, false);
1121   if (m == NULL) {
1122     assert(error_msg != NULL, "Must have error_msg");
1123     tty->print_cr("Got error: %s", error_msg);
1124     return -1;
1125   }
1126 
1127   // Pattern works - now check if it matches
1128   int result = m->matches(mh);
1129   delete m;
1130   assert(result == 0 || result == 1, "Result out of range");
1131   return result;
1132 WB_END
1133 
1134 WB_ENTRY(void, WB_MarkMethodProfiled(JNIEnv* env, jobject o, jobject method))
1135   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1136   CHECK_JNI_EXCEPTION(env);
1137   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1138 
1139   MethodData* mdo = mh->method_data();
1140   if (mdo == NULL) {
1141     Method::build_interpreter_method_data(mh, CHECK_AND_CLEAR);
1142     mdo = mh->method_data();
1143   }
1144   mdo->init();
1145   InvocationCounter* icnt = mdo->invocation_counter();
1146   InvocationCounter* bcnt = mdo->backedge_counter();
1147   // set i-counter according to CompilationPolicy::is_method_profiled
1148   icnt->set(Tier4MinInvocationThreshold);
1149   bcnt->set(Tier4CompileThreshold);
1150 WB_END
1151 
1152 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
1153   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1154   CHECK_JNI_EXCEPTION(env);
1155   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1156   MutexLocker mu(THREAD, Compile_lock);
1157   MethodData* mdo = mh->method_data();
1158   MethodCounters* mcs = mh->method_counters();
1159 
1160   if (mdo != NULL) {
1161     mdo->init();
1162     ResourceMark rm(THREAD);
1163     int arg_count = mdo->method()->size_of_parameters();
1164     for (int i = 0; i < arg_count; i++) {
1165       mdo->set_arg_modified(i, 0);
1166     }
1167     MutexLocker mu(THREAD, mdo->extra_data_lock());
1168     mdo->clean_method_data(/*always_clean*/true);
1169   }
1170 
1171   mh->clear_not_c1_compilable();
1172   mh->clear_not_c2_compilable();
1173   mh->clear_not_c2_osr_compilable();
1174   NOT_PRODUCT(mh->set_compiled_invocation_count(0));
1175   if (mcs != NULL) {
1176     mcs->clear_counters();
1177   }
1178 WB_END
1179 
1180 template <typename T, int type_enum>
1181 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) {
1182   if (name == NULL) {
1183     return false;
1184   }
1185   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1186   const char* flag_name = env->GetStringUTFChars(name, NULL);
1187   CHECK_JNI_EXCEPTION_(env, false);
1188   const JVMFlag* flag = JVMFlag::find_declared_flag(flag_name);
1189   JVMFlag::Error result = JVMFlagAccess::get<T, type_enum>(flag, value);
1190   env->ReleaseStringUTFChars(name, flag_name);
1191   return (result == JVMFlag::SUCCESS);
1192 }
1193 
1194 template <typename T, int type_enum>
1195 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) {
1196   if (name == NULL) {
1197     return false;
1198   }
1199   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1200   const char* flag_name = env->GetStringUTFChars(name, NULL);
1201   CHECK_JNI_EXCEPTION_(env, false);
1202   JVMFlag* flag = JVMFlag::find_flag(flag_name);
1203   JVMFlag::Error result = JVMFlagAccess::set<T, type_enum>(flag, value, JVMFlagOrigin::INTERNAL);
1204   env->ReleaseStringUTFChars(name, flag_name);
1205   return (result == JVMFlag::SUCCESS);
1206 }
1207 
1208 template <typename T>
1209 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
1210   ResourceMark rm(thread);
1211   jclass clazz = env->FindClass(name->as_C_string());
1212   CHECK_JNI_EXCEPTION_(env, NULL);
1213   jmethodID methodID = env->GetStaticMethodID(clazz,
1214         vmSymbols::valueOf_name()->as_C_string(),
1215         sig->as_C_string());
1216   CHECK_JNI_EXCEPTION_(env, NULL);
1217   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
1218   CHECK_JNI_EXCEPTION_(env, NULL);
1219   return result;
1220 }
1221 
1222 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
1223   return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
1224 }
1225 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
1226   return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
1227 }
1228 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
1229   return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
1230 }
1231 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
1232   return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
1233 }*/
1234 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
1235   return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
1236 }
1237 
1238 static const JVMFlag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
1239   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1240   const char* flag_name = env->GetStringUTFChars(name, NULL);
1241   CHECK_JNI_EXCEPTION_(env, NULL);
1242   const JVMFlag* result = JVMFlag::find_declared_flag(flag_name);
1243   env->ReleaseStringUTFChars(name, flag_name);
1244   return result;
1245 }
1246 
1247 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name))
1248   const JVMFlag* flag = getVMFlag(thread, env, name);
1249   return (flag != NULL) && flag->is_constant_in_binary();
1250 WB_END
1251 
1252 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name))
1253   const JVMFlag* flag = getVMFlag(thread, env, name);
1254   return (flag != NULL) && !(flag->is_unlocked() || flag->is_unlocker());
1255 WB_END
1256 
1257 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
1258   bool result;
1259   if (GetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result)) {
1260     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1261     return booleanBox(thread, env, result);
1262   }
1263   return NULL;
1264 WB_END
1265 
1266 template <typename T, int type_enum>
1267 jobject GetVMFlag_longBox(JNIEnv* env, JavaThread* thread, jstring name) {
1268   T result;
1269   if (GetVMFlag <T, type_enum> (thread, env, name, &result)) {
1270     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1271     return longBox(thread, env, result);
1272   }
1273   return NULL;
1274 }
1275 
1276 WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name))
1277   return GetVMFlag_longBox<JVM_FLAG_TYPE(int)>(env, thread, name);
1278 WB_END
1279 
1280 WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name))
1281   return GetVMFlag_longBox<JVM_FLAG_TYPE(uint)>(env, thread, name);
1282 WB_END
1283 
1284 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
1285   return GetVMFlag_longBox<JVM_FLAG_TYPE(intx)>(env, thread, name);
1286 WB_END
1287 
1288 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
1289   return GetVMFlag_longBox<JVM_FLAG_TYPE(uintx)>(env, thread, name);
1290 WB_END
1291 
1292 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
1293   return GetVMFlag_longBox<JVM_FLAG_TYPE(uint64_t)>(env, thread, name);
1294 WB_END
1295 
1296 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
1297   return GetVMFlag_longBox<JVM_FLAG_TYPE(size_t)>(env, thread, name);
1298 WB_END
1299 
1300 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
1301   double result;
1302   if (GetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result)) {
1303     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1304     return doubleBox(thread, env, result);
1305   }
1306   return NULL;
1307 WB_END
1308 
1309 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
1310   ccstr ccstrResult;
1311   if (GetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, &ccstrResult)) {
1312     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1313     jstring result = env->NewStringUTF(ccstrResult);
1314     CHECK_JNI_EXCEPTION_(env, NULL);
1315     return result;
1316   }
1317   return NULL;
1318 WB_END
1319 
1320 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
1321   bool result = value == JNI_TRUE ? true : false;
1322   SetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result);
1323 WB_END
1324 
1325 WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1326   int result = value;
1327   SetVMFlag <JVM_FLAG_TYPE(int)> (thread, env, name, &result);
1328 WB_END
1329 
1330 WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1331   uint result = value;
1332   SetVMFlag <JVM_FLAG_TYPE(uint)> (thread, env, name, &result);
1333 WB_END
1334 
1335 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1336   intx result = value;
1337   SetVMFlag <JVM_FLAG_TYPE(intx)> (thread, env, name, &result);
1338 WB_END
1339 
1340 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1341   uintx result = value;
1342   SetVMFlag <JVM_FLAG_TYPE(uintx)> (thread, env, name, &result);
1343 WB_END
1344 
1345 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1346   uint64_t result = value;
1347   SetVMFlag <JVM_FLAG_TYPE(uint64_t)> (thread, env, name, &result);
1348 WB_END
1349 
1350 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1351   size_t result = value;
1352   SetVMFlag <JVM_FLAG_TYPE(size_t)> (thread, env, name, &result);
1353 WB_END
1354 
1355 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
1356   double result = value;
1357   SetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result);
1358 WB_END
1359 
1360 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
1361   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1362   const char* ccstrValue;
1363   if (value == NULL) {
1364     ccstrValue = NULL;
1365   }
1366   else {
1367     ccstrValue = env->GetStringUTFChars(value, NULL);
1368     CHECK_JNI_EXCEPTION(env);
1369   }
1370   {
1371     ccstr param = ccstrValue;
1372     ThreadInVMfromNative ttvfn(thread); // back to VM
1373     if (SetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, &param)) {
1374       assert(param == NULL, "old value is freed automatically and not returned");
1375     }
1376   }
1377   if (value != NULL) {
1378     env->ReleaseStringUTFChars(value, ccstrValue);
1379   }
1380 WB_END
1381 
1382 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
1383   WhiteBox::compilation_locked = true;
1384 WB_END
1385 
1386 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
1387   MonitorLocker mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
1388   WhiteBox::compilation_locked = false;
1389   mo.notify_all();
1390 WB_END
1391 
1392 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
1393   // Force a code cache sweep and block until it finished
1394   NMethodSweeper::force_sweep();
1395 WB_END
1396 
1397 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
1398   ResourceMark rm(THREAD);
1399   int len;
1400   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
1401   return (StringTable::lookup(name, len) != NULL);
1402 WB_END
1403 
1404 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
1405   Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
1406   Universe::heap()->collect(GCCause::_wb_full_gc);
1407 #if INCLUDE_G1GC
1408   if (UseG1GC) {
1409     // Needs to be cleared explicitly for G1
1410     Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
1411   }
1412 #endif // INCLUDE_G1GC
1413 WB_END
1414 
1415 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
1416   Universe::heap()->collect(GCCause::_wb_young_gc);
1417 WB_END
1418 
1419 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
1420   // static+volatile in order to force the read to happen
1421   // (not be eliminated by the compiler)
1422   static char c;
1423   static volatile char* p;
1424 
1425   p = os::reserve_memory(os::vm_allocation_granularity());
1426   if (p == NULL) {
1427     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
1428   }
1429 
1430   c = *p;
1431 WB_END
1432 
1433 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
1434   const char* features = VM_Version::features_string();
1435   ThreadToNativeFromVM ttn(thread);
1436   jstring features_string = env->NewStringUTF(features);
1437 
1438   CHECK_JNI_EXCEPTION_(env, NULL);
1439 
1440   return features_string;
1441 WB_END
1442 
1443 int WhiteBox::get_blob_type(const CodeBlob* code) {
1444   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1445   return CodeCache::get_code_heap(code)->code_blob_type();
1446 }
1447 
1448 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
1449   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1450   return CodeCache::get_code_heap(blob_type);
1451 }
1452 
1453 struct CodeBlobStub {
1454   CodeBlobStub(const CodeBlob* blob) :
1455       name(os::strdup(blob->name())),
1456       size(blob->size()),
1457       blob_type(WhiteBox::get_blob_type(blob)),
1458       address((jlong) blob) { }
1459   ~CodeBlobStub() { os::free((void*) name); }
1460   const char* const name;
1461   const jint        size;
1462   const jint        blob_type;
1463   const jlong       address;
1464 };
1465 
1466 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
1467   ResourceMark rm;
1468   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1469   CHECK_JNI_EXCEPTION_(env, NULL);
1470   jobjectArray result = env->NewObjectArray(4, clazz, NULL);
1471 
1472   jstring name = env->NewStringUTF(cb->name);
1473   CHECK_JNI_EXCEPTION_(env, NULL);
1474   env->SetObjectArrayElement(result, 0, name);
1475 
1476   jobject obj = integerBox(thread, env, cb->size);
1477   CHECK_JNI_EXCEPTION_(env, NULL);
1478   env->SetObjectArrayElement(result, 1, obj);
1479 
1480   obj = integerBox(thread, env, cb->blob_type);
1481   CHECK_JNI_EXCEPTION_(env, NULL);
1482   env->SetObjectArrayElement(result, 2, obj);
1483 
1484   obj = longBox(thread, env, cb->address);
1485   CHECK_JNI_EXCEPTION_(env, NULL);
1486   env->SetObjectArrayElement(result, 3, obj);
1487 
1488   return result;
1489 }
1490 
1491 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1492   ResourceMark rm(THREAD);
1493   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1494   CHECK_JNI_EXCEPTION_(env, NULL);
1495   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1496   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1497   jobjectArray result = NULL;
1498   if (code == NULL) {
1499     return result;
1500   }
1501   int comp_level = code->comp_level();
1502   int insts_size = code->insts_size();
1503 
1504   ThreadToNativeFromVM ttn(thread);
1505   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1506   CHECK_JNI_EXCEPTION_(env, NULL);
1507   result = env->NewObjectArray(5, clazz, NULL);
1508   if (result == NULL) {
1509     return result;
1510   }
1511 
1512   CodeBlobStub stub(code);
1513   jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1514   CHECK_JNI_EXCEPTION_(env, NULL);
1515   env->SetObjectArrayElement(result, 0, codeBlob);
1516 
1517   jobject level = integerBox(thread, env, comp_level);
1518   CHECK_JNI_EXCEPTION_(env, NULL);
1519   env->SetObjectArrayElement(result, 1, level);
1520 
1521   jbyteArray insts = env->NewByteArray(insts_size);
1522   CHECK_JNI_EXCEPTION_(env, NULL);
1523   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1524   env->SetObjectArrayElement(result, 2, insts);
1525 
1526   jobject id = integerBox(thread, env, code->compile_id());
1527   CHECK_JNI_EXCEPTION_(env, NULL);
1528   env->SetObjectArrayElement(result, 3, id);
1529 
1530   jobject entry_point = longBox(thread, env, (jlong) code->entry_point());
1531   CHECK_JNI_EXCEPTION_(env, NULL);
1532   env->SetObjectArrayElement(result, 4, entry_point);
1533 
1534   return result;
1535 WB_END
1536 
1537 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1538   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1539   BufferBlob* blob;
1540   int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1541   if (full_size < size) {
1542     full_size += align_up(size - full_size, oopSize);
1543   }
1544   {
1545     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1546     blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1547     if (blob != NULL) {
1548       ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1549     }
1550   }
1551   // Track memory usage statistic after releasing CodeCache_lock
1552   MemoryService::track_code_cache_memory_usage();
1553   return blob;
1554 }
1555 
1556 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
1557   if (size < 0) {
1558     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1559       err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size));
1560   }
1561   return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
1562 WB_END
1563 
1564 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
1565   if (addr == 0) {
1566     return;
1567   }
1568   BufferBlob::free((BufferBlob*) addr);
1569 WB_END
1570 
1571 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
1572   ResourceMark rm;
1573   GrowableArray<CodeBlobStub*> blobs;
1574   {
1575     MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1576     CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
1577     if (heap == NULL) {
1578       return NULL;
1579     }
1580     for (CodeBlob* cb = (CodeBlob*) heap->first();
1581          cb != NULL; cb = (CodeBlob*) heap->next(cb)) {
1582       CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub);
1583       new (stub) CodeBlobStub(cb);
1584       blobs.append(stub);
1585     }
1586   }
1587   ThreadToNativeFromVM ttn(thread);
1588   jobjectArray result = NULL;
1589   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1590   CHECK_JNI_EXCEPTION_(env, NULL);
1591   result = env->NewObjectArray(blobs.length(), clazz, NULL);
1592   CHECK_JNI_EXCEPTION_(env, NULL);
1593   if (result == NULL) {
1594     return result;
1595   }
1596   int i = 0;
1597   for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin();
1598        it != blobs.end(); ++it) {
1599     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
1600     CHECK_JNI_EXCEPTION_(env, NULL);
1601     env->SetObjectArrayElement(result, i, obj);
1602     CHECK_JNI_EXCEPTION_(env, NULL);
1603     ++i;
1604   }
1605   return result;
1606 WB_END
1607 
1608 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1609   return CompileBroker::get_compilation_activity_mode();
1610 WB_END
1611 
1612 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1613   if (addr == 0) {
1614     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1615       "WB_GetCodeBlob: addr is null");
1616   }
1617   ThreadToNativeFromVM ttn(thread);
1618   CodeBlobStub stub((CodeBlob*) addr);
1619   return codeBlob2objectArray(thread, env, &stub);
1620 WB_END
1621 
1622 WB_ENTRY(jlong, WB_GetMethodData(JNIEnv* env, jobject wv, jobject method))
1623   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1624   CHECK_JNI_EXCEPTION_(env, 0);
1625   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1626   return (jlong) mh->method_data();
1627 WB_END
1628 
1629 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1630   return (jlong) thread->stack_size();
1631 WB_END
1632 
1633 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1634   return (jlong) thread->stack_overflow_state()->stack_available(
1635                    os::current_stack_pointer()) - (jlong)StackOverflow::stack_shadow_zone_size();
1636 WB_END
1637 
1638 
1639 int WhiteBox::array_bytes_to_length(size_t bytes) {
1640   return Array<u1>::bytes_to_length(bytes);
1641 }
1642 
1643 ///////////////
1644 // MetaspaceTestContext and MetaspaceTestArena
1645 WB_ENTRY(jlong, WB_CreateMetaspaceTestContext(JNIEnv* env, jobject wb, jlong commit_limit, jlong reserve_limit))
1646   metaspace::MetaspaceTestContext* context =
1647       new metaspace::MetaspaceTestContext("whitebox-metaspace-context", (size_t) commit_limit, (size_t) reserve_limit);
1648   return (jlong)p2i(context);
1649 WB_END
1650 
1651 WB_ENTRY(void, WB_DestroyMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
1652   delete (metaspace::MetaspaceTestContext*) context;
1653 WB_END
1654 
1655 WB_ENTRY(void, WB_PurgeMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
1656   metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
1657   context0->purge_area();
1658 WB_END
1659 
1660 WB_ENTRY(void, WB_PrintMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
1661   metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
1662   context0->print_on(tty);
1663 WB_END
1664 
1665 WB_ENTRY(jlong, WB_GetTotalCommittedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
1666   metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
1667   return context0->committed_words();
1668 WB_END
1669 
1670 WB_ENTRY(jlong, WB_GetTotalUsedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context))
1671   metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
1672   return context0->used_words();
1673 WB_END
1674 
1675 WB_ENTRY(jlong, WB_CreateArenaInTestContext(JNIEnv* env, jobject wb, jlong context, jboolean is_micro))
1676   const Metaspace::MetaspaceType type = is_micro ? Metaspace::ReflectionMetaspaceType : Metaspace::StandardMetaspaceType;
1677   metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context;
1678   return (jlong)p2i(context0->create_arena(type));
1679 WB_END
1680 
1681 WB_ENTRY(void, WB_DestroyMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena))
1682   delete (metaspace::MetaspaceTestArena*) arena;
1683 WB_END
1684 
1685 WB_ENTRY(jlong, WB_AllocateFromMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong word_size))
1686   metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena;
1687   MetaWord* p = arena0->allocate((size_t) word_size);
1688   return (jlong)p2i(p);
1689 WB_END
1690 
1691 WB_ENTRY(void, WB_DeallocateToMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong p, jlong word_size))
1692   metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena;
1693   arena0->deallocate((MetaWord*)p, (size_t) word_size);
1694 WB_END
1695 
1696 WB_ENTRY(jlong, WB_GetMaxMetaspaceAllocationSize(JNIEnv* env, jobject wb))
1697   return (jlong) Metaspace::max_allocation_word_size() * BytesPerWord;
1698 WB_END
1699 
1700 //////////////
1701 
1702 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1703   if (size < 0) {
1704     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1705         err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1706   }
1707 
1708   oop class_loader_oop = JNIHandles::resolve(class_loader);
1709   ClassLoaderData* cld = class_loader_oop != NULL
1710       ? java_lang_ClassLoader::loader_data_acquire(class_loader_oop)
1711       : ClassLoaderData::the_null_class_loader_data();
1712 
1713   void* metadata = MetadataFactory::new_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1714 
1715   return (jlong)(uintptr_t)metadata;
1716 WB_END
1717 
1718 WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jboolean is_open,
1719                                 jstring version, jstring location, jobjectArray packages))
1720   Handle h_module (THREAD, JNIHandles::resolve(module));
1721   Modules::define_module(h_module, is_open, version, location, packages, CHECK);
1722 WB_END
1723 
1724 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
1725   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1726   Handle h_to_module (THREAD, JNIHandles::resolve(to_module));
1727   Modules::add_module_exports_qualified(h_from_module, package, h_to_module, CHECK);
1728 WB_END
1729 
1730 WB_ENTRY(void, WB_AddModuleExportsToAllUnnamed(JNIEnv* env, jobject o, jclass module, jstring package))
1731   Handle h_module (THREAD, JNIHandles::resolve(module));
1732   Modules::add_module_exports_to_all_unnamed(h_module, package, CHECK);
1733 WB_END
1734 
1735 WB_ENTRY(void, WB_AddModuleExportsToAll(JNIEnv* env, jobject o, jclass module, jstring package))
1736   Handle h_module (THREAD, JNIHandles::resolve(module));
1737   Modules::add_module_exports(h_module, package, Handle(), CHECK);
1738 WB_END
1739 
1740 WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject source_module))
1741   Handle h_from_module (THREAD, JNIHandles::resolve(from_module));
1742   Handle h_source_module (THREAD, JNIHandles::resolve(source_module));
1743   Modules::add_reads_module(h_from_module, h_source_module, CHECK);
1744 WB_END
1745 
1746 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1747   if (inc < 0) {
1748     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1749         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1750   }
1751 
1752   jlong max_size_t = (jlong) ((size_t) -1);
1753   if (inc > max_size_t) {
1754     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1755         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1756   }
1757 
1758   size_t new_cap_until_GC = 0;
1759   size_t aligned_inc = align_down((size_t) inc, Metaspace::commit_alignment());
1760   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1761   if (!success) {
1762     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1763                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
1764                 "due to contention with another thread");
1765   }
1766   return (jlong) new_cap_until_GC;
1767 WB_END
1768 
1769 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
1770   return (jlong) MetaspaceGC::capacity_until_GC();
1771 WB_END
1772 
1773 // The function is only valid when CDS is available.
1774 WB_ENTRY(jlong, WB_MetaspaceSharedRegionAlignment(JNIEnv* env, jobject wb))
1775 #if INCLUDE_CDS
1776   return (jlong)MetaspaceShared::core_region_alignment();
1777 #else
1778   ShouldNotReachHere();
1779   return 0L;
1780 #endif
1781 WB_END
1782 
1783 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1784   oop obj_oop = JNIHandles::resolve(obj);
1785   return (jboolean) obj_oop->mark().has_monitor();
1786 WB_END
1787 
1788 WB_ENTRY(jboolean, WB_DeflateIdleMonitors(JNIEnv* env, jobject wb))
1789   log_info(monitorinflation)("WhiteBox initiated DeflateIdleMonitors");
1790   return ObjectSynchronizer::request_deflate_idle_monitors();
1791 WB_END
1792 
1793 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1794   VM_ForceSafepoint force_safepoint_op;
1795   VMThread::execute(&force_safepoint_op);
1796 WB_END
1797 
1798 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
1799   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1800   return (jlong) ik->constants();
1801 WB_END
1802 
1803 WB_ENTRY(jint, WB_GetConstantPoolCacheIndexTag(JNIEnv* env, jobject wb))
1804   return ConstantPool::CPCACHE_INDEX_TAG;
1805 WB_END
1806 
1807 WB_ENTRY(jint, WB_GetConstantPoolCacheLength(JNIEnv* env, jobject wb, jclass klass))
1808   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1809   ConstantPool* cp = ik->constants();
1810   if (cp->cache() == NULL) {
1811       return -1;
1812   }
1813   return cp->cache()->length();
1814 WB_END
1815 
1816 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1817   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1818   ConstantPool* cp = ik->constants();
1819   if (cp->cache() == NULL) {
1820     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1821   }
1822   jint cpci = index;
1823   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1824   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1825     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1826   }
1827   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1828   return cpi;
1829 WB_END
1830 
1831 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1832   return ConstantPool::encode_invokedynamic_index(index);
1833 WB_END
1834 
1835 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1836   VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1837   VMThread::execute(&clear_ics);
1838 WB_END
1839 
1840 template <typename T>
1841 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1842   assert(value != NULL, "sanity");
1843   if (method == NULL || name == NULL) {
1844     return false;
1845   }
1846   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1847   CHECK_JNI_EXCEPTION_(env, false);
1848   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1849   // can't be in VM when we call JNI
1850   ThreadToNativeFromVM ttnfv(thread);
1851   const char* flag_name = env->GetStringUTFChars(name, NULL);
1852   CHECK_JNI_EXCEPTION_(env, false);
1853   enum CompileCommand option = CompilerOracle::string_to_option(flag_name);
1854   env->ReleaseStringUTFChars(name, flag_name);
1855   if (option == CompileCommand::Unknown) {
1856     return false;
1857   }
1858   if (!CompilerOracle::option_matches_type(option, *value)) {
1859     return false;
1860   }
1861   return CompilerOracle::has_option_value(mh, option, *value);
1862 }
1863 
1864 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1865   bool result;
1866   if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1867     // can't be in VM when we call JNI
1868     ThreadToNativeFromVM ttnfv(thread);
1869     return booleanBox(thread, env, result);
1870   }
1871   return NULL;
1872 WB_END
1873 
1874 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1875   intx result;
1876   if (GetMethodOption <intx> (thread, env, method, name, &result)) {
1877     // can't be in VM when we call JNI
1878     ThreadToNativeFromVM ttnfv(thread);
1879     return longBox(thread, env, result);
1880   }
1881   return NULL;
1882 WB_END
1883 
1884 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1885   uintx result;
1886   if (GetMethodOption <uintx> (thread, env, method, name, &result)) {
1887     // can't be in VM when we call JNI
1888     ThreadToNativeFromVM ttnfv(thread);
1889     return longBox(thread, env, result);
1890   }
1891   return NULL;
1892 WB_END
1893 
1894 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1895   double result;
1896   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1897     // can't be in VM when we call JNI
1898     ThreadToNativeFromVM ttnfv(thread);
1899     return doubleBox(thread, env, result);
1900   }
1901   return NULL;
1902 WB_END
1903 
1904 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1905   ccstr ccstrResult;
1906   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1907     // can't be in VM when we call JNI
1908     ThreadToNativeFromVM ttnfv(thread);
1909     jstring result = env->NewStringUTF(ccstrResult);
1910     CHECK_JNI_EXCEPTION_(env, NULL);
1911     return result;
1912   }
1913   return NULL;
1914 WB_END
1915 
1916 WB_ENTRY(jobject, WB_GetDefaultArchivePath(JNIEnv* env, jobject wb))
1917   const char* p = Arguments::get_default_shared_archive_path();
1918   ThreadToNativeFromVM ttn(thread);
1919   jstring path_string = env->NewStringUTF(p);
1920 
1921   CHECK_JNI_EXCEPTION_(env, NULL);
1922 
1923   return path_string;
1924 WB_END
1925 
1926 WB_ENTRY(jboolean, WB_IsSharingEnabled(JNIEnv* env, jobject wb))
1927   return UseSharedSpaces;
1928 WB_END
1929 
1930 WB_ENTRY(jboolean, WB_CDSMemoryMappingFailed(JNIEnv* env, jobject wb))
1931   return FileMapInfo::memory_mapping_failed();
1932 WB_END
1933 
1934 WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
1935   oop obj_oop = JNIHandles::resolve(obj);
1936   return Universe::heap()->is_archived_object(obj_oop);
1937 WB_END
1938 
1939 WB_ENTRY(jboolean, WB_IsSharedInternedString(JNIEnv* env, jobject wb, jobject str))
1940   ResourceMark rm(THREAD);
1941   oop str_oop = JNIHandles::resolve(str);
1942   int length;
1943   jchar* chars = java_lang_String::as_unicode_string(str_oop, length, CHECK_(false));
1944   return StringTable::lookup_shared(chars, length) == str_oop;
1945 WB_END
1946 
1947 WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz))
1948   return (jboolean)MetaspaceShared::is_in_shared_metaspace(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
1949 WB_END
1950 
1951 WB_ENTRY(jboolean, WB_AreSharedStringsMapped(JNIEnv* env))
1952   return HeapShared::closed_regions_mapped();
1953 WB_END
1954 
1955 WB_ENTRY(jobject, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass clazz))
1956   Klass *k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1957   if (k->is_instance_klass()) {
1958     InstanceKlass *ik = InstanceKlass::cast(k);
1959     ConstantPool *cp = ik->constants();
1960     objArrayOop refs =  cp->resolved_references();
1961     return (jobject)JNIHandles::make_local(THREAD, refs);
1962   } else {
1963     return NULL;
1964   }
1965 WB_END
1966 
1967 WB_ENTRY(void, WB_LinkClass(JNIEnv* env, jobject wb, jclass clazz))
1968   Klass *k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1969   if (!k->is_instance_klass()) {
1970     return;
1971   }
1972   InstanceKlass *ik = InstanceKlass::cast(k);
1973   ik->link_class(THREAD); // may throw verification error
1974 WB_END
1975 
1976 WB_ENTRY(jboolean, WB_AreOpenArchiveHeapObjectsMapped(JNIEnv* env))
1977   return HeapShared::open_regions_mapped();
1978 WB_END
1979 
1980 WB_ENTRY(jboolean, WB_IsCDSIncluded(JNIEnv* env))
1981 #if INCLUDE_CDS
1982   return true;
1983 #else
1984   return false;
1985 #endif // INCLUDE_CDS
1986 WB_END
1987 
1988 WB_ENTRY(jboolean, WB_isC2OrJVMCIIncluded(JNIEnv* env))
1989 #if COMPILER2_OR_JVMCI
1990   return true;
1991 #else
1992   return false;
1993 #endif
1994 WB_END
1995 
1996 WB_ENTRY(jboolean, WB_IsJVMCISupportedByGC(JNIEnv* env))
1997 #if INCLUDE_JVMCI
1998   return JVMCIGlobals::gc_supports_jvmci();
1999 #else
2000   return false;
2001 #endif
2002 WB_END
2003 
2004 WB_ENTRY(jboolean, WB_CanWriteJavaHeapArchive(JNIEnv* env))
2005   return HeapShared::can_write();
2006 WB_END
2007 
2008 
2009 WB_ENTRY(jboolean, WB_IsJFRIncluded(JNIEnv* env))
2010 #if INCLUDE_JFR
2011   return true;
2012 #else
2013   return false;
2014 #endif // INCLUDE_JFR
2015 WB_END
2016 
2017 #if INCLUDE_CDS
2018 
2019 WB_ENTRY(jint, WB_GetCDSOffsetForName(JNIEnv* env, jobject o, jstring name))
2020   ResourceMark rm;
2021   char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
2022   jint result = (jint)CDSConstants::get_cds_offset(c_name);
2023   return result;
2024 WB_END
2025 
2026 WB_ENTRY(jint, WB_GetCDSConstantForName(JNIEnv* env, jobject o, jstring name))
2027   ResourceMark rm;
2028   char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
2029   jint result = (jint)CDSConstants::get_cds_constant(c_name);
2030   return result;
2031 WB_END
2032 
2033 #endif // INCLUDE_CDS
2034 
2035 WB_ENTRY(jboolean, WB_HandshakeReadMonitors(JNIEnv* env, jobject wb, jobject thread_handle))
2036   class ReadMonitorsClosure : public HandshakeClosure {
2037     jboolean _executed;
2038 
2039     void do_thread(Thread* th) {
2040       JavaThread* jt = JavaThread::cast(th);
2041       ResourceMark rm;
2042 
2043       GrowableArray<MonitorInfo*>* info = new GrowableArray<MonitorInfo*>();
2044 
2045       if (!jt->has_last_Java_frame()) {
2046         return;
2047       }
2048       RegisterMap rmap(jt);
2049       for (javaVFrame* vf = jt->last_java_vframe(&rmap); vf != NULL; vf = vf->java_sender()) {
2050         GrowableArray<MonitorInfo*> *monitors = vf->monitors();
2051         if (monitors != NULL) {
2052           int len = monitors->length();
2053           // Walk monitors youngest to oldest
2054           for (int i = len - 1; i >= 0; i--) {
2055             MonitorInfo* mon_info = monitors->at(i);
2056             if (mon_info->eliminated()) continue;
2057             oop owner = mon_info->owner();
2058             if (owner != NULL) {
2059               info->append(mon_info);
2060             }
2061           }
2062         }
2063       }
2064       _executed = true;
2065     }
2066 
2067    public:
2068     ReadMonitorsClosure() : HandshakeClosure("WB_HandshakeReadMonitors"), _executed(false) {}
2069     jboolean executed() const { return _executed; }
2070   };
2071 
2072   ReadMonitorsClosure rmc;
2073   oop thread_oop = JNIHandles::resolve(thread_handle);
2074   if (thread_oop != NULL) {
2075     JavaThread* target = java_lang_Thread::thread(thread_oop);
2076     Handshake::execute(&rmc, target);
2077   }
2078   return rmc.executed();
2079 WB_END
2080 
2081 WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle, jboolean all_threads))
2082   class TraceSelfClosure : public HandshakeClosure {
2083     jint _num_threads_completed;
2084 
2085     void do_thread(Thread* th) {
2086       JavaThread* jt = JavaThread::cast(th);
2087       ResourceMark rm;
2088 
2089       jt->print_on(tty);
2090       jt->print_stack_on(tty);
2091       tty->cr();
2092       Atomic::inc(&_num_threads_completed);
2093     }
2094 
2095   public:
2096     TraceSelfClosure(Thread* thread) : HandshakeClosure("WB_TraceSelf"), _num_threads_completed(0) {}
2097 
2098     jint num_threads_completed() const { return _num_threads_completed; }
2099   };
2100   TraceSelfClosure tsc(Thread::current());
2101 
2102   if (all_threads) {
2103     Handshake::execute(&tsc);
2104   } else {
2105     oop thread_oop = JNIHandles::resolve(thread_handle);
2106     if (thread_oop != NULL) {
2107       JavaThread* target = java_lang_Thread::thread(thread_oop);
2108       Handshake::execute(&tsc, target);
2109     }
2110   }
2111   return tsc.num_threads_completed();
2112 WB_END
2113 
2114 WB_ENTRY(void, WB_AsyncHandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle))
2115   class TraceSelfClosure : public AsyncHandshakeClosure {
2116     JavaThread* _self;
2117     void do_thread(Thread* th) {
2118       assert(th->is_Java_thread(), "sanity");
2119       // AsynchHandshake handshakes are only executed by target.
2120       assert(_self == th, "Must be");
2121       assert(Thread::current() == th, "Must be");
2122       JavaThread* jt = JavaThread::cast(th);
2123       ResourceMark rm;
2124       jt->print_on(tty);
2125       jt->print_stack_on(tty);
2126       tty->cr();
2127     }
2128 
2129   public:
2130     TraceSelfClosure(JavaThread* self_target) : AsyncHandshakeClosure("WB_TraceSelf"), _self(self_target) {}
2131   };
2132   oop thread_oop = JNIHandles::resolve(thread_handle);
2133   if (thread_oop != NULL) {
2134     JavaThread* target = java_lang_Thread::thread(thread_oop);
2135     TraceSelfClosure* tsc = new TraceSelfClosure(target);
2136     Handshake::execute(tsc, target);
2137   }
2138 WB_END
2139 
2140 static volatile int _emulated_lock = 0;
2141 
2142 WB_ENTRY(void, WB_LockAndBlock(JNIEnv* env, jobject wb, jboolean suspender))
2143   JavaThread* self = JavaThread::current();
2144 
2145   {
2146     // Before trying to acquire the lock transition into a safepoint safe state.
2147     // Otherwise if either suspender or suspendee blocks for a safepoint
2148     // in ~ThreadBlockInVM the other one could loop forever trying to acquire
2149     // the lock without allowing the safepoint to progress.
2150     ThreadBlockInVM tbivm(self);
2151 
2152     // We will deadlock here if we are 'suspender' and 'suspendee'
2153     // suspended in ~ThreadBlockInVM. This verifies we only suspend
2154     // at the right place.
2155     while (Atomic::cmpxchg(&_emulated_lock, 0, 1) != 0) {}
2156     assert(_emulated_lock == 1, "Must be locked");
2157 
2158     // Sleep much longer in suspendee to force situation where
2159     // 'suspender' is waiting above to acquire lock.
2160     os::naked_short_sleep(suspender ? 1 : 10);
2161   }
2162   Atomic::store(&_emulated_lock, 0);
2163 WB_END
2164 
2165 // Some convenience methods to deal with objects from java
2166 int WhiteBox::offset_for_field(const char* field_name, oop object,
2167     Symbol* signature_symbol) {
2168   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
2169 
2170   //Get the class of our object
2171   Klass* arg_klass = object->klass();
2172   //Turn it into an instance-klass
2173   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
2174 
2175   //Create symbols to look for in the class
2176   TempNewSymbol name_symbol = SymbolTable::new_symbol(field_name);
2177 
2178   //To be filled in with an offset of the field we're looking for
2179   fieldDescriptor fd;
2180 
2181   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
2182   if (res == NULL) {
2183     tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
2184         name_symbol->as_C_string());
2185     vm_exit_during_initialization("Invalid layout of preloaded class: use -Xlog:class+load=info to see the origin of the problem class");
2186   }
2187 
2188   //fetch the field at the offset we've found
2189   int dest_offset = fd.offset();
2190 
2191   return dest_offset;
2192 }
2193 
2194 
2195 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
2196   int offset = offset_for_field(field_name, object,
2197       vmSymbols::string_signature());
2198   oop string = object->obj_field(offset);
2199   if (string == NULL) {
2200     return NULL;
2201   }
2202   const char* ret = java_lang_String::as_utf8_string(string);
2203   return ret;
2204 }
2205 
2206 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
2207   int offset =
2208       offset_for_field(field_name, object, vmSymbols::bool_signature());
2209   bool ret = (object->bool_field(offset) == JNI_TRUE);
2210   return ret;
2211 }
2212 
2213 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
2214   ResourceMark rm;
2215   Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(wbclass));
2216   const char* klass_name = klass->external_name();
2217 
2218   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
2219 
2220   //  one by one registration natives for exception catching
2221   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
2222   CHECK_JNI_EXCEPTION(env);
2223   for (int i = 0, n = method_count; i < n; ++i) {
2224     // Skip dummy entries
2225     if (method_array[i].fnPtr == NULL) continue;
2226     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
2227       jthrowable throwable_obj = env->ExceptionOccurred();
2228       if (throwable_obj != NULL) {
2229         env->ExceptionClear();
2230         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
2231           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
2232           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
2233           tty->print_cr("Warning: 'NoSuchMethodError' on register of %s::%s%s",
2234               klass_name, method_array[i].name, method_array[i].signature);
2235         }
2236       } else {
2237         // Registration failed unexpectedly.
2238         tty->print_cr("Warning: unexpected error on register of %s::%s%s. All methods will be unregistered",
2239             klass_name, method_array[i].name, method_array[i].signature);
2240         env->UnregisterNatives(wbclass);
2241         break;
2242       }
2243     }
2244   }
2245 }
2246 
2247 WB_ENTRY(jint, WB_AddCompilerDirective(JNIEnv* env, jobject o, jstring compDirect))
2248   // can't be in VM when we call JNI
2249   ThreadToNativeFromVM ttnfv(thread);
2250   const char* dir = env->GetStringUTFChars(compDirect, NULL);
2251   CHECK_JNI_EXCEPTION_(env, 0);
2252   int ret;
2253   {
2254     ThreadInVMfromNative ttvfn(thread); // back to VM
2255     ret = DirectivesParser::parse_string(dir, tty);
2256   }
2257   env->ReleaseStringUTFChars(compDirect, dir);
2258   // -1 for error parsing directive. Return 0 as number of directives added.
2259   if (ret == -1) {
2260     ret = 0;
2261   }
2262   return (jint) ret;
2263 WB_END
2264 
2265 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
2266   DirectivesStack::pop(count);
2267 WB_END
2268 
2269 // Checks that the library libfile has the noexecstack bit set.
2270 WB_ENTRY(jboolean, WB_CheckLibSpecifiesNoexecstack(JNIEnv* env, jobject o, jstring libfile))
2271   jboolean ret = false;
2272 #ifdef LINUX
2273   // Can't be in VM when we call JNI.
2274   ThreadToNativeFromVM ttnfv(thread);
2275   const char* lf = env->GetStringUTFChars(libfile, NULL);
2276   CHECK_JNI_EXCEPTION_(env, 0);
2277   ret = (jboolean) ElfFile::specifies_noexecstack(lf);
2278   env->ReleaseStringUTFChars(libfile, lf);
2279 #endif
2280   return ret;
2281 WB_END
2282 
2283 WB_ENTRY(jboolean, WB_IsContainerized(JNIEnv* env, jobject o))
2284   LINUX_ONLY(return OSContainer::is_containerized();)
2285   return false;
2286 WB_END
2287 
2288 WB_ENTRY(jint, WB_ValidateCgroup(JNIEnv* env,
2289                                     jobject o,
2290                                     jstring proc_cgroups,
2291                                     jstring proc_self_cgroup,
2292                                     jstring proc_self_mountinfo))
2293   jint ret = 0;
2294 #ifdef LINUX
2295   ThreadToNativeFromVM ttnfv(thread);
2296   const char* p_cgroups = env->GetStringUTFChars(proc_cgroups, NULL);
2297   CHECK_JNI_EXCEPTION_(env, 0);
2298   const char* p_s_cgroup = env->GetStringUTFChars(proc_self_cgroup, NULL);
2299   CHECK_JNI_EXCEPTION_(env, 0);
2300   const char* p_s_mountinfo = env->GetStringUTFChars(proc_self_mountinfo, NULL);
2301   CHECK_JNI_EXCEPTION_(env, 0);
2302   u1 cg_type_flags = 0;
2303   // This sets cg_type_flags
2304   WhiteBox::validate_cgroup(p_cgroups, p_s_cgroup, p_s_mountinfo, &cg_type_flags);
2305   ret = (jint)cg_type_flags;
2306   env->ReleaseStringUTFChars(proc_cgroups, p_cgroups);
2307   env->ReleaseStringUTFChars(proc_self_cgroup, p_s_cgroup);
2308   env->ReleaseStringUTFChars(proc_self_mountinfo, p_s_mountinfo);
2309 #endif
2310   return ret;
2311 WB_END
2312 
2313 WB_ENTRY(void, WB_PrintOsInfo(JNIEnv* env, jobject o))
2314   os::print_os_info(tty);
2315 WB_END
2316 
2317 // Elf decoder
2318 WB_ENTRY(void, WB_DisableElfSectionCache(JNIEnv* env))
2319 #if !defined(_WINDOWS) && !defined(__APPLE__) && !defined(_AIX)
2320   ElfFile::_do_not_cache_elf_section = true;
2321 #endif
2322 WB_END
2323 
2324 WB_ENTRY(jlong, WB_ResolvedMethodItemsCount(JNIEnv* env, jobject o))
2325   return (jlong) ResolvedMethodTable::items_count();
2326 WB_END
2327 
2328 WB_ENTRY(jint, WB_ProtectionDomainRemovedCount(JNIEnv* env, jobject o))
2329   return (jint) SystemDictionary::pd_cache_table()->removed_entries_count();
2330 WB_END
2331 
2332 WB_ENTRY(jint, WB_GetKlassMetadataSize(JNIEnv* env, jobject wb, jclass mirror))
2333   Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(mirror));
2334   // Return size in bytes.
2335   return k->size() * wordSize;
2336 WB_END
2337 
2338 // See test/hotspot/jtreg/runtime/Thread/ThreadObjAccessAtExit.java.
2339 // It explains how the thread's priority field is used for test state coordination.
2340 //
2341 WB_ENTRY(void, WB_CheckThreadObjOfTerminatingThread(JNIEnv* env, jobject wb, jobject target_handle))
2342   oop target_oop = JNIHandles::resolve_non_null(target_handle);
2343   jlong tid = java_lang_Thread::thread_id(target_oop);
2344   JavaThread* target = java_lang_Thread::thread(target_oop);
2345 
2346   // Grab a ThreadsListHandle to protect the target thread whilst terminating
2347   ThreadsListHandle tlh;
2348 
2349   // Look up the target thread by tid to ensure it is present
2350   JavaThread* t = tlh.list()->find_JavaThread_from_java_tid(tid);
2351   if (t == NULL) {
2352     THROW_MSG(vmSymbols::java_lang_RuntimeException(), "Target thread not found in ThreadsList!");
2353   }
2354 
2355   tty->print_cr("WB_CheckThreadObjOfTerminatingThread: target thread is protected");
2356   // Allow target to terminate by boosting priority
2357   java_lang_Thread::set_priority(t->threadObj(), ThreadPriority(NormPriority + 1));
2358 
2359   // Now wait for the target to terminate
2360   while (!target->is_terminated()) {
2361     ThreadBlockInVM tbivm(thread);  // just in case target is involved in a safepoint
2362     os::naked_short_sleep(0);
2363   }
2364 
2365   tty->print_cr("WB_CheckThreadObjOfTerminatingThread: target thread is terminated");
2366 
2367   // Now release the GC inducing thread - we have to re-resolve the external oop that
2368   // was passed in as GC may have occurred and we don't know if we can trust t->threadObj() now.
2369   oop original = JNIHandles::resolve_non_null(target_handle);
2370   java_lang_Thread::set_priority(original, ThreadPriority(NormPriority + 2));
2371 
2372   tty->print_cr("WB_CheckThreadObjOfTerminatingThread: GC has been initiated - checking threadObj:");
2373 
2374   // The Java code should be creating garbage and triggering GC, which would potentially move
2375   // the threadObj oop. If the exiting thread is properly protected then its threadObj should
2376   // remain valid and equal to our initial target_handle. Loop a few times to give GC a chance to
2377   // kick in.
2378   for (int i = 0; i < 5; i++) {
2379     oop original = JNIHandles::resolve_non_null(target_handle);
2380     oop current = t->threadObj();
2381     if (original != current) {
2382       tty->print_cr("WB_CheckThreadObjOfTerminatingThread: failed comparison on iteration %d", i);
2383       THROW_MSG(vmSymbols::java_lang_RuntimeException(), "Target thread oop has changed!");
2384     } else {
2385       tty->print_cr("WB_CheckThreadObjOfTerminatingThread: successful comparison on iteration %d", i);
2386       ThreadBlockInVM tbivm(thread);
2387       os::naked_short_sleep(50);
2388     }
2389   }
2390 WB_END
2391 
2392 WB_ENTRY(void, WB_VerifyFrames(JNIEnv* env, jobject wb, jboolean log, jboolean update_map))
2393   ResourceMark rm; // for verify
2394   stringStream st;
2395   for (StackFrameStream fst(JavaThread::current(), update_map, true); !fst.is_done(); fst.next()) {
2396     frame* current_frame = fst.current();
2397     if (log) {
2398       current_frame->print_value_on(&st, NULL);
2399     }
2400     current_frame->verify(fst.register_map());
2401   }
2402   if (log) {
2403     tty->print_cr("[WhiteBox::VerifyFrames] Walking Frames");
2404     tty->print_raw(st.as_string());
2405     tty->print_cr("[WhiteBox::VerifyFrames] Done");
2406   }
2407 WB_END
2408 
2409 WB_ENTRY(jboolean, WB_IsJVMTIIncluded(JNIEnv* env, jobject wb))
2410 #if INCLUDE_JVMTI
2411   return JNI_TRUE;
2412 #else
2413   return JNI_FALSE;
2414 #endif
2415 WB_END
2416 
2417 WB_ENTRY(void, WB_WaitUnsafe(JNIEnv* env, jobject wb, jint time))
2418     os::naked_short_sleep(time);
2419 WB_END
2420 
2421 WB_ENTRY(jstring, WB_GetLibcName(JNIEnv* env, jobject o))
2422   ThreadToNativeFromVM ttn(thread);
2423   jstring info_string = env->NewStringUTF(XSTR(LIBC));
2424   CHECK_JNI_EXCEPTION_(env, NULL);
2425   return info_string;
2426 WB_END
2427 
2428 WB_ENTRY(void, WB_LockCritical(JNIEnv* env, jobject wb))
2429   GCLocker::lock_critical(thread);
2430 WB_END
2431 
2432 WB_ENTRY(void, WB_UnlockCritical(JNIEnv* env, jobject wb))
2433   GCLocker::unlock_critical(thread);
2434 WB_END
2435 
2436 #define CC (char*)
2437 
2438 static JNINativeMethod methods[] = {
2439   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
2440   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
2441   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
2442   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
2443   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
2444   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
2445   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
2446   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
2447   {CC"getHeapAlignment",                 CC"()J",                   (void*)&WB_GetHeapAlignment},
2448   {CC"countAliveClasses0",               CC"(Ljava/lang/String;)I", (void*)&WB_CountAliveClasses },
2449   {CC"getSymbolRefcount",                CC"(Ljava/lang/String;)I", (void*)&WB_GetSymbolRefcount },
2450   {CC"parseCommandLine0",
2451       CC"(Ljava/lang/String;C[Ljdk/test/whitebox/parser/DiagnosticCommand;)[Ljava/lang/Object;",
2452       (void*) &WB_ParseCommandLine
2453   },
2454   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
2455                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
2456   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
2457                                                       (void*)&WB_AddToSystemClassLoaderSearch},
2458   {CC"getCompressedOopsMaxHeapSize", CC"()J",
2459       (void*)&WB_GetCompressedOopsMaxHeapSize},
2460   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
2461   {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
2462   {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
2463 #if INCLUDE_CDS
2464   {CC"getCDSOffsetForName0", CC"(Ljava/lang/String;)I",  (void*)&WB_GetCDSOffsetForName},
2465   {CC"getCDSConstantForName0", CC"(Ljava/lang/String;)I",  (void*)&WB_GetCDSConstantForName},
2466 #endif
2467 #if INCLUDE_G1GC
2468   {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
2469   {CC"g1IsHumongous0",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
2470   {CC"g1BelongsToHumongousRegion0", CC"(J)Z",         (void*)&WB_G1BelongsToHumongousRegion},
2471   {CC"g1BelongsToFreeRegion0", CC"(J)Z",              (void*)&WB_G1BelongsToFreeRegion},
2472   {CC"g1NumMaxRegions",    CC"()J",                   (void*)&WB_G1NumMaxRegions  },
2473   {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
2474   {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
2475   {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
2476   {CC"g1HasRegionsToUncommit",  CC"()Z",              (void*)&WB_G1HasRegionsToUncommit},
2477   {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;",
2478                                                       (void*)&WB_G1AuxiliaryMemoryUsage  },
2479   {CC"g1ActiveMemoryNodeCount", CC"()I",              (void*)&WB_G1ActiveMemoryNodeCount },
2480   {CC"g1MemoryNodeIds",    CC"()[I",                  (void*)&WB_G1MemoryNodeIds },
2481   {CC"g1GetMixedGCInfo",   CC"(I)[J",                 (void*)&WB_G1GetMixedGCInfo },
2482 #endif // INCLUDE_G1GC
2483 #if INCLUDE_PARALLELGC
2484   {CC"psVirtualSpaceAlignment",CC"()J",               (void*)&WB_PSVirtualSpaceAlignment},
2485   {CC"psHeapGenerationAlignment",CC"()J",             (void*)&WB_PSHeapGenerationAlignment},
2486 #endif
2487 #if INCLUDE_NMT
2488   {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
2489   {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
2490   {CC"NMTMallocWithPseudoStackAndType", CC"(JII)J",   (void*)&WB_NMTMallocWithPseudoStackAndType},
2491   {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
2492   {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
2493   {CC"NMTAttemptReserveMemoryAt",    CC"(JJ)J",       (void*)&WB_NMTAttemptReserveMemoryAt },
2494   {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
2495   {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
2496   {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
2497   {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
2498   {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
2499   {CC"NMTNewArena",         CC"(J)J",                 (void*)&WB_NMTNewArena        },
2500   {CC"NMTFreeArena",        CC"(J)V",                 (void*)&WB_NMTFreeArena       },
2501   {CC"NMTArenaMalloc",      CC"(JJ)V",                (void*)&WB_NMTArenaMalloc     },
2502 #endif // INCLUDE_NMT
2503   {CC"deoptimizeFrames",   CC"(Z)I",                  (void*)&WB_DeoptimizeFrames  },
2504   {CC"isFrameDeoptimized", CC"(I)Z",                  (void*)&WB_IsFrameDeoptimized},
2505   {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
2506   {CC"deoptimizeMethod0",   CC"(Ljava/lang/reflect/Executable;Z)I",
2507                                                       (void*)&WB_DeoptimizeMethod  },
2508   {CC"isMethodCompiled0",   CC"(Ljava/lang/reflect/Executable;Z)Z",
2509                                                       (void*)&WB_IsMethodCompiled  },
2510   {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z",
2511                                                       (void*)&WB_IsMethodCompilable},
2512   {CC"isMethodQueuedForCompilation0",
2513       CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
2514   {CC"isIntrinsicAvailable0",
2515       CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z",
2516                                                       (void*)&WB_IsIntrinsicAvailable},
2517   {CC"makeMethodNotCompilable0",
2518       CC"(Ljava/lang/reflect/Executable;IZ)V",        (void*)&WB_MakeMethodNotCompilable},
2519   {CC"testSetDontInlineMethod0",
2520       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetDontInlineMethod},
2521   {CC"getMethodCompilationLevel0",
2522       CC"(Ljava/lang/reflect/Executable;Z)I",         (void*)&WB_GetMethodCompilationLevel},
2523   {CC"getMethodEntryBci0",
2524       CC"(Ljava/lang/reflect/Executable;)I",          (void*)&WB_GetMethodEntryBci},
2525   {CC"getCompileQueueSize",
2526       CC"(I)I",                                       (void*)&WB_GetCompileQueueSize},
2527   {CC"testSetForceInlineMethod0",
2528       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetForceInlineMethod},
2529   {CC"enqueueMethodForCompilation0",
2530       CC"(Ljava/lang/reflect/Executable;II)Z",        (void*)&WB_EnqueueMethodForCompilation},
2531   {CC"enqueueInitializerForCompilation0",
2532       CC"(Ljava/lang/Class;I)Z",                      (void*)&WB_EnqueueInitializerForCompilation},
2533   {CC"markMethodProfiled",
2534       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_MarkMethodProfiled},
2535   {CC"clearMethodState0",
2536       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_ClearMethodState},
2537   {CC"lockCompilation",    CC"()V",                   (void*)&WB_LockCompilation},
2538   {CC"unlockCompilation",  CC"()V",                   (void*)&WB_UnlockCompilation},
2539   {CC"matchesMethod",
2540       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
2541                                                       (void*)&WB_MatchesMethod},
2542   {CC"matchesInline",
2543       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
2544                                                       (void*)&WB_MatchesInline},
2545   {CC"shouldPrintAssembly",
2546         CC"(Ljava/lang/reflect/Executable;I)Z",
2547                                                         (void*)&WB_ShouldPrintAssembly},
2548 
2549   {CC"isConstantVMFlag",   CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag},
2550   {CC"isLockedVMFlag",     CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag},
2551   {CC"setBooleanVMFlag",   CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
2552   {CC"setIntVMFlag",       CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag},
2553   {CC"setUintVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag},
2554   {CC"setIntxVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
2555   {CC"setUintxVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
2556   {CC"setUint64VMFlag",    CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
2557   {CC"setSizeTVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag},
2558   {CC"setDoubleVMFlag",    CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
2559   {CC"setStringVMFlag",    CC"(Ljava/lang/String;Ljava/lang/String;)V",
2560                                                       (void*)&WB_SetStringVMFlag},
2561   {CC"getBooleanVMFlag",   CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
2562                                                       (void*)&WB_GetBooleanVMFlag},
2563   {CC"getIntVMFlag",       CC"(Ljava/lang/String;)Ljava/lang/Long;",
2564                                                       (void*)&WB_GetIntVMFlag},
2565   {CC"getUintVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
2566                                                       (void*)&WB_GetUintVMFlag},
2567   {CC"getIntxVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
2568                                                       (void*)&WB_GetIntxVMFlag},
2569   {CC"getUintxVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
2570                                                       (void*)&WB_GetUintxVMFlag},
2571   {CC"getUint64VMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Long;",
2572                                                       (void*)&WB_GetUint64VMFlag},
2573   {CC"getSizeTVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
2574                                                       (void*)&WB_GetSizeTVMFlag},
2575   {CC"getDoubleVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Double;",
2576                                                       (void*)&WB_GetDoubleVMFlag},
2577   {CC"getStringVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/String;",
2578                                                       (void*)&WB_GetStringVMFlag},
2579   {CC"isInStringTable",    CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable  },
2580   {CC"fullGC",   CC"()V",                             (void*)&WB_FullGC },
2581   {CC"youngGC",  CC"()V",                             (void*)&WB_YoungGC },
2582   {CC"readReservedMemory", CC"()V",                   (void*)&WB_ReadReservedMemory },
2583   {CC"allocateMetaspace",
2584      CC"(Ljava/lang/ClassLoader;J)J",                 (void*)&WB_AllocateMetaspace },
2585   {CC"incMetaspaceCapacityUntilGC", CC"(J)J",         (void*)&WB_IncMetaspaceCapacityUntilGC },
2586   {CC"metaspaceCapacityUntilGC", CC"()J",             (void*)&WB_MetaspaceCapacityUntilGC },
2587   {CC"metaspaceSharedRegionAlignment", CC"()J",       (void*)&WB_MetaspaceSharedRegionAlignment },
2588   {CC"getCPUFeatures",     CC"()Ljava/lang/String;",  (void*)&WB_GetCPUFeatures     },
2589   {CC"getNMethod0",         CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
2590                                                       (void*)&WB_GetNMethod         },
2591   {CC"forceNMethodSweep",  CC"()V",                   (void*)&WB_ForceNMethodSweep  },
2592   {CC"allocateCodeBlob",   CC"(II)J",                 (void*)&WB_AllocateCodeBlob   },
2593   {CC"freeCodeBlob",       CC"(J)V",                  (void*)&WB_FreeCodeBlob       },
2594   {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
2595   {CC"getCompilationActivityMode",
2596                            CC"()I",                   (void*)&WB_GetCompilationActivityMode},
2597   {CC"getMethodData0",     CC"(Ljava/lang/reflect/Executable;)J",
2598                                                       (void*)&WB_GetMethodData      },
2599   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
2600   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
2601   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
2602   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2603                                                       (void*)&WB_DefineModule },
2604   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2605                                                       (void*)&WB_AddModuleExports },
2606   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2607                                                       (void*)&WB_AddReadsModule },
2608   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2609                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2610   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2611                                                       (void*)&WB_AddModuleExportsToAll },
2612   {CC"deflateIdleMonitors", CC"()Z",                  (void*)&WB_DeflateIdleMonitors },
2613   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2614   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2615   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2616   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2617   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2618   {CC"remapInstructionOperandFromCPCache0",
2619       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2620   {CC"encodeConstantPoolIndyIndex0",
2621       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2622   {CC"getMethodBooleanOption",
2623       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2624                                                       (void*)&WB_GetMethodBooleaneOption},
2625   {CC"getMethodIntxOption",
2626       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2627                                                       (void*)&WB_GetMethodIntxOption},
2628   {CC"getMethodUintxOption",
2629       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2630                                                       (void*)&WB_GetMethodUintxOption},
2631   {CC"getMethodDoubleOption",
2632       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2633                                                       (void*)&WB_GetMethodDoubleOption},
2634   {CC"getMethodStringOption",
2635       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2636                                                       (void*)&WB_GetMethodStringOption},
2637   {CC"getDefaultArchivePath",             CC"()Ljava/lang/String;",
2638                                                       (void*)&WB_GetDefaultArchivePath},
2639   {CC"isSharingEnabled",   CC"()Z",                   (void*)&WB_IsSharingEnabled},
2640   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2641   {CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString },
2642   {CC"isSharedClass",      CC"(Ljava/lang/Class;)Z",  (void*)&WB_IsSharedClass },
2643   {CC"areSharedStringsMapped",            CC"()Z",    (void*)&WB_AreSharedStringsMapped },
2644   {CC"getResolvedReferences", CC"(Ljava/lang/Class;)Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2645   {CC"linkClass",          CC"(Ljava/lang/Class;)V",  (void*)&WB_LinkClass},
2646   {CC"areOpenArchiveHeapObjectsMapped",   CC"()Z",    (void*)&WB_AreOpenArchiveHeapObjectsMapped},
2647   {CC"isCDSIncluded",                     CC"()Z",    (void*)&WB_IsCDSIncluded },
2648   {CC"isJFRIncluded",                     CC"()Z",    (void*)&WB_IsJFRIncluded },
2649   {CC"isC2OrJVMCIIncluded",               CC"()Z",    (void*)&WB_isC2OrJVMCIIncluded },
2650   {CC"isJVMCISupportedByGC",              CC"()Z",    (void*)&WB_IsJVMCISupportedByGC},
2651   {CC"canWriteJavaHeapArchive",           CC"()Z",    (void*)&WB_CanWriteJavaHeapArchive },
2652   {CC"cdsMemoryMappingFailed",            CC"()Z",    (void*)&WB_CDSMemoryMappingFailed },
2653 
2654   {CC"clearInlineCaches0",  CC"(Z)V",                 (void*)&WB_ClearInlineCaches },
2655   {CC"handshakeReadMonitors", CC"(Ljava/lang/Thread;)Z", (void*)&WB_HandshakeReadMonitors },
2656   {CC"handshakeWalkStack", CC"(Ljava/lang/Thread;Z)I", (void*)&WB_HandshakeWalkStack },
2657   {CC"asyncHandshakeWalkStack", CC"(Ljava/lang/Thread;)V", (void*)&WB_AsyncHandshakeWalkStack },
2658   {CC"lockAndBlock", CC"(Z)V",                        (void*)&WB_LockAndBlock},
2659   {CC"checkThreadObjOfTerminatingThread", CC"(Ljava/lang/Thread;)V", (void*)&WB_CheckThreadObjOfTerminatingThread },
2660   {CC"verifyFrames",                CC"(ZZ)V",            (void*)&WB_VerifyFrames },
2661   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)I",
2662                                                       (void*)&WB_AddCompilerDirective },
2663   {CC"removeCompilerDirective",   CC"(I)V",           (void*)&WB_RemoveCompilerDirective },
2664   {CC"isGCSupported",             CC"(I)Z",           (void*)&WB_IsGCSupported},
2665   {CC"isGCSupportedByJVMCICompiler", CC"(I)Z",        (void*)&WB_IsGCSupportedByJVMCICompiler},
2666   {CC"isGCSelected",              CC"(I)Z",           (void*)&WB_IsGCSelected},
2667   {CC"isGCSelectedErgonomically", CC"()Z",            (void*)&WB_IsGCSelectedErgonomically},
2668   {CC"supportsConcurrentGCBreakpoints", CC"()Z",      (void*)&WB_SupportsConcurrentGCBreakpoints},
2669   {CC"concurrentGCAcquireControl0", CC"()V",          (void*)&WB_ConcurrentGCAcquireControl},
2670   {CC"concurrentGCReleaseControl0", CC"()V",          (void*)&WB_ConcurrentGCReleaseControl},
2671   {CC"concurrentGCRunToIdle0",    CC"()V",            (void*)&WB_ConcurrentGCRunToIdle},
2672   {CC"concurrentGCRunTo0",        CC"(Ljava/lang/String;)Z",
2673                                                       (void*)&WB_ConcurrentGCRunTo},
2674   {CC"checkLibSpecifiesNoexecstack", CC"(Ljava/lang/String;)Z",
2675                                                       (void*)&WB_CheckLibSpecifiesNoexecstack},
2676   {CC"isContainerized",           CC"()Z",            (void*)&WB_IsContainerized },
2677   {CC"validateCgroup",
2678       CC"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I",
2679                                                       (void*)&WB_ValidateCgroup },
2680   {CC"printOsInfo",               CC"()V",            (void*)&WB_PrintOsInfo },
2681   {CC"disableElfSectionCache",    CC"()V",            (void*)&WB_DisableElfSectionCache },
2682   {CC"resolvedMethodItemsCount",  CC"()J",            (void*)&WB_ResolvedMethodItemsCount },
2683   {CC"protectionDomainRemovedCount",   CC"()I",       (void*)&WB_ProtectionDomainRemovedCount },
2684   {CC"getKlassMetadataSize", CC"(Ljava/lang/Class;)I",(void*)&WB_GetKlassMetadataSize},
2685 
2686   {CC"createMetaspaceTestContext", CC"(JJ)J",         (void*)&WB_CreateMetaspaceTestContext},
2687   {CC"destroyMetaspaceTestContext", CC"(J)V",         (void*)&WB_DestroyMetaspaceTestContext},
2688   {CC"purgeMetaspaceTestContext", CC"(J)V",           (void*)&WB_PurgeMetaspaceTestContext},
2689   {CC"printMetaspaceTestContext", CC"(J)V",           (void*)&WB_PrintMetaspaceTestContext},
2690   {CC"getTotalCommittedWordsInMetaspaceTestContext", CC"(J)J",(void*)&WB_GetTotalCommittedWordsInMetaspaceTestContext},
2691   {CC"getTotalUsedWordsInMetaspaceTestContext", CC"(J)J", (void*)&WB_GetTotalUsedWordsInMetaspaceTestContext},
2692   {CC"createArenaInTestContext", CC"(JZ)J",           (void*)&WB_CreateArenaInTestContext},
2693   {CC"destroyMetaspaceTestArena", CC"(J)V",           (void*)&WB_DestroyMetaspaceTestArena},
2694   {CC"allocateFromMetaspaceTestArena", CC"(JJ)J",     (void*)&WB_AllocateFromMetaspaceTestArena},
2695   {CC"deallocateToMetaspaceTestArena", CC"(JJJ)V",    (void*)&WB_DeallocateToMetaspaceTestArena},
2696   {CC"maxMetaspaceAllocationSize", CC"()J",           (void*)&WB_GetMaxMetaspaceAllocationSize},
2697 
2698   {CC"isJVMTIIncluded", CC"()Z",                      (void*)&WB_IsJVMTIIncluded},
2699   {CC"waitUnsafe", CC"(I)V",                          (void*)&WB_WaitUnsafe},
2700   {CC"getLibcName",     CC"()Ljava/lang/String;",     (void*)&WB_GetLibcName},
2701 
2702   {CC"lockCritical",    CC"()V",                      (void*)&WB_LockCritical},
2703   {CC"unlockCritical",  CC"()V",                      (void*)&WB_UnlockCritical},
2704 };
2705 
2706 
2707 #undef CC
2708 
2709 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
2710   {
2711     if (WhiteBoxAPI) {
2712       // Make sure that wbclass is loaded by the null classloader
2713       InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(wbclass)));
2714       Handle loader(THREAD, ik->class_loader());
2715       if (loader.is_null()) {
2716         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
2717         WhiteBox::set_used();
2718       }
2719     }
2720   }
2721 JVM_END