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;
557 return result;
558 }
559
560 clazz = env->FindClass(vmSymbols::java_lang_Integer()->as_C_string());
561 CHECK_JNI_EXCEPTION_(env, NULL);
562 jmethodID constructor = env->GetMethodID(clazz, vmSymbols::object_initializer_name()->as_C_string(), vmSymbols::int_void_signature()->as_C_string());
563 CHECK_JNI_EXCEPTION_(env, NULL);
564 jobject obj = env->NewObject(clazz, constructor, code->comp_level());
565 CHECK_JNI_EXCEPTION_(env, NULL);
566 env->SetObjectArrayElement(result, 0, obj);
567
568 jbyteArray insts = env->NewByteArray(insts_size);
569 CHECK_JNI_EXCEPTION_(env, NULL);
570 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
571 env->SetObjectArrayElement(result, 1, insts);
572
573 return result;
574 WB_END
575
576
577 //Some convenience methods to deal with objects from java
578 int WhiteBox::offset_for_field(const char* field_name, oop object,
579 Symbol* signature_symbol) {
580 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
581 Thread* THREAD = Thread::current();
582
583 //Get the class of our object
584 Klass* arg_klass = object->klass();
585 //Turn it into an instance-klass
586 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
587
588 //Create symbols to look for in the class
589 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
590 THREAD);
591
592 //To be filled in with an offset of the field we're looking for
593 fieldDescriptor fd;
594
595 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
596 if (res == NULL) {
671 {CC"testSetDontInlineMethod",
672 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod},
673 {CC"getMethodCompilationLevel",
674 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel},
675 {CC"getMethodEntryBci",
676 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci},
677 {CC"getCompileQueueSize",
678 CC"(I)I", (void*)&WB_GetCompileQueueSize},
679 {CC"testSetForceInlineMethod",
680 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod},
681 {CC"enqueueMethodForCompilation",
682 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
683 {CC"clearMethodState",
684 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
685 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
686 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
687 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
688 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
689 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
690 (void*)&WB_GetNMethod },
691 };
692
693 #undef CC
694
695 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
696 {
697 if (WhiteBoxAPI) {
698 // Make sure that wbclass is loaded by the null classloader
699 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
700 Handle loader(ikh->class_loader());
701 if (loader.is_null()) {
702 ResourceMark rm;
703 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
704 bool result = true;
705 // one by one registration natives for exception catching
706 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
707 CHECK_JNI_EXCEPTION(env);
708 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
709 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
710 result = false;
|
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;
559 return result;
560 }
561
562 clazz = env->FindClass(vmSymbols::java_lang_Integer()->as_C_string());
563 CHECK_JNI_EXCEPTION_(env, NULL);
564 jmethodID constructor = env->GetMethodID(clazz, vmSymbols::object_initializer_name()->as_C_string(), vmSymbols::int_void_signature()->as_C_string());
565 CHECK_JNI_EXCEPTION_(env, NULL);
566 jobject obj = env->NewObject(clazz, constructor, code->comp_level());
567 CHECK_JNI_EXCEPTION_(env, NULL);
568 env->SetObjectArrayElement(result, 0, obj);
569
570 jbyteArray insts = env->NewByteArray(insts_size);
571 CHECK_JNI_EXCEPTION_(env, NULL);
572 env->SetByteArrayRegion(insts, 0, insts_size, (jbyte*) code->insts_begin());
573 env->SetObjectArrayElement(result, 1, insts);
574
575 return result;
576 WB_END
577
578
579 WB_ENTRY(jlong, WB_GetThreadFullStackSize(JNIEnv* env, jobject o))
580 return (jlong) Thread::current()->stack_size();
581 WB_END
582
583 WB_ENTRY(jlong, WB_GetThreadRemainingStackSize(JNIEnv* env, jobject o))
584 JavaThread* t = JavaThread::current();
585 return (jlong) ((ptrdiff_t) t->stack_available(os::current_stack_pointer()) - StackShadowPages * os::vm_page_size());
586 WB_END
587
588 //Some convenience methods to deal with objects from java
589 int WhiteBox::offset_for_field(const char* field_name, oop object,
590 Symbol* signature_symbol) {
591 assert(field_name != NULL && strlen(field_name) > 0, "Field name not valid");
592 Thread* THREAD = Thread::current();
593
594 //Get the class of our object
595 Klass* arg_klass = object->klass();
596 //Turn it into an instance-klass
597 InstanceKlass* ik = InstanceKlass::cast(arg_klass);
598
599 //Create symbols to look for in the class
600 TempNewSymbol name_symbol = SymbolTable::lookup(field_name, (int) strlen(field_name),
601 THREAD);
602
603 //To be filled in with an offset of the field we're looking for
604 fieldDescriptor fd;
605
606 Klass* res = ik->find_field(name_symbol, signature_symbol, &fd);
607 if (res == NULL) {
682 {CC"testSetDontInlineMethod",
683 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetDontInlineMethod},
684 {CC"getMethodCompilationLevel",
685 CC"(Ljava/lang/reflect/Executable;Z)I", (void*)&WB_GetMethodCompilationLevel},
686 {CC"getMethodEntryBci",
687 CC"(Ljava/lang/reflect/Executable;)I", (void*)&WB_GetMethodEntryBci},
688 {CC"getCompileQueueSize",
689 CC"(I)I", (void*)&WB_GetCompileQueueSize},
690 {CC"testSetForceInlineMethod",
691 CC"(Ljava/lang/reflect/Executable;Z)Z", (void*)&WB_TestSetForceInlineMethod},
692 {CC"enqueueMethodForCompilation",
693 CC"(Ljava/lang/reflect/Executable;II)Z", (void*)&WB_EnqueueMethodForCompilation},
694 {CC"clearMethodState",
695 CC"(Ljava/lang/reflect/Executable;)V", (void*)&WB_ClearMethodState},
696 {CC"isInStringTable", CC"(Ljava/lang/String;)Z", (void*)&WB_IsInStringTable },
697 {CC"fullGC", CC"()V", (void*)&WB_FullGC },
698 {CC"readReservedMemory", CC"()V", (void*)&WB_ReadReservedMemory },
699 {CC"getCPUFeatures", CC"()Ljava/lang/String;", (void*)&WB_GetCPUFeatures },
700 {CC"getNMethod", CC"(Ljava/lang/reflect/Executable;Z)[Ljava/lang/Object;",
701 (void*)&WB_GetNMethod },
702 {CC"getThreadFullStackSize", CC"()J", (void*)&WB_GetThreadFullStackSize },
703 {CC"getThreadRemainingStackSize", CC"()J", (void*)&WB_GetThreadRemainingStackSize },
704 };
705
706 #undef CC
707
708 JVM_ENTRY(void, JVM_RegisterWhiteBoxMethods(JNIEnv* env, jclass wbclass))
709 {
710 if (WhiteBoxAPI) {
711 // Make sure that wbclass is loaded by the null classloader
712 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
713 Handle loader(ikh->class_loader());
714 if (loader.is_null()) {
715 ResourceMark rm;
716 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
717 bool result = true;
718 // one by one registration natives for exception catching
719 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
720 CHECK_JNI_EXCEPTION(env);
721 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
722 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
723 result = false;
|