comparison src/share/vm/graal/graalCompilerToVM.cpp @ 5246:8bf2c37c46c4

added RiCompiledMethod.executeVarargs(Object...) to support compiling and calling arbitrary Java methods
author Doug Simon <doug.simon@oracle.com>
date Tue, 17 Apr 2012 13:52:38 +0200
parents cce31bc56c00
children af8958fe5a3a
comparison
equal deleted inserted replaced
5245:71ac4221b1b0 5246:8bf2c37c46c4
964 methodHandle method = getMethodFromHotSpotMethod(hotspot_method); 964 methodHandle method = getMethodFromHotSpotMethod(hotspot_method);
965 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL); 965 oop element = java_lang_StackTraceElement::create(method, bci, CHECK_NULL);
966 return JNIHandles::make_local(element); 966 return JNIHandles::make_local(element);
967 } 967 }
968 968
969 class JavaArgumentPusher : public SignatureIterator {
970 protected:
971 JavaCallArguments* _jca;
972 arrayOop _args;
973 int _index;
974
975 oop next_arg(BasicType expectedType) {
976 assert(_index < _args->length(), "out of bounds");
977 oop arg = ((oop*) _args->base(T_OBJECT))[_index++];
978 assert(expectedType == T_OBJECT || java_lang_boxing_object::is_instance(arg, expectedType), "arg type mismatch");
979 return arg;
980 }
981
982 public:
983 JavaArgumentPusher(Symbol* signature, JavaCallArguments* jca, arrayOop args, bool is_static) : SignatureIterator(signature) {
984 this->_return_type = T_ILLEGAL;
985 _jca = jca;
986 _index = 0;
987 _args = args;
988 if (!is_static) {
989 _jca->push_oop(next_arg(T_OBJECT));
990 }
991 iterate();
992 assert(_index == args->length(), "arg count mismatch with signature");
993 }
994
995 inline void do_bool() { if (!is_return_type()) _jca->push_int(next_arg(T_BOOLEAN)->bool_field(java_lang_boxing_object::value_offset_in_bytes(T_BOOLEAN))); }
996 inline void do_char() { if (!is_return_type()) _jca->push_int(next_arg(T_CHAR)->char_field(java_lang_boxing_object::value_offset_in_bytes(T_CHAR))); }
997 inline void do_short() { if (!is_return_type()) _jca->push_int(next_arg(T_SHORT)->short_field(java_lang_boxing_object::value_offset_in_bytes(T_SHORT))); }
998 inline void do_byte() { if (!is_return_type()) _jca->push_int(next_arg(T_BYTE)->byte_field(java_lang_boxing_object::value_offset_in_bytes(T_BYTE))); }
999 inline void do_int() { if (!is_return_type()) _jca->push_int(next_arg(T_INT)->int_field(java_lang_boxing_object::value_offset_in_bytes(T_INT))); }
1000
1001 inline void do_long() { if (!is_return_type()) _jca->push_long(next_arg(T_LONG)->long_field(java_lang_boxing_object::value_offset_in_bytes(T_LONG))); }
1002 inline void do_float() { if (!is_return_type()) _jca->push_float(next_arg(T_FLOAT)->float_field(java_lang_boxing_object::value_offset_in_bytes(T_FLOAT))); }
1003 inline void do_double() { if (!is_return_type()) _jca->push_double(next_arg(T_DOUBLE)->double_field(java_lang_boxing_object::value_offset_in_bytes(T_DOUBLE))); }
1004
1005 inline void do_object() { _jca->push_oop(next_arg(T_OBJECT)); }
1006 inline void do_object(int begin, int end) { if (!is_return_type()) _jca->push_oop(next_arg(T_OBJECT)); }
1007 inline void do_array(int begin, int end) { if (!is_return_type()) _jca->push_oop(next_arg(T_OBJECT)); }
1008 inline void do_void() { }
1009 };
1010
1011 // public Object executeCompiledMethodVarargs(HotSpotCompiledMethod method, Object... args);
1012 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_executeCompiledMethodVarargs(JNIEnv *env, jobject, jobject method, jobject args) {
1013 TRACE_graal_3("CompilerToVM::executeCompiledMethod");
1014
1015 VM_ENTRY_MARK;
1016 ResourceMark rm;
1017 HandleMark hm;
1018
1019 assert(method != NULL, "just checking");
1020 methodHandle mh = getMethodFromHotSpotMethod(HotSpotCompiledMethod::method(method));
1021 Symbol* signature = mh->signature();
1022 JavaCallArguments jca;
1023
1024 JavaArgumentPusher jap(signature, &jca, (arrayOop) JNIHandles::resolve(args), mh->is_static());
1025 JavaValue result(jap.get_ret_type());
1026
1027 nmethod* nm = (nmethod*) HotSpotCompiledMethod::nmethod(method);
1028 if (nm == NULL || !nm->is_alive()) {
1029 THROW_0(vmSymbols::MethodInvalidatedException());
1030 }
1031 JavaCalls::call(&result, mh, nm, &jca, CHECK_NULL);
1032
1033 if (jap.get_ret_type() == T_VOID) {
1034 return NULL;
1035 } else if (jap.get_ret_type() == T_OBJECT) {
1036 return JNIHandles::make_local((oop) result.get_jobject());
1037 } else {
1038 oop o = java_lang_boxing_object::create(jap.get_ret_type(), (jvalue *) result.get_value_addr(), CHECK_NULL);
1039 return JNIHandles::make_local(o);
1040 }
1041 }
1042
969 // public Object executeCompiledMethod(HotSpotCompiledMethod method, Object arg1, Object arg2, Object arg3); 1043 // public Object executeCompiledMethod(HotSpotCompiledMethod method, Object arg1, Object arg2, Object arg3);
970 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_executeCompiledMethod(JNIEnv *env, jobject, jobject method, jobject arg1, jobject arg2, jobject arg3) { 1044 JNIEXPORT jobject JNICALL Java_com_oracle_graal_hotspot_bridge_CompilerToVMImpl_executeCompiledMethod(JNIEnv *env, jobject, jobject method, jobject arg1, jobject arg2, jobject arg3) {
971 TRACE_graal_3("CompilerToVM::executeCompiledMethod"); 1045 TRACE_graal_3("CompilerToVM::executeCompiledMethod");
972 1046
973 VM_ENTRY_MARK; 1047 VM_ENTRY_MARK;
1084 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(installStub)}, 1158 {CC"installStub", CC"("TARGET_METHOD")"PROXY, FN_PTR(installStub)},
1085 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)}, 1159 {CC"disassembleNative", CC"([BJ)"STRING, FN_PTR(disassembleNative)},
1086 {CC"disassembleJava", CC"("RESOLVED_METHOD")"STRING, FN_PTR(disassembleJava)}, 1160 {CC"disassembleJava", CC"("RESOLVED_METHOD")"STRING, FN_PTR(disassembleJava)},
1087 {CC"RiMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(RiMethod_1toStackTraceElement)}, 1161 {CC"RiMethod_toStackTraceElement", CC"("RESOLVED_METHOD"I)"STACK_TRACE_ELEMENT, FN_PTR(RiMethod_1toStackTraceElement)},
1088 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)}, 1162 {CC"executeCompiledMethod", CC"("HS_COMP_METHOD OBJECT OBJECT OBJECT")"OBJECT, FN_PTR(executeCompiledMethod)},
1163 {CC"executeCompiledMethodVarargs", CC"("HS_COMP_METHOD "["OBJECT")"OBJECT, FN_PTR(executeCompiledMethodVarargs)},
1089 {CC"RiMethod_vtableEntryOffset", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_vtableEntryOffset)}, 1164 {CC"RiMethod_vtableEntryOffset", CC"("RESOLVED_METHOD")I", FN_PTR(RiMethod_vtableEntryOffset)},
1090 {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, 1165 {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)},
1091 }; 1166 };
1092 1167
1093 int CompilerToVM_methods_count() { 1168 int CompilerToVM_methods_count() {