Mercurial > hg > graal-compiler
comparison src/share/vm/graal/graalVMEntries.cpp @ 3555:22d11b3bc561
Various hacks to be able to install machine code from a Java thread.
author | Thomas Wuerthinger <thomas@wuerthinger.net> |
---|---|
date | Wed, 24 Aug 2011 01:05:02 +0200 |
parents | aa7b62997aa0 |
children | f70a4cc629e7 |
comparison
equal
deleted
inserted
replaced
3554:b20889b42d12 | 3555:22d11b3bc561 |
---|---|
141 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); | 141 cimethod = (ciMethod*)CURRENT_ENV->get_object(method); |
142 } | 142 } |
143 return cimethod->has_balanced_monitors(); | 143 return cimethod->has_balanced_monitors(); |
144 } | 144 } |
145 | 145 |
146 // public RiMethod getRiMethod(java.lang.reflect.Method reflectionMethod); | |
147 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_getRiMethod(JNIEnv *, jobject, jobject reflection_method_handle) { | |
148 TRACE_graal_3("VMEntries::getRiMethod"); | |
149 VM_ENTRY_MARK; | |
150 oop reflection_method = JNIHandles::resolve(reflection_method_handle); | |
151 oop reflection_holder = java_lang_reflect_Method::clazz(reflection_method); | |
152 int slot = java_lang_reflect_Method::slot(reflection_method); | |
153 klassOop holder = java_lang_Class::as_klassOop(reflection_holder); | |
154 methodOop method = instanceKlass::cast(holder)->method_with_idnum(slot); | |
155 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); | |
156 return JNIHandles::make_local(THREAD, ret); | |
157 } | |
158 | |
146 // public boolean RiMethod_uniqueConcreteMethod(long vmId); | 159 // public boolean RiMethod_uniqueConcreteMethod(long vmId); |
147 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jobject hotspot_method) { | 160 JNIEXPORT jobject JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod(JNIEnv *, jobject, jobject hotspot_method) { |
148 TRACE_graal_3("VMEntries::RiMethod_uniqueConcreteMethod"); | 161 TRACE_graal_3("VMEntries::RiMethod_uniqueConcreteMethod"); |
149 VM_ENTRY_MARK; | 162 VM_ENTRY_MARK; |
150 methodOop m = getMethodFromHotSpotMethod(hotspot_method); | 163 methodOop m = getMethodFromHotSpotMethod(hotspot_method); |
169 } | 182 } |
170 if (unique_concrete.is_null()) { | 183 if (unique_concrete.is_null()) { |
171 return NULL; | 184 return NULL; |
172 } | 185 } |
173 | 186 |
174 Handle name = VmIds::toString<Handle>(unique_concrete->name(), CHECK_NULL); | 187 oop method_resolved = GraalCompiler::createHotSpotMethodResolved(unique_concrete(), CHECK_NULL); |
175 oop method_resolved = GraalCompiler::createHotSpotMethodResolved(unique_concrete(), name, CHECK_NULL); | |
176 return JNIHandles::make_local(THREAD, method_resolved); | 188 return JNIHandles::make_local(THREAD, method_resolved); |
177 } | 189 } |
178 | 190 |
179 // public native int RiMethod_invocationCount(long vmId); | 191 // public native int RiMethod_invocationCount(long vmId); |
180 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) { | 192 JNIEXPORT jint JNICALL Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount(JNIEnv *, jobject, jobject hotspot_method) { |
460 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF); | 472 Bytecodes::Code bc = (Bytecodes::Code) (((int) byteCode) & 0xFF); |
461 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder()); | 473 ciInstanceKlass* loading_klass = (ciInstanceKlass *) CURRENT_ENV->get_object(cp->pool_holder()); |
462 ciMethod *cimethod = CURRENT_ENV->get_method_by_index(cp, index, bc, loading_klass); | 474 ciMethod *cimethod = CURRENT_ENV->get_method_by_index(cp, index, bc, loading_klass); |
463 if (cimethod->is_loaded()) { | 475 if (cimethod->is_loaded()) { |
464 methodOop method = (methodOop) cimethod->get_oop(); | 476 methodOop method = (methodOop) cimethod->get_oop(); |
465 Handle name = VmIds::toString<Handle>(method->name(), CHECK_NULL); | 477 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); |
466 oop ret = GraalCompiler::createHotSpotMethodResolved(method, name, CHECK_NULL); | |
467 return JNIHandles::make_local(THREAD, ret); | 478 return JNIHandles::make_local(THREAD, ret); |
468 } else { | 479 } else { |
469 Handle name = VmIds::toString<Handle>(cimethod->name()->get_symbol(), CHECK_NULL); | 480 Handle name = VmIds::toString<Handle>(cimethod->name()->get_symbol(), CHECK_NULL); |
470 Handle signature = VmIds::toString<Handle>(cimethod->signature()->as_symbol()->get_symbol(), CHECK_NULL); | 481 Handle signature = VmIds::toString<Handle>(cimethod->signature()->as_symbol()->get_symbol(), CHECK_NULL); |
471 Handle holder = GraalCompiler::get_RiType(cimethod->holder(), cp->klass(), THREAD); | 482 Handle holder = GraalCompiler::get_RiType(cimethod->holder(), cp->klass(), THREAD); |
582 ResourceMark rm; | 593 ResourceMark rm; |
583 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->klass_part()->name()->as_C_string()); | 594 tty->print_cr("Could not resolve method %s %s on klass %s", name_symbol->as_C_string(), signature_symbol->as_C_string(), klass->klass_part()->name()->as_C_string()); |
584 } | 595 } |
585 return NULL; | 596 return NULL; |
586 } | 597 } |
587 oop ret = GraalCompiler::createHotSpotMethodResolved(method, Handle(JNIHandles::resolve(name)), CHECK_NULL); | 598 oop ret = GraalCompiler::createHotSpotMethodResolved(method, CHECK_NULL); |
588 return JNIHandles::make_local(THREAD, ret); | 599 return JNIHandles::make_local(THREAD, ret); |
589 } | 600 } |
590 | 601 |
591 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other); | 602 // public boolean RiType_isSubtypeOf(HotSpotTypeResolved klass, RiType other); |
592 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) { | 603 JNIEXPORT jboolean JNICALL Java_com_oracle_graal_runtime_VMEntries_RiType_2isSubtypeOf(JNIEnv *, jobject, jobject klass, jobject jother) { |
856 } | 867 } |
857 | 868 |
858 // public void installMethod(HotSpotTargetMethod targetMethod); | 869 // public void installMethod(HotSpotTargetMethod targetMethod); |
859 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod) { | 870 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod) { |
860 VM_ENTRY_MARK; | 871 VM_ENTRY_MARK; |
861 CodeInstaller installer(JNIHandles::resolve(targetMethod)); | 872 if (CURRENT_ENV == NULL) { |
873 Arena arena; | |
874 ciEnv env(&arena); | |
875 CodeInstaller installer(JNIHandles::resolve(targetMethod)); | |
876 } else { | |
877 CodeInstaller installer(JNIHandles::resolve(targetMethod)); | |
878 } | |
862 } | 879 } |
863 | 880 |
864 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name); | 881 // public HotSpotProxy installStub(HotSpotTargetMethod targetMethod, String name); |
865 JNIEXPORT jlong JNICALL Java_com_oracle_graal_runtime_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) { | 882 JNIEXPORT jlong JNICALL Java_com_oracle_graal_runtime_VMEntries_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) { |
866 VM_ENTRY_MARK; | 883 VM_ENTRY_MARK; |
867 jlong id; | 884 jlong id; |
868 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); | 885 if (CURRENT_ENV == NULL) { |
886 Arena arena; | |
887 ciEnv env(&arena); | |
888 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); | |
889 } else { | |
890 CodeInstaller installer(JNIHandles::resolve(targetMethod), id); | |
891 } | |
869 return id; | 892 return id; |
870 } | 893 } |
871 | 894 |
872 // public void recordBailout(String reason); | 895 // public void recordBailout(String reason); |
873 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_recordBailout(JNIEnv *jniEnv, jobject, jobject message) { | 896 JNIEXPORT void JNICALL Java_com_oracle_graal_runtime_VMEntries_recordBailout(JNIEnv *jniEnv, jobject, jobject message) { |
889 #define PROXY "J" | 912 #define PROXY "J" |
890 #define TYPE "Lcom/sun/cri/ri/RiType;" | 913 #define TYPE "Lcom/sun/cri/ri/RiType;" |
891 #define RESOLVED_TYPE "Lcom/oracle/max/graal/runtime/HotSpotTypeResolved;" | 914 #define RESOLVED_TYPE "Lcom/oracle/max/graal/runtime/HotSpotTypeResolved;" |
892 #define METHOD "Lcom/sun/cri/ri/RiMethod;" | 915 #define METHOD "Lcom/sun/cri/ri/RiMethod;" |
893 #define RESOLVED_METHOD "Lcom/oracle/max/graal/runtime/HotSpotMethodResolved;" | 916 #define RESOLVED_METHOD "Lcom/oracle/max/graal/runtime/HotSpotMethodResolved;" |
917 #define REFLECT_METHOD "Ljava/lang/reflect/Method;" | |
894 #define TYPE_PROFILE "Lcom/sun/cri/ri/RiTypeProfile;" | 918 #define TYPE_PROFILE "Lcom/sun/cri/ri/RiTypeProfile;" |
895 #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;" | 919 #define SIGNATURE "Lcom/sun/cri/ri/RiSignature;" |
896 #define FIELD "Lcom/sun/cri/ri/RiField;" | 920 #define FIELD "Lcom/sun/cri/ri/RiField;" |
897 #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;" | 921 #define CONSTANT_POOL "Lcom/sun/cri/ri/RiConstantPool;" |
898 #define EXCEPTION_HANDLERS "[Lcom/sun/cri/ri/RiExceptionHandler;" | 922 #define EXCEPTION_HANDLERS "[Lcom/sun/cri/ri/RiExceptionHandler;" |
909 {CC"RiMethod_code", CC"("RESOLVED_METHOD")[B", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1code)}, | 933 {CC"RiMethod_code", CC"("RESOLVED_METHOD")[B", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1code)}, |
910 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature)}, | 934 {CC"RiMethod_signature", CC"("RESOLVED_METHOD")"STRING, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1signature)}, |
911 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)}, | 935 {CC"RiMethod_exceptionHandlers", CC"("RESOLVED_METHOD")"EXCEPTION_HANDLERS, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1exceptionHandlers)}, |
912 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)}, | 936 {CC"RiMethod_hasBalancedMonitors", CC"("RESOLVED_METHOD")Z", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1hasBalancedMonitors)}, |
913 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)}, | 937 {CC"RiMethod_uniqueConcreteMethod", CC"("RESOLVED_METHOD")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1uniqueConcreteMethod)}, |
938 {CC"getRiMethod", CC"("REFLECT_METHOD")"METHOD, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_getRiMethod)}, | |
914 {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile)}, | 939 {CC"RiMethod_typeProfile", CC"("RESOLVED_METHOD"I)"TYPE_PROFILE, FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2typeProfile)}, |
915 {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability)}, | 940 {CC"RiMethod_branchProbability", CC"("RESOLVED_METHOD"I)D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2branchProbability)}, |
916 {CC"RiMethod_switchProbability", CC"("RESOLVED_METHOD"I)[D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2switchProbability)}, | 941 {CC"RiMethod_switchProbability", CC"("RESOLVED_METHOD"I)[D", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2switchProbability)}, |
917 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount)}, | 942 {CC"RiMethod_invocationCount", CC"("RESOLVED_METHOD")I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_1invocationCount)}, |
918 {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability)}, | 943 {CC"RiMethod_exceptionProbability", CC"("RESOLVED_METHOD"I)I", FN_PTR(Java_com_oracle_graal_runtime_VMEntries_RiMethod_2exceptionProbability)}, |