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