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