1 /*
   2  * Copyright (c) 2012, 2015, 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/stringTable.hpp"
  31 #include "code/codeCache.hpp"
  32 #include "jvmtifiles/jvmtiEnv.hpp"
  33 #include "memory/metadataFactory.hpp"
  34 #include "memory/universe.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "prims/wbtestmethods/parserTests.hpp"
  37 #include "prims/whitebox.hpp"
  38 #include "runtime/arguments.hpp"
  39 #include "runtime/compilationPolicy.hpp"
  40 #include "runtime/deoptimization.hpp"
  41 #include "runtime/interfaceSupport.hpp"
  42 #include "runtime/os.hpp"
  43 #include "runtime/sweeper.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/thread.hpp"
  46 #include "runtime/vm_version.hpp"
  47 #include "utilities/array.hpp"
  48 #include "utilities/debug.hpp"
  49 #include "utilities/exceptions.hpp"
  50 #include "utilities/macros.hpp"
  51 #if INCLUDE_ALL_GCS
  52 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp"
  53 #include "gc_implementation/g1/concurrentMark.hpp"
  54 #include "gc_implementation/g1/concurrentMarkThread.hpp"
  55 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
  56 #include "gc_implementation/g1/heapRegionRemSet.hpp"
  57 #endif // INCLUDE_ALL_GCS
  58 #if INCLUDE_NMT
  59 #include "services/mallocSiteTable.hpp"
  60 #include "services/memTracker.hpp"
  61 #include "utilities/nativeCallStack.hpp"
  62 #endif // INCLUDE_NMT
  63 
  64 
  65 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  66 
  67 #define SIZE_T_MAX_VALUE ((size_t) -1)
  68 
  69 bool WhiteBox::_used = false;
  70 volatile bool WhiteBox::compilation_locked = false;
  71 
  72 class VM_WhiteBoxOperation : public VM_Operation {
  73  public:
  74   VM_WhiteBoxOperation()                         { }
  75   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
  76   bool allow_nested_vm_operations() const        { return true; }
  77 };
  78 
  79 
  80 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
  81   return (jlong)(void*)JNIHandles::resolve(obj);
  82 WB_END
  83 
  84 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
  85   return heapOopSize;
  86 WB_END
  87 
  88 WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o))
  89   return os::vm_page_size();
  90 WB_END
  91 
  92 class WBIsKlassAliveClosure : public KlassClosure {
  93     Symbol* _name;
  94     bool _found;
  95 public:
  96     WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {}
  97 
  98     void do_klass(Klass* k) {
  99       if (_found) return;
 100       Symbol* ksym = k->name();
 101       if (ksym->fast_compare(_name) == 0) {
 102         _found = true;
 103       }
 104     }
 105 
 106     bool found() const {
 107         return _found;
 108     }
 109 };
 110 
 111 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
 112   Handle h_name = JNIHandles::resolve(name);
 113   if (h_name.is_null()) return false;
 114   Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
 115   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 116 
 117   WBIsKlassAliveClosure closure(sym);
 118   ClassLoaderDataGraph::classes_do(&closure);
 119 
 120   return closure.found();
 121 WB_END
 122 
 123 WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 124 #if INCLUDE_JVMTI
 125   ResourceMark rm;
 126   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 127   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 128   jvmtiError err = jvmti_env->AddToBootstrapClassLoaderSearch(seg);
 129   assert(err == JVMTI_ERROR_NONE, "must not fail");
 130 #endif
 131 }
 132 WB_END
 133 
 134 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 135 #if INCLUDE_JVMTI
 136   ResourceMark rm;
 137   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 138   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 139   jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg);
 140   assert(err == JVMTI_ERROR_NONE, "must not fail");
 141 #endif
 142 }
 143 WB_END
 144 
 145 
 146 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
 147   return (jlong)Arguments::max_heap_for_compressed_oops();
 148 }
 149 WB_END
 150 
 151 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
 152   CollectorPolicy * p = Universe::heap()->collector_policy();
 153   gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap "
 154     SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Space alignment "SIZE_FORMAT" Heap alignment "SIZE_FORMAT,
 155     p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(),
 156     p->space_alignment(), p->heap_alignment());
 157 }
 158 WB_END
 159 
 160 #ifndef PRODUCT
 161 // Forward declaration
 162 void TestReservedSpace_test();
 163 void TestReserveMemorySpecial_test();
 164 void TestVirtualSpace_test();
 165 void TestMetaspaceAux_test();
 166 #endif
 167 
 168 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
 169 #ifndef PRODUCT
 170   TestReservedSpace_test();
 171   TestReserveMemorySpecial_test();
 172   TestVirtualSpace_test();
 173   TestMetaspaceAux_test();
 174 #endif
 175 WB_END
 176 
 177 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
 178   size_t granularity = os::vm_allocation_granularity();
 179   ReservedHeapSpace rhs(100 * granularity, granularity, false);
 180   VirtualSpace vs;
 181   vs.initialize(rhs, 50 * granularity);
 182 
 183   // Check if constraints are complied
 184   if (!( UseCompressedOops && rhs.base() != NULL &&
 185          Universe::narrow_oop_base() != NULL &&
 186          Universe::narrow_oop_use_implicit_null_checks() )) {
 187     tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
 188                   "\tUseCompressedOops is %d\n"
 189                   "\trhs.base() is "PTR_FORMAT"\n"
 190                   "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n"
 191                   "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
 192                   UseCompressedOops,
 193                   rhs.base(),
 194                   Universe::narrow_oop_base(),
 195                   Universe::narrow_oop_use_implicit_null_checks());
 196     return;
 197   }
 198   tty->print_cr("Reading from no access area... ");
 199   tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
 200                 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
 201 WB_END
 202 
 203 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
 204                                            size_t magnitude, size_t iterations) {
 205   size_t granularity = os::vm_allocation_granularity();
 206   ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false);
 207   VirtualSpace vs;
 208   if (!vs.initialize(rhs, 0)) {
 209     tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
 210     return 3;
 211   }
 212 
 213   long seed = os::random();
 214   tty->print_cr("Random seed is %ld", seed);
 215   os::init_random(seed);
 216 
 217   for (size_t i = 0; i < iterations; i++) {
 218 
 219     // Whether we will shrink or grow
 220     bool shrink = os::random() % 2L == 0;
 221 
 222     // Get random delta to resize virtual space
 223     size_t delta = (size_t)os::random() % magnitude;
 224 
 225     // If we are about to shrink virtual space below zero, then expand instead
 226     if (shrink && vs.committed_size() < delta) {
 227       shrink = false;
 228     }
 229 
 230     // Resizing by delta
 231     if (shrink) {
 232       vs.shrink_by(delta);
 233     } else {
 234       // If expanding fails expand_by will silently return false
 235       vs.expand_by(delta, true);
 236     }
 237   }
 238   return 0;
 239 }
 240 
 241 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
 242         jlong reserved_space_size, jlong magnitude, jlong iterations))
 243   tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", "
 244                 "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude,
 245                 iterations);
 246   if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
 247     tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
 248     return 1;
 249   }
 250 
 251   // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
 252   // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
 253   if (sizeof(size_t) < sizeof(jlong)) {
 254     jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
 255     if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
 256         || iterations > size_t_max_value) {
 257       tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
 258       return 2;
 259     }
 260   }
 261 
 262   return wb_stress_virtual_space_resize((size_t) reserved_space_size,
 263                                         (size_t) magnitude, (size_t) iterations);
 264 WB_END
 265 
 266 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj))
 267   oop p = JNIHandles::resolve(obj);
 268 #if INCLUDE_ALL_GCS
 269   if (UseG1GC) {
 270     G1CollectedHeap* g1 = G1CollectedHeap::heap();
 271     const HeapRegion* hr = g1->heap_region_containing(p);
 272     if (hr == NULL) {
 273       return false;
 274     }
 275     return !(hr->is_young());
 276   } else if (UseParallelGC) {
 277     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 278     return !psh->is_in_young(p);
 279   }
 280 #endif // INCLUDE_ALL_GCS
 281   GenCollectedHeap* gch = GenCollectedHeap::heap();
 282   return !gch->is_in_young(p);
 283 WB_END
 284 
 285 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
 286   oop p = JNIHandles::resolve(obj);
 287   return p->size() * HeapWordSize;
 288 WB_END
 289 
 290 #if INCLUDE_ALL_GCS
 291 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
 292   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 293   oop result = JNIHandles::resolve(obj);
 294   const HeapRegion* hr = g1->heap_region_containing(result);
 295   return hr->is_humongous();
 296 WB_END
 297 
 298 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
 299   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 300   size_t nr = g1->num_free_regions();
 301   return (jlong)nr;
 302 WB_END
 303 
 304 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
 305   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 306   return g1->concurrent_mark()->cmThread()->during_cycle();
 307 WB_END
 308 
 309 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
 310   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 311   if (!g1h->concurrent_mark()->cmThread()->during_cycle()) {
 312     g1h->collect(GCCause::_wb_conc_mark);
 313     return true;
 314   }
 315   return false;
 316 WB_END
 317 
 318 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
 319   return (jint)HeapRegion::GrainBytes;
 320 WB_END
 321 #endif // INCLUDE_ALL_GCS
 322 
 323 #if INCLUDE_NMT
 324 // Alloc memory using the test memory type so that we can use that to see if
 325 // NMT picks it up correctly
 326 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
 327   jlong addr = 0;
 328   addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
 329   return addr;
 330 WB_END
 331 
 332 // Alloc memory with pseudo call stack. The test can create psudo malloc
 333 // allocation site to stress the malloc tracking.
 334 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
 335   address pc = (address)(size_t)pseudo_stack;
 336   NativeCallStack stack(&pc, 1);
 337   return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
 338 WB_END
 339 
 340 // Free the memory allocated by NMTAllocTest
 341 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
 342   os::free((void*)(uintptr_t)mem);
 343 WB_END
 344 
 345 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
 346   jlong addr = 0;
 347 
 348   addr = (jlong)(uintptr_t)os::reserve_memory(size);
 349   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 350 
 351   return addr;
 352 WB_END
 353 
 354 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 355   os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
 356   MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
 357 WB_END
 358 
 359 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 360   os::uncommit_memory((char *)(uintptr_t)addr, size);
 361 WB_END
 362 
 363 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 364   os::release_memory((char *)(uintptr_t)addr, size);
 365 WB_END
 366 
 367 WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
 368   // Test that we can downgrade NMT levels but not upgrade them.
 369   if (MemTracker::tracking_level() == NMT_off) {
 370     MemTracker::transition_to(NMT_off);
 371     return MemTracker::tracking_level() == NMT_off;
 372   } else {
 373     assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
 374     MemTracker::transition_to(NMT_summary);
 375     assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
 376 
 377     // Can't go to detail once NMT is set to summary.
 378     MemTracker::transition_to(NMT_detail);
 379     assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now");
 380 
 381     // Shutdown sets tracking level to minimal.
 382     MemTracker::shutdown();
 383     assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now");
 384 
 385     // Once the tracking level is minimal, we cannot increase to summary.
 386     // The code ignores this request instead of asserting because if the malloc site
 387     // table overflows in another thread, it tries to change the code to summary.
 388     MemTracker::transition_to(NMT_summary);
 389     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 390 
 391     // Really can never go up to detail, verify that the code would never do this.
 392     MemTracker::transition_to(NMT_detail);
 393     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 394     return MemTracker::tracking_level() == NMT_minimal;
 395   }
 396 WB_END
 397 
 398 WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
 399   int hash_size = MallocSiteTable::hash_buckets();
 400   assert(hash_size > 0, "NMT hash_size should be > 0");
 401   return (jint)hash_size;
 402 WB_END
 403 #endif // INCLUDE_NMT
 404 
 405 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
 406   assert(method != NULL, "method should not be null");
 407   ThreadToNativeFromVM ttn(thread);
 408   return env->FromReflectedMethod(method);
 409 }
 410 
 411 // Deoptimizes all compiled frames and makes nmethods not entrant if it's requested
 412 class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation {
 413  private:
 414   int _result;
 415   const bool _make_not_entrant;
 416  public:
 417   VM_WhiteBoxDeoptimizeFrames(bool make_not_entrant) :
 418         _result(0), _make_not_entrant(make_not_entrant) { }
 419   int  result() const { return _result; }
 420 
 421   void doit() {
 422     for (JavaThread* t = Threads::first(); t != NULL; t = t->next()) {
 423       if (t->has_last_Java_frame()) {
 424         for (StackFrameStream fst(t, UseBiasedLocking); !fst.is_done(); fst.next()) {
 425           frame* f = fst.current();
 426           if (f->can_be_deoptimized() && !f->is_deoptimized_frame()) {
 427             RegisterMap* reg_map = fst.register_map();
 428             Deoptimization::deoptimize(t, *f, reg_map);
 429             if (_make_not_entrant) {
 430                 nmethod* nm = CodeCache::find_nmethod(f->pc());
 431                 assert(nm != NULL, "sanity check");
 432                 nm->make_not_entrant();
 433             }
 434             ++_result;
 435           }
 436         }
 437       }
 438     }
 439   }
 440 };
 441 
 442 WB_ENTRY(jint, WB_DeoptimizeFrames(JNIEnv* env, jobject o, jboolean make_not_entrant))
 443   VM_WhiteBoxDeoptimizeFrames op(make_not_entrant == JNI_TRUE);
 444   VMThread::execute(&op);
 445   return op.result();
 446 WB_END
 447 
 448 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
 449   MutexLockerEx mu(Compile_lock);
 450   CodeCache::mark_all_nmethods_for_deoptimization();
 451   VM_Deoptimize op;
 452   VMThread::execute(&op);
 453 WB_END
 454 
 455 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 456   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 457   int result = 0;
 458   CHECK_JNI_EXCEPTION_(env, result);
 459   MutexLockerEx mu(Compile_lock);
 460   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 461   if (is_osr) {
 462     result += mh->mark_osr_nmethods();
 463   } else if (mh->code() != NULL) {
 464     mh->code()->mark_for_deoptimization();
 465     ++result;
 466   }
 467   result += CodeCache::mark_for_deoptimization(mh());
 468   if (result > 0) {
 469     VM_Deoptimize op;
 470     VMThread::execute(&op);
 471   }
 472   return result;
 473 WB_END
 474 
 475 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 476   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 477   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 478   MutexLockerEx mu(Compile_lock);
 479   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 480   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 481   if (code == NULL) {
 482     return JNI_FALSE;
 483   }
 484   return (code->is_alive() && !code->is_marked_for_deoptimization());
 485 WB_END
 486 
 487 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 488   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 489   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 490   MutexLockerEx mu(Compile_lock);
 491   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 492   if (is_osr) {
 493     return CompilationPolicy::can_be_osr_compiled(mh, comp_level);
 494   } else {
 495     return CompilationPolicy::can_be_compiled(mh, comp_level);
 496   }
 497 WB_END
 498 
 499 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method))
 500   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 501   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 502   MutexLockerEx mu(Compile_lock);
 503   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 504   return mh->queued_for_compilation();
 505 WB_END
 506 
 507 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 508   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 509   CHECK_JNI_EXCEPTION_(env, CompLevel_none);
 510   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 511   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 512   return (code != NULL ? code->comp_level() : CompLevel_none);
 513 WB_END
 514 
 515 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 516   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 517   CHECK_JNI_EXCEPTION(env);
 518   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 519   if (is_osr) {
 520     mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox");
 521   } else {
 522     mh->set_not_compilable(comp_level, true /* report */, "WhiteBox");
 523   }
 524 WB_END
 525 
 526 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
 527   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 528   CHECK_JNI_EXCEPTION_(env, InvocationEntryBci);
 529   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 530   nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
 531   return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
 532 WB_END
 533 
 534 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 535   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 536   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 537   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 538   bool result = mh->dont_inline();
 539   mh->set_dont_inline(value == JNI_TRUE);
 540   return result;
 541 WB_END
 542 
 543 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
 544   if (comp_level == CompLevel_any) {
 545     return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
 546         CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
 547   } else {
 548     return CompileBroker::queue_size(comp_level);
 549   }
 550 WB_END
 551 
 552 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 553   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 554   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 555   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 556   bool result = mh->force_inline();
 557   mh->set_force_inline(value == JNI_TRUE);
 558   return result;
 559 WB_END
 560 
 561 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
 562   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 563   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 564   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 565   nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD);
 566   MutexLockerEx mu(Compile_lock);
 567   return (mh->queued_for_compilation() || nm != NULL);
 568 WB_END
 569 
 570 class AlwaysFalseClosure : public BoolObjectClosure {
 571  public:
 572   bool do_object_b(oop p) { return false; }
 573 };
 574 
 575 static AlwaysFalseClosure always_false;
 576 
 577 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
 578   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 579   CHECK_JNI_EXCEPTION(env);
 580   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 581   MutexLockerEx mu(Compile_lock);
 582   MethodData* mdo = mh->method_data();
 583   MethodCounters* mcs = mh->method_counters();
 584 
 585   if (mdo != NULL) {
 586     mdo->init();
 587     ResourceMark rm;
 588     int arg_count = mdo->method()->size_of_parameters();
 589     for (int i = 0; i < arg_count; i++) {
 590       mdo->set_arg_modified(i, 0);
 591     }
 592     MutexLockerEx mu(mdo->extra_data_lock());
 593     mdo->clean_method_data(&always_false);
 594   }
 595 
 596   mh->clear_not_c1_compilable();
 597   mh->clear_not_c2_compilable();
 598   mh->clear_not_c2_osr_compilable();
 599   NOT_PRODUCT(mh->set_compiled_invocation_count(0));
 600   if (mcs != NULL) {
 601     mcs->backedge_counter()->init();
 602     mcs->invocation_counter()->init();
 603     mcs->set_interpreter_invocation_count(0);
 604     mcs->set_interpreter_throwout_count(0);
 605 
 606 #ifdef TIERED
 607     mcs->set_rate(0.0F);
 608     mh->set_prev_event_count(0);
 609     mh->set_prev_time(0);
 610 #endif
 611   }
 612 WB_END
 613 
 614 template <typename T>
 615 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*, bool, bool)) {
 616   if (name == NULL) {
 617     return false;
 618   }
 619   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 620   const char* flag_name = env->GetStringUTFChars(name, NULL);
 621   bool result = (*TAt)(flag_name, value, true, true);
 622   env->ReleaseStringUTFChars(name, flag_name);
 623   return result;
 624 }
 625 
 626 template <typename T>
 627 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAtPut)(const char*, T*, Flag::Flags)) {
 628   if (name == NULL) {
 629     return false;
 630   }
 631   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 632   const char* flag_name = env->GetStringUTFChars(name, NULL);
 633   bool result = (*TAtPut)(flag_name, value, Flag::INTERNAL);
 634   env->ReleaseStringUTFChars(name, flag_name);
 635   return result;
 636 }
 637 
 638 template <typename T>
 639 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
 640   ResourceMark rm(thread);
 641   jclass clazz = env->FindClass(name->as_C_string());
 642   CHECK_JNI_EXCEPTION_(env, NULL);
 643   jmethodID methodID = env->GetStaticMethodID(clazz,
 644         vmSymbols::valueOf_name()->as_C_string(),
 645         sig->as_C_string());
 646   CHECK_JNI_EXCEPTION_(env, NULL);
 647   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
 648   CHECK_JNI_EXCEPTION_(env, NULL);
 649   return result;
 650 }
 651 
 652 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
 653   return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
 654 }
 655 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
 656   return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
 657 }
 658 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
 659   return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
 660 }
 661 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
 662   return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
 663 }*/
 664 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
 665   return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
 666 }
 667 
 668 static Flag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
 669   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 670   const char* flag_name = env->GetStringUTFChars(name, NULL);
 671   Flag* result = Flag::find_flag(flag_name, strlen(flag_name), true, true);
 672   env->ReleaseStringUTFChars(name, flag_name);
 673   return result;
 674 }
 675 
 676 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name))
 677   Flag* flag = getVMFlag(thread, env, name);
 678   return (flag != NULL) && flag->is_constant_in_binary();
 679 WB_END
 680 
 681 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name))
 682   Flag* flag = getVMFlag(thread, env, name);
 683   return (flag != NULL) && !(flag->is_unlocked() || flag->is_unlocker());
 684 WB_END
 685 
 686 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
 687   bool result;
 688   if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) {
 689     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 690     return booleanBox(thread, env, result);
 691   }
 692   return NULL;
 693 WB_END
 694 
 695 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
 696   intx result;
 697   if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) {
 698     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 699     return longBox(thread, env, result);
 700   }
 701   return NULL;
 702 WB_END
 703 
 704 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
 705   uintx result;
 706   if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) {
 707     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 708     return longBox(thread, env, result);
 709   }
 710   return NULL;
 711 WB_END
 712 
 713 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
 714   uint64_t result;
 715   if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) {
 716     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 717     return longBox(thread, env, result);
 718   }
 719   return NULL;
 720 WB_END
 721 
 722 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
 723   uintx result;
 724   if (GetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAt)) {
 725     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 726     return longBox(thread, env, result);
 727   }
 728   return NULL;
 729 WB_END
 730 
 731 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
 732   double result;
 733   if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) {
 734     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 735     return doubleBox(thread, env, result);
 736   }
 737   return NULL;
 738 WB_END
 739 
 740 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
 741   ccstr ccstrResult;
 742   if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) {
 743     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 744     jstring result = env->NewStringUTF(ccstrResult);
 745     CHECK_JNI_EXCEPTION_(env, NULL);
 746     return result;
 747   }
 748   return NULL;
 749 WB_END
 750 
 751 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
 752   bool result = value == JNI_TRUE ? true : false;
 753   SetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAtPut);
 754 WB_END
 755 
 756 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 757   intx result = value;
 758   SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut);
 759 WB_END
 760 
 761 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 762   uintx result = value;
 763   SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut);
 764 WB_END
 765 
 766 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 767   uint64_t result = value;
 768   SetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAtPut);
 769 WB_END
 770 
 771 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 772   size_t result = value;
 773   SetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAtPut);
 774 WB_END
 775 
 776 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
 777   double result = value;
 778   SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut);
 779 WB_END
 780 
 781 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
 782   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 783   const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL);
 784   ccstr ccstrResult = ccstrValue;
 785   bool needFree;
 786   {
 787     ThreadInVMfromNative ttvfn(thread); // back to VM
 788     needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut);
 789   }
 790   if (value != NULL) {
 791     env->ReleaseStringUTFChars(value, ccstrValue);
 792   }
 793   if (needFree) {
 794     FREE_C_HEAP_ARRAY(char, ccstrResult);
 795   }
 796 WB_END
 797 
 798 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
 799   WhiteBox::compilation_locked = true;
 800 WB_END
 801 
 802 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
 803   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
 804   WhiteBox::compilation_locked = false;
 805   mo.notify_all();
 806 WB_END
 807 
 808 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
 809   // Force a code cache sweep and block until it finished
 810   NMethodSweeper::force_sweep();





































 811 WB_END
 812 
 813 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
 814   ResourceMark rm(THREAD);
 815   int len;
 816   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
 817   return (StringTable::lookup(name, len) != NULL);
 818 WB_END
 819 
 820 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
 821   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
 822   Universe::heap()->collect(GCCause::_last_ditch_collection);
 823 #if INCLUDE_ALL_GCS
 824   if (UseG1GC) {
 825     // Needs to be cleared explicitly for G1
 826     Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false);
 827   }
 828 #endif // INCLUDE_ALL_GCS
 829 WB_END
 830 
 831 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
 832   Universe::heap()->collect(GCCause::_wb_young_gc);
 833 WB_END
 834 
 835 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
 836   // static+volatile in order to force the read to happen
 837   // (not be eliminated by the compiler)
 838   static char c;
 839   static volatile char* p;
 840 
 841   p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
 842   if (p == NULL) {
 843     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
 844   }
 845 
 846   c = *p;
 847 WB_END
 848 
 849 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
 850   const char* cpu_features = VM_Version::cpu_features();
 851   ThreadToNativeFromVM ttn(thread);
 852   jstring features_string = env->NewStringUTF(cpu_features);
 853 
 854   CHECK_JNI_EXCEPTION_(env, NULL);
 855 
 856   return features_string;
 857 WB_END
 858 
 859 int WhiteBox::get_blob_type(const CodeBlob* code) {
 860   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 861   return CodeCache::get_code_heap(code)->code_blob_type();
 862 }
 863 
 864 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
 865   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 866   return CodeCache::get_code_heap(blob_type);
 867 }
 868 
 869 struct CodeBlobStub {
 870   CodeBlobStub(const CodeBlob* blob) :
 871       name(os::strdup(blob->name())),
 872       size(blob->size()),
 873       blob_type(WhiteBox::get_blob_type(blob)) { }
 874   ~CodeBlobStub() { os::free((void*) name); }
 875   const char* const name;
 876   const int         size;
 877   const int         blob_type;
 878 };
 879 
 880 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
 881   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
 882   CHECK_JNI_EXCEPTION_(env, NULL);
 883   jobjectArray result = env->NewObjectArray(3, clazz, NULL);
 884 
 885   jstring name = env->NewStringUTF(cb->name);
 886   CHECK_JNI_EXCEPTION_(env, NULL);
 887   env->SetObjectArrayElement(result, 0, name);
 888 
 889   jobject obj = integerBox(thread, env, cb->size);
 890   CHECK_JNI_EXCEPTION_(env, NULL);
 891   env->SetObjectArrayElement(result, 1, obj);
 892 
 893   obj = integerBox(thread, env, cb->blob_type);
 894   CHECK_JNI_EXCEPTION_(env, NULL);
 895   env->SetObjectArrayElement(result, 2, obj);
 896 
 897   return result;
 898 }
 899 
 900 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 901   ResourceMark rm(THREAD);
 902   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 903   CHECK_JNI_EXCEPTION_(env, NULL);
 904   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 905   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 906   jobjectArray result = NULL;
 907   if (code == NULL) {
 908     return result;
 909   }
 910   int insts_size = code->insts_size();
 911 
 912   ThreadToNativeFromVM ttn(thread);
 913   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
 914   CHECK_JNI_EXCEPTION_(env, NULL);
 915   result = env->NewObjectArray(4, clazz, NULL);
 916   if (result == NULL) {
 917     return result;
 918   }
 919 
 920   CodeBlobStub stub(code);
 921   jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
 922   env->SetObjectArrayElement(result, 0, codeBlob);
 923 
 924   jobject level = integerBox(thread, env, code->comp_level());
 925   CHECK_JNI_EXCEPTION_(env, NULL);
 926   env->SetObjectArrayElement(result, 1, level);
 927 
 928   jbyteArray insts = env->NewByteArray(insts_size);
 929   CHECK_JNI_EXCEPTION_(env, NULL);
 930   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
 931   env->SetObjectArrayElement(result, 2, insts);
 932 
 933   jobject id = integerBox(thread, env, code->compile_id());
 934   CHECK_JNI_EXCEPTION_(env, NULL);
 935   env->SetObjectArrayElement(result, 3, id);
 936 
 937   return result;
 938 WB_END
 939 
 940 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
 941   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 942   BufferBlob* blob;
 943   int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
 944   if (full_size < size) {
 945     full_size += round_to(size - full_size, oopSize);
 946   }
 947   {
 948     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 949     blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
 950     ::new (blob) BufferBlob("WB::DummyBlob", full_size);
 951   }
 952   // Track memory usage statistic after releasing CodeCache_lock
 953   MemoryService::track_code_cache_memory_usage();
 954   return blob;
 955 }
 956 
 957 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
 958     return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
 959 WB_END
 960 
 961 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
 962     BufferBlob::free((BufferBlob*) addr);
 963 WB_END
 964 
 965 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
 966   ResourceMark rm;
 967   GrowableArray<CodeBlobStub*> blobs;
 968   {
 969     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
 970     CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
 971     if (heap == NULL) {
 972       return NULL;
 973     }
 974     for (CodeBlob* cb = (CodeBlob*) heap->first();
 975          cb != NULL; cb = (CodeBlob*) heap->next(cb)) {
 976       CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub);
 977       new (stub) CodeBlobStub(cb);
 978       blobs.append(stub);
 979     }
 980   }
 981   if (blobs.length() == 0) {
 982     return NULL;
 983   }
 984   ThreadToNativeFromVM ttn(thread);
 985   jobjectArray result = NULL;
 986   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
 987   CHECK_JNI_EXCEPTION_(env, NULL);
 988   result = env->NewObjectArray(blobs.length(), clazz, NULL);
 989   if (result == NULL) {
 990     return result;
 991   }
 992   int i = 0;
 993   for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin();
 994        it != blobs.end(); ++it) {
 995     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
 996     env->SetObjectArrayElement(result, i, obj);
 997     ++i;
 998   }
 999   return result;
1000 WB_END
1001 
1002 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1003   return CompileBroker::get_compilation_activity_mode();
1004 WB_END
1005 
1006 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1007     ThreadToNativeFromVM ttn(thread);
1008     CodeBlobStub stub((CodeBlob*) addr);
1009     return codeBlob2objectArray(thread, env, &stub);
1010 WB_END
1011 
1012 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1013   return (jlong) Thread::current()->stack_size();
1014 WB_END
1015 
1016 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1017   JavaThread* t = JavaThread::current();
1018   return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size();
1019 WB_END
1020 
1021 int WhiteBox::array_bytes_to_length(size_t bytes) {
1022   return Array<u1>::bytes_to_length(bytes);
1023 }
1024 
1025 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1026   if (size < 0) {
1027     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1028         err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1029   }
1030 
1031   oop class_loader_oop = JNIHandles::resolve(class_loader);
1032   ClassLoaderData* cld = class_loader_oop != NULL
1033       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1034       : ClassLoaderData::the_null_class_loader_data();
1035 
1036   void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1037 
1038   return (jlong)(uintptr_t)metadata;
1039 WB_END
1040 
1041 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1042   oop class_loader_oop = JNIHandles::resolve(class_loader);
1043   ClassLoaderData* cld = class_loader_oop != NULL
1044       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1045       : ClassLoaderData::the_null_class_loader_data();
1046 
1047   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1048 WB_END
1049 
1050 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1051   if (inc < 0) {
1052     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1053         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1054   }
1055 
1056   jlong max_size_t = (jlong) ((size_t) -1);
1057   if (inc > max_size_t) {
1058     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1059         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1060   }
1061 
1062   size_t new_cap_until_GC = 0;
1063   size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment());
1064   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1065   if (!success) {
1066     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1067                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
1068                 "due to contention with another thread");
1069   }
1070   return (jlong) new_cap_until_GC;
1071 WB_END
1072 
1073 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
1074   return (jlong) MetaspaceGC::capacity_until_GC();
1075 WB_END
1076 
1077 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1078   Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1079                                            Monitor::_safepoint_check_always :
1080                                            Monitor::_safepoint_check_never;
1081   MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1082                    attemptedNoSafepointValue == JNI_TRUE);
1083 WB_END
1084 
1085 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1086   oop obj_oop = JNIHandles::resolve(obj);
1087   return (jboolean) obj_oop->mark()->has_monitor();
1088 WB_END
1089 
1090 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1091   VM_ForceSafepoint force_safepoint_op;
1092   VMThread::execute(&force_safepoint_op);
1093 WB_END
1094 
1095 template <typename T>
1096 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1097   assert(value != NULL, "sanity");
1098   if (method == NULL || name == NULL) {
1099     return false;
1100   }
1101   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1102   CHECK_JNI_EXCEPTION_(env, false);
1103   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1104   // can't be in VM when we call JNI
1105   ThreadToNativeFromVM ttnfv(thread);
1106   const char* flag_name = env->GetStringUTFChars(name, NULL);
1107   bool result =  CompilerOracle::has_option_value(mh, flag_name, *value);
1108   env->ReleaseStringUTFChars(name, flag_name);
1109   return result;
1110 }
1111 
1112 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1113   bool result;
1114   if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1115     // can't be in VM when we call JNI
1116     ThreadToNativeFromVM ttnfv(thread);
1117     return booleanBox(thread, env, result);
1118   }
1119   return NULL;
1120 WB_END
1121 
1122 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1123   intx result;
1124   if (GetMethodOption <intx> (thread, env, method, name, &result)) {
1125     // can't be in VM when we call JNI
1126     ThreadToNativeFromVM ttnfv(thread);
1127     return longBox(thread, env, result);
1128   }
1129   return NULL;
1130 WB_END
1131 
1132 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1133   uintx result;
1134   if (GetMethodOption <uintx> (thread, env, method, name, &result)) {
1135     // can't be in VM when we call JNI
1136     ThreadToNativeFromVM ttnfv(thread);
1137     return longBox(thread, env, result);
1138   }
1139   return NULL;
1140 WB_END
1141 
1142 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1143   double result;
1144   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1145     // can't be in VM when we call JNI
1146     ThreadToNativeFromVM ttnfv(thread);
1147     return doubleBox(thread, env, result);
1148   }
1149   return NULL;
1150 WB_END
1151 
1152 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1153   ccstr ccstrResult;
1154   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1155     // can't be in VM when we call JNI
1156     ThreadToNativeFromVM ttnfv(thread);
1157     jstring result = env->NewStringUTF(ccstrResult);
1158     CHECK_JNI_EXCEPTION_(env, NULL);
1159     return result;
1160   }
1161   return NULL;
1162 WB_END
1163 
1164 //Some convenience methods to deal with objects from java
1165 int WhiteBox::offset_for_field(const char* field_name, oop object,
1166     Symbol* signature_symbol) {
1167   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1168   Thread* THREAD = Thread::current();
1169 
1170   //Get the class of our object
1171   Klass* arg_klass = object->klass();
1172   //Turn it into an instance-klass
1173   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1174 
1175   //Create symbols to look for in the class
1176   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1177       THREAD);
1178 
1179   //To be filled in with an offset of the field we're looking for
1180   fieldDescriptor fd;
1181 
1182   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1183   if (res == NULL) {
1184     tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1185         name_symbol->as_C_string());
1186     fatal("Invalid layout of preloaded class");
1187   }
1188 
1189   //fetch the field at the offset we've found
1190   int dest_offset = fd.offset();
1191 
1192   return dest_offset;
1193 }
1194 
1195 
1196 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1197   int offset = offset_for_field(field_name, object,
1198       vmSymbols::string_signature());
1199   oop string = object->obj_field(offset);
1200   if (string == NULL) {
1201     return NULL;
1202   }
1203   const char* ret = java_lang_String::as_utf8_string(string);
1204   return ret;
1205 }
1206 
1207 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
1208   int offset =
1209       offset_for_field(field_name, object, vmSymbols::bool_signature());
1210   bool ret = (object->bool_field(offset) == JNI_TRUE);
1211   return ret;
1212 }
1213 
1214 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
1215   ResourceMark rm;
1216   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
1217 
1218   //  one by one registration natives for exception catching
1219   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
1220   CHECK_JNI_EXCEPTION(env);
1221   for (int i = 0, n = method_count; i < n; ++i) {
1222     // Skip dummy entries
1223     if (method_array[i].fnPtr == NULL) continue;
1224     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
1225       jthrowable throwable_obj = env->ExceptionOccurred();
1226       if (throwable_obj != NULL) {
1227         env->ExceptionClear();
1228         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
1229           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
1230           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
1231           tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
1232               method_array[i].name, method_array[i].signature);
1233         }
1234       } else {
1235         // Registration failed unexpectedly.
1236         tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
1237             method_array[i].name, method_array[i].signature);
1238         env->UnregisterNatives(wbclass);
1239         break;
1240       }
1241     }
1242   }
1243 }
1244 
1245 #define CC (char*)
1246 
1247 static JNINativeMethod methods[] = {
1248   {CC"getObjectAddress",   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1249   {CC"getObjectSize",      CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1250   {CC"isObjectInOldGen",   CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1251   {CC"getHeapOopSize",     CC"()I",                   (void*)&WB_GetHeapOopSize    },
1252   {CC"getVMPageSize",      CC"()I",                   (void*)&WB_GetVMPageSize     },
1253   {CC"isClassAlive0",      CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1254   {CC"parseCommandLine",
1255       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1256       (void*) &WB_ParseCommandLine
1257   },
1258   {CC"addToBootstrapClassLoaderSearch", CC"(Ljava/lang/String;)V",
1259                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1260   {CC"addToSystemClassLoaderSearch",    CC"(Ljava/lang/String;)V",
1261                                                       (void*)&WB_AddToSystemClassLoaderSearch},
1262   {CC"getCompressedOopsMaxHeapSize", CC"()J",
1263       (void*)&WB_GetCompressedOopsMaxHeapSize},
1264   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
1265   {CC"runMemoryUnitTests", CC"()V",                   (void*)&WB_RunMemoryUnitTests},
1266   {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
1267   {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
1268 #if INCLUDE_ALL_GCS
1269   {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
1270   {CC"g1IsHumongous",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
1271   {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
1272   {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
1273   {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
1274 #endif // INCLUDE_ALL_GCS
1275 #if INCLUDE_NMT
1276   {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
1277   {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
1278   {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
1279   {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
1280   {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
1281   {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
1282   {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
1283   {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
1284   {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
1285 #endif // INCLUDE_NMT
1286   {CC"deoptimizeFrames",   CC"(Z)I",                  (void*)&WB_DeoptimizeFrames  },
1287   {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
1288   {CC"deoptimizeMethod",   CC"(Ljava/lang/reflect/Executable;Z)I",
1289                                                       (void*)&WB_DeoptimizeMethod  },
1290   {CC"isMethodCompiled",   CC"(Ljava/lang/reflect/Executable;Z)Z",
1291                                                       (void*)&WB_IsMethodCompiled  },
1292   {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z",
1293                                                       (void*)&WB_IsMethodCompilable},
1294   {CC"isMethodQueuedForCompilation",
1295       CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
1296   {CC"makeMethodNotCompilable",
1297       CC"(Ljava/lang/reflect/Executable;IZ)V",        (void*)&WB_MakeMethodNotCompilable},
1298   {CC"testSetDontInlineMethod",
1299       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetDontInlineMethod},
1300   {CC"getMethodCompilationLevel",
1301       CC"(Ljava/lang/reflect/Executable;Z)I",         (void*)&WB_GetMethodCompilationLevel},
1302   {CC"getMethodEntryBci",
1303       CC"(Ljava/lang/reflect/Executable;)I",          (void*)&WB_GetMethodEntryBci},
1304   {CC"getCompileQueueSize",
1305       CC"(I)I",                                       (void*)&WB_GetCompileQueueSize},
1306   {CC"testSetForceInlineMethod",
1307       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetForceInlineMethod},
1308   {CC"enqueueMethodForCompilation",
1309       CC"(Ljava/lang/reflect/Executable;II)Z",        (void*)&WB_EnqueueMethodForCompilation},
1310   {CC"clearMethodState",
1311       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_ClearMethodState},
1312   {CC"lockCompilation",    CC"()V",                   (void*)&WB_LockCompilation},
1313   {CC"unlockCompilation",  CC"()V",                   (void*)&WB_UnlockCompilation},
1314   {CC"isConstantVMFlag",   CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag},
1315   {CC"isLockedVMFlag",     CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag},
1316   {CC"setBooleanVMFlag",   CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
1317   {CC"setIntxVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
1318   {CC"setUintxVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
1319   {CC"setUint64VMFlag",    CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
1320   {CC"setSizeTVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag},
1321   {CC"setDoubleVMFlag",    CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
1322   {CC"setStringVMFlag",    CC"(Ljava/lang/String;Ljava/lang/String;)V",
1323                                                       (void*)&WB_SetStringVMFlag},
1324   {CC"getBooleanVMFlag",   CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
1325                                                       (void*)&WB_GetBooleanVMFlag},
1326   {CC"getIntxVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
1327                                                       (void*)&WB_GetIntxVMFlag},
1328   {CC"getUintxVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1329                                                       (void*)&WB_GetUintxVMFlag},
1330   {CC"getUint64VMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Long;",
1331                                                       (void*)&WB_GetUint64VMFlag},
1332   {CC"getSizeTVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1333                                                       (void*)&WB_GetSizeTVMFlag},
1334   {CC"getDoubleVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Double;",
1335                                                       (void*)&WB_GetDoubleVMFlag},
1336   {CC"getStringVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/String;",
1337                                                       (void*)&WB_GetStringVMFlag},
1338   {CC"isInStringTable",    CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable  },
1339   {CC"fullGC",   CC"()V",                             (void*)&WB_FullGC },
1340   {CC"youngGC",  CC"()V",                             (void*)&WB_YoungGC },
1341   {CC"readReservedMemory", CC"()V",                   (void*)&WB_ReadReservedMemory },
1342   {CC"allocateMetaspace",
1343      CC"(Ljava/lang/ClassLoader;J)J",                 (void*)&WB_AllocateMetaspace },
1344   {CC"freeMetaspace",
1345      CC"(Ljava/lang/ClassLoader;JJ)V",                (void*)&WB_FreeMetaspace },
1346   {CC"incMetaspaceCapacityUntilGC", CC"(J)J",         (void*)&WB_IncMetaspaceCapacityUntilGC },
1347   {CC"metaspaceCapacityUntilGC", CC"()J",             (void*)&WB_MetaspaceCapacityUntilGC },
1348   {CC"getCPUFeatures",     CC"()Ljava/lang/String;",  (void*)&WB_GetCPUFeatures     },
1349   {CC"getNMethod",         CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1350                                                       (void*)&WB_GetNMethod         },
1351   {CC"forceNMethodSweep",  CC"()V",                   (void*)&WB_ForceNMethodSweep  },
1352   {CC"allocateCodeBlob",   CC"(II)J",                 (void*)&WB_AllocateCodeBlob   },
1353   {CC"freeCodeBlob",       CC"(J)V",                  (void*)&WB_FreeCodeBlob       },
1354   {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1355   {CC"getCompilationActivityMode",
1356                            CC"()I",                   (void*)&WB_GetCompilationActivityMode},
1357   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
1358   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
1359   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
1360   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
1361   {CC"isMonitorInflated",  CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
1362   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
1363   {CC"getMethodBooleanOption",
1364       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1365                                                       (void*)&WB_GetMethodBooleaneOption},
1366   {CC"getMethodIntxOption",
1367       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1368                                                       (void*)&WB_GetMethodIntxOption},
1369   {CC"getMethodUintxOption",
1370       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1371                                                       (void*)&WB_GetMethodUintxOption},
1372   {CC"getMethodDoubleOption",
1373       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1374                                                       (void*)&WB_GetMethodDoubleOption},
1375   {CC"getMethodStringOption",
1376       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1377                                                       (void*)&WB_GetMethodStringOption},
1378 };
1379 
1380 #undef CC
1381 
1382 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1383   {
1384     if (WhiteBoxAPI) {
1385       // Make sure that wbclass is loaded by the null classloader
1386       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1387       Handle loader(ikh->class_loader());
1388       if (loader.is_null()) {
1389         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1390         WhiteBox::register_extended(env, wbclass, thread);
1391         WhiteBox::set_used();
1392       }
1393     }
1394   }
1395 JVM_END
--- EOF ---