Mercurial > hg > truffle
comparison src/share/vm/prims/whitebox.cpp @ 10408:836a62f43af9
Merge with http://hg.openjdk.java.net/hsx/hsx25/hotspot/
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Wed, 19 Jun 2013 10:45:56 +0200 |
parents | f54c85acc043 |
children | a837fa3d3f86 |
comparison
equal
deleted
inserted
replaced
10086:e0fb8a213650 | 10408:836a62f43af9 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 2012, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
35 | 35 |
36 #include "runtime/interfaceSupport.hpp" | 36 #include "runtime/interfaceSupport.hpp" |
37 #include "runtime/os.hpp" | 37 #include "runtime/os.hpp" |
38 #include "utilities/debug.hpp" | 38 #include "utilities/debug.hpp" |
39 #include "utilities/macros.hpp" | 39 #include "utilities/macros.hpp" |
40 #include "utilities/exceptions.hpp" | |
40 | 41 |
41 #if INCLUDE_ALL_GCS | 42 #if INCLUDE_ALL_GCS |
42 #include "gc_implementation/g1/concurrentMark.hpp" | 43 #include "gc_implementation/g1/concurrentMark.hpp" |
43 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" | 44 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp" |
44 #include "gc_implementation/g1/heapRegionRemSet.hpp" | 45 #include "gc_implementation/g1/heapRegionRemSet.hpp" |
91 ClassLoaderDataGraph::classes_do(&closure); | 92 ClassLoaderDataGraph::classes_do(&closure); |
92 | 93 |
93 return closure.found(); | 94 return closure.found(); |
94 WB_END | 95 WB_END |
95 | 96 |
97 WB_ENTRY(void, WB_PrintHeapSizes(JNIEnv* env, jobject o)) { | |
98 CollectorPolicy * p = Universe::heap()->collector_policy(); | |
99 gclog_or_tty->print_cr("Minimum heap "SIZE_FORMAT" Initial heap " | |
100 SIZE_FORMAT" Maximum heap "SIZE_FORMAT" Min alignment "SIZE_FORMAT" Max alignment "SIZE_FORMAT, | |
101 p->min_heap_byte_size(), p->initial_heap_byte_size(), p->max_heap_byte_size(), | |
102 p->min_alignment(), p->max_alignment()); | |
103 } | |
104 WB_END | |
105 | |
96 #if INCLUDE_ALL_GCS | 106 #if INCLUDE_ALL_GCS |
97 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) | 107 WB_ENTRY(jboolean, WB_G1IsHumongous(JNIEnv* env, jobject o, jobject obj)) |
98 G1CollectedHeap* g1 = G1CollectedHeap::heap(); | 108 G1CollectedHeap* g1 = G1CollectedHeap::heap(); |
99 oop result = JNIHandles::resolve(obj); | 109 oop result = JNIHandles::resolve(obj); |
100 const HeapRegion* hr = g1->heap_region_containing(result); | 110 const HeapRegion* hr = g1->heap_region_containing(result); |
235 nmethod* code = mh->code(); | 245 nmethod* code = mh->code(); |
236 return (code != NULL ? code->comp_level() : CompLevel_none); | 246 return (code != NULL ? code->comp_level() : CompLevel_none); |
237 WB_END | 247 WB_END |
238 | 248 |
239 | 249 |
240 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method)) | 250 WB_ENTRY(void, WB_MakeMethodNotCompilable(JNIEnv* env, jobject o, jobject method, jint comp_level)) |
241 jmethodID jmid = reflected_method_to_jmid(thread, env, method); | 251 jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
242 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); | 252 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
243 mh->set_not_compilable(); | 253 mh->set_not_compilable(comp_level, true /* report */, "WhiteBox"); |
244 WB_END | 254 WB_END |
245 | 255 |
246 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) | 256 WB_ENTRY(jboolean, WB_TestSetDontInlineMethod(JNIEnv* env, jobject o, jobject method, jboolean value)) |
247 jmethodID jmid = reflected_method_to_jmid(thread, env, method); | 257 jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
248 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); | 258 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
276 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) | 286 WB_ENTRY(void, WB_ClearMethodState(JNIEnv* env, jobject o, jobject method)) |
277 jmethodID jmid = reflected_method_to_jmid(thread, env, method); | 287 jmethodID jmid = reflected_method_to_jmid(thread, env, method); |
278 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); | 288 methodHandle mh(THREAD, Method::checked_resolve_jmethod_id(jmid)); |
279 MutexLockerEx mu(Compile_lock); | 289 MutexLockerEx mu(Compile_lock); |
280 MethodData* mdo = mh->method_data(); | 290 MethodData* mdo = mh->method_data(); |
291 MethodCounters* mcs = mh->method_counters(); | |
281 | 292 |
282 if (mdo != NULL) { | 293 if (mdo != NULL) { |
283 mdo->init(); | 294 mdo->init(); |
284 ResourceMark rm; | 295 ResourceMark rm; |
285 int arg_count = mdo->method()->size_of_parameters(); | 296 int arg_count = mdo->method()->size_of_parameters(); |
286 for (int i = 0; i < arg_count; i++) { | 297 for (int i = 0; i < arg_count; i++) { |
287 mdo->set_arg_modified(i, 0); | 298 mdo->set_arg_modified(i, 0); |
288 } | 299 } |
289 } | 300 } |
290 | 301 |
291 mh->backedge_counter()->init(); | |
292 mh->invocation_counter()->init(); | |
293 mh->set_interpreter_invocation_count(0); | |
294 mh->set_interpreter_throwout_count(0); | |
295 mh->clear_not_c1_compilable(); | 302 mh->clear_not_c1_compilable(); |
296 mh->clear_not_c2_compilable(); | 303 mh->clear_not_c2_compilable(); |
297 mh->clear_not_c2_osr_compilable(); | 304 mh->clear_not_c2_osr_compilable(); |
298 NOT_PRODUCT(mh->set_compiled_invocation_count(0)); | 305 NOT_PRODUCT(mh->set_compiled_invocation_count(0)); |
306 if (mcs != NULL) { | |
307 mcs->backedge_counter()->init(); | |
308 mcs->invocation_counter()->init(); | |
309 mcs->set_interpreter_invocation_count(0); | |
310 mcs->set_interpreter_throwout_count(0); | |
299 | 311 |
300 #ifdef TIERED | 312 #ifdef TIERED |
301 mh->set_rate(0.0F); | 313 mcs->set_rate(0.0F); |
302 mh->set_prev_event_count(0); | 314 mh->set_prev_event_count(0, THREAD); |
303 mh->set_prev_time(0); | 315 mh->set_prev_time(0, THREAD); |
304 #endif | 316 #endif |
317 } | |
305 WB_END | 318 WB_END |
306 | 319 |
307 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) | 320 WB_ENTRY(jboolean, WB_IsInStringTable(JNIEnv* env, jobject o, jstring javaString)) |
308 ResourceMark rm(THREAD); | 321 ResourceMark rm(THREAD); |
309 int len; | 322 int len; |
310 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len); | 323 jchar* name = java_lang_String::as_unicode_string(JNIHandles::resolve(javaString), len, CHECK_false); |
311 oop found_string = StringTable::the_table()->lookup(name, len); | 324 return (StringTable::lookup(name, len) != NULL); |
312 if (found_string == NULL) { | |
313 return false; | |
314 } | |
315 return true; | |
316 WB_END | 325 WB_END |
317 | 326 |
318 | 327 |
319 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) | 328 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
320 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); | 329 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
321 Universe::heap()->collect(GCCause::_last_ditch_collection); | 330 Universe::heap()->collect(GCCause::_last_ditch_collection); |
331 WB_END | |
332 | |
333 | |
334 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o)) | |
335 // static+volatile in order to force the read to happen | |
336 // (not be eliminated by the compiler) | |
337 static char c; | |
338 static volatile char* p; | |
339 | |
340 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0); | |
341 if (p == NULL) { | |
342 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory"); | |
343 } | |
344 | |
345 c = *p; | |
322 WB_END | 346 WB_END |
323 | 347 |
324 //Some convenience methods to deal with objects from java | 348 //Some convenience methods to deal with objects from java |
325 int WhiteBox::offset_for_field(const char* field_name, oop object, | 349 int WhiteBox::offset_for_field(const char* field_name, oop object, |
326 Symbol* signature_symbol) { | 350 Symbol* signature_symbol) { |
380 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, | 404 {CC"isClassAlive0", CC"(Ljava/lang/String;)Z", (void*)&WB_IsClassAlive }, |
381 {CC"parseCommandLine", | 405 {CC"parseCommandLine", |
382 CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", | 406 CC"(Ljava/lang/String;[Lsun/hotspot/parser/DiagnosticCommand;)[Ljava/lang/Object;", |
383 (void*) &WB_ParseCommandLine | 407 (void*) &WB_ParseCommandLine |
384 }, | 408 }, |
409 {CC"printHeapSizes", CC"()V", (void*)&WB_PrintHeapSizes }, | |
385 #if INCLUDE_ALL_GCS | 410 #if INCLUDE_ALL_GCS |
386 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, | 411 {CC"g1InConcurrentMark", CC"()Z", (void*)&WB_G1InConcurrentMark}, |
387 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, | 412 {CC"g1IsHumongous", CC"(Ljava/lang/Object;)Z", (void*)&WB_G1IsHumongous }, |
388 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, | 413 {CC"g1NumFreeRegions", CC"()J", (void*)&WB_G1NumFreeRegions }, |
389 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, | 414 {CC"g1RegionSize", CC"()I", (void*)&WB_G1RegionSize }, |
396 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, | 421 {CC"NMTUncommitMemory", CC"(JJ)V", (void*)&WB_NMTUncommitMemory }, |
397 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, | 422 {CC"NMTReleaseMemory", CC"(JJ)V", (void*)&WB_NMTReleaseMemory }, |
398 {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge}, | 423 {CC"NMTWaitForDataMerge", CC"()Z", (void*)&WB_NMTWaitForDataMerge}, |
399 #endif // INCLUDE_NMT | 424 #endif // INCLUDE_NMT |
400 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, | 425 {CC"deoptimizeAll", CC"()V", (void*)&WB_DeoptimizeAll }, |
401 {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Method;)I", | 426 {CC"deoptimizeMethod", CC"(Ljava/lang/reflect/Executable;)I", |
402 (void*)&WB_DeoptimizeMethod }, | 427 (void*)&WB_DeoptimizeMethod }, |
403 {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Method;)Z", | 428 {CC"isMethodCompiled", CC"(Ljava/lang/reflect/Executable;)Z", |
404 (void*)&WB_IsMethodCompiled }, | 429 (void*)&WB_IsMethodCompiled }, |
405 {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Method;I)Z", | 430 {CC"isMethodCompilable", CC"(Ljava/lang/reflect/Executable;I)Z", |
406 (void*)&WB_IsMethodCompilable}, | 431 (void*)&WB_IsMethodCompilable}, |
407 {CC"isMethodQueuedForCompilation", | 432 {CC"isMethodQueuedForCompilation", |
408 CC"(Ljava/lang/reflect/Method;)Z", (void*)&WB_IsMethodQueuedForCompilation}, | 433 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation}, |
409 {CC"makeMethodNotCompilable", | 434 {CC"makeMethodNotCompilable", |
410 CC"(Ljava/lang/reflect/Method;)V", (void*)&WB_MakeMethodNotCompilable}, | 435 CC"(Ljava/lang/reflect/Executable;I)V", (void*)&WB_MakeMethodNotCompilable}, |
411 {CC"testSetDontInlineMethod", | 436 {CC"testSetDontInlineMethod", |
412 CC"(Ljava/lang/reflect/Method;Z)Z", (void*)&WB_TestSetDontInlineMethod}, | 437 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod}, |
413 {CC"getMethodCompilationLevel", | 438 {CC"getMethodCompilationLevel", |
414 CC"(Ljava/lang/reflect/Method;)I", (void*)&WB_GetMethodCompilationLevel}, | 439 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodCompilationLevel}, |
415 {CC"getCompileQueuesSize", | 440 {CC"getCompileQueuesSize", |
416 CC"()I", (void*)&WB_GetCompileQueuesSize}, | 441 CC"()I", (void*)&WB_GetCompileQueuesSize}, |
417 {CC"testSetForceInlineMethod", | 442 {CC"testSetForceInlineMethod", |
418 CC"(Ljava/lang/reflect/Method;Z)Z", (void*)&WB_TestSetForceInlineMethod}, | 443 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod}, |
419 {CC"enqueueMethodForCompilation", | 444 {CC"enqueueMethodForCompilation", |
420 CC"(Ljava/lang/reflect/Method;I)Z", (void*)&WB_EnqueueMethodForCompilation}, | 445 CC"(Ljava/lang/reflect/Executable;I)Z", (void*)&WB_EnqueueMethodForCompilation}, |
421 {CC"clearMethodState", | 446 {CC"clearMethodState", |
422 CC"(Ljava/lang/reflect/Method;)V", (void*)&WB_ClearMethodState}, | 447 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState}, |
423 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, | 448 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable }, |
424 {CC"fullGC", CC"()V", (void*)&WB_FullGC }, | 449 {CC"fullGC", CC"()V", (void*)&WB_FullGC }, |
450 | |
451 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory }, | |
425 }; | 452 }; |
426 | 453 |
427 #undef CC | 454 #undef CC |
428 | 455 |
429 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) | 456 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass)) |
431 if (WhiteBoxAPI) { | 458 if (WhiteBoxAPI) { |
432 // Make sure that wbclass is loaded by the null classloader | 459 // Make sure that wbclass is loaded by the null classloader |
433 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); | 460 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
434 Handle loader(ikh->class_loader()); | 461 Handle loader(ikh->class_loader()); |
435 if (loader.is_null()) { | 462 if (loader.is_null()) { |
463 ResourceMark rm; | |
436 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI | 464 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI |
437 jint result = env->RegisterNatives(wbclass, methods, sizeof(methods)/sizeof(methods[0])); | 465 bool result = true; |
438 if (result == 0) { | 466 // one by one registration natives for exception catching |
467 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); | |
468 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { | |
469 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { | |
470 result = false; | |
471 if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) { | |
472 // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native | |
473 // ignoring the exception | |
474 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); | |
475 env->ExceptionClear(); | |
476 } else { | |
477 // register is failed w/o exception or w/ unexpected exception | |
478 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", methods[i].name, methods[i].signature); | |
479 env->UnregisterNatives(wbclass); | |
480 break; | |
481 } | |
482 } | |
483 } | |
484 | |
485 if (result) { | |
439 WhiteBox::set_used(); | 486 WhiteBox::set_used(); |
440 } | 487 } |
441 } | 488 } |
442 } | 489 } |
443 } | 490 } |