whitebox.cpp revision 9111:a41fe5ffa839
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 68PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC 69 70#define SIZE_T_MAX_VALUE ((size_t) -1) 71 72bool WhiteBox::_used = false; 73volatile bool WhiteBox::compilation_locked = false; 74 75class 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 83WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) 84 return (jlong)(void*)JNIHandles::resolve(obj); 85WB_END 86 87WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) 88 return heapOopSize; 89WB_END 90 91WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o)) 92 return os::vm_page_size(); 93WB_END 94 95WB_ENTRY(jlong, WB_GetVMAllocationGranularity(JNIEnv* env, jobject o)) 96 return os::vm_allocation_granularity(); 97WB_END 98 99WB_ENTRY(jlong, WB_GetVMLargePageSize(JNIEnv* env, jobject o)) 100 return os::large_page_size(); 101WB_END 102 103class WBIsKlassAliveClosure : public KlassClosure { 104 Symbol* _name; 105 bool _found; 106public: 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 122WB_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(); 132WB_END 133 134WB_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} 143WB_END 144 145WB_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} 154WB_END 155 156 157WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { 158 return (jlong)Arguments::max_heap_for_compressed_oops(); 159} 160WB_END 161 162WB_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} 169WB_END 170 171#ifndef PRODUCT 172// Forward declaration 173void TestReservedSpace_test(); 174void TestReserveMemorySpecial_test(); 175void TestVirtualSpace_test(); 176void TestMetaspaceAux_test(); 177#endif 178 179WB_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 186WB_END 187 188WB_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 )); 212WB_END 213 214static 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 252WB_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); 275WB_END 276 277WB_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); 294WB_END 295 296WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj)) 297 oop p = JNIHandles::resolve(obj); 298 return p->size() * HeapWordSize; 299WB_END 300 301WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o)) 302 size_t alignment = Universe::heap()->collector_policy()->space_alignment(); 303 return (jlong)alignment; 304WB_END 305 306#if INCLUDE_ALL_GCS 307WB_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(); 312WB_END 313 314WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o)) 315 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 316 size_t nr = g1->max_regions(); 317 return (jlong)nr; 318WB_END 319 320WB_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; 324WB_END 325 326WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) 327 G1CollectedHeap* g1 = G1CollectedHeap::heap(); 328 return g1->concurrent_mark()->cmThread()->during_cycle(); 329WB_END 330 331WB_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; 338WB_END 339 340WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) 341 return (jint)HeapRegion::GrainBytes; 342WB_END 343 344WB_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; 348WB_END 349 350WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o)) 351 size_t alignment = ParallelScavengeHeap::heap()->generation_alignment(); 352 return (jlong)alignment; 353WB_END 354 355WB_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()); 361WB_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 367WB_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; 371WB_END 372 373// Alloc memory with pseudo call stack. The test can create psudo malloc 374// allocation site to stress the malloc tracking. 375WB_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); 379WB_END 380 381// Free the memory allocated by NMTAllocTest 382WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) 383 os::free((void*)(uintptr_t)mem); 384WB_END 385 386WB_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; 393WB_END 394 395WB_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); 398WB_END 399 400WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 401 os::uncommit_memory((char *)(uintptr_t)addr, size); 402WB_END 403 404WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 405 os::release_memory((char *)(uintptr_t)addr, size); 406WB_END 407 408WB_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 } 437WB_END 438 439WB_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; 443WB_END 444#endif // INCLUDE_NMT 445 446static 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 453class 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 483WB_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(); 487WB_END 488 489WB_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); 494WB_END 495 496WB_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; 514WB_END 515 516WB_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()); 526WB_END 527 528WB_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 } 538WB_END 539 540WB_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(); 546WB_END 547 548WB_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 } 564WB_END 565 566WB_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); 572WB_END 573 574WB_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 } 583WB_END 584 585WB_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); 591WB_END 592 593WB_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; 600WB_END 601 602WB_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 } 609WB_END 610 611WB_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; 618WB_END 619 620WB_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); 627WB_END 628 629 630WB_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; 653WB_END 654 655class AlwaysFalseClosure : public BoolObjectClosure { 656 public: 657 bool do_object_b(oop p) { return false; } 658}; 659 660static AlwaysFalseClosure always_false; 661 662WB_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 } 697WB_END 698 699template <typename T> 700static 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 711template <typename T> 712static 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 723template <typename T> 724static 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 737static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) { 738 return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value); 739} 740static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) { 741 return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value); 742} 743static 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}*/ 749static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) { 750 return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value); 751} 752 753static 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 761WB_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(); 764WB_END 765 766WB_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()); 769WB_END 770 771WB_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; 778WB_END 779 780WB_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; 787WB_END 788 789WB_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; 796WB_END 797 798WB_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; 805WB_END 806 807WB_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; 814WB_END 815 816WB_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; 823WB_END 824 825WB_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; 832WB_END 833 834WB_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; 841WB_END 842 843WB_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; 852WB_END 853 854WB_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); 857WB_END 858 859WB_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); 862WB_END 863 864WB_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); 867WB_END 868 869WB_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); 872WB_END 873 874WB_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); 877WB_END 878 879WB_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); 882WB_END 883 884WB_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); 887WB_END 888 889WB_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); 892WB_END 893 894WB_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 } 909WB_END 910 911WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout)) 912 WhiteBox::compilation_locked = true; 913WB_END 914 915WB_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(); 919WB_END 920 921WB_ENTRY(void, WB_ForceNMethodSweep(JNIEnv* env, jobject o)) 922 // Force a code cache sweep and block until it finished 923 NMethodSweeper::force_sweep(); 924WB_END 925 926WB_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); 931WB_END 932 933WB_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 942WB_END 943 944WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) 945 Universe::heap()->collect(GCCause::_wb_young_gc); 946WB_END 947 948WB_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; 960WB_END 961 962WB_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; 970WB_END 971 972int 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 977CodeHeap* 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 982struct 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 993static 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 1013WB_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(5, 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 jobject address = longBox(thread, env, (jlong) code); 1051 CHECK_JNI_EXCEPTION_(env, NULL); 1052 env->SetObjectArrayElement(result, 4, address); 1053 1054 return result; 1055WB_END 1056 1057CodeBlob* WhiteBox::allocate_code_blob(int size, int blob_type) { 1058 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); 1059 BufferBlob* blob; 1060 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob)); 1061 if (full_size < size) { 1062 full_size += round_to(size - full_size, oopSize); 1063 } 1064 { 1065 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1066 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type); 1067 ::new (blob) BufferBlob("WB::DummyBlob", full_size); 1068 } 1069 // Track memory usage statistic after releasing CodeCache_lock 1070 MemoryService::track_code_cache_memory_usage(); 1071 return blob; 1072} 1073 1074WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type)) 1075 if (size < 0) { 1076 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1077 err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size)); 1078 } 1079 return (jlong) WhiteBox::allocate_code_blob(size, blob_type); 1080WB_END 1081 1082WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr)) 1083 if (addr == 0) { 1084 return; 1085 } 1086 BufferBlob::free((BufferBlob*) addr); 1087WB_END 1088 1089WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type)) 1090 ResourceMark rm; 1091 GrowableArray<CodeBlobStub*> blobs; 1092 { 1093 MutexLockerEx mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1094 CodeHeap* heap = WhiteBox::get_code_heap(blob_type); 1095 if (heap == NULL) { 1096 return NULL; 1097 } 1098 for (CodeBlob* cb = (CodeBlob*) heap->first(); 1099 cb != NULL; cb = (CodeBlob*) heap->next(cb)) { 1100 CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub); 1101 new (stub) CodeBlobStub(cb); 1102 blobs.append(stub); 1103 } 1104 } 1105 if (blobs.length() == 0) { 1106 return NULL; 1107 } 1108 ThreadToNativeFromVM ttn(thread); 1109 jobjectArray result = NULL; 1110 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); 1111 CHECK_JNI_EXCEPTION_(env, NULL); 1112 result = env->NewObjectArray(blobs.length(), clazz, NULL); 1113 if (result == NULL) { 1114 return result; 1115 } 1116 int i = 0; 1117 for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin(); 1118 it != blobs.end(); ++it) { 1119 jobjectArray obj = codeBlob2objectArray(thread, env, *it); 1120 env->SetObjectArrayElement(result, i, obj); 1121 ++i; 1122 } 1123 return result; 1124WB_END 1125 1126WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o)) 1127 return CompileBroker::get_compilation_activity_mode(); 1128WB_END 1129 1130WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr)) 1131 if (addr == 0) { 1132 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), 1133 "WB_GetCodeBlob: addr is null"); 1134 } 1135 ThreadToNativeFromVM ttn(thread); 1136 CodeBlobStub stub((CodeBlob*) addr); 1137 return codeBlob2objectArray(thread, env, &stub); 1138WB_END 1139 1140WB_ENTRY(jlong, WB_GetMethodData(JNIEnv* env, jobject wv, jobject method)) 1141 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1142 CHECK_JNI_EXCEPTION_(env, 0); 1143 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid)); 1144 return (jlong) mh->method_data(); 1145WB_END 1146 1147WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o)) 1148 return (jlong) Thread::current()->stack_size(); 1149WB_END 1150 1151WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o)) 1152 JavaThread* t = JavaThread::current(); 1153 return (jlong) t->stack_available(os::current_stack_pointer()) - (jlong) StackShadowPages * os::vm_page_size(); 1154WB_END 1155 1156 1157int WhiteBox::array_bytes_to_length(size_t bytes) { 1158 return Array<u1>::bytes_to_length(bytes); 1159} 1160 1161WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size)) 1162 if (size < 0) { 1163 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1164 err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size)); 1165 } 1166 1167 oop class_loader_oop = JNIHandles::resolve(class_loader); 1168 ClassLoaderData* cld = class_loader_oop != NULL 1169 ? java_lang_ClassLoader::loader_data(class_loader_oop) 1170 : ClassLoaderData::the_null_class_loader_data(); 1171 1172 void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread); 1173 1174 return (jlong)(uintptr_t)metadata; 1175WB_END 1176 1177WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size)) 1178 oop class_loader_oop = JNIHandles::resolve(class_loader); 1179 ClassLoaderData* cld = class_loader_oop != NULL 1180 ? java_lang_ClassLoader::loader_data(class_loader_oop) 1181 : ClassLoaderData::the_null_class_loader_data(); 1182 1183 MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr); 1184WB_END 1185 1186WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc)) 1187 if (inc < 0) { 1188 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1189 err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc)); 1190 } 1191 1192 jlong max_size_t = (jlong) ((size_t) -1); 1193 if (inc > max_size_t) { 1194 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1195 err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc)); 1196 } 1197 1198 size_t new_cap_until_GC = 0; 1199 size_t aligned_inc = align_size_down((size_t) inc, Metaspace::commit_alignment()); 1200 bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC); 1201 if (!success) { 1202 THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), 1203 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC " 1204 "due to contention with another thread"); 1205 } 1206 return (jlong) new_cap_until_GC; 1207WB_END 1208 1209WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb)) 1210 return (jlong) MetaspaceGC::capacity_until_GC(); 1211WB_END 1212 1213 1214 1215WB_ENTRY(void, WB_AssertMatchingSafepointCalls(JNIEnv* env, jobject o, jboolean mutexSafepointValue, jboolean attemptedNoSafepointValue)) 1216 Monitor::SafepointCheckRequired sfpt_check_required = mutexSafepointValue ? 1217 Monitor::_safepoint_check_always : 1218 Monitor::_safepoint_check_never; 1219 MutexLockerEx ml(new Mutex(Mutex::leaf, "SFPT_Test_lock", true, sfpt_check_required), 1220 attemptedNoSafepointValue == JNI_TRUE); 1221WB_END 1222 1223WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) 1224 oop obj_oop = JNIHandles::resolve(obj); 1225 return (jboolean) obj_oop->mark()->has_monitor(); 1226WB_END 1227 1228WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb)) 1229 VM_ForceSafepoint force_safepoint_op; 1230 VMThread::execute(&force_safepoint_op); 1231WB_END 1232 1233WB_ENTRY(long, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass)) 1234 instanceKlassHandle ikh(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1235 return (long) ikh->constants(); 1236WB_END 1237 1238template <typename T> 1239static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) { 1240 assert(value != NULL, "sanity"); 1241 if (method == NULL || name == NULL) { 1242 return false; 1243 } 1244 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1245 CHECK_JNI_EXCEPTION_(env, false); 1246 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid)); 1247 // can't be in VM when we call JNI 1248 ThreadToNativeFromVM ttnfv(thread); 1249 const char* flag_name = env->GetStringUTFChars(name, NULL); 1250 bool result = CompilerOracle::has_option_value(mh, flag_name, *value); 1251 env->ReleaseStringUTFChars(name, flag_name); 1252 return result; 1253} 1254 1255WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 1256 bool result; 1257 if (GetMethodOption<bool> (thread, env, method, name, &result)) { 1258 // can't be in VM when we call JNI 1259 ThreadToNativeFromVM ttnfv(thread); 1260 return booleanBox(thread, env, result); 1261 } 1262 return NULL; 1263WB_END 1264 1265WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 1266 intx result; 1267 if (GetMethodOption <intx> (thread, env, method, name, &result)) { 1268 // can't be in VM when we call JNI 1269 ThreadToNativeFromVM ttnfv(thread); 1270 return longBox(thread, env, result); 1271 } 1272 return NULL; 1273WB_END 1274 1275WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 1276 uintx result; 1277 if (GetMethodOption <uintx> (thread, env, method, name, &result)) { 1278 // can't be in VM when we call JNI 1279 ThreadToNativeFromVM ttnfv(thread); 1280 return longBox(thread, env, result); 1281 } 1282 return NULL; 1283WB_END 1284 1285WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 1286 double result; 1287 if (GetMethodOption <double> (thread, env, method, name, &result)) { 1288 // can't be in VM when we call JNI 1289 ThreadToNativeFromVM ttnfv(thread); 1290 return doubleBox(thread, env, result); 1291 } 1292 return NULL; 1293WB_END 1294 1295WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 1296 ccstr ccstrResult; 1297 if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) { 1298 // can't be in VM when we call JNI 1299 ThreadToNativeFromVM ttnfv(thread); 1300 jstring result = env->NewStringUTF(ccstrResult); 1301 CHECK_JNI_EXCEPTION_(env, NULL); 1302 return result; 1303 } 1304 return NULL; 1305WB_END 1306 1307WB_ENTRY(jboolean, WB_IsShared(JNIEnv* env, jobject wb, jobject obj)) 1308 oop obj_oop = JNIHandles::resolve(obj); 1309 return MetaspaceShared::is_in_shared_space((void*)obj_oop); 1310WB_END 1311 1312WB_ENTRY(jboolean, WB_AreSharedStringsIgnored(JNIEnv* env)) 1313 return StringTable::shared_string_ignored(); 1314WB_END 1315 1316//Some convenience methods to deal with objects from java 1317int WhiteBox::offset_for_field(const char* field_name, oop object, 1318 Symbol* signature_symbol) { 1319 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); 1320 Thread* THREAD = Thread::current(); 1321 1322 //Get the class of our object 1323 Klass* arg_klass = object->klass(); 1324 //Turn it into an instance-klass 1325 InstanceKlass* ik = InstanceKlass::cast(arg_klass); 1326 1327 //Create symbols to look for in the class 1328 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), 1329 THREAD); 1330 1331 //To be filled in with an offset of the field we're looking for 1332 fieldDescriptor fd; 1333 1334 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); 1335 if (res == NULL) { 1336 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), 1337 name_symbol->as_C_string()); 1338 vm_exit_during_initialization("Invalid layout of preloaded class: use -XX:+TraceClassLoading to see the origin of the problem class"); 1339 } 1340 1341 //fetch the field at the offset we've found 1342 int dest_offset = fd.offset(); 1343 1344 return dest_offset; 1345} 1346 1347 1348const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { 1349 int offset = offset_for_field(field_name, object, 1350 vmSymbols::string_signature()); 1351 oop string = object->obj_field(offset); 1352 if (string == NULL) { 1353 return NULL; 1354 } 1355 const char* ret = java_lang_String::as_utf8_string(string); 1356 return ret; 1357} 1358 1359bool WhiteBox::lookup_bool(const char* field_name, oop object) { 1360 int offset = 1361 offset_for_field(field_name, object, vmSymbols::bool_signature()); 1362 bool ret = (object->bool_field(offset) == JNI_TRUE); 1363 return ret; 1364} 1365 1366void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { 1367 ResourceMark rm; 1368 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1369 1370 // one by one registration natives for exception catching 1371 jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); 1372 CHECK_JNI_EXCEPTION(env); 1373 for (int i = 0, n = method_count; i < n; ++i) { 1374 // Skip dummy entries 1375 if (method_array[i].fnPtr == NULL) continue; 1376 if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { 1377 jthrowable throwable_obj = env->ExceptionOccurred(); 1378 if (throwable_obj != NULL) { 1379 env->ExceptionClear(); 1380 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) { 1381 // NoSuchMethodError is thrown when a method can't be found or a method is not native. 1382 // Ignoring the exception since it is not preventing use of other WhiteBox methods. 1383 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", 1384 method_array[i].name, method_array[i].signature); 1385 } 1386 } else { 1387 // Registration failed unexpectedly. 1388 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", 1389 method_array[i].name, method_array[i].signature); 1390 env->UnregisterNatives(wbclass); 1391 break; 1392 } 1393 } 1394 } 1395} 1396 1397#define CC (char*) 1398 1399static JNINativeMethod methods[] = { 1400 {CC"getObjectAddress0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, 1401 {CC"getObjectSize0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, 1402 {CC"isObjectInOldGen0", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, 1403 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, 1404 {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize }, 1405 {CC"getVMAllocationGranularity", CC"()J", (void*)&WB_GetVMAllocationGranularity }, 1406 {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize}, 1407 {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment}, 1408 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, 1409 {CC"parseCommandLine0", 1410 CC"(Ljava/lang/String;C[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", 1411 (void*) &WB_ParseCommandLine 1412 }, 1413 {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V", 1414 (void*)&WB_AddToBootstrapClassLoaderSearch}, 1415 {CC"addToSystemClassLoaderSearch0", CC"(Ljava/lang/String;)V", 1416 (void*)&WB_AddToSystemClassLoaderSearch}, 1417 {CC"getCompressedOopsMaxHeapSize", CC"()J", 1418 (void*)&WB_GetCompressedOopsMaxHeapSize}, 1419 {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, 1420 {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests}, 1421 {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, 1422 {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, 1423#if INCLUDE_ALL_GCS 1424 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, 1425 {CC"g1IsHumongous0", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, 1426 {CC"g1NumMaxRegions", CC"()J", (void*)&WB_G1NumMaxRegions }, 1427 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, 1428 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, 1429 {CC"g1StartConcMarkCycle", CC"()Z", (void*)&WB_G1StartMarkCycle }, 1430 {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;", 1431 (void*)&WB_G1AuxiliaryMemoryUsage }, 1432 {CC"psVirtualSpaceAlignment",CC"()J", (void*)&WB_PSVirtualSpaceAlignment}, 1433 {CC"psHeapGenerationAlignment",CC"()J", (void*)&WB_PSHeapGenerationAlignment}, 1434#endif // INCLUDE_ALL_GCS 1435#if INCLUDE_NMT 1436 {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, 1437 {CC"NMTMallocWithPseudoStack", CC"(JI)J", (void*)&WB_NMTMallocWithPseudoStack}, 1438 {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, 1439 {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, 1440 {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, 1441 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, 1442 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, 1443 {CC"NMTChangeTrackingLevel", CC"()Z", (void*)&WB_NMTChangeTrackingLevel}, 1444 {CC"NMTGetHashSize", CC"()I", (void*)&WB_NMTGetHashSize }, 1445#endif // INCLUDE_NMT 1446 {CC"deoptimizeFrames", CC"(Z)I", (void*)&WB_DeoptimizeFrames }, 1447 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, 1448 {CC"deoptimizeMethod0", CC"(Ljava/lang/reflect/Executable;Z)I", 1449 (void*)&WB_DeoptimizeMethod }, 1450 {CC"isMethodCompiled0", CC"(Ljava/lang/reflect/Executable;Z)Z", 1451 (void*)&WB_IsMethodCompiled }, 1452 {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z", 1453 (void*)&WB_IsMethodCompilable}, 1454 {CC"isMethodQueuedForCompilation0", 1455 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, 1456 {CC"isIntrinsicAvailable0", 1457 CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z", 1458 (void*)&WB_IsIntrinsicAvailable}, 1459 {CC"makeMethodNotCompilable0", 1460 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable}, 1461 {CC"testSetDontInlineMethod0", 1462 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, 1463 {CC"getMethodCompilationLevel0", 1464 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel}, 1465 {CC"getMethodEntryBci0", 1466 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, 1467 {CC"getCompileQueueSize", 1468 CC"(I)I", (void*)&WB_GetCompileQueueSize}, 1469 {CC"testSetForceInlineMethod0", 1470 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, 1471 {CC"enqueueMethodForCompilation0", 1472 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, 1473 {CC"clearMethodState0", 1474 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, 1475 {CC"lockCompilation", CC"()V", (void*)&WB_LockCompilation}, 1476 {CC"unlockCompilation", CC"()V", (void*)&WB_UnlockCompilation}, 1477 {CC"matchesMethod", 1478 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I", 1479 (void*)&WB_MatchesMethod}, 1480 {CC"isConstantVMFlag", CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag}, 1481 {CC"isLockedVMFlag", CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag}, 1482 {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag}, 1483 {CC"setIntVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag}, 1484 {CC"setUintVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag}, 1485 {CC"setIntxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag}, 1486 {CC"setUintxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag}, 1487 {CC"setUint64VMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag}, 1488 {CC"setSizeTVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag}, 1489 {CC"setDoubleVMFlag", CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag}, 1490 {CC"setStringVMFlag", CC"(Ljava/lang/String;Ljava/lang/String;)V", 1491 (void*)&WB_SetStringVMFlag}, 1492 {CC"getBooleanVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Boolean;", 1493 (void*)&WB_GetBooleanVMFlag}, 1494 {CC"getIntVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1495 (void*)&WB_GetIntVMFlag}, 1496 {CC"getUintVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1497 (void*)&WB_GetUintVMFlag}, 1498 {CC"getIntxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1499 (void*)&WB_GetIntxVMFlag}, 1500 {CC"getUintxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1501 (void*)&WB_GetUintxVMFlag}, 1502 {CC"getUint64VMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1503 (void*)&WB_GetUint64VMFlag}, 1504 {CC"getSizeTVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 1505 (void*)&WB_GetSizeTVMFlag}, 1506 {CC"getDoubleVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Double;", 1507 (void*)&WB_GetDoubleVMFlag}, 1508 {CC"getStringVMFlag", CC"(Ljava/lang/String;)Ljava/lang/String;", 1509 (void*)&WB_GetStringVMFlag}, 1510 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, 1511 {CC"fullGC", CC"()V", (void*)&WB_FullGC }, 1512 {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, 1513 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, 1514 {CC"allocateMetaspace", 1515 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, 1516 {CC"freeMetaspace", 1517 CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace }, 1518 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, 1519 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, 1520 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, 1521 {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", 1522 (void*)&WB_GetNMethod }, 1523 {CC"forceNMethodSweep", CC"()V", (void*)&WB_ForceNMethodSweep }, 1524 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, 1525 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, 1526 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries }, 1527 {CC"getCompilationActivityMode", 1528 CC"()I", (void*)&WB_GetCompilationActivityMode}, 1529 {CC"getMethodData0", CC"(Ljava/lang/reflect/Executable;)J", 1530 (void*)&WB_GetMethodData }, 1531 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob }, 1532 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize }, 1533 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize }, 1534 {CC"assertMatchingSafepointCalls", CC"(ZZ)V", (void*)&WB_AssertMatchingSafepointCalls }, 1535 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated }, 1536 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint }, 1537 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool }, 1538 {CC"getMethodBooleanOption", 1539 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;", 1540 (void*)&WB_GetMethodBooleaneOption}, 1541 {CC"getMethodIntxOption", 1542 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;", 1543 (void*)&WB_GetMethodIntxOption}, 1544 {CC"getMethodUintxOption", 1545 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;", 1546 (void*)&WB_GetMethodUintxOption}, 1547 {CC"getMethodDoubleOption", 1548 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;", 1549 (void*)&WB_GetMethodDoubleOption}, 1550 {CC"getMethodStringOption", 1551 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;", 1552 (void*)&WB_GetMethodStringOption}, 1553 {CC"isShared", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsShared }, 1554 {CC"areSharedStringsIgnored", CC"()Z", (void*)&WB_AreSharedStringsIgnored }, 1555}; 1556 1557#undef CC 1558 1559JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) 1560 { 1561 if (WhiteBoxAPI) { 1562 // Make sure that wbclass is loaded by the null classloader 1563 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); 1564 Handle loader(ikh->class_loader()); 1565 if (loader.is_null()) { 1566 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0])); 1567 WhiteBox::register_extended(env, wbclass, thread); 1568 WhiteBox::set_used(); 1569 } 1570 } 1571 } 1572JVM_END 1573