16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include "memory/universe.hpp"
28 #include "oops/oop.inline.hpp"
29
30 #include "classfile/symbolTable.hpp"
31 #include "classfile/classLoaderData.hpp"
32
33 #include "prims/whitebox.hpp"
34 #include "prims/wbtestmethods/parserTests.hpp"
35
36 #include "runtime/arguments.hpp"
37 #include "runtime/interfaceSupport.hpp"
38 #include "runtime/os.hpp"
39 #include "utilities/debug.hpp"
40 #include "utilities/macros.hpp"
41 #include "utilities/exceptions.hpp"
42
43 #if INCLUDE_ALL_GCS
44 #include "gc_implementation/g1/concurrentMark.hpp"
45 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
46 #include "gc_implementation/g1/heapRegionRemSet.hpp"
47 #endif // INCLUDE_ALL_GCS
48
49 #ifdef INCLUDE_NMT
50 #include "services/memTracker.hpp"
51 #endif // INCLUDE_NMT
52
53 #include "compiler/compileBroker.hpp"
54 #include "runtime/compilationPolicy.hpp"
55
56 #define SIZE_T_MAX_VALUE ((size_t) -1)
57
58 bool WhiteBox::_used = false;
472 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
473 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
474 Universe::heap()->collect(GCCause::_last_ditch_collection);
475 WB_END
476
477
478 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
479 // static+volatile in order to force the read to happen
480 // (not be eliminated by the compiler)
481 static char c;
482 static volatile char* p;
483
484 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
485 if (p == NULL) {
486 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
487 }
488
489 c = *p;
490 WB_END
491
492 //Some convenience methods to deal with objects from java
493 int WhiteBox::offset_for_field(const char* field_name, oop object,
494 Symbol* signature_symbol) {
495 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
496 Thread* THREAD = Thread::current();
497
498 //Get the class of our object
499 Klass* arg_klass = object->klass();
500 //Turn it into an instance-klass
501 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
502
503 //Create symbols to look for in the class
504 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
505 THREAD);
506
507 //To be filled in with an offset of the field we're looking for
508 fieldDescriptor fd;
509
510 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
511 if (res == NULL) {
583 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation},
584 {CC"makeMethodNotCompilable",
585 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable},
586 {CC"testSetDontInlineMethod",
587 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod},
588 {CC"getMethodCompilationLevel",
589 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel},
590 {CC"getMethodEntryBci",
591 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci},
592 {CC"getCompileQueueSize",
593 CC"(I)I", (void*)&WB_GetCompileQueueSize},
594 {CC"testSetForceInlineMethod",
595 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod},
596 {CC"enqueueMethodForCompilation",
597 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
598 {CC"clearMethodState",
599 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
600 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
601 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
602 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
603 };
604
605 #undef CC
606
607 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
608 {
609 if (WhiteBoxAPI) {
610 // Make sure that wbclass is loaded by the null classloader
611 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
612 Handle loader(ikh->class_loader());
613 if (loader.is_null()) {
614 ResourceMark rm;
615 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
616 bool result = true;
617 // one by one registration natives for exception catching
618 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
619 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
620 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
621 result = false;
622 if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) {
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26
27 #include "memory/universe.hpp"
28 #include "oops/oop.inline.hpp"
29
30 #include "classfile/symbolTable.hpp"
31 #include "classfile/classLoaderData.hpp"
32
33 #include "prims/whitebox.hpp"
34 #include "prims/wbtestmethods/parserTests.hpp"
35
36 #include "runtime/thread.hpp"
37 #include "runtime/arguments.hpp"
38 #include "runtime/interfaceSupport.hpp"
39 #include "runtime/os.hpp"
40
41 #include "utilities/debug.hpp"
42 #include "utilities/macros.hpp"
43 #include "utilities/exceptions.hpp"
44
45 #if INCLUDE_ALL_GCS
46 #include "gc_implementation/g1/concurrentMark.hpp"
47 #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
48 #include "gc_implementation/g1/heapRegionRemSet.hpp"
49 #endif // INCLUDE_ALL_GCS
50
51 #ifdef INCLUDE_NMT
52 #include "services/memTracker.hpp"
53 #endif // INCLUDE_NMT
54
55 #include "compiler/compileBroker.hpp"
56 #include "runtime/compilationPolicy.hpp"
57
58 #define SIZE_T_MAX_VALUE ((size_t) -1)
59
60 bool WhiteBox::_used = false;
474 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
475 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
476 Universe::heap()->collect(GCCause::_last_ditch_collection);
477 WB_END
478
479
480 WB_ENTRY(void, WB_ReadReservedMemory(JNIEnv* env, jobject o))
481 // static+volatile in order to force the read to happen
482 // (not be eliminated by the compiler)
483 static char c;
484 static volatile char* p;
485
486 p = os::reserve_memory(os::vm_allocation_granularity(), NULL, 0);
487 if (p == NULL) {
488 THROW_MSG(vmSymbols::java_lang_OutOfMemoryError(), "Failed to reserve memory");
489 }
490
491 c = *p;
492 WB_END
493
494 WB_ENTRY(jlong, WB_GetThreadFullStackSize(JNIEnv* env, jobject o))
495 return (jlong) Thread::current()->stack_size();
496 WB_END
497
498 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
499 JavaThread* t = JavaThread::current();
500 return (jlong) ( (ptrdiff_t) t->stack_available(os::current_stack_pointer()) - StackShadowPages * os::vm_page_size() );
501 WB_END
502
503 //Some convenience methods to deal with objects from java
504 int WhiteBox::offset_for_field(const char* field_name, oop object,
505 Symbol* signature_symbol) {
506 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
507 Thread* THREAD = Thread::current();
508
509 //Get the class of our object
510 Klass* arg_klass = object->klass();
511 //Turn it into an instance-klass
512 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
513
514 //Create symbols to look for in the class
515 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
516 THREAD);
517
518 //To be filled in with an offset of the field we're looking for
519 fieldDescriptor fd;
520
521 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
522 if (res == NULL) {
594 CC"(Ljava/lang/reflect/Executable;)Z", (void*)&WB_IsMethodQueuedForCompilation},
595 {CC"makeMethodNotCompilable",
596 CC"(Ljava/lang/reflect/Executable;IZ)V", (void*)&WB_MakeMethodNotCompilable},
597 {CC"testSetDontInlineMethod",
598 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod},
599 {CC"getMethodCompilationLevel",
600 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel},
601 {CC"getMethodEntryBci",
602 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci},
603 {CC"getCompileQueueSize",
604 CC"(I)I", (void*)&WB_GetCompileQueueSize},
605 {CC"testSetForceInlineMethod",
606 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod},
607 {CC"enqueueMethodForCompilation",
608 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
609 {CC"clearMethodState",
610 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
611 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
612 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
613 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
614 {CC"getThreadFullStackSize", CC"()J", (void*)&WB_GetThreadFullStackSize },
615 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
616 };
617
618 #undef CC
619
620 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
621 {
622 if (WhiteBoxAPI) {
623 // Make sure that wbclass is loaded by the null classloader
624 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
625 Handle loader(ikh->class_loader());
626 if (loader.is_null()) {
627 ResourceMark rm;
628 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
629 bool result = true;
630 // one by one registration natives for exception catching
631 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
632 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
633 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
634 result = false;
635 if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) {
|