1 /* 2 * Copyright (c) 2012, 2024, 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 #include "cds.h" 27 #include "cds/archiveHeapLoader.hpp" 28 #include "cds/cdsConstants.hpp" 29 #include "cds/filemap.hpp" 30 #include "cds/heapShared.hpp" 31 #include "cds/metaspaceShared.hpp" 32 #include "classfile/classLoaderDataGraph.hpp" 33 #include "classfile/classLoaderStats.hpp" 34 #include "classfile/classPrinter.hpp" 35 #include "classfile/javaClasses.inline.hpp" 36 #include "classfile/modules.hpp" 37 #include "classfile/protectionDomainCache.hpp" 38 #include "classfile/stringTable.hpp" 39 #include "classfile/symbolTable.hpp" 40 #include "classfile/systemDictionary.hpp" 41 #include "classfile/vmSymbols.hpp" 42 #include "code/codeCache.hpp" 43 #include "compiler/compilationPolicy.hpp" 44 #include "compiler/directivesParser.hpp" 45 #include "compiler/methodMatcher.hpp" 46 #include "gc/shared/concurrentGCBreakpoints.hpp" 47 #include "gc/shared/gcConfig.hpp" 48 #include "gc/shared/gcLocker.inline.hpp" 49 #include "gc/shared/genArguments.hpp" 50 #include "jvmtifiles/jvmtiEnv.hpp" 51 #include "logging/log.hpp" 52 #include "memory/iterator.hpp" 53 #include "memory/metadataFactory.hpp" 54 #include "memory/iterator.inline.hpp" 55 #include "memory/metaspace/testHelpers.hpp" 56 #include "memory/metaspaceUtils.hpp" 57 #include "memory/oopFactory.hpp" 58 #include "memory/resourceArea.hpp" 59 #include "memory/universe.hpp" 60 #include "nmt/mallocSiteTable.hpp" 61 #include "nmt/memTracker.hpp" 62 #include "oops/array.hpp" 63 #include "oops/compressedOops.hpp" 64 #include "oops/compressedOops.inline.hpp" 65 #include "oops/constantPool.inline.hpp" 66 #include "oops/klass.inline.hpp" 67 #include "oops/method.inline.hpp" 68 #include "oops/methodData.inline.hpp" 69 #include "oops/objArrayKlass.hpp" 70 #include "oops/objArrayOop.inline.hpp" 71 #include "oops/oop.inline.hpp" 72 #include "oops/objArrayOop.inline.hpp" 73 #include "oops/typeArrayOop.inline.hpp" 74 #include "prims/jvmtiEnvBase.hpp" 75 #include "prims/resolvedMethodTable.hpp" 76 #include "prims/wbtestmethods/parserTests.hpp" 77 #include "prims/whitebox.inline.hpp" 78 #include "runtime/arguments.hpp" 79 #include "runtime/atomic.hpp" 80 #include "runtime/deoptimization.hpp" 81 #include "runtime/fieldDescriptor.inline.hpp" 82 #include "runtime/flags/jvmFlag.hpp" 83 #include "runtime/flags/jvmFlagAccess.hpp" 84 #include "runtime/frame.inline.hpp" 85 #include "runtime/handles.inline.hpp" 86 #include "runtime/handshake.hpp" 87 #include "runtime/interfaceSupport.inline.hpp" 88 #include "runtime/javaCalls.hpp" 89 #include "runtime/javaThread.inline.hpp" 90 #include "runtime/jniHandles.inline.hpp" 91 #include "runtime/lockStack.hpp" 92 #include "runtime/os.hpp" 93 #include "runtime/stackFrameStream.inline.hpp" 94 #include "runtime/synchronizer.hpp" 95 #include "runtime/threadSMR.hpp" 96 #include "runtime/vframe.hpp" 97 #include "runtime/vm_version.hpp" 98 #include "services/memoryService.hpp" 99 #include "utilities/align.hpp" 100 #include "utilities/checkedCast.hpp" 101 #include "utilities/debug.hpp" 102 #include "utilities/elfFile.hpp" 103 #include "utilities/exceptions.hpp" 104 #include "utilities/macros.hpp" 105 #include "utilities/nativeCallStack.hpp" 106 #include "utilities/ostream.hpp" 107 #if INCLUDE_G1GC 108 #include "gc/g1/g1Arguments.hpp" 109 #include "gc/g1/g1CollectedHeap.inline.hpp" 110 #include "gc/g1/g1ConcurrentMark.hpp" 111 #include "gc/g1/g1ConcurrentMarkThread.inline.hpp" 112 #include "gc/g1/g1HeapRegionManager.hpp" 113 #include "gc/g1/g1HeapRegionRemSet.inline.hpp" 114 #endif // INCLUDE_G1GC 115 #if INCLUDE_PARALLELGC 116 #include "gc/parallel/parallelScavengeHeap.inline.hpp" 117 #endif // INCLUDE_PARALLELGC 118 #if INCLUDE_SERIALGC 119 #include "gc/serial/serialHeap.hpp" 120 #endif // INCLUDE_SERIALGC 121 #if INCLUDE_ZGC 122 #include "gc/z/zAddress.inline.hpp" 123 #endif // INCLUDE_ZGC 124 #if INCLUDE_JVMCI 125 #include "jvmci/jvmciEnv.hpp" 126 #include "jvmci/jvmciRuntime.hpp" 127 #endif 128 #ifdef LINUX 129 #include "cgroupSubsystem_linux.hpp" 130 #include "osContainer_linux.hpp" 131 #include "os_linux.hpp" 132 #endif 133 134 #define CHECK_JNI_EXCEPTION_(env, value) \ 135 do { \ 136 JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \ 137 THREAD->clear_pending_jni_exception_check(); \ 138 if (HAS_PENDING_EXCEPTION) { \ 139 return(value); \ 140 } \ 141 } while (0) 142 143 #define CHECK_JNI_EXCEPTION(env) \ 144 do { \ 145 JavaThread* THREAD = JavaThread::thread_from_jni_environment(env); \ 146 THREAD->clear_pending_jni_exception_check(); \ 147 if (HAS_PENDING_EXCEPTION) { \ 148 return; \ 149 } \ 150 } while (0) 151 152 bool WhiteBox::_used = false; 153 volatile bool WhiteBox::compilation_locked = false; 154 155 class VM_WhiteBoxOperation : public VM_Operation { 156 public: 157 VM_WhiteBoxOperation() { } 158 VMOp_Type type() const { return VMOp_WhiteBoxOperation; } 159 bool allow_nested_vm_operations() const { return true; } 160 }; 161 162 163 WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) 164 return (jlong)(void*)JNIHandles::resolve(obj); 165 WB_END 166 167 WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) 168 return heapOopSize; 169 WB_END 170 171 WB_ENTRY(jint, WB_GetVMPageSize(JNIEnv* env, jobject o)) 172 return (jint)os::vm_page_size(); 173 WB_END 174 175 WB_ENTRY(jlong, WB_GetVMAllocationGranularity(JNIEnv* env, jobject o)) 176 return os::vm_allocation_granularity(); 177 WB_END 178 179 WB_ENTRY(jlong, WB_GetVMLargePageSize(JNIEnv* env, jobject o)) 180 return os::large_page_size(); 181 WB_END 182 183 class WBIsKlassAliveClosure : public LockedClassesDo { 184 Symbol* _name; 185 int _count; 186 public: 187 WBIsKlassAliveClosure(Symbol* name) : _name(name), _count(0) {} 188 189 void do_klass(Klass* k) { 190 Symbol* ksym = k->name(); 191 if (ksym->fast_compare(_name) == 0) { 192 _count++; 193 } else if (k->is_instance_klass()) { 194 // Need special handling for hidden classes because the JVM 195 // appends "+<hex-address>" to hidden class names. 196 InstanceKlass *ik = InstanceKlass::cast(k); 197 if (ik->is_hidden()) { 198 ResourceMark rm; 199 char* k_name = ksym->as_C_string(); 200 // Find the first '+' char and truncate the string at that point. 201 // NOTE: This will not work correctly if the original hidden class 202 // name contains a '+'. 203 char* plus_char = strchr(k_name, '+'); 204 if (plus_char != nullptr) { 205 *plus_char = 0; 206 char* c_name = _name->as_C_string(); 207 if (strcmp(c_name, k_name) == 0) { 208 _count++; 209 } 210 } 211 } 212 } 213 } 214 215 int count() const { 216 return _count; 217 } 218 }; 219 220 WB_ENTRY(jint, WB_CountAliveClasses(JNIEnv* env, jobject target, jstring name)) 221 oop h_name = JNIHandles::resolve(name); 222 if (h_name == nullptr) { 223 return 0; 224 } 225 Symbol* sym = java_lang_String::as_symbol(h_name); 226 TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return 227 228 WBIsKlassAliveClosure closure(sym); 229 ClassLoaderDataGraph::classes_do(&closure); 230 231 // Return the count of alive classes with this name. 232 return closure.count(); 233 WB_END 234 235 WB_ENTRY(jint, WB_GetSymbolRefcount(JNIEnv* env, jobject unused, jstring name)) 236 oop h_name = JNIHandles::resolve(name); 237 if (h_name == nullptr) { 238 return 0; 239 } 240 Symbol* sym = java_lang_String::as_symbol(h_name); 241 TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return 242 return (jint)sym->refcount(); 243 WB_END 244 245 246 WB_ENTRY(void, WB_AddToBootstrapClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) { 247 #if INCLUDE_JVMTI 248 ResourceMark rm; 249 const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment)); 250 JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION); 251 jvmtiError err = jvmti_env->AddToBootstrapClassLoaderSearch(seg); 252 assert(err == JVMTI_ERROR_NONE, "must not fail"); 253 #endif 254 } 255 WB_END 256 257 WB_ENTRY(void, WB_AddToSystemClassLoaderSearch(JNIEnv* env, jobject o, jstring segment)) { 258 #if INCLUDE_JVMTI 259 ResourceMark rm; 260 const char* seg = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(segment)); 261 JvmtiEnv* jvmti_env = JvmtiEnv::create_a_jvmti(JVMTI_VERSION); 262 jvmtiError err = jvmti_env->AddToSystemClassLoaderSearch(seg); 263 assert(err == JVMTI_ERROR_NONE, "must not fail"); 264 #endif 265 } 266 WB_END 267 268 269 WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { 270 return (jlong)Arguments::max_heap_for_compressed_oops(); 271 } 272 WB_END 273 274 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { 275 tty->print_cr("Minimum heap " SIZE_FORMAT " Initial heap " SIZE_FORMAT " " 276 "Maximum heap " SIZE_FORMAT " Space alignment " SIZE_FORMAT " Heap alignment " SIZE_FORMAT, 277 MinHeapSize, 278 InitialHeapSize, 279 MaxHeapSize, 280 SpaceAlignment, 281 HeapAlignment); 282 } 283 WB_END 284 285 WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o)) 286 size_t granularity = os::vm_allocation_granularity(); 287 ReservedHeapSpace rhs(100 * granularity, granularity, os::vm_page_size()); 288 VirtualSpace vs; 289 vs.initialize(rhs, 50 * granularity); 290 291 // Check if constraints are complied 292 if (!( UseCompressedOops && rhs.base() != nullptr && 293 CompressedOops::base() != nullptr && 294 CompressedOops::use_implicit_null_checks() )) { 295 tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n " 296 "\tUseCompressedOops is %d\n" 297 "\trhs.base() is " PTR_FORMAT "\n" 298 "\tCompressedOops::base() is " PTR_FORMAT "\n" 299 "\tCompressedOops::use_implicit_null_checks() is %d", 300 UseCompressedOops, 301 p2i(rhs.base()), 302 p2i(CompressedOops::base()), 303 CompressedOops::use_implicit_null_checks()); 304 return; 305 } 306 tty->print_cr("Reading from no access area... "); 307 tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c", 308 *(vs.low_boundary() - rhs.noaccess_prefix() / 2 )); 309 WB_END 310 311 static jint wb_stress_virtual_space_resize(size_t reserved_space_size, 312 size_t magnitude, size_t iterations) { 313 size_t granularity = os::vm_allocation_granularity(); 314 ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, os::vm_page_size()); 315 VirtualSpace vs; 316 if (!vs.initialize(rhs, 0)) { 317 tty->print_cr("Failed to initialize VirtualSpace. Can't proceed."); 318 return 3; 319 } 320 321 int seed = os::random(); 322 tty->print_cr("Random seed is %d", seed); 323 324 for (size_t i = 0; i < iterations; i++) { 325 326 // Whether we will shrink or grow 327 bool shrink = os::random() % 2L == 0; 328 329 // Get random delta to resize virtual space 330 size_t delta = (size_t)os::random() % magnitude; 331 332 // If we are about to shrink virtual space below zero, then expand instead 333 if (shrink && vs.committed_size() < delta) { 334 shrink = false; 335 } 336 337 // Resizing by delta 338 if (shrink) { 339 vs.shrink_by(delta); 340 } else { 341 // If expanding fails expand_by will silently return false 342 vs.expand_by(delta, true); 343 } 344 } 345 return 0; 346 } 347 348 WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o, 349 jlong reserved_space_size, jlong magnitude, jlong iterations)) 350 tty->print_cr("reservedSpaceSize=" JLONG_FORMAT ", magnitude=" JLONG_FORMAT ", " 351 "iterations=" JLONG_FORMAT "\n", reserved_space_size, magnitude, 352 iterations); 353 if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) { 354 tty->print_cr("One of variables printed above is negative. Can't proceed.\n"); 355 return 1; 356 } 357 358 // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is 359 // always 8 byte. That's why we should avoid overflow in case of 32bit platform. 360 if (sizeof(size_t) < sizeof(jlong)) { 361 jlong size_t_max_value = (jlong)SIZE_MAX; 362 if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value 363 || iterations > size_t_max_value) { 364 tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n"); 365 return 2; 366 } 367 } 368 369 return wb_stress_virtual_space_resize((size_t) reserved_space_size, 370 (size_t) magnitude, (size_t) iterations); 371 WB_END 372 373 WB_ENTRY(jboolean, WB_IsGCSupported(JNIEnv* env, jobject o, jint name)) 374 return GCConfig::is_gc_supported((CollectedHeap::Name)name); 375 WB_END 376 377 WB_ENTRY(jboolean, WB_HasLibgraal(JNIEnv* env, jobject o)) 378 #if INCLUDE_JVMCI 379 return JVMCI::shared_library_exists(); 380 #endif 381 return false; 382 WB_END 383 384 WB_ENTRY(jboolean, WB_IsGCSupportedByJVMCICompiler(JNIEnv* env, jobject o, jint name)) 385 #if INCLUDE_JVMCI 386 if (EnableJVMCI) { 387 // Enter the JVMCI env that will be used by the CompileBroker. 388 JVMCIEnv jvmciEnv(thread, __FILE__, __LINE__); 389 return jvmciEnv.init_error() == JNI_OK && jvmciEnv.runtime()->is_gc_supported(&jvmciEnv, (CollectedHeap::Name)name); 390 } 391 #endif 392 return false; 393 WB_END 394 395 WB_ENTRY(jboolean, WB_IsGCSelected(JNIEnv* env, jobject o, jint name)) 396 return GCConfig::is_gc_selected((CollectedHeap::Name)name); 397 WB_END 398 399 WB_ENTRY(jboolean, WB_IsGCSelectedErgonomically(JNIEnv* env, jobject o)) 400 return GCConfig::is_gc_selected_ergonomically(); 401 WB_END 402 403 WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj)) 404 oop p = JNIHandles::resolve(obj); 405 #if INCLUDE_G1GC 406 if (UseG1GC) { 407 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 408 const HeapRegion* hr = g1h->heap_region_containing(p); 409 return hr->is_old_or_humongous(); 410 } 411 #endif 412 #if INCLUDE_PARALLELGC 413 if (UseParallelGC) { 414 ParallelScavengeHeap* psh = ParallelScavengeHeap::heap(); 415 return !psh->is_in_young(p); 416 } 417 #endif 418 #if INCLUDE_ZGC 419 if (UseZGC) { 420 if (ZGenerational) { 421 return ZHeap::heap()->is_old(to_zaddress(p)); 422 } else { 423 return Universe::heap()->is_in(p); 424 } 425 } 426 #endif 427 #if INCLUDE_SHENANDOAHGC 428 if (UseShenandoahGC) { 429 return Universe::heap()->is_in(p); 430 } 431 #endif 432 #if INCLUDE_SERIALGC 433 if (UseSerialGC) { 434 return !SerialHeap::heap()->is_in_young(p); 435 } 436 #endif 437 ShouldNotReachHere(); 438 return false; 439 WB_END 440 441 WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj)) 442 oop p = JNIHandles::resolve(obj); 443 return p->size() * HeapWordSize; 444 WB_END 445 446 WB_ENTRY(jlong, WB_GetHeapSpaceAlignment(JNIEnv* env, jobject o)) 447 return (jlong)SpaceAlignment; 448 WB_END 449 450 WB_ENTRY(jlong, WB_GetHeapAlignment(JNIEnv* env, jobject o)) 451 return (jlong)HeapAlignment; 452 WB_END 453 454 WB_ENTRY(jboolean, WB_SupportsConcurrentGCBreakpoints(JNIEnv* env, jobject o)) 455 return Universe::heap()->supports_concurrent_gc_breakpoints(); 456 WB_END 457 458 WB_ENTRY(void, WB_ConcurrentGCAcquireControl(JNIEnv* env, jobject o)) 459 ConcurrentGCBreakpoints::acquire_control(); 460 WB_END 461 462 WB_ENTRY(void, WB_ConcurrentGCReleaseControl(JNIEnv* env, jobject o)) 463 ConcurrentGCBreakpoints::release_control(); 464 WB_END 465 466 WB_ENTRY(void, WB_ConcurrentGCRunToIdle(JNIEnv* env, jobject o)) 467 ConcurrentGCBreakpoints::run_to_idle(); 468 WB_END 469 470 WB_ENTRY(jboolean, WB_ConcurrentGCRunTo(JNIEnv* env, jobject o, jobject at)) 471 Handle h_name(THREAD, JNIHandles::resolve(at)); 472 ResourceMark rm; 473 const char* c_name = java_lang_String::as_utf8_string(h_name()); 474 return ConcurrentGCBreakpoints::run_to(c_name); 475 WB_END 476 477 #if INCLUDE_G1GC 478 479 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) 480 if (UseG1GC) { 481 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 482 oop result = JNIHandles::resolve(obj); 483 const HeapRegion* hr = g1h->heap_region_containing(result); 484 return hr->is_humongous(); 485 } 486 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1IsHumongous: G1 GC is not enabled"); 487 WB_END 488 489 WB_ENTRY(jboolean, WB_G1BelongsToHumongousRegion(JNIEnv* env, jobject o, jlong addr)) 490 if (UseG1GC) { 491 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 492 const HeapRegion* hr = g1h->heap_region_containing((void*) addr); 493 return hr->is_humongous(); 494 } 495 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToHumongousRegion: G1 GC is not enabled"); 496 WB_END 497 498 WB_ENTRY(jboolean, WB_G1BelongsToFreeRegion(JNIEnv* env, jobject o, jlong addr)) 499 if (UseG1GC) { 500 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 501 const HeapRegion* hr = g1h->heap_region_containing((void*) addr); 502 return hr->is_free(); 503 } 504 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1BelongsToFreeRegion: G1 GC is not enabled"); 505 WB_END 506 507 WB_ENTRY(jlong, WB_G1NumMaxRegions(JNIEnv* env, jobject o)) 508 if (UseG1GC) { 509 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 510 size_t nr = g1h->max_regions(); 511 return (jlong)nr; 512 } 513 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumMaxRegions: G1 GC is not enabled"); 514 WB_END 515 516 WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) 517 if (UseG1GC) { 518 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 519 size_t nr = g1h->num_free_regions(); 520 return (jlong)nr; 521 } 522 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1NumFreeRegions: G1 GC is not enabled"); 523 WB_END 524 525 WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) 526 if (UseG1GC) { 527 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 528 return g1h->concurrent_mark()->cm_thread()->in_progress(); 529 } 530 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1InConcurrentMark: G1 GC is not enabled"); 531 WB_END 532 533 WB_ENTRY(jint, WB_G1CompletedConcurrentMarkCycles(JNIEnv* env, jobject o)) 534 if (UseG1GC) { 535 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 536 G1ConcurrentMark* cm = g1h->concurrent_mark(); 537 return cm->completed_mark_cycles(); 538 } 539 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1CompletedConcurrentMarkCycles: G1 GC is not enabled"); 540 WB_END 541 542 WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) 543 if (UseG1GC) { 544 return (jint)HeapRegion::GrainBytes; 545 } 546 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1RegionSize: G1 GC is not enabled"); 547 WB_END 548 549 WB_ENTRY(jboolean, WB_G1HasRegionsToUncommit(JNIEnv* env, jobject o)) 550 if (UseG1GC) { 551 return G1CollectedHeap::heap()->has_uncommittable_regions(); 552 } 553 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1HasRegionsToUncommit: G1 GC is not enabled"); 554 WB_END 555 556 #endif // INCLUDE_G1GC 557 558 #if INCLUDE_PARALLELGC 559 560 WB_ENTRY(jlong, WB_PSVirtualSpaceAlignment(JNIEnv* env, jobject o)) 561 if (UseParallelGC) { 562 return GenAlignment; 563 } 564 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSVirtualSpaceAlignment: Parallel GC is not enabled"); 565 WB_END 566 567 WB_ENTRY(jlong, WB_PSHeapGenerationAlignment(JNIEnv* env, jobject o)) 568 if (UseParallelGC) { 569 return GenAlignment; 570 } 571 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_PSHeapGenerationAlignment: Parallel GC is not enabled"); 572 WB_END 573 574 #endif // INCLUDE_PARALLELGC 575 576 #if INCLUDE_G1GC 577 578 WB_ENTRY(jobject, WB_G1AuxiliaryMemoryUsage(JNIEnv* env)) 579 if (UseG1GC) { 580 ResourceMark rm(THREAD); 581 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 582 MemoryUsage usage = g1h->get_auxiliary_data_memory_usage(); 583 Handle h = MemoryService::create_MemoryUsage_obj(usage, CHECK_NULL); 584 return JNIHandles::make_local(THREAD, h()); 585 } 586 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1AuxiliaryMemoryUsage: G1 GC is not enabled"); 587 WB_END 588 589 WB_ENTRY(jint, WB_G1ActiveMemoryNodeCount(JNIEnv* env, jobject o)) 590 if (UseG1GC) { 591 G1NUMA* numa = G1NUMA::numa(); 592 return (jint)numa->num_active_nodes(); 593 } 594 THROW_MSG_0(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1ActiveMemoryNodeCount: G1 GC is not enabled"); 595 WB_END 596 597 WB_ENTRY(jintArray, WB_G1MemoryNodeIds(JNIEnv* env, jobject o)) 598 if (UseG1GC) { 599 G1NUMA* numa = G1NUMA::numa(); 600 int num_node_ids = checked_cast<int>(numa->num_active_nodes()); 601 const uint* node_ids = numa->node_ids(); 602 603 typeArrayOop result = oopFactory::new_intArray(num_node_ids, CHECK_NULL); 604 for (int i = 0; i < num_node_ids; i++) { 605 result->int_at_put(i, checked_cast<jint>(node_ids[i])); 606 } 607 return (jintArray) JNIHandles::make_local(THREAD, result); 608 } 609 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1MemoryNodeIds: G1 GC is not enabled"); 610 WB_END 611 612 class OldRegionsLivenessClosure: public HeapRegionClosure { 613 614 private: 615 const int _liveness; 616 size_t _total_count; 617 size_t _total_memory; 618 size_t _total_memory_to_free; 619 620 public: 621 OldRegionsLivenessClosure(int liveness) : 622 _liveness(liveness), 623 _total_count(0), 624 _total_memory(0), 625 _total_memory_to_free(0) { } 626 627 size_t total_count() { return _total_count; } 628 size_t total_memory() { return _total_memory; } 629 size_t total_memory_to_free() { return _total_memory_to_free; } 630 631 bool do_heap_region(HeapRegion* r) { 632 if (r->is_old()) { 633 size_t live = r->live_bytes(); 634 size_t size = r->used(); 635 size_t reg_size = HeapRegion::GrainBytes; 636 if (size > 0 && ((int)(live * 100 / size) < _liveness)) { 637 _total_memory += size; 638 ++_total_count; 639 if (size == reg_size) { 640 // We don't include non-full regions since they are unlikely included in mixed gc 641 // for testing purposes it's enough to have lowest estimation of total memory that is expected to be freed 642 _total_memory_to_free += size - live; 643 } 644 } 645 } 646 return false; 647 } 648 }; 649 650 651 WB_ENTRY(jlongArray, WB_G1GetMixedGCInfo(JNIEnv* env, jobject o, jint liveness)) 652 if (!UseG1GC) { 653 THROW_MSG_NULL(vmSymbols::java_lang_UnsupportedOperationException(), "WB_G1GetMixedGCInfo: G1 GC is not enabled"); 654 } 655 if (liveness < 0) { 656 THROW_MSG_NULL(vmSymbols::java_lang_IllegalArgumentException(), "liveness value should be non-negative"); 657 } 658 659 G1CollectedHeap* g1h = G1CollectedHeap::heap(); 660 OldRegionsLivenessClosure rli(liveness); 661 g1h->heap_region_iterate(&rli); 662 663 typeArrayOop result = oopFactory::new_longArray(3, CHECK_NULL); 664 result->long_at_put(0, rli.total_count()); 665 result->long_at_put(1, rli.total_memory()); 666 result->long_at_put(2, rli.total_memory_to_free()); 667 return (jlongArray) JNIHandles::make_local(THREAD, result); 668 WB_END 669 670 #endif // INCLUDE_G1GC 671 672 // Alloc memory using the test memory type so that we can use that to see if 673 // NMT picks it up correctly 674 WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size)) 675 jlong addr = 0; 676 addr = (jlong)(uintptr_t)os::malloc(size, mtTest); 677 return addr; 678 WB_END 679 680 // Alloc memory with pseudo call stack. The test can create pseudo malloc 681 // allocation site to stress the malloc tracking. 682 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack)) 683 address pc = (address)(size_t)pseudo_stack; 684 NativeCallStack stack(&pc, 1); 685 return (jlong)(uintptr_t)os::malloc(size, mtTest, stack); 686 WB_END 687 688 // Alloc memory with pseudo call stack and specific memory type. 689 WB_ENTRY(jlong, WB_NMTMallocWithPseudoStackAndType(JNIEnv* env, jobject o, jlong size, jint pseudo_stack, jint type)) 690 address pc = (address)(size_t)pseudo_stack; 691 NativeCallStack stack(&pc, 1); 692 return (jlong)(uintptr_t)os::malloc(size, (MEMFLAGS)type, stack); 693 WB_END 694 695 // Free the memory allocated by NMTAllocTest 696 WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) 697 os::free((void*)(uintptr_t)mem); 698 WB_END 699 700 WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) 701 jlong addr = 0; 702 703 addr = (jlong)(uintptr_t)os::reserve_memory(size); 704 MemTracker::record_virtual_memory_type((address)addr, mtTest); 705 706 return addr; 707 WB_END 708 709 WB_ENTRY(jlong, WB_NMTAttemptReserveMemoryAt(JNIEnv* env, jobject o, jlong addr, jlong size)) 710 addr = (jlong)(uintptr_t)os::attempt_reserve_memory_at((char*)(uintptr_t)addr, (size_t)size); 711 MemTracker::record_virtual_memory_type((address)addr, mtTest); 712 713 return addr; 714 WB_END 715 716 WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 717 os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem); 718 MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest); 719 WB_END 720 721 WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 722 os::uncommit_memory((char *)(uintptr_t)addr, size); 723 WB_END 724 725 WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) 726 os::release_memory((char *)(uintptr_t)addr, size); 727 WB_END 728 729 WB_ENTRY(jint, WB_NMTGetHashSize(JNIEnv* env, jobject o)) 730 int hash_size = MallocSiteTable::hash_buckets(); 731 assert(hash_size > 0, "NMT hash_size should be > 0"); 732 return (jint)hash_size; 733 WB_END 734 735 WB_ENTRY(jlong, WB_NMTNewArena(JNIEnv* env, jobject o, jlong init_size)) 736 Arena* arena = new (mtTest) Arena(mtTest, Arena::Tag::tag_other, size_t(init_size)); 737 return (jlong)arena; 738 WB_END 739 740 WB_ENTRY(void, WB_NMTFreeArena(JNIEnv* env, jobject o, jlong arena)) 741 Arena* a = (Arena*)arena; 742 delete a; 743 WB_END 744 745 WB_ENTRY(void, WB_NMTArenaMalloc(JNIEnv* env, jobject o, jlong arena, jlong size)) 746 Arena* a = (Arena*)arena; 747 a->Amalloc(size_t(size)); 748 WB_END 749 750 static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { 751 assert(method != nullptr, "method should not be null"); 752 ThreadToNativeFromVM ttn(thread); 753 return env->FromReflectedMethod(method); 754 } 755 756 // Deoptimizes all compiled frames and makes nmethods not entrant if it's requested 757 class VM_WhiteBoxDeoptimizeFrames : public VM_WhiteBoxOperation { 758 private: 759 int _result; 760 const bool _make_not_entrant; 761 public: 762 VM_WhiteBoxDeoptimizeFrames(bool make_not_entrant) : 763 _result(0), _make_not_entrant(make_not_entrant) { } 764 int result() const { return _result; } 765 766 void doit() { 767 for (JavaThreadIteratorWithHandle jtiwh; JavaThread *t = jtiwh.next(); ) { 768 if (t->has_last_Java_frame()) { 769 for (StackFrameStream fst(t, false /* update */, true /* process_frames */); !fst.is_done(); fst.next()) { 770 frame* f = fst.current(); 771 if (f->can_be_deoptimized() && !f->is_deoptimized_frame()) { 772 Deoptimization::deoptimize(t, *f); 773 if (_make_not_entrant) { 774 CompiledMethod* cm = CodeCache::find_compiled(f->pc()); 775 assert(cm != nullptr, "sanity check"); 776 cm->make_not_entrant(); 777 } 778 ++_result; 779 } 780 } 781 } 782 } 783 } 784 }; 785 786 WB_ENTRY(jint, WB_DeoptimizeFrames(JNIEnv* env, jobject o, jboolean make_not_entrant)) 787 VM_WhiteBoxDeoptimizeFrames op(make_not_entrant == JNI_TRUE); 788 VMThread::execute(&op); 789 return op.result(); 790 WB_END 791 792 WB_ENTRY(jboolean, WB_IsFrameDeoptimized(JNIEnv* env, jobject o, jint depth)) 793 bool result = false; 794 if (thread->has_last_Java_frame()) { 795 RegisterMap reg_map(thread, 796 RegisterMap::UpdateMap::include, 797 RegisterMap::ProcessFrames::include, 798 RegisterMap::WalkContinuation::skip); 799 javaVFrame *jvf = thread->last_java_vframe(®_map); 800 for (jint d = 0; d < depth && jvf != nullptr; d++) { 801 jvf = jvf->java_sender(); 802 } 803 result = jvf != nullptr && jvf->fr().is_deoptimized_frame(); 804 } 805 return result; 806 WB_END 807 808 WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) 809 DeoptimizationScope deopt_scope; 810 CodeCache::mark_all_nmethods_for_deoptimization(&deopt_scope); 811 deopt_scope.deoptimize_marked(); 812 WB_END 813 814 WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 815 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 816 int result = 0; 817 CHECK_JNI_EXCEPTION_(env, result); 818 819 DeoptimizationScope deopt_scope; 820 { 821 MutexLocker mu(Compile_lock); 822 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 823 if (is_osr) { 824 result += mh->method_holder()->mark_osr_nmethods(&deopt_scope, mh()); 825 } else { 826 MutexLocker ml(CompiledMethod_lock, Mutex::_no_safepoint_check_flag); 827 if (mh->code() != nullptr) { 828 deopt_scope.mark(mh->code()); 829 ++result; 830 } 831 } 832 CodeCache::mark_for_deoptimization(&deopt_scope, mh()); 833 } 834 835 deopt_scope.deoptimize_marked(); 836 837 return result; 838 WB_END 839 840 WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 841 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 842 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 843 MutexLocker mu(Compile_lock); 844 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 845 CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 846 if (code == nullptr) { 847 return JNI_FALSE; 848 } 849 return !code->is_marked_for_deoptimization(); 850 WB_END 851 852 static bool is_excluded_for_compiler(AbstractCompiler* comp, methodHandle& mh) { 853 if (comp == nullptr) { 854 return true; 855 } 856 DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, comp); 857 bool exclude = directive->ExcludeOption; 858 DirectivesStack::release(directive); 859 return exclude; 860 } 861 862 static bool can_be_compiled_at_level(methodHandle& mh, jboolean is_osr, int level) { 863 if (is_osr) { 864 return CompilationPolicy::can_be_osr_compiled(mh, level); 865 } else { 866 return CompilationPolicy::can_be_compiled(mh, level); 867 } 868 } 869 870 WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) 871 if (method == nullptr || comp_level > CompilationPolicy::highest_compile_level()) { 872 return false; 873 } 874 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 875 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 876 MutexLocker mu(Compile_lock); 877 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 878 879 // The ExcludeOption directive is evaluated lazily upon compilation attempt. If a method was not tried to be compiled by 880 // a compiler, yet, the method object is not set to be not compilable by that compiler. Thus, evaluate the compiler directive 881 // to exclude a compilation of 'method'. 882 if (comp_level == CompLevel_any) { 883 // Both compilers could have ExcludeOption set. Check all combinations. 884 bool excluded_c1 = is_excluded_for_compiler(CompileBroker::compiler1(), mh); 885 bool excluded_c2 = is_excluded_for_compiler(CompileBroker::compiler2(), mh); 886 if (excluded_c1 && excluded_c2) { 887 // Compilation of 'method' excluded by both compilers. 888 return false; 889 } 890 891 if (excluded_c1) { 892 // C1 only has ExcludeOption set: Check if compilable with C2. 893 return can_be_compiled_at_level(mh, is_osr, CompLevel_full_optimization); 894 } else if (excluded_c2) { 895 // C2 only has ExcludeOption set: Check if compilable with C1. 896 return can_be_compiled_at_level(mh, is_osr, CompLevel_simple); 897 } 898 } else if (comp_level > CompLevel_none && is_excluded_for_compiler(CompileBroker::compiler((int)comp_level), mh)) { 899 // Compilation of 'method' excluded by compiler used for 'comp_level'. 900 return false; 901 } 902 903 return can_be_compiled_at_level(mh, is_osr, (int)comp_level); 904 WB_END 905 906 WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) 907 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 908 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 909 MutexLocker mu(Compile_lock); 910 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 911 return mh->queued_for_compilation(); 912 WB_END 913 914 WB_ENTRY(jboolean, WB_IsIntrinsicAvailable(JNIEnv* env, jobject o, jobject method, jobject compilation_context, jint compLevel)) 915 if (compLevel < CompLevel_none || compLevel > CompilationPolicy::highest_compile_level()) { 916 return false; // Intrinsic is not available on a non-existent compilation level. 917 } 918 jmethodID method_id, compilation_context_id; 919 method_id = reflected_method_to_jmid(thread, env, method); 920 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 921 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(method_id)); 922 923 DirectiveSet* directive; 924 AbstractCompiler* comp = CompileBroker::compiler((int)compLevel); 925 assert(comp != nullptr, "compiler not available"); 926 if (compilation_context != nullptr) { 927 compilation_context_id = reflected_method_to_jmid(thread, env, compilation_context); 928 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 929 methodHandle cch(THREAD, Method::checked_resolve_jmethod_id(compilation_context_id)); 930 directive = DirectivesStack::getMatchingDirective(cch, comp); 931 } else { 932 // Calling with null matches default directive 933 directive = DirectivesStack::getDefaultDirective(comp); 934 } 935 bool result = comp->is_intrinsic_available(mh, directive); 936 DirectivesStack::release(directive); 937 return result; 938 WB_END 939 940 WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 941 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 942 CHECK_JNI_EXCEPTION_(env, CompLevel_none); 943 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 944 CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 945 return (code != nullptr ? code->comp_level() : CompLevel_none); 946 WB_END 947 948 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) 949 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 950 CHECK_JNI_EXCEPTION(env); 951 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 952 if (is_osr) { 953 mh->set_not_osr_compilable("WhiteBox", comp_level); 954 } else { 955 mh->set_not_compilable("WhiteBox", comp_level); 956 } 957 WB_END 958 959 WB_ENTRY(jint, WB_GetMethodDecompileCount(JNIEnv* env, jobject o, jobject method)) 960 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 961 CHECK_JNI_EXCEPTION_(env, 0); 962 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 963 uint cnt = 0; 964 MethodData* mdo = mh->method_data(); 965 if (mdo != nullptr) { 966 cnt = mdo->decompile_count(); 967 } 968 return cnt; 969 WB_END 970 971 // Get the trap count of a method for a specific reason. If the trap count for 972 // that reason did overflow, this includes the overflow trap count of the method. 973 // If 'reason' is null, the sum of the traps for all reasons will be returned. 974 // This number includes the overflow trap count if the trap count for any reason 975 // did overflow. 976 WB_ENTRY(jint, WB_GetMethodTrapCount(JNIEnv* env, jobject o, jobject method, jstring reason_obj)) 977 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 978 CHECK_JNI_EXCEPTION_(env, 0); 979 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 980 uint cnt = 0; 981 MethodData* mdo = mh->method_data(); 982 if (mdo != nullptr) { 983 ResourceMark rm(THREAD); 984 char* reason_str = (reason_obj == nullptr) ? 985 nullptr : java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(reason_obj)); 986 bool overflow = false; 987 for (uint reason = 0; reason < mdo->trap_reason_limit(); reason++) { 988 if (reason_str != nullptr && !strcmp(reason_str, Deoptimization::trap_reason_name(reason))) { 989 cnt = mdo->trap_count(reason); 990 // Count in the overflow trap count on overflow 991 if (cnt == (uint)-1) { 992 cnt = mdo->trap_count_limit() + mdo->overflow_trap_count(); 993 } 994 break; 995 } else if (reason_str == nullptr) { 996 uint c = mdo->trap_count(reason); 997 if (c == (uint)-1) { 998 c = mdo->trap_count_limit(); 999 if (!overflow) { 1000 // Count overflow trap count just once 1001 overflow = true; 1002 c += mdo->overflow_trap_count(); 1003 } 1004 } 1005 cnt += c; 1006 } 1007 } 1008 } 1009 return cnt; 1010 WB_END 1011 1012 WB_ENTRY(jint, WB_GetDeoptCount(JNIEnv* env, jobject o, jstring reason_obj, jstring action_obj)) 1013 if (reason_obj == nullptr && action_obj == nullptr) { 1014 return Deoptimization::total_deoptimization_count(); 1015 } 1016 ResourceMark rm(THREAD); 1017 const char *reason_str = (reason_obj == nullptr) ? 1018 nullptr : java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(reason_obj)); 1019 const char *action_str = (action_obj == nullptr) ? 1020 nullptr : java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(action_obj)); 1021 1022 return Deoptimization::deoptimization_count(reason_str, action_str); 1023 WB_END 1024 1025 WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method)) 1026 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1027 CHECK_JNI_EXCEPTION_(env, InvocationEntryBci); 1028 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1029 CompiledMethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false); 1030 return (code != nullptr && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci); 1031 WB_END 1032 1033 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) 1034 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1035 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1036 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1037 bool result = mh->dont_inline(); 1038 mh->set_dont_inline(value == JNI_TRUE); 1039 return result; 1040 WB_END 1041 1042 WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level)) 1043 if (comp_level == CompLevel_any) { 1044 return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + 1045 CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; 1046 } else { 1047 return CompileBroker::queue_size(comp_level); 1048 } 1049 WB_END 1050 1051 WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) 1052 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1053 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1054 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1055 bool result = mh->force_inline(); 1056 mh->set_force_inline(value == JNI_TRUE); 1057 return result; 1058 WB_END 1059 1060 #ifdef LINUX 1061 bool WhiteBox::validate_cgroup(const char* proc_cgroups, 1062 const char* proc_self_cgroup, 1063 const char* proc_self_mountinfo, 1064 u1* cg_flags) { 1065 CgroupInfo cg_infos[CG_INFO_LENGTH]; 1066 return CgroupSubsystemFactory::determine_type(cg_infos, proc_cgroups, 1067 proc_self_cgroup, 1068 proc_self_mountinfo, cg_flags); 1069 } 1070 #endif 1071 1072 bool WhiteBox::compile_method(Method* method, int comp_level, int bci, JavaThread* THREAD) { 1073 // Screen for unavailable/bad comp level or null method 1074 AbstractCompiler* comp = CompileBroker::compiler(comp_level); 1075 if (method == nullptr) { 1076 tty->print_cr("WB error: request to compile null method"); 1077 return false; 1078 } 1079 if (comp_level > CompilationPolicy::highest_compile_level()) { 1080 tty->print_cr("WB error: invalid compilation level %d", comp_level); 1081 return false; 1082 } 1083 if (comp == nullptr) { 1084 tty->print_cr("WB error: no compiler for requested compilation level %d", comp_level); 1085 return false; 1086 } 1087 1088 // Check if compilation is blocking 1089 methodHandle mh(THREAD, method); 1090 DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, comp); 1091 bool is_blocking = !directive->BackgroundCompilationOption; 1092 DirectivesStack::release(directive); 1093 1094 // Compile method and check result 1095 nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), CompileTask::Reason_Whitebox, CHECK_false); 1096 MutexLocker mu(THREAD, Compile_lock); 1097 bool is_queued = mh->queued_for_compilation(); 1098 if ((!is_blocking && is_queued) || nm != nullptr) { 1099 return true; 1100 } 1101 // Check code again because compilation may be finished before Compile_lock is acquired. 1102 if (bci == InvocationEntryBci) { 1103 CompiledMethod* code = mh->code(); 1104 if (code != nullptr && code->as_nmethod_or_null() != nullptr) { 1105 return true; 1106 } 1107 } else if (mh->lookup_osr_nmethod_for(bci, comp_level, false) != nullptr) { 1108 return true; 1109 } 1110 tty->print("WB error: failed to %s compile at level %d method ", is_blocking ? "blocking" : "", comp_level); 1111 mh->print_short_name(tty); 1112 tty->cr(); 1113 if (is_blocking && is_queued) { 1114 tty->print_cr("WB error: blocking compilation is still in queue!"); 1115 } 1116 return false; 1117 } 1118 1119 WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) 1120 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1121 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1122 return WhiteBox::compile_method(Method::checked_resolve_jmethod_id(jmid), comp_level, bci, THREAD); 1123 WB_END 1124 1125 WB_ENTRY(jboolean, WB_EnqueueInitializerForCompilation(JNIEnv* env, jobject o, jclass klass, jint comp_level)) 1126 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1127 Method* clinit = ik->class_initializer(); 1128 if (clinit == nullptr || clinit->method_holder()->is_not_initialized()) { 1129 return false; 1130 } 1131 return WhiteBox::compile_method(clinit, comp_level, InvocationEntryBci, THREAD); 1132 WB_END 1133 1134 WB_ENTRY(jboolean, WB_ShouldPrintAssembly(JNIEnv* env, jobject o, jobject method, jint comp_level)) 1135 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1136 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1137 1138 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1139 DirectiveSet* directive = DirectivesStack::getMatchingDirective(mh, CompileBroker::compiler(comp_level)); 1140 bool result = directive->PrintAssemblyOption; 1141 DirectivesStack::release(directive); 1142 1143 return result; 1144 WB_END 1145 1146 WB_ENTRY(jint, WB_MatchesInline(JNIEnv* env, jobject o, jobject method, jstring pattern)) 1147 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1148 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1149 1150 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1151 1152 ResourceMark rm(THREAD); 1153 const char* error_msg = nullptr; 1154 char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern)); 1155 InlineMatcher* m = InlineMatcher::parse_inline_pattern(method_str, error_msg); 1156 1157 if (m == nullptr) { 1158 assert(error_msg != nullptr, "Always have an error message"); 1159 tty->print_cr("Got error: %s", error_msg); 1160 return -1; // Pattern failed 1161 } 1162 1163 // Pattern works - now check if it matches 1164 int result; 1165 if (m->match(mh, InlineMatcher::force_inline)) { 1166 result = 2; // Force inline match 1167 } else if (m->match(mh, InlineMatcher::dont_inline)) { 1168 result = 1; // Dont inline match 1169 } else { 1170 result = 0; // No match 1171 } 1172 delete m; 1173 return result; 1174 WB_END 1175 1176 WB_ENTRY(jint, WB_MatchesMethod(JNIEnv* env, jobject o, jobject method, jstring pattern)) 1177 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1178 CHECK_JNI_EXCEPTION_(env, JNI_FALSE); 1179 1180 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1181 1182 ResourceMark rm; 1183 char* method_str = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(pattern)); 1184 1185 const char* error_msg = nullptr; 1186 1187 BasicMatcher* m = BasicMatcher::parse_method_pattern(method_str, error_msg, false); 1188 if (m == nullptr) { 1189 assert(error_msg != nullptr, "Must have error_msg"); 1190 tty->print_cr("Got error: %s", error_msg); 1191 return -1; 1192 } 1193 1194 // Pattern works - now check if it matches 1195 int result = m->matches(mh); 1196 delete m; 1197 assert(result == 0 || result == 1, "Result out of range"); 1198 return result; 1199 WB_END 1200 1201 WB_ENTRY(void, WB_MarkMethodProfiled(JNIEnv* env, jobject o, jobject method)) 1202 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1203 CHECK_JNI_EXCEPTION(env); 1204 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1205 1206 MethodData* mdo = mh->method_data(); 1207 if (mdo == nullptr) { 1208 Method::build_profiling_method_data(mh, CHECK_AND_CLEAR); 1209 mdo = mh->method_data(); 1210 } 1211 mdo->init(); 1212 InvocationCounter* icnt = mdo->invocation_counter(); 1213 InvocationCounter* bcnt = mdo->backedge_counter(); 1214 // set i-counter according to CompilationPolicy::is_method_profiled 1215 icnt->set(Tier4MinInvocationThreshold); 1216 bcnt->set(Tier4CompileThreshold); 1217 WB_END 1218 1219 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) 1220 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1221 CHECK_JNI_EXCEPTION(env); 1222 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1223 MutexLocker mu(THREAD, Compile_lock); 1224 MethodData* mdo = mh->method_data(); 1225 MethodCounters* mcs = mh->method_counters(); 1226 1227 if (mdo != nullptr) { 1228 mdo->init(); 1229 ResourceMark rm(THREAD); 1230 int arg_count = mdo->method()->size_of_parameters(); 1231 for (int i = 0; i < arg_count; i++) { 1232 mdo->set_arg_modified(i, 0); 1233 } 1234 mdo->clean_method_data(/*always_clean*/true); 1235 } 1236 1237 mh->clear_is_not_c1_compilable(); 1238 mh->clear_is_not_c2_compilable(); 1239 mh->clear_is_not_c2_osr_compilable(); 1240 NOT_PRODUCT(mh->set_compiled_invocation_count(0)); 1241 if (mcs != nullptr) { 1242 mcs->clear_counters(); 1243 } 1244 WB_END 1245 1246 template <typename T, int type_enum> 1247 static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) { 1248 if (name == nullptr) { 1249 return false; 1250 } 1251 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1252 const char* flag_name = env->GetStringUTFChars(name, nullptr); 1253 CHECK_JNI_EXCEPTION_(env, false); 1254 const JVMFlag* flag = JVMFlag::find_declared_flag(flag_name); 1255 JVMFlag::Error result = JVMFlagAccess::get<T, type_enum>(flag, value); 1256 env->ReleaseStringUTFChars(name, flag_name); 1257 return (result == JVMFlag::SUCCESS); 1258 } 1259 1260 template <typename T, int type_enum> 1261 static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value) { 1262 if (name == nullptr) { 1263 return false; 1264 } 1265 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1266 const char* flag_name = env->GetStringUTFChars(name, nullptr); 1267 CHECK_JNI_EXCEPTION_(env, false); 1268 JVMFlag* flag = JVMFlag::find_flag(flag_name); 1269 JVMFlag::Error result = JVMFlagAccess::set<T, type_enum>(flag, value, JVMFlagOrigin::INTERNAL); 1270 env->ReleaseStringUTFChars(name, flag_name); 1271 return (result == JVMFlag::SUCCESS); 1272 } 1273 1274 template <typename T> 1275 static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) { 1276 ResourceMark rm(thread); 1277 jclass clazz = env->FindClass(name->as_C_string()); 1278 CHECK_JNI_EXCEPTION_(env, nullptr); 1279 jmethodID methodID = env->GetStaticMethodID(clazz, 1280 vmSymbols::valueOf_name()->as_C_string(), 1281 sig->as_C_string()); 1282 CHECK_JNI_EXCEPTION_(env, nullptr); 1283 jobject result = env->CallStaticObjectMethod(clazz, methodID, value); 1284 CHECK_JNI_EXCEPTION_(env, nullptr); 1285 return result; 1286 } 1287 1288 static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) { 1289 return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value); 1290 } 1291 static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) { 1292 return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value); 1293 } 1294 static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) { 1295 return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value); 1296 } 1297 /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) { 1298 return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value); 1299 }*/ 1300 static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) { 1301 return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value); 1302 } 1303 1304 static const JVMFlag* getVMFlag(JavaThread* thread, JNIEnv* env, jstring name) { 1305 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1306 const char* flag_name = env->GetStringUTFChars(name, nullptr); 1307 CHECK_JNI_EXCEPTION_(env, nullptr); 1308 const JVMFlag* result = JVMFlag::find_declared_flag(flag_name); 1309 env->ReleaseStringUTFChars(name, flag_name); 1310 return result; 1311 } 1312 1313 WB_ENTRY(jboolean, WB_IsConstantVMFlag(JNIEnv* env, jobject o, jstring name)) 1314 const JVMFlag* flag = getVMFlag(thread, env, name); 1315 return (flag != nullptr) && flag->is_constant_in_binary(); 1316 WB_END 1317 1318 WB_ENTRY(jboolean, WB_IsDefaultVMFlag(JNIEnv* env, jobject o, jstring name)) 1319 const JVMFlag* flag = getVMFlag(thread, env, name); 1320 return (flag != nullptr) && flag->is_default(); 1321 WB_END 1322 1323 WB_ENTRY(jboolean, WB_IsLockedVMFlag(JNIEnv* env, jobject o, jstring name)) 1324 const JVMFlag* flag = getVMFlag(thread, env, name); 1325 return (flag != nullptr) && !(flag->is_unlocked() || flag->is_unlocker()); 1326 WB_END 1327 1328 WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name)) 1329 bool result; 1330 if (GetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result)) { 1331 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1332 return booleanBox(thread, env, result); 1333 } 1334 return nullptr; 1335 WB_END 1336 1337 template <typename T, int type_enum> 1338 jobject GetVMFlag_longBox(JNIEnv* env, JavaThread* thread, jstring name) { 1339 T result; 1340 if (GetVMFlag <T, type_enum> (thread, env, name, &result)) { 1341 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1342 return longBox(thread, env, result); 1343 } 1344 return nullptr; 1345 } 1346 1347 WB_ENTRY(jobject, WB_GetIntVMFlag(JNIEnv* env, jobject o, jstring name)) 1348 return GetVMFlag_longBox<JVM_FLAG_TYPE(int)>(env, thread, name); 1349 WB_END 1350 1351 WB_ENTRY(jobject, WB_GetUintVMFlag(JNIEnv* env, jobject o, jstring name)) 1352 return GetVMFlag_longBox<JVM_FLAG_TYPE(uint)>(env, thread, name); 1353 WB_END 1354 1355 WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name)) 1356 return GetVMFlag_longBox<JVM_FLAG_TYPE(intx)>(env, thread, name); 1357 WB_END 1358 1359 WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name)) 1360 return GetVMFlag_longBox<JVM_FLAG_TYPE(uintx)>(env, thread, name); 1361 WB_END 1362 1363 WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name)) 1364 return GetVMFlag_longBox<JVM_FLAG_TYPE(uint64_t)>(env, thread, name); 1365 WB_END 1366 1367 WB_ENTRY(jobject, WB_GetSizeTVMFlag(JNIEnv* env, jobject o, jstring name)) 1368 return GetVMFlag_longBox<JVM_FLAG_TYPE(size_t)>(env, thread, name); 1369 WB_END 1370 1371 WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name)) 1372 double result; 1373 if (GetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result)) { 1374 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1375 return doubleBox(thread, env, result); 1376 } 1377 return nullptr; 1378 WB_END 1379 1380 WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name)) 1381 ccstr ccstrResult; 1382 if (GetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, &ccstrResult)) { 1383 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1384 jstring result = env->NewStringUTF(ccstrResult); 1385 CHECK_JNI_EXCEPTION_(env, nullptr); 1386 return result; 1387 } 1388 return nullptr; 1389 WB_END 1390 1391 WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value)) 1392 bool result = value == JNI_TRUE ? true : false; 1393 SetVMFlag <JVM_FLAG_TYPE(bool)> (thread, env, name, &result); 1394 WB_END 1395 1396 WB_ENTRY(void, WB_SetIntVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1397 int result = checked_cast<int>(value); 1398 SetVMFlag <JVM_FLAG_TYPE(int)> (thread, env, name, &result); 1399 WB_END 1400 1401 WB_ENTRY(void, WB_SetUintVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1402 uint result = checked_cast<uint>(value); 1403 SetVMFlag <JVM_FLAG_TYPE(uint)> (thread, env, name, &result); 1404 WB_END 1405 1406 WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1407 intx result = value; 1408 SetVMFlag <JVM_FLAG_TYPE(intx)> (thread, env, name, &result); 1409 WB_END 1410 1411 WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1412 uintx result = value; 1413 SetVMFlag <JVM_FLAG_TYPE(uintx)> (thread, env, name, &result); 1414 WB_END 1415 1416 WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1417 uint64_t result = value; 1418 SetVMFlag <JVM_FLAG_TYPE(uint64_t)> (thread, env, name, &result); 1419 WB_END 1420 1421 WB_ENTRY(void, WB_SetSizeTVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) 1422 size_t result = value; 1423 SetVMFlag <JVM_FLAG_TYPE(size_t)> (thread, env, name, &result); 1424 WB_END 1425 1426 WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value)) 1427 double result = value; 1428 SetVMFlag <JVM_FLAG_TYPE(double)> (thread, env, name, &result); 1429 WB_END 1430 1431 WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value)) 1432 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 1433 const char* ccstrValue; 1434 if (value == nullptr) { 1435 ccstrValue = nullptr; 1436 } 1437 else { 1438 ccstrValue = env->GetStringUTFChars(value, nullptr); 1439 CHECK_JNI_EXCEPTION(env); 1440 } 1441 { 1442 ccstr param = ccstrValue; 1443 ThreadInVMfromNative ttvfn(thread); // back to VM 1444 if (SetVMFlag <JVM_FLAG_TYPE(ccstr)> (thread, env, name, ¶m)) { 1445 assert(param == nullptr, "old value is freed automatically and not returned"); 1446 } 1447 } 1448 if (value != nullptr) { 1449 env->ReleaseStringUTFChars(value, ccstrValue); 1450 } 1451 WB_END 1452 1453 WB_ENTRY(void, WB_LockCompilation(JNIEnv* env, jobject o, jlong timeout)) 1454 WhiteBox::compilation_locked = true; 1455 WB_END 1456 1457 WB_ENTRY(void, WB_UnlockCompilation(JNIEnv* env, jobject o)) 1458 MonitorLocker mo(Compilation_lock, Mutex::_no_safepoint_check_flag); 1459 WhiteBox::compilation_locked = false; 1460 mo.notify_all(); 1461 WB_END 1462 1463 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) 1464 ResourceMark rm(THREAD); 1465 int len; 1466 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); 1467 return (StringTable::lookup(name, len) != nullptr); 1468 WB_END 1469 1470 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) 1471 Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(true); 1472 Universe::heap()->collect(GCCause::_wb_full_gc); 1473 #if INCLUDE_G1GC || INCLUDE_SERIALGC 1474 if (UseG1GC || UseSerialGC) { 1475 // Needs to be cleared explicitly for G1 and Serial GC. 1476 Universe::heap()->soft_ref_policy()->set_should_clear_all_soft_refs(false); 1477 } 1478 #endif // INCLUDE_G1GC || INCLUDE_SERIALGC 1479 WB_END 1480 1481 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) 1482 Universe::heap()->collect(GCCause::_wb_young_gc); 1483 WB_END 1484 1485 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) 1486 // static+volatile in order to force the read to happen 1487 // (not be eliminated by the compiler) 1488 static char c; 1489 static volatile char* p; 1490 1491 p = os::reserve_memory(os::vm_allocation_granularity()); 1492 if (p == nullptr) { 1493 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); 1494 } 1495 1496 c = *p; 1497 WB_END 1498 1499 WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o)) 1500 const char* features = VM_Version::features_string(); 1501 ThreadToNativeFromVM ttn(thread); 1502 jstring features_string = env->NewStringUTF(features); 1503 1504 CHECK_JNI_EXCEPTION_(env, nullptr); 1505 1506 return features_string; 1507 WB_END 1508 1509 CodeBlobType WhiteBox::get_blob_type(const CodeBlob* code) { 1510 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); 1511 return CodeCache::get_code_heap(code)->code_blob_type(); 1512 } 1513 1514 CodeHeap* WhiteBox::get_code_heap(CodeBlobType blob_type) { 1515 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); 1516 return CodeCache::get_code_heap(blob_type); 1517 } 1518 1519 struct CodeBlobStub { 1520 CodeBlobStub(const CodeBlob* blob) : 1521 name(os::strdup(blob->name())), 1522 size(blob->size()), 1523 blob_type(static_cast<jint>(WhiteBox::get_blob_type(blob))), 1524 address((jlong) blob) { } 1525 ~CodeBlobStub() { os::free((void*) name); } 1526 const char* const name; 1527 const jint size; 1528 const jint blob_type; 1529 const jlong address; 1530 }; 1531 1532 static jobjectArray codeBlob2objectArray(JavaThread* thread, JNIEnv* env, CodeBlobStub* cb) { 1533 ResourceMark rm; 1534 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); 1535 CHECK_JNI_EXCEPTION_(env, nullptr); 1536 jobjectArray result = env->NewObjectArray(4, clazz, nullptr); 1537 1538 jstring name = env->NewStringUTF(cb->name); 1539 CHECK_JNI_EXCEPTION_(env, nullptr); 1540 env->SetObjectArrayElement(result, 0, name); 1541 1542 jobject obj = integerBox(thread, env, cb->size); 1543 CHECK_JNI_EXCEPTION_(env, nullptr); 1544 env->SetObjectArrayElement(result, 1, obj); 1545 1546 obj = integerBox(thread, env, cb->blob_type); 1547 CHECK_JNI_EXCEPTION_(env, nullptr); 1548 env->SetObjectArrayElement(result, 2, obj); 1549 1550 obj = longBox(thread, env, cb->address); 1551 CHECK_JNI_EXCEPTION_(env, nullptr); 1552 env->SetObjectArrayElement(result, 3, obj); 1553 1554 return result; 1555 } 1556 1557 WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) 1558 ResourceMark rm(THREAD); 1559 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1560 CHECK_JNI_EXCEPTION_(env, nullptr); 1561 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); 1562 CompiledMethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); 1563 jobjectArray result = nullptr; 1564 if (code == nullptr) { 1565 return result; 1566 } 1567 int comp_level = code->comp_level(); 1568 int insts_size = code->insts_size(); 1569 1570 ThreadToNativeFromVM ttn(thread); 1571 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); 1572 CHECK_JNI_EXCEPTION_(env, nullptr); 1573 result = env->NewObjectArray(5, clazz, nullptr); 1574 if (result == nullptr) { 1575 return result; 1576 } 1577 1578 CodeBlobStub stub(code); 1579 jobjectArray codeBlob = codeBlob2objectArray(thread, env, &stub); 1580 CHECK_JNI_EXCEPTION_(env, nullptr); 1581 env->SetObjectArrayElement(result, 0, codeBlob); 1582 1583 jobject level = integerBox(thread, env, comp_level); 1584 CHECK_JNI_EXCEPTION_(env, nullptr); 1585 env->SetObjectArrayElement(result, 1, level); 1586 1587 jbyteArray insts = env->NewByteArray(insts_size); 1588 CHECK_JNI_EXCEPTION_(env, nullptr); 1589 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin()); 1590 env->SetObjectArrayElement(result, 2, insts); 1591 1592 jobject id = integerBox(thread, env, code->compile_id()); 1593 CHECK_JNI_EXCEPTION_(env, nullptr); 1594 env->SetObjectArrayElement(result, 3, id); 1595 1596 jobject entry_point = longBox(thread, env, (jlong) code->entry_point()); 1597 CHECK_JNI_EXCEPTION_(env, nullptr); 1598 env->SetObjectArrayElement(result, 4, entry_point); 1599 1600 return result; 1601 WB_END 1602 1603 CodeBlob* WhiteBox::allocate_code_blob(int size, CodeBlobType blob_type) { 1604 guarantee(WhiteBoxAPI, "internal testing API :: WhiteBox has to be enabled"); 1605 BufferBlob* blob; 1606 int full_size = CodeBlob::align_code_offset(sizeof(BufferBlob)); 1607 if (full_size < size) { 1608 full_size += align_up(size - full_size, oopSize); 1609 } 1610 { 1611 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1612 blob = (BufferBlob*) CodeCache::allocate(full_size, blob_type); 1613 if (blob != nullptr) { 1614 ::new (blob) BufferBlob("WB::DummyBlob", full_size); 1615 } 1616 } 1617 // Track memory usage statistic after releasing CodeCache_lock 1618 MemoryService::track_code_cache_memory_usage(); 1619 return blob; 1620 } 1621 1622 WB_ENTRY(jlong, WB_AllocateCodeBlob(JNIEnv* env, jobject o, jint size, jint blob_type)) 1623 if (size < 0) { 1624 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1625 err_msg("WB_AllocateCodeBlob: size is negative: " INT32_FORMAT, size)); 1626 } 1627 return (jlong) WhiteBox::allocate_code_blob(size, static_cast<CodeBlobType>(blob_type)); 1628 WB_END 1629 1630 WB_ENTRY(void, WB_FreeCodeBlob(JNIEnv* env, jobject o, jlong addr)) 1631 if (addr == 0) { 1632 return; 1633 } 1634 BufferBlob::free((BufferBlob*) addr); 1635 WB_END 1636 1637 WB_ENTRY(jobjectArray, WB_GetCodeHeapEntries(JNIEnv* env, jobject o, jint blob_type)) 1638 ResourceMark rm; 1639 GrowableArray<CodeBlobStub*> blobs; 1640 { 1641 MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag); 1642 CodeHeap* heap = WhiteBox::get_code_heap(static_cast<CodeBlobType>(blob_type)); 1643 if (heap == nullptr) { 1644 return nullptr; 1645 } 1646 for (CodeBlob* cb = (CodeBlob*) heap->first(); 1647 cb != nullptr; cb = (CodeBlob*) heap->next(cb)) { 1648 CodeBlobStub* stub = NEW_RESOURCE_OBJ(CodeBlobStub); 1649 new (stub) CodeBlobStub(cb); 1650 blobs.append(stub); 1651 } 1652 } 1653 ThreadToNativeFromVM ttn(thread); 1654 jobjectArray result = nullptr; 1655 jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); 1656 CHECK_JNI_EXCEPTION_(env, nullptr); 1657 result = env->NewObjectArray(blobs.length(), clazz, nullptr); 1658 CHECK_JNI_EXCEPTION_(env, nullptr); 1659 if (result == nullptr) { 1660 return result; 1661 } 1662 int i = 0; 1663 for (GrowableArrayIterator<CodeBlobStub*> it = blobs.begin(); 1664 it != blobs.end(); ++it) { 1665 jobjectArray obj = codeBlob2objectArray(thread, env, *it); 1666 CHECK_JNI_EXCEPTION_(env, nullptr); 1667 env->SetObjectArrayElement(result, i, obj); 1668 CHECK_JNI_EXCEPTION_(env, nullptr); 1669 ++i; 1670 } 1671 return result; 1672 WB_END 1673 1674 WB_ENTRY(jint, WB_GetCompilationActivityMode(JNIEnv* env, jobject o)) 1675 return CompileBroker::get_compilation_activity_mode(); 1676 WB_END 1677 1678 WB_ENTRY(jobjectArray, WB_GetCodeBlob(JNIEnv* env, jobject o, jlong addr)) 1679 if (addr == 0) { 1680 THROW_MSG_NULL(vmSymbols::java_lang_NullPointerException(), 1681 "WB_GetCodeBlob: addr is null"); 1682 } 1683 ThreadToNativeFromVM ttn(thread); 1684 CodeBlobStub stub((CodeBlob*) addr); 1685 return codeBlob2objectArray(thread, env, &stub); 1686 WB_END 1687 1688 WB_ENTRY(jlong, WB_GetMethodData(JNIEnv* env, jobject wv, jobject method)) 1689 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 1690 CHECK_JNI_EXCEPTION_(env, 0); 1691 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid)); 1692 return (jlong) mh->method_data(); 1693 WB_END 1694 1695 WB_ENTRY(jlong, WB_GetThreadStackSize(JNIEnv* env, jobject o)) 1696 return (jlong) thread->stack_size(); 1697 WB_END 1698 1699 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o)) 1700 return (jlong) thread->stack_overflow_state()->stack_available( 1701 os::current_stack_pointer()) - (jlong)StackOverflow::stack_shadow_zone_size(); 1702 WB_END 1703 1704 1705 int WhiteBox::array_bytes_to_length(size_t bytes) { 1706 return Array<u1>::bytes_to_length(bytes); 1707 } 1708 1709 /////////////// 1710 // MetaspaceTestContext and MetaspaceTestArena 1711 WB_ENTRY(jlong, WB_CreateMetaspaceTestContext(JNIEnv* env, jobject wb, jlong commit_limit, jlong reserve_limit)) 1712 metaspace::MetaspaceTestContext* context = 1713 new metaspace::MetaspaceTestContext("whitebox-metaspace-context", (size_t) commit_limit, (size_t) reserve_limit); 1714 return (jlong)p2i(context); 1715 WB_END 1716 1717 WB_ENTRY(void, WB_DestroyMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context)) 1718 delete (metaspace::MetaspaceTestContext*) context; 1719 WB_END 1720 1721 WB_ENTRY(void, WB_PurgeMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context)) 1722 metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context; 1723 context0->purge_area(); 1724 WB_END 1725 1726 WB_ENTRY(void, WB_PrintMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context)) 1727 metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context; 1728 context0->print_on(tty); 1729 WB_END 1730 1731 WB_ENTRY(jlong, WB_GetTotalCommittedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context)) 1732 metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context; 1733 return context0->committed_words(); 1734 WB_END 1735 1736 WB_ENTRY(jlong, WB_GetTotalUsedWordsInMetaspaceTestContext(JNIEnv* env, jobject wb, jlong context)) 1737 metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context; 1738 return context0->used_words(); 1739 WB_END 1740 1741 WB_ENTRY(jlong, WB_CreateArenaInTestContext(JNIEnv* env, jobject wb, jlong context, jboolean is_micro)) 1742 const Metaspace::MetaspaceType type = is_micro ? Metaspace::ReflectionMetaspaceType : Metaspace::StandardMetaspaceType; 1743 metaspace::MetaspaceTestContext* context0 = (metaspace::MetaspaceTestContext*) context; 1744 return (jlong)p2i(context0->create_arena(type)); 1745 WB_END 1746 1747 WB_ENTRY(void, WB_DestroyMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena)) 1748 delete (metaspace::MetaspaceTestArena*) arena; 1749 WB_END 1750 1751 WB_ENTRY(jlong, WB_AllocateFromMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong word_size)) 1752 metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena; 1753 MetaWord* p = arena0->allocate((size_t) word_size); 1754 return (jlong)p2i(p); 1755 WB_END 1756 1757 WB_ENTRY(void, WB_DeallocateToMetaspaceTestArena(JNIEnv* env, jobject wb, jlong arena, jlong p, jlong word_size)) 1758 metaspace::MetaspaceTestArena* arena0 = (metaspace::MetaspaceTestArena*) arena; 1759 arena0->deallocate((MetaWord*)p, (size_t) word_size); 1760 WB_END 1761 1762 WB_ENTRY(jlong, WB_GetMaxMetaspaceAllocationSize(JNIEnv* env, jobject wb)) 1763 return (jlong) Metaspace::max_allocation_word_size() * BytesPerWord; 1764 WB_END 1765 1766 ////////////// 1767 1768 WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size)) 1769 if (size < 0) { 1770 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1771 err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size)); 1772 } 1773 1774 oop class_loader_oop = JNIHandles::resolve(class_loader); 1775 ClassLoaderData* cld = class_loader_oop != nullptr 1776 ? java_lang_ClassLoader::loader_data_acquire(class_loader_oop) 1777 : ClassLoaderData::the_null_class_loader_data(); 1778 1779 void* metadata = MetadataFactory::new_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread); 1780 1781 return (jlong)(uintptr_t)metadata; 1782 WB_END 1783 1784 WB_ENTRY(void, WB_DefineModule(JNIEnv* env, jobject o, jobject module, jboolean is_open, 1785 jstring version, jstring location, jobjectArray packages)) 1786 Handle h_module (THREAD, JNIHandles::resolve(module)); 1787 Modules::define_module(h_module, is_open, version, location, packages, CHECK); 1788 WB_END 1789 1790 WB_ENTRY(void, WB_AddModuleExports(JNIEnv* env, jobject o, jobject from_module, jstring package, jobject to_module)) 1791 Handle h_from_module (THREAD, JNIHandles::resolve(from_module)); 1792 Handle h_to_module (THREAD, JNIHandles::resolve(to_module)); 1793 Modules::add_module_exports_qualified(h_from_module, package, h_to_module, CHECK); 1794 WB_END 1795 1796 WB_ENTRY(void, WB_AddModuleExportsToAllUnnamed(JNIEnv* env, jobject o, jclass module, jstring package)) 1797 Handle h_module (THREAD, JNIHandles::resolve(module)); 1798 Modules::add_module_exports_to_all_unnamed(h_module, package, CHECK); 1799 WB_END 1800 1801 WB_ENTRY(void, WB_AddModuleExportsToAll(JNIEnv* env, jobject o, jclass module, jstring package)) 1802 Handle h_module (THREAD, JNIHandles::resolve(module)); 1803 Modules::add_module_exports(h_module, package, Handle(), CHECK); 1804 WB_END 1805 1806 WB_ENTRY(void, WB_AddReadsModule(JNIEnv* env, jobject o, jobject from_module, jobject source_module)) 1807 Handle h_from_module (THREAD, JNIHandles::resolve(from_module)); 1808 Handle h_source_module (THREAD, JNIHandles::resolve(source_module)); 1809 Modules::add_reads_module(h_from_module, h_source_module, CHECK); 1810 WB_END 1811 1812 WB_ENTRY(jlong, WB_IncMetaspaceCapacityUntilGC(JNIEnv* env, jobject wb, jlong inc)) 1813 if (inc < 0) { 1814 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1815 err_msg("WB_IncMetaspaceCapacityUntilGC: inc is negative: " JLONG_FORMAT, inc)); 1816 } 1817 1818 jlong max_size_t = (jlong) ((size_t) -1); 1819 if (inc > max_size_t) { 1820 THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), 1821 err_msg("WB_IncMetaspaceCapacityUntilGC: inc does not fit in size_t: " JLONG_FORMAT, inc)); 1822 } 1823 1824 size_t new_cap_until_GC = 0; 1825 size_t aligned_inc = align_down((size_t) inc, Metaspace::commit_alignment()); 1826 bool success = MetaspaceGC::inc_capacity_until_GC(aligned_inc, &new_cap_until_GC); 1827 if (!success) { 1828 THROW_MSG_0(vmSymbols::java_lang_IllegalStateException(), 1829 "WB_IncMetaspaceCapacityUntilGC: could not increase capacity until GC " 1830 "due to contention with another thread"); 1831 } 1832 return (jlong) new_cap_until_GC; 1833 WB_END 1834 1835 WB_ENTRY(jlong, WB_MetaspaceCapacityUntilGC(JNIEnv* env, jobject wb)) 1836 return (jlong) MetaspaceGC::capacity_until_GC(); 1837 WB_END 1838 1839 // The function is only valid when CDS is available. 1840 WB_ENTRY(jlong, WB_MetaspaceSharedRegionAlignment(JNIEnv* env, jobject wb)) 1841 #if INCLUDE_CDS 1842 return (jlong)MetaspaceShared::core_region_alignment(); 1843 #else 1844 ShouldNotReachHere(); 1845 return 0L; 1846 #endif 1847 WB_END 1848 1849 WB_ENTRY(jboolean, WB_IsMonitorInflated(JNIEnv* env, jobject wb, jobject obj)) 1850 oop obj_oop = JNIHandles::resolve(obj); 1851 return (jboolean) obj_oop->mark().has_monitor(); 1852 WB_END 1853 1854 WB_ENTRY(jint, WB_getLockStackCapacity(JNIEnv* env)) 1855 return (jint) LockStack::CAPACITY; 1856 WB_END 1857 1858 WB_ENTRY(jboolean, WB_supportsRecursiveLightweightLocking(JNIEnv* env)) 1859 return (jboolean) VM_Version::supports_recursive_lightweight_locking(); 1860 WB_END 1861 1862 WB_ENTRY(jboolean, WB_DeflateIdleMonitors(JNIEnv* env, jobject wb)) 1863 log_info(monitorinflation)("WhiteBox initiated DeflateIdleMonitors"); 1864 return ObjectSynchronizer::request_deflate_idle_monitors_from_wb(); 1865 WB_END 1866 1867 WB_ENTRY(void, WB_ForceSafepoint(JNIEnv* env, jobject wb)) 1868 VM_ForceSafepoint force_safepoint_op; 1869 VMThread::execute(&force_safepoint_op); 1870 WB_END 1871 1872 WB_ENTRY(void, WB_ForceClassLoaderStatsSafepoint(JNIEnv* env, jobject wb)) 1873 nullStream dev_null; 1874 ClassLoaderStatsVMOperation force_op(&dev_null); 1875 VMThread::execute(&force_op); 1876 WB_END 1877 1878 WB_ENTRY(jlong, WB_GetConstantPool(JNIEnv* env, jobject wb, jclass klass)) 1879 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1880 return (jlong) ik->constants(); 1881 WB_END 1882 1883 WB_ENTRY(jobjectArray, WB_GetResolvedReferences(JNIEnv* env, jobject wb, jclass klass)) 1884 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1885 objArrayOop resolved_refs= ik->constants()->resolved_references(); 1886 return (jobjectArray)JNIHandles::make_local(THREAD, resolved_refs); 1887 WB_END 1888 1889 WB_ENTRY(jint, WB_ConstantPoolEncodeIndyIndex(JNIEnv* env, jobject wb, jint index)) 1890 return ConstantPool::encode_invokedynamic_index(index); 1891 WB_END 1892 1893 WB_ENTRY(jobjectArray, WB_getObjectsViaKlassOopMaps(JNIEnv* env, jobject wb, jobject thing)) 1894 oop aoop = JNIHandles::resolve(thing); 1895 if (!aoop->is_instance()) { 1896 return nullptr; 1897 } 1898 instanceHandle ih(THREAD, (instanceOop) aoop); 1899 InstanceKlass* klass = InstanceKlass::cast(ih->klass()); 1900 if (klass->nonstatic_oop_map_count() == 0) { 1901 return nullptr; 1902 } 1903 const OopMapBlock* map = klass->start_of_nonstatic_oop_maps(); 1904 const OopMapBlock* const end = map + klass->nonstatic_oop_map_count(); 1905 int oop_count = 0; 1906 while (map < end) { 1907 oop_count += map->count(); 1908 map++; 1909 } 1910 1911 objArrayHandle result_array = 1912 oopFactory::new_objArray_handle(vmClasses::Object_klass(), oop_count, CHECK_NULL); 1913 map = klass->start_of_nonstatic_oop_maps(); 1914 int index = 0; 1915 while (map < end) { 1916 int offset = map->offset(); 1917 for (unsigned int j = 0; j < map->count(); j++) { 1918 result_array->obj_at_put(index++, ih->obj_field(offset)); 1919 offset += heapOopSize; 1920 } 1921 map++; 1922 } 1923 return (jobjectArray)JNIHandles::make_local(THREAD, result_array()); 1924 WB_END 1925 1926 class CollectOops : public BasicOopIterateClosure { 1927 public: 1928 GrowableArray<Handle>* array; 1929 1930 jobjectArray create_jni_result(JNIEnv* env, TRAPS) { 1931 objArrayHandle result_array = 1932 oopFactory::new_objArray_handle(vmClasses::Object_klass(), array->length(), CHECK_NULL); 1933 for (int i = 0 ; i < array->length(); i++) { 1934 result_array->obj_at_put(i, array->at(i)()); 1935 } 1936 return (jobjectArray)JNIHandles::make_local(THREAD, result_array()); 1937 } 1938 1939 void add_oop(oop o) { 1940 Handle oh = Handle(Thread::current(), o); 1941 // Value might be oop, but JLS can't see as Object, just iterate through it... 1942 if (oh != nullptr && oh->is_inline_type()) { 1943 oh->oop_iterate(this); 1944 } else { 1945 array->append(oh); 1946 } 1947 } 1948 1949 void do_oop(oop* o) { add_oop(HeapAccess<>::oop_load(o)); } 1950 void do_oop(narrowOop* v) { add_oop(HeapAccess<>::oop_load(v)); } 1951 }; 1952 1953 1954 WB_ENTRY(jobjectArray, WB_getObjectsViaOopIterator(JNIEnv* env, jobject wb, jobject thing)) 1955 ResourceMark rm(thread); 1956 Handle objh(thread, JNIHandles::resolve(thing)); 1957 GrowableArray<Handle>* array = new GrowableArray<Handle>(128); 1958 CollectOops collectOops; 1959 collectOops.array = array; 1960 objh->oop_iterate(&collectOops); 1961 return collectOops.create_jni_result(env, THREAD); 1962 WB_END 1963 1964 WB_ENTRY(jobjectArray, WB_getObjectsViaFrameOopIterator(JNIEnv* env, jobject wb, jint depth)) 1965 ResourceMark rm(THREAD); 1966 GrowableArray<Handle>* array = new GrowableArray<Handle>(128); 1967 CollectOops collectOops; 1968 collectOops.array = array; 1969 StackFrameStream sfs(thread, false /* update */, true /* process_frames */); 1970 while (depth > 0) { // Skip the native WB API frame 1971 sfs.next(); 1972 frame* f = sfs.current(); 1973 f->oops_do(&collectOops, nullptr, sfs.register_map()); 1974 depth--; 1975 } 1976 return collectOops.create_jni_result(env, THREAD); 1977 WB_END 1978 1979 1980 WB_ENTRY(jint, WB_getFieldEntriesLength(JNIEnv* env, jobject wb, jclass klass)) 1981 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1982 ConstantPool* cp = ik->constants(); 1983 if (cp->cache() == nullptr) { 1984 return -1; 1985 } 1986 return cp->resolved_field_entries_length(); 1987 WB_END 1988 1989 WB_ENTRY(jint, WB_getFieldCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index)) 1990 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 1991 ConstantPool* cp = ik->constants(); 1992 if (cp->cache() == nullptr) { 1993 return -1; 1994 } 1995 return cp->resolved_field_entry_at(index)->constant_pool_index(); 1996 WB_END 1997 1998 WB_ENTRY(jint, WB_getMethodEntriesLength(JNIEnv* env, jobject wb, jclass klass)) 1999 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 2000 ConstantPool* cp = ik->constants(); 2001 if (cp->cache() == nullptr) { 2002 return -1; 2003 } 2004 return cp->resolved_method_entries_length(); 2005 WB_END 2006 2007 WB_ENTRY(jint, WB_getMethodCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index)) 2008 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 2009 ConstantPool* cp = ik->constants(); 2010 if (cp->cache() == nullptr) { 2011 return -1; 2012 } 2013 return cp->resolved_method_entry_at(index)->constant_pool_index(); 2014 WB_END 2015 2016 WB_ENTRY(jint, WB_getIndyInfoLength(JNIEnv* env, jobject wb, jclass klass)) 2017 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 2018 ConstantPool* cp = ik->constants(); 2019 if (cp->cache() == nullptr) { 2020 return -1; 2021 } 2022 return cp->resolved_indy_entries_length(); 2023 WB_END 2024 2025 WB_ENTRY(jint, WB_getIndyCPIndex(JNIEnv* env, jobject wb, jclass klass, jint index)) 2026 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(klass))); 2027 ConstantPool* cp = ik->constants(); 2028 if (cp->cache() == nullptr) { 2029 return -1; 2030 } 2031 return cp->resolved_indy_entry_at(index)->constant_pool_index(); 2032 WB_END 2033 2034 WB_ENTRY(jobject, WB_printClasses(JNIEnv* env, jobject wb, jstring class_name_pattern, jint flags)) 2035 ThreadToNativeFromVM ttnfv(thread); 2036 const char* c = env->GetStringUTFChars(class_name_pattern, nullptr); 2037 ResourceMark rm; 2038 stringStream st; 2039 { 2040 ThreadInVMfromNative ttvfn(thread); // back to VM 2041 ClassPrinter::print_classes(c, flags, &st); 2042 } 2043 jstring result = env->NewStringUTF(st.freeze()); 2044 CHECK_JNI_EXCEPTION_(env, nullptr); 2045 return result; 2046 WB_END 2047 2048 WB_ENTRY(jobject, WB_printMethods(JNIEnv* env, jobject wb, jstring class_name_pattern, jstring method_pattern, jint flags)) 2049 ThreadToNativeFromVM ttnfv(thread); 2050 const char* c = env->GetStringUTFChars(class_name_pattern, nullptr); 2051 const char* m = env->GetStringUTFChars(method_pattern, nullptr); 2052 ResourceMark rm; 2053 stringStream st; 2054 { 2055 ThreadInVMfromNative ttvfn(thread); // back to VM 2056 ClassPrinter::print_methods(c, m, flags, &st); 2057 } 2058 jstring result = env->NewStringUTF(st.freeze()); 2059 CHECK_JNI_EXCEPTION_(env, nullptr); 2060 return result; 2061 WB_END 2062 2063 WB_ENTRY(void, WB_ClearInlineCaches(JNIEnv* env, jobject wb, jboolean preserve_static_stubs)) 2064 VM_ClearICs clear_ics(preserve_static_stubs == JNI_TRUE); 2065 VMThread::execute(&clear_ics); 2066 WB_END 2067 2068 template <typename T> 2069 static bool GetMethodOption(JavaThread* thread, JNIEnv* env, jobject method, jstring name, T* value) { 2070 assert(value != nullptr, "sanity"); 2071 if (method == nullptr || name == nullptr) { 2072 return false; 2073 } 2074 jmethodID jmid = reflected_method_to_jmid(thread, env, method); 2075 CHECK_JNI_EXCEPTION_(env, false); 2076 methodHandle mh(thread, Method::checked_resolve_jmethod_id(jmid)); 2077 // can't be in VM when we call JNI 2078 ThreadToNativeFromVM ttnfv(thread); 2079 const char* flag_name = env->GetStringUTFChars(name, nullptr); 2080 CHECK_JNI_EXCEPTION_(env, false); 2081 enum CompileCommand option = CompilerOracle::string_to_option(flag_name); 2082 env->ReleaseStringUTFChars(name, flag_name); 2083 if (option == CompileCommand::Unknown) { 2084 return false; 2085 } 2086 if (!CompilerOracle::option_matches_type(option, *value)) { 2087 return false; 2088 } 2089 return CompilerOracle::has_option_value(mh, option, *value); 2090 } 2091 2092 WB_ENTRY(jobject, WB_GetMethodBooleaneOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 2093 bool result; 2094 if (GetMethodOption<bool> (thread, env, method, name, &result)) { 2095 // can't be in VM when we call JNI 2096 ThreadToNativeFromVM ttnfv(thread); 2097 return booleanBox(thread, env, result); 2098 } 2099 return nullptr; 2100 WB_END 2101 2102 WB_ENTRY(jobject, WB_GetMethodIntxOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 2103 intx result; 2104 if (GetMethodOption <intx> (thread, env, method, name, &result)) { 2105 // can't be in VM when we call JNI 2106 ThreadToNativeFromVM ttnfv(thread); 2107 return longBox(thread, env, result); 2108 } 2109 return nullptr; 2110 WB_END 2111 2112 WB_ENTRY(jobject, WB_GetMethodUintxOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 2113 uintx result; 2114 if (GetMethodOption <uintx> (thread, env, method, name, &result)) { 2115 // can't be in VM when we call JNI 2116 ThreadToNativeFromVM ttnfv(thread); 2117 return longBox(thread, env, result); 2118 } 2119 return nullptr; 2120 WB_END 2121 2122 WB_ENTRY(jobject, WB_GetMethodDoubleOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 2123 double result; 2124 if (GetMethodOption <double> (thread, env, method, name, &result)) { 2125 // can't be in VM when we call JNI 2126 ThreadToNativeFromVM ttnfv(thread); 2127 return doubleBox(thread, env, result); 2128 } 2129 return nullptr; 2130 WB_END 2131 2132 WB_ENTRY(jobject, WB_GetMethodStringOption(JNIEnv* env, jobject wb, jobject method, jstring name)) 2133 ccstr ccstrResult; 2134 if (GetMethodOption <ccstr> (thread, env, method, name, &ccstrResult)) { 2135 // can't be in VM when we call JNI 2136 ThreadToNativeFromVM ttnfv(thread); 2137 jstring result = env->NewStringUTF(ccstrResult); 2138 CHECK_JNI_EXCEPTION_(env, nullptr); 2139 return result; 2140 } 2141 return nullptr; 2142 WB_END 2143 2144 WB_ENTRY(jobject, WB_GetDefaultArchivePath(JNIEnv* env, jobject wb)) 2145 const char* p = CDSConfig::default_archive_path(); 2146 ThreadToNativeFromVM ttn(thread); 2147 jstring path_string = env->NewStringUTF(p); 2148 2149 CHECK_JNI_EXCEPTION_(env, nullptr); 2150 2151 return path_string; 2152 WB_END 2153 2154 WB_ENTRY(jboolean, WB_IsSharingEnabled(JNIEnv* env, jobject wb)) 2155 return UseSharedSpaces; 2156 WB_END 2157 2158 WB_ENTRY(jint, WB_GetCDSGenericHeaderMinVersion(JNIEnv* env, jobject wb)) 2159 #if INCLUDE_CDS 2160 return (jint)CDS_GENERIC_HEADER_SUPPORTED_MIN_VERSION; 2161 #else 2162 ShouldNotReachHere(); 2163 return (jint)-1; 2164 #endif 2165 WB_END 2166 2167 WB_ENTRY(jint, WB_GetCDSCurrentVersion(JNIEnv* env, jobject wb)) 2168 #if INCLUDE_CDS 2169 return (jint)CURRENT_CDS_ARCHIVE_VERSION; 2170 #else 2171 ShouldNotReachHere(); 2172 return (jint)-1; 2173 #endif 2174 WB_END 2175 2176 WB_ENTRY(jboolean, WB_CDSMemoryMappingFailed(JNIEnv* env, jobject wb)) 2177 return FileMapInfo::memory_mapping_failed(); 2178 WB_END 2179 2180 WB_ENTRY(jboolean, WB_IsSharedInternedString(JNIEnv* env, jobject wb, jobject str)) 2181 ResourceMark rm(THREAD); 2182 oop str_oop = JNIHandles::resolve(str); 2183 int length; 2184 jchar* chars = java_lang_String::as_unicode_string(str_oop, length, CHECK_(false)); 2185 return StringTable::lookup_shared(chars, length) == str_oop; 2186 WB_END 2187 2188 WB_ENTRY(jboolean, WB_IsSharedClass(JNIEnv* env, jobject wb, jclass clazz)) 2189 return (jboolean)MetaspaceShared::is_in_shared_metaspace(java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz))); 2190 WB_END 2191 2192 WB_ENTRY(jboolean, WB_AreSharedStringsMapped(JNIEnv* env)) 2193 return ArchiveHeapLoader::is_mapped(); 2194 WB_END 2195 2196 WB_ENTRY(void, WB_LinkClass(JNIEnv* env, jobject wb, jclass clazz)) 2197 Klass *k = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(clazz)); 2198 if (!k->is_instance_klass()) { 2199 return; 2200 } 2201 InstanceKlass *ik = InstanceKlass::cast(k); 2202 ik->link_class(THREAD); // may throw verification error 2203 WB_END 2204 2205 WB_ENTRY(jboolean, WB_AreOpenArchiveHeapObjectsMapped(JNIEnv* env)) 2206 return ArchiveHeapLoader::is_mapped(); 2207 WB_END 2208 2209 WB_ENTRY(jboolean, WB_IsCDSIncluded(JNIEnv* env)) 2210 #if INCLUDE_CDS 2211 return true; 2212 #else 2213 return false; 2214 #endif // INCLUDE_CDS 2215 WB_END 2216 2217 WB_ENTRY(jboolean, WB_isC2OrJVMCIIncluded(JNIEnv* env)) 2218 #if COMPILER2_OR_JVMCI 2219 return true; 2220 #else 2221 return false; 2222 #endif 2223 WB_END 2224 2225 WB_ENTRY(jboolean, WB_IsJVMCISupportedByGC(JNIEnv* env)) 2226 #if INCLUDE_JVMCI 2227 return JVMCIGlobals::gc_supports_jvmci(); 2228 #else 2229 return false; 2230 #endif 2231 WB_END 2232 2233 WB_ENTRY(jboolean, WB_CanWriteJavaHeapArchive(JNIEnv* env)) 2234 return HeapShared::can_write(); 2235 WB_END 2236 2237 2238 WB_ENTRY(jboolean, WB_IsJFRIncluded(JNIEnv* env)) 2239 #if INCLUDE_JFR 2240 return true; 2241 #else 2242 return false; 2243 #endif // INCLUDE_JFR 2244 WB_END 2245 2246 WB_ENTRY(jboolean, WB_IsDTraceIncluded(JNIEnv* env)) 2247 #if defined(DTRACE_ENABLED) 2248 return true; 2249 #else 2250 return false; 2251 #endif // DTRACE_ENABLED 2252 WB_END 2253 2254 #if INCLUDE_CDS 2255 2256 WB_ENTRY(jint, WB_GetCDSOffsetForName(JNIEnv* env, jobject o, jstring name)) 2257 ResourceMark rm; 2258 char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 2259 jint result = (jint)CDSConstants::get_cds_offset(c_name); 2260 return result; 2261 WB_END 2262 2263 WB_ENTRY(jint, WB_GetCDSConstantForName(JNIEnv* env, jobject o, jstring name)) 2264 ResourceMark rm; 2265 char* c_name = java_lang_String::as_utf8_string(JNIHandles::resolve_non_null(name)); 2266 jint result = (jint)CDSConstants::get_cds_constant(c_name); 2267 return result; 2268 WB_END 2269 2270 #endif // INCLUDE_CDS 2271 2272 WB_ENTRY(jboolean, WB_HandshakeReadMonitors(JNIEnv* env, jobject wb, jobject thread_handle)) 2273 class ReadMonitorsClosure : public HandshakeClosure { 2274 jboolean _executed; 2275 2276 void do_thread(Thread* th) { 2277 JavaThread* jt = JavaThread::cast(th); 2278 ResourceMark rm; 2279 2280 GrowableArray<MonitorInfo*>* info = new GrowableArray<MonitorInfo*>(); 2281 2282 if (!jt->has_last_Java_frame()) { 2283 return; 2284 } 2285 RegisterMap rmap(jt, 2286 RegisterMap::UpdateMap::include, 2287 RegisterMap::ProcessFrames::include, 2288 RegisterMap::WalkContinuation::skip); 2289 for (javaVFrame* vf = jt->last_java_vframe(&rmap); vf != nullptr; vf = vf->java_sender()) { 2290 GrowableArray<MonitorInfo*> *monitors = vf->monitors(); 2291 if (monitors != nullptr) { 2292 int len = monitors->length(); 2293 // Walk monitors youngest to oldest 2294 for (int i = len - 1; i >= 0; i--) { 2295 MonitorInfo* mon_info = monitors->at(i); 2296 if (mon_info->eliminated()) continue; 2297 oop owner = mon_info->owner(); 2298 if (owner != nullptr) { 2299 info->append(mon_info); 2300 } 2301 } 2302 } 2303 } 2304 _executed = true; 2305 } 2306 2307 public: 2308 ReadMonitorsClosure() : HandshakeClosure("WB_HandshakeReadMonitors"), _executed(false) {} 2309 jboolean executed() const { return _executed; } 2310 }; 2311 2312 ReadMonitorsClosure rmc; 2313 if (thread_handle != nullptr) { 2314 ThreadsListHandle tlh; 2315 JavaThread* target = nullptr; 2316 bool is_alive = tlh.cv_internal_thread_to_JavaThread(thread_handle, &target, nullptr); 2317 if (is_alive) { 2318 Handshake::execute(&rmc, &tlh, target); 2319 } 2320 } 2321 return rmc.executed(); 2322 WB_END 2323 2324 WB_ENTRY(jint, WB_HandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle, jboolean all_threads)) 2325 class TraceSelfClosure : public HandshakeClosure { 2326 jint _num_threads_completed; 2327 2328 void do_thread(Thread* th) { 2329 JavaThread* jt = JavaThread::cast(th); 2330 ResourceMark rm; 2331 2332 jt->print_on(tty); 2333 jt->print_stack_on(tty); 2334 tty->cr(); 2335 Atomic::inc(&_num_threads_completed); 2336 } 2337 2338 public: 2339 TraceSelfClosure(Thread* thread) : HandshakeClosure("WB_TraceSelf"), _num_threads_completed(0) {} 2340 2341 jint num_threads_completed() const { return _num_threads_completed; } 2342 }; 2343 TraceSelfClosure tsc(Thread::current()); 2344 2345 if (all_threads) { 2346 Handshake::execute(&tsc); 2347 } else if (thread_handle != nullptr) { 2348 ThreadsListHandle tlh; 2349 JavaThread* target = nullptr; 2350 bool is_alive = tlh.cv_internal_thread_to_JavaThread(thread_handle, &target, nullptr); 2351 if (is_alive) { 2352 Handshake::execute(&tsc, &tlh, target); 2353 } 2354 } 2355 return tsc.num_threads_completed(); 2356 WB_END 2357 2358 WB_ENTRY(void, WB_AsyncHandshakeWalkStack(JNIEnv* env, jobject wb, jobject thread_handle)) 2359 class TraceSelfClosure : public AsyncHandshakeClosure { 2360 JavaThread* _self; 2361 void do_thread(Thread* th) { 2362 assert(th->is_Java_thread(), "sanity"); 2363 // AsynchHandshake handshakes are only executed by target. 2364 assert(_self == th, "Must be"); 2365 assert(Thread::current() == th, "Must be"); 2366 JavaThread* jt = JavaThread::cast(th); 2367 ResourceMark rm; 2368 jt->print_on(tty); 2369 jt->print_stack_on(tty); 2370 tty->cr(); 2371 } 2372 2373 public: 2374 TraceSelfClosure(JavaThread* self_target) : AsyncHandshakeClosure("WB_TraceSelf"), _self(self_target) {} 2375 }; 2376 if (thread_handle != nullptr) { 2377 ThreadsListHandle tlh; 2378 JavaThread* target = nullptr; 2379 bool is_alive = tlh.cv_internal_thread_to_JavaThread(thread_handle, &target, nullptr); 2380 if (is_alive) { 2381 TraceSelfClosure* tsc = new TraceSelfClosure(target); 2382 Handshake::execute(tsc, target); 2383 } 2384 } 2385 WB_END 2386 2387 static volatile int _emulated_lock = 0; 2388 2389 WB_ENTRY(void, WB_LockAndBlock(JNIEnv* env, jobject wb, jboolean suspender)) 2390 JavaThread* self = JavaThread::current(); 2391 2392 { 2393 // Before trying to acquire the lock transition into a safepoint safe state. 2394 // Otherwise if either suspender or suspendee blocks for a safepoint 2395 // in ~ThreadBlockInVM the other one could loop forever trying to acquire 2396 // the lock without allowing the safepoint to progress. 2397 ThreadBlockInVM tbivm(self); 2398 2399 // We will deadlock here if we are 'suspender' and 'suspendee' 2400 // suspended in ~ThreadBlockInVM. This verifies we only suspend 2401 // at the right place. 2402 while (Atomic::cmpxchg(&_emulated_lock, 0, 1) != 0) {} 2403 assert(_emulated_lock == 1, "Must be locked"); 2404 2405 // Sleep much longer in suspendee to force situation where 2406 // 'suspender' is waiting above to acquire lock. 2407 os::naked_short_sleep(suspender ? 1 : 10); 2408 } 2409 Atomic::store(&_emulated_lock, 0); 2410 WB_END 2411 2412 // Some convenience methods to deal with objects from java 2413 int WhiteBox::offset_for_field(const char* field_name, oop object, 2414 Symbol* signature_symbol) { 2415 assert(field_name != nullptr && strlen(field_name) > 0, "Field name not valid"); 2416 2417 //Get the class of our object 2418 Klass* arg_klass = object->klass(); 2419 //Turn it into an instance-klass 2420 InstanceKlass* ik = InstanceKlass::cast(arg_klass); 2421 2422 //Create symbols to look for in the class 2423 TempNewSymbol name_symbol = SymbolTable::new_symbol(field_name); 2424 2425 //To be filled in with an offset of the field we're looking for 2426 fieldDescriptor fd; 2427 2428 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); 2429 if (res == nullptr) { 2430 tty->print_cr("Invalid layout of %s at %s", ik->external_name(), 2431 name_symbol->as_C_string()); 2432 vm_exit_during_initialization("Invalid layout of preloaded class: use -Xlog:class+load=info to see the origin of the problem class"); 2433 } 2434 2435 //fetch the field at the offset we've found 2436 int dest_offset = fd.offset(); 2437 2438 return dest_offset; 2439 } 2440 2441 2442 const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { 2443 int offset = offset_for_field(field_name, object, 2444 vmSymbols::string_signature()); 2445 oop string = object->obj_field(offset); 2446 if (string == nullptr) { 2447 return nullptr; 2448 } 2449 const char* ret = java_lang_String::as_utf8_string(string); 2450 return ret; 2451 } 2452 2453 bool WhiteBox::lookup_bool(const char* field_name, oop object) { 2454 int offset = 2455 offset_for_field(field_name, object, vmSymbols::bool_signature()); 2456 bool ret = (object->bool_field(offset) == JNI_TRUE); 2457 return ret; 2458 } 2459 2460 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { 2461 ResourceMark rm; 2462 Klass* klass = java_lang_Class::as_Klass(JNIHandles::resolve_non_null(wbclass)); 2463 const char* klass_name = klass->external_name(); 2464 2465 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI 2466 2467 // one by one registration natives for exception catching 2468 jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); 2469 CHECK_JNI_EXCEPTION(env); 2470 for (int i = 0, n = method_count; i < n; ++i) { 2471 // Skip dummy entries 2472 if (method_array[i].fnPtr == nullptr) continue; 2473 if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { 2474 jthrowable throwable_obj = env->ExceptionOccurred(); 2475 if (throwable_obj != nullptr) { 2476 env->ExceptionClear(); 2477 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) { 2478 // NoSuchMethodError is thrown when a method can't be found or a method is not native. 2479 // Ignoring the exception since it is not preventing use of other WhiteBox methods. 2480 tty->print_cr("Warning: 'NoSuchMethodError' on register of %s::%s%s", 2481 klass_name, method_array[i].name, method_array[i].signature); 2482 } 2483 } else { 2484 // Registration failed unexpectedly. 2485 tty->print_cr("Warning: unexpected error on register of %s::%s%s. All methods will be unregistered", 2486 klass_name, method_array[i].name, method_array[i].signature); 2487 env->UnregisterNatives(wbclass); 2488 break; 2489 } 2490 } 2491 } 2492 } 2493 2494 WB_ENTRY(jint, WB_AddCompilerDirective(JNIEnv* env, jobject o, jstring compDirect)) 2495 // can't be in VM when we call JNI 2496 ThreadToNativeFromVM ttnfv(thread); 2497 const char* dir = env->GetStringUTFChars(compDirect, nullptr); 2498 CHECK_JNI_EXCEPTION_(env, 0); 2499 int ret; 2500 { 2501 ThreadInVMfromNative ttvfn(thread); // back to VM 2502 ret = DirectivesParser::parse_string(dir, tty); 2503 } 2504 env->ReleaseStringUTFChars(compDirect, dir); 2505 // -1 for error parsing directive. Return 0 as number of directives added. 2506 if (ret == -1) { 2507 ret = 0; 2508 } 2509 return (jint) ret; 2510 WB_END 2511 2512 WB_ENTRY(void, WB_RemoveCompilerDirective(JNIEnv* env, jobject o, jint count)) 2513 DirectivesStack::pop(count); 2514 WB_END 2515 2516 // Checks that the library libfile has the noexecstack bit set. 2517 WB_ENTRY(jboolean, WB_CheckLibSpecifiesNoexecstack(JNIEnv* env, jobject o, jstring libfile)) 2518 jboolean ret = false; 2519 #ifdef LINUX 2520 // Can't be in VM when we call JNI. 2521 ThreadToNativeFromVM ttnfv(thread); 2522 const char* lf = env->GetStringUTFChars(libfile, nullptr); 2523 CHECK_JNI_EXCEPTION_(env, 0); 2524 ret = (jboolean) ElfFile::specifies_noexecstack(lf); 2525 env->ReleaseStringUTFChars(libfile, lf); 2526 #endif 2527 return ret; 2528 WB_END 2529 2530 WB_ENTRY(jboolean, WB_IsContainerized(JNIEnv* env, jobject o)) 2531 LINUX_ONLY(return OSContainer::is_containerized();) 2532 return false; 2533 WB_END 2534 2535 // Physical memory of the host machine (including containers) 2536 WB_ENTRY(jlong, WB_HostPhysicalMemory(JNIEnv* env, jobject o)) 2537 LINUX_ONLY(return os::Linux::physical_memory();) 2538 return os::physical_memory(); 2539 WB_END 2540 2541 // Physical swap of the host machine (including containers), Linux only. 2542 WB_ENTRY(jlong, WB_HostPhysicalSwap(JNIEnv* env, jobject o)) 2543 LINUX_ONLY(return (jlong)os::Linux::host_swap();) 2544 return -1; // Not used/implemented on other platforms 2545 WB_END 2546 2547 WB_ENTRY(jint, WB_ValidateCgroup(JNIEnv* env, 2548 jobject o, 2549 jstring proc_cgroups, 2550 jstring proc_self_cgroup, 2551 jstring proc_self_mountinfo)) 2552 jint ret = 0; 2553 #ifdef LINUX 2554 ThreadToNativeFromVM ttnfv(thread); 2555 const char* p_cgroups = env->GetStringUTFChars(proc_cgroups, nullptr); 2556 CHECK_JNI_EXCEPTION_(env, 0); 2557 const char* p_s_cgroup = env->GetStringUTFChars(proc_self_cgroup, nullptr); 2558 CHECK_JNI_EXCEPTION_(env, 0); 2559 const char* p_s_mountinfo = env->GetStringUTFChars(proc_self_mountinfo, nullptr); 2560 CHECK_JNI_EXCEPTION_(env, 0); 2561 u1 cg_type_flags = 0; 2562 // This sets cg_type_flags 2563 WhiteBox::validate_cgroup(p_cgroups, p_s_cgroup, p_s_mountinfo, &cg_type_flags); 2564 ret = (jint)cg_type_flags; 2565 env->ReleaseStringUTFChars(proc_cgroups, p_cgroups); 2566 env->ReleaseStringUTFChars(proc_self_cgroup, p_s_cgroup); 2567 env->ReleaseStringUTFChars(proc_self_mountinfo, p_s_mountinfo); 2568 #endif 2569 return ret; 2570 WB_END 2571 2572 WB_ENTRY(void, WB_PrintOsInfo(JNIEnv* env, jobject o)) 2573 os::print_os_info(tty); 2574 WB_END 2575 2576 // Elf decoder 2577 WB_ENTRY(void, WB_DisableElfSectionCache(JNIEnv* env)) 2578 #if !defined(_WINDOWS) && !defined(__APPLE__) && !defined(_AIX) 2579 ElfFile::_do_not_cache_elf_section = true; 2580 #endif 2581 WB_END 2582 2583 WB_ENTRY(jlong, WB_ResolvedMethodItemsCount(JNIEnv* env, jobject o)) 2584 return (jlong) ResolvedMethodTable::items_count(); 2585 WB_END 2586 2587 WB_ENTRY(jint, WB_ProtectionDomainRemovedCount(JNIEnv* env, jobject o)) 2588 return (jint) ProtectionDomainCacheTable::removed_entries_count(); 2589 WB_END 2590 2591 WB_ENTRY(jint, WB_GetKlassMetadataSize(JNIEnv* env, jobject wb, jclass mirror)) 2592 Klass* k = java_lang_Class::as_Klass(JNIHandles::resolve(mirror)); 2593 // Return size in bytes. 2594 return k->size() * wordSize; 2595 WB_END 2596 2597 // See test/hotspot/jtreg/runtime/Thread/ThreadObjAccessAtExit.java. 2598 // It explains how the thread's priority field is used for test state coordination. 2599 // 2600 WB_ENTRY(void, WB_CheckThreadObjOfTerminatingThread(JNIEnv* env, jobject wb, jobject target_handle)) 2601 oop target_oop = JNIHandles::resolve_non_null(target_handle); 2602 jlong tid = java_lang_Thread::thread_id(target_oop); 2603 JavaThread* target = java_lang_Thread::thread(target_oop); 2604 2605 // Grab a ThreadsListHandle to protect the target thread whilst terminating 2606 ThreadsListHandle tlh; 2607 2608 // Look up the target thread by tid to ensure it is present 2609 JavaThread* t = tlh.list()->find_JavaThread_from_java_tid(tid); 2610 if (t == nullptr) { 2611 THROW_MSG(vmSymbols::java_lang_RuntimeException(), "Target thread not found in ThreadsList!"); 2612 } 2613 2614 tty->print_cr("WB_CheckThreadObjOfTerminatingThread: target thread is protected"); 2615 // Allow target to terminate by boosting priority 2616 java_lang_Thread::set_priority(t->threadObj(), ThreadPriority(NormPriority + 1)); 2617 2618 // Now wait for the target to terminate 2619 while (!target->is_terminated()) { 2620 ThreadBlockInVM tbivm(thread); // just in case target is involved in a safepoint 2621 os::naked_short_sleep(0); 2622 } 2623 2624 tty->print_cr("WB_CheckThreadObjOfTerminatingThread: target thread is terminated"); 2625 2626 // Now release the GC inducing thread - we have to re-resolve the external oop that 2627 // was passed in as GC may have occurred and we don't know if we can trust t->threadObj() now. 2628 oop original = JNIHandles::resolve_non_null(target_handle); 2629 java_lang_Thread::set_priority(original, ThreadPriority(NormPriority + 2)); 2630 2631 tty->print_cr("WB_CheckThreadObjOfTerminatingThread: GC has been initiated - checking threadObj:"); 2632 2633 // The Java code should be creating garbage and triggering GC, which would potentially move 2634 // the threadObj oop. If the exiting thread is properly protected then its threadObj should 2635 // remain valid and equal to our initial target_handle. Loop a few times to give GC a chance to 2636 // kick in. 2637 for (int i = 0; i < 5; i++) { 2638 oop original = JNIHandles::resolve_non_null(target_handle); 2639 oop current = t->threadObj(); 2640 if (original != current) { 2641 tty->print_cr("WB_CheckThreadObjOfTerminatingThread: failed comparison on iteration %d", i); 2642 THROW_MSG(vmSymbols::java_lang_RuntimeException(), "Target thread oop has changed!"); 2643 } else { 2644 tty->print_cr("WB_CheckThreadObjOfTerminatingThread: successful comparison on iteration %d", i); 2645 ThreadBlockInVM tbivm(thread); 2646 os::naked_short_sleep(50); 2647 } 2648 } 2649 WB_END 2650 2651 WB_ENTRY(void, WB_VerifyFrames(JNIEnv* env, jobject wb, jboolean log, jboolean update_map)) 2652 ResourceMark rm; // for verify 2653 stringStream st; 2654 for (StackFrameStream fst(JavaThread::current(), update_map, true); !fst.is_done(); fst.next()) { 2655 frame* current_frame = fst.current(); 2656 if (log) { 2657 current_frame->print_value_on(&st, nullptr); 2658 } 2659 current_frame->verify(fst.register_map()); 2660 } 2661 if (log) { 2662 tty->print_cr("[WhiteBox::VerifyFrames] Walking Frames"); 2663 tty->print_raw(st.freeze()); 2664 tty->print_cr("[WhiteBox::VerifyFrames] Done"); 2665 } 2666 WB_END 2667 2668 WB_ENTRY(jboolean, WB_IsJVMTIIncluded(JNIEnv* env, jobject wb)) 2669 #if INCLUDE_JVMTI 2670 return JNI_TRUE; 2671 #else 2672 return JNI_FALSE; 2673 #endif 2674 WB_END 2675 2676 WB_ENTRY(void, WB_WaitUnsafe(JNIEnv* env, jobject wb, jint time)) 2677 os::naked_short_sleep(time); 2678 WB_END 2679 2680 WB_ENTRY(jstring, WB_GetLibcName(JNIEnv* env, jobject o)) 2681 ThreadToNativeFromVM ttn(thread); 2682 jstring info_string = env->NewStringUTF(XSTR(LIBC)); 2683 CHECK_JNI_EXCEPTION_(env, nullptr); 2684 return info_string; 2685 WB_END 2686 2687 WB_ENTRY(void, WB_LockCritical(JNIEnv* env, jobject wb)) 2688 GCLocker::lock_critical(thread); 2689 WB_END 2690 2691 WB_ENTRY(void, WB_UnlockCritical(JNIEnv* env, jobject wb)) 2692 GCLocker::unlock_critical(thread); 2693 WB_END 2694 2695 WB_ENTRY(void, WB_PinObject(JNIEnv* env, jobject wb, jobject o)) 2696 #if INCLUDE_G1GC 2697 if (!UseG1GC) { 2698 ShouldNotReachHere(); 2699 return; 2700 } 2701 oop obj = JNIHandles::resolve(o); 2702 G1CollectedHeap::heap()->pin_object(thread, obj); 2703 #else 2704 ShouldNotReachHere(); 2705 #endif // INCLUDE_G1GC 2706 WB_END 2707 2708 WB_ENTRY(void, WB_UnpinObject(JNIEnv* env, jobject wb, jobject o)) 2709 #if INCLUDE_G1GC 2710 if (!UseG1GC) { 2711 ShouldNotReachHere(); 2712 return; 2713 } 2714 oop obj = JNIHandles::resolve(o); 2715 G1CollectedHeap::heap()->unpin_object(thread, obj); 2716 #else 2717 ShouldNotReachHere(); 2718 #endif // INCLUDE_G1GC 2719 WB_END 2720 2721 WB_ENTRY(jboolean, WB_SetVirtualThreadsNotifyJvmtiMode(JNIEnv* env, jobject wb, jboolean enable)) 2722 if (!Continuations::enabled()) { 2723 tty->print_cr("WB error: must be Continuations::enabled()!"); 2724 return JNI_FALSE; 2725 } 2726 jboolean result = false; 2727 #if INCLUDE_JVMTI 2728 if (enable) { 2729 result = JvmtiEnvBase::enable_virtual_threads_notify_jvmti(); 2730 } else { 2731 result = JvmtiEnvBase::disable_virtual_threads_notify_jvmti(); 2732 } 2733 #endif 2734 return result; 2735 WB_END 2736 2737 WB_ENTRY(void, WB_PreTouchMemory(JNIEnv* env, jobject wb, jlong addr, jlong size)) 2738 void* const from = (void*)addr; 2739 void* const to = (void*)(addr + size); 2740 if (from > to) { 2741 os::pretouch_memory(from, to, os::vm_page_size()); 2742 } 2743 WB_END 2744 2745 WB_ENTRY(void, WB_CleanMetaspaces(JNIEnv* env, jobject target)) 2746 ClassLoaderDataGraph::safepoint_and_clean_metaspaces(); 2747 WB_END 2748 2749 #define CC (char*) 2750 2751 static JNINativeMethod methods[] = { 2752 {CC"getObjectAddress0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, 2753 {CC"getObjectSize0", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, 2754 {CC"isObjectInOldGen0", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, 2755 {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, 2756 {CC"getVMPageSize", CC"()I", (void*)&WB_GetVMPageSize }, 2757 {CC"getVMAllocationGranularity", CC"()J", (void*)&WB_GetVMAllocationGranularity }, 2758 {CC"getVMLargePageSize", CC"()J", (void*)&WB_GetVMLargePageSize}, 2759 {CC"getHeapSpaceAlignment", CC"()J", (void*)&WB_GetHeapSpaceAlignment}, 2760 {CC"getHeapAlignment", CC"()J", (void*)&WB_GetHeapAlignment}, 2761 {CC"countAliveClasses0", CC"(Ljava/lang/String;)I", (void*)&WB_CountAliveClasses }, 2762 {CC"getSymbolRefcount", CC"(Ljava/lang/String;)I", (void*)&WB_GetSymbolRefcount }, 2763 {CC"parseCommandLine0", 2764 CC"(Ljava/lang/String;C[Ljdk/test/whitebox/parser/DiagnosticCommand;)[Ljava/lang/Object;", 2765 (void*) &WB_ParseCommandLine 2766 }, 2767 {CC"addToBootstrapClassLoaderSearch0", CC"(Ljava/lang/String;)V", 2768 (void*)&WB_AddToBootstrapClassLoaderSearch}, 2769 {CC"addToSystemClassLoaderSearch0", CC"(Ljava/lang/String;)V", 2770 (void*)&WB_AddToSystemClassLoaderSearch}, 2771 {CC"getCompressedOopsMaxHeapSize", CC"()J", 2772 (void*)&WB_GetCompressedOopsMaxHeapSize}, 2773 {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, 2774 {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, 2775 {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, 2776 #if INCLUDE_CDS 2777 {CC"getCDSOffsetForName0", CC"(Ljava/lang/String;)I", (void*)&WB_GetCDSOffsetForName}, 2778 {CC"getCDSConstantForName0", CC"(Ljava/lang/String;)I", (void*)&WB_GetCDSConstantForName}, 2779 #endif 2780 #if INCLUDE_G1GC 2781 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, 2782 {CC"g1CompletedConcurrentMarkCycles", CC"()I", (void*)&WB_G1CompletedConcurrentMarkCycles}, 2783 {CC"g1IsHumongous0", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, 2784 {CC"g1BelongsToHumongousRegion0", CC"(J)Z", (void*)&WB_G1BelongsToHumongousRegion}, 2785 {CC"g1BelongsToFreeRegion0", CC"(J)Z", (void*)&WB_G1BelongsToFreeRegion}, 2786 {CC"g1NumMaxRegions", CC"()J", (void*)&WB_G1NumMaxRegions }, 2787 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, 2788 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, 2789 {CC"g1HasRegionsToUncommit", CC"()Z", (void*)&WB_G1HasRegionsToUncommit}, 2790 {CC"g1AuxiliaryMemoryUsage", CC"()Ljava/lang/management/MemoryUsage;", 2791 (void*)&WB_G1AuxiliaryMemoryUsage }, 2792 {CC"g1ActiveMemoryNodeCount", CC"()I", (void*)&WB_G1ActiveMemoryNodeCount }, 2793 {CC"g1MemoryNodeIds", CC"()[I", (void*)&WB_G1MemoryNodeIds }, 2794 {CC"g1GetMixedGCInfo", CC"(I)[J", (void*)&WB_G1GetMixedGCInfo }, 2795 #endif // INCLUDE_G1GC 2796 #if INCLUDE_PARALLELGC 2797 {CC"psVirtualSpaceAlignment",CC"()J", (void*)&WB_PSVirtualSpaceAlignment}, 2798 {CC"psHeapGenerationAlignment",CC"()J", (void*)&WB_PSHeapGenerationAlignment}, 2799 #endif 2800 {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, 2801 {CC"NMTMallocWithPseudoStack", CC"(JI)J", (void*)&WB_NMTMallocWithPseudoStack}, 2802 {CC"NMTMallocWithPseudoStackAndType", CC"(JII)J", (void*)&WB_NMTMallocWithPseudoStackAndType}, 2803 {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, 2804 {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, 2805 {CC"NMTAttemptReserveMemoryAt", CC"(JJ)J", (void*)&WB_NMTAttemptReserveMemoryAt }, 2806 {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, 2807 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, 2808 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, 2809 {CC"NMTGetHashSize", CC"()I", (void*)&WB_NMTGetHashSize }, 2810 {CC"NMTNewArena", CC"(J)J", (void*)&WB_NMTNewArena }, 2811 {CC"NMTFreeArena", CC"(J)V", (void*)&WB_NMTFreeArena }, 2812 {CC"NMTArenaMalloc", CC"(JJ)V", (void*)&WB_NMTArenaMalloc }, 2813 {CC"deoptimizeFrames", CC"(Z)I", (void*)&WB_DeoptimizeFrames }, 2814 {CC"isFrameDeoptimized", CC"(I)Z", (void*)&WB_IsFrameDeoptimized}, 2815 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, 2816 {CC"deoptimizeMethod0", CC"(Ljava/lang/reflect/Executable;Z)I", 2817 (void*)&WB_DeoptimizeMethod }, 2818 {CC"isMethodCompiled0", CC"(Ljava/lang/reflect/Executable;Z)Z", 2819 (void*)&WB_IsMethodCompiled }, 2820 {CC"isMethodCompilable0", CC"(Ljava/lang/reflect/Executable;IZ)Z", 2821 (void*)&WB_IsMethodCompilable}, 2822 {CC"isMethodQueuedForCompilation0", 2823 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, 2824 {CC"isIntrinsicAvailable0", 2825 CC"(Ljava/lang/reflect/Executable;Ljava/lang/reflect/Executable;I)Z", 2826 (void*)&WB_IsIntrinsicAvailable}, 2827 {CC"makeMethodNotCompilable0", 2828 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable}, 2829 {CC"testSetDontInlineMethod0", 2830 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, 2831 {CC"getMethodCompilationLevel0", 2832 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel}, 2833 {CC"getMethodDecompileCount0", 2834 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodDecompileCount}, 2835 {CC"getMethodTrapCount0", 2836 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I", 2837 (void*)&WB_GetMethodTrapCount}, 2838 {CC"getDeoptCount0", 2839 CC"(Ljava/lang/String;Ljava/lang/String;)I", (void*)&WB_GetDeoptCount}, 2840 {CC"getMethodEntryBci0", 2841 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, 2842 {CC"getCompileQueueSize", 2843 CC"(I)I", (void*)&WB_GetCompileQueueSize}, 2844 {CC"testSetForceInlineMethod0", 2845 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, 2846 {CC"enqueueMethodForCompilation0", 2847 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, 2848 {CC"enqueueInitializerForCompilation0", 2849 CC"(Ljava/lang/Class;I)Z", (void*)&WB_EnqueueInitializerForCompilation}, 2850 {CC"markMethodProfiled", 2851 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_MarkMethodProfiled}, 2852 {CC"clearMethodState0", 2853 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, 2854 {CC"lockCompilation", CC"()V", (void*)&WB_LockCompilation}, 2855 {CC"unlockCompilation", CC"()V", (void*)&WB_UnlockCompilation}, 2856 {CC"matchesMethod", 2857 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I", 2858 (void*)&WB_MatchesMethod}, 2859 {CC"matchesInline", 2860 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)I", 2861 (void*)&WB_MatchesInline}, 2862 {CC"shouldPrintAssembly", 2863 CC"(Ljava/lang/reflect/Executable;I)Z", 2864 (void*)&WB_ShouldPrintAssembly}, 2865 2866 {CC"isConstantVMFlag", CC"(Ljava/lang/String;)Z", (void*)&WB_IsConstantVMFlag}, 2867 {CC"isDefaultVMFlag", CC"(Ljava/lang/String;)Z", (void*)&WB_IsDefaultVMFlag}, 2868 {CC"isLockedVMFlag", CC"(Ljava/lang/String;)Z", (void*)&WB_IsLockedVMFlag}, 2869 {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag}, 2870 {CC"setIntVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntVMFlag}, 2871 {CC"setUintVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintVMFlag}, 2872 {CC"setIntxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag}, 2873 {CC"setUintxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag}, 2874 {CC"setUint64VMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag}, 2875 {CC"setSizeTVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetSizeTVMFlag}, 2876 {CC"setDoubleVMFlag", CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag}, 2877 {CC"setStringVMFlag", CC"(Ljava/lang/String;Ljava/lang/String;)V", 2878 (void*)&WB_SetStringVMFlag}, 2879 {CC"getBooleanVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Boolean;", 2880 (void*)&WB_GetBooleanVMFlag}, 2881 {CC"getIntVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2882 (void*)&WB_GetIntVMFlag}, 2883 {CC"getUintVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2884 (void*)&WB_GetUintVMFlag}, 2885 {CC"getIntxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2886 (void*)&WB_GetIntxVMFlag}, 2887 {CC"getUintxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2888 (void*)&WB_GetUintxVMFlag}, 2889 {CC"getUint64VMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2890 (void*)&WB_GetUint64VMFlag}, 2891 {CC"getSizeTVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", 2892 (void*)&WB_GetSizeTVMFlag}, 2893 {CC"getDoubleVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Double;", 2894 (void*)&WB_GetDoubleVMFlag}, 2895 {CC"getStringVMFlag", CC"(Ljava/lang/String;)Ljava/lang/String;", 2896 (void*)&WB_GetStringVMFlag}, 2897 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, 2898 {CC"fullGC", CC"()V", (void*)&WB_FullGC }, 2899 {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, 2900 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, 2901 {CC"allocateMetaspace", 2902 CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, 2903 {CC"incMetaspaceCapacityUntilGC", CC"(J)J", (void*)&WB_IncMetaspaceCapacityUntilGC }, 2904 {CC"metaspaceCapacityUntilGC", CC"()J", (void*)&WB_MetaspaceCapacityUntilGC }, 2905 {CC"metaspaceSharedRegionAlignment", CC"()J", (void*)&WB_MetaspaceSharedRegionAlignment }, 2906 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, 2907 {CC"getNMethod0", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", 2908 (void*)&WB_GetNMethod }, 2909 {CC"allocateCodeBlob", CC"(II)J", (void*)&WB_AllocateCodeBlob }, 2910 {CC"freeCodeBlob", CC"(J)V", (void*)&WB_FreeCodeBlob }, 2911 {CC"getCodeHeapEntries", CC"(I)[Ljava/lang/Object;",(void*)&WB_GetCodeHeapEntries }, 2912 {CC"getCompilationActivityMode", 2913 CC"()I", (void*)&WB_GetCompilationActivityMode}, 2914 {CC"getMethodData0", CC"(Ljava/lang/reflect/Executable;)J", 2915 (void*)&WB_GetMethodData }, 2916 {CC"getCodeBlob", CC"(J)[Ljava/lang/Object;",(void*)&WB_GetCodeBlob }, 2917 {CC"getThreadStackSize", CC"()J", (void*)&WB_GetThreadStackSize }, 2918 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize }, 2919 {CC"DefineModule", CC"(Ljava/lang/Object;ZLjava/lang/String;Ljava/lang/String;[Ljava/lang/Object;)V", 2920 (void*)&WB_DefineModule }, 2921 {CC"AddModuleExports", CC"(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V", 2922 (void*)&WB_AddModuleExports }, 2923 {CC"AddReadsModule", CC"(Ljava/lang/Object;Ljava/lang/Object;)V", 2924 (void*)&WB_AddReadsModule }, 2925 {CC"AddModuleExportsToAllUnnamed", CC"(Ljava/lang/Object;Ljava/lang/String;)V", 2926 (void*)&WB_AddModuleExportsToAllUnnamed }, 2927 {CC"AddModuleExportsToAll", CC"(Ljava/lang/Object;Ljava/lang/String;)V", 2928 (void*)&WB_AddModuleExportsToAll }, 2929 {CC"deflateIdleMonitors", CC"()Z", (void*)&WB_DeflateIdleMonitors }, 2930 {CC"isMonitorInflated0", CC"(Ljava/lang/Object;)Z", (void*)&WB_IsMonitorInflated }, 2931 {CC"getLockStackCapacity", CC"()I", (void*)&WB_getLockStackCapacity }, 2932 {CC"supportsRecursiveLightweightLocking", CC"()Z", (void*)&WB_supportsRecursiveLightweightLocking }, 2933 {CC"forceSafepoint", CC"()V", (void*)&WB_ForceSafepoint }, 2934 {CC"forceClassLoaderStatsSafepoint", CC"()V", (void*)&WB_ForceClassLoaderStatsSafepoint }, 2935 {CC"getConstantPool0", CC"(Ljava/lang/Class;)J", (void*)&WB_GetConstantPool }, 2936 {CC"getResolvedReferences0", CC"(Ljava/lang/Class;)[Ljava/lang/Object;", (void*)&WB_GetResolvedReferences}, 2937 {CC"encodeConstantPoolIndyIndex0", 2938 CC"(I)I", (void*)&WB_ConstantPoolEncodeIndyIndex}, 2939 {CC"getObjectsViaKlassOopMaps0", 2940 CC"(Ljava/lang/Object;)[Ljava/lang/Object;", (void*)&WB_getObjectsViaKlassOopMaps}, 2941 {CC"getObjectsViaOopIterator0", 2942 CC"(Ljava/lang/Object;)[Ljava/lang/Object;",(void*)&WB_getObjectsViaOopIterator}, 2943 {CC"getObjectsViaFrameOopIterator", 2944 CC"(I)[Ljava/lang/Object;", (void*)&WB_getObjectsViaFrameOopIterator}, 2945 {CC"getFieldEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getFieldEntriesLength}, 2946 {CC"getFieldCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getFieldCPIndex}, 2947 {CC"getMethodEntriesLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getMethodEntriesLength}, 2948 {CC"getMethodCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getMethodCPIndex}, 2949 {CC"getIndyInfoLength0", CC"(Ljava/lang/Class;)I", (void*)&WB_getIndyInfoLength}, 2950 {CC"getIndyCPIndex0", CC"(Ljava/lang/Class;I)I", (void*)&WB_getIndyCPIndex}, 2951 {CC"printClasses0", CC"(Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printClasses}, 2952 {CC"printMethods0", CC"(Ljava/lang/String;Ljava/lang/String;I)Ljava/lang/String;", (void*)&WB_printMethods}, 2953 {CC"getMethodBooleanOption", 2954 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Boolean;", 2955 (void*)&WB_GetMethodBooleaneOption}, 2956 {CC"getMethodIntxOption", 2957 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;", 2958 (void*)&WB_GetMethodIntxOption}, 2959 {CC"getMethodUintxOption", 2960 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Long;", 2961 (void*)&WB_GetMethodUintxOption}, 2962 {CC"getMethodDoubleOption", 2963 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/Double;", 2964 (void*)&WB_GetMethodDoubleOption}, 2965 {CC"getMethodStringOption", 2966 CC"(Ljava/lang/reflect/Executable;Ljava/lang/String;)Ljava/lang/String;", 2967 (void*)&WB_GetMethodStringOption}, 2968 {CC"getDefaultArchivePath", CC"()Ljava/lang/String;", 2969 (void*)&WB_GetDefaultArchivePath}, 2970 {CC"getCDSGenericHeaderMinVersion", CC"()I", (void*)&WB_GetCDSGenericHeaderMinVersion}, 2971 {CC"getCurrentCDSVersion", CC"()I", (void*)&WB_GetCDSCurrentVersion}, 2972 {CC"isSharingEnabled", CC"()Z", (void*)&WB_IsSharingEnabled}, 2973 {CC"isSharedInternedString", CC"(Ljava/lang/String;)Z", (void*)&WB_IsSharedInternedString }, 2974 {CC"isSharedClass", CC"(Ljava/lang/Class;)Z", (void*)&WB_IsSharedClass }, 2975 {CC"areSharedStringsMapped", CC"()Z", (void*)&WB_AreSharedStringsMapped }, 2976 {CC"linkClass", CC"(Ljava/lang/Class;)V", (void*)&WB_LinkClass}, 2977 {CC"areOpenArchiveHeapObjectsMapped", CC"()Z", (void*)&WB_AreOpenArchiveHeapObjectsMapped}, 2978 {CC"isCDSIncluded", CC"()Z", (void*)&WB_IsCDSIncluded }, 2979 {CC"isJFRIncluded", CC"()Z", (void*)&WB_IsJFRIncluded }, 2980 {CC"isDTraceIncluded", CC"()Z", (void*)&WB_IsDTraceIncluded }, 2981 {CC"hasLibgraal", CC"()Z", (void*)&WB_HasLibgraal }, 2982 {CC"isC2OrJVMCIIncluded", CC"()Z", (void*)&WB_isC2OrJVMCIIncluded }, 2983 {CC"isJVMCISupportedByGC", CC"()Z", (void*)&WB_IsJVMCISupportedByGC}, 2984 {CC"canWriteJavaHeapArchive", CC"()Z", (void*)&WB_CanWriteJavaHeapArchive }, 2985 {CC"cdsMemoryMappingFailed", CC"()Z", (void*)&WB_CDSMemoryMappingFailed }, 2986 2987 {CC"clearInlineCaches0", CC"(Z)V", (void*)&WB_ClearInlineCaches }, 2988 {CC"handshakeReadMonitors", CC"(Ljava/lang/Thread;)Z", (void*)&WB_HandshakeReadMonitors }, 2989 {CC"handshakeWalkStack", CC"(Ljava/lang/Thread;Z)I", (void*)&WB_HandshakeWalkStack }, 2990 {CC"asyncHandshakeWalkStack", CC"(Ljava/lang/Thread;)V", (void*)&WB_AsyncHandshakeWalkStack }, 2991 {CC"lockAndBlock", CC"(Z)V", (void*)&WB_LockAndBlock}, 2992 {CC"checkThreadObjOfTerminatingThread", CC"(Ljava/lang/Thread;)V", (void*)&WB_CheckThreadObjOfTerminatingThread }, 2993 {CC"verifyFrames", CC"(ZZ)V", (void*)&WB_VerifyFrames }, 2994 {CC"addCompilerDirective", CC"(Ljava/lang/String;)I", 2995 (void*)&WB_AddCompilerDirective }, 2996 {CC"removeCompilerDirective", CC"(I)V", (void*)&WB_RemoveCompilerDirective }, 2997 {CC"isGCSupported", CC"(I)Z", (void*)&WB_IsGCSupported}, 2998 {CC"isGCSupportedByJVMCICompiler", CC"(I)Z", (void*)&WB_IsGCSupportedByJVMCICompiler}, 2999 {CC"isGCSelected", CC"(I)Z", (void*)&WB_IsGCSelected}, 3000 {CC"isGCSelectedErgonomically", CC"()Z", (void*)&WB_IsGCSelectedErgonomically}, 3001 {CC"supportsConcurrentGCBreakpoints", CC"()Z", (void*)&WB_SupportsConcurrentGCBreakpoints}, 3002 {CC"concurrentGCAcquireControl0", CC"()V", (void*)&WB_ConcurrentGCAcquireControl}, 3003 {CC"concurrentGCReleaseControl0", CC"()V", (void*)&WB_ConcurrentGCReleaseControl}, 3004 {CC"concurrentGCRunToIdle0", CC"()V", (void*)&WB_ConcurrentGCRunToIdle}, 3005 {CC"concurrentGCRunTo0", CC"(Ljava/lang/String;)Z", 3006 (void*)&WB_ConcurrentGCRunTo}, 3007 {CC"checkLibSpecifiesNoexecstack", CC"(Ljava/lang/String;)Z", 3008 (void*)&WB_CheckLibSpecifiesNoexecstack}, 3009 {CC"isContainerized", CC"()Z", (void*)&WB_IsContainerized }, 3010 {CC"validateCgroup", 3011 CC"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I", 3012 (void*)&WB_ValidateCgroup }, 3013 {CC"hostPhysicalMemory", CC"()J", (void*)&WB_HostPhysicalMemory }, 3014 {CC"hostPhysicalSwap", CC"()J", (void*)&WB_HostPhysicalSwap }, 3015 {CC"printOsInfo", CC"()V", (void*)&WB_PrintOsInfo }, 3016 {CC"disableElfSectionCache", CC"()V", (void*)&WB_DisableElfSectionCache }, 3017 {CC"resolvedMethodItemsCount", CC"()J", (void*)&WB_ResolvedMethodItemsCount }, 3018 {CC"protectionDomainRemovedCount", CC"()I", (void*)&WB_ProtectionDomainRemovedCount }, 3019 {CC"getKlassMetadataSize", CC"(Ljava/lang/Class;)I",(void*)&WB_GetKlassMetadataSize}, 3020 3021 {CC"createMetaspaceTestContext", CC"(JJ)J", (void*)&WB_CreateMetaspaceTestContext}, 3022 {CC"destroyMetaspaceTestContext", CC"(J)V", (void*)&WB_DestroyMetaspaceTestContext}, 3023 {CC"purgeMetaspaceTestContext", CC"(J)V", (void*)&WB_PurgeMetaspaceTestContext}, 3024 {CC"printMetaspaceTestContext", CC"(J)V", (void*)&WB_PrintMetaspaceTestContext}, 3025 {CC"getTotalCommittedWordsInMetaspaceTestContext", CC"(J)J",(void*)&WB_GetTotalCommittedWordsInMetaspaceTestContext}, 3026 {CC"getTotalUsedWordsInMetaspaceTestContext", CC"(J)J", (void*)&WB_GetTotalUsedWordsInMetaspaceTestContext}, 3027 {CC"createArenaInTestContext", CC"(JZ)J", (void*)&WB_CreateArenaInTestContext}, 3028 {CC"destroyMetaspaceTestArena", CC"(J)V", (void*)&WB_DestroyMetaspaceTestArena}, 3029 {CC"allocateFromMetaspaceTestArena", CC"(JJ)J", (void*)&WB_AllocateFromMetaspaceTestArena}, 3030 {CC"deallocateToMetaspaceTestArena", CC"(JJJ)V", (void*)&WB_DeallocateToMetaspaceTestArena}, 3031 {CC"maxMetaspaceAllocationSize", CC"()J", (void*)&WB_GetMaxMetaspaceAllocationSize}, 3032 3033 {CC"isJVMTIIncluded", CC"()Z", (void*)&WB_IsJVMTIIncluded}, 3034 {CC"waitUnsafe", CC"(I)V", (void*)&WB_WaitUnsafe}, 3035 {CC"getLibcName", CC"()Ljava/lang/String;", (void*)&WB_GetLibcName}, 3036 3037 {CC"lockCritical", CC"()V", (void*)&WB_LockCritical}, 3038 {CC"unlockCritical", CC"()V", (void*)&WB_UnlockCritical}, 3039 {CC"pinObject", CC"(Ljava/lang/Object;)V", (void*)&WB_PinObject}, 3040 {CC"unpinObject", CC"(Ljava/lang/Object;)V", (void*)&WB_UnpinObject}, 3041 {CC"setVirtualThreadsNotifyJvmtiMode", CC"(Z)Z", (void*)&WB_SetVirtualThreadsNotifyJvmtiMode}, 3042 {CC"preTouchMemory", CC"(JJ)V", (void*)&WB_PreTouchMemory}, 3043 {CC"cleanMetaspaces", CC"()V", (void*)&WB_CleanMetaspaces}, 3044 }; 3045 3046 3047 #undef CC 3048 3049 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) 3050 { 3051 if (WhiteBoxAPI) { 3052 // Make sure that wbclass is loaded by the null classloader 3053 InstanceKlass* ik = InstanceKlass::cast(java_lang_Class::as_Klass(JNIHandles::resolve(wbclass))); 3054 Handle loader(THREAD, ik->class_loader()); 3055 if (loader.is_null()) { 3056 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0])); 3057 WhiteBox::set_used(); 3058 } 3059 } 3060 } 3061 JVM_END