37 #include "memory/resourceArea.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "oops/objArrayOop.inline.hpp"
40 #include "prims/jvm.h"
41 #include "runtime/biasedLocking.hpp"
42 #include "runtime/interfaceSupport.hpp"
43 #include "runtime/reflection.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "utilities/debug.hpp"
46 #include "utilities/defaultStream.hpp"
47
48 #if defined(_MSC_VER)
49 #define strtoll _strtoi64
50 #endif
51
52 jobject JVMCIRuntime::_HotSpotJVMCIRuntime_instance = NULL;
53 bool JVMCIRuntime::_HotSpotJVMCIRuntime_initialized = false;
54 bool JVMCIRuntime::_well_known_classes_initialized = false;
55 int JVMCIRuntime::_trivial_prefixes_count = 0;
56 char** JVMCIRuntime::_trivial_prefixes = NULL;
57 bool JVMCIRuntime::_shutdown_called = false;
58
59 BasicType JVMCIRuntime::kindToBasicType(Handle kind, TRAPS) {
60 if (kind.is_null()) {
61 THROW_(vmSymbols::java_lang_NullPointerException(), T_ILLEGAL);
62 }
63 jchar ch = JavaKind::typeChar(kind);
64 switch(ch) {
65 case 'z': return T_BOOLEAN;
66 case 'b': return T_BYTE;
67 case 's': return T_SHORT;
68 case 'c': return T_CHAR;
69 case 'i': return T_INT;
70 case 'f': return T_FLOAT;
71 case 'j': return T_LONG;
72 case 'd': return T_DOUBLE;
73 case 'a': return T_OBJECT;
74 case '-': return T_ILLEGAL;
75 default:
76 JVMCI_ERROR_(T_ILLEGAL, "unexpected Kind: %c", ch);
649 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
650 #endif
651
652 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
653 "runtime",
654 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
655 objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
656 if (trivial_prefixes != NULL) {
657 char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
658 for (int i = 0; i < trivial_prefixes->length(); i++) {
659 oop str = trivial_prefixes->obj_at(i);
660 if (str == NULL) {
661 THROW(vmSymbols::java_lang_NullPointerException());
662 } else {
663 prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
664 }
665 }
666 _trivial_prefixes = prefixes;
667 _trivial_prefixes_count = trivial_prefixes->length();
668 }
669 _HotSpotJVMCIRuntime_initialized = true;
670 _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
671 }
672 }
673
674 void JVMCIRuntime::initialize_JVMCI(TRAPS) {
675 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
676 callStatic("jdk/vm/ci/runtime/JVMCI",
677 "getRuntime",
678 "()Ljdk/vm/ci/runtime/JVMCIRuntime;", NULL, CHECK);
679 }
680 assert(_HotSpotJVMCIRuntime_initialized == true, "what?");
681 }
682
683 void JVMCIRuntime::initialize_well_known_classes(TRAPS) {
684 if (JVMCIRuntime::_well_known_classes_initialized == false) {
685 SystemDictionary::WKID scan = SystemDictionary::FIRST_JVMCI_WKID;
686 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_JVMCI_WKID, scan, CHECK);
687 JVMCIJavaClasses::compute_offsets(CHECK);
688 JVMCIRuntime::_well_known_classes_initialized = true;
786 warning(message); \
787 char buf[512]; \
788 jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
789 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
790 return; \
791 } \
792 (void)(0
793
794 void JVMCIRuntime::shutdown(TRAPS) {
795 if (_HotSpotJVMCIRuntime_instance != NULL) {
796 _shutdown_called = true;
797 HandleMark hm(THREAD);
798 Handle receiver = get_HotSpotJVMCIRuntime(CHECK);
799 JavaValue result(T_VOID);
800 JavaCallArguments args;
801 args.push_oop(receiver);
802 JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK);
803 }
804 }
805
806 bool JVMCIRuntime::treat_as_trivial(Method* method) {
807 if (_HotSpotJVMCIRuntime_initialized) {
808 for (int i = 0; i < _trivial_prefixes_count; i++) {
809 if (method->method_holder()->name()->starts_with(_trivial_prefixes[i])) {
810 return true;
811 }
812 }
813 }
814 return false;
815 }
|
37 #include "memory/resourceArea.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "oops/objArrayOop.inline.hpp"
40 #include "prims/jvm.h"
41 #include "runtime/biasedLocking.hpp"
42 #include "runtime/interfaceSupport.hpp"
43 #include "runtime/reflection.hpp"
44 #include "runtime/sharedRuntime.hpp"
45 #include "utilities/debug.hpp"
46 #include "utilities/defaultStream.hpp"
47
48 #if defined(_MSC_VER)
49 #define strtoll _strtoi64
50 #endif
51
52 jobject JVMCIRuntime::_HotSpotJVMCIRuntime_instance = NULL;
53 bool JVMCIRuntime::_HotSpotJVMCIRuntime_initialized = false;
54 bool JVMCIRuntime::_well_known_classes_initialized = false;
55 int JVMCIRuntime::_trivial_prefixes_count = 0;
56 char** JVMCIRuntime::_trivial_prefixes = NULL;
57 JVMCIRuntime::CompLevelAdjustment JVMCIRuntime::_comp_level_adjustment = JVMCIRuntime::none;
58 bool JVMCIRuntime::_shutdown_called = false;
59
60 BasicType JVMCIRuntime::kindToBasicType(Handle kind, TRAPS) {
61 if (kind.is_null()) {
62 THROW_(vmSymbols::java_lang_NullPointerException(), T_ILLEGAL);
63 }
64 jchar ch = JavaKind::typeChar(kind);
65 switch(ch) {
66 case 'z': return T_BOOLEAN;
67 case 'b': return T_BYTE;
68 case 's': return T_SHORT;
69 case 'c': return T_CHAR;
70 case 'i': return T_INT;
71 case 'f': return T_FLOAT;
72 case 'j': return T_LONG;
73 case 'd': return T_DOUBLE;
74 case 'a': return T_OBJECT;
75 case '-': return T_ILLEGAL;
76 default:
77 JVMCI_ERROR_(T_ILLEGAL, "unexpected Kind: %c", ch);
650 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
651 #endif
652
653 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
654 "runtime",
655 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
656 objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
657 if (trivial_prefixes != NULL) {
658 char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
659 for (int i = 0; i < trivial_prefixes->length(); i++) {
660 oop str = trivial_prefixes->obj_at(i);
661 if (str == NULL) {
662 THROW(vmSymbols::java_lang_NullPointerException());
663 } else {
664 prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
665 }
666 }
667 _trivial_prefixes = prefixes;
668 _trivial_prefixes_count = trivial_prefixes->length();
669 }
670 int adjustment = HotSpotJVMCIRuntime::compilationLevelAdjustment(result);
671 assert(adjustment >= JVMCIRuntime::none &&
672 adjustment <= JVMCIRuntime::by_full_signature,
673 "compilation level adjustment out of bounds");
674 _comp_level_adjustment = (CompLevelAdjustment) adjustment;
675 _HotSpotJVMCIRuntime_initialized = true;
676 _HotSpotJVMCIRuntime_instance = JNIHandles::make_global(result());
677 }
678 }
679
680 void JVMCIRuntime::initialize_JVMCI(TRAPS) {
681 if (JNIHandles::resolve(_HotSpotJVMCIRuntime_instance) == NULL) {
682 callStatic("jdk/vm/ci/runtime/JVMCI",
683 "getRuntime",
684 "()Ljdk/vm/ci/runtime/JVMCIRuntime;", NULL, CHECK);
685 }
686 assert(_HotSpotJVMCIRuntime_initialized == true, "what?");
687 }
688
689 void JVMCIRuntime::initialize_well_known_classes(TRAPS) {
690 if (JVMCIRuntime::_well_known_classes_initialized == false) {
691 SystemDictionary::WKID scan = SystemDictionary::FIRST_JVMCI_WKID;
692 SystemDictionary::initialize_wk_klasses_through(SystemDictionary::LAST_JVMCI_WKID, scan, CHECK);
693 JVMCIJavaClasses::compute_offsets(CHECK);
694 JVMCIRuntime::_well_known_classes_initialized = true;
792 warning(message); \
793 char buf[512]; \
794 jio_snprintf(buf, 512, "Uncaught exception at %s:%d", __FILE__, __LINE__); \
795 JVMCIRuntime::abort_on_pending_exception(PENDING_EXCEPTION, buf); \
796 return; \
797 } \
798 (void)(0
799
800 void JVMCIRuntime::shutdown(TRAPS) {
801 if (_HotSpotJVMCIRuntime_instance != NULL) {
802 _shutdown_called = true;
803 HandleMark hm(THREAD);
804 Handle receiver = get_HotSpotJVMCIRuntime(CHECK);
805 JavaValue result(T_VOID);
806 JavaCallArguments args;
807 args.push_oop(receiver);
808 JavaCalls::call_special(&result, receiver->klass(), vmSymbols::shutdown_method_name(), vmSymbols::void_method_signature(), &args, CHECK);
809 }
810 }
811
812 CompLevel JVMCIRuntime::adjust_comp_level_inner(methodHandle method, bool is_osr, CompLevel level, JavaThread* thread) {
813 JVMCICompiler* compiler = JVMCICompiler::instance(thread);
814 if (compiler != NULL && compiler->is_bootstrapping()) {
815 return level;
816 }
817 if (!is_HotSpotJVMCIRuntime_initialized() || !_comp_level_adjustment) {
818 // JVMCI cannot participate in compilation scheduling until
819 // JVMCI is initialized and indicates it wants to participate.
820 return level;
821 }
822
823 #define CHECK_RETURN THREAD); \
824 if (HAS_PENDING_EXCEPTION) { \
825 Handle exception(THREAD, PENDING_EXCEPTION); \
826 CLEAR_PENDING_EXCEPTION; \
827 \
828 java_lang_Throwable::java_printStackTrace(exception, THREAD); \
829 if (HAS_PENDING_EXCEPTION) { \
830 CLEAR_PENDING_EXCEPTION; \
831 } \
832 return level; \
833 } \
834 (void)(0
835
836
837 Thread* THREAD = thread;
838 HandleMark hm;
839 Handle receiver = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK_RETURN);
840 Handle name;
841 Handle sig;
842 if (_comp_level_adjustment == JVMCIRuntime::by_full_signature) {
843 name = java_lang_String::create_from_symbol(method->name(), CHECK_RETURN);
844 sig = java_lang_String::create_from_symbol(method->signature(), CHECK_RETURN);
845 } else {
846 name = Handle();
847 sig = Handle();
848 }
849
850 JavaValue result(T_INT);
851 JavaCallArguments args;
852 args.push_oop(receiver);
853 args.push_oop(method->method_holder()->java_mirror());
854 args.push_oop(name());
855 args.push_oop(sig());
856 args.push_int(is_osr);
857 args.push_int(level);
858 JavaCalls::call_special(&result, receiver->klass(), vmSymbols::adjustCompilationLevel_name(),
859 vmSymbols::adjustCompilationLevel_signature(), &args, CHECK_RETURN);
860
861 int comp_level = result.get_jint();
862 if (comp_level < CompLevel_none || comp_level > CompLevel_full_optimization) {
863 assert(false, "compilation level out of bounds");
864 return level;
865 }
866 return (CompLevel) comp_level;
867 #undef CHECK_RETURN
868 }
869
870 bool JVMCIRuntime::treat_as_trivial(Method* method) {
871 if (_HotSpotJVMCIRuntime_initialized) {
872 for (int i = 0; i < _trivial_prefixes_count; i++) {
873 if (method->method_holder()->name()->starts_with(_trivial_prefixes[i])) {
874 return true;
875 }
876 }
877 }
878 return false;
879 }
|