rev 8995 : 8046155: JEP165: Compiler Control
Summary:
Reviewed-by:

   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 "compiler/methodMatcher.hpp"
  33 #include "jvmtifiles/jvmtiEnv.hpp"
  34 #include "memory/metadataFactory.hpp"
  35 #include "memory/metaspaceShared.hpp"
  36 #include "memory/universe.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "prims/wbtestmethods/parserTests.hpp"
  39 #include "prims/whitebox.hpp"
  40 #include "runtime/arguments.hpp"
  41 #include "runtime/compilationPolicy.hpp"
  42 #include "runtime/deoptimization.hpp"
  43 #include "runtime/interfaceSupport.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/os.hpp"
  46 #include "runtime/sweeper.hpp"
  47 #include "runtime/thread.hpp"
  48 #include "runtime/vm_version.hpp"
  49 #include "utilities/array.hpp"
  50 #include "utilities/debug.hpp"
  51 #include "utilities/exceptions.hpp"
  52 #include "utilities/macros.hpp"
  53 #if INCLUDE_ALL_GCS
  54 #include "gc/g1/concurrentMark.hpp"
  55 #include "gc/g1/concurrentMarkThread.hpp"
  56 #include "gc/g1/g1CollectedHeap.inline.hpp"
  57 #include "gc/g1/heapRegionRemSet.hpp"
  58 #include "gc/parallel/parallelScavengeHeap.inline.hpp"
  59 #include "gc/parallel/adjoiningGenerations.hpp"
  60 #endif // INCLUDE_ALL_GCS
  61 #if INCLUDE_NMT
  62 #include "services/mallocSiteTable.hpp"
  63 #include "services/memTracker.hpp"
  64 #include "utilities/nativeCallStack.hpp"
  65 #endif // INCLUDE_NMT
  66 
  67 
  68 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
  69 
  70 #define SIZE_T_MAX_VALUE ((size_t) -1)
  71 
  72 bool WhiteBox::_used = false;
  73 volatile bool WhiteBox::compilation_locked = false;
  74 
  75 class VM_WhiteBoxOperation : public VM_Operation {
  76  public:
  77   VM_WhiteBoxOperation()                         { }
  78   VMOp_Type type()                  const        { return VMOp_WhiteBoxOperation; }
  79   bool allow_nested_vm_operations() const        { return true; }
  80 };
  81 
  82 
  83 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj))
  84   return (jlong)(void*)JNIHandles::resolve(obj);
  85 WB_END
  86 
  87 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o))
  88   return heapOopSize;
  89 WB_END
  90 
  91 WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o))
  92   return os::vm_page_size();
  93 WB_END
  94 
  95 WB_ENTRY(jlong, WB_GetVMAllocationGranularity(JNIEnv* env, jobject o))
  96   return os::vm_allocation_granularity();
  97 WB_END
  98 
  99 WB_ENTRY(jlong, WB_GetVMLargePageSize(JNIEnv* env, jobject o))
 100   return os::large_page_size();
 101 WB_END
 102 
 103 class WBIsKlassAliveClosure : public KlassClosure {
 104     Symbol* _name;
 105     bool _found;
 106 public:
 107     WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {}
 108 
 109     void do_klass(Klass* k) {
 110       if (_found) return;
 111       Symbol* ksym = k->name();
 112       if (ksym->fast_compare(_name) == 0) {
 113         _found = true;
 114       }
 115     }
 116 
 117     bool found() const {
 118         return _found;
 119     }
 120 };
 121 
 122 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name))
 123   Handle h_name = JNIHandles::resolve(name);
 124   if (h_name.is_null()) return false;
 125   Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false);
 126   TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return
 127 
 128   WBIsKlassAliveClosure closure(sym);
 129   ClassLoaderDataGraph::classes_do(&closure);
 130 
 131   return closure.found();
 132 WB_END
 133 
 134 WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(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->AddToBootstrapClassLoaderSearch(seg);
 140   assert(err == JVMTI_ERROR_NONE, "must not fail");
 141 #endif
 142 }
 143 WB_END
 144 
 145 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) {
 146 #if INCLUDE_JVMTI
 147   ResourceMark rm;
 148   const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment));
 149   JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION);
 150   jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg);
 151   assert(err == JVMTI_ERROR_NONE, "must not fail");
 152 #endif
 153 }
 154 WB_END
 155 
 156 
 157 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) {
 158   return (jlong)Arguments::max_heap_for_compressed_oops();
 159 }
 160 WB_END
 161 
 162 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) {
 163   CollectorPolicy * p = Universe::heap()->collector_policy();
 164   gclog_or_tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap "
 165     SIZE_FORMAT " Maximum heap " SIZE_FORMAT " Space alignment " SIZE_FORMAT " Heap alignment " SIZE_FORMAT,
 166     p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(),
 167     p->space_alignment(), p->heap_alignment());
 168 }
 169 WB_END
 170 
 171 #ifndef PRODUCT
 172 // Forward declaration
 173 void TestReservedSpace_test();
 174 void TestReserveMemorySpecial_test();
 175 void TestVirtualSpace_test();
 176 void TestMetaspaceAux_test();
 177 #endif
 178 
 179 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o))
 180 #ifndef PRODUCT
 181   TestReservedSpace_test();
 182   TestReserveMemorySpecial_test();
 183   TestVirtualSpace_test();
 184   TestMetaspaceAux_test();
 185 #endif
 186 WB_END
 187 
 188 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o))
 189   size_t granularity = os::vm_allocation_granularity();
 190   ReservedHeapSpace rhs(100 * granularity, granularity, false);
 191   VirtualSpace vs;
 192   vs.initialize(rhs, 50 * granularity);
 193 
 194   // Check if constraints are complied
 195   if (!( UseCompressedOops && rhs.base() != NULL &&
 196          Universe::narrow_oop_base() != NULL &&
 197          Universe::narrow_oop_use_implicit_null_checks() )) {
 198     tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n "
 199                   "\tUseCompressedOops is %d\n"
 200                   "\trhs.base() is " PTR_FORMAT "\n"
 201                   "\tUniverse::narrow_oop_base() is " PTR_FORMAT "\n"
 202                   "\tUniverse::narrow_oop_use_implicit_null_checks() is %d",
 203                   UseCompressedOops,
 204                   rhs.base(),
 205                   Universe::narrow_oop_base(),
 206                   Universe::narrow_oop_use_implicit_null_checks());
 207     return;
 208   }
 209   tty->print_cr("Reading from no access area... ");
 210   tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c",
 211                 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 ));
 212 WB_END
 213 
 214 static jint wb_stress_virtual_space_resize(size_t reserved_space_size,
 215                                            size_t magnitude, size_t iterations) {
 216   size_t granularity = os::vm_allocation_granularity();
 217   ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false);
 218   VirtualSpace vs;
 219   if (!vs.initialize(rhs, 0)) {
 220     tty->print_cr("Failed to initialize VirtualSpace. Can't proceed.");
 221     return 3;
 222   }
 223 
 224   long seed = os::random();
 225   tty->print_cr("Random seed is %ld", seed);
 226   os::init_random(seed);
 227 
 228   for (size_t i = 0; i < iterations; i++) {
 229 
 230     // Whether we will shrink or grow
 231     bool shrink = os::random() % 2L == 0;
 232 
 233     // Get random delta to resize virtual space
 234     size_t delta = (size_t)os::random() % magnitude;
 235 
 236     // If we are about to shrink virtual space below zero, then expand instead
 237     if (shrink && vs.committed_size() < delta) {
 238       shrink = false;
 239     }
 240 
 241     // Resizing by delta
 242     if (shrink) {
 243       vs.shrink_by(delta);
 244     } else {
 245       // If expanding fails expand_by will silently return false
 246       vs.expand_by(delta, true);
 247     }
 248   }
 249   return 0;
 250 }
 251 
 252 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o,
 253         jlong reserved_space_size, jlong magnitude, jlong iterations))
 254   tty->print_cr("reservedSpaceSize=" JLONG_FORMAT ", magnitude=" JLONG_FORMAT ", "
 255                 "iterations=" JLONG_FORMAT "\n", reserved_space_size, magnitude,
 256                 iterations);
 257   if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) {
 258     tty->print_cr("One of variables printed above is negative. Can't proceed.\n");
 259     return 1;
 260   }
 261 
 262   // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is
 263   // always 8 byte. That's why we should avoid overflow in case of 32bit platform.
 264   if (sizeof(size_t) < sizeof(jlong)) {
 265     jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE;
 266     if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value
 267         || iterations > size_t_max_value) {
 268       tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n");
 269       return 2;
 270     }
 271   }
 272 
 273   return wb_stress_virtual_space_resize((size_t) reserved_space_size,
 274                                         (size_t) magnitude, (size_t) iterations);
 275 WB_END
 276 
 277 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj))
 278   oop p = JNIHandles::resolve(obj);
 279 #if INCLUDE_ALL_GCS
 280   if (UseG1GC) {
 281     G1CollectedHeap* g1 = G1CollectedHeap::heap();
 282     const HeapRegion* hr = g1->heap_region_containing(p);
 283     if (hr == NULL) {
 284       return false;
 285     }
 286     return !(hr->is_young());
 287   } else if (UseParallelGC) {
 288     ParallelScavengeHeap* psh = ParallelScavengeHeap::heap();
 289     return !psh->is_in_young(p);
 290   }
 291 #endif // INCLUDE_ALL_GCS
 292   GenCollectedHeap* gch = GenCollectedHeap::heap();
 293   return !gch->is_in_young(p);
 294 WB_END
 295 
 296 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj))
 297   oop p = JNIHandles::resolve(obj);
 298   return p->size() * HeapWordSize;
 299 WB_END
 300 
 301 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o))
 302   size_t alignment = Universe::heap()->collector_policy()->space_alignment();
 303   return (jlong)alignment;
 304 WB_END
 305 
 306 #if INCLUDE_ALL_GCS
 307 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj))
 308   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 309   oop result = JNIHandles::resolve(obj);
 310   const HeapRegion* hr = g1->heap_region_containing(result);
 311   return hr->is_humongous();
 312 WB_END
 313 
 314 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o))
 315   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 316   size_t nr = g1->max_regions();
 317   return (jlong)nr;
 318 WB_END
 319 
 320 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o))
 321   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 322   size_t nr = g1->num_free_regions();
 323   return (jlong)nr;
 324 WB_END
 325 
 326 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o))
 327   G1CollectedHeap* g1 = G1CollectedHeap::heap();
 328   return g1->concurrent_mark()->cmThread()->during_cycle();
 329 WB_END
 330 
 331 WB_ENTRY(jboolean, WB_G1StartMarkCycle(JNIEnv* env, jobject o))
 332   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 333   if (!g1h->concurrent_mark()->cmThread()->during_cycle()) {
 334     g1h->collect(GCCause::_wb_conc_mark);
 335     return true;
 336   }
 337   return false;
 338 WB_END
 339 
 340 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o))
 341   return (jint)HeapRegion::GrainBytes;
 342 WB_END
 343 
 344 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o))
 345   ParallelScavengeHeap* ps = ParallelScavengeHeap::heap();
 346   size_t alignment = ps->gens()->virtual_spaces()->alignment();
 347   return (jlong)alignment;
 348 WB_END
 349 
 350 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o))
 351   size_t alignment = ParallelScavengeHeap::heap()->generation_alignment();
 352   return (jlong)alignment;
 353 WB_END
 354 
 355 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env))
 356   ResourceMark rm(THREAD);
 357   G1CollectedHeap* g1h = G1CollectedHeap::heap();
 358   MemoryUsage usage = g1h->get_auxiliary_data_memory_usage();
 359   Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL);
 360   return JNIHandles::make_local(env, h());
 361 WB_END
 362 #endif // INCLUDE_ALL_GCS
 363 
 364 #if INCLUDE_NMT
 365 // Alloc memory using the test memory type so that we can use that to see if
 366 // NMT picks it up correctly
 367 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size))
 368   jlong addr = 0;
 369   addr = (jlong)(uintptr_t)os::malloc(size, mtTest);
 370   return addr;
 371 WB_END
 372 
 373 // Alloc memory with pseudo call stack. The test can create psudo malloc
 374 // allocation site to stress the malloc tracking.
 375 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack))
 376   address pc = (address)(size_t)pseudo_stack;
 377   NativeCallStack stack(&pc, 1);
 378   return (jlong)(uintptr_t)os::malloc(size, mtTest, stack);
 379 WB_END
 380 
 381 // Free the memory allocated by NMTAllocTest
 382 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem))
 383   os::free((void*)(uintptr_t)mem);
 384 WB_END
 385 
 386 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size))
 387   jlong addr = 0;
 388 
 389   addr = (jlong)(uintptr_t)os::reserve_memory(size);
 390   MemTracker::record_virtual_memory_type((address)addr, mtTest);
 391 
 392   return addr;
 393 WB_END
 394 
 395 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 396   os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem);
 397   MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest);
 398 WB_END
 399 
 400 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 401   os::uncommit_memory((char *)(uintptr_t)addr, size);
 402 WB_END
 403 
 404 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size))
 405   os::release_memory((char *)(uintptr_t)addr, size);
 406 WB_END
 407 
 408 WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env))
 409   // Test that we can downgrade NMT levels but not upgrade them.
 410   if (MemTracker::tracking_level() == NMT_off) {
 411     MemTracker::transition_to(NMT_off);
 412     return MemTracker::tracking_level() == NMT_off;
 413   } else {
 414     assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking");
 415     MemTracker::transition_to(NMT_summary);
 416     assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now");
 417 
 418     // Can't go to detail once NMT is set to summary.
 419     MemTracker::transition_to(NMT_detail);
 420     assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now");
 421 
 422     // Shutdown sets tracking level to minimal.
 423     MemTracker::shutdown();
 424     assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now");
 425 
 426     // Once the tracking level is minimal, we cannot increase to summary.
 427     // The code ignores this request instead of asserting because if the malloc site
 428     // table overflows in another thread, it tries to change the code to summary.
 429     MemTracker::transition_to(NMT_summary);
 430     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 431 
 432     // Really can never go up to detail, verify that the code would never do this.
 433     MemTracker::transition_to(NMT_detail);
 434     assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now");
 435     return MemTracker::tracking_level() == NMT_minimal;
 436   }
 437 WB_END
 438 
 439 WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o))
 440   int hash_size = MallocSiteTable::hash_buckets();
 441   assert(hash_size > 0, "NMT hash_size should be > 0");
 442   return (jint)hash_size;
 443 WB_END
 444 #endif // INCLUDE_NMT
 445 
 446 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) {
 447   assert(method != NULL, "method should not be null");
 448   ThreadToNativeFromVM ttn(thread);
 449   return env->FromReflectedMethod(method);
 450 }
 451 
 452 // Deoptimizes all compiled frames and makes nmethods not entrant if it's requested
 453 class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation {
 454  private:
 455   int _result;
 456   const bool _make_not_entrant;
 457  public:
 458   VM_WhiteBoxDeoptimizeFrames(bool make_not_entrant) :
 459         _result(0), _make_not_entrant(make_not_entrant) { }
 460   int  result() const { return _result; }
 461 
 462   void doit() {
 463     for (JavaThread* t = Threads::first(); t != NULL; t = t->next()) {
 464       if (t->has_last_Java_frame()) {
 465         for (StackFrameStream fst(t, UseBiasedLocking); !fst.is_done(); fst.next()) {
 466           frame* f = fst.current();
 467           if (f->can_be_deoptimized() && !f->is_deoptimized_frame()) {
 468             RegisterMap* reg_map = fst.register_map();
 469             Deoptimization::deoptimize(t, *f, reg_map);
 470             if (_make_not_entrant) {
 471                 nmethod* nm = CodeCache::find_nmethod(f->pc());
 472                 assert(nm != NULL, "sanity check");
 473                 nm->make_not_entrant();
 474             }
 475             ++_result;
 476           }
 477         }
 478       }
 479     }
 480   }
 481 };
 482 
 483 WB_ENTRY(jint, WB_DeoptimizeFrames(JNIEnv* env, jobject o, jboolean make_not_entrant))
 484   VM_WhiteBoxDeoptimizeFrames op(make_not_entrant == JNI_TRUE);
 485   VMThread::execute(&op);
 486   return op.result();
 487 WB_END
 488 
 489 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o))
 490   MutexLockerEx mu(Compile_lock);
 491   CodeCache::mark_all_nmethods_for_deoptimization();
 492   VM_Deoptimize op;
 493   VMThread::execute(&op);
 494 WB_END
 495 
 496 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 497   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 498   int result = 0;
 499   CHECK_JNI_EXCEPTION_(env, result);
 500   MutexLockerEx mu(Compile_lock);
 501   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 502   if (is_osr) {
 503     result += mh->mark_osr_nmethods();
 504   } else if (mh->code() != NULL) {
 505     mh->code()->mark_for_deoptimization();
 506     ++result;
 507   }
 508   result += CodeCache::mark_for_deoptimization(mh());
 509   if (result > 0) {
 510     VM_Deoptimize op;
 511     VMThread::execute(&op);
 512   }
 513   return result;
 514 WB_END
 515 
 516 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 517   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 518   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 519   MutexLockerEx mu(Compile_lock);
 520   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 521   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 522   if (code == NULL) {
 523     return JNI_FALSE;
 524   }
 525   return (code->is_alive() && !code->is_marked_for_deoptimization());
 526 WB_END
 527 
 528 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 529   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 530   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 531   MutexLockerEx mu(Compile_lock);
 532   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 533   if (is_osr) {
 534     return CompilationPolicy::can_be_osr_compiled(mh, comp_level);
 535   } else {
 536     return CompilationPolicy::can_be_compiled(mh, comp_level);
 537   }
 538 WB_END
 539 
 540 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method))
 541   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 542   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 543   MutexLockerEx mu(Compile_lock);
 544   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 545   return mh->queued_for_compilation();
 546 WB_END
 547 
 548 WB_ENTRY(jboolean, WB_IsIntrinsicAvailable(JNIEnv* env, jobject o, jobject method, jobject compilation_context, jint compLevel))
 549   if (compLevel < CompLevel_none || compLevel > CompLevel_highest_tier) {
 550     return false; // Intrinsic is not available on a non-existent compilation level.
 551   }
 552   jmethodID method_id, compilation_context_id;
 553   method_id = reflected_method_to_jmid(thread, env, method);
 554   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 555   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(method_id));
 556 
 557   DirectiveSet* dirset;
 558   if (compilation_context != NULL) {
 559     compilation_context_id = reflected_method_to_jmid(thread, env, compilation_context);
 560     CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 561     methodHandle cch(THREAD, Method::checked_resolve_jmethod_id(compilation_context_id));
 562     dirset = CompileBroker::dirstack()->getMatchingDirective(cch, (int)compLevel);
 563   } else {
 564     // Calling with NULL matches default directive
 565     dirset = CompileBroker::dirstack()->getMatchingDirective(NULL, (int)compLevel);
 566   }
 567   return CompileBroker::compiler(compLevel)->is_intrinsic_available(mh, dirset);
 568 WB_END
 569 
 570 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 571   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 572   CHECK_JNI_EXCEPTION_(env, CompLevel_none);
 573   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 574   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 575   return (code != NULL ? code->comp_level() : CompLevel_none);
 576 WB_END
 577 
 578 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 579   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 580   CHECK_JNI_EXCEPTION(env);
 581   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 582   if (is_osr) {
 583     mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox");
 584   } else {
 585     mh->set_not_compilable(comp_level, true /* report */, "WhiteBox");
 586   }
 587 WB_END
 588 
 589 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
 590   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 591   CHECK_JNI_EXCEPTION_(env, InvocationEntryBci);
 592   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 593   nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
 594   return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
 595 WB_END
 596 
 597 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 598   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 599   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 600   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 601   bool result = mh->dont_inline();
 602   mh->set_dont_inline(value == JNI_TRUE);
 603   return result;
 604 WB_END
 605 
 606 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
 607   if (comp_level == CompLevel_any) {
 608     return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
 609         CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
 610   } else {
 611     return CompileBroker::queue_size(comp_level);
 612   }
 613 WB_END
 614 
 615 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 616   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 617   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 618   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 619   bool result = mh->force_inline();
 620   mh->set_force_inline(value == JNI_TRUE);
 621   return result;
 622 WB_END
 623 
 624 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
 625   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 626   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 627   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 628   nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD);
 629   MutexLockerEx mu(Compile_lock);
 630   return (mh->queued_for_compilation() || nm != NULL);
 631 WB_END
 632 
 633 WB_ENTRY(jint, WB_MatchesInline(JNIEnv* env, jobject o, jobject method, jstring pattern))
 634   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 635   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 636 
 637   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 638 
 639   ResourceMark rm;
 640   const char* error_msg = NULL;
 641   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
 642   InlineMatcher* m = InlineMatcher::parse_inline_pattern(method_str, error_msg);
 643 
 644   if (m == NULL) {
 645     assert(error_msg != NULL, "Always have an error message");
 646     tty->print_cr("Got error: %s", error_msg);
 647     return -1; // Pattern failed
 648   }
 649 
 650   // Pattern works - now check if it matches
 651   int result;
 652   if (m->match(mh, InlineMatcher::force_inline)) {
 653     result = 2; // Force inline match
 654   } else if (m->match(mh, InlineMatcher::dont_inline)) {
 655     result = 1; // Dont inline match
 656   } else {
 657     result = 0; // No match
 658   }
 659   delete m;
 660   return result;
 661 WB_END
 662 
 663 
 664 WB_ENTRY(jint, WB_MatchesMethod(JNIEnv* env, jobject o, jobject method, jstring pattern))
 665   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 666   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 667 
 668   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 669 
 670   ResourceMark rm;
 671   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
 672 
 673   const char* error_msg = NULL;
 674 
 675   BasicMatcher* m = BasicMatcher::parse_method_pattern(method_str, error_msg);
 676   if (m == NULL) {
 677     assert(error_msg != NULL, "Must have error_msg");
 678     tty->print_cr("Got error: %s", error_msg);
 679     return -1;
 680   }
 681 
 682   // Pattern works - now check if it matches
 683   int result = m->matches(mh);
 684   delete m;
 685   assert(result == 0 || result == 1, "Result out of range");
 686   return result;
 687 WB_END
 688 
 689 class AlwaysFalseClosure : public BoolObjectClosure {
 690  public:
 691   bool do_object_b(oop p) { return false; }
 692 };
 693 
 694 static AlwaysFalseClosure always_false;
 695 
 696 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
 697   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 698   CHECK_JNI_EXCEPTION(env);
 699   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 700   MutexLockerEx mu(Compile_lock);
 701   MethodData* mdo = mh->method_data();
 702   MethodCounters* mcs = mh->method_counters();
 703 
 704   if (mdo != NULL) {
 705     mdo->init();
 706     ResourceMark rm;
 707     int arg_count = mdo->method()->size_of_parameters();
 708     for (int i = 0; i < arg_count; i++) {
 709       mdo->set_arg_modified(i, 0);
 710     }
 711     MutexLockerEx mu(mdo->extra_data_lock());
 712     mdo->clean_method_data(&always_false);
 713   }
 714 
 715   mh->clear_not_c1_compilable();
 716   mh->clear_not_c2_compilable();
 717   mh->clear_not_c2_osr_compilable();
 718   NOT_PRODUCT(mh->set_compiled_invocation_count(0));
 719   if (mcs != NULL) {
 720     mcs->backedge_counter()->init();
 721     mcs->invocation_counter()->init();
 722     mcs->set_interpreter_invocation_count(0);
 723     mcs->set_interpreter_throwout_count(0);
 724 
 725 #ifdef TIERED
 726     mcs->set_rate(0.0F);
 727     mh->set_prev_event_count(0);
 728     mh->set_prev_time(0);
 729 #endif
 730   }
 731 WB_END
 732 
 733 template <typename T>
 734 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, Flag::Error (*TAt)(const char*, T*, bool, bool)) {
 735   if (name == NULL) {
 736     return false;
 737   }
 738   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 739   const char* flag_name = env->GetStringUTFChars(name, NULL);
 740   Flag::Error result = (*TAt)(flag_name, value, true, true);
 741   env->ReleaseStringUTFChars(name, flag_name);
 742   return (result == Flag::SUCCESS);
 743 }
 744 
 745 template <typename T>
 746 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, Flag::Error (*TAtPut)(const char*, T*, Flag::Flags)) {
 747   if (name == NULL) {
 748     return false;
 749   }
 750   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 751   const char* flag_name = env->GetStringUTFChars(name, NULL);
 752   Flag::Error result = (*TAtPut)(flag_name, value, Flag::INTERNAL);
 753   env->ReleaseStringUTFChars(name, flag_name);
 754   return (result == Flag::SUCCESS);
 755 }
 756 
 757 template <typename T>
 758 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
 759   ResourceMark rm(thread);
 760   jclass clazz = env->FindClass(name->as_C_string());
 761   CHECK_JNI_EXCEPTION_(env, NULL);
 762   jmethodID methodID = env->GetStaticMethodID(clazz,
 763         vmSymbols::valueOf_name()->as_C_string(),
 764         sig->as_C_string());
 765   CHECK_JNI_EXCEPTION_(env, NULL);
 766   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
 767   CHECK_JNI_EXCEPTION_(env, NULL);
 768   return result;
 769 }
 770 
 771 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
 772   return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
 773 }
 774 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
 775   return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
 776 }
 777 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
 778   return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
 779 }
 780 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
 781   return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
 782 }*/
 783 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
 784   return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
 785 }
 786 
 787 static Flag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
 788   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 789   const char* flag_name = env->GetStringUTFChars(name, NULL);
 790   Flag* result = Flag::find_flag(flag_name, strlen(flag_name), true, true);
 791   env->ReleaseStringUTFChars(name, flag_name);
 792   return result;
 793 }
 794 
 795 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name))
 796   Flag* flag = getVMFlag(thread, env, name);
 797   return (flag != NULL) && flag->is_constant_in_binary();
 798 WB_END
 799 
 800 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name))
 801   Flag* flag = getVMFlag(thread, env, name);
 802   return (flag != NULL) && !(flag->is_unlocked() || flag->is_unlocker());
 803 WB_END
 804 
 805 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
 806   bool result;
 807   if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) {
 808     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 809     return booleanBox(thread, env, result);
 810   }
 811   return NULL;
 812 WB_END
 813 
 814 WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name))
 815   int result;
 816   if (GetVMFlag <int> (thread, env, name, &result, &CommandLineFlags::intAt)) {
 817     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 818     return longBox(thread, env, result);
 819   }
 820   return NULL;
 821 WB_END
 822 
 823 WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name))
 824   uint result;
 825   if (GetVMFlag <uint> (thread, env, name, &result, &CommandLineFlags::uintAt)) {
 826     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 827     return longBox(thread, env, result);
 828   }
 829   return NULL;
 830 WB_END
 831 
 832 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
 833   intx result;
 834   if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) {
 835     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 836     return longBox(thread, env, result);
 837   }
 838   return NULL;
 839 WB_END
 840 
 841 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
 842   uintx result;
 843   if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) {
 844     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 845     return longBox(thread, env, result);
 846   }
 847   return NULL;
 848 WB_END
 849 
 850 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
 851   uint64_t result;
 852   if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) {
 853     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 854     return longBox(thread, env, result);
 855   }
 856   return NULL;
 857 WB_END
 858 
 859 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
 860   uintx result;
 861   if (GetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAt)) {
 862     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 863     return longBox(thread, env, result);
 864   }
 865   return NULL;
 866 WB_END
 867 
 868 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
 869   double result;
 870   if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) {
 871     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 872     return doubleBox(thread, env, result);
 873   }
 874   return NULL;
 875 WB_END
 876 
 877 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
 878   ccstr ccstrResult;
 879   if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) {
 880     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 881     jstring result = env->NewStringUTF(ccstrResult);
 882     CHECK_JNI_EXCEPTION_(env, NULL);
 883     return result;
 884   }
 885   return NULL;
 886 WB_END
 887 
 888 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
 889   bool result = value == JNI_TRUE ? true : false;
 890   SetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAtPut);
 891 WB_END
 892 
 893 WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 894   int result = value;
 895   SetVMFlag <int> (thread, env, name, &result, &CommandLineFlags::intAtPut);
 896 WB_END
 897 
 898 WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 899   uint result = value;
 900   SetVMFlag <uint> (thread, env, name, &result, &CommandLineFlags::uintAtPut);
 901 WB_END
 902 
 903 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 904   intx result = value;
 905   SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut);
 906 WB_END
 907 
 908 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 909   uintx result = value;
 910   SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut);
 911 WB_END
 912 
 913 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 914   uint64_t result = value;
 915   SetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAtPut);
 916 WB_END
 917 
 918 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 919   size_t result = value;
 920   SetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAtPut);
 921 WB_END
 922 
 923 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
 924   double result = value;
 925   SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut);
 926 WB_END
 927 
 928 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
 929   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 930   const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL);
 931   ccstr ccstrResult = ccstrValue;
 932   bool needFree;
 933   {
 934     ThreadInVMfromNative ttvfn(thread); // back to VM
 935     needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut);
 936   }
 937   if (value != NULL) {
 938     env->ReleaseStringUTFChars(value, ccstrValue);
 939   }
 940   if (needFree) {
 941     FREE_C_HEAP_ARRAY(char, ccstrResult);
 942   }
 943 WB_END
 944 
 945 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
 946   WhiteBox::compilation_locked = true;
 947 WB_END
 948 
 949 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
 950   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
 951   WhiteBox::compilation_locked = false;
 952   mo.notify_all();
 953 WB_END
 954 
 955 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
 956   // Force a code cache sweep and block until it finished
 957   NMethodSweeper::force_sweep();
 958 WB_END
 959 
 960 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
 961   ResourceMark rm(THREAD);
 962   int len;
 963   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
 964   return (StringTable::lookup(name, len) != NULL);
 965 WB_END
 966 
 967 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
 968   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
 969   Universe::heap()->collect(GCCause::_last_ditch_collection);
 970 #if INCLUDE_ALL_GCS
 971   if (UseG1GC) {
 972     // Needs to be cleared explicitly for G1
 973     Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false);
 974   }
 975 #endif // INCLUDE_ALL_GCS
 976 WB_END
 977 
 978 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
 979   Universe::heap()->collect(GCCause::_wb_young_gc);
 980 WB_END
 981 
 982 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
 983   // static+volatile in order to force the read to happen
 984   // (not be eliminated by the compiler)
 985   static char c;
 986   static volatile char* p;
 987 
 988   p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
 989   if (p == NULL) {
 990     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
 991   }
 992 
 993   c = *p;
 994 WB_END
 995 
 996 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
 997   const char* cpu_features = VM_Version::cpu_features();
 998   ThreadToNativeFromVM ttn(thread);
 999   jstring features_string = env->NewStringUTF(cpu_features);
1000 
1001   CHECK_JNI_EXCEPTION_(env, NULL);
1002 
1003   return features_string;
1004 WB_END
1005 
1006 int WhiteBox::get_blob_type(const CodeBlob* code) {
1007   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1008   return CodeCache::get_code_heap(code)->code_blob_type();
1009 }
1010 
1011 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
1012   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1013   return CodeCache::get_code_heap(blob_type);
1014 }
1015 
1016 struct CodeBlobStub {
1017   CodeBlobStub(const CodeBlob* blob) :
1018       name(os::strdup(blob->name())),
1019       size(blob->size()),
1020       blob_type(WhiteBox::get_blob_type(blob)) { }
1021   ~CodeBlobStub() { os::free((void*) name); }
1022   const char* const name;
1023   const int         size;
1024   const int         blob_type;
1025 };
1026 
1027 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
1028   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1029   CHECK_JNI_EXCEPTION_(env, NULL);
1030   jobjectArray result = env->NewObjectArray(3, clazz, NULL);
1031 
1032   jstring name = env->NewStringUTF(cb->name);
1033   CHECK_JNI_EXCEPTION_(env, NULL);
1034   env->SetObjectArrayElement(result, 0, name);
1035 
1036   jobject obj = integerBox(thread, env, cb->size);
1037   CHECK_JNI_EXCEPTION_(env, NULL);
1038   env->SetObjectArrayElement(result, 1, obj);
1039 
1040   obj = integerBox(thread, env, cb->blob_type);
1041   CHECK_JNI_EXCEPTION_(env, NULL);
1042   env->SetObjectArrayElement(result, 2, obj);
1043 
1044   return result;
1045 }
1046 
1047 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1048   ResourceMark rm(THREAD);
1049   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1050   CHECK_JNI_EXCEPTION_(env, NULL);
1051   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1052   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1053   jobjectArray result = NULL;
1054   if (code == NULL) {
1055     return result;
1056   }
1057   int insts_size = code->insts_size();
1058 
1059   ThreadToNativeFromVM ttn(thread);
1060   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1061   CHECK_JNI_EXCEPTION_(env, NULL);
1062   result = env->NewObjectArray(4, clazz, NULL);
1063   if (result == NULL) {
1064     return result;
1065   }
1066 
1067   CodeBlobStub stub(code);
1068   jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1069   env->SetObjectArrayElement(result, 0, codeBlob);
1070 
1071   jobject level = integerBox(thread, env, code->comp_level());
1072   CHECK_JNI_EXCEPTION_(env, NULL);
1073   env->SetObjectArrayElement(result, 1, level);
1074 
1075   jbyteArray insts = env->NewByteArray(insts_size);
1076   CHECK_JNI_EXCEPTION_(env, NULL);
1077   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1078   env->SetObjectArrayElement(result, 2, insts);
1079 
1080   jobject id = integerBox(thread, env, code->compile_id());
1081   CHECK_JNI_EXCEPTION_(env, NULL);
1082   env->SetObjectArrayElement(result, 3, id);
1083 
1084   return result;
1085 WB_END
1086 
1087 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1088   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1089   BufferBlob* blob;
1090   int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1091   if (full_size < size) {
1092     full_size += round_to(size - full_size, oopSize);
1093   }
1094   {
1095     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1096     blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1097     ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1098   }
1099   // Track memory usage statistic after releasing CodeCache_lock
1100   MemoryService::track_code_cache_memory_usage();
1101   return blob;
1102 }
1103 
1104 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
1105   if (size < 0) {
1106     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1107       err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size));
1108   }
1109   return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
1110 WB_END
1111 
1112 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
1113   if (addr == 0) {
1114     return;
1115   }
1116   BufferBlob::free((BufferBlob*) addr);
1117 WB_END
1118 
1119 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
1120   ResourceMark rm;
1121   GrowableArray<CodeBlobStub*> blobs;
1122   {
1123     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1124     CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
1125     if (heap == NULL) {
1126       return NULL;
1127     }
1128     for (CodeBlob* cb = (CodeBlob*) heap->first();
1129          cb != NULL; cb = (CodeBlob*) heap->next(cb)) {
1130       CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub);
1131       new (stub) CodeBlobStub(cb);
1132       blobs.append(stub);
1133     }
1134   }
1135   if (blobs.length() == 0) {
1136     return NULL;
1137   }
1138   ThreadToNativeFromVM ttn(thread);
1139   jobjectArray result = NULL;
1140   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1141   CHECK_JNI_EXCEPTION_(env, NULL);
1142   result = env->NewObjectArray(blobs.length(), clazz, NULL);
1143   if (result == NULL) {
1144     return result;
1145   }
1146   int i = 0;
1147   for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin();
1148        it != blobs.end(); ++it) {
1149     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
1150     env->SetObjectArrayElement(result, i, obj);
1151     ++i;
1152   }
1153   return result;
1154 WB_END
1155 
1156 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1157   return CompileBroker::get_compilation_activity_mode();
1158 WB_END
1159 
1160 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1161   if (addr == 0) {
1162     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1163       "WB_GetCodeBlob: addr is null");
1164   }
1165   ThreadToNativeFromVM ttn(thread);
1166   CodeBlobStub stub((CodeBlob*) addr);
1167   return codeBlob2objectArray(thread, env, &stub);
1168 WB_END
1169 
1170 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1171   return (jlong) Thread::current()->stack_size();
1172 WB_END
1173 
1174 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1175   JavaThread* t = JavaThread::current();
1176   return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size();
1177 WB_END
1178 
1179 int WhiteBox::array_bytes_to_length(size_t bytes) {
1180   return Array<u1>::bytes_to_length(bytes);
1181 }
1182 
1183 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1184   if (size < 0) {
1185     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1186         err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1187   }
1188 
1189   oop class_loader_oop = JNIHandles::resolve(class_loader);
1190   ClassLoaderData* cld = class_loader_oop != NULL
1191       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1192       : ClassLoaderData::the_null_class_loader_data();
1193 
1194   void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1195 
1196   return (jlong)(uintptr_t)metadata;
1197 WB_END
1198 
1199 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1200   oop class_loader_oop = JNIHandles::resolve(class_loader);
1201   ClassLoaderData* cld = class_loader_oop != NULL
1202       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1203       : ClassLoaderData::the_null_class_loader_data();
1204 
1205   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1206 WB_END
1207 
1208 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1209   if (inc < 0) {
1210     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1211         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1212   }
1213 
1214   jlong max_size_t = (jlong) ((size_t) -1);
1215   if (inc > max_size_t) {
1216     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1217         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1218   }
1219 
1220   size_t new_cap_until_GC = 0;
1221   size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment());
1222   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1223   if (!success) {
1224     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1225                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
1226                 "due to contention with another thread");
1227   }
1228   return (jlong) new_cap_until_GC;
1229 WB_END
1230 
1231 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
1232   return (jlong) MetaspaceGC::capacity_until_GC();
1233 WB_END
1234 
1235 
1236 
1237 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1238   Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1239                                            Monitor::_safepoint_check_always :
1240                                            Monitor::_safepoint_check_never;
1241   MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1242                    attemptedNoSafepointValue == JNI_TRUE);
1243 WB_END
1244 
1245 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1246   oop obj_oop = JNIHandles::resolve(obj);
1247   return (jboolean) obj_oop->mark()->has_monitor();
1248 WB_END
1249 
1250 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1251   VM_ForceSafepoint force_safepoint_op;
1252   VMThread::execute(&force_safepoint_op);
1253 WB_END
1254 
1255 template <typename T>
1256 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1257   assert(value != NULL, "sanity");
1258   if (method == NULL || name == NULL) {
1259     return false;
1260   }
1261   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1262   CHECK_JNI_EXCEPTION_(env, false);
1263   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1264   // can't be in VM when we call JNI
1265   ThreadToNativeFromVM ttnfv(thread);
1266   const char* flag_name = env->GetStringUTFChars(name, NULL);
1267   bool result =  CompilerOracle::has_option_value(mh, flag_name, *value);
1268   env->ReleaseStringUTFChars(name, flag_name);
1269   return result;
1270 }
1271 
1272 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1273   bool result;
1274   if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1275     // can't be in VM when we call JNI
1276     ThreadToNativeFromVM ttnfv(thread);
1277     return booleanBox(thread, env, result);
1278   }
1279   return NULL;
1280 WB_END
1281 
1282 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1283   intx result;
1284   if (GetMethodOption <intx> (thread, env, method, name, &result)) {
1285     // can't be in VM when we call JNI
1286     ThreadToNativeFromVM ttnfv(thread);
1287     return longBox(thread, env, result);
1288   }
1289   return NULL;
1290 WB_END
1291 
1292 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1293   uintx result;
1294   if (GetMethodOption <uintx> (thread, env, method, name, &result)) {
1295     // can't be in VM when we call JNI
1296     ThreadToNativeFromVM ttnfv(thread);
1297     return longBox(thread, env, result);
1298   }
1299   return NULL;
1300 WB_END
1301 
1302 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1303   double result;
1304   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1305     // can't be in VM when we call JNI
1306     ThreadToNativeFromVM ttnfv(thread);
1307     return doubleBox(thread, env, result);
1308   }
1309   return NULL;
1310 WB_END
1311 
1312 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1313   ccstr ccstrResult;
1314   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1315     // can't be in VM when we call JNI
1316     ThreadToNativeFromVM ttnfv(thread);
1317     jstring result = env->NewStringUTF(ccstrResult);
1318     CHECK_JNI_EXCEPTION_(env, NULL);
1319     return result;
1320   }
1321   return NULL;
1322 WB_END
1323 
1324 WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
1325   oop obj_oop = JNIHandles::resolve(obj);
1326   return MetaspaceShared::is_in_shared_space((void*)obj_oop);
1327 WB_END
1328 
1329 WB_ENTRY(jboolean, WB_AreSharedStringsIgnored(JNIEnv* env))
1330   return StringTable::shared_string_ignored();
1331 WB_END
1332 
1333 //Some convenience methods to deal with objects from java
1334 int WhiteBox::offset_for_field(const char* field_name, oop object,
1335     Symbol* signature_symbol) {
1336   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1337   Thread* THREAD = Thread::current();
1338 
1339   //Get the class of our object
1340   Klass* arg_klass = object->klass();
1341   //Turn it into an instance-klass
1342   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1343 
1344   //Create symbols to look for in the class
1345   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1346       THREAD);
1347 
1348   //To be filled in with an offset of the field we're looking for
1349   fieldDescriptor fd;
1350 
1351   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1352   if (res == NULL) {
1353     tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1354         name_symbol->as_C_string());
1355     vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class");
1356   }
1357 
1358   //fetch the field at the offset we've found
1359   int dest_offset = fd.offset();
1360 
1361   return dest_offset;
1362 }
1363 
1364 
1365 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1366   int offset = offset_for_field(field_name, object,
1367       vmSymbols::string_signature());
1368   oop string = object->obj_field(offset);
1369   if (string == NULL) {
1370     return NULL;
1371   }
1372   const char* ret = java_lang_String::as_utf8_string(string);
1373   return ret;
1374 }
1375 
1376 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
1377   int offset =
1378       offset_for_field(field_name, object, vmSymbols::bool_signature());
1379   bool ret = (object->bool_field(offset) == JNI_TRUE);
1380   return ret;
1381 }
1382 
1383 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
1384   ResourceMark rm;
1385   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
1386 
1387   //  one by one registration natives for exception catching
1388   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
1389   CHECK_JNI_EXCEPTION(env);
1390   for (int i = 0, n = method_count; i < n; ++i) {
1391     // Skip dummy entries
1392     if (method_array[i].fnPtr == NULL) continue;
1393     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
1394       jthrowable throwable_obj = env->ExceptionOccurred();
1395       if (throwable_obj != NULL) {
1396         env->ExceptionClear();
1397         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
1398           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
1399           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
1400           tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
1401               method_array[i].name, method_array[i].signature);
1402         }
1403       } else {
1404         // Registration failed unexpectedly.
1405         tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
1406             method_array[i].name, method_array[i].signature);
1407         env->UnregisterNatives(wbclass);
1408         break;
1409       }
1410     }
1411   }
1412 }
1413 
1414 #define CC (char*)
1415 
1416 static JNINativeMethod methods[] = {
1417   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1418   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1419   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1420   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1421   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1422   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1423   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1424   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1425   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1426   {CC"parseCommandLine0",
1427       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1428       (void*) &WB_ParseCommandLine
1429   },
1430   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1431                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1432   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
1433                                                       (void*)&WB_AddToSystemClassLoaderSearch},
1434   {CC"getCompressedOopsMaxHeapSize", CC"()J",
1435       (void*)&WB_GetCompressedOopsMaxHeapSize},
1436   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
1437   {CC"runMemoryUnitTests", CC"()V",                   (void*)&WB_RunMemoryUnitTests},
1438   {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
1439   {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
1440 #if INCLUDE_ALL_GCS
1441   {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
1442   {CC"g1IsHumongous0",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
1443   {CC"g1NumMaxRegions",    CC"()J",                   (void*)&WB_G1NumMaxRegions  },
1444   {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
1445   {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
1446   {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
1447   {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;",
1448                                                       (void*)&WB_G1AuxiliaryMemoryUsage  },
1449   {CC"psVirtualSpaceAlignment",CC"()J",               (void*)&WB_PSVirtualSpaceAlignment},
1450   {CC"psHeapGenerationAlignment",CC"()J",             (void*)&WB_PSHeapGenerationAlignment},
1451 #endif // INCLUDE_ALL_GCS
1452 #if INCLUDE_NMT
1453   {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
1454   {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
1455   {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
1456   {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
1457   {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
1458   {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
1459   {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
1460   {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
1461   {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
1462 #endif // INCLUDE_NMT
1463   {CC"deoptimizeFrames",   CC"(Z)I",                  (void*)&WB_DeoptimizeFrames  },
1464   {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
1465     {CC"deoptimizeMethod0",   CC"(Ljava/lang/reflect/Executable;Z)I",
1466                                                         (void*)&WB_DeoptimizeMethod  },
1467   {CC"isMethodCompiled0",   CC"(Ljava/lang/reflect/Executable;Z)Z",
1468                                                       (void*)&WB_IsMethodCompiled  },
1469   {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z",
1470                                                       (void*)&WB_IsMethodCompilable},
1471   {CC"isMethodQueuedForCompilation0",
1472       CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
1473   {CC"isIntrinsicAvailable0",
1474       CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z",
1475                                                       (void*)&WB_IsIntrinsicAvailable},
1476   {CC"makeMethodNotCompilable0",
1477       CC"(Ljava/lang/reflect/Executable;IZ)V",        (void*)&WB_MakeMethodNotCompilable},
1478   {CC"testSetDontInlineMethod0",
1479       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetDontInlineMethod},
1480   {CC"getMethodCompilationLevel0",
1481       CC"(Ljava/lang/reflect/Executable;Z)I",         (void*)&WB_GetMethodCompilationLevel},
1482   {CC"getMethodEntryBci0",
1483       CC"(Ljava/lang/reflect/Executable;)I",          (void*)&WB_GetMethodEntryBci},
1484   {CC"getCompileQueueSize",
1485       CC"(I)I",                                       (void*)&WB_GetCompileQueueSize},
1486   {CC"testSetForceInlineMethod0",
1487       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetForceInlineMethod},
1488   {CC"enqueueMethodForCompilation0",
1489       CC"(Ljava/lang/reflect/Executable;II)Z",        (void*)&WB_EnqueueMethodForCompilation},
1490   {CC"clearMethodState0",
1491       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_ClearMethodState},
1492   {CC"lockCompilation",    CC"()V",                   (void*)&WB_LockCompilation},
1493   {CC"unlockCompilation",  CC"()V",                   (void*)&WB_UnlockCompilation},
1494   {CC"matchesMethod",
1495       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
1496                                                       (void*)&WB_MatchesMethod},
1497   {CC"matchesInline",
1498       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
1499                                                       (void*)&WB_MatchesInline},
1500   {CC"isConstantVMFlag",   CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag},
1501   {CC"isLockedVMFlag",     CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag},
1502   {CC"setBooleanVMFlag",   CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
1503   {CC"setIntVMFlag",       CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag},
1504   {CC"setUintVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag},
1505   {CC"setIntxVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
1506   {CC"setUintxVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
1507   {CC"setUint64VMFlag",    CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
1508   {CC"setSizeTVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag},
1509   {CC"setDoubleVMFlag",    CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
1510   {CC"setStringVMFlag",    CC"(Ljava/lang/String;Ljava/lang/String;)V",
1511                                                       (void*)&WB_SetStringVMFlag},
1512   {CC"getBooleanVMFlag",   CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
1513                                                       (void*)&WB_GetBooleanVMFlag},
1514   {CC"getIntVMFlag",       CC"(Ljava/lang/String;)Ljava/lang/Long;",
1515                                                       (void*)&WB_GetIntVMFlag},
1516   {CC"getUintVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
1517                                                       (void*)&WB_GetUintVMFlag},
1518   {CC"getIntxVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
1519                                                       (void*)&WB_GetIntxVMFlag},
1520   {CC"getUintxVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1521                                                       (void*)&WB_GetUintxVMFlag},
1522   {CC"getUint64VMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Long;",
1523                                                       (void*)&WB_GetUint64VMFlag},
1524   {CC"getSizeTVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1525                                                       (void*)&WB_GetSizeTVMFlag},
1526   {CC"getDoubleVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Double;",
1527                                                       (void*)&WB_GetDoubleVMFlag},
1528   {CC"getStringVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/String;",
1529                                                       (void*)&WB_GetStringVMFlag},
1530   {CC"isInStringTable",    CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable  },
1531   {CC"fullGC",   CC"()V",                             (void*)&WB_FullGC },
1532   {CC"youngGC",  CC"()V",                             (void*)&WB_YoungGC },
1533   {CC"readReservedMemory", CC"()V",                   (void*)&WB_ReadReservedMemory },
1534   {CC"allocateMetaspace",
1535      CC"(Ljava/lang/ClassLoader;J)J",                 (void*)&WB_AllocateMetaspace },
1536   {CC"freeMetaspace",
1537      CC"(Ljava/lang/ClassLoader;JJ)V",                (void*)&WB_FreeMetaspace },
1538   {CC"incMetaspaceCapacityUntilGC", CC"(J)J",         (void*)&WB_IncMetaspaceCapacityUntilGC },
1539   {CC"metaspaceCapacityUntilGC", CC"()J",             (void*)&WB_MetaspaceCapacityUntilGC },
1540   {CC"getCPUFeatures",     CC"()Ljava/lang/String;",  (void*)&WB_GetCPUFeatures     },
1541   {CC"getNMethod0",         CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1542                                                       (void*)&WB_GetNMethod         },
1543   {CC"forceNMethodSweep",  CC"()V",                   (void*)&WB_ForceNMethodSweep  },
1544   {CC"allocateCodeBlob",   CC"(II)J",                 (void*)&WB_AllocateCodeBlob   },
1545   {CC"freeCodeBlob",       CC"(J)V",                  (void*)&WB_FreeCodeBlob       },
1546   {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1547   {CC"getCompilationActivityMode",
1548                            CC"()I",                   (void*)&WB_GetCompilationActivityMode},
1549   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
1550   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
1551   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
1552   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
1553   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
1554   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
1555   {CC"getMethodBooleanOption",
1556       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1557                                                       (void*)&WB_GetMethodBooleaneOption},
1558   {CC"getMethodIntxOption",
1559       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1560                                                       (void*)&WB_GetMethodIntxOption},
1561   {CC"getMethodUintxOption",
1562       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1563                                                       (void*)&WB_GetMethodUintxOption},
1564   {CC"getMethodDoubleOption",
1565       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1566                                                       (void*)&WB_GetMethodDoubleOption},
1567   {CC"getMethodStringOption",
1568       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1569                                                       (void*)&WB_GetMethodStringOption},
1570   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1571   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
1572 };
1573 
1574 #undef CC
1575 
1576 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1577   {
1578     if (WhiteBoxAPI) {
1579       // Make sure that wbclass is loaded by the null classloader
1580       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1581       Handle loader(ikh->class_loader());
1582       if (loader.is_null()) {
1583         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1584         WhiteBox::register_extended(env, wbclass, thread);
1585         WhiteBox::set_used();
1586       }
1587     }
1588   }
1589 JVM_END
--- EOF ---