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