comparison src/share/vm/graal/graalCompilerToVM.cpp @ 5275:290b3025b66f

added support for disassembling code after installation (so that the result of patching and relocation can be seen)
author Doug Simon <doug.simon@oracle.com>
date Mon, 23 Apr 2012 15:49:11 +0200
parents af8958fe5a3a
children b5cd7bc05695
comparison
equal deleted inserted replaced
5274:e72dd6533eb9 5275:290b3025b66f
875 set_int(env, config, "arrayClassElementOffset", in_bytes(objArrayKlass::element_klass_offset())); 875 set_int(env, config, "arrayClassElementOffset", in_bytes(objArrayKlass::element_klass_offset()));
876 return config; 876 return config;
877 } 877 }
878 878
879 // public HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode); 879 // public HotSpotCompiledMethod installMethod(HotSpotTargetMethod targetMethod, boolean installCode);
880 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code) { 880 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_installMethod(JNIEnv *jniEnv, jobject, jobject targetMethod, jboolean install_code, jobject info) {
881 VM_ENTRY_MARK; 881 VM_ENTRY_MARK;
882 ResourceMark rm; 882 ResourceMark rm;
883 HandleMark hm; 883 HandleMark hm;
884 Handle targetMethodHandle = JNIHandles::resolve(targetMethod); 884 Handle targetMethodHandle = JNIHandles::resolve(targetMethod);
885 nmethod* nm = NULL; 885 nmethod* nm = NULL;
886 Arena arena; 886 Arena arena;
887 ciEnv env(&arena); 887 ciEnv env(&arena);
888 CodeInstaller installer(targetMethodHandle, nm, install_code != 0); 888 CodeInstaller installer(targetMethodHandle, nm, install_code != 0);
889
890 if (info != NULL) {
891 arrayOop codeCopy = oopFactory::new_byteArray(nm->code_size(), CHECK_0);
892 memcpy(codeCopy->base(T_BYTE), nm->code_begin(), nm->code_size());
893 HotSpotCodeInfo::set_code(info, codeCopy);
894 HotSpotCodeInfo::set_start(info, (jlong) nm->code_begin());
895 }
889 896
890 // if install_code is true then we installed the code into the given method, no need to return an RiCompiledMethod 897 // if install_code is true then we installed the code into the given method, no need to return an RiCompiledMethod
891 if (!install_code && nm != NULL) { 898 if (!install_code && nm != NULL) {
892 instanceKlass::cast(HotSpotCompiledMethod::klass())->initialize(CHECK_NULL); 899 instanceKlass::cast(HotSpotCompiledMethod::klass())->initialize(CHECK_NULL);
893 Handle obj = instanceKlass::cast(HotSpotCompiledMethod::klass())->allocate_permanent_instance(CHECK_NULL); 900 Handle obj = instanceKlass::cast(HotSpotCompiledMethod::klass())->allocate_permanent_instance(CHECK_NULL);
901 return NULL; 908 return NULL;
902 } 909 }
903 } 910 }
904 911
905 // public long installStub(HotSpotTargetMethod targetMethod, String name); 912 // public long installStub(HotSpotTargetMethod targetMethod, String name);
906 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod) { 913 JNIEXPORT jlong JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_installStub(JNIEnv *jniEnv, jobject, jobject targetMethod, jobject info) {
907 VM_ENTRY_MARK; 914 VM_ENTRY_MARK;
908 ResourceMark rm; 915 ResourceMark rm;
909 HandleMark hm; 916 HandleMark hm;
910 Handle targetMethodHandle = JNIHandles::resolve(targetMethod); 917 Handle targetMethodHandle = JNIHandles::resolve(targetMethod);
911 jlong id; 918 jlong id;
912 Arena arena; 919 Arena arena;
913 ciEnv env(&arena); 920 ciEnv env(&arena);
914 CodeInstaller installer(targetMethodHandle, id); 921 BufferBlob* blob;
922 CodeInstaller installer(targetMethodHandle, blob, id);
923
924 if (info != NULL) {
925 arrayOop codeCopy = oopFactory::new_byteArray(blob->code_size(), CHECK_0);
926 memcpy(codeCopy->base(T_BYTE), blob->code_begin(), blob->code_size());
927 HotSpotCodeInfo::set_code(info, codeCopy);
928 HotSpotCodeInfo::set_start(info, (jlong) blob->code_begin());
929 }
930
915 return id; 931 return id;
916 } 932 }
917 933
918 // public String disassembleNative(byte[] code, long address); 934 // public String disassembleNative(byte[] code, long address);
919 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_disassembleNative(JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address) { 935 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_disassembleNative(JNIEnv *jniEnv, jobject, jbyteArray code, jlong start_address) {
1112 #define EXCEPTION_HANDLERS "[Lcom/oracle/max/cri/ri/RiExceptionHandler;" 1128 #define EXCEPTION_HANDLERS "[Lcom/oracle/max/cri/ri/RiExceptionHandler;"
1113 #define TARGET_METHOD "Lcom/oracle/graal/hotspot/HotSpotTargetMethod;" 1129 #define TARGET_METHOD "Lcom/oracle/graal/hotspot/HotSpotTargetMethod;"
1114 #define CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;" 1130 #define CONFIG "Lcom/oracle/graal/hotspot/HotSpotVMConfig;"
1115 #define HS_METHOD "Lcom/oracle/graal/hotspot/ri/HotSpotMethod;" 1131 #define HS_METHOD "Lcom/oracle/graal/hotspot/ri/HotSpotMethod;"
1116 #define HS_COMP_METHOD "Lcom/oracle/graal/hotspot/ri/HotSpotCompiledMethod;" 1132 #define HS_COMP_METHOD "Lcom/oracle/graal/hotspot/ri/HotSpotCompiledMethod;"
1133 #define HS_CODE_INFO "Lcom/oracle/graal/hotspot/ri/HotSpotCodeInfo;"
1117 #define METHOD_DATA "Lcom/oracle/graal/hotspot/ri/HotSpotMethodData;" 1134 #define METHOD_DATA "Lcom/oracle/graal/hotspot/ri/HotSpotMethodData;"
1118 #define CI_CONSTANT "Lcom/oracle/max/cri/ci/CiConstant;" 1135 #define CI_CONSTANT "Lcom/oracle/max/cri/ci/CiConstant;"
1119 #define CI_KIND "Lcom/oracle/max/cri/ci/CiKind;" 1136 #define CI_KIND "Lcom/oracle/max/cri/ci/CiKind;"
1120 #define CI_RUNTIME_CALL "Lcom/oracle/max/cri/ci/CiRuntimeCall;" 1137 #define CI_RUNTIME_CALL "Lcom/oracle/max/cri/ci/CiRuntimeCall;"
1121 #define STRING "Ljava/lang/String;" 1138 #define STRING "Ljava/lang/String;"
1151 {CC"RiType_isInitialized", CC"("RESOLVED_TYPE")Z", FN_PTR(RiType_1isInitialized)}, 1168 {CC"RiType_isInitialized", CC"("RESOLVED_TYPE")Z", FN_PTR(RiType_1isInitialized)},
1152 {CC"getPrimitiveArrayType", CC"("CI_KIND")"TYPE, FN_PTR(getPrimitiveArrayType)}, 1169 {CC"getPrimitiveArrayType", CC"("CI_KIND")"TYPE, FN_PTR(getPrimitiveArrayType)},
1153 {CC"getMaxCallTargetOffset", CC"("CI_RUNTIME_CALL")J", FN_PTR(getMaxCallTargetOffset)}, 1170 {CC"getMaxCallTargetOffset", CC"("CI_RUNTIME_CALL")J", FN_PTR(getMaxCallTargetOffset)},
1154 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(getType)}, 1171 {CC"getType", CC"("CLASS")"TYPE, FN_PTR(getType)},
1155 {CC"getConfiguration", CC"()"CONFIG, FN_PTR(getConfiguration)}, 1172 {CC"getConfiguration", CC"()"CONFIG, FN_PTR(getConfiguration)},
1156 {CC"installMethod", CC"("TARGET_METHOD"Z)"HS_COMP_METHOD, FN_PTR(installMethod)}, 1173 {CC"installMethod", CC"("TARGET_METHOD"Z"HS_CODE_INFO")"HS_COMP_METHOD, FN_PTR(installMethod)},
1157 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(installStub)}, 1174 {CC"installStub", CC"("TARGET_METHOD HS_CODE_INFO")"PROXY, FN_PTR(installStub)},
1158 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)}, 1175 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)},
1159 {CC"disassembleJava", CC"("RESOLVED_METHOD")"STRING, FN_PTR(disassembleJava)}, 1176 {CC"disassembleJava", CC"("RESOLVED_METHOD")"STRING, FN_PTR(disassembleJava)},
1160 {CC"RiMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(RiMethod_1toStackTraceElement)}, 1177 {CC"RiMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(RiMethod_1toStackTraceElement)},
1161 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)}, 1178 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)},
1162 {CC"executeCompiledMethodVarargs", CC"("HS_COMP_METHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, 1179 {CC"executeCompiledMethodVarargs", CC"("HS_COMP_METHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)},