1 /* 2 * Copyright (c) 2012, 2014, 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 "code/codeCache.hpp" 28 #include "memory/metadataFactory.hpp" 29 #include "memory/universe.hpp" 30 #include "oops/oop.inline.hpp" 31 32 #include "classfile/stringTable.hpp" 33 #include "classfile/classLoaderData.hpp" 34 35 #include "prims/whitebox.hpp" 36 #include "prims/wbtestmethods/parserTests.hpp" 37 38 #include "runtime/thread.hpp" 39 #include "runtime/arguments.hpp" 40 #include "runtime/interfaceSupport.hpp" 41 #include "runtime/os.hpp" 42 #include "runtime/vm_version.hpp" 43 44 #include "utilities/array.hpp" 45 #include "utilities/debug.hpp" 46 #include "utilities/macros.hpp" 47 #include "utilities/exceptions.hpp" 48 49 #if INCLUDE_ALL_GCS 50 #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" 51 #include "gc_implementation/g1/concurrentMark.hpp" 52 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" 53 #include "gc_implementation/g1/heapRegionRemSet.hpp" 54 #endif // INCLUDE_ALL_GCS 55 56 #if INCLUDE_NMT 57 #include "services/mallocSiteTable.hpp" 58 #include "services/memTracker.hpp" 59 #include "utilities/nativeCallStack.hpp" 60 #endif // INCLUDE_NMT 61 62 #include "compiler/compileBroker.hpp" 63 #include "runtime/compilationPolicy.hpp" 64 65 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 66 67 #define SIZE_T_MAX_VALUE ((size_t) -1) 68 69 bool WhiteBox::_used = false; 70 71 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) 72 return (jlong)(void*)JNIHandles::resolve(obj); 73 WB_END 74 75 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) 76 return heapOopSize; 77 WB_END 78 79 80 class WBIsKlassAliveClosure : public KlassClosure { 81 Symbol* _name; 82 bool _found; 83 public: 84 WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {} 85 86 void do_klass(Klass* k) { 87 if (_found) return; 88 Symbol* ksym = k->name(); 89 if (ksym->fast_compare(_name) == 0) { 90 _found = true; 91 } 92 } 93 94 bool found() const { 95 return _found; 96 } 97 }; 98 99 WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name)) 100 Handle h_name = JNIHandles::resolve(name); 101 if (h_name.is_null()) return false; 102 Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false); 103 TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return 104 105 WBIsKlassAliveClosure closure(sym); 106 ClassLoaderDataGraph::classes_do(&closure); 107 108 return closure.found(); 109 WB_END 110 111 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { 112 return (jlong)Arguments::max_heap_for_compressed_oops(); 113 } 114 WB_END 115 116 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { 117 CollectorPolicy * p = Universe::heap()->collector_policy(); 118 gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " 119 SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Space alignment "SIZE_FORMAT" Heap alignment "SIZE_FORMAT, 120 p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), 121 p->space_alignment(), p->heap_alignment()); 122 } 123 WB_END 124 125 #ifndef PRODUCT 126 // Forward declaration 127 void TestReservedSpace_test(); 128 void TestReserveMemorySpecial_test(); 129 void TestVirtualSpace_test(); 130 void TestMetaspaceAux_test(); 131 #endif 132 133 WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o)) 134 #ifndef PRODUCT 135 TestReservedSpace_test(); 136 TestReserveMemorySpecial_test(); 137 TestVirtualSpace_test(); 138 TestMetaspaceAux_test(); 139 #endif 140 WB_END 141 142 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o)) 143 size_t granularity = os::vm_allocation_granularity(); 144 ReservedHeapSpace rhs(100 * granularity, granularity, false, NULL); 145 VirtualSpace vs; 146 vs.initialize(rhs, 50 * granularity); 147 148 //Check if constraints are complied 149 if (!( UseCompressedOops && rhs.base() != NULL && 150 Universe::narrow_oop_base() != NULL && 151 Universe::narrow_oop_use_implicit_null_checks() )) { 152 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n " 153 "\tUseCompressedOops is %d\n" 154 "\trhs.base() is "PTR_FORMAT"\n" 155 "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n" 156 "\tUniverse::narrow_oop_use_implicit_null_checks() is %d", 157 UseCompressedOops, 158 rhs.base(), 159 Universe::narrow_oop_base(), 160 Universe::narrow_oop_use_implicit_null_checks()); 161 return; 162 } 163 tty->print_cr("Reading from no access area... "); 164 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c", 165 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 )); 166 WB_END 167 168 static jint wb_stress_virtual_space_resize(size_t reserved_space_size, 169 size_t magnitude, size_t iterations) { 170 size_t granularity = os::vm_allocation_granularity(); 171 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false, NULL); 172 VirtualSpace vs; 173 if (!vs.initialize(rhs, 0)) { 174 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed."); 175 return 3; 176 } 177 178 long seed = os::random(); 179 tty->print_cr("Random seed is %ld", seed); 180 os::init_random(seed); 181 182 for (size_t i = 0; i < iterations; i++) { 183 184 // Whether we will shrink or grow 185 bool shrink = os::random() % 2L == 0; 186 187 // Get random delta to resize virtual space 188 size_t delta = (size_t)os::random() % magnitude; 189 190 // If we are about to shrink virtual space below zero, then expand instead 191 if (shrink && vs.committed_size() < delta) { 192 shrink = false; 193 } 194 195 // Resizing by delta 196 if (shrink) { 197 vs.shrink_by(delta); 198 } else { 199 // If expanding fails expand_by will silently return false 200 vs.expand_by(delta, true); 201 } 202 } 203 return 0; 204 } 205 206 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o, 207 jlong reserved_space_size, jlong magnitude, jlong iterations)) 208 tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", " 209 "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude, 210 iterations); 211 if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) { 212 tty->print_cr("One of variables printed above is negative. Can't proceed.\n"); 213 return 1; 214 } 215 216 // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is 217 // always 8 byte. That's why we should avoid overflow in case of 32bit platform. 218 if (sizeof(size_t) < sizeof(jlong)) { 219 jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE; 220 if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value 221 || iterations > size_t_max_value) { 222 tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n"); 223 return 2; 224 } 225 } 226 227 return wb_stress_virtual_space_resize((size_t) reserved_space_size, 228 (size_t) magnitude, (size_t) iterations); 229 WB_END 230 231 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj)) 232 oop p = JNIHandles::resolve(obj); 233 #if INCLUDE_ALL_GCS 234 if (UseG1GC) { 235 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 236 const HeapRegion* hr = g1->heap_region_containing(p); 237 if (hr == NULL) { 238 return false; 239 } 240 return !(hr->is_young()); 241 } else if (UseParallelGC) { 242 ParallelScavengeHeap* psh = ParallelScavengeHeap::heap(); 243 return !psh->is_in_young(p); 244 } 245 #endif // INCLUDE_ALL_GCS 246 GenCollectedHeap* gch = GenCollectedHeap::heap(); 247 return !gch->is_in_young(p); 248 WB_END 249 250 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj)) 251 oop p = JNIHandles::resolve(obj); 252 return p->size() * HeapWordSize; 253 WB_END 254 255 #if INCLUDE_ALL_GCS 256 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) 257 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 258 oop result = JNIHandles::resolve(obj); 259 const HeapRegion* hr = g1->heap_region_containing(result); 260 return hr->is_humongous(); 261 WB_END 262 263 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) 264 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 265 size_t nr = g1->num_free_regions(); 266 return (jlong)nr; 267 WB_END 268 269 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) 270 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 271 ConcurrentMark* cm = g1->concurrent_mark(); 272 return cm->concurrent_marking_in_progress(); 273 WB_END 274 275 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) 276 return (jint)HeapRegion::GrainBytes; 277 WB_END 278 #endif // INCLUDE_ALL_GCS 279 280 #if INCLUDE_NMT 281 // Alloc memory using the test memory type so that we can use that to see if 282 // NMT picks it up correctly 283 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size)) 284 jlong addr = 0; 285 addr = (jlong)(uintptr_t)os::malloc(size, mtTest); 286 return addr; 287 WB_END 288 289 // Alloc memory with pseudo call stack. The test can create psudo malloc 290 // allocation site to stress the malloc tracking. 291 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack)) 292 address pc = (address)(size_t)pseudo_stack; 293 NativeCallStack stack(&pc, 1); 294 return (jlong)os::malloc(size, mtTest, stack); 295 WB_END 296 297 // Free the memory allocated by NMTAllocTest 298 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) 299 os::free((void*)(uintptr_t)mem, mtTest); 300 WB_END 301 302 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) 303 jlong addr = 0; 304 305 addr = (jlong)(uintptr_t)os::reserve_memory(size); 306 MemTracker::record_virtual_memory_type((address)addr, mtTest); 307 308 return addr; 309 WB_END 310 311 312 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 313 os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem); 314 MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest); 315 WB_END 316 317 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 318 os::uncommit_memory((char *)(uintptr_t)addr, size); 319 WB_END 320 321 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 322 os::release_memory((char *)(uintptr_t)addr, size); 323 WB_END 324 325 WB_ENTRY(jboolean, WB_NMTIsDetailSupported(JNIEnv* env)) 326 return MemTracker::tracking_level() == NMT_detail; 327 WB_END 328 329 WB_ENTRY(void, WB_NMTOverflowHashBucket(JNIEnv* env, jobject o, jlong num)) 330 address pc = (address)1; 331 for (jlong index = 0; index < num; index ++) { 332 NativeCallStack stack(&pc, 1); 333 os::malloc(0, mtTest, stack); 334 pc += MallocSiteTable::hash_buckets(); 335 } 336 WB_END 337 338 WB_ENTRY(jboolean, WB_NMTChangeTrackingLevel(JNIEnv* env)) 339 // Test that we can downgrade NMT levels but not upgrade them. 340 if (MemTracker::tracking_level() == NMT_off) { 341 MemTracker::transition_to(NMT_off); 342 return MemTracker::tracking_level() == NMT_off; 343 } else { 344 assert(MemTracker::tracking_level() == NMT_detail, "Should start out as detail tracking"); 345 MemTracker::transition_to(NMT_summary); 346 assert(MemTracker::tracking_level() == NMT_summary, "Should be summary now"); 347 348 // Can't go to detail once NMT is set to summary. 349 MemTracker::transition_to(NMT_detail); 350 assert(MemTracker::tracking_level() == NMT_summary, "Should still be summary now"); 351 352 // Shutdown sets tracking level to minimal. 353 MemTracker::shutdown(); 354 assert(MemTracker::tracking_level() == NMT_minimal, "Should be minimal now"); 355 356 // Once the tracking level is minimal, we cannot increase to summary. 357 // The code ignores this request instead of asserting because if the malloc site 358 // table overflows in another thread, it tries to change the code to summary. 359 MemTracker::transition_to(NMT_summary); 360 assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now"); 361 362 // Really can never go up to detail, verify that the code would never do this. 363 MemTracker::transition_to(NMT_detail); 364 assert(MemTracker::tracking_level() == NMT_minimal, "Should still be minimal now"); 365 return MemTracker::tracking_level() == NMT_minimal; 366 } 367 WB_END 368 #endif // INCLUDE_NMT 369 370 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { 371 assert(method != NULL, "method should not be null"); 372 ThreadToNativeFromVM ttn(thread); 373 return env->FromReflectedMethod(method); 374 } 375 376 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) 377 MutexLockerEx mu(Compile_lock); 378 CodeCache::mark_all_nmethods_for_deoptimization(); 379 VM_Deoptimize op; 380 VMThread::execute(&op); 381 WB_END 382 383 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 384 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 385 int result = 0; 386 CHECK_JNI_EXCEPTION_(env, result); 387 MutexLockerEx mu(Compile_lock); 388 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 389 nmethod* code; 390 if (is_osr) { 391 int bci = InvocationEntryBci; 392 while ((code = mh->lookup_osr_nmethod_for(bci, CompLevel_none, false)) != NULL) { 393 code->mark_for_deoptimization(); 394 ++result; 395 bci = code->osr_entry_bci() + 1; 396 } 397 } else { 398 code = mh->code(); 399 } 400 if (code != NULL) { 401 code->mark_for_deoptimization(); 402 ++result; 403 } 404 result += CodeCache::mark_for_deoptimization(mh()); 405 if (result > 0) { 406 VM_Deoptimize op; 407 VMThread::execute(&op); 408 } 409 return result; 410 WB_END 411 412 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 413 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 414 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 415 MutexLockerEx mu(Compile_lock); 416 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 417 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 418 if (code == NULL) { 419 return JNI_FALSE; 420 } 421 return (code->is_alive() && !code->is_marked_for_deoptimization()); 422 WB_END 423 424 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) 425 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 426 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 427 MutexLockerEx mu(Compile_lock); 428 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 429 if (is_osr) { 430 return CompilationPolicy::can_be_osr_compiled(mh, comp_level); 431 } else { 432 return CompilationPolicy::can_be_compiled(mh, comp_level); 433 } 434 WB_END 435 436 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) 437 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 438 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 439 MutexLockerEx mu(Compile_lock); 440 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 441 return mh->queued_for_compilation(); 442 WB_END 443 444 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 445 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 446 CHECK_JNI_EXCEPTION_(env, CompLevel_none); 447 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 448 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 449 return (code != NULL ? code->comp_level() : CompLevel_none); 450 WB_END 451 452 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) 453 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 454 CHECK_JNI_EXCEPTION(env); 455 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 456 if (is_osr) { 457 mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox"); 458 } else { 459 mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); 460 } 461 WB_END 462 463 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method)) 464 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 465 CHECK_JNI_EXCEPTION_(env, InvocationEntryBci); 466 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 467 nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false); 468 return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci); 469 WB_END 470 471 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) 472 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 473 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 474 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 475 bool result = mh->dont_inline(); 476 mh->set_dont_inline(value == JNI_TRUE); 477 return result; 478 WB_END 479 480 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level)) 481 if (comp_level == CompLevel_any) { 482 return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + 483 CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; 484 } else { 485 return CompileBroker::queue_size(comp_level); 486 } 487 WB_END 488 489 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) 490 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 491 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 492 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 493 bool result = mh->force_inline(); 494 mh->set_force_inline(value == JNI_TRUE); 495 return result; 496 WB_END 497 498 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) 499 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 500 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 501 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 502 nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); 503 MutexLockerEx mu(Compile_lock); 504 return (mh->queued_for_compilation() || nm != NULL); 505 WB_END 506 507 class VM_WhiteBoxOperation : public VM_Operation { 508 public: 509 VM_WhiteBoxOperation() { } 510 VMOp_Type type() const { return VMOp_WhiteBoxOperation; } 511 bool allow_nested_vm_operations() const { return true; } 512 }; 513 514 class AlwaysFalseClosure : public BoolObjectClosure { 515 public: 516 bool do_object_b(oop p) { return false; } 517 }; 518 519 static AlwaysFalseClosure always_false; 520 521 class VM_WhiteBoxCleanMethodData : public VM_WhiteBoxOperation { 522 public: 523 VM_WhiteBoxCleanMethodData(MethodData* mdo) : _mdo(mdo) { } 524 void doit() { 525 _mdo->clean_method_data(&always_false); 526 } 527 private: 528 MethodData* _mdo; 529 }; 530 531 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) 532 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 533 CHECK_JNI_EXCEPTION(env); 534 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 535 MutexLockerEx mu(Compile_lock); 536 MethodData* mdo = mh->method_data(); 537 MethodCounters* mcs = mh->method_counters(); 538 539 if (mdo != NULL) { 540 mdo->init(); 541 ResourceMark rm; 542 int arg_count = mdo->method()->size_of_parameters(); 543 for (int i = 0; i < arg_count; i++) { 544 mdo->set_arg_modified(i, 0); 545 } 546 VM_WhiteBoxCleanMethodData op(mdo); 547 VMThread::execute(&op); 548 } 549 550 mh->clear_not_c1_compilable(); 551 mh->clear_not_c2_compilable(); 552 mh->clear_not_c2_osr_compilable(); 553 NOT_PRODUCT(mh->set_compiled_invocation_count(0)); 554 if (mcs != NULL) { 555 mcs->backedge_counter()->init(); 556 mcs->invocation_counter()->init(); 557 mcs->set_interpreter_invocation_count(0); 558 mcs->set_interpreter_throwout_count(0); 559 560 #ifdef TIERED 561 mcs->set_rate(0.0F); 562 mh->set_prev_event_count(0); 563 mh->set_prev_time(0); 564 #endif 565 } 566 WB_END 567 568 template <typename T> 569 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*)) { 570 if (name == NULL) { 571 return false; 572 } 573 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 574 const char* flag_name = env->GetStringUTFChars(name, NULL); 575 bool result = (*TAt)(flag_name, value); 576 env->ReleaseStringUTFChars(name, flag_name); 577 return result; 578 } 579 580 template <typename T> 581 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAtPut)(const char*, T*, Flag::Flags)) { 582 if (name == NULL) { 583 return false; 584 } 585 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 586 const char* flag_name = env->GetStringUTFChars(name, NULL); 587 bool result = (*TAtPut)(flag_name, value, Flag::INTERNAL); 588 env->ReleaseStringUTFChars(name, flag_name); 589 return result; 590 } 591 592 template <typename T> 593 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) { 594 ResourceMark rm(thread); 595 jclass clazz = env->FindClass(name->as_C_string()); 596 CHECK_JNI_EXCEPTION_(env, NULL); 597 jmethodID methodID = env->GetStaticMethodID(clazz, 598 vmSymbols::valueOf_name()->as_C_string(), 599 sig->as_C_string()); 600 CHECK_JNI_EXCEPTION_(env, NULL); 601 jobject result = env->CallStaticObjectMethod(clazz, methodID, value); 602 CHECK_JNI_EXCEPTION_(env, NULL); 603 return result; 604 } 605 606 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) { 607 return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value); 608 } 609 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) { 610 return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value); 611 } 612 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) { 613 return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value); 614 } 615 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) { 616 return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value); 617 }*/ 618 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) { 619 return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value); 620 } 621 622 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name)) 623 bool result; 624 if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) { 625 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 626 return booleanBox(thread, env, result); 627 } 628 return NULL; 629 WB_END 630 631 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name)) 632 intx result; 633 if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) { 634 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 635 return longBox(thread, env, result); 636 } 637 return NULL; 638 WB_END 639 640 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name)) 641 uintx result; 642 if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) { 643 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 644 return longBox(thread, env, result); 645 } 646 return NULL; 647 WB_END 648 649 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name)) 650 uint64_t result; 651 if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) { 652 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 653 return longBox(thread, env, result); 654 } 655 return NULL; 656 WB_END 657 658 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name)) 659 uintx result; 660 if (GetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAt)) { 661 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 662 return longBox(thread, env, result); 663 } 664 return NULL; 665 WB_END 666 667 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name)) 668 double result; 669 if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) { 670 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 671 return doubleBox(thread, env, result); 672 } 673 return NULL; 674 WB_END 675 676 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name)) 677 ccstr ccstrResult; 678 if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) { 679 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 680 jstring result = env->NewStringUTF(ccstrResult); 681 CHECK_JNI_EXCEPTION_(env, NULL); 682 return result; 683 } 684 return NULL; 685 WB_END 686 687 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value)) 688 bool result = value == JNI_TRUE ? true : false; 689 SetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAtPut); 690 WB_END 691 692 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 693 intx result = value; 694 SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut); 695 WB_END 696 697 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 698 uintx result = value; 699 SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut); 700 WB_END 701 702 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 703 uint64_t result = value; 704 SetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAtPut); 705 WB_END 706 707 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 708 size_t result = value; 709 SetVMFlag <size_t> (thread, env, name, &result, &CommandLineFlags::size_tAtPut); 710 WB_END 711 712 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value)) 713 double result = value; 714 SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut); 715 WB_END 716 717 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value)) 718 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 719 const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL); 720 ccstr ccstrResult = ccstrValue; 721 bool needFree; 722 { 723 ThreadInVMfromNative ttvfn(thread); // back to VM 724 needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut); 725 } 726 if (value != NULL) { 727 env->ReleaseStringUTFChars(value, ccstrValue); 728 } 729 if (needFree) { 730 FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal); 731 } 732 WB_END 733 734 735 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) 736 ResourceMark rm(THREAD); 737 int len; 738 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); 739 return (StringTable::lookup(name, len) != NULL); 740 WB_END 741 742 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) 743 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); 744 Universe::heap()->collect(GCCause::_last_ditch_collection); 745 #if INCLUDE_ALL_GCS 746 if (UseG1GC) { 747 // Needs to be cleared explicitly for G1 748 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false); 749 } 750 #endif // INCLUDE_ALL_GCS 751 WB_END 752 753 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) 754 Universe::heap()->collect(GCCause::_wb_young_gc); 755 WB_END 756 757 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) 758 // static+volatile in order to force the read to happen 759 // (not be eliminated by the compiler) 760 static char c; 761 static volatile char* p; 762 763 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); 764 if (p == NULL) { 765 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); 766 } 767 768 c = *p; 769 WB_END 770 771 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o)) 772 const char* cpu_features = VM_Version::cpu_features(); 773 ThreadToNativeFromVM ttn(thread); 774 jstring features_string = env->NewStringUTF(cpu_features); 775 776 CHECK_JNI_EXCEPTION_(env, NULL); 777 778 return features_string; 779 WB_END 780 781 782 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 783 ResourceMark rm(THREAD); 784 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 785 CHECK_JNI_EXCEPTION_(env, NULL); 786 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 787 nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 788 jobjectArray result = NULL; 789 if (code == NULL) { 790 return result; 791 } 792 int insts_size = code->insts_size(); 793 794 ThreadToNativeFromVM ttn(thread); 795 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); 796 CHECK_JNI_EXCEPTION_(env, NULL); 797 result = env->NewObjectArray(2, clazz, NULL); 798 if (result == NULL) { 799 return result; 800 } 801 802 jobject obj = integerBox(thread, env, code->comp_level()); 803 CHECK_JNI_EXCEPTION_(env, NULL); 804 env->SetObjectArrayElement(result, 0, obj); 805 806 jbyteArray insts = env->NewByteArray(insts_size); 807 CHECK_JNI_EXCEPTION_(env, NULL); 808 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin()); 809 env->SetObjectArrayElement(result, 1, insts); 810 811 return result; 812 WB_END 813 814 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o)) 815 return (jlong) Thread::current()->stack_size(); 816 WB_END 817 818 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o)) 819 JavaThread* t = JavaThread::current(); 820 return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size(); 821 WB_END 822 823 int WhiteBox::array_bytes_to_length(size_t bytes) { 824 return Array<u1>::bytes_to_length(bytes); 825 } 826 827 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size)) 828 if (size < 0) { 829 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 830 err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size)); 831 } 832 833 oop class_loader_oop = JNIHandles::resolve(class_loader); 834 ClassLoaderData* cld = class_loader_oop != NULL 835 ? java_lang_ClassLoader::loader_data(class_loader_oop) 836 : ClassLoaderData::the_null_class_loader_data(); 837 838 void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread); 839 840 return (jlong)(uintptr_t)metadata; 841 WB_END 842 843 WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size)) 844 oop class_loader_oop = JNIHandles::resolve(class_loader); 845 ClassLoaderData* cld = class_loader_oop != NULL 846 ? java_lang_ClassLoader::loader_data(class_loader_oop) 847 : ClassLoaderData::the_null_class_loader_data(); 848 849 MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr); 850 WB_END 851 852 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc)) 853 if (inc < 0) { 854 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 855 err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc)); 856 } 857 858 jlong max_size_t = (jlong) ((size_t) -1); 859 if (inc > max_size_t) { 860 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 861 err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc)); 862 } 863 864 size_t new_cap_until_GC = 0; 865 size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment()); 866 bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC); 867 if (!success) { 868 THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), 869 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC " 870 "due to contention with another thread"); 871 } 872 return (jlong) new_cap_until_GC; 873 WB_END 874 875 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb)) 876 return (jlong) MetaspaceGC::capacity_until_GC(); 877 WB_END 878 879 //Some convenience methods to deal with objects from java 880 int WhiteBox::offset_for_field(const char* field_name, oop object, 881 Symbol* signature_symbol) { 882 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); 883 Thread* THREAD = Thread::current(); 884 885 //Get the class of our object 886 Klass* arg_klass = object->klass(); 887 //Turn it into an instance-klass 888 InstanceKlass* ik = InstanceKlass::cast(arg_klass); 889 890 //Create symbols to look for in the class 891 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), 892 THREAD); 893 894 //To be filled in with an offset of the field we're looking for 895 fieldDescriptor fd; 896 897 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); 898 if (res == NULL) { 899 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), 900 name_symbol->as_C_string()); 901 fatal("Invalid layout of preloaded class"); 902 } 903 904 //fetch the field at the offset we've found 905 int dest_offset = fd.offset(); 906 907 return dest_offset; 908 } 909 910 911 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { 912 int offset = offset_for_field(field_name, object, 913 vmSymbols::string_signature()); 914 oop string = object->obj_field(offset); 915 if (string == NULL) { 916 return NULL; 917 } 918 const char* ret = java_lang_String::as_utf8_string(string); 919 return ret; 920 } 921 922 bool WhiteBox::lookup_bool(const char* field_name, oop object) { 923 int offset = 924 offset_for_field(field_name, object, vmSymbols::bool_signature()); 925 bool ret = (object->bool_field(offset) == JNI_TRUE); 926 return ret; 927 } 928 929 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { 930 ResourceMark rm; 931 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 932 933 // one by one registration natives for exception catching 934 jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); 935 CHECK_JNI_EXCEPTION(env); 936 for (int i = 0, n = method_count; i < n; ++i) { 937 // Skip dummy entries 938 if (method_array[i].fnPtr == NULL) continue; 939 if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { 940 jthrowable throwable_obj = env->ExceptionOccurred(); 941 if (throwable_obj != NULL) { 942 env->ExceptionClear(); 943 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) { 944 // NoSuchMethodError is thrown when a method can't be found or a method is not native. 945 // Ignoring the exception since it is not preventing use of other WhiteBox methods. 946 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", 947 method_array[i].name, method_array[i].signature); 948 } 949 } else { 950 // Registration failed unexpectedly. 951 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", 952 method_array[i].name, method_array[i].signature); 953 env->UnregisterNatives(wbclass); 954 break; 955 } 956 } 957 } 958 } 959 960 #define CC (char*) 961 962 static JNINativeMethod methods[] = { 963 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, 964 {CC"getObjectSize", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, 965 {CC"isObjectInOldGen", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, 966 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, 967 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, 968 {CC"parseCommandLine", 969 CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", 970 (void*) &WB_ParseCommandLine 971 }, 972 {CC"getCompressedOopsMaxHeapSize", CC"()J", 973 (void*)&WB_GetCompressedOopsMaxHeapSize}, 974 {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, 975 {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests}, 976 {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, 977 {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, 978 #if INCLUDE_ALL_GCS 979 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, 980 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, 981 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, 982 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, 983 #endif // INCLUDE_ALL_GCS 984 #if INCLUDE_NMT 985 {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, 986 {CC"NMTMallocWithPseudoStack", CC"(JI)J", (void*)&WB_NMTMallocWithPseudoStack}, 987 {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, 988 {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, 989 {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, 990 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, 991 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, 992 {CC"NMTOverflowHashBucket", CC"(J)V", (void*)&WB_NMTOverflowHashBucket}, 993 {CC"NMTIsDetailSupported",CC"()Z", (void*)&WB_NMTIsDetailSupported}, 994 {CC"NMTChangeTrackingLevel", CC"()Z", (void*)&WB_NMTChangeTrackingLevel}, 995 #endif // INCLUDE_NMT 996 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, 997 {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;Z)I", 998 (void*)&WB_DeoptimizeMethod }, 999 {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;Z)Z", 1000 (void*)&WB_IsMethodCompiled }, 1001 {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z", 1002 (void*)&WB_IsMethodCompilable}, 1003 {CC"isMethodQueuedForCompilation", 1004 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, 1005 {CC"makeMethodNotCompilable", 1006 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable}, 1007 {CC"testSetDontInlineMethod", 1008 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, 1009 {CC"getMethodCompilationLevel", 1010 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel}, 1011 {CC"getMethodEntryBci", 1012 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, 1013 {CC"getCompileQueueSize", 1014 CC"(I)I", (void*)&WB_GetCompileQueueSize}, 1015 {CC"testSetForceInlineMethod", 1016 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, 1017 {CC"enqueueMethodForCompilation", 1018 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, 1019 {CC"clearMethodState", 1020 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, 1021 {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag}, 1022 {CC"setIntxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag}, 1023 {CC"setUintxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag}, 1024 {CC"setUint64VMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag}, 1025 {CC"setSizeTVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag}, 1026 {CC"setDoubleVMFlag", CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag}, 1027 {CC"setStringVMFlag", CC"(Ljava/lang/String;Ljava/lang/String;)V", 1028 (void*)&WB_SetStringVMFlag}, 1029 {CC"getBooleanVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Boolean;", 1030 (void*)&WB_GetBooleanVMFlag}, 1031 {CC"getIntxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1032 (void*)&WB_GetIntxVMFlag}, 1033 {CC"getUintxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1034 (void*)&WB_GetUintxVMFlag}, 1035 {CC"getUint64VMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1036 (void*)&WB_GetUint64VMFlag}, 1037 {CC"getSizeTVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1038 (void*)&WB_GetSizeTVMFlag}, 1039 {CC"getDoubleVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Double;", 1040 (void*)&WB_GetDoubleVMFlag}, 1041 {CC"getStringVMFlag", CC"(Ljava/lang/String;)Ljava/lang/String;", 1042 (void*)&WB_GetStringVMFlag}, 1043 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, 1044 {CC"fullGC", CC"()V", (void*)&WB_FullGC }, 1045 {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, 1046 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, 1047 {CC"allocateMetaspace", 1048 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, 1049 {CC"freeMetaspace", 1050 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace }, 1051 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, 1052 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, 1053 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, 1054 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", 1055 (void*)&WB_GetNMethod }, 1056 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize }, 1057 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize }, 1058 }; 1059 1060 #undef CC 1061 1062 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) 1063 { 1064 if (WhiteBoxAPI) { 1065 // Make sure that wbclass is loaded by the null classloader 1066 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); 1067 Handle loader(ikh->class_loader()); 1068 if (loader.is_null()) { 1069 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0])); 1070 WhiteBox::register_extended(env, wbclass, thread); 1071 WhiteBox::set_used(); 1072 } 1073 } 1074 } 1075 JVM_END