1 /*
   2  * Copyright (c) 2012, 2018, 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 
  27 #include <new>
  28 
  29 #include "classfile/classLoaderData.hpp"
  30 #include "classfile/modules.hpp"
  31 #include "classfile/protectionDomainCache.hpp"
  32 #include "classfile/stringTable.hpp"
  33 #include "code/codeCache.hpp"
  34 #include "compiler/methodMatcher.hpp"
  35 #include "compiler/directivesParser.hpp"
  36 #include "gc/shared/gcConfig.hpp"
  37 #include "gc/shared/genCollectedHeap.hpp"
  38 #include "jvmtifiles/jvmtiEnv.hpp"
  39 #include "memory/metadataFactory.hpp"
  40 #include "memory/metaspaceShared.hpp"
  41 #include "memory/iterator.hpp"
  42 #include "memory/resourceArea.hpp"
  43 #include "memory/universe.hpp"
  44 #include "memory/oopFactory.hpp"
  45 #include "oops/array.hpp"
  46 #include "oops/compressedOops.inline.hpp"
  47 #include "oops/constantPool.inline.hpp"
  48 #include "oops/method.inline.hpp"
  49 #include "oops/objArrayKlass.hpp"
  50 #include "oops/objArrayOop.inline.hpp"
  51 #include "oops/oop.inline.hpp"
  52 #include "oops/objArrayOop.inline.hpp"
  53 #include "oops/typeArrayOop.inline.hpp"
  54 #include "prims/resolvedMethodTable.hpp"
  55 #include "prims/wbtestmethods/parserTests.hpp"
  56 #include "prims/whitebox.inline.hpp"
  57 #include "runtime/arguments.hpp"
  58 #include "runtime/compilationPolicy.hpp"
  59 #include "runtime/deoptimization.hpp"
  60 #include "runtime/fieldDescriptor.inline.hpp"
  61 #include "runtime/flags/jvmFlag.hpp"
  62 #include "runtime/frame.inline.hpp"
  63 #include "runtime/handshake.hpp"
  64 #include "runtime/interfaceSupport.inline.hpp"
  65 #include "runtime/javaCalls.hpp"
  66 #include "runtime/jniHandles.inline.hpp"
  67 #include "runtime/os.hpp"
  68 #include "runtime/sweeper.hpp"
  69 #include "runtime/thread.hpp"
  70 #include "runtime/threadSMR.hpp"
  71 #include "runtime/vm_version.hpp"
  72 #include "services/memoryService.hpp"
  73 #include "utilities/align.hpp"
  74 #include "utilities/debug.hpp"
  75 #include "utilities/elfFile.hpp"
  76 #include "utilities/exceptions.hpp"
  77 #include "utilities/macros.hpp"
  78 #if INCLUDE_CDS
  79 #include "prims/cdsoffsets.hpp"
  80 #endif // INCLUDE_CDS
  81 #if INCLUDE_G1GC
  82 #include "gc/g1/g1CollectedHeap.inline.hpp"
  83 #include "gc/g1/g1ConcurrentMark.hpp"
  84 #include "gc/g1/g1ConcurrentMarkThread.hpp"
  85 #include "gc/g1/heapRegionRemSet.hpp"
  86 #endif // INCLUDE_G1GC
  87 #if INCLUDE_PARALLELGC
  88 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
  89 #include "gc/parallel/adjoiningGenerations.hpp"
  90 #endif // INCLUDE_PARALLELGC
  91 #if INCLUDE_NMT
  92 #include "services/mallocSiteTable.hpp"
  93 #include "services/memTracker.hpp"
  94 #include "utilities/nativeCallStack.hpp"
  95 #endif // INCLUDE_NMT
  96 
  97 #ifdef LINUX
  98 #include "osContainer_linux.hpp"
  99 #endif
 100 
 101 #define SIZE_T_MAX_VALUE ((size_t) -1)
 102 
 103 #define CHECK_JNI_EXCEPTION_(env, value)                               \
 104   do {                                                                 \
 105     JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \
 106     THREAD->clear_pending_jni_exception_check();                       \
 107     if (HAS_PENDING_EXCEPTION) {                                       \
 108       return(value);                                                   \
 109     }                                                                  \
 110   } while (0)
 111 
 112 #define CHECK_JNI_EXCEPTION(env)                                       \
 113   do {                                                                 \
 114     JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \
 115     THREAD->clear_pending_jni_exception_check();                       \
 116     if (HAS_PENDING_EXCEPTION) {                                       \
 117       return;                                                          \
 118     }                                                                  \
 119   } while (0)
 120 
 121 bool WhiteBox::_used = false;
 122 volatile bool WhiteBox::compilation_locked = false;
 123 
 124 class VM_WhiteBoxOperation : public VM_Operation {
 125  public:
 126   VM_WhiteBoxOperation()                         { }
 127   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
 128   bool allow_nested_vm_operations() const        { return true; }
 129 };
 130 
 131 
 132 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
 133   return (jlong)(void*)JNIHandles::resolve(obj);
 134 WB_END
 135 
 136 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
 137   return heapOopSize;
 138 WB_END
 139 
 140 WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o))
 141   return os::vm_page_size();
 142 WB_END
 143 
 144 WB_ENTRY(jlong, WB_GetVMAllocationGranularity(JNIEnv* env, jobject o))
 145   return os::vm_allocation_granularity();
 146 WB_END
 147 
 148 WB_ENTRY(jlong, WB_GetVMLargePageSize(JNIEnv* env, jobject o))
 149   return os::large_page_size();
 150 WB_END
 151 
 152 class WBIsKlassAliveClosure : public LockedClassesDo {
 153     Symbol* _name;
 154     bool _found;
 155 public:
 156     WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {}
 157 
 158     void do_klass(Klass* k) {
 159       if (_found) return;
 160       Symbol* ksym = k->name();
 161       if (ksym->fast_compare(_name) == 0) {
 162         _found = true;
 163       }
 164     }
 165 
 166     bool found() const {
 167         return _found;
 168     }
 169 };
 170 
 171 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
 172   oop h_name = JNIHandles::resolve(name);
 173   if (h_name == NULL) return false;
 174   Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
 175   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 176 
 177   WBIsKlassAliveClosure closure(sym);
 178   ClassLoaderDataGraph::classes_do(&closure);
 179 
 180   return closure.found();
 181 WB_END
 182 
 183 WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 184 #if INCLUDE_JVMTI
 185   ResourceMark rm;
 186   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 187   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 188   jvmtiError err = jvmti_env->AddToBootstrapClassLoaderSearch(seg);
 189   assert(err == JVMTI_ERROR_NONE, "must not fail");
 190 #endif
 191 }
 192 WB_END
 193 
 194 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 195 #if INCLUDE_JVMTI
 196   ResourceMark rm;
 197   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 198   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 199   jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg);
 200   assert(err == JVMTI_ERROR_NONE, "must not fail");
 201 #endif
 202 }
 203 WB_END
 204 
 205 
 206 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
 207   return (jlong)Arguments::max_heap_for_compressed_oops();
 208 }
 209 WB_END
 210 
 211 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
 212   CollectorPolicy * p = Universe::heap()->collector_policy();
 213   tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap "
 214     SIZE_FORMAT " Maximum heap " SIZE_FORMAT " Space alignment " SIZE_FORMAT " Heap alignment " SIZE_FORMAT,
 215     p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(),
 216     p->space_alignment(), p->heap_alignment());
 217 }
 218 WB_END
 219 
 220 #ifndef PRODUCT
 221 // Forward declaration
 222 void TestReservedSpace_test();
 223 void TestReserveMemorySpecial_test();
 224 void TestVirtualSpace_test();
 225 void TestMetaspaceUtils_test();
 226 #endif
 227 
 228 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
 229 #ifndef PRODUCT
 230   TestReservedSpace_test();
 231   TestReserveMemorySpecial_test();
 232   TestVirtualSpace_test();
 233   TestMetaspaceUtils_test();
 234 #endif
 235 WB_END
 236 
 237 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
 238   size_t granularity = os::vm_allocation_granularity();
 239   ReservedHeapSpace rhs(100 * granularity, granularity, false);
 240   VirtualSpace vs;
 241   vs.initialize(rhs, 50 * granularity);
 242 
 243   // Check if constraints are complied
 244   if (!( UseCompressedOops && rhs.base() != NULL &&
 245          Universe::narrow_oop_base() != NULL &&
 246          Universe::narrow_oop_use_implicit_null_checks() )) {
 247     tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
 248                   "\tUseCompressedOops is %d\n"
 249                   "\trhs.base() is " PTR_FORMAT "\n"
 250                   "\tUniverse::narrow_oop_base() is " PTR_FORMAT "\n"
 251                   "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
 252                   UseCompressedOops,
 253                   p2i(rhs.base()),
 254                   p2i(Universe::narrow_oop_base()),
 255                   Universe::narrow_oop_use_implicit_null_checks());
 256     return;
 257   }
 258   tty->print_cr("Reading from no access area... ");
 259   tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
 260                 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
 261 WB_END
 262 
 263 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
 264                                            size_t magnitude, size_t iterations) {
 265   size_t granularity = os::vm_allocation_granularity();
 266   ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false);
 267   VirtualSpace vs;
 268   if (!vs.initialize(rhs, 0)) {
 269     tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
 270     return 3;
 271   }
 272 
 273   int seed = os::random();
 274   tty->print_cr("Random seed is %d", seed);
 275   os::init_random(seed);
 276 
 277   for (size_t i = 0; i < iterations; i++) {
 278 
 279     // Whether we will shrink or grow
 280     bool shrink = os::random() % 2L == 0;
 281 
 282     // Get random delta to resize virtual space
 283     size_t delta = (size_t)os::random() % magnitude;
 284 
 285     // If we are about to shrink virtual space below zero, then expand instead
 286     if (shrink && vs.committed_size() < delta) {
 287       shrink = false;
 288     }
 289 
 290     // Resizing by delta
 291     if (shrink) {
 292       vs.shrink_by(delta);
 293     } else {
 294       // If expanding fails expand_by will silently return false
 295       vs.expand_by(delta, true);
 296     }
 297   }
 298   return 0;
 299 }
 300 
 301 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
 302         jlong reserved_space_size, jlong magnitude, jlong iterations))
 303   tty->print_cr("reservedSpaceSize=" JLONG_FORMAT ", magnitude=" JLONG_FORMAT ", "
 304                 "iterations=" JLONG_FORMAT "\n", reserved_space_size, magnitude,
 305                 iterations);
 306   if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
 307     tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
 308     return 1;
 309   }
 310 
 311   // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
 312   // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
 313   if (sizeof(size_t) < sizeof(jlong)) {
 314     jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
 315     if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
 316         || iterations > size_t_max_value) {
 317       tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
 318       return 2;
 319     }
 320   }
 321 
 322   return wb_stress_virtual_space_resize((size_t) reserved_space_size,
 323                                         (size_t) magnitude, (size_t) iterations);
 324 WB_END
 325 
 326 WB_ENTRY(jboolean, WB_IsGCSupported(JNIEnv* env, jobject o, jint name))
 327   return GCConfig::is_gc_supported((CollectedHeap::Name)name);
 328 WB_END
 329 
 330 WB_ENTRY(jboolean, WB_IsGCSelected(JNIEnv* env, jobject o, jint name))
 331   return GCConfig::is_gc_selected((CollectedHeap::Name)name);
 332 WB_END
 333 
 334 WB_ENTRY(jboolean, WB_IsGCSelectedErgonomically(JNIEnv* env, jobject o))
 335   return GCConfig::is_gc_selected_ergonomically();
 336 WB_END
 337 
 338 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj))
 339   oop p = JNIHandles::resolve(obj);
 340 #if INCLUDE_G1GC
 341   if (UseG1GC) {
 342     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 343     const HeapRegion* hr = g1h->heap_region_containing(p);
 344     if (hr == NULL) {
 345       return false;
 346     }
 347     return !(hr->is_young());
 348   }
 349 #endif
 350 #if INCLUDE_PARALLELGC
 351   if (UseParallelGC) {
 352     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 353     return !psh->is_in_young(p);
 354   }
 355 #endif
 356 #if INCLUDE_ZGC
 357   if (UseZGC) {
 358     return Universe::heap()->is_in(p);
 359   }
 360 #endif
 361   GenCollectedHeap* gch = GenCollectedHeap::heap();
 362   return !gch->is_in_young(p);
 363 WB_END
 364 
 365 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
 366   oop p = JNIHandles::resolve(obj);
 367   return p->size() * HeapWordSize;
 368 WB_END
 369 
 370 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))
 371   size_t alignment = Universe::heap()->collector_policy()->space_alignment();
 372   return (jlong)alignment;
 373 WB_END
 374 
 375 WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o))
 376   size_t alignment = Universe::heap()->collector_policy()->heap_alignment();
 377   return (jlong)alignment;
 378 WB_END
 379 
 380 WB_ENTRY(jboolean, WB_SupportsConcurrentGCPhaseControl(JNIEnv* env, jobject o))
 381   return Universe::heap()->supports_concurrent_phase_control();
 382 WB_END
 383 
 384 WB_ENTRY(jobjectArray, WB_GetConcurrentGCPhases(JNIEnv* env, jobject o))
 385   const char* const* phases = Universe::heap()->concurrent_phases();
 386   jint nphases = 0;
 387   for ( ; phases[nphases] != NULL; ++nphases) ;
 388 
 389   ResourceMark rm(thread);
 390   ThreadToNativeFromVM ttn(thread);
 391   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
 392   CHECK_JNI_EXCEPTION_(env, NULL);
 393 
 394   jobjectArray result = env->NewObjectArray(nphases, clazz, NULL);
 395   CHECK_JNI_EXCEPTION_(env, NULL);
 396 
 397   // If push fails, return with pending exception.
 398   if (env->PushLocalFrame(nphases) < 0) return NULL;
 399   for (jint i = 0; i < nphases; ++i) {
 400     jstring phase = env->NewStringUTF(phases[i]);
 401     CHECK_JNI_EXCEPTION_(env, NULL);
 402     env->SetObjectArrayElement(result, i, phase);
 403     CHECK_JNI_EXCEPTION_(env, NULL);
 404   }
 405   env->PopLocalFrame(NULL);
 406 
 407   return result;
 408 WB_END
 409 
 410 WB_ENTRY(jboolean, WB_RequestConcurrentGCPhase(JNIEnv* env, jobject o, jstring name))
 411   Handle h_name(THREAD, JNIHandles::resolve(name));
 412   ResourceMark rm;
 413   const char* c_name = java_lang_String::as_utf8_string(h_name());
 414   return Universe::heap()->request_concurrent_phase(c_name);
 415 WB_END
 416 
 417 #if INCLUDE_G1GC
 418 
 419 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
 420   if (UseG1GC) {
 421     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 422     oop result = JNIHandles::resolve(obj);
 423     const HeapRegion* hr = g1h->heap_region_containing(result);
 424     return hr->is_humongous();
 425   }
 426   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1IsHumongous: G1 GC is not enabled");
 427 WB_END
 428 
 429 WB_ENTRY(jboolean, WB_G1BelongsToHumongousRegion(JNIEnv* env, jobject o, jlong addr))
 430   if (UseG1GC) {
 431     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 432     const HeapRegion* hr = g1h->heap_region_containing((void*) addr);
 433     return hr->is_humongous();
 434   }
 435   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToHumongousRegion: G1 GC is not enabled");
 436 WB_END
 437 
 438 WB_ENTRY(jboolean, WB_G1BelongsToFreeRegion(JNIEnv* env, jobject o, jlong addr))
 439   if (UseG1GC) {
 440     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 441     const HeapRegion* hr = g1h->heap_region_containing((void*) addr);
 442     return hr->is_free();
 443   }
 444   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToFreeRegion: G1 GC is not enabled");
 445 WB_END
 446 
 447 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o))
 448   if (UseG1GC) {
 449     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 450     size_t nr = g1h->max_regions();
 451     return (jlong)nr;
 452   }
 453   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumMaxRegions: G1 GC is not enabled");
 454 WB_END
 455 
 456 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
 457   if (UseG1GC) {
 458     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 459     size_t nr = g1h->num_free_regions();
 460     return (jlong)nr;
 461   }
 462   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumFreeRegions: G1 GC is not enabled");
 463 WB_END
 464 
 465 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
 466   if (UseG1GC) {
 467     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 468     return g1h->concurrent_mark()->cm_thread()->during_cycle();
 469   }
 470   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1InConcurrentMark: G1 GC is not enabled");
 471 WB_END
 472 
 473 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
 474   if (UseG1GC) {
 475     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 476     if (!g1h->concurrent_mark()->cm_thread()->during_cycle()) {
 477       g1h->collect(GCCause::_wb_conc_mark);
 478       return true;
 479     }
 480     return false;
 481   }
 482   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1StartMarkCycle: G1 GC is not enabled");
 483 WB_END
 484 
 485 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
 486   if (UseG1GC) {
 487     return (jint)HeapRegion::GrainBytes;
 488   }
 489   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1RegionSize: G1 GC is not enabled");
 490 WB_END
 491 
 492 #endif // INCLUDE_G1GC
 493 
 494 #if INCLUDE_PARALLELGC
 495 
 496 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o))
 497   if (UseParallelGC) {
 498     return ParallelScavengeHeap::heap()->gens()->virtual_spaces()->alignment();
 499   }
 500   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSVirtualSpaceAlignment: Parallel GC is not enabled");
 501 WB_END
 502 
 503 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o))
 504   if (UseParallelGC) {
 505     return ParallelScavengeHeap::heap()->generation_alignment();
 506   }
 507   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSHeapGenerationAlignment: Parallel GC is not enabled");
 508 WB_END
 509 
 510 #endif // INCLUDE_PARALLELGC
 511 
 512 #if INCLUDE_G1GC
 513 
 514 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env))
 515   if (UseG1GC) {
 516     ResourceMark rm(THREAD);
 517     G1CollectedHeap* g1h = G1CollectedHeap::heap();
 518     MemoryUsage usage = g1h->get_auxiliary_data_memory_usage();
 519     Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
 520     return JNIHandles::make_local(env, h());
 521   }
 522   THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1AuxiliaryMemoryUsage: G1 GC is not enabled");
 523 WB_END
 524 
 525 class OldRegionsLivenessClosure: public HeapRegionClosure {
 526 
 527  private:
 528   const int _liveness;
 529   size_t _total_count;
 530   size_t _total_memory;
 531   size_t _total_memory_to_free;
 532 
 533  public:
 534   OldRegionsLivenessClosure(int liveness) :
 535     _liveness(liveness),
 536     _total_count(0),
 537     _total_memory(0),
 538     _total_memory_to_free(0) { }
 539 
 540     size_t total_count() { return _total_count; }
 541     size_t total_memory() { return _total_memory; }
 542     size_t total_memory_to_free() { return _total_memory_to_free; }
 543 
 544   bool do_heap_region(HeapRegion* r) {
 545     if (r->is_old()) {
 546       size_t prev_live = r->marked_bytes();
 547       size_t live = r->live_bytes();
 548       size_t size = r->used();
 549       size_t reg_size = HeapRegion::GrainBytes;
 550       if (size > 0 && ((int)(live * 100 / size) < _liveness)) {
 551         _total_memory += size;
 552         ++_total_count;
 553         if (size == reg_size) {
 554         // we don't include non-full regions since they are unlikely included in mixed gc
 555         // for testing purposes it's enough to have lowest estimation of total memory that is expected to be freed
 556           _total_memory_to_free += size - prev_live;
 557         }
 558       }
 559     }
 560     return false;
 561   }
 562 };
 563 
 564 
 565 WB_ENTRY(jlongArray, WB_G1GetMixedGCInfo(JNIEnv* env, jobject o, jint liveness))
 566   if (!UseG1GC) {
 567     THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1GetMixedGCInfo: G1 GC is not enabled");
 568   }
 569   if (liveness < 0) {
 570     THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "liveness value should be non-negative");
 571   }
 572 
 573   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 574   OldRegionsLivenessClosure rli(liveness);
 575   g1h->heap_region_iterate(&rli);
 576 
 577   typeArrayOop result = oopFactory::new_longArray(3, CHECK_NULL);
 578   result->long_at_put(0, rli.total_count());
 579   result->long_at_put(1, rli.total_memory());
 580   result->long_at_put(2, rli.total_memory_to_free());
 581   return (jlongArray) JNIHandles::make_local(env, result);
 582 WB_END
 583 
 584 #endif // INCLUDE_G1GC
 585 
 586 #if INCLUDE_NMT
 587 // Alloc memory using the test memory type so that we can use that to see if
 588 // NMT picks it up correctly
 589 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
 590   jlong addr = 0;
 591   addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
 592   return addr;
 593 WB_END
 594 
 595 // Alloc memory with pseudo call stack. The test can create psudo malloc
 596 // allocation site to stress the malloc tracking.
 597 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
 598   address pc = (address)(size_t)pseudo_stack;
 599   NativeCallStack stack(&pc, 1);
 600   return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
 601 WB_END
 602 
 603 // Free the memory allocated by NMTAllocTest
 604 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
 605   os::free((void*)(uintptr_t)mem);
 606 WB_END
 607 
 608 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
 609   jlong addr = 0;
 610 
 611   addr = (jlong)(uintptr_t)os::reserve_memory(size);
 612   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 613 
 614   return addr;
 615 WB_END
 616 
 617 WB_ENTRY(jlong, WB_NMTAttemptReserveMemoryAt(JNIEnv* env, jobject o, jlong addr, jlong size))
 618   addr = (jlong)(uintptr_t)os::attempt_reserve_memory_at((size_t)size, (char*)(uintptr_t)addr);
 619   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 620 
 621   return addr;
 622 WB_END
 623 
 624 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 625   os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
 626   MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
 627 WB_END
 628 
 629 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 630   os::uncommit_memory((char *)(uintptr_t)addr, size);
 631 WB_END
 632 
 633 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 634   os::release_memory((char *)(uintptr_t)addr, size);
 635 WB_END
 636 
 637 WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
 638   // Test that we can downgrade NMT levels but not upgrade them.
 639   if (MemTracker::tracking_level() == NMT_off) {
 640     MemTracker::transition_to(NMT_off);
 641     return MemTracker::tracking_level() == NMT_off;
 642   } else {
 643     assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
 644     MemTracker::transition_to(NMT_summary);
 645     assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
 646 
 647     // Can't go to detail once NMT is set to summary.
 648     MemTracker::transition_to(NMT_detail);
 649     assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now");
 650 
 651     // Shutdown sets tracking level to minimal.
 652     MemTracker::shutdown();
 653     assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now");
 654 
 655     // Once the tracking level is minimal, we cannot increase to summary.
 656     // The code ignores this request instead of asserting because if the malloc site
 657     // table overflows in another thread, it tries to change the code to summary.
 658     MemTracker::transition_to(NMT_summary);
 659     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 660 
 661     // Really can never go up to detail, verify that the code would never do this.
 662     MemTracker::transition_to(NMT_detail);
 663     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 664     return MemTracker::tracking_level() == NMT_minimal;
 665   }
 666 WB_END
 667 
 668 WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
 669   int hash_size = MallocSiteTable::hash_buckets();
 670   assert(hash_size > 0, "NMT hash_size should be > 0");
 671   return (jint)hash_size;
 672 WB_END
 673 #endif // INCLUDE_NMT
 674 
 675 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
 676   assert(method != NULL, "method should not be null");
 677   ThreadToNativeFromVM ttn(thread);
 678   return env->FromReflectedMethod(method);
 679 }
 680 
 681 // Deoptimizes all compiled frames and makes nmethods not entrant if it's requested
 682 class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation {
 683  private:
 684   int _result;
 685   const bool _make_not_entrant;
 686  public:
 687   VM_WhiteBoxDeoptimizeFrames(bool make_not_entrant) :
 688         _result(0), _make_not_entrant(make_not_entrant) { }
 689   int  result() const { return _result; }
 690 
 691   void doit() {
 692     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) {
 693       if (t->has_last_Java_frame()) {
 694         for (StackFrameStream fst(t, UseBiasedLocking); !fst.is_done(); fst.next()) {
 695           frame* f = fst.current();
 696           if (f->can_be_deoptimized() && !f->is_deoptimized_frame()) {
 697             RegisterMap* reg_map = fst.register_map();
 698             Deoptimization::deoptimize(t, *f, reg_map);
 699             if (_make_not_entrant) {
 700                 CompiledMethod* cm = CodeCache::find_compiled(f->pc());
 701                 assert(cm != NULL, "sanity check");
 702                 cm->make_not_entrant();
 703             }
 704             ++_result;
 705           }
 706         }
 707       }
 708     }
 709   }
 710 };
 711 
 712 WB_ENTRY(jint, WB_DeoptimizeFrames(JNIEnv* env, jobject o, jboolean make_not_entrant))
 713   VM_WhiteBoxDeoptimizeFrames op(make_not_entrant == JNI_TRUE);
 714   VMThread::execute(&op);
 715   return op.result();
 716 WB_END
 717 
 718 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
 719   MutexLockerEx mu(Compile_lock);
 720   CodeCache::mark_all_nmethods_for_deoptimization();
 721   VM_Deoptimize op;
 722   VMThread::execute(&op);
 723 WB_END
 724 
 725 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 726   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 727   int result = 0;
 728   CHECK_JNI_EXCEPTION_(env, result);
 729   MutexLockerEx mu(Compile_lock);
 730   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 731   if (is_osr) {
 732     result += mh->mark_osr_nmethods();
 733   } else if (mh->code() != NULL) {
 734     mh->code()->mark_for_deoptimization();
 735     ++result;
 736   }
 737   result += CodeCache::mark_for_deoptimization(mh());
 738   if (result > 0) {
 739     VM_Deoptimize op;
 740     VMThread::execute(&op);
 741   }
 742   return result;
 743 WB_END
 744 
 745 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 746   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 747   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 748   MutexLockerEx mu(Compile_lock);
 749   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 750   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 751   if (code == NULL) {
 752     return JNI_FALSE;
 753   }
 754   return (code->is_alive() && !code->is_marked_for_deoptimization());
 755 WB_END
 756 
 757 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 758   if (method == NULL || comp_level > MIN2((CompLevel) TieredStopAtLevel, CompLevel_highest_tier)) {
 759     return false;
 760   }
 761   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 762   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 763   MutexLockerEx mu(Compile_lock);
 764   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 765   if (is_osr) {
 766     return CompilationPolicy::can_be_osr_compiled(mh, comp_level);
 767   } else {
 768     return CompilationPolicy::can_be_compiled(mh, comp_level);
 769   }
 770 WB_END
 771 
 772 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method))
 773   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 774   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 775   MutexLockerEx mu(Compile_lock);
 776   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 777   return mh->queued_for_compilation();
 778 WB_END
 779 
 780 WB_ENTRY(jboolean, WB_IsIntrinsicAvailable(JNIEnv* env, jobject o, jobject method, jobject compilation_context, jint compLevel))
 781   if (compLevel < CompLevel_none || compLevel > MIN2((CompLevel) TieredStopAtLevel, CompLevel_highest_tier)) {
 782     return false; // Intrinsic is not available on a non-existent compilation level.
 783   }
 784   jmethodID method_id, compilation_context_id;
 785   method_id = reflected_method_to_jmid(thread, env, method);
 786   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 787   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(method_id));
 788 
 789   DirectiveSet* directive;
 790   AbstractCompiler* comp = CompileBroker::compiler((int)compLevel);
 791   assert(comp != NULL, "compiler not available");
 792   if (compilation_context != NULL) {
 793     compilation_context_id = reflected_method_to_jmid(thread, env, compilation_context);
 794     CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 795     methodHandle cch(THREAD, Method::checked_resolve_jmethod_id(compilation_context_id));
 796     directive = DirectivesStack::getMatchingDirective(cch, comp);
 797   } else {
 798     // Calling with NULL matches default directive
 799     directive = DirectivesStack::getDefaultDirective(comp);
 800   }
 801   bool result = comp->is_intrinsic_available(mh, directive);
 802   DirectivesStack::release(directive);
 803   return result;
 804 WB_END
 805 
 806 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 807   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 808   CHECK_JNI_EXCEPTION_(env, CompLevel_none);
 809   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 810   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 811   return (code != NULL ? code->comp_level() : CompLevel_none);
 812 WB_END
 813 
 814 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 815   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 816   CHECK_JNI_EXCEPTION(env);
 817   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 818   if (is_osr) {
 819     mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox");
 820   } else {
 821     mh->set_not_compilable(comp_level, true /* report */, "WhiteBox");
 822   }
 823 WB_END
 824 
 825 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
 826   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 827   CHECK_JNI_EXCEPTION_(env, InvocationEntryBci);
 828   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 829   CompiledMethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
 830   return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
 831 WB_END
 832 
 833 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 834   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 835   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 836   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 837   bool result = mh->dont_inline();
 838   mh->set_dont_inline(value == JNI_TRUE);
 839   return result;
 840 WB_END
 841 
 842 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
 843   if (comp_level == CompLevel_any) {
 844     return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
 845         CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
 846   } else {
 847     return CompileBroker::queue_size(comp_level);
 848   }
 849 WB_END
 850 
 851 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 852   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 853   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 854   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 855   bool result = mh->force_inline();
 856   mh->set_force_inline(value == JNI_TRUE);
 857   return result;
 858 WB_END
 859 
 860 bool WhiteBox::compile_method(Method* method, int comp_level, int bci, Thread* THREAD) {
 861   // Screen for unavailable/bad comp level or null method
 862   AbstractCompiler* comp = CompileBroker::compiler(comp_level);
 863   if (method == NULL) {
 864     tty->print_cr("WB error: request to compile NULL method");
 865     return false;
 866   }
 867   if (comp_level > MIN2((CompLevel) TieredStopAtLevel, CompLevel_highest_tier)) {
 868     tty->print_cr("WB error: invalid compilation level %d", comp_level);
 869     return false;
 870   }
 871   if (comp == NULL) {
 872     tty->print_cr("WB error: no compiler for requested compilation level %d", comp_level);
 873     return false;
 874   }
 875 
 876   // Check if compilation is blocking
 877   methodHandle mh(THREAD, method);
 878   DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, comp);
 879   bool is_blocking = !directive->BackgroundCompilationOption;
 880   DirectivesStack::release(directive);
 881 
 882   // Compile method and check result
 883   nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), CompileTask::Reason_Whitebox, THREAD);
 884   MutexLockerEx mu(Compile_lock);
 885   bool is_queued = mh->queued_for_compilation();
 886   if ((!is_blocking && is_queued) || nm != NULL) {
 887     return true;
 888   }
 889   tty->print("WB error: failed to %s compile at level %d method ", is_blocking ? "blocking" : "", comp_level);
 890   mh->print_short_name(tty);
 891   tty->cr();
 892   if (is_blocking && is_queued) {
 893     tty->print_cr("WB error: blocking compilation is still in queue!");
 894   }
 895   return false;
 896 }
 897 
 898 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
 899   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 900   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 901   return WhiteBox::compile_method(Method::checked_resolve_jmethod_id(jmid), comp_level, bci, THREAD);
 902 WB_END
 903 
 904 WB_ENTRY(jboolean, WB_EnqueueInitializerForCompilation(JNIEnv* env, jobject o, jclass klass, jint comp_level))
 905   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
 906   return WhiteBox::compile_method(ik->class_initializer(), comp_level, InvocationEntryBci, THREAD);
 907 WB_END
 908 
 909 WB_ENTRY(jboolean, WB_ShouldPrintAssembly(JNIEnv* env, jobject o, jobject method, jint comp_level))
 910   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 911   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 912 
 913   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 914   DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, CompileBroker::compiler(comp_level));
 915   bool result = directive->PrintAssemblyOption;
 916   DirectivesStack::release(directive);
 917 
 918   return result;
 919 WB_END
 920 
 921 WB_ENTRY(jint, WB_MatchesInline(JNIEnv* env, jobject o, jobject method, jstring pattern))
 922   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 923   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 924 
 925   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 926 
 927   ResourceMark rm;
 928   const char* error_msg = NULL;
 929   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
 930   InlineMatcher* m = InlineMatcher::parse_inline_pattern(method_str, error_msg);
 931 
 932   if (m == NULL) {
 933     assert(error_msg != NULL, "Always have an error message");
 934     tty->print_cr("Got error: %s", error_msg);
 935     return -1; // Pattern failed
 936   }
 937 
 938   // Pattern works - now check if it matches
 939   int result;
 940   if (m->match(mh, InlineMatcher::force_inline)) {
 941     result = 2; // Force inline match
 942   } else if (m->match(mh, InlineMatcher::dont_inline)) {
 943     result = 1; // Dont inline match
 944   } else {
 945     result = 0; // No match
 946   }
 947   delete m;
 948   return result;
 949 WB_END
 950 
 951 WB_ENTRY(jint, WB_MatchesMethod(JNIEnv* env, jobject o, jobject method, jstring pattern))
 952   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 953   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 954 
 955   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 956 
 957   ResourceMark rm;
 958   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
 959 
 960   const char* error_msg = NULL;
 961 
 962   BasicMatcher* m = BasicMatcher::parse_method_pattern(method_str, error_msg);
 963   if (m == NULL) {
 964     assert(error_msg != NULL, "Must have error_msg");
 965     tty->print_cr("Got error: %s", error_msg);
 966     return -1;
 967   }
 968 
 969   // Pattern works - now check if it matches
 970   int result = m->matches(mh);
 971   delete m;
 972   assert(result == 0 || result == 1, "Result out of range");
 973   return result;
 974 WB_END
 975 
 976 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
 977   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 978   CHECK_JNI_EXCEPTION(env);
 979   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 980   MutexLockerEx mu(Compile_lock);
 981   MethodData* mdo = mh->method_data();
 982   MethodCounters* mcs = mh->method_counters();
 983 
 984   if (mdo != NULL) {
 985     mdo->init();
 986     ResourceMark rm;
 987     int arg_count = mdo->method()->size_of_parameters();
 988     for (int i = 0; i < arg_count; i++) {
 989       mdo->set_arg_modified(i, 0);
 990     }
 991     MutexLockerEx mu(mdo->extra_data_lock());
 992     mdo->clean_method_data(/*always_clean*/true);
 993   }
 994 
 995   mh->clear_not_c1_compilable();
 996   mh->clear_not_c2_compilable();
 997   mh->clear_not_c2_osr_compilable();
 998   NOT_PRODUCT(mh->set_compiled_invocation_count(0));
 999   if (mcs != NULL) {
1000     mcs->backedge_counter()->init();
1001     mcs->invocation_counter()->init();
1002     mcs->set_interpreter_invocation_count(0);
1003     mcs->set_interpreter_throwout_count(0);
1004 
1005 #ifdef TIERED
1006     mcs->set_rate(0.0F);
1007     mh->set_prev_event_count(0);
1008     mh->set_prev_time(0);
1009 #endif
1010   }
1011 WB_END
1012 
1013 template <typename T>
1014 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, JVMFlag::Error (*TAt)(const char*, T*, bool, bool)) {
1015   if (name == NULL) {
1016     return false;
1017   }
1018   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1019   const char* flag_name = env->GetStringUTFChars(name, NULL);
1020   CHECK_JNI_EXCEPTION_(env, false);
1021   JVMFlag::Error result = (*TAt)(flag_name, value, true, true);
1022   env->ReleaseStringUTFChars(name, flag_name);
1023   return (result == JVMFlag::SUCCESS);
1024 }
1025 
1026 template <typename T>
1027 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, JVMFlag::Error (*TAtPut)(const char*, T*, JVMFlag::Flags)) {
1028   if (name == NULL) {
1029     return false;
1030   }
1031   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1032   const char* flag_name = env->GetStringUTFChars(name, NULL);
1033   CHECK_JNI_EXCEPTION_(env, false);
1034   JVMFlag::Error result = (*TAtPut)(flag_name, value, JVMFlag::INTERNAL);
1035   env->ReleaseStringUTFChars(name, flag_name);
1036   return (result == JVMFlag::SUCCESS);
1037 }
1038 
1039 template <typename T>
1040 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
1041   ResourceMark rm(thread);
1042   jclass clazz = env->FindClass(name->as_C_string());
1043   CHECK_JNI_EXCEPTION_(env, NULL);
1044   jmethodID methodID = env->GetStaticMethodID(clazz,
1045         vmSymbols::valueOf_name()->as_C_string(),
1046         sig->as_C_string());
1047   CHECK_JNI_EXCEPTION_(env, NULL);
1048   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
1049   CHECK_JNI_EXCEPTION_(env, NULL);
1050   return result;
1051 }
1052 
1053 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
1054   return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
1055 }
1056 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
1057   return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
1058 }
1059 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
1060   return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
1061 }
1062 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
1063   return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
1064 }*/
1065 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
1066   return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
1067 }
1068 
1069 static JVMFlag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
1070   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1071   const char* flag_name = env->GetStringUTFChars(name, NULL);
1072   CHECK_JNI_EXCEPTION_(env, NULL);
1073   JVMFlag* result = JVMFlag::find_flag(flag_name, strlen(flag_name), true, true);
1074   env->ReleaseStringUTFChars(name, flag_name);
1075   return result;
1076 }
1077 
1078 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name))
1079   JVMFlag* flag = getVMFlag(thread, env, name);
1080   return (flag != NULL) && flag->is_constant_in_binary();
1081 WB_END
1082 
1083 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name))
1084   JVMFlag* flag = getVMFlag(thread, env, name);
1085   return (flag != NULL) && !(flag->is_unlocked() || flag->is_unlocker());
1086 WB_END
1087 
1088 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
1089   bool result;
1090   if (GetVMFlag <bool> (thread, env, name, &result, &JVMFlag::boolAt)) {
1091     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1092     return booleanBox(thread, env, result);
1093   }
1094   return NULL;
1095 WB_END
1096 
1097 WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name))
1098   int result;
1099   if (GetVMFlag <int> (thread, env, name, &result, &JVMFlag::intAt)) {
1100     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1101     return longBox(thread, env, result);
1102   }
1103   return NULL;
1104 WB_END
1105 
1106 WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name))
1107   uint result;
1108   if (GetVMFlag <uint> (thread, env, name, &result, &JVMFlag::uintAt)) {
1109     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1110     return longBox(thread, env, result);
1111   }
1112   return NULL;
1113 WB_END
1114 
1115 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
1116   intx result;
1117   if (GetVMFlag <intx> (thread, env, name, &result, &JVMFlag::intxAt)) {
1118     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1119     return longBox(thread, env, result);
1120   }
1121   return NULL;
1122 WB_END
1123 
1124 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
1125   uintx result;
1126   if (GetVMFlag <uintx> (thread, env, name, &result, &JVMFlag::uintxAt)) {
1127     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1128     return longBox(thread, env, result);
1129   }
1130   return NULL;
1131 WB_END
1132 
1133 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
1134   uint64_t result;
1135   if (GetVMFlag <uint64_t> (thread, env, name, &result, &JVMFlag::uint64_tAt)) {
1136     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1137     return longBox(thread, env, result);
1138   }
1139   return NULL;
1140 WB_END
1141 
1142 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
1143   size_t result;
1144   if (GetVMFlag <size_t> (thread, env, name, &result, &JVMFlag::size_tAt)) {
1145     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1146     return longBox(thread, env, result);
1147   }
1148   return NULL;
1149 WB_END
1150 
1151 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
1152   double result;
1153   if (GetVMFlag <double> (thread, env, name, &result, &JVMFlag::doubleAt)) {
1154     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1155     return doubleBox(thread, env, result);
1156   }
1157   return NULL;
1158 WB_END
1159 
1160 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
1161   ccstr ccstrResult;
1162   if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &JVMFlag::ccstrAt)) {
1163     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1164     jstring result = env->NewStringUTF(ccstrResult);
1165     CHECK_JNI_EXCEPTION_(env, NULL);
1166     return result;
1167   }
1168   return NULL;
1169 WB_END
1170 
1171 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
1172   bool result = value == JNI_TRUE ? true : false;
1173   SetVMFlag <bool> (thread, env, name, &result, &JVMFlag::boolAtPut);
1174 WB_END
1175 
1176 WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1177   int result = value;
1178   SetVMFlag <int> (thread, env, name, &result, &JVMFlag::intAtPut);
1179 WB_END
1180 
1181 WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1182   uint result = value;
1183   SetVMFlag <uint> (thread, env, name, &result, &JVMFlag::uintAtPut);
1184 WB_END
1185 
1186 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1187   intx result = value;
1188   SetVMFlag <intx> (thread, env, name, &result, &JVMFlag::intxAtPut);
1189 WB_END
1190 
1191 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1192   uintx result = value;
1193   SetVMFlag <uintx> (thread, env, name, &result, &JVMFlag::uintxAtPut);
1194 WB_END
1195 
1196 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1197   uint64_t result = value;
1198   SetVMFlag <uint64_t> (thread, env, name, &result, &JVMFlag::uint64_tAtPut);
1199 WB_END
1200 
1201 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
1202   size_t result = value;
1203   SetVMFlag <size_t> (thread, env, name, &result, &JVMFlag::size_tAtPut);
1204 WB_END
1205 
1206 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
1207   double result = value;
1208   SetVMFlag <double> (thread, env, name, &result, &JVMFlag::doubleAtPut);
1209 WB_END
1210 
1211 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
1212   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
1213   const char* ccstrValue;
1214   if (value == NULL) {
1215     ccstrValue = NULL;
1216   }
1217   else {
1218     ccstrValue = env->GetStringUTFChars(value, NULL);
1219     CHECK_JNI_EXCEPTION(env);
1220   }
1221   ccstr ccstrResult = ccstrValue;
1222   bool needFree;
1223   {
1224     ThreadInVMfromNative ttvfn(thread); // back to VM
1225     needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &JVMFlag::ccstrAtPut);
1226   }
1227   if (value != NULL) {
1228     env->ReleaseStringUTFChars(value, ccstrValue);
1229   }
1230   if (needFree) {
1231     FREE_C_HEAP_ARRAY(char, ccstrResult);
1232   }
1233 WB_END
1234 
1235 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
1236   WhiteBox::compilation_locked = true;
1237 WB_END
1238 
1239 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
1240   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
1241   WhiteBox::compilation_locked = false;
1242   mo.notify_all();
1243 WB_END
1244 
1245 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
1246   // Force a code cache sweep and block until it finished
1247   NMethodSweeper::force_sweep();
1248 WB_END
1249 
1250 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
1251   ResourceMark rm(THREAD);
1252   int len;
1253   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
1254   return (StringTable::lookup(name, len) != NULL);
1255 WB_END
1256 
1257 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
1258   Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true);
1259   Universe::heap()->collect(GCCause::_wb_full_gc);
1260 #if INCLUDE_G1GC
1261   if (UseG1GC) {
1262     // Needs to be cleared explicitly for G1
1263     Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false);
1264   }
1265 #endif // INCLUDE_G1GC
1266 WB_END
1267 
1268 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
1269   Universe::heap()->collect(GCCause::_wb_young_gc);
1270 WB_END
1271 
1272 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
1273   // static+volatile in order to force the read to happen
1274   // (not be eliminated by the compiler)
1275   static char c;
1276   static volatile char* p;
1277 
1278   p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
1279   if (p == NULL) {
1280     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
1281   }
1282 
1283   c = *p;
1284 WB_END
1285 
1286 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
1287   const char* features = VM_Version::features_string();
1288   ThreadToNativeFromVM ttn(thread);
1289   jstring features_string = env->NewStringUTF(features);
1290 
1291   CHECK_JNI_EXCEPTION_(env, NULL);
1292 
1293   return features_string;
1294 WB_END
1295 
1296 int WhiteBox::get_blob_type(const CodeBlob* code) {
1297   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1298   if (code->is_aot()) {
1299     return -1;
1300   }
1301   return CodeCache::get_code_heap(code)->code_blob_type();
1302 }
1303 
1304 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
1305   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1306   return CodeCache::get_code_heap(blob_type);
1307 }
1308 
1309 struct CodeBlobStub {
1310   CodeBlobStub(const CodeBlob* blob) :
1311       name(os::strdup(blob->name())),
1312       size(blob->size()),
1313       blob_type(WhiteBox::get_blob_type(blob)),
1314       address((jlong) blob) { }
1315   ~CodeBlobStub() { os::free((void*) name); }
1316   const char* const name;
1317   const jint        size;
1318   const jint        blob_type;
1319   const jlong       address;
1320 };
1321 
1322 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
1323   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1324   CHECK_JNI_EXCEPTION_(env, NULL);
1325   jobjectArray result = env->NewObjectArray(4, clazz, NULL);
1326 
1327   jstring name = env->NewStringUTF(cb->name);
1328   CHECK_JNI_EXCEPTION_(env, NULL);
1329   env->SetObjectArrayElement(result, 0, name);
1330 
1331   jobject obj = integerBox(thread, env, cb->size);
1332   CHECK_JNI_EXCEPTION_(env, NULL);
1333   env->SetObjectArrayElement(result, 1, obj);
1334 
1335   obj = integerBox(thread, env, cb->blob_type);
1336   CHECK_JNI_EXCEPTION_(env, NULL);
1337   env->SetObjectArrayElement(result, 2, obj);
1338 
1339   obj = longBox(thread, env, cb->address);
1340   CHECK_JNI_EXCEPTION_(env, NULL);
1341   env->SetObjectArrayElement(result, 3, obj);
1342 
1343   return result;
1344 }
1345 
1346 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1347   ResourceMark rm(THREAD);
1348   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1349   CHECK_JNI_EXCEPTION_(env, NULL);
1350   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1351   CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1352   jobjectArray result = NULL;
1353   if (code == NULL) {
1354     return result;
1355   }
1356   int comp_level = code->comp_level();
1357   int insts_size = comp_level == CompLevel_aot ? code->code_end() - code->code_begin() : code->insts_size();
1358 
1359   ThreadToNativeFromVM ttn(thread);
1360   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1361   CHECK_JNI_EXCEPTION_(env, NULL);
1362   result = env->NewObjectArray(5, clazz, NULL);
1363   if (result == NULL) {
1364     return result;
1365   }
1366 
1367   CodeBlobStub stub(code);
1368   jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1369   CHECK_JNI_EXCEPTION_(env, NULL);
1370   env->SetObjectArrayElement(result, 0, codeBlob);
1371 
1372   jobject level = integerBox(thread, env, comp_level);
1373   CHECK_JNI_EXCEPTION_(env, NULL);
1374   env->SetObjectArrayElement(result, 1, level);
1375 
1376   jbyteArray insts = env->NewByteArray(insts_size);
1377   CHECK_JNI_EXCEPTION_(env, NULL);
1378   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1379   env->SetObjectArrayElement(result, 2, insts);
1380 
1381   jobject id = integerBox(thread, env, code->compile_id());
1382   CHECK_JNI_EXCEPTION_(env, NULL);
1383   env->SetObjectArrayElement(result, 3, id);
1384 
1385   jobject entry_point = longBox(thread, env, (jlong) code->entry_point());
1386   CHECK_JNI_EXCEPTION_(env, NULL);
1387   env->SetObjectArrayElement(result, 4, entry_point);
1388 
1389   return result;
1390 WB_END
1391 
1392 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1393   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1394   BufferBlob* blob;
1395   int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1396   if (full_size < size) {
1397     full_size += align_up(size - full_size, oopSize);
1398   }
1399   {
1400     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1401     blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1402     if (blob != NULL) {
1403       ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1404     }
1405   }
1406   // Track memory usage statistic after releasing CodeCache_lock
1407   MemoryService::track_code_cache_memory_usage();
1408   return blob;
1409 }
1410 
1411 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
1412   if (size < 0) {
1413     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1414       err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size));
1415   }
1416   return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
1417 WB_END
1418 
1419 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
1420   if (addr == 0) {
1421     return;
1422   }
1423   BufferBlob::free((BufferBlob*) addr);
1424 WB_END
1425 
1426 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
1427   ResourceMark rm;
1428   GrowableArray<CodeBlobStub*> blobs;
1429   {
1430     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1431     CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
1432     if (heap == NULL) {
1433       return NULL;
1434     }
1435     for (CodeBlob* cb = (CodeBlob*) heap->first();
1436          cb != NULL; cb = (CodeBlob*) heap->next(cb)) {
1437       CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub);
1438       new (stub) CodeBlobStub(cb);
1439       blobs.append(stub);
1440     }
1441   }
1442   if (blobs.length() == 0) {
1443     return NULL;
1444   }
1445   ThreadToNativeFromVM ttn(thread);
1446   jobjectArray result = NULL;
1447   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1448   CHECK_JNI_EXCEPTION_(env, NULL);
1449   result = env->NewObjectArray(blobs.length(), clazz, NULL);
1450   CHECK_JNI_EXCEPTION_(env, NULL);
1451   if (result == NULL) {
1452     return result;
1453   }
1454   int i = 0;
1455   for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin();
1456        it != blobs.end(); ++it) {
1457     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
1458     CHECK_JNI_EXCEPTION_(env, NULL);
1459     env->SetObjectArrayElement(result, i, obj);
1460     CHECK_JNI_EXCEPTION_(env, NULL);
1461     ++i;
1462   }
1463   return result;
1464 WB_END
1465 
1466 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1467   return CompileBroker::get_compilation_activity_mode();
1468 WB_END
1469 
1470 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1471   if (addr == 0) {
1472     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1473       "WB_GetCodeBlob: addr is null");
1474   }
1475   ThreadToNativeFromVM ttn(thread);
1476   CodeBlobStub stub((CodeBlob*) addr);
1477   return codeBlob2objectArray(thread, env, &stub);
1478 WB_END
1479 
1480 WB_ENTRY(jlong, WB_GetMethodData(JNIEnv* env, jobject wv, jobject method))
1481   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1482   CHECK_JNI_EXCEPTION_(env, 0);
1483   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1484   return (jlong) mh->method_data();
1485 WB_END
1486 
1487 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1488   return (jlong) Thread::current()->stack_size();
1489 WB_END
1490 
1491 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1492   JavaThread* t = JavaThread::current();
1493   return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong)JavaThread::stack_shadow_zone_size();
1494 WB_END
1495 
1496 
1497 int WhiteBox::array_bytes_to_length(size_t bytes) {
1498   return Array<u1>::bytes_to_length(bytes);
1499 }
1500 
1501 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1502   if (size < 0) {
1503     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1504         err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1505   }
1506 
1507   oop class_loader_oop = JNIHandles::resolve(class_loader);
1508   ClassLoaderData* cld = class_loader_oop != NULL
1509       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1510       : ClassLoaderData::the_null_class_loader_data();
1511 
1512   void* metadata = MetadataFactory::new_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1513 
1514   return (jlong)(uintptr_t)metadata;
1515 WB_END
1516 
1517 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1518   oop class_loader_oop = JNIHandles::resolve(class_loader);
1519   ClassLoaderData* cld = class_loader_oop != NULL
1520       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1521       : ClassLoaderData::the_null_class_loader_data();
1522 
1523   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1524 WB_END
1525 
1526 WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jboolean is_open,
1527                                 jstring version, jstring location, jobjectArray packages))
1528   ResourceMark rm(THREAD);
1529 
1530   objArrayOop packages_oop = objArrayOop(JNIHandles::resolve(packages));
1531   objArrayHandle packages_h(THREAD, packages_oop);
1532   int num_packages = (packages_h == NULL ? 0 : packages_h->length());
1533 
1534   char** pkgs = NULL;
1535   if (num_packages > 0) {
1536     pkgs = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char*, num_packages);
1537     for (int x = 0; x < num_packages; x++) {
1538       oop pkg_str = packages_h->obj_at(x);
1539       if (pkg_str == NULL || !pkg_str->is_a(SystemDictionary::String_klass())) {
1540         THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(),
1541                   err_msg("Bad package name"));
1542       }
1543       pkgs[x] = java_lang_String::as_utf8_string(pkg_str);
1544     }
1545   }
1546   Modules::define_module(module, is_open, version, location, (const char* const*)pkgs, num_packages, CHECK);
1547 WB_END
1548 
1549 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module))
1550   ResourceMark rm(THREAD);
1551   char* package_name = NULL;
1552   if (package != NULL) {
1553       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1554   }
1555   Modules::add_module_exports_qualified(from_module, package_name, to_module, CHECK);
1556 WB_END
1557 
1558 WB_ENTRY(void, WB_AddModuleExportsToAllUnnamed(JNIEnv* env, jobject o, jclass module, jstring package))
1559   ResourceMark rm(THREAD);
1560   char* package_name = NULL;
1561   if (package != NULL) {
1562       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1563   }
1564   Modules::add_module_exports_to_all_unnamed(module, package_name, CHECK);
1565 WB_END
1566 
1567 WB_ENTRY(void, WB_AddModuleExportsToAll(JNIEnv* env, jobject o, jclass module, jstring package))
1568   ResourceMark rm(THREAD);
1569   char* package_name = NULL;
1570   if (package != NULL) {
1571       package_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(package));
1572   }
1573   Modules::add_module_exports(module, package_name, NULL, CHECK);
1574 WB_END
1575 
1576 WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject source_module))
1577   Modules::add_reads_module(from_module, source_module, CHECK);
1578 WB_END
1579 
1580 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1581   if (inc < 0) {
1582     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1583         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1584   }
1585 
1586   jlong max_size_t = (jlong) ((size_t) -1);
1587   if (inc > max_size_t) {
1588     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1589         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1590   }
1591 
1592   size_t new_cap_until_GC = 0;
1593   size_t aligned_inc = align_down((size_t) inc, Metaspace::commit_alignment());
1594   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1595   if (!success) {
1596     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1597                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
1598                 "due to contention with another thread");
1599   }
1600   return (jlong) new_cap_until_GC;
1601 WB_END
1602 
1603 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
1604   return (jlong) MetaspaceGC::capacity_until_GC();
1605 WB_END
1606 
1607 WB_ENTRY(jboolean, WB_MetaspaceShouldConcurrentCollect(JNIEnv* env, jobject wb))
1608   return MetaspaceGC::should_concurrent_collect();
1609 WB_END
1610 
1611 WB_ENTRY(jlong, WB_MetaspaceReserveAlignment(JNIEnv* env, jobject wb))
1612   return (jlong)Metaspace::reserve_alignment();
1613 WB_END
1614 
1615 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1616   Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1617                                            Monitor::_safepoint_check_always :
1618                                            Monitor::_safepoint_check_never;
1619   MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1620                    attemptedNoSafepointValue == JNI_TRUE);
1621 WB_END
1622 
1623 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1624   oop obj_oop = JNIHandles::resolve(obj);
1625   return (jboolean) obj_oop->mark()->has_monitor();
1626 WB_END
1627 
1628 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1629   VM_ForceSafepoint force_safepoint_op;
1630   VMThread::execute(&force_safepoint_op);
1631 WB_END
1632 
1633 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass))
1634   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1635   return (jlong) ik->constants();
1636 WB_END
1637 
1638 WB_ENTRY(jint, WB_GetConstantPoolCacheIndexTag(JNIEnv* env, jobject wb))
1639   return ConstantPool::CPCACHE_INDEX_TAG;
1640 WB_END
1641 
1642 WB_ENTRY(jint, WB_GetConstantPoolCacheLength(JNIEnv* env, jobject wb, jclass klass))
1643   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1644   ConstantPool* cp = ik->constants();
1645   if (cp->cache() == NULL) {
1646       return -1;
1647   }
1648   return cp->cache()->length();
1649 WB_END
1650 
1651 WB_ENTRY(jint, WB_ConstantPoolRemapInstructionOperandFromCache(JNIEnv* env, jobject wb, jclass klass, jint index))
1652   InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass)));
1653   ConstantPool* cp = ik->constants();
1654   if (cp->cache() == NULL) {
1655     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), "Constant pool does not have a cache");
1656   }
1657   jint cpci = index;
1658   jint cpciTag = ConstantPool::CPCACHE_INDEX_TAG;
1659   if (cpciTag > cpci || cpci >= cp->cache()->length() + cpciTag) {
1660     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), "Constant pool cache index is out of range");
1661   }
1662   jint cpi = cp->remap_instruction_operand_from_cache(cpci);
1663   return cpi;
1664 WB_END
1665 
1666 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index))
1667   return ConstantPool::encode_invokedynamic_index(index);
1668 WB_END
1669 
1670 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing))
1671   oop aoop = JNIHandles::resolve(thing);
1672   if (!aoop->is_instance()) {
1673     return NULL;
1674   }
1675   instanceHandle ih(THREAD, (instanceOop) aoop);
1676   InstanceKlass* klass = InstanceKlass::cast(aoop->klass());
1677   if (klass->nonstatic_oop_map_count() == 0) {
1678     return NULL;
1679   }
1680   const OopMapBlock* map = klass->start_of_nonstatic_oop_maps();
1681   const OopMapBlock* const end = map + klass->nonstatic_oop_map_count();
1682   int oop_count = 0;
1683   while (map < end) {
1684     oop_count += map->count();
1685     map++;
1686   }
1687 
1688   objArrayOop result_array =
1689       oopFactory::new_objArray(SystemDictionary::Object_klass(), oop_count, CHECK_NULL);
1690   map = klass->start_of_nonstatic_oop_maps();
1691   instanceOop ioop = ih();
1692   int index = 0;
1693   while (map < end) {
1694     int offset = map->offset();
1695     for (unsigned int j = 0; j < map->count(); j++) {
1696       result_array->obj_at_put(index++, ioop->obj_field(offset));
1697       offset += heapOopSize;
1698     }
1699     map++;
1700   }
1701   return (jobjectArray)JNIHandles::make_local(env, result_array);
1702 WB_END
1703 
1704 class CollectOops : public BasicOopIterateClosure {
1705  public:
1706   GrowableArray<Handle>* array;
1707 
1708   objArrayOop create_results(TRAPS) {
1709     objArrayOop result_array =
1710         oopFactory::new_objArray(SystemDictionary::Object_klass(), array->length(), CHECK_NULL);
1711     for (int i = 0 ; i < array->length(); i++) {
1712       result_array->obj_at_put(i, array->at(i)());
1713     }
1714     return result_array;
1715   }
1716 
1717   jobjectArray create_jni_result(JNIEnv* env, TRAPS) {
1718     return (jobjectArray)JNIHandles::make_local(env, create_results(THREAD));
1719   }
1720 
1721   void add_oop(oop o) {
1722     // Value might be oop, but JLS can't see as Object, just iterate through it...
1723     if (o != NULL && o->is_value()) {
1724       o->oop_iterate(this);
1725     } else {
1726       array->append(Handle(Thread::current(), o));
1727     }
1728   }
1729 
1730   void do_oop(oop* o) { add_oop(*o); }
1731   void do_oop(narrowOop* v) { add_oop(CompressedOops::decode(*v)); }
1732 };
1733 
1734 
1735 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing))
1736   ResourceMark rm(THREAD);
1737   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1738   CollectOops collectOops;
1739   collectOops.array = array;
1740 
1741   JNIHandles::resolve(thing)->oop_iterate(&collectOops);
1742 
1743   return collectOops.create_jni_result(env, THREAD);
1744 WB_END
1745 
1746 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth))
1747   ResourceMark rm(THREAD);
1748   GrowableArray<Handle>* array = new GrowableArray<Handle>(128);
1749   CollectOops collectOops;
1750   collectOops.array = array;
1751   StackFrameStream sfs(thread);
1752   while (depth > 0) { // Skip the native WB API frame
1753     sfs.next();
1754     frame* f = sfs.current();
1755     f->oops_do(&collectOops, NULL, sfs.register_map());
1756     depth--;
1757   }
1758   return collectOops.create_jni_result(env, THREAD);
1759 WB_END
1760 
1761 
1762 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs))
1763   VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE);
1764   VMThread::execute(&clear_ics);
1765 WB_END
1766 
1767 template <typename T>
1768 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1769   assert(value != NULL, "sanity");
1770   if (method == NULL || name == NULL) {
1771     return false;
1772   }
1773   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1774   CHECK_JNI_EXCEPTION_(env, false);
1775   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1776   // can't be in VM when we call JNI
1777   ThreadToNativeFromVM ttnfv(thread);
1778   const char* flag_name = env->GetStringUTFChars(name, NULL);
1779   CHECK_JNI_EXCEPTION_(env, false);
1780   bool result =  CompilerOracle::has_option_value(mh, flag_name, *value);
1781   env->ReleaseStringUTFChars(name, flag_name);
1782   return result;
1783 }
1784 
1785 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1786   bool result;
1787   if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1788     // can't be in VM when we call JNI
1789     ThreadToNativeFromVM ttnfv(thread);
1790     return booleanBox(thread, env, result);
1791   }
1792   return NULL;
1793 WB_END
1794 
1795 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1796   intx result;
1797   if (GetMethodOption <intx> (thread, env, method, name, &result)) {
1798     // can't be in VM when we call JNI
1799     ThreadToNativeFromVM ttnfv(thread);
1800     return longBox(thread, env, result);
1801   }
1802   return NULL;
1803 WB_END
1804 
1805 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1806   uintx result;
1807   if (GetMethodOption <uintx> (thread, env, method, name, &result)) {
1808     // can't be in VM when we call JNI
1809     ThreadToNativeFromVM ttnfv(thread);
1810     return longBox(thread, env, result);
1811   }
1812   return NULL;
1813 WB_END
1814 
1815 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1816   double result;
1817   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1818     // can't be in VM when we call JNI
1819     ThreadToNativeFromVM ttnfv(thread);
1820     return doubleBox(thread, env, result);
1821   }
1822   return NULL;
1823 WB_END
1824 
1825 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1826   ccstr ccstrResult;
1827   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1828     // can't be in VM when we call JNI
1829     ThreadToNativeFromVM ttnfv(thread);
1830     jstring result = env->NewStringUTF(ccstrResult);
1831     CHECK_JNI_EXCEPTION_(env, NULL);
1832     return result;
1833   }
1834   return NULL;
1835 WB_END
1836 
1837 WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
1838   oop obj_oop = JNIHandles::resolve(obj);
1839   return MetaspaceShared::is_archive_object(obj_oop);
1840 WB_END
1841 
1842 WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz))
1843   return (jboolean)MetaspaceShared::is_in_shared_metaspace(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)));
1844 WB_END
1845 
1846 WB_ENTRY(jboolean, WB_AreSharedStringsIgnored(JNIEnv* env))
1847   return !StringTable::shared_string_mapped();
1848 WB_END
1849 
1850 WB_ENTRY(jobject, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass clazz))
1851   Klass *k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz));
1852   if (k->is_instance_klass()) {
1853     InstanceKlass *ik = InstanceKlass::cast(k);
1854     ConstantPool *cp = ik->constants();
1855     objArrayOop refs =  cp->resolved_references();
1856     return (jobject)JNIHandles::make_local(env, refs);
1857   } else {
1858     return NULL;
1859   }
1860 WB_END
1861 
1862 WB_ENTRY(jboolean, WB_AreOpenArchiveHeapObjectsMapped(JNIEnv* env))
1863   return MetaspaceShared::open_archive_heap_region_mapped();
1864 WB_END
1865 
1866 WB_ENTRY(jboolean, WB_IsCDSIncludedInVmBuild(JNIEnv* env))
1867 #if INCLUDE_CDS
1868 # ifdef _LP64
1869     if (!UseCompressedOops || !UseCompressedClassPointers) {
1870       // On 64-bit VMs, CDS is supported only with compressed oops/pointers
1871       return false;
1872     }
1873 # endif // _LP64
1874   return true;
1875 #else
1876   return false;
1877 #endif // INCLUDE_CDS
1878 WB_END
1879 
1880 WB_ENTRY(jboolean, WB_IsJavaHeapArchiveSupported(JNIEnv* env))
1881   return MetaspaceShared::is_heap_object_archiving_allowed();
1882 WB_END
1883 
1884 
1885 WB_ENTRY(jboolean, WB_IsJFRIncludedInVmBuild(JNIEnv* env))
1886 #if INCLUDE_JFR
1887   return true;
1888 #else
1889   return false;
1890 #endif // INCLUDE_JFR
1891 WB_END
1892 
1893 #if INCLUDE_CDS
1894 
1895 WB_ENTRY(jint, WB_GetOffsetForName(JNIEnv* env, jobject o, jstring name))
1896   ResourceMark rm;
1897   char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name));
1898   int result = CDSOffsets::find_offset(c_name);
1899   return (jint)result;
1900 WB_END
1901 
1902 #endif // INCLUDE_CDS
1903 
1904 WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle, jboolean all_threads))
1905   class TraceSelfClosure : public ThreadClosure {
1906     jint _num_threads_completed;
1907 
1908     void do_thread(Thread* th) {
1909       assert(th->is_Java_thread(), "sanity");
1910       JavaThread* jt = (JavaThread*)th;
1911       ResourceMark rm;
1912 
1913       jt->print_on(tty);
1914       jt->print_stack_on(tty);
1915       tty->cr();
1916       Atomic::inc(&_num_threads_completed);
1917     }
1918 
1919   public:
1920     TraceSelfClosure() : _num_threads_completed(0) {}
1921 
1922     jint num_threads_completed() const { return _num_threads_completed; }
1923   };
1924   TraceSelfClosure tsc;
1925 
1926   if (all_threads) {
1927     Handshake::execute(&tsc);
1928   } else {
1929     oop thread_oop = JNIHandles::resolve(thread_handle);
1930     if (thread_oop != NULL) {
1931       JavaThread* target = java_lang_Thread::thread(thread_oop);
1932       Handshake::execute(&tsc, target);
1933     }
1934   }
1935   return tsc.num_threads_completed();
1936 WB_END
1937 
1938 //Some convenience methods to deal with objects from java
1939 int WhiteBox::offset_for_field(const char* field_name, oop object,
1940     Symbol* signature_symbol) {
1941   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1942   Thread* THREAD = Thread::current();
1943 
1944   //Get the class of our object
1945   Klass* arg_klass = object->klass();
1946   //Turn it into an instance-klass
1947   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1948 
1949   //Create symbols to look for in the class
1950   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1951       THREAD);
1952 
1953   //To be filled in with an offset of the field we're looking for
1954   fieldDescriptor fd;
1955 
1956   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1957   if (res == NULL) {
1958     tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1959         name_symbol->as_C_string());
1960     vm_exit_during_initialization("Invalid layout of preloaded class: use -Xlog:class+load=info to see the origin of the problem class");
1961   }
1962 
1963   //fetch the field at the offset we've found
1964   int dest_offset = fd.offset();
1965 
1966   return dest_offset;
1967 }
1968 
1969 
1970 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1971   int offset = offset_for_field(field_name, object,
1972       vmSymbols::string_signature());
1973   oop string = object->obj_field(offset);
1974   if (string == NULL) {
1975     return NULL;
1976   }
1977   const char* ret = java_lang_String::as_utf8_string(string);
1978   return ret;
1979 }
1980 
1981 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
1982   int offset =
1983       offset_for_field(field_name, object, vmSymbols::bool_signature());
1984   bool ret = (object->bool_field(offset) == JNI_TRUE);
1985   return ret;
1986 }
1987 
1988 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
1989   ResourceMark rm;
1990   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
1991 
1992   //  one by one registration natives for exception catching
1993   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
1994   CHECK_JNI_EXCEPTION(env);
1995   for (int i = 0, n = method_count; i < n; ++i) {
1996     // Skip dummy entries
1997     if (method_array[i].fnPtr == NULL) continue;
1998     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
1999       jthrowable throwable_obj = env->ExceptionOccurred();
2000       if (throwable_obj != NULL) {
2001         env->ExceptionClear();
2002         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
2003           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
2004           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
2005           tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
2006               method_array[i].name, method_array[i].signature);
2007         }
2008       } else {
2009         // Registration failed unexpectedly.
2010         tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
2011             method_array[i].name, method_array[i].signature);
2012         env->UnregisterNatives(wbclass);
2013         break;
2014       }
2015     }
2016   }
2017 }
2018 
2019 WB_ENTRY(jint, WB_AddCompilerDirective(JNIEnv* env, jobject o, jstring compDirect))
2020   // can't be in VM when we call JNI
2021   ThreadToNativeFromVM ttnfv(thread);
2022   const char* dir = env->GetStringUTFChars(compDirect, NULL);
2023   CHECK_JNI_EXCEPTION_(env, 0);
2024   int ret;
2025   {
2026     ThreadInVMfromNative ttvfn(thread); // back to VM
2027     ret = DirectivesParser::parse_string(dir, tty);
2028   }
2029   env->ReleaseStringUTFChars(compDirect, dir);
2030   // -1 for error parsing directive. Return 0 as number of directives added.
2031   if (ret == -1) {
2032     ret = 0;
2033   }
2034   return (jint) ret;
2035 WB_END
2036 
2037 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count))
2038   DirectivesStack::pop(count);
2039 WB_END
2040 
2041 // Checks that the library libfile has the noexecstack bit set.
2042 WB_ENTRY(jboolean, WB_CheckLibSpecifiesNoexecstack(JNIEnv* env, jobject o, jstring libfile))
2043   jboolean ret = false;
2044 #ifdef LINUX
2045   // Can't be in VM when we call JNI.
2046   ThreadToNativeFromVM ttnfv(thread);
2047   const char* lf = env->GetStringUTFChars(libfile, NULL);
2048   CHECK_JNI_EXCEPTION_(env, 0);
2049   ret = (jboolean) ElfFile::specifies_noexecstack(lf);
2050   env->ReleaseStringUTFChars(libfile, lf);
2051 #endif
2052   return ret;
2053 WB_END
2054 
2055 WB_ENTRY(jboolean, WB_IsContainerized(JNIEnv* env, jobject o))
2056   LINUX_ONLY(return OSContainer::is_containerized();)
2057   return false;
2058 WB_END
2059 
2060 WB_ENTRY(void, WB_PrintOsInfo(JNIEnv* env, jobject o))
2061   os::print_os_info(tty);
2062 WB_END
2063 
2064 // Elf decoder
2065 WB_ENTRY(void, WB_DisableElfSectionCache(JNIEnv* env))
2066 #if !defined(_WINDOWS) && !defined(__APPLE__) && !defined(_AIX)
2067   ElfFile::_do_not_cache_elf_section = true;
2068 #endif
2069 WB_END
2070 
2071 WB_ENTRY(jint, WB_ResolvedMethodRemovedCount(JNIEnv* env, jobject o))
2072   return (jint) ResolvedMethodTable::removed_entries_count();
2073 WB_END
2074 
2075 WB_ENTRY(jint, WB_ProtectionDomainRemovedCount(JNIEnv* env, jobject o))
2076   return (jint) SystemDictionary::pd_cache_table()->removed_entries_count();
2077 WB_END
2078 
2079 
2080 #define CC (char*)
2081 
2082 static JNINativeMethod methods[] = {
2083   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
2084   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
2085   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
2086   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
2087   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
2088   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
2089   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
2090   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
2091   {CC"getHeapAlignment",                 CC"()J",                   (void*)&WB_GetHeapAlignment},
2092   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
2093   {CC"parseCommandLine0",
2094       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
2095       (void*) &WB_ParseCommandLine
2096   },
2097   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
2098                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
2099   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
2100                                                       (void*)&WB_AddToSystemClassLoaderSearch},
2101   {CC"getCompressedOopsMaxHeapSize", CC"()J",
2102       (void*)&WB_GetCompressedOopsMaxHeapSize},
2103   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
2104   {CC"runMemoryUnitTests", CC"()V",                   (void*)&WB_RunMemoryUnitTests},
2105   {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
2106   {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
2107 #if INCLUDE_CDS
2108   {CC"getOffsetForName0", CC"(Ljava/lang/String;)I",  (void*)&WB_GetOffsetForName},
2109 #endif
2110 #if INCLUDE_G1GC
2111   {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
2112   {CC"g1IsHumongous0",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
2113   {CC"g1BelongsToHumongousRegion0", CC"(J)Z",         (void*)&WB_G1BelongsToHumongousRegion},
2114   {CC"g1BelongsToFreeRegion0", CC"(J)Z",              (void*)&WB_G1BelongsToFreeRegion},
2115   {CC"g1NumMaxRegions",    CC"()J",                   (void*)&WB_G1NumMaxRegions  },
2116   {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
2117   {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
2118   {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
2119   {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;",
2120                                                       (void*)&WB_G1AuxiliaryMemoryUsage  },
2121   {CC"g1GetMixedGCInfo",   CC"(I)[J",                 (void*)&WB_G1GetMixedGCInfo },
2122 #endif // INCLUDE_G1GC
2123 #if INCLUDE_PARALLELGC
2124   {CC"psVirtualSpaceAlignment",CC"()J",               (void*)&WB_PSVirtualSpaceAlignment},
2125   {CC"psHeapGenerationAlignment",CC"()J",             (void*)&WB_PSHeapGenerationAlignment},
2126 #endif
2127 #if INCLUDE_NMT
2128   {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
2129   {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
2130   {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
2131   {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
2132   {CC"NMTAttemptReserveMemoryAt",    CC"(JJ)J",       (void*)&WB_NMTAttemptReserveMemoryAt },
2133   {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
2134   {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
2135   {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
2136   {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
2137   {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
2138 #endif // INCLUDE_NMT
2139   {CC"deoptimizeFrames",   CC"(Z)I",                  (void*)&WB_DeoptimizeFrames  },
2140   {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
2141   {CC"deoptimizeMethod0",   CC"(Ljava/lang/reflect/Executable;Z)I",
2142                                                       (void*)&WB_DeoptimizeMethod  },
2143   {CC"isMethodCompiled0",   CC"(Ljava/lang/reflect/Executable;Z)Z",
2144                                                       (void*)&WB_IsMethodCompiled  },
2145   {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z",
2146                                                       (void*)&WB_IsMethodCompilable},
2147   {CC"isMethodQueuedForCompilation0",
2148       CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
2149   {CC"isIntrinsicAvailable0",
2150       CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z",
2151                                                       (void*)&WB_IsIntrinsicAvailable},
2152   {CC"makeMethodNotCompilable0",
2153       CC"(Ljava/lang/reflect/Executable;IZ)V",        (void*)&WB_MakeMethodNotCompilable},
2154   {CC"testSetDontInlineMethod0",
2155       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetDontInlineMethod},
2156   {CC"getMethodCompilationLevel0",
2157       CC"(Ljava/lang/reflect/Executable;Z)I",         (void*)&WB_GetMethodCompilationLevel},
2158   {CC"getMethodEntryBci0",
2159       CC"(Ljava/lang/reflect/Executable;)I",          (void*)&WB_GetMethodEntryBci},
2160   {CC"getCompileQueueSize",
2161       CC"(I)I",                                       (void*)&WB_GetCompileQueueSize},
2162   {CC"testSetForceInlineMethod0",
2163       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetForceInlineMethod},
2164   {CC"enqueueMethodForCompilation0",
2165       CC"(Ljava/lang/reflect/Executable;II)Z",        (void*)&WB_EnqueueMethodForCompilation},
2166   {CC"enqueueInitializerForCompilation0",
2167       CC"(Ljava/lang/Class;I)Z",                      (void*)&WB_EnqueueInitializerForCompilation},
2168   {CC"clearMethodState0",
2169       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_ClearMethodState},
2170   {CC"lockCompilation",    CC"()V",                   (void*)&WB_LockCompilation},
2171   {CC"unlockCompilation",  CC"()V",                   (void*)&WB_UnlockCompilation},
2172   {CC"matchesMethod",
2173       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
2174                                                       (void*)&WB_MatchesMethod},
2175   {CC"matchesInline",
2176       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
2177                                                       (void*)&WB_MatchesInline},
2178   {CC"shouldPrintAssembly",
2179         CC"(Ljava/lang/reflect/Executable;I)Z",
2180                                                         (void*)&WB_ShouldPrintAssembly},
2181 
2182   {CC"isConstantVMFlag",   CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag},
2183   {CC"isLockedVMFlag",     CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag},
2184   {CC"setBooleanVMFlag",   CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
2185   {CC"setIntVMFlag",       CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag},
2186   {CC"setUintVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag},
2187   {CC"setIntxVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
2188   {CC"setUintxVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
2189   {CC"setUint64VMFlag",    CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
2190   {CC"setSizeTVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag},
2191   {CC"setDoubleVMFlag",    CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
2192   {CC"setStringVMFlag",    CC"(Ljava/lang/String;Ljava/lang/String;)V",
2193                                                       (void*)&WB_SetStringVMFlag},
2194   {CC"getBooleanVMFlag",   CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
2195                                                       (void*)&WB_GetBooleanVMFlag},
2196   {CC"getIntVMFlag",       CC"(Ljava/lang/String;)Ljava/lang/Long;",
2197                                                       (void*)&WB_GetIntVMFlag},
2198   {CC"getUintVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
2199                                                       (void*)&WB_GetUintVMFlag},
2200   {CC"getIntxVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
2201                                                       (void*)&WB_GetIntxVMFlag},
2202   {CC"getUintxVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
2203                                                       (void*)&WB_GetUintxVMFlag},
2204   {CC"getUint64VMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Long;",
2205                                                       (void*)&WB_GetUint64VMFlag},
2206   {CC"getSizeTVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
2207                                                       (void*)&WB_GetSizeTVMFlag},
2208   {CC"getDoubleVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Double;",
2209                                                       (void*)&WB_GetDoubleVMFlag},
2210   {CC"getStringVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/String;",
2211                                                       (void*)&WB_GetStringVMFlag},
2212   {CC"isInStringTable",    CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable  },
2213   {CC"fullGC",   CC"()V",                             (void*)&WB_FullGC },
2214   {CC"youngGC",  CC"()V",                             (void*)&WB_YoungGC },
2215   {CC"readReservedMemory", CC"()V",                   (void*)&WB_ReadReservedMemory },
2216   {CC"allocateMetaspace",
2217      CC"(Ljava/lang/ClassLoader;J)J",                 (void*)&WB_AllocateMetaspace },
2218   {CC"freeMetaspace",
2219      CC"(Ljava/lang/ClassLoader;JJ)V",                (void*)&WB_FreeMetaspace },
2220   {CC"incMetaspaceCapacityUntilGC", CC"(J)J",         (void*)&WB_IncMetaspaceCapacityUntilGC },
2221   {CC"metaspaceCapacityUntilGC", CC"()J",             (void*)&WB_MetaspaceCapacityUntilGC },
2222   {CC"metaspaceShouldConcurrentCollect", CC"()Z",     (void*)&WB_MetaspaceShouldConcurrentCollect },
2223   {CC"metaspaceReserveAlignment", CC"()J",            (void*)&WB_MetaspaceReserveAlignment },
2224   {CC"getCPUFeatures",     CC"()Ljava/lang/String;",  (void*)&WB_GetCPUFeatures     },
2225   {CC"getNMethod0",         CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
2226                                                       (void*)&WB_GetNMethod         },
2227   {CC"forceNMethodSweep",  CC"()V",                   (void*)&WB_ForceNMethodSweep  },
2228   {CC"allocateCodeBlob",   CC"(II)J",                 (void*)&WB_AllocateCodeBlob   },
2229   {CC"freeCodeBlob",       CC"(J)V",                  (void*)&WB_FreeCodeBlob       },
2230   {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
2231   {CC"getCompilationActivityMode",
2232                            CC"()I",                   (void*)&WB_GetCompilationActivityMode},
2233   {CC"getMethodData0",     CC"(Ljava/lang/reflect/Executable;)J",
2234                                                       (void*)&WB_GetMethodData      },
2235   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
2236   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
2237   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
2238   {CC"DefineModule",       CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V",
2239                                                       (void*)&WB_DefineModule },
2240   {CC"AddModuleExports",   CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V",
2241                                                       (void*)&WB_AddModuleExports },
2242   {CC"AddReadsModule",     CC"(Ljava/lang/Object;Ljava/lang/Object;)V",
2243                                                       (void*)&WB_AddReadsModule },
2244   {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2245                                                       (void*)&WB_AddModuleExportsToAllUnnamed },
2246   {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V",
2247                                                       (void*)&WB_AddModuleExportsToAll },
2248   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
2249   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
2250   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
2251   {CC"getConstantPool0",   CC"(Ljava/lang/Class;)J",  (void*)&WB_GetConstantPool    },
2252   {CC"getConstantPoolCacheIndexTag0", CC"()I",  (void*)&WB_GetConstantPoolCacheIndexTag},
2253   {CC"getConstantPoolCacheLength0", CC"(Ljava/lang/Class;)I",  (void*)&WB_GetConstantPoolCacheLength},
2254   {CC"remapInstructionOperandFromCPCache0",
2255       CC"(Ljava/lang/Class;I)I",                      (void*)&WB_ConstantPoolRemapInstructionOperandFromCache},
2256   {CC"encodeConstantPoolIndyIndex0",
2257       CC"(I)I",                      (void*)&WB_ConstantPoolEncodeIndyIndex},
2258   {CC"getObjectsViaKlassOopMaps0",
2259       CC"(Ljava/lang/Object;)[Ljava/lang/Object;",    (void*)&WB_getObjectsViaKlassOopMaps},
2260   {CC"getObjectsViaOopIterator0",
2261           CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator},
2262   {CC"getObjectsViaFrameOopIterator",
2263       CC"(I)[Ljava/lang/Object;",                     (void*)&WB_getObjectsViaFrameOopIterator},
2264   {CC"getMethodBooleanOption",
2265       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
2266                                                       (void*)&WB_GetMethodBooleaneOption},
2267   {CC"getMethodIntxOption",
2268       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2269                                                       (void*)&WB_GetMethodIntxOption},
2270   {CC"getMethodUintxOption",
2271       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
2272                                                       (void*)&WB_GetMethodUintxOption},
2273   {CC"getMethodDoubleOption",
2274       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
2275                                                       (void*)&WB_GetMethodDoubleOption},
2276   {CC"getMethodStringOption",
2277       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
2278                                                       (void*)&WB_GetMethodStringOption},
2279   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
2280   {CC"isSharedClass",      CC"(Ljava/lang/Class;)Z",  (void*)&WB_IsSharedClass },
2281   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
2282   {CC"getResolvedReferences", CC"(Ljava/lang/Class;)Ljava/lang/Object;", (void*)&WB_GetResolvedReferences},
2283   {CC"areOpenArchiveHeapObjectsMapped",   CC"()Z",    (void*)&WB_AreOpenArchiveHeapObjectsMapped},
2284   {CC"isCDSIncludedInVmBuild",            CC"()Z",    (void*)&WB_IsCDSIncludedInVmBuild },
2285   {CC"isJFRIncludedInVmBuild",            CC"()Z",    (void*)&WB_IsJFRIncludedInVmBuild },
2286   {CC"isJavaHeapArchiveSupported",      CC"()Z",      (void*)&WB_IsJavaHeapArchiveSupported },
2287 
2288   {CC"clearInlineCaches0",  CC"(Z)V",                 (void*)&WB_ClearInlineCaches },
2289   {CC"handshakeWalkStack", CC"(Ljava/lang/Thread;Z)I", (void*)&WB_HandshakeWalkStack },
2290   {CC"addCompilerDirective",    CC"(Ljava/lang/String;)I",
2291                                                       (void*)&WB_AddCompilerDirective },
2292   {CC"removeCompilerDirective",   CC"(I)V",           (void*)&WB_RemoveCompilerDirective },
2293   {CC"isGCSupported",             CC"(I)Z",           (void*)&WB_IsGCSupported},
2294   {CC"isGCSelected",              CC"(I)Z",           (void*)&WB_IsGCSelected},
2295   {CC"isGCSelectedErgonomically", CC"()Z",            (void*)&WB_IsGCSelectedErgonomically},
2296   {CC"supportsConcurrentGCPhaseControl", CC"()Z",     (void*)&WB_SupportsConcurrentGCPhaseControl},
2297   {CC"getConcurrentGCPhases",     CC"()[Ljava/lang/String;",
2298                                                       (void*)&WB_GetConcurrentGCPhases},
2299   {CC"requestConcurrentGCPhase0", CC"(Ljava/lang/String;)Z",
2300                                                       (void*)&WB_RequestConcurrentGCPhase},
2301   {CC"checkLibSpecifiesNoexecstack", CC"(Ljava/lang/String;)Z",
2302                                                       (void*)&WB_CheckLibSpecifiesNoexecstack},
2303   {CC"isContainerized",           CC"()Z",            (void*)&WB_IsContainerized },
2304   {CC"printOsInfo",               CC"()V",            (void*)&WB_PrintOsInfo },
2305   {CC"disableElfSectionCache",    CC"()V",            (void*)&WB_DisableElfSectionCache },
2306   {CC"resolvedMethodRemovedCount",     CC"()I",       (void*)&WB_ResolvedMethodRemovedCount },
2307   {CC"protectionDomainRemovedCount",   CC"()I",       (void*)&WB_ProtectionDomainRemovedCount },
2308 };
2309 
2310 
2311 #undef CC
2312 
2313 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
2314   {
2315     if (WhiteBoxAPI) {
2316       // Make sure that wbclass is loaded by the null classloader
2317       InstanceKlass* ik = InstanceKlass::cast(JNIHandles::resolve(wbclass)->klass());
2318       Handle loader(THREAD, ik->class_loader());
2319       if (loader.is_null()) {
2320         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
2321         WhiteBox::set_used();
2322       }
2323     }
2324   }
2325 JVM_END