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