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   if (compilation_context != NULL) {
 557     compilation_context_id = reflected_method_to_jmid(thread, env, compilation_context);
 558     CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 559     methodHandle cch(THREAD, Method::checked_resolve_jmethod_id(compilation_context_id));
 560     return CompileBroker::compiler(compLevel)->is_intrinsic_available(mh, cch);
 561   } else {
 562     return CompileBroker::compiler(compLevel)->is_intrinsic_available(mh, NULL);

 563   }

 564 WB_END
 565 
 566 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
 567   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 568   CHECK_JNI_EXCEPTION_(env, CompLevel_none);
 569   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 570   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
 571   return (code != NULL ? code->comp_level() : CompLevel_none);
 572 WB_END
 573 
 574 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr))
 575   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 576   CHECK_JNI_EXCEPTION(env);
 577   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 578   if (is_osr) {
 579     mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox");
 580   } else {
 581     mh->set_not_compilable(comp_level, true /* report */, "WhiteBox");
 582   }
 583 WB_END
 584 
 585 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method))
 586   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 587   CHECK_JNI_EXCEPTION_(env, InvocationEntryBci);
 588   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 589   nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false);
 590   return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci);
 591 WB_END
 592 
 593 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 594   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 595   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 596   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 597   bool result = mh->dont_inline();
 598   mh->set_dont_inline(value == JNI_TRUE);
 599   return result;
 600 WB_END
 601 
 602 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level))
 603   if (comp_level == CompLevel_any) {
 604     return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ +
 605         CompileBroker::queue_size(CompLevel_full_profile) /* C1 */;
 606   } else {
 607     return CompileBroker::queue_size(comp_level);
 608   }
 609 WB_END
 610 
 611 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value))
 612   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 613   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 614   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 615   bool result = mh->force_inline();
 616   mh->set_force_inline(value == JNI_TRUE);
 617   return result;
 618 WB_END
 619 
 620 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci))
 621   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 622   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 623   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 624   nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD);
 625   MutexLockerEx mu(Compile_lock);
 626   return (mh->queued_for_compilation() || nm != NULL);
 627 WB_END
 628 






























 629 
 630 WB_ENTRY(jint, WB_MatchesMethod(JNIEnv* env, jobject o, jobject method, jstring pattern))
 631   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 632   CHECK_JNI_EXCEPTION_(env, JNI_FALSE);
 633 
 634   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 635 
 636   ResourceMark rm;
 637   char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern));
 638 
 639   const char* error_msg = NULL;
 640 
 641   BasicMatcher* m = BasicMatcher::parse_method_pattern(method_str, error_msg);
 642   if (m == NULL) {
 643     assert(error_msg != NULL, "Must have error_msg");
 644     tty->print_cr("Got error: %s", error_msg);
 645     return -1;
 646   }
 647 
 648   // Pattern works - now check if it matches
 649   int result = m->matches(mh);
 650   delete m;
 651   assert(result == 0 || result == 1, "Result out of range");
 652   return result;
 653 WB_END
 654 
 655 class AlwaysFalseClosure : public BoolObjectClosure {
 656  public:
 657   bool do_object_b(oop p) { return false; }
 658 };
 659 
 660 static AlwaysFalseClosure always_false;
 661 
 662 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method))
 663   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
 664   CHECK_JNI_EXCEPTION(env);
 665   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
 666   MutexLockerEx mu(Compile_lock);
 667   MethodData* mdo = mh->method_data();
 668   MethodCounters* mcs = mh->method_counters();
 669 
 670   if (mdo != NULL) {
 671     mdo->init();
 672     ResourceMark rm;
 673     int arg_count = mdo->method()->size_of_parameters();
 674     for (int i = 0; i < arg_count; i++) {
 675       mdo->set_arg_modified(i, 0);
 676     }
 677     MutexLockerEx mu(mdo->extra_data_lock());
 678     mdo->clean_method_data(&always_false);
 679   }
 680 
 681   mh->clear_not_c1_compilable();
 682   mh->clear_not_c2_compilable();
 683   mh->clear_not_c2_osr_compilable();
 684   NOT_PRODUCT(mh->set_compiled_invocation_count(0));
 685   if (mcs != NULL) {
 686     mcs->backedge_counter()->init();
 687     mcs->invocation_counter()->init();
 688     mcs->set_interpreter_invocation_count(0);
 689     mcs->set_interpreter_throwout_count(0);
 690 
 691 #ifdef TIERED
 692     mcs->set_rate(0.0F);
 693     mh->set_prev_event_count(0);
 694     mh->set_prev_time(0);
 695 #endif
 696   }
 697 WB_END
 698 
 699 template <typename T>
 700 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, Flag::Error (*TAt)(const char*, T*, bool, bool)) {
 701   if (name == NULL) {
 702     return false;
 703   }
 704   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 705   const char* flag_name = env->GetStringUTFChars(name, NULL);
 706   Flag::Error result = (*TAt)(flag_name, value, true, true);
 707   env->ReleaseStringUTFChars(name, flag_name);
 708   return (result == Flag::SUCCESS);
 709 }
 710 
 711 template <typename T>
 712 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, Flag::Error (*TAtPut)(const char*, T*, Flag::Flags)) {
 713   if (name == NULL) {
 714     return false;
 715   }
 716   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 717   const char* flag_name = env->GetStringUTFChars(name, NULL);
 718   Flag::Error result = (*TAtPut)(flag_name, value, Flag::INTERNAL);
 719   env->ReleaseStringUTFChars(name, flag_name);
 720   return (result == Flag::SUCCESS);
 721 }
 722 
 723 template <typename T>
 724 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) {
 725   ResourceMark rm(thread);
 726   jclass clazz = env->FindClass(name->as_C_string());
 727   CHECK_JNI_EXCEPTION_(env, NULL);
 728   jmethodID methodID = env->GetStaticMethodID(clazz,
 729         vmSymbols::valueOf_name()->as_C_string(),
 730         sig->as_C_string());
 731   CHECK_JNI_EXCEPTION_(env, NULL);
 732   jobject result = env->CallStaticObjectMethod(clazz, methodID, value);
 733   CHECK_JNI_EXCEPTION_(env, NULL);
 734   return result;
 735 }
 736 
 737 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) {
 738   return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value);
 739 }
 740 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) {
 741   return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value);
 742 }
 743 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) {
 744   return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value);
 745 }
 746 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) {
 747   return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value);
 748 }*/
 749 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) {
 750   return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value);
 751 }
 752 
 753 static Flag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) {
 754   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 755   const char* flag_name = env->GetStringUTFChars(name, NULL);
 756   Flag* result = Flag::find_flag(flag_name, strlen(flag_name), true, true);
 757   env->ReleaseStringUTFChars(name, flag_name);
 758   return result;
 759 }
 760 
 761 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name))
 762   Flag* flag = getVMFlag(thread, env, name);
 763   return (flag != NULL) && flag->is_constant_in_binary();
 764 WB_END
 765 
 766 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name))
 767   Flag* flag = getVMFlag(thread, env, name);
 768   return (flag != NULL) && !(flag->is_unlocked() || flag->is_unlocker());
 769 WB_END
 770 
 771 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name))
 772   bool result;
 773   if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) {
 774     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 775     return booleanBox(thread, env, result);
 776   }
 777   return NULL;
 778 WB_END
 779 
 780 WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name))
 781   int result;
 782   if (GetVMFlag <int> (thread, env, name, &result, &CommandLineFlags::intAt)) {
 783     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 784     return longBox(thread, env, result);
 785   }
 786   return NULL;
 787 WB_END
 788 
 789 WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name))
 790   uint result;
 791   if (GetVMFlag <uint> (thread, env, name, &result, &CommandLineFlags::uintAt)) {
 792     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 793     return longBox(thread, env, result);
 794   }
 795   return NULL;
 796 WB_END
 797 
 798 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name))
 799   intx result;
 800   if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) {
 801     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 802     return longBox(thread, env, result);
 803   }
 804   return NULL;
 805 WB_END
 806 
 807 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name))
 808   uintx result;
 809   if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) {
 810     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 811     return longBox(thread, env, result);
 812   }
 813   return NULL;
 814 WB_END
 815 
 816 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name))
 817   uint64_t result;
 818   if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) {
 819     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 820     return longBox(thread, env, result);
 821   }
 822   return NULL;
 823 WB_END
 824 
 825 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name))
 826   uintx result;
 827   if (GetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAt)) {
 828     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 829     return longBox(thread, env, result);
 830   }
 831   return NULL;
 832 WB_END
 833 
 834 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name))
 835   double result;
 836   if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) {
 837     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 838     return doubleBox(thread, env, result);
 839   }
 840   return NULL;
 841 WB_END
 842 
 843 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name))
 844   ccstr ccstrResult;
 845   if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) {
 846     ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 847     jstring result = env->NewStringUTF(ccstrResult);
 848     CHECK_JNI_EXCEPTION_(env, NULL);
 849     return result;
 850   }
 851   return NULL;
 852 WB_END
 853 
 854 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value))
 855   bool result = value == JNI_TRUE ? true : false;
 856   SetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAtPut);
 857 WB_END
 858 
 859 WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 860   int result = value;
 861   SetVMFlag <int> (thread, env, name, &result, &CommandLineFlags::intAtPut);
 862 WB_END
 863 
 864 WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 865   uint result = value;
 866   SetVMFlag <uint> (thread, env, name, &result, &CommandLineFlags::uintAtPut);
 867 WB_END
 868 
 869 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 870   intx result = value;
 871   SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut);
 872 WB_END
 873 
 874 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 875   uintx result = value;
 876   SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut);
 877 WB_END
 878 
 879 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 880   uint64_t result = value;
 881   SetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAtPut);
 882 WB_END
 883 
 884 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value))
 885   size_t result = value;
 886   SetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAtPut);
 887 WB_END
 888 
 889 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value))
 890   double result = value;
 891   SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut);
 892 WB_END
 893 
 894 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value))
 895   ThreadToNativeFromVM ttnfv(thread);   // can't be in VM when we call JNI
 896   const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL);
 897   ccstr ccstrResult = ccstrValue;
 898   bool needFree;
 899   {
 900     ThreadInVMfromNative ttvfn(thread); // back to VM
 901     needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut);
 902   }
 903   if (value != NULL) {
 904     env->ReleaseStringUTFChars(value, ccstrValue);
 905   }
 906   if (needFree) {
 907     FREE_C_HEAP_ARRAY(char, ccstrResult);
 908   }
 909 WB_END
 910 
 911 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout))
 912   WhiteBox::compilation_locked = true;
 913 WB_END
 914 
 915 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o))
 916   MonitorLockerEx mo(Compilation_lock, Mutex::_no_safepoint_check_flag);
 917   WhiteBox::compilation_locked = false;
 918   mo.notify_all();
 919 WB_END
 920 
 921 WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o))
 922   // Force a code cache sweep and block until it finished
 923   NMethodSweeper::force_sweep();
 924 WB_END
 925 
 926 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString))
 927   ResourceMark rm(THREAD);
 928   int len;
 929   jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false);
 930   return (StringTable::lookup(name, len) != NULL);
 931 WB_END
 932 
 933 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
 934   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
 935   Universe::heap()->collect(GCCause::_last_ditch_collection);
 936 #if INCLUDE_ALL_GCS
 937   if (UseG1GC) {
 938     // Needs to be cleared explicitly for G1
 939     Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false);
 940   }
 941 #endif // INCLUDE_ALL_GCS
 942 WB_END
 943 
 944 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
 945   Universe::heap()->collect(GCCause::_wb_young_gc);
 946 WB_END
 947 
 948 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
 949   // static+volatile in order to force the read to happen
 950   // (not be eliminated by the compiler)
 951   static char c;
 952   static volatile char* p;
 953 
 954   p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
 955   if (p == NULL) {
 956     THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
 957   }
 958 
 959   c = *p;
 960 WB_END
 961 
 962 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o))
 963   const char* cpu_features = VM_Version::cpu_features();
 964   ThreadToNativeFromVM ttn(thread);
 965   jstring features_string = env->NewStringUTF(cpu_features);
 966 
 967   CHECK_JNI_EXCEPTION_(env, NULL);
 968 
 969   return features_string;
 970 WB_END
 971 
 972 int WhiteBox::get_blob_type(const CodeBlob* code) {
 973   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 974   return CodeCache::get_code_heap(code)->code_blob_type();
 975 }
 976 
 977 CodeHeap* WhiteBox::get_code_heap(int blob_type) {
 978   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
 979   return CodeCache::get_code_heap(blob_type);
 980 }
 981 
 982 struct CodeBlobStub {
 983   CodeBlobStub(const CodeBlob* blob) :
 984       name(os::strdup(blob->name())),
 985       size(blob->size()),
 986       blob_type(WhiteBox::get_blob_type(blob)) { }
 987   ~CodeBlobStub() { os::free((void*) name); }
 988   const char* const name;
 989   const int         size;
 990   const int         blob_type;
 991 };
 992 
 993 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) {
 994   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
 995   CHECK_JNI_EXCEPTION_(env, NULL);
 996   jobjectArray result = env->NewObjectArray(3, clazz, NULL);
 997 
 998   jstring name = env->NewStringUTF(cb->name);
 999   CHECK_JNI_EXCEPTION_(env, NULL);
1000   env->SetObjectArrayElement(result, 0, name);
1001 
1002   jobject obj = integerBox(thread, env, cb->size);
1003   CHECK_JNI_EXCEPTION_(env, NULL);
1004   env->SetObjectArrayElement(result, 1, obj);
1005 
1006   obj = integerBox(thread, env, cb->blob_type);
1007   CHECK_JNI_EXCEPTION_(env, NULL);
1008   env->SetObjectArrayElement(result, 2, obj);
1009 
1010   return result;
1011 }
1012 
1013 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr))
1014   ResourceMark rm(THREAD);
1015   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1016   CHECK_JNI_EXCEPTION_(env, NULL);
1017   methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid));
1018   nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code();
1019   jobjectArray result = NULL;
1020   if (code == NULL) {
1021     return result;
1022   }
1023   int insts_size = code->insts_size();
1024 
1025   ThreadToNativeFromVM ttn(thread);
1026   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1027   CHECK_JNI_EXCEPTION_(env, NULL);
1028   result = env->NewObjectArray(4, clazz, NULL);
1029   if (result == NULL) {
1030     return result;
1031   }
1032 
1033   CodeBlobStub stub(code);
1034   jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub);
1035   env->SetObjectArrayElement(result, 0, codeBlob);
1036 
1037   jobject level = integerBox(thread, env, code->comp_level());
1038   CHECK_JNI_EXCEPTION_(env, NULL);
1039   env->SetObjectArrayElement(result, 1, level);
1040 
1041   jbyteArray insts = env->NewByteArray(insts_size);
1042   CHECK_JNI_EXCEPTION_(env, NULL);
1043   env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
1044   env->SetObjectArrayElement(result, 2, insts);
1045 
1046   jobject id = integerBox(thread, env, code->compile_id());
1047   CHECK_JNI_EXCEPTION_(env, NULL);
1048   env->SetObjectArrayElement(result, 3, id);
1049 
1050   return result;
1051 WB_END
1052 
1053 CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) {
1054   guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled");
1055   BufferBlob* blob;
1056   int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob));
1057   if (full_size < size) {
1058     full_size += round_to(size - full_size, oopSize);
1059   }
1060   {
1061     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1062     blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type);
1063     ::new (blob) BufferBlob("WB::DummyBlob", full_size);
1064   }
1065   // Track memory usage statistic after releasing CodeCache_lock
1066   MemoryService::track_code_cache_memory_usage();
1067   return blob;
1068 }
1069 
1070 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type))
1071   if (size < 0) {
1072     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1073       err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size));
1074   }
1075   return (jlong) WhiteBox::allocate_code_blob(size, blob_type);
1076 WB_END
1077 
1078 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr))
1079   if (addr == 0) {
1080     return;
1081   }
1082   BufferBlob::free((BufferBlob*) addr);
1083 WB_END
1084 
1085 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type))
1086   ResourceMark rm;
1087   GrowableArray<CodeBlobStub*> blobs;
1088   {
1089     MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
1090     CodeHeap* heap = WhiteBox::get_code_heap(blob_type);
1091     if (heap == NULL) {
1092       return NULL;
1093     }
1094     for (CodeBlob* cb = (CodeBlob*) heap->first();
1095          cb != NULL; cb = (CodeBlob*) heap->next(cb)) {
1096       CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub);
1097       new (stub) CodeBlobStub(cb);
1098       blobs.append(stub);
1099     }
1100   }
1101   if (blobs.length() == 0) {
1102     return NULL;
1103   }
1104   ThreadToNativeFromVM ttn(thread);
1105   jobjectArray result = NULL;
1106   jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string());
1107   CHECK_JNI_EXCEPTION_(env, NULL);
1108   result = env->NewObjectArray(blobs.length(), clazz, NULL);
1109   if (result == NULL) {
1110     return result;
1111   }
1112   int i = 0;
1113   for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin();
1114        it != blobs.end(); ++it) {
1115     jobjectArray obj = codeBlob2objectArray(thread, env, *it);
1116     env->SetObjectArrayElement(result, i, obj);
1117     ++i;
1118   }
1119   return result;
1120 WB_END
1121 
1122 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o))
1123   return CompileBroker::get_compilation_activity_mode();
1124 WB_END
1125 
1126 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr))
1127   if (addr == 0) {
1128     THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(),
1129       "WB_GetCodeBlob: addr is null");
1130   }
1131   ThreadToNativeFromVM ttn(thread);
1132   CodeBlobStub stub((CodeBlob*) addr);
1133   return codeBlob2objectArray(thread, env, &stub);
1134 WB_END
1135 
1136 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o))
1137   return (jlong) Thread::current()->stack_size();
1138 WB_END
1139 
1140 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
1141   JavaThread* t = JavaThread::current();
1142   return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size();
1143 WB_END
1144 
1145 int WhiteBox::array_bytes_to_length(size_t bytes) {
1146   return Array<u1>::bytes_to_length(bytes);
1147 }
1148 
1149 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size))
1150   if (size < 0) {
1151     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1152         err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size));
1153   }
1154 
1155   oop class_loader_oop = JNIHandles::resolve(class_loader);
1156   ClassLoaderData* cld = class_loader_oop != NULL
1157       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1158       : ClassLoaderData::the_null_class_loader_data();
1159 
1160   void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread);
1161 
1162   return (jlong)(uintptr_t)metadata;
1163 WB_END
1164 
1165 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size))
1166   oop class_loader_oop = JNIHandles::resolve(class_loader);
1167   ClassLoaderData* cld = class_loader_oop != NULL
1168       ? java_lang_ClassLoader::loader_data(class_loader_oop)
1169       : ClassLoaderData::the_null_class_loader_data();
1170 
1171   MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr);
1172 WB_END
1173 
1174 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc))
1175   if (inc < 0) {
1176     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1177         err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc));
1178   }
1179 
1180   jlong max_size_t = (jlong) ((size_t) -1);
1181   if (inc > max_size_t) {
1182     THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(),
1183         err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc));
1184   }
1185 
1186   size_t new_cap_until_GC = 0;
1187   size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment());
1188   bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC);
1189   if (!success) {
1190     THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(),
1191                 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC "
1192                 "due to contention with another thread");
1193   }
1194   return (jlong) new_cap_until_GC;
1195 WB_END
1196 
1197 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb))
1198   return (jlong) MetaspaceGC::capacity_until_GC();
1199 WB_END
1200 
1201 
1202 
1203 WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue))
1204   Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ?
1205                                            Monitor::_safepoint_check_always :
1206                                            Monitor::_safepoint_check_never;
1207   MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required),
1208                    attemptedNoSafepointValue == JNI_TRUE);
1209 WB_END
1210 
1211 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj))
1212   oop obj_oop = JNIHandles::resolve(obj);
1213   return (jboolean) obj_oop->mark()->has_monitor();
1214 WB_END
1215 
1216 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb))
1217   VM_ForceSafepoint force_safepoint_op;
1218   VMThread::execute(&force_safepoint_op);
1219 WB_END
1220 
1221 template <typename T>
1222 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) {
1223   assert(value != NULL, "sanity");
1224   if (method == NULL || name == NULL) {
1225     return false;
1226   }
1227   jmethodID jmid = reflected_method_to_jmid(thread, env, method);
1228   CHECK_JNI_EXCEPTION_(env, false);
1229   methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid));
1230   // can't be in VM when we call JNI
1231   ThreadToNativeFromVM ttnfv(thread);
1232   const char* flag_name = env->GetStringUTFChars(name, NULL);
1233   bool result =  CompilerOracle::has_option_value(mh, flag_name, *value);
1234   env->ReleaseStringUTFChars(name, flag_name);
1235   return result;
1236 }
1237 
1238 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1239   bool result;
1240   if (GetMethodOption<bool> (thread, env, method, name, &result)) {
1241     // can't be in VM when we call JNI
1242     ThreadToNativeFromVM ttnfv(thread);
1243     return booleanBox(thread, env, result);
1244   }
1245   return NULL;
1246 WB_END
1247 
1248 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1249   intx result;
1250   if (GetMethodOption <intx> (thread, env, method, name, &result)) {
1251     // can't be in VM when we call JNI
1252     ThreadToNativeFromVM ttnfv(thread);
1253     return longBox(thread, env, result);
1254   }
1255   return NULL;
1256 WB_END
1257 
1258 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1259   uintx result;
1260   if (GetMethodOption <uintx> (thread, env, method, name, &result)) {
1261     // can't be in VM when we call JNI
1262     ThreadToNativeFromVM ttnfv(thread);
1263     return longBox(thread, env, result);
1264   }
1265   return NULL;
1266 WB_END
1267 
1268 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1269   double result;
1270   if (GetMethodOption <double> (thread, env, method, name, &result)) {
1271     // can't be in VM when we call JNI
1272     ThreadToNativeFromVM ttnfv(thread);
1273     return doubleBox(thread, env, result);
1274   }
1275   return NULL;
1276 WB_END
1277 
1278 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name))
1279   ccstr ccstrResult;
1280   if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) {
1281     // can't be in VM when we call JNI
1282     ThreadToNativeFromVM ttnfv(thread);
1283     jstring result = env->NewStringUTF(ccstrResult);
1284     CHECK_JNI_EXCEPTION_(env, NULL);
1285     return result;
1286   }
1287   return NULL;
1288 WB_END
1289 
1290 WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj))
1291   oop obj_oop = JNIHandles::resolve(obj);
1292   return MetaspaceShared::is_in_shared_space((void*)obj_oop);
1293 WB_END
1294 
1295 WB_ENTRY(jboolean, WB_AreSharedStringsIgnored(JNIEnv* env))
1296   return StringTable::shared_string_ignored();
1297 WB_END
1298 
1299 //Some convenience methods to deal with objects from java
1300 int WhiteBox::offset_for_field(const char* field_name, oop object,
1301     Symbol* signature_symbol) {
1302   assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
1303   Thread* THREAD = Thread::current();
1304 
1305   //Get the class of our object
1306   Klass* arg_klass = object->klass();
1307   //Turn it into an instance-klass
1308   InstanceKlass* ik = InstanceKlass::cast(arg_klass);
1309 
1310   //Create symbols to look for in the class
1311   TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
1312       THREAD);
1313 
1314   //To be filled in with an offset of the field we're looking for
1315   fieldDescriptor fd;
1316 
1317   Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
1318   if (res == NULL) {
1319     tty->print_cr("Invalid layout of %s at %s", ik->external_name(),
1320         name_symbol->as_C_string());
1321     vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class");
1322   }
1323 
1324   //fetch the field at the offset we've found
1325   int dest_offset = fd.offset();
1326 
1327   return dest_offset;
1328 }
1329 
1330 
1331 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) {
1332   int offset = offset_for_field(field_name, object,
1333       vmSymbols::string_signature());
1334   oop string = object->obj_field(offset);
1335   if (string == NULL) {
1336     return NULL;
1337   }
1338   const char* ret = java_lang_String::as_utf8_string(string);
1339   return ret;
1340 }
1341 
1342 bool WhiteBox::lookup_bool(const char* field_name, oop object) {
1343   int offset =
1344       offset_for_field(field_name, object, vmSymbols::bool_signature());
1345   bool ret = (object->bool_field(offset) == JNI_TRUE);
1346   return ret;
1347 }
1348 
1349 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
1350   ResourceMark rm;
1351   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
1352 
1353   //  one by one registration natives for exception catching
1354   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
1355   CHECK_JNI_EXCEPTION(env);
1356   for (int i = 0, n = method_count; i < n; ++i) {
1357     // Skip dummy entries
1358     if (method_array[i].fnPtr == NULL) continue;
1359     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
1360       jthrowable throwable_obj = env->ExceptionOccurred();
1361       if (throwable_obj != NULL) {
1362         env->ExceptionClear();
1363         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
1364           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
1365           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
1366           tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
1367               method_array[i].name, method_array[i].signature);
1368         }
1369       } else {
1370         // Registration failed unexpectedly.
1371         tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
1372             method_array[i].name, method_array[i].signature);
1373         env->UnregisterNatives(wbclass);
1374         break;
1375       }
1376     }
1377   }
1378 }
1379 
1380 #define CC (char*)
1381 
1382 static JNINativeMethod methods[] = {
1383   {CC"getObjectAddress0",                CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
1384   {CC"getObjectSize0",                   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize     },
1385   {CC"isObjectInOldGen0",                CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen  },
1386   {CC"getHeapOopSize",                   CC"()I",                   (void*)&WB_GetHeapOopSize    },
1387   {CC"getVMPageSize",                    CC"()I",                   (void*)&WB_GetVMPageSize     },
1388   {CC"getVMAllocationGranularity",       CC"()J",                   (void*)&WB_GetVMAllocationGranularity },
1389   {CC"getVMLargePageSize",               CC"()J",                   (void*)&WB_GetVMLargePageSize},
1390   {CC"getHeapSpaceAlignment",            CC"()J",                   (void*)&WB_GetHeapSpaceAlignment},
1391   {CC"isClassAlive0",                    CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive      },
1392   {CC"parseCommandLine0",
1393       CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;",
1394       (void*) &WB_ParseCommandLine
1395   },
1396   {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V",
1397                                                       (void*)&WB_AddToBootstrapClassLoaderSearch},
1398   {CC"addToSystemClassLoaderSearch0",    CC"(Ljava/lang/String;)V",
1399                                                       (void*)&WB_AddToSystemClassLoaderSearch},
1400   {CC"getCompressedOopsMaxHeapSize", CC"()J",
1401       (void*)&WB_GetCompressedOopsMaxHeapSize},
1402   {CC"printHeapSizes",     CC"()V",                   (void*)&WB_PrintHeapSizes    },
1403   {CC"runMemoryUnitTests", CC"()V",                   (void*)&WB_RunMemoryUnitTests},
1404   {CC"readFromNoaccessArea",CC"()V",                  (void*)&WB_ReadFromNoaccessArea},
1405   {CC"stressVirtualSpaceResize",CC"(JJJ)I",           (void*)&WB_StressVirtualSpaceResize},
1406 #if INCLUDE_ALL_GCS
1407   {CC"g1InConcurrentMark", CC"()Z",                   (void*)&WB_G1InConcurrentMark},
1408   {CC"g1IsHumongous0",      CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous     },
1409   {CC"g1NumMaxRegions",    CC"()J",                   (void*)&WB_G1NumMaxRegions  },
1410   {CC"g1NumFreeRegions",   CC"()J",                   (void*)&WB_G1NumFreeRegions  },
1411   {CC"g1RegionSize",       CC"()I",                   (void*)&WB_G1RegionSize      },
1412   {CC"g1StartConcMarkCycle",       CC"()Z",           (void*)&WB_G1StartMarkCycle  },
1413   {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;",
1414                                                       (void*)&WB_G1AuxiliaryMemoryUsage  },
1415   {CC"psVirtualSpaceAlignment",CC"()J",               (void*)&WB_PSVirtualSpaceAlignment},
1416   {CC"psHeapGenerationAlignment",CC"()J",             (void*)&WB_PSHeapGenerationAlignment},
1417 #endif // INCLUDE_ALL_GCS
1418 #if INCLUDE_NMT
1419   {CC"NMTMalloc",           CC"(J)J",                 (void*)&WB_NMTMalloc          },
1420   {CC"NMTMallocWithPseudoStack", CC"(JI)J",           (void*)&WB_NMTMallocWithPseudoStack},
1421   {CC"NMTFree",             CC"(J)V",                 (void*)&WB_NMTFree            },
1422   {CC"NMTReserveMemory",    CC"(J)J",                 (void*)&WB_NMTReserveMemory   },
1423   {CC"NMTCommitMemory",     CC"(JJ)V",                (void*)&WB_NMTCommitMemory    },
1424   {CC"NMTUncommitMemory",   CC"(JJ)V",                (void*)&WB_NMTUncommitMemory  },
1425   {CC"NMTReleaseMemory",    CC"(JJ)V",                (void*)&WB_NMTReleaseMemory   },
1426   {CC"NMTChangeTrackingLevel", CC"()Z",               (void*)&WB_NMTChangeTrackingLevel},
1427   {CC"NMTGetHashSize",      CC"()I",                  (void*)&WB_NMTGetHashSize     },
1428 #endif // INCLUDE_NMT
1429   {CC"deoptimizeFrames",   CC"(Z)I",                  (void*)&WB_DeoptimizeFrames  },
1430   {CC"deoptimizeAll",      CC"()V",                   (void*)&WB_DeoptimizeAll     },
1431     {CC"deoptimizeMethod0",   CC"(Ljava/lang/reflect/Executable;Z)I",
1432                                                         (void*)&WB_DeoptimizeMethod  },
1433   {CC"isMethodCompiled0",   CC"(Ljava/lang/reflect/Executable;Z)Z",
1434                                                       (void*)&WB_IsMethodCompiled  },
1435   {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z",
1436                                                       (void*)&WB_IsMethodCompilable},
1437   {CC"isMethodQueuedForCompilation0",
1438       CC"(Ljava/lang/reflect/Executable;)Z",          (void*)&WB_IsMethodQueuedForCompilation},
1439   {CC"isIntrinsicAvailable0",
1440       CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z",
1441                                                       (void*)&WB_IsIntrinsicAvailable},
1442   {CC"makeMethodNotCompilable0",
1443       CC"(Ljava/lang/reflect/Executable;IZ)V",        (void*)&WB_MakeMethodNotCompilable},
1444   {CC"testSetDontInlineMethod0",
1445       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetDontInlineMethod},
1446   {CC"getMethodCompilationLevel0",
1447       CC"(Ljava/lang/reflect/Executable;Z)I",         (void*)&WB_GetMethodCompilationLevel},
1448   {CC"getMethodEntryBci0",
1449       CC"(Ljava/lang/reflect/Executable;)I",          (void*)&WB_GetMethodEntryBci},
1450   {CC"getCompileQueueSize",
1451       CC"(I)I",                                       (void*)&WB_GetCompileQueueSize},
1452   {CC"testSetForceInlineMethod0",
1453       CC"(Ljava/lang/reflect/Executable;Z)Z",         (void*)&WB_TestSetForceInlineMethod},
1454   {CC"enqueueMethodForCompilation0",
1455       CC"(Ljava/lang/reflect/Executable;II)Z",        (void*)&WB_EnqueueMethodForCompilation},
1456   {CC"clearMethodState0",
1457       CC"(Ljava/lang/reflect/Executable;)V",          (void*)&WB_ClearMethodState},
1458   {CC"lockCompilation",    CC"()V",                   (void*)&WB_LockCompilation},
1459   {CC"unlockCompilation",  CC"()V",                   (void*)&WB_UnlockCompilation},
1460   {CC"matchesMethod",
1461       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I",
1462                                                       (void*)&WB_MatchesMethod},



1463   {CC"isConstantVMFlag",   CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag},
1464   {CC"isLockedVMFlag",     CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag},
1465   {CC"setBooleanVMFlag",   CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag},
1466   {CC"setIntVMFlag",       CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag},
1467   {CC"setUintVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag},
1468   {CC"setIntxVMFlag",      CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag},
1469   {CC"setUintxVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag},
1470   {CC"setUint64VMFlag",    CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag},
1471   {CC"setSizeTVMFlag",     CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag},
1472   {CC"setDoubleVMFlag",    CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag},
1473   {CC"setStringVMFlag",    CC"(Ljava/lang/String;Ljava/lang/String;)V",
1474                                                       (void*)&WB_SetStringVMFlag},
1475   {CC"getBooleanVMFlag",   CC"(Ljava/lang/String;)Ljava/lang/Boolean;",
1476                                                       (void*)&WB_GetBooleanVMFlag},
1477   {CC"getIntVMFlag",       CC"(Ljava/lang/String;)Ljava/lang/Long;",
1478                                                       (void*)&WB_GetIntVMFlag},
1479   {CC"getUintVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
1480                                                       (void*)&WB_GetUintVMFlag},
1481   {CC"getIntxVMFlag",      CC"(Ljava/lang/String;)Ljava/lang/Long;",
1482                                                       (void*)&WB_GetIntxVMFlag},
1483   {CC"getUintxVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1484                                                       (void*)&WB_GetUintxVMFlag},
1485   {CC"getUint64VMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Long;",
1486                                                       (void*)&WB_GetUint64VMFlag},
1487   {CC"getSizeTVMFlag",     CC"(Ljava/lang/String;)Ljava/lang/Long;",
1488                                                       (void*)&WB_GetSizeTVMFlag},
1489   {CC"getDoubleVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/Double;",
1490                                                       (void*)&WB_GetDoubleVMFlag},
1491   {CC"getStringVMFlag",    CC"(Ljava/lang/String;)Ljava/lang/String;",
1492                                                       (void*)&WB_GetStringVMFlag},
1493   {CC"isInStringTable",    CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable  },
1494   {CC"fullGC",   CC"()V",                             (void*)&WB_FullGC },
1495   {CC"youngGC",  CC"()V",                             (void*)&WB_YoungGC },
1496   {CC"readReservedMemory", CC"()V",                   (void*)&WB_ReadReservedMemory },
1497   {CC"allocateMetaspace",
1498      CC"(Ljava/lang/ClassLoader;J)J",                 (void*)&WB_AllocateMetaspace },
1499   {CC"freeMetaspace",
1500      CC"(Ljava/lang/ClassLoader;JJ)V",                (void*)&WB_FreeMetaspace },
1501   {CC"incMetaspaceCapacityUntilGC", CC"(J)J",         (void*)&WB_IncMetaspaceCapacityUntilGC },
1502   {CC"metaspaceCapacityUntilGC", CC"()J",             (void*)&WB_MetaspaceCapacityUntilGC },
1503   {CC"getCPUFeatures",     CC"()Ljava/lang/String;",  (void*)&WB_GetCPUFeatures     },
1504   {CC"getNMethod0",         CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
1505                                                       (void*)&WB_GetNMethod         },
1506   {CC"forceNMethodSweep",  CC"()V",                   (void*)&WB_ForceNMethodSweep  },
1507   {CC"allocateCodeBlob",   CC"(II)J",                 (void*)&WB_AllocateCodeBlob   },
1508   {CC"freeCodeBlob",       CC"(J)V",                  (void*)&WB_FreeCodeBlob       },
1509   {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries },
1510   {CC"getCompilationActivityMode",
1511                            CC"()I",                   (void*)&WB_GetCompilationActivityMode},
1512   {CC"getCodeBlob",        CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob        },
1513   {CC"getThreadStackSize", CC"()J",                   (void*)&WB_GetThreadStackSize },
1514   {CC"getThreadRemainingStackSize", CC"()J",          (void*)&WB_GetThreadRemainingStackSize },
1515   {CC"assertMatchingSafepointCalls", CC"(ZZ)V",       (void*)&WB_AssertMatchingSafepointCalls },
1516   {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated  },
1517   {CC"forceSafepoint",     CC"()V",                   (void*)&WB_ForceSafepoint     },
1518   {CC"getMethodBooleanOption",
1519       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;",
1520                                                       (void*)&WB_GetMethodBooleaneOption},
1521   {CC"getMethodIntxOption",
1522       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1523                                                       (void*)&WB_GetMethodIntxOption},
1524   {CC"getMethodUintxOption",
1525       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;",
1526                                                       (void*)&WB_GetMethodUintxOption},
1527   {CC"getMethodDoubleOption",
1528       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;",
1529                                                       (void*)&WB_GetMethodDoubleOption},
1530   {CC"getMethodStringOption",
1531       CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;",
1532                                                       (void*)&WB_GetMethodStringOption},
1533   {CC"isShared",           CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared },
1534   {CC"areSharedStringsIgnored",           CC"()Z",    (void*)&WB_AreSharedStringsIgnored },
1535 };
1536 
1537 #undef CC
1538 
1539 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
1540   {
1541     if (WhiteBoxAPI) {
1542       // Make sure that wbclass is loaded by the null classloader
1543       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
1544       Handle loader(ikh->class_loader());
1545       if (loader.is_null()) {
1546         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
1547         WhiteBox::register_extended(env, wbclass, thread);
1548         WhiteBox::set_used();
1549       }
1550     }
1551   }
1552 JVM_END
--- EOF ---