90 assert(caller_frame.is_compiled_frame(), "must be compiled");
91 return caller_frame.is_deoptimized_frame();
92 }
93
94 // Stress deoptimization
95 static void deopt_caller() {
96 if ( !caller_is_deopted()) {
97 JavaThread* thread = JavaThread::current();
98 RegisterMap reg_map(thread, false);
99 frame runtime_frame = thread->last_frame();
100 frame caller_frame = runtime_frame.sender(®_map);
101 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
102 assert(caller_is_deopted(), "Must be deoptimized");
103 }
104 }
105
106 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance(JavaThread* thread, Klass* klass))
107 JRT_BLOCK;
108 assert(klass->is_klass(), "not a class");
109 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
110 instanceKlassHandle h(thread, klass);
111 h->check_valid_for_instantiation(true, CHECK);
112 // make sure klass is initialized
113 h->initialize(CHECK);
114 // allocate instance and return via TLS
115 oop obj = h->allocate_instance(CHECK);
116 thread->set_vm_result(obj);
117 JRT_BLOCK_END;
118
119 if (ReduceInitialCardMarks) {
120 new_store_pre_barrier(thread);
121 }
122 JRT_END
123
124 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length))
125 JRT_BLOCK;
126 // Note: no handle for klass needed since they are not used
127 // anymore after new_objArray() and no GC can happen before.
128 // (This may have to change if this code changes!)
129 assert(array_klass->is_klass(), "not a class");
130 oop obj;
131 if (array_klass->is_typeArray_klass()) {
132 BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();
133 obj = oopFactory::new_typeArray(elt_type, length, CHECK);
134 } else {
135 Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
170 "compiler must check this first");
171 // GC may decide to give back a safer copy of new_obj.
172 new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
173 thread->set_vm_result(new_obj);
174 }
175
176 JRT_ENTRY(void, JVMCIRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
177 assert(klass->is_klass(), "not a class");
178 assert(rank >= 1, "rank must be nonzero");
179 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
180 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
181 thread->set_vm_result(obj);
182 JRT_END
183
184 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array(JavaThread* thread, oopDesc* element_mirror, jint length))
185 oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
186 thread->set_vm_result(obj);
187 JRT_END
188
189 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror))
190 instanceKlassHandle klass(THREAD, java_lang_Class::as_Klass(type_mirror));
191
192 if (klass == NULL) {
193 ResourceMark rm(THREAD);
194 THROW(vmSymbols::java_lang_InstantiationException());
195 }
196
197 // Create new instance (the receiver)
198 klass->check_valid_for_instantiation(false, CHECK);
199
200 // Make sure klass gets initialized
201 klass->initialize(CHECK);
202
203 oop obj = klass->allocate_instance(CHECK);
204 thread->set_vm_result(obj);
205 JRT_END
206
207 extern void vm_exit(int code);
208
209 // Enter this method from compiled code handler below. This is where we transition
210 // to VM mode. This is done as a helper routine so that the method called directly
624 ResourceMark rm;
625 TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK);
626 TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK);
627 Handle jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK);
628 JavaValue result(T_OBJECT);
629 JavaCalls::call_virtual(&result, jvmciRuntime, HotSpotJVMCIRuntime::klass(), getCompiler, sig, CHECK);
630 }
631
632 // private static JVMCIRuntime JVMCI.initializeRuntime()
633 JVM_ENTRY(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c))
634 if (!EnableJVMCI) {
635 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled")
636 }
637 JVMCIRuntime::initialize_HotSpotJVMCIRuntime(CHECK_NULL);
638 jobject ret = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CHECK_NULL);
639 return ret;
640 JVM_END
641
642 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) {
643 TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle()));
644 KlassHandle klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
645 TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle()));
646 TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle()));
647 JavaValue result(T_OBJECT);
648 if (args == NULL) {
649 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_(Handle()));
650 } else {
651 JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle()));
652 }
653 return Handle(THREAD, (oop)result.get_jobject());
654 }
655
656 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
657 guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
658 JVMCIRuntime::initialize_well_known_classes(CHECK);
659 // This should only be called in the context of the JVMCI class being initialized
660 instanceKlassHandle klass = InstanceKlass::cast(SystemDictionary::JVMCI_klass());
661 guarantee(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
662 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
663
664 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
665 "runtime",
666 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
667 objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
668 if (trivial_prefixes != NULL) {
669 char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
670 for (int i = 0; i < trivial_prefixes->length(); i++) {
671 oop str = trivial_prefixes->obj_at(i);
672 if (str == NULL) {
673 THROW(vmSymbols::java_lang_NullPointerException());
674 } else {
675 prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
676 }
677 }
678 _trivial_prefixes = prefixes;
679 _trivial_prefixes_count = trivial_prefixes->length();
680 }
|
90 assert(caller_frame.is_compiled_frame(), "must be compiled");
91 return caller_frame.is_deoptimized_frame();
92 }
93
94 // Stress deoptimization
95 static void deopt_caller() {
96 if ( !caller_is_deopted()) {
97 JavaThread* thread = JavaThread::current();
98 RegisterMap reg_map(thread, false);
99 frame runtime_frame = thread->last_frame();
100 frame caller_frame = runtime_frame.sender(®_map);
101 Deoptimization::deoptimize_frame(thread, caller_frame.id(), Deoptimization::Reason_constraint);
102 assert(caller_is_deopted(), "Must be deoptimized");
103 }
104 }
105
106 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_instance(JavaThread* thread, Klass* klass))
107 JRT_BLOCK;
108 assert(klass->is_klass(), "not a class");
109 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
110 InstanceKlass* ik = InstanceKlass::cast(klass);
111 ik->check_valid_for_instantiation(true, CHECK);
112 // make sure klass is initialized
113 ik->initialize(CHECK);
114 // allocate instance and return via TLS
115 oop obj = ik->allocate_instance(CHECK);
116 thread->set_vm_result(obj);
117 JRT_BLOCK_END;
118
119 if (ReduceInitialCardMarks) {
120 new_store_pre_barrier(thread);
121 }
122 JRT_END
123
124 JRT_BLOCK_ENTRY(void, JVMCIRuntime::new_array(JavaThread* thread, Klass* array_klass, jint length))
125 JRT_BLOCK;
126 // Note: no handle for klass needed since they are not used
127 // anymore after new_objArray() and no GC can happen before.
128 // (This may have to change if this code changes!)
129 assert(array_klass->is_klass(), "not a class");
130 oop obj;
131 if (array_klass->is_typeArray_klass()) {
132 BasicType elt_type = TypeArrayKlass::cast(array_klass)->element_type();
133 obj = oopFactory::new_typeArray(elt_type, length, CHECK);
134 } else {
135 Handle holder(THREAD, array_klass->klass_holder()); // keep the klass alive
170 "compiler must check this first");
171 // GC may decide to give back a safer copy of new_obj.
172 new_obj = Universe::heap()->new_store_pre_barrier(thread, new_obj);
173 thread->set_vm_result(new_obj);
174 }
175
176 JRT_ENTRY(void, JVMCIRuntime::new_multi_array(JavaThread* thread, Klass* klass, int rank, jint* dims))
177 assert(klass->is_klass(), "not a class");
178 assert(rank >= 1, "rank must be nonzero");
179 Handle holder(THREAD, klass->klass_holder()); // keep the klass alive
180 oop obj = ArrayKlass::cast(klass)->multi_allocate(rank, dims, CHECK);
181 thread->set_vm_result(obj);
182 JRT_END
183
184 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_array(JavaThread* thread, oopDesc* element_mirror, jint length))
185 oop obj = Reflection::reflect_new_array(element_mirror, length, CHECK);
186 thread->set_vm_result(obj);
187 JRT_END
188
189 JRT_ENTRY(void, JVMCIRuntime::dynamic_new_instance(JavaThread* thread, oopDesc* type_mirror))
190 InstanceKlass* klass = InstanceKlass::cast(java_lang_Class::as_Klass(type_mirror));
191
192 if (klass == NULL) {
193 ResourceMark rm(THREAD);
194 THROW(vmSymbols::java_lang_InstantiationException());
195 }
196
197 // Create new instance (the receiver)
198 klass->check_valid_for_instantiation(false, CHECK);
199
200 // Make sure klass gets initialized
201 klass->initialize(CHECK);
202
203 oop obj = klass->allocate_instance(CHECK);
204 thread->set_vm_result(obj);
205 JRT_END
206
207 extern void vm_exit(int code);
208
209 // Enter this method from compiled code handler below. This is where we transition
210 // to VM mode. This is done as a helper routine so that the method called directly
624 ResourceMark rm;
625 TempNewSymbol getCompiler = SymbolTable::new_symbol("getCompiler", CHECK);
626 TempNewSymbol sig = SymbolTable::new_symbol("()Ljdk/vm/ci/runtime/JVMCICompiler;", CHECK);
627 Handle jvmciRuntime = JVMCIRuntime::get_HotSpotJVMCIRuntime(CHECK);
628 JavaValue result(T_OBJECT);
629 JavaCalls::call_virtual(&result, jvmciRuntime, HotSpotJVMCIRuntime::klass(), getCompiler, sig, CHECK);
630 }
631
632 // private static JVMCIRuntime JVMCI.initializeRuntime()
633 JVM_ENTRY(jobject, JVM_GetJVMCIRuntime(JNIEnv *env, jclass c))
634 if (!EnableJVMCI) {
635 THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), "JVMCI is not enabled")
636 }
637 JVMCIRuntime::initialize_HotSpotJVMCIRuntime(CHECK_NULL);
638 jobject ret = JVMCIRuntime::get_HotSpotJVMCIRuntime_jobject(CHECK_NULL);
639 return ret;
640 JVM_END
641
642 Handle JVMCIRuntime::callStatic(const char* className, const char* methodName, const char* signature, JavaCallArguments* args, TRAPS) {
643 TempNewSymbol name = SymbolTable::new_symbol(className, CHECK_(Handle()));
644 Klass* klass = SystemDictionary::resolve_or_fail(name, true, CHECK_(Handle()));
645 TempNewSymbol runtime = SymbolTable::new_symbol(methodName, CHECK_(Handle()));
646 TempNewSymbol sig = SymbolTable::new_symbol(signature, CHECK_(Handle()));
647 JavaValue result(T_OBJECT);
648 if (args == NULL) {
649 JavaCalls::call_static(&result, klass, runtime, sig, CHECK_(Handle()));
650 } else {
651 JavaCalls::call_static(&result, klass, runtime, sig, args, CHECK_(Handle()));
652 }
653 return Handle(THREAD, (oop)result.get_jobject());
654 }
655
656 void JVMCIRuntime::initialize_HotSpotJVMCIRuntime(TRAPS) {
657 guarantee(!_HotSpotJVMCIRuntime_initialized, "cannot reinitialize HotSpotJVMCIRuntime");
658 JVMCIRuntime::initialize_well_known_classes(CHECK);
659 // This should only be called in the context of the JVMCI class being initialized
660 InstanceKlass* klass = SystemDictionary::JVMCI_klass();
661 guarantee(klass->is_being_initialized() && klass->is_reentrant_initialization(THREAD),
662 "HotSpotJVMCIRuntime initialization should only be triggered through JVMCI initialization");
663
664 Handle result = callStatic("jdk/vm/ci/hotspot/HotSpotJVMCIRuntime",
665 "runtime",
666 "()Ljdk/vm/ci/hotspot/HotSpotJVMCIRuntime;", NULL, CHECK);
667 objArrayOop trivial_prefixes = HotSpotJVMCIRuntime::trivialPrefixes(result);
668 if (trivial_prefixes != NULL) {
669 char** prefixes = NEW_C_HEAP_ARRAY(char*, trivial_prefixes->length(), mtCompiler);
670 for (int i = 0; i < trivial_prefixes->length(); i++) {
671 oop str = trivial_prefixes->obj_at(i);
672 if (str == NULL) {
673 THROW(vmSymbols::java_lang_NullPointerException());
674 } else {
675 prefixes[i] = strdup(java_lang_String::as_utf8_string(str));
676 }
677 }
678 _trivial_prefixes = prefixes;
679 _trivial_prefixes_count = trivial_prefixes->length();
680 }
|