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