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