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