Wed, 27 Aug 2014 08:19:12 -0400
8046598: Scalable Native memory tracking development
Summary: Enhance scalability of native memory tracking
Reviewed-by: coleenp, ctornqvi, gtriantafill
mgerdin@3619 | 1 | /* |
iignatyev@6525 | 2 | * Copyright (c) 2012, 2014, Oracle and/or its affiliates. All rights reserved. |
mgerdin@3619 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
mgerdin@3619 | 4 | * |
mgerdin@3619 | 5 | * This code is free software; you can redistribute it and/or modify it |
mgerdin@3619 | 6 | * under the terms of the GNU General Public License version 2 only, as |
mgerdin@3619 | 7 | * published by the Free Software Foundation. |
mgerdin@3619 | 8 | * |
mgerdin@3619 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
mgerdin@3619 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
mgerdin@3619 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
mgerdin@3619 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
mgerdin@3619 | 13 | * accompanied this code). |
mgerdin@3619 | 14 | * |
mgerdin@3619 | 15 | * You should have received a copy of the GNU General Public License version |
mgerdin@3619 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
mgerdin@3619 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
mgerdin@3619 | 18 | * |
mgerdin@3619 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
mgerdin@3619 | 20 | * or visit www.oracle.com if you need additional information or have any |
mgerdin@3619 | 21 | * questions. |
mgerdin@3619 | 22 | * |
mgerdin@3619 | 23 | */ |
mgerdin@3619 | 24 | |
mgerdin@3619 | 25 | #include "precompiled.hpp" |
mgerdin@3619 | 26 | |
stefank@6992 | 27 | #include "memory/metadataFactory.hpp" |
mgerdin@3619 | 28 | #include "memory/universe.hpp" |
mgerdin@3619 | 29 | #include "oops/oop.inline.hpp" |
nloodin@3681 | 30 | |
nloodin@3681 | 31 | #include "classfile/symbolTable.hpp" |
coleenp@4037 | 32 | #include "classfile/classLoaderData.hpp" |
nloodin@3681 | 33 | |
mgerdin@3619 | 34 | #include "prims/whitebox.hpp" |
nloodin@3681 | 35 | #include "prims/wbtestmethods/parserTests.hpp" |
nloodin@3681 | 36 | |
tschatzl@5701 | 37 | #include "runtime/arguments.hpp" |
mgerdin@3619 | 38 | #include "runtime/interfaceSupport.hpp" |
mgerdin@3619 | 39 | #include "runtime/os.hpp" |
stefank@6992 | 40 | #include "utilities/array.hpp" |
mgerdin@3619 | 41 | #include "utilities/debug.hpp" |
jprovino@4542 | 42 | #include "utilities/macros.hpp" |
mikael@5174 | 43 | #include "utilities/exceptions.hpp" |
mgerdin@3619 | 44 | |
jprovino@4542 | 45 | #if INCLUDE_ALL_GCS |
tschatzl@7071 | 46 | #include "gc_implementation/parallelScavenge/parallelScavengeHeap.inline.hpp" |
mgerdin@3619 | 47 | #include "gc_implementation/g1/concurrentMark.hpp" |
mgerdin@3619 | 48 | #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
mgerdin@3619 | 49 | #include "gc_implementation/g1/heapRegionRemSet.hpp" |
jprovino@4542 | 50 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 51 | |
zgu@7074 | 52 | #if INCLUDE_NMT |
zgu@7074 | 53 | #include "services/mallocSiteTable.hpp" |
ctornqvi@4512 | 54 | #include "services/memTracker.hpp" |
zgu@7074 | 55 | #include "utilities/nativeCallStack.hpp" |
ctornqvi@4512 | 56 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 57 | |
iignatyev@4592 | 58 | #include "compiler/compileBroker.hpp" |
iignatyev@4908 | 59 | #include "runtime/compilationPolicy.hpp" |
iignatyev@4592 | 60 | |
drchase@6680 | 61 | PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC |
drchase@6680 | 62 | |
mgerdin@6078 | 63 | #define SIZE_T_MAX_VALUE ((size_t) -1) |
mgerdin@6078 | 64 | |
mgerdin@3619 | 65 | bool WhiteBox::_used = false; |
mgerdin@3619 | 66 | |
mgerdin@3619 | 67 | WB_ENTRY(jlong, WB_GetObjectAddress(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 68 | return (jlong)(void*)JNIHandles::resolve(obj); |
mgerdin@3619 | 69 | WB_END |
mgerdin@3619 | 70 | |
mgerdin@3619 | 71 | WB_ENTRY(jint, WB_GetHeapOopSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 72 | return heapOopSize; |
mgerdin@3619 | 73 | WB_END |
mgerdin@3619 | 74 | |
coleenp@4037 | 75 | |
coleenp@4037 | 76 | class WBIsKlassAliveClosure : public KlassClosure { |
coleenp@4037 | 77 | Symbol* _name; |
coleenp@4037 | 78 | bool _found; |
coleenp@4037 | 79 | public: |
coleenp@4037 | 80 | WBIsKlassAliveClosure(Symbol* name) : _name(name), _found(false) {} |
coleenp@4037 | 81 | |
coleenp@4037 | 82 | void do_klass(Klass* k) { |
coleenp@4037 | 83 | if (_found) return; |
coleenp@4037 | 84 | Symbol* ksym = k->name(); |
coleenp@4037 | 85 | if (ksym->fast_compare(_name) == 0) { |
coleenp@4037 | 86 | _found = true; |
coleenp@4037 | 87 | } |
coleenp@4037 | 88 | } |
coleenp@4037 | 89 | |
coleenp@4037 | 90 | bool found() const { |
coleenp@4037 | 91 | return _found; |
coleenp@4037 | 92 | } |
coleenp@4037 | 93 | }; |
coleenp@4037 | 94 | |
coleenp@4037 | 95 | WB_ENTRY(jboolean, WB_IsClassAlive(JNIEnv* env, jobject target, jstring name)) |
coleenp@4037 | 96 | Handle h_name = JNIHandles::resolve(name); |
coleenp@4037 | 97 | if (h_name.is_null()) return false; |
coleenp@4037 | 98 | Symbol* sym = java_lang_String::as_symbol(h_name, CHECK_false); |
coleenp@4037 | 99 | TempNewSymbol tsym(sym); // Make sure to decrement reference count on sym on return |
coleenp@4037 | 100 | |
coleenp@4037 | 101 | WBIsKlassAliveClosure closure(sym); |
coleenp@4037 | 102 | ClassLoaderDataGraph::classes_do(&closure); |
coleenp@4037 | 103 | |
coleenp@4037 | 104 | return closure.found(); |
coleenp@4037 | 105 | WB_END |
coleenp@4037 | 106 | |
tschatzl@5701 | 107 | WB_ENTRY(jlong, WB_GetCompressedOopsMaxHeapSize(JNIEnv* env, jobject o)) { |
tschatzl@5701 | 108 | return (jlong)Arguments::max_heap_for_compressed_oops(); |
tschatzl@5701 | 109 | } |
tschatzl@5701 | 110 | WB_END |
tschatzl@5701 | 111 | |
tschatzl@5073 | 112 | WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { |
tschatzl@5073 | 113 | CollectorPolicy * p = Universe::heap()->collector_policy(); |
tschatzl@5073 | 114 | gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " |
tschatzl@5073 | 115 | SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Min alignment "SIZE_FORMAT" Max alignment "SIZE_FORMAT, |
tschatzl@5073 | 116 | p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), |
jwilhelm@6085 | 117 | p->space_alignment(), p->heap_alignment()); |
tschatzl@5073 | 118 | } |
tschatzl@5073 | 119 | WB_END |
tschatzl@5073 | 120 | |
mgerdin@6078 | 121 | #ifndef PRODUCT |
mgerdin@6078 | 122 | // Forward declaration |
mgerdin@6078 | 123 | void TestReservedSpace_test(); |
mgerdin@6078 | 124 | void TestReserveMemorySpecial_test(); |
mgerdin@6078 | 125 | void TestVirtualSpace_test(); |
mgerdin@6078 | 126 | void TestMetaspaceAux_test(); |
mgerdin@6078 | 127 | #endif |
mgerdin@6078 | 128 | |
mgerdin@6078 | 129 | WB_ENTRY(void, WB_RunMemoryUnitTests(JNIEnv* env, jobject o)) |
mgerdin@6078 | 130 | #ifndef PRODUCT |
mgerdin@6078 | 131 | TestReservedSpace_test(); |
mgerdin@6078 | 132 | TestReserveMemorySpecial_test(); |
mgerdin@6078 | 133 | TestVirtualSpace_test(); |
mgerdin@6078 | 134 | TestMetaspaceAux_test(); |
mgerdin@6078 | 135 | #endif |
mgerdin@6078 | 136 | WB_END |
mgerdin@6078 | 137 | |
mgerdin@6078 | 138 | WB_ENTRY(void, WB_ReadFromNoaccessArea(JNIEnv* env, jobject o)) |
mgerdin@6078 | 139 | size_t granularity = os::vm_allocation_granularity(); |
mgerdin@6078 | 140 | ReservedHeapSpace rhs(100 * granularity, granularity, false, NULL); |
mgerdin@6078 | 141 | VirtualSpace vs; |
mgerdin@6078 | 142 | vs.initialize(rhs, 50 * granularity); |
mgerdin@6078 | 143 | |
mgerdin@6078 | 144 | //Check if constraints are complied |
mgerdin@6078 | 145 | if (!( UseCompressedOops && rhs.base() != NULL && |
mgerdin@6078 | 146 | Universe::narrow_oop_base() != NULL && |
mgerdin@6078 | 147 | Universe::narrow_oop_use_implicit_null_checks() )) { |
mgerdin@6078 | 148 | tty->print_cr("WB_ReadFromNoaccessArea method is useless:\n " |
mgerdin@6078 | 149 | "\tUseCompressedOops is %d\n" |
mgerdin@6078 | 150 | "\trhs.base() is "PTR_FORMAT"\n" |
mgerdin@6078 | 151 | "\tUniverse::narrow_oop_base() is "PTR_FORMAT"\n" |
mgerdin@6078 | 152 | "\tUniverse::narrow_oop_use_implicit_null_checks() is %d", |
mgerdin@6078 | 153 | UseCompressedOops, |
mgerdin@6078 | 154 | rhs.base(), |
mgerdin@6078 | 155 | Universe::narrow_oop_base(), |
mgerdin@6078 | 156 | Universe::narrow_oop_use_implicit_null_checks()); |
mgerdin@6078 | 157 | return; |
mgerdin@6078 | 158 | } |
mgerdin@6078 | 159 | tty->print_cr("Reading from no access area... "); |
mgerdin@6078 | 160 | tty->print_cr("*(vs.low_boundary() - rhs.noaccess_prefix() / 2 ) = %c", |
mgerdin@6078 | 161 | *(vs.low_boundary() - rhs.noaccess_prefix() / 2 )); |
mgerdin@6078 | 162 | WB_END |
mgerdin@6078 | 163 | |
mgerdin@6078 | 164 | static jint wb_stress_virtual_space_resize(size_t reserved_space_size, |
mgerdin@6078 | 165 | size_t magnitude, size_t iterations) { |
mgerdin@6078 | 166 | size_t granularity = os::vm_allocation_granularity(); |
mgerdin@6078 | 167 | ReservedHeapSpace rhs(reserved_space_size * granularity, granularity, false, NULL); |
mgerdin@6078 | 168 | VirtualSpace vs; |
mgerdin@6078 | 169 | if (!vs.initialize(rhs, 0)) { |
mgerdin@6078 | 170 | tty->print_cr("Failed to initialize VirtualSpace. Can't proceed."); |
mgerdin@6078 | 171 | return 3; |
mgerdin@6078 | 172 | } |
mgerdin@6078 | 173 | |
mgerdin@6078 | 174 | long seed = os::random(); |
mgerdin@6078 | 175 | tty->print_cr("Random seed is %ld", seed); |
mgerdin@6078 | 176 | os::init_random(seed); |
mgerdin@6078 | 177 | |
mgerdin@6078 | 178 | for (size_t i = 0; i < iterations; i++) { |
mgerdin@6078 | 179 | |
mgerdin@6078 | 180 | // Whether we will shrink or grow |
mgerdin@6078 | 181 | bool shrink = os::random() % 2L == 0; |
mgerdin@6078 | 182 | |
mgerdin@6078 | 183 | // Get random delta to resize virtual space |
mgerdin@6078 | 184 | size_t delta = (size_t)os::random() % magnitude; |
mgerdin@6078 | 185 | |
mgerdin@6078 | 186 | // If we are about to shrink virtual space below zero, then expand instead |
mgerdin@6078 | 187 | if (shrink && vs.committed_size() < delta) { |
mgerdin@6078 | 188 | shrink = false; |
mgerdin@6078 | 189 | } |
mgerdin@6078 | 190 | |
mgerdin@6078 | 191 | // Resizing by delta |
mgerdin@6078 | 192 | if (shrink) { |
mgerdin@6078 | 193 | vs.shrink_by(delta); |
mgerdin@6078 | 194 | } else { |
mgerdin@6078 | 195 | // If expanding fails expand_by will silently return false |
mgerdin@6078 | 196 | vs.expand_by(delta, true); |
mgerdin@6078 | 197 | } |
mgerdin@6078 | 198 | } |
mgerdin@6078 | 199 | return 0; |
mgerdin@6078 | 200 | } |
mgerdin@6078 | 201 | |
mgerdin@6078 | 202 | WB_ENTRY(jint, WB_StressVirtualSpaceResize(JNIEnv* env, jobject o, |
mgerdin@6078 | 203 | jlong reserved_space_size, jlong magnitude, jlong iterations)) |
mgerdin@6078 | 204 | tty->print_cr("reservedSpaceSize="JLONG_FORMAT", magnitude="JLONG_FORMAT", " |
mgerdin@6078 | 205 | "iterations="JLONG_FORMAT"\n", reserved_space_size, magnitude, |
mgerdin@6078 | 206 | iterations); |
mgerdin@6078 | 207 | if (reserved_space_size < 0 || magnitude < 0 || iterations < 0) { |
mgerdin@6078 | 208 | tty->print_cr("One of variables printed above is negative. Can't proceed.\n"); |
mgerdin@6078 | 209 | return 1; |
mgerdin@6078 | 210 | } |
mgerdin@6078 | 211 | |
mgerdin@6078 | 212 | // sizeof(size_t) depends on whether OS is 32bit or 64bit. sizeof(jlong) is |
mgerdin@6078 | 213 | // always 8 byte. That's why we should avoid overflow in case of 32bit platform. |
mgerdin@6078 | 214 | if (sizeof(size_t) < sizeof(jlong)) { |
mgerdin@6078 | 215 | jlong size_t_max_value = (jlong) SIZE_T_MAX_VALUE; |
mgerdin@6078 | 216 | if (reserved_space_size > size_t_max_value || magnitude > size_t_max_value |
mgerdin@6078 | 217 | || iterations > size_t_max_value) { |
mgerdin@6078 | 218 | tty->print_cr("One of variables printed above overflows size_t. Can't proceed.\n"); |
mgerdin@6078 | 219 | return 2; |
mgerdin@6078 | 220 | } |
mgerdin@6078 | 221 | } |
mgerdin@6078 | 222 | |
mgerdin@6078 | 223 | return wb_stress_virtual_space_resize((size_t) reserved_space_size, |
mgerdin@6078 | 224 | (size_t) magnitude, (size_t) iterations); |
mgerdin@6078 | 225 | WB_END |
mgerdin@6078 | 226 | |
tschatzl@7071 | 227 | WB_ENTRY(jboolean, WB_isObjectInOldGen(JNIEnv* env, jobject o, jobject obj)) |
tschatzl@7071 | 228 | oop p = JNIHandles::resolve(obj); |
tschatzl@7071 | 229 | #if INCLUDE_ALL_GCS |
tschatzl@7071 | 230 | if (UseG1GC) { |
tschatzl@7071 | 231 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
tschatzl@7071 | 232 | const HeapRegion* hr = g1->heap_region_containing(p); |
tschatzl@7071 | 233 | if (hr == NULL) { |
tschatzl@7071 | 234 | return false; |
tschatzl@7071 | 235 | } |
tschatzl@7071 | 236 | return !(hr->is_young()); |
tschatzl@7071 | 237 | } else if (UseParallelGC) { |
tschatzl@7071 | 238 | ParallelScavengeHeap* psh = ParallelScavengeHeap::heap(); |
tschatzl@7071 | 239 | return !psh->is_in_young(p); |
tschatzl@7071 | 240 | } |
tschatzl@7071 | 241 | #endif // INCLUDE_ALL_GCS |
tschatzl@7071 | 242 | GenCollectedHeap* gch = GenCollectedHeap::heap(); |
tschatzl@7071 | 243 | return !gch->is_in_young(p); |
tschatzl@7071 | 244 | WB_END |
tschatzl@7071 | 245 | |
tschatzl@7071 | 246 | WB_ENTRY(jlong, WB_GetObjectSize(JNIEnv* env, jobject o, jobject obj)) |
tschatzl@7071 | 247 | oop p = JNIHandles::resolve(obj); |
tschatzl@7071 | 248 | return p->size() * HeapWordSize; |
tschatzl@7071 | 249 | WB_END |
tschatzl@7071 | 250 | |
jprovino@4542 | 251 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 252 | WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) |
mgerdin@3619 | 253 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 254 | oop result = JNIHandles::resolve(obj); |
mgerdin@3619 | 255 | const HeapRegion* hr = g1->heap_region_containing(result); |
mgerdin@3619 | 256 | return hr->isHumongous(); |
mgerdin@3619 | 257 | WB_END |
mgerdin@3619 | 258 | |
mgerdin@3619 | 259 | WB_ENTRY(jlong, WB_G1NumFreeRegions(JNIEnv* env, jobject o)) |
mgerdin@3619 | 260 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
tschatzl@7050 | 261 | size_t nr = g1->num_free_regions(); |
mgerdin@3619 | 262 | return (jlong)nr; |
mgerdin@3619 | 263 | WB_END |
mgerdin@3619 | 264 | |
mgerdin@3619 | 265 | WB_ENTRY(jboolean, WB_G1InConcurrentMark(JNIEnv* env, jobject o)) |
mgerdin@3619 | 266 | G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
mgerdin@3619 | 267 | ConcurrentMark* cm = g1->concurrent_mark(); |
mgerdin@3619 | 268 | return cm->concurrent_marking_in_progress(); |
mgerdin@3619 | 269 | WB_END |
mgerdin@3619 | 270 | |
mgerdin@3619 | 271 | WB_ENTRY(jint, WB_G1RegionSize(JNIEnv* env, jobject o)) |
mgerdin@3619 | 272 | return (jint)HeapRegion::GrainBytes; |
mgerdin@3619 | 273 | WB_END |
jprovino@4542 | 274 | #endif // INCLUDE_ALL_GCS |
mgerdin@3619 | 275 | |
cjplummer@5586 | 276 | #if INCLUDE_NMT |
ctornqvi@4512 | 277 | // Alloc memory using the test memory type so that we can use that to see if |
ctornqvi@4512 | 278 | // NMT picks it up correctly |
ctornqvi@4885 | 279 | WB_ENTRY(jlong, WB_NMTMalloc(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 280 | jlong addr = 0; |
zgu@7074 | 281 | addr = (jlong)(uintptr_t)os::malloc(size, mtTest); |
zgu@7074 | 282 | return addr; |
zgu@7074 | 283 | WB_END |
ctornqvi@4512 | 284 | |
zgu@7074 | 285 | // Alloc memory with pseudo call stack. The test can create psudo malloc |
zgu@7074 | 286 | // allocation site to stress the malloc tracking. |
zgu@7074 | 287 | WB_ENTRY(jlong, WB_NMTMallocWithPseudoStack(JNIEnv* env, jobject o, jlong size, jint pseudo_stack)) |
zgu@7074 | 288 | address pc = (address)(size_t)pseudo_stack; |
zgu@7074 | 289 | NativeCallStack stack(&pc, 1); |
zgu@7074 | 290 | return (jlong)os::malloc(size, mtTest, stack); |
ctornqvi@4512 | 291 | WB_END |
ctornqvi@4512 | 292 | |
ctornqvi@4512 | 293 | // Free the memory allocated by NMTAllocTest |
ctornqvi@4885 | 294 | WB_ENTRY(void, WB_NMTFree(JNIEnv* env, jobject o, jlong mem)) |
ctornqvi@4885 | 295 | os::free((void*)(uintptr_t)mem, mtTest); |
ctornqvi@4885 | 296 | WB_END |
ctornqvi@4512 | 297 | |
ctornqvi@4885 | 298 | WB_ENTRY(jlong, WB_NMTReserveMemory(JNIEnv* env, jobject o, jlong size)) |
ctornqvi@4885 | 299 | jlong addr = 0; |
ctornqvi@4885 | 300 | |
ctornqvi@4885 | 301 | addr = (jlong)(uintptr_t)os::reserve_memory(size); |
ctornqvi@4885 | 302 | MemTracker::record_virtual_memory_type((address)addr, mtTest); |
ctornqvi@4512 | 303 | |
ctornqvi@4885 | 304 | return addr; |
ctornqvi@4885 | 305 | WB_END |
ctornqvi@4512 | 306 | |
ctornqvi@4885 | 307 | |
ctornqvi@4885 | 308 | WB_ENTRY(void, WB_NMTCommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
dcubed@5255 | 309 | os::commit_memory((char *)(uintptr_t)addr, size, !ExecMem); |
ctornqvi@4885 | 310 | MemTracker::record_virtual_memory_type((address)(uintptr_t)addr, mtTest); |
ctornqvi@4885 | 311 | WB_END |
ctornqvi@4885 | 312 | |
ctornqvi@4885 | 313 | WB_ENTRY(void, WB_NMTUncommitMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 314 | os::uncommit_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4885 | 315 | WB_END |
ctornqvi@4885 | 316 | |
ctornqvi@4885 | 317 | WB_ENTRY(void, WB_NMTReleaseMemory(JNIEnv* env, jobject o, jlong addr, jlong size)) |
ctornqvi@4885 | 318 | os::release_memory((char *)(uintptr_t)addr, size); |
ctornqvi@4512 | 319 | WB_END |
ctornqvi@4512 | 320 | |
zgu@7074 | 321 | WB_ENTRY(jboolean, WB_NMTIsDetailSupported(JNIEnv* env)) |
zgu@7074 | 322 | return MemTracker::tracking_level() == NMT_detail; |
ctornqvi@4512 | 323 | WB_END |
ctornqvi@4512 | 324 | |
zgu@7074 | 325 | WB_ENTRY(void, WB_NMTOverflowHashBucket(JNIEnv* env, jobject o, jlong num)) |
zgu@7074 | 326 | address pc = (address)1; |
zgu@7074 | 327 | for (jlong index = 0; index < num; index ++) { |
zgu@7074 | 328 | NativeCallStack stack(&pc, 1); |
zgu@7074 | 329 | os::malloc(0, mtTest, stack); |
zgu@7074 | 330 | pc += MallocSiteTable::hash_buckets(); |
zgu@7074 | 331 | } |
cjplummer@5586 | 332 | WB_END |
cjplummer@5586 | 333 | |
zgu@7074 | 334 | |
ctornqvi@4512 | 335 | #endif // INCLUDE_NMT |
ctornqvi@4512 | 336 | |
iignatyev@4592 | 337 | static jmethodID reflected_method_to_jmid(JavaThread* thread, JNIEnv* env, jobject method) { |
iignatyev@4592 | 338 | assert(method != NULL, "method should not be null"); |
iignatyev@4592 | 339 | ThreadToNativeFromVM ttn(thread); |
iignatyev@4592 | 340 | return env->FromReflectedMethod(method); |
iignatyev@4592 | 341 | } |
iignatyev@4592 | 342 | |
iignatyev@4592 | 343 | WB_ENTRY(void, WB_DeoptimizeAll(JNIEnv* env, jobject o)) |
iignatyev@4592 | 344 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 345 | CodeCache::mark_all_nmethods_for_deoptimization(); |
iignatyev@4592 | 346 | VM_Deoptimize op; |
iignatyev@4592 | 347 | VMThread::execute(&op); |
iignatyev@4592 | 348 | WB_END |
iignatyev@4592 | 349 | |
iignatyev@5541 | 350 | WB_ENTRY(jint, WB_DeoptimizeMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 351 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 352 | int result = 0; |
ccheung@6346 | 353 | CHECK_JNI_EXCEPTION_(env, result); |
iignatyev@4592 | 354 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 355 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 356 | nmethod* code; |
iignatyev@5541 | 357 | if (is_osr) { |
iignatyev@5541 | 358 | int bci = InvocationEntryBci; |
iignatyev@5541 | 359 | while ((code = mh->lookup_osr_nmethod_for(bci, CompLevel_none, false)) != NULL) { |
iignatyev@5541 | 360 | code->mark_for_deoptimization(); |
iignatyev@5541 | 361 | ++result; |
iignatyev@5541 | 362 | bci = code->osr_entry_bci() + 1; |
iignatyev@5541 | 363 | } |
iignatyev@5541 | 364 | } else { |
iignatyev@5541 | 365 | code = mh->code(); |
iignatyev@5541 | 366 | } |
iignatyev@4592 | 367 | if (code != NULL) { |
iignatyev@4592 | 368 | code->mark_for_deoptimization(); |
iignatyev@4592 | 369 | ++result; |
iignatyev@4592 | 370 | } |
iignatyev@4592 | 371 | result += CodeCache::mark_for_deoptimization(mh()); |
iignatyev@4592 | 372 | if (result > 0) { |
iignatyev@4592 | 373 | VM_Deoptimize op; |
iignatyev@4592 | 374 | VMThread::execute(&op); |
iignatyev@4592 | 375 | } |
iignatyev@4592 | 376 | return result; |
iignatyev@4592 | 377 | WB_END |
iignatyev@4592 | 378 | |
iignatyev@5541 | 379 | WB_ENTRY(jboolean, WB_IsMethodCompiled(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 380 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 381 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4592 | 382 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 383 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 384 | nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); |
iignatyev@4592 | 385 | if (code == NULL) { |
iignatyev@4592 | 386 | return JNI_FALSE; |
iignatyev@4592 | 387 | } |
iignatyev@4592 | 388 | return (code->is_alive() && !code->is_marked_for_deoptimization()); |
iignatyev@4592 | 389 | WB_END |
iignatyev@4592 | 390 | |
iignatyev@5541 | 391 | WB_ENTRY(jboolean, WB_IsMethodCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) |
iignatyev@4592 | 392 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 393 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4592 | 394 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 395 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 396 | if (is_osr) { |
iignatyev@5541 | 397 | return CompilationPolicy::can_be_osr_compiled(mh, comp_level); |
iignatyev@5541 | 398 | } else { |
iignatyev@5541 | 399 | return CompilationPolicy::can_be_compiled(mh, comp_level); |
iignatyev@5541 | 400 | } |
iignatyev@4592 | 401 | WB_END |
iignatyev@4592 | 402 | |
iignatyev@4592 | 403 | WB_ENTRY(jboolean, WB_IsMethodQueuedForCompilation(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4592 | 404 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 405 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4592 | 406 | MutexLockerEx mu(Compile_lock); |
iignatyev@4592 | 407 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 408 | return mh->queued_for_compilation(); |
iignatyev@4592 | 409 | WB_END |
iignatyev@4592 | 410 | |
iignatyev@5541 | 411 | WB_ENTRY(jint, WB_GetMethodCompilationLevel(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@4592 | 412 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 413 | CHECK_JNI_EXCEPTION_(env, CompLevel_none); |
iignatyev@4592 | 414 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 415 | nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); |
iignatyev@4592 | 416 | return (code != NULL ? code->comp_level() : CompLevel_none); |
iignatyev@4592 | 417 | WB_END |
iignatyev@4592 | 418 | |
iignatyev@5541 | 419 | WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level, jboolean is_osr)) |
iignatyev@4592 | 420 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 421 | CHECK_JNI_EXCEPTION(env); |
iignatyev@4592 | 422 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 423 | if (is_osr) { |
iignatyev@5541 | 424 | mh->set_not_osr_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@5541 | 425 | } else { |
iignatyev@5541 | 426 | mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); |
iignatyev@5541 | 427 | } |
iignatyev@5541 | 428 | WB_END |
iignatyev@5541 | 429 | |
iignatyev@5541 | 430 | WB_ENTRY(jint, WB_GetMethodEntryBci(JNIEnv* env, jobject o, jobject method)) |
iignatyev@5541 | 431 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 432 | CHECK_JNI_EXCEPTION_(env, InvocationEntryBci); |
iignatyev@5541 | 433 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 434 | nmethod* code = mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false); |
iignatyev@5541 | 435 | return (code != NULL && code->is_osr_method() ? code->osr_entry_bci() : InvocationEntryBci); |
iignatyev@4592 | 436 | WB_END |
iignatyev@4592 | 437 | |
iignatyev@4908 | 438 | WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4592 | 439 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 440 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4592 | 441 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4592 | 442 | bool result = mh->dont_inline(); |
iignatyev@4592 | 443 | mh->set_dont_inline(value == JNI_TRUE); |
iignatyev@4592 | 444 | return result; |
iignatyev@4592 | 445 | WB_END |
iignatyev@4592 | 446 | |
iignatyev@5541 | 447 | WB_ENTRY(jint, WB_GetCompileQueueSize(JNIEnv* env, jobject o, jint comp_level)) |
iignatyev@5541 | 448 | if (comp_level == CompLevel_any) { |
iignatyev@5541 | 449 | return CompileBroker::queue_size(CompLevel_full_optimization) /* C2 */ + |
iignatyev@5541 | 450 | CompileBroker::queue_size(CompLevel_full_profile) /* C1 */; |
iignatyev@5541 | 451 | } else { |
iignatyev@5541 | 452 | return CompileBroker::queue_size(comp_level); |
iignatyev@5541 | 453 | } |
iignatyev@4592 | 454 | WB_END |
iignatyev@4592 | 455 | |
iignatyev@4908 | 456 | WB_ENTRY(jboolean, WB_TestSetForceInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
iignatyev@4908 | 457 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 458 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4908 | 459 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 460 | bool result = mh->force_inline(); |
iignatyev@4908 | 461 | mh->set_force_inline(value == JNI_TRUE); |
iignatyev@4908 | 462 | return result; |
iignatyev@4908 | 463 | WB_END |
iignatyev@4908 | 464 | |
iignatyev@5541 | 465 | WB_ENTRY(jboolean, WB_EnqueueMethodForCompilation(JNIEnv* env, jobject o, jobject method, jint comp_level, jint bci)) |
iignatyev@4908 | 466 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 467 | CHECK_JNI_EXCEPTION_(env, JNI_FALSE); |
iignatyev@4908 | 468 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@5541 | 469 | nmethod* nm = CompileBroker::compile_method(mh, bci, comp_level, mh, mh->invocation_count(), "WhiteBox", THREAD); |
iignatyev@4908 | 470 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 471 | return (mh->queued_for_compilation() || nm != NULL); |
iignatyev@4908 | 472 | WB_END |
iignatyev@4908 | 473 | |
iignatyev@6610 | 474 | class VM_WhiteBoxOperation : public VM_Operation { |
iignatyev@6610 | 475 | public: |
iignatyev@6610 | 476 | VM_WhiteBoxOperation() { } |
iignatyev@6610 | 477 | VMOp_Type type() const { return VMOp_WhiteBoxOperation; } |
iignatyev@6610 | 478 | bool allow_nested_vm_operations() const { return true; } |
iignatyev@6610 | 479 | }; |
iignatyev@6610 | 480 | |
iignatyev@6610 | 481 | class AlwaysFalseClosure : public BoolObjectClosure { |
iignatyev@6610 | 482 | public: |
iignatyev@6610 | 483 | bool do_object_b(oop p) { return false; } |
iignatyev@6610 | 484 | }; |
iignatyev@6610 | 485 | |
iignatyev@6610 | 486 | static AlwaysFalseClosure always_false; |
iignatyev@6610 | 487 | |
iignatyev@6610 | 488 | class VM_WhiteBoxCleanMethodData : public VM_WhiteBoxOperation { |
iignatyev@6610 | 489 | public: |
iignatyev@6610 | 490 | VM_WhiteBoxCleanMethodData(MethodData* mdo) : _mdo(mdo) { } |
iignatyev@6610 | 491 | void doit() { |
iignatyev@6610 | 492 | _mdo->clean_method_data(&always_false); |
iignatyev@6610 | 493 | } |
iignatyev@6610 | 494 | private: |
iignatyev@6610 | 495 | MethodData* _mdo; |
iignatyev@6610 | 496 | }; |
iignatyev@6610 | 497 | |
iignatyev@4908 | 498 | WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) |
iignatyev@4908 | 499 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
ccheung@6346 | 500 | CHECK_JNI_EXCEPTION(env); |
iignatyev@4908 | 501 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@4908 | 502 | MutexLockerEx mu(Compile_lock); |
iignatyev@4908 | 503 | MethodData* mdo = mh->method_data(); |
jiangli@4938 | 504 | MethodCounters* mcs = mh->method_counters(); |
iignatyev@4908 | 505 | |
iignatyev@4908 | 506 | if (mdo != NULL) { |
iignatyev@4908 | 507 | mdo->init(); |
iignatyev@4908 | 508 | ResourceMark rm; |
iignatyev@4908 | 509 | int arg_count = mdo->method()->size_of_parameters(); |
iignatyev@4908 | 510 | for (int i = 0; i < arg_count; i++) { |
iignatyev@4908 | 511 | mdo->set_arg_modified(i, 0); |
iignatyev@4908 | 512 | } |
iignatyev@6610 | 513 | VM_WhiteBoxCleanMethodData op(mdo); |
iignatyev@6610 | 514 | VMThread::execute(&op); |
iignatyev@4908 | 515 | } |
iignatyev@4908 | 516 | |
iignatyev@4908 | 517 | mh->clear_not_c1_compilable(); |
iignatyev@4908 | 518 | mh->clear_not_c2_compilable(); |
iignatyev@4908 | 519 | mh->clear_not_c2_osr_compilable(); |
iignatyev@4908 | 520 | NOT_PRODUCT(mh->set_compiled_invocation_count(0)); |
jiangli@4938 | 521 | if (mcs != NULL) { |
jiangli@4938 | 522 | mcs->backedge_counter()->init(); |
jiangli@4938 | 523 | mcs->invocation_counter()->init(); |
jiangli@4938 | 524 | mcs->set_interpreter_invocation_count(0); |
jiangli@4938 | 525 | mcs->set_interpreter_throwout_count(0); |
iignatyev@4908 | 526 | |
iignatyev@4908 | 527 | #ifdef TIERED |
jiangli@4938 | 528 | mcs->set_rate(0.0F); |
jiangli@4938 | 529 | mh->set_prev_event_count(0, THREAD); |
jiangli@4938 | 530 | mh->set_prev_time(0, THREAD); |
iignatyev@4908 | 531 | #endif |
jiangli@4938 | 532 | } |
iignatyev@4908 | 533 | WB_END |
iignatyev@4908 | 534 | |
iignatyev@6963 | 535 | template <typename T> |
iignatyev@6963 | 536 | static bool GetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAt)(const char*, T*)) { |
iignatyev@6963 | 537 | if (name == NULL) { |
iignatyev@6963 | 538 | return false; |
iignatyev@6963 | 539 | } |
iignatyev@6963 | 540 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 541 | const char* flag_name = env->GetStringUTFChars(name, NULL); |
iignatyev@6963 | 542 | bool result = (*TAt)(flag_name, value); |
iignatyev@6963 | 543 | env->ReleaseStringUTFChars(name, flag_name); |
iignatyev@6963 | 544 | return result; |
iignatyev@6963 | 545 | } |
iignatyev@6963 | 546 | |
iignatyev@6963 | 547 | template <typename T> |
iignatyev@6963 | 548 | static bool SetVMFlag(JavaThread* thread, JNIEnv* env, jstring name, T* value, bool (*TAtPut)(const char*, T*, Flag::Flags)) { |
iignatyev@6963 | 549 | if (name == NULL) { |
iignatyev@6963 | 550 | return false; |
iignatyev@6963 | 551 | } |
iignatyev@6963 | 552 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 553 | const char* flag_name = env->GetStringUTFChars(name, NULL); |
iignatyev@6963 | 554 | bool result = (*TAtPut)(flag_name, value, Flag::INTERNAL); |
iignatyev@6963 | 555 | env->ReleaseStringUTFChars(name, flag_name); |
iignatyev@6963 | 556 | return result; |
iignatyev@6963 | 557 | } |
iignatyev@6963 | 558 | |
iignatyev@6963 | 559 | template <typename T> |
iignatyev@6963 | 560 | static jobject box(JavaThread* thread, JNIEnv* env, Symbol* name, Symbol* sig, T value) { |
iignatyev@6963 | 561 | ResourceMark rm(thread); |
iignatyev@6963 | 562 | jclass clazz = env->FindClass(name->as_C_string()); |
iignatyev@6963 | 563 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6963 | 564 | jmethodID methodID = env->GetStaticMethodID(clazz, |
iignatyev@6963 | 565 | vmSymbols::valueOf_name()->as_C_string(), |
iignatyev@6963 | 566 | sig->as_C_string()); |
iignatyev@6963 | 567 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6963 | 568 | jobject result = env->CallStaticObjectMethod(clazz, methodID, value); |
iignatyev@6963 | 569 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6963 | 570 | return result; |
iignatyev@6963 | 571 | } |
iignatyev@6963 | 572 | |
iignatyev@6963 | 573 | static jobject booleanBox(JavaThread* thread, JNIEnv* env, jboolean value) { |
iignatyev@6963 | 574 | return box(thread, env, vmSymbols::java_lang_Boolean(), vmSymbols::Boolean_valueOf_signature(), value); |
iignatyev@6963 | 575 | } |
iignatyev@6963 | 576 | static jobject integerBox(JavaThread* thread, JNIEnv* env, jint value) { |
iignatyev@6963 | 577 | return box(thread, env, vmSymbols::java_lang_Integer(), vmSymbols::Integer_valueOf_signature(), value); |
iignatyev@6963 | 578 | } |
iignatyev@6963 | 579 | static jobject longBox(JavaThread* thread, JNIEnv* env, jlong value) { |
iignatyev@6963 | 580 | return box(thread, env, vmSymbols::java_lang_Long(), vmSymbols::Long_valueOf_signature(), value); |
iignatyev@6963 | 581 | } |
iignatyev@6963 | 582 | /* static jobject floatBox(JavaThread* thread, JNIEnv* env, jfloat value) { |
iignatyev@6963 | 583 | return box(thread, env, vmSymbols::java_lang_Float(), vmSymbols::Float_valueOf_signature(), value); |
iignatyev@6963 | 584 | }*/ |
iignatyev@6963 | 585 | static jobject doubleBox(JavaThread* thread, JNIEnv* env, jdouble value) { |
iignatyev@6963 | 586 | return box(thread, env, vmSymbols::java_lang_Double(), vmSymbols::Double_valueOf_signature(), value); |
iignatyev@6963 | 587 | } |
iignatyev@6963 | 588 | |
iignatyev@6963 | 589 | WB_ENTRY(jobject, WB_GetBooleanVMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 590 | bool result; |
iignatyev@6963 | 591 | if (GetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAt)) { |
iignatyev@6963 | 592 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 593 | return booleanBox(thread, env, result); |
iignatyev@6963 | 594 | } |
iignatyev@6963 | 595 | return NULL; |
iignatyev@6963 | 596 | WB_END |
iignatyev@6963 | 597 | |
iignatyev@6963 | 598 | WB_ENTRY(jobject, WB_GetIntxVMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 599 | intx result; |
iignatyev@6963 | 600 | if (GetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAt)) { |
iignatyev@6963 | 601 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 602 | return longBox(thread, env, result); |
iignatyev@6963 | 603 | } |
iignatyev@6963 | 604 | return NULL; |
iignatyev@6963 | 605 | WB_END |
iignatyev@6963 | 606 | |
iignatyev@6963 | 607 | WB_ENTRY(jobject, WB_GetUintxVMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 608 | uintx result; |
iignatyev@6963 | 609 | if (GetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAt)) { |
iignatyev@6963 | 610 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 611 | return longBox(thread, env, result); |
iignatyev@6963 | 612 | } |
iignatyev@6963 | 613 | return NULL; |
iignatyev@6963 | 614 | WB_END |
iignatyev@6963 | 615 | |
iignatyev@6963 | 616 | WB_ENTRY(jobject, WB_GetUint64VMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 617 | uint64_t result; |
iignatyev@6963 | 618 | if (GetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAt)) { |
iignatyev@6963 | 619 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 620 | return longBox(thread, env, result); |
iignatyev@6963 | 621 | } |
iignatyev@6963 | 622 | return NULL; |
iignatyev@6963 | 623 | WB_END |
iignatyev@6963 | 624 | |
iignatyev@6963 | 625 | WB_ENTRY(jobject, WB_GetDoubleVMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 626 | double result; |
iignatyev@6963 | 627 | if (GetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAt)) { |
iignatyev@6963 | 628 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 629 | return doubleBox(thread, env, result); |
iignatyev@6963 | 630 | } |
iignatyev@6963 | 631 | return NULL; |
iignatyev@6963 | 632 | WB_END |
iignatyev@6963 | 633 | |
iignatyev@6963 | 634 | WB_ENTRY(jstring, WB_GetStringVMFlag(JNIEnv* env, jobject o, jstring name)) |
iignatyev@6963 | 635 | ccstr ccstrResult; |
iignatyev@6963 | 636 | if (GetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAt)) { |
iignatyev@6963 | 637 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 638 | jstring result = env->NewStringUTF(ccstrResult); |
iignatyev@6963 | 639 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6963 | 640 | return result; |
iignatyev@6963 | 641 | } |
iignatyev@6963 | 642 | return NULL; |
iignatyev@6963 | 643 | WB_END |
iignatyev@6963 | 644 | |
iignatyev@6963 | 645 | WB_ENTRY(void, WB_SetBooleanVMFlag(JNIEnv* env, jobject o, jstring name, jboolean value)) |
iignatyev@6963 | 646 | bool result = value == JNI_TRUE ? true : false; |
iignatyev@6963 | 647 | SetVMFlag <bool> (thread, env, name, &result, &CommandLineFlags::boolAtPut); |
iignatyev@6963 | 648 | WB_END |
iignatyev@6963 | 649 | |
iignatyev@6963 | 650 | WB_ENTRY(void, WB_SetIntxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) |
iignatyev@6963 | 651 | intx result = value; |
iignatyev@6963 | 652 | SetVMFlag <intx> (thread, env, name, &result, &CommandLineFlags::intxAtPut); |
iignatyev@6963 | 653 | WB_END |
iignatyev@6963 | 654 | |
iignatyev@6963 | 655 | WB_ENTRY(void, WB_SetUintxVMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) |
iignatyev@6963 | 656 | uintx result = value; |
iignatyev@6963 | 657 | SetVMFlag <uintx> (thread, env, name, &result, &CommandLineFlags::uintxAtPut); |
iignatyev@6963 | 658 | WB_END |
iignatyev@6963 | 659 | |
iignatyev@6963 | 660 | WB_ENTRY(void, WB_SetUint64VMFlag(JNIEnv* env, jobject o, jstring name, jlong value)) |
iignatyev@6963 | 661 | uint64_t result = value; |
iignatyev@6963 | 662 | SetVMFlag <uint64_t> (thread, env, name, &result, &CommandLineFlags::uint64_tAtPut); |
iignatyev@6963 | 663 | WB_END |
iignatyev@6963 | 664 | |
iignatyev@6963 | 665 | WB_ENTRY(void, WB_SetDoubleVMFlag(JNIEnv* env, jobject o, jstring name, jdouble value)) |
iignatyev@6963 | 666 | double result = value; |
iignatyev@6963 | 667 | SetVMFlag <double> (thread, env, name, &result, &CommandLineFlags::doubleAtPut); |
iignatyev@6963 | 668 | WB_END |
iignatyev@6963 | 669 | |
iignatyev@6963 | 670 | WB_ENTRY(void, WB_SetStringVMFlag(JNIEnv* env, jobject o, jstring name, jstring value)) |
iignatyev@6963 | 671 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@6963 | 672 | const char* ccstrValue = (value == NULL) ? NULL : env->GetStringUTFChars(value, NULL); |
iignatyev@6963 | 673 | ccstr ccstrResult = ccstrValue; |
iignatyev@6963 | 674 | bool needFree; |
iignatyev@6963 | 675 | { |
iignatyev@6963 | 676 | ThreadInVMfromNative ttvfn(thread); // back to VM |
iignatyev@6963 | 677 | needFree = SetVMFlag <ccstr> (thread, env, name, &ccstrResult, &CommandLineFlags::ccstrAtPut); |
iignatyev@6963 | 678 | } |
iignatyev@6963 | 679 | if (value != NULL) { |
iignatyev@6963 | 680 | env->ReleaseStringUTFChars(value, ccstrValue); |
iignatyev@6963 | 681 | } |
iignatyev@6963 | 682 | if (needFree) { |
iignatyev@6963 | 683 | FREE_C_HEAP_ARRAY(char, ccstrResult, mtInternal); |
iignatyev@6963 | 684 | } |
iignatyev@6963 | 685 | WB_END |
iignatyev@6963 | 686 | |
iignatyev@6963 | 687 | |
mgerdin@4850 | 688 | WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
mgerdin@4850 | 689 | ResourceMark rm(THREAD); |
mgerdin@4850 | 690 | int len; |
hseigel@4987 | 691 | jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); |
hseigel@4987 | 692 | return (StringTable::lookup(name, len) != NULL); |
mgerdin@4850 | 693 | WB_END |
mgerdin@4850 | 694 | |
mgerdin@4850 | 695 | WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
mgerdin@4850 | 696 | Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
mgerdin@4850 | 697 | Universe::heap()->collect(GCCause::_last_ditch_collection); |
mgerdin@4850 | 698 | WB_END |
mgerdin@4850 | 699 | |
tschatzl@7071 | 700 | WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) |
tschatzl@7071 | 701 | Universe::heap()->collect(GCCause::_wb_young_gc); |
tschatzl@7071 | 702 | WB_END |
mikael@4989 | 703 | |
mikael@5174 | 704 | WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) |
mikael@5174 | 705 | // static+volatile in order to force the read to happen |
mikael@5174 | 706 | // (not be eliminated by the compiler) |
mikael@5174 | 707 | static char c; |
mikael@5174 | 708 | static volatile char* p; |
mikael@5174 | 709 | |
mikael@5174 | 710 | p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); |
mikael@5174 | 711 | if (p == NULL) { |
mikael@5174 | 712 | THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); |
mikael@5174 | 713 | } |
mikael@5174 | 714 | |
mikael@5174 | 715 | c = *p; |
mikael@4989 | 716 | WB_END |
mikael@4989 | 717 | |
iignatyev@6427 | 718 | WB_ENTRY(jstring, WB_GetCPUFeatures(JNIEnv* env, jobject o)) |
iignatyev@6427 | 719 | const char* cpu_features = VM_Version::cpu_features(); |
iignatyev@6427 | 720 | ThreadToNativeFromVM ttn(thread); |
iignatyev@6427 | 721 | jstring features_string = env->NewStringUTF(cpu_features); |
iignatyev@6427 | 722 | |
iignatyev@6427 | 723 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6427 | 724 | |
iignatyev@6427 | 725 | return features_string; |
iignatyev@6427 | 726 | WB_END |
iignatyev@6427 | 727 | |
iignatyev@6525 | 728 | |
iignatyev@6525 | 729 | WB_ENTRY(jobjectArray, WB_GetNMethod(JNIEnv* env, jobject o, jobject method, jboolean is_osr)) |
iignatyev@6525 | 730 | ResourceMark rm(THREAD); |
iignatyev@6525 | 731 | jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
iignatyev@6525 | 732 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6525 | 733 | methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
iignatyev@6525 | 734 | nmethod* code = is_osr ? mh->lookup_osr_nmethod_for(InvocationEntryBci, CompLevel_none, false) : mh->code(); |
iignatyev@6525 | 735 | jobjectArray result = NULL; |
iignatyev@6525 | 736 | if (code == NULL) { |
iignatyev@6525 | 737 | return result; |
iignatyev@6525 | 738 | } |
iignatyev@6525 | 739 | int insts_size = code->insts_size(); |
iignatyev@6525 | 740 | |
iignatyev@6525 | 741 | ThreadToNativeFromVM ttn(thread); |
iignatyev@6525 | 742 | jclass clazz = env->FindClass(vmSymbols::java_lang_Object()->as_C_string()); |
iignatyev@6525 | 743 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6525 | 744 | result = env->NewObjectArray(2, clazz, NULL); |
iignatyev@6525 | 745 | if (result == NULL) { |
iignatyev@6525 | 746 | return result; |
iignatyev@6525 | 747 | } |
iignatyev@6525 | 748 | |
iignatyev@6963 | 749 | jobject obj = integerBox(thread, env, code->comp_level()); |
iignatyev@6525 | 750 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6525 | 751 | env->SetObjectArrayElement(result, 0, obj); |
iignatyev@6525 | 752 | |
iignatyev@6525 | 753 | jbyteArray insts = env->NewByteArray(insts_size); |
iignatyev@6525 | 754 | CHECK_JNI_EXCEPTION_(env, NULL); |
iignatyev@6525 | 755 | env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin()); |
iignatyev@6525 | 756 | env->SetObjectArrayElement(result, 1, insts); |
iignatyev@6525 | 757 | |
iignatyev@6525 | 758 | return result; |
iignatyev@6525 | 759 | WB_END |
iignatyev@6525 | 760 | |
iignatyev@6525 | 761 | |
stefank@6992 | 762 | int WhiteBox::array_bytes_to_length(size_t bytes) { |
stefank@6992 | 763 | return Array<u1>::bytes_to_length(bytes); |
stefank@6992 | 764 | } |
stefank@6992 | 765 | |
stefank@6992 | 766 | WB_ENTRY(jlong, WB_AllocateMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong size)) |
stefank@6992 | 767 | if (size < 0) { |
stefank@6992 | 768 | THROW_MSG_0(vmSymbols::java_lang_IllegalArgumentException(), |
stefank@6992 | 769 | err_msg("WB_AllocateMetaspace: size is negative: " JLONG_FORMAT, size)); |
stefank@6992 | 770 | } |
stefank@6992 | 771 | |
stefank@6992 | 772 | oop class_loader_oop = JNIHandles::resolve(class_loader); |
stefank@6992 | 773 | ClassLoaderData* cld = class_loader_oop != NULL |
stefank@6992 | 774 | ? java_lang_ClassLoader::loader_data(class_loader_oop) |
stefank@6992 | 775 | : ClassLoaderData::the_null_class_loader_data(); |
stefank@6992 | 776 | |
stefank@6992 | 777 | void* metadata = MetadataFactory::new_writeable_array<u1>(cld, WhiteBox::array_bytes_to_length((size_t)size), thread); |
stefank@6992 | 778 | |
stefank@6992 | 779 | return (jlong)(uintptr_t)metadata; |
stefank@6992 | 780 | WB_END |
stefank@6992 | 781 | |
stefank@6992 | 782 | WB_ENTRY(void, WB_FreeMetaspace(JNIEnv* env, jobject wb, jobject class_loader, jlong addr, jlong size)) |
stefank@6992 | 783 | oop class_loader_oop = JNIHandles::resolve(class_loader); |
stefank@6992 | 784 | ClassLoaderData* cld = class_loader_oop != NULL |
stefank@6992 | 785 | ? java_lang_ClassLoader::loader_data(class_loader_oop) |
stefank@6992 | 786 | : ClassLoaderData::the_null_class_loader_data(); |
stefank@6992 | 787 | |
stefank@6992 | 788 | MetadataFactory::free_array(cld, (Array<u1>*)(uintptr_t)addr); |
stefank@6992 | 789 | WB_END |
stefank@6992 | 790 | |
nloodin@3681 | 791 | //Some convenience methods to deal with objects from java |
nloodin@3681 | 792 | int WhiteBox::offset_for_field(const char* field_name, oop object, |
nloodin@3681 | 793 | Symbol* signature_symbol) { |
nloodin@3681 | 794 | assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid"); |
nloodin@3681 | 795 | Thread* THREAD = Thread::current(); |
nloodin@3681 | 796 | |
nloodin@3681 | 797 | //Get the class of our object |
coleenp@4037 | 798 | Klass* arg_klass = object->klass(); |
nloodin@3681 | 799 | //Turn it into an instance-klass |
coleenp@4037 | 800 | InstanceKlass* ik = InstanceKlass::cast(arg_klass); |
nloodin@3681 | 801 | |
nloodin@3681 | 802 | //Create symbols to look for in the class |
nloodin@3681 | 803 | TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name), |
nloodin@3681 | 804 | THREAD); |
nloodin@3681 | 805 | |
nloodin@3681 | 806 | //To be filled in with an offset of the field we're looking for |
nloodin@3681 | 807 | fieldDescriptor fd; |
nloodin@3681 | 808 | |
coleenp@4037 | 809 | Klass* res = ik->find_field(name_symbol, signature_symbol, &fd); |
nloodin@3681 | 810 | if (res == NULL) { |
nloodin@3681 | 811 | tty->print_cr("Invalid layout of %s at %s", ik->external_name(), |
nloodin@3681 | 812 | name_symbol->as_C_string()); |
nloodin@3681 | 813 | fatal("Invalid layout of preloaded class"); |
nloodin@3681 | 814 | } |
nloodin@3681 | 815 | |
nloodin@3681 | 816 | //fetch the field at the offset we've found |
nloodin@3681 | 817 | int dest_offset = fd.offset(); |
nloodin@3681 | 818 | |
nloodin@3681 | 819 | return dest_offset; |
nloodin@3681 | 820 | } |
nloodin@3681 | 821 | |
nloodin@3681 | 822 | |
nloodin@3681 | 823 | const char* WhiteBox::lookup_jstring(const char* field_name, oop object) { |
nloodin@3681 | 824 | int offset = offset_for_field(field_name, object, |
nloodin@3681 | 825 | vmSymbols::string_signature()); |
nloodin@3681 | 826 | oop string = object->obj_field(offset); |
sla@3905 | 827 | if (string == NULL) { |
sla@3905 | 828 | return NULL; |
sla@3905 | 829 | } |
nloodin@3681 | 830 | const char* ret = java_lang_String::as_utf8_string(string); |
nloodin@3681 | 831 | return ret; |
nloodin@3681 | 832 | } |
nloodin@3681 | 833 | |
nloodin@3681 | 834 | bool WhiteBox::lookup_bool(const char* field_name, oop object) { |
nloodin@3681 | 835 | int offset = |
nloodin@3681 | 836 | offset_for_field(field_name, object, vmSymbols::bool_signature()); |
nloodin@3681 | 837 | bool ret = (object->bool_field(offset) == JNI_TRUE); |
nloodin@3681 | 838 | return ret; |
nloodin@3681 | 839 | } |
nloodin@3681 | 840 | |
nloodin@3681 | 841 | |
mgerdin@3619 | 842 | #define CC (char*) |
mgerdin@3619 | 843 | |
mgerdin@3619 | 844 | static JNINativeMethod methods[] = { |
mgerdin@3619 | 845 | {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, |
tschatzl@7071 | 846 | {CC"getObjectSize", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectSize }, |
tschatzl@7071 | 847 | {CC"isObjectInOldGen", CC"(Ljava/lang/Object;)Z", (void*)&WB_isObjectInOldGen }, |
mgerdin@3619 | 848 | {CC"getHeapOopSize", CC"()I", (void*)&WB_GetHeapOopSize }, |
iignatyev@4592 | 849 | {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, |
iignatyev@4592 | 850 | {CC"parseCommandLine", |
iignatyev@4592 | 851 | CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", |
nloodin@3681 | 852 | (void*) &WB_ParseCommandLine |
nloodin@3681 | 853 | }, |
tschatzl@5701 | 854 | {CC"getCompressedOopsMaxHeapSize", CC"()J", |
tschatzl@5701 | 855 | (void*)&WB_GetCompressedOopsMaxHeapSize}, |
tschatzl@5073 | 856 | {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, |
mgerdin@6078 | 857 | {CC"runMemoryUnitTests", CC"()V", (void*)&WB_RunMemoryUnitTests}, |
mgerdin@6078 | 858 | {CC"readFromNoaccessArea",CC"()V", (void*)&WB_ReadFromNoaccessArea}, |
mgerdin@6078 | 859 | {CC"stressVirtualSpaceResize",CC"(JJJ)I", (void*)&WB_StressVirtualSpaceResize}, |
jprovino@4542 | 860 | #if INCLUDE_ALL_GCS |
mgerdin@3619 | 861 | {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, |
mgerdin@3619 | 862 | {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, |
mgerdin@3619 | 863 | {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, |
mgerdin@3619 | 864 | {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, |
jprovino@4542 | 865 | #endif // INCLUDE_ALL_GCS |
cjplummer@5586 | 866 | #if INCLUDE_NMT |
ctornqvi@4885 | 867 | {CC"NMTMalloc", CC"(J)J", (void*)&WB_NMTMalloc }, |
zgu@7074 | 868 | {CC"NMTMallocWithPseudoStack", CC"(JI)J", (void*)&WB_NMTMallocWithPseudoStack}, |
ctornqvi@4885 | 869 | {CC"NMTFree", CC"(J)V", (void*)&WB_NMTFree }, |
ctornqvi@4885 | 870 | {CC"NMTReserveMemory", CC"(J)J", (void*)&WB_NMTReserveMemory }, |
ctornqvi@4885 | 871 | {CC"NMTCommitMemory", CC"(JJ)V", (void*)&WB_NMTCommitMemory }, |
ctornqvi@4885 | 872 | {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, |
ctornqvi@4885 | 873 | {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, |
zgu@7074 | 874 | {CC"NMTOverflowHashBucket", CC"(J)V", (void*)&WB_NMTOverflowHashBucket}, |
cjplummer@5586 | 875 | {CC"NMTIsDetailSupported",CC"()Z", (void*)&WB_NMTIsDetailSupported}, |
ctornqvi@4512 | 876 | #endif // INCLUDE_NMT |
iignatyev@4592 | 877 | {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, |
iignatyev@5541 | 878 | {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;Z)I", |
iignatyev@4592 | 879 | (void*)&WB_DeoptimizeMethod }, |
iignatyev@5541 | 880 | {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;Z)Z", |
iignatyev@4592 | 881 | (void*)&WB_IsMethodCompiled }, |
iignatyev@5541 | 882 | {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;IZ)Z", |
iignatyev@4592 | 883 | (void*)&WB_IsMethodCompilable}, |
iignatyev@4592 | 884 | {CC"isMethodQueuedForCompilation", |
iignatyev@4951 | 885 | CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, |
iignatyev@4592 | 886 | {CC"makeMethodNotCompilable", |
iignatyev@5541 | 887 | CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable}, |
iignatyev@4908 | 888 | {CC"testSetDontInlineMethod", |
iignatyev@4951 | 889 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, |
iignatyev@4592 | 890 | {CC"getMethodCompilationLevel", |
iignatyev@5541 | 891 | CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel}, |
iignatyev@5541 | 892 | {CC"getMethodEntryBci", |
iignatyev@5541 | 893 | CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci}, |
iignatyev@5541 | 894 | {CC"getCompileQueueSize", |
iignatyev@5541 | 895 | CC"(I)I", (void*)&WB_GetCompileQueueSize}, |
iignatyev@4908 | 896 | {CC"testSetForceInlineMethod", |
iignatyev@4951 | 897 | CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, |
iignatyev@4908 | 898 | {CC"enqueueMethodForCompilation", |
iignatyev@5541 | 899 | CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation}, |
iignatyev@4908 | 900 | {CC"clearMethodState", |
iignatyev@4951 | 901 | CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, |
iignatyev@6963 | 902 | {CC"setBooleanVMFlag", CC"(Ljava/lang/String;Z)V",(void*)&WB_SetBooleanVMFlag}, |
iignatyev@6963 | 903 | {CC"setIntxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetIntxVMFlag}, |
iignatyev@6963 | 904 | {CC"setUintxVMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUintxVMFlag}, |
iignatyev@6963 | 905 | {CC"setUint64VMFlag", CC"(Ljava/lang/String;J)V",(void*)&WB_SetUint64VMFlag}, |
iignatyev@6963 | 906 | {CC"setDoubleVMFlag", CC"(Ljava/lang/String;D)V",(void*)&WB_SetDoubleVMFlag}, |
iignatyev@6963 | 907 | {CC"setStringVMFlag", CC"(Ljava/lang/String;Ljava/lang/String;)V", |
iignatyev@6963 | 908 | (void*)&WB_SetStringVMFlag}, |
iignatyev@6963 | 909 | {CC"getBooleanVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Boolean;", |
iignatyev@6963 | 910 | (void*)&WB_GetBooleanVMFlag}, |
iignatyev@6963 | 911 | {CC"getIntxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", |
iignatyev@6963 | 912 | (void*)&WB_GetIntxVMFlag}, |
iignatyev@6963 | 913 | {CC"getUintxVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", |
iignatyev@6963 | 914 | (void*)&WB_GetUintxVMFlag}, |
iignatyev@6963 | 915 | {CC"getUint64VMFlag", CC"(Ljava/lang/String;)Ljava/lang/Long;", |
iignatyev@6963 | 916 | (void*)&WB_GetUint64VMFlag}, |
iignatyev@6963 | 917 | {CC"getDoubleVMFlag", CC"(Ljava/lang/String;)Ljava/lang/Double;", |
iignatyev@6963 | 918 | (void*)&WB_GetDoubleVMFlag}, |
iignatyev@6963 | 919 | {CC"getStringVMFlag", CC"(Ljava/lang/String;)Ljava/lang/String;", |
iignatyev@6963 | 920 | (void*)&WB_GetStringVMFlag}, |
iignatyev@6963 | 921 | {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, |
mgerdin@4850 | 922 | {CC"fullGC", CC"()V", (void*)&WB_FullGC }, |
tschatzl@7071 | 923 | {CC"youngGC", CC"()V", (void*)&WB_YoungGC }, |
mikael@5174 | 924 | {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, |
stefank@6992 | 925 | {CC"allocateMetaspace", |
stefank@6992 | 926 | CC"(Ljava/lang/ClassLoader;J)J", (void*)&WB_AllocateMetaspace }, |
stefank@6992 | 927 | {CC"freeMetaspace", |
stefank@6992 | 928 | CC"(Ljava/lang/ClassLoader;JJ)V", (void*)&WB_FreeMetaspace }, |
iignatyev@6427 | 929 | {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures }, |
iignatyev@6525 | 930 | {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;", |
iignatyev@6525 | 931 | (void*)&WB_GetNMethod }, |
mgerdin@3619 | 932 | }; |
mgerdin@3619 | 933 | |
mgerdin@3619 | 934 | #undef CC |
mgerdin@3619 | 935 | |
mgerdin@3619 | 936 | JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) |
mgerdin@3619 | 937 | { |
mgerdin@3619 | 938 | if (WhiteBoxAPI) { |
mgerdin@3619 | 939 | // Make sure that wbclass is loaded by the null classloader |
mgerdin@3619 | 940 | instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
mgerdin@3619 | 941 | Handle loader(ikh->class_loader()); |
mgerdin@3619 | 942 | if (loader.is_null()) { |
iignatyev@5028 | 943 | ResourceMark rm; |
mgerdin@3619 | 944 | ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
iignatyev@5028 | 945 | bool result = true; |
iignatyev@5028 | 946 | // one by one registration natives for exception catching |
iignatyev@5028 | 947 | jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); |
ccheung@6346 | 948 | CHECK_JNI_EXCEPTION(env); |
iignatyev@5028 | 949 | for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { |
iignatyev@5028 | 950 | if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { |
iignatyev@5028 | 951 | result = false; |
ccheung@6346 | 952 | jthrowable throwable_obj = env->ExceptionOccurred(); |
ccheung@6346 | 953 | if (throwable_obj != NULL) { |
iignatyev@5028 | 954 | env->ExceptionClear(); |
ccheung@6346 | 955 | if (env->IsInstanceOf(throwable_obj, exceptionKlass)) { |
ccheung@6346 | 956 | // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native |
ccheung@6346 | 957 | // ignoring the exception |
ccheung@6346 | 958 | tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); |
ccheung@6346 | 959 | } |
iignatyev@5028 | 960 | } else { |
iignatyev@5028 | 961 | // register is failed w/o exception or w/ unexpected exception |
iignatyev@5028 | 962 | tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", methods[i].name, methods[i].signature); |
iignatyev@5028 | 963 | env->UnregisterNatives(wbclass); |
iignatyev@5028 | 964 | break; |
iignatyev@5028 | 965 | } |
iignatyev@5028 | 966 | } |
iignatyev@5028 | 967 | } |
iignatyev@5028 | 968 | |
iignatyev@5028 | 969 | if (result) { |
mgerdin@3619 | 970 | WhiteBox::set_used(); |
mgerdin@3619 | 971 | } |
mgerdin@3619 | 972 | } |
mgerdin@3619 | 973 | } |
mgerdin@3619 | 974 | } |
mgerdin@3619 | 975 | JVM_END |