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