# HG changeset patch # User Thomas Wuerthinger # Date 1371995349 -7200 # Node ID aa685bff0926ea0c0b711c873eafd54b942592fe # Parent 40b8c383bc31b1054e163265d9f766d64d2b89c2# Parent 53ba9df05fa2cd457b6397fb04c3ebe796102e1f Merge. diff -r 53ba9df05fa2 -r aa685bff0926 graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotNmethodTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotNmethodTest.java Fri Jun 21 11:58:39 2013 -0700 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotNmethodTest.java Sun Jun 23 15:49:09 2013 +0200 @@ -42,7 +42,7 @@ Assert.assertTrue(nmethod.isValid()); Object result; try { - result = nmethod.execute("a", "b", "c"); + result = nmethod.execute(null, "b", "c"); assertEquals(43, result); } catch (InvalidInstalledCodeException e) { Assert.fail("Code was invalidated"); @@ -59,6 +59,21 @@ } @Test + public void testInstallCodeInvalidationWhileRunning() { + final ResolvedJavaMethod testJavaMethod = runtime.lookupJavaMethod(getMethod("foo")); + final StructuredGraph graph = parse("otherFoo"); + final HotSpotNmethod nmethod = (HotSpotNmethod) getCode(testJavaMethod, graph); + Object result; + try { + result = nmethod.execute(nmethod, null, null); + assertEquals(43, result); + } catch (InvalidInstalledCodeException e) { + Assert.fail("Code was invalidated"); + } + Assert.assertFalse(nmethod.isValid()); + } + + @Test public void testInstalledCodeCalledFromCompiledCode() { final ResolvedJavaMethod testJavaMethod = runtime.lookupJavaMethod(getMethod("foo")); final StructuredGraph graph = parse("otherFoo"); @@ -66,7 +81,7 @@ Assert.assertTrue(nmethod.isValid()); try { for (int i = 0; i < ITERATION_COUNT; ++i) { - nmethod.execute("a", "b", "c"); + nmethod.execute(null, "b", "c"); } } catch (InvalidInstalledCodeException e) { Assert.fail("Code was invalidated"); @@ -74,12 +89,15 @@ } @SuppressWarnings("unused") - public static Object foo(Object a1, Object a2, Object a3) { + public static Object foo(HotSpotNmethod method, Object a2, Object a3) { return 42; } @SuppressWarnings("unused") - public static Object otherFoo(Object a1, Object a2, Object a3) { + public static Object otherFoo(HotSpotNmethod method, Object a2, Object a3) { + if (method != null) { + method.invalidate(); + } return 43; } } diff -r 53ba9df05fa2 -r aa685bff0926 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Fri Jun 21 11:58:39 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java Sun Jun 23 15:49:09 2013 +0200 @@ -206,9 +206,9 @@ StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); - Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, long nmethod) throws InvalidInstalledCodeException; + Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; - Object executeCompiledMethodVarargs(Object[] args, long nmethod) throws InvalidInstalledCodeException; + Object executeCompiledMethodVarargs(Object[] args, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException; int getVtableEntryOffset(long metaspaceMethod); @@ -229,7 +229,5 @@ */ void reprofile(long metaspaceMethod); - void invalidateInstalledCode(long nativeMethod); - - boolean isInstalledCodeValid(long nativeMethod); + void invalidateInstalledCode(HotSpotInstalledCode hotspotInstalledCode); } diff -r 53ba9df05fa2 -r aa685bff0926 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Fri Jun 21 11:58:39 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java Sun Jun 23 15:49:09 2013 +0200 @@ -143,7 +143,7 @@ public native StackTraceElement getStackTraceElement(long metaspaceMethod, int bci); @Override - public native Object executeCompiledMethodVarargs(Object[] args, long nmethod); + public native Object executeCompiledMethodVarargs(Object[] args, HotSpotInstalledCode hotspotInstalledCode); @Override public native int getVtableEntryOffset(long metaspaceMethod); @@ -170,14 +170,11 @@ public native Object lookupAppendixInPool(HotSpotResolvedObjectType pool, int cpi, byte opcode); @Override - public native void invalidateInstalledCode(long nativeMethod); + public native void invalidateInstalledCode(HotSpotInstalledCode hotspotInstalledCode); @Override - public native boolean isInstalledCodeValid(long nativeMethod); - - @Override - public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, long nmethod) throws InvalidInstalledCodeException { - return executeCompiledMethodIntrinsic(arg1, arg2, arg3, nmethod); + public Object executeCompiledMethod(Object arg1, Object arg2, Object arg3, HotSpotInstalledCode hotspotInstalledCode) throws InvalidInstalledCodeException { + return executeCompiledMethodIntrinsic(arg1, arg2, arg3, hotspotInstalledCode); } /** @@ -187,5 +184,5 @@ * stub that does the necessary argument shuffling and a tail call via an indirect jump to the * verified entry point of the given native method. */ - private static native Object executeCompiledMethodIntrinsic(Object arg1, Object arg2, Object arg3, long nmethod); + private static native Object executeCompiledMethodIntrinsic(Object arg1, Object arg2, Object arg3, HotSpotInstalledCode hotspotInstalledCode); } diff -r 53ba9df05fa2 -r aa685bff0926 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNmethod.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNmethod.java Fri Jun 21 11:58:39 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotNmethod.java Sun Jun 23 15:49:09 2013 +0200 @@ -68,12 +68,12 @@ @Override public boolean isValid() { - return graalRuntime().getCompilerToVM().isInstalledCodeValid(codeBlob); + return codeBlob != 0; } @Override public void invalidate() { - graalRuntime().getCompilerToVM().invalidateInstalledCode(codeBlob); + graalRuntime().getCompilerToVM().invalidateInstalledCode(this); } @Override @@ -87,7 +87,7 @@ assert method.getSignature().getParameterKind(0) == Kind.Object; assert method.getSignature().getParameterKind(1) == Kind.Object; assert !Modifier.isStatic(method.getModifiers()) || method.getSignature().getParameterKind(2) == Kind.Object; - return graalRuntime().getCompilerToVM().executeCompiledMethod(arg1, arg2, arg3, codeBlob); + return graalRuntime().getCompilerToVM().executeCompiledMethod(arg1, arg2, arg3, this); } private boolean checkArgs(Object... args) { @@ -107,7 +107,7 @@ @Override public Object executeVarargs(Object... args) throws InvalidInstalledCodeException { assert checkArgs(args); - return graalRuntime().getCompilerToVM().executeCompiledMethodVarargs(args, codeBlob); + return graalRuntime().getCompilerToVM().executeCompiledMethodVarargs(args, this); } @Override diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/sparc/vm/sharedRuntime_sparc.cpp --- a/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/sparc/vm/sharedRuntime_sparc.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -1826,20 +1826,6 @@ verify_oop_args(masm, method, sig_bt, regs); vmIntrinsics::ID iid = method->intrinsic_id(); - -#ifdef GRAAL - if (iid == vmIntrinsics::_CompilerToVMImpl_executeCompiledMethod) { - // We are called from compiled code here. The three object arguments - // are already in the correct registers (j_rarg0, jrarg1, jrarg2). The - // fourth argument (j_rarg3) is a raw pointer to the nmethod. Make a tail - // call to its verified entry point. - __ set(nmethod::verified_entry_point_offset(), O0); - __ JMP(O0, 0); - __ delayed()->nop(); - return; - } -#endif - // Now write the args into the outgoing interpreter space bool has_receiver = false; Register receiver_reg = noreg; diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/sparc/vm/stubGenerator_sparc.cpp --- a/src/cpu/sparc/vm/stubGenerator_sparc.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/sparc/vm/stubGenerator_sparc.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -3412,6 +3412,7 @@ // These entry points require SharedInfo::stack0 to be set up in non-core builds StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError)); StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError)); + StubRoutines::_throw_InvalidInstalledCodeException_entry= generate_throw_exception("InvalidInstalledCodeException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_InvalidInstalledCodeException)); StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call)); StubRoutines::_handler_for_unsafe_access_entry = diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/x86/vm/c2_globals_x86.hpp --- a/src/cpu/x86/vm/c2_globals_x86.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/x86/vm/c2_globals_x86.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -86,7 +86,11 @@ define_pd_global(bool, OptoScheduling, false); define_pd_global(bool, OptoBundling, false); +#ifdef GRAAL +define_pd_global(intx, ReservedCodeCacheSize, 64*M); +#else define_pd_global(intx, ReservedCodeCacheSize, 48*M); +#endif define_pd_global(uintx,CodeCacheMinBlockLength, 4); // Heap related flags diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/x86/vm/sharedRuntime_x86_64.cpp --- a/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/x86/vm/sharedRuntime_x86_64.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -40,6 +40,9 @@ #ifdef COMPILER2 #include "opto/runtime.hpp" #endif +#ifdef GRAAL +#include "graal/graalJavaAccess.hpp" +#endif #define __ masm-> @@ -1674,9 +1677,22 @@ if (iid == vmIntrinsics::_CompilerToVMImpl_executeCompiledMethod) { // We are called from compiled code here. The three object arguments // are already in the correct registers (j_rarg0, jrarg1, jrarg2). The - // fourth argument (j_rarg3) is a raw pointer to the nmethod. Make a tail - // call to its verified entry point. + // fourth argument (j_rarg3) is a pointer to the HotSpotInstalledCode object. + + // Load the nmethod pointer from the HotSpotInstalledCode object + __ movq(j_rarg3, Address(j_rarg3, sizeof(oopDesc))); + + // Check whether the nmethod was invalidated + __ testq(j_rarg3, j_rarg3); + Label invalid_nmethod; + __ jcc(Assembler::zero, invalid_nmethod); + + // Perform a tail call to the verified entry point of the nmethod. __ jmp(Address(j_rarg3, nmethod::verified_entry_point_offset())); + + __ bind(invalid_nmethod); + + __ jump(RuntimeAddress(StubRoutines::throw_InvalidInstalledCodeException_entry())); return; } #endif diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/x86/vm/stubGenerator_x86_32.cpp --- a/src/cpu/x86/vm/stubGenerator_x86_32.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/x86/vm/stubGenerator_x86_32.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -2897,6 +2897,7 @@ // and need to be relocatable, so they each fabricate a RuntimeStub internally. StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError)); StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError)); + StubRoutines::_throw_InvalidInstalledCodeException_entry = generate_throw_exception("InvalidInstalledCodeException throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_InvalidInstalledCodeException)); StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call)); //------------------------------------------------------------------------------------------------------------------------ diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/x86/vm/stubGenerator_x86_64.cpp --- a/src/cpu/x86/vm/stubGenerator_x86_64.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/x86/vm/stubGenerator_x86_64.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -3756,6 +3756,12 @@ SharedRuntime:: throw_IncompatibleClassChangeError)); + StubRoutines::_throw_InvalidInstalledCodeException_entry = + generate_throw_exception("InvalidInstalledCodeException throw_exception", + CAST_FROM_FN_PTR(address, + SharedRuntime:: + throw_InvalidInstalledCodeException)); + StubRoutines::_throw_NullPointerException_at_call_entry = generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, diff -r 53ba9df05fa2 -r aa685bff0926 src/cpu/x86/vm/templateInterpreter_x86_64.cpp --- a/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/cpu/x86/vm/templateInterpreter_x86_64.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -46,6 +46,9 @@ #include "runtime/vframeArray.hpp" #include "utilities/debug.hpp" #include "utilities/macros.hpp" +#ifdef GRAAL +#include "graal/graalJavaAccess.hpp" +#endif #define __ _masm-> @@ -908,20 +911,34 @@ // Move first object argument from interpreter calling convention to compiled // code calling convention. - __ movq(j_rarg0, Address(r11, Interpreter::stackElementSize*5)); + __ movq(j_rarg0, Address(r11, Interpreter::stackElementSize*4)); // Move second object argument. - __ movq(j_rarg1, Address(r11, Interpreter::stackElementSize*4)); + __ movq(j_rarg1, Address(r11, Interpreter::stackElementSize*3)); // Move third object argument. - __ movq(j_rarg2, Address(r11, Interpreter::stackElementSize*3)); + __ movq(j_rarg2, Address(r11, Interpreter::stackElementSize*2)); + + // Load the raw pointer to the HotSpotInstalledCode object. + __ movq(j_rarg3, Address(r11, Interpreter::stackElementSize)); - // Load the raw pointer to the nmethod. - __ movq(j_rarg3, Address(r11, Interpreter::stackElementSize)); + // Load the nmethod pointer from the HotSpotInstalledCode object + __ movq(j_rarg3, Address(j_rarg3, sizeof(oopDesc))); + + // Check whether the nmethod was invalidated + __ testq(j_rarg3, j_rarg3); + Label invalid_nmethod; + __ jcc(Assembler::zero, invalid_nmethod); // Perform a tail call to the verified entry point of the nmethod. __ jmp(Address(j_rarg3, nmethod::verified_entry_point_offset())); + __ bind(invalid_nmethod); + + __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_InvalidInstalledCodeException)); + // the call_VM checks for exception, so we should never return here. + __ should_not_reach_here(); + return entry_point; } diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/classfile/vmSymbols.hpp --- a/src/share/vm/classfile/vmSymbols.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/classfile/vmSymbols.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -348,6 +348,8 @@ template(com_oracle_graal_api_code_VirtualObject, "com/oracle/graal/api/code/VirtualObject") \ template(com_oracle_graal_api_code_RegisterSaveLayout, "com/oracle/graal/api/code/RegisterSaveLayout") \ template(com_oracle_graal_api_code_InvalidInstalledCodeException, "com/oracle/graal/api/code/InvalidInstalledCodeException") \ + /* graal.truffle */ \ + template(com_oracle_graal_truffle_GraalTruffleRuntime, "com/oracle/graal/truffle/GraalTruffleRuntime") \ template(startCompiler_name, "startCompiler") \ template(bootstrap_name, "bootstrap") \ template(shutdownCompiler_name, "shutdownCompiler") \ @@ -382,6 +384,7 @@ template(getVMToCompiler_name, "getVMToCompiler") \ template(getVMToCompiler_signature, "()Lcom/oracle/graal/hotspot/bridge/VMToCompiler;") \ template(getInstance_name, "getInstance") \ + template(getTruffleRuntimeInstance_signature, "()Lcom/oracle/graal/truffle/GraalTruffleRuntime;") \ template(makeInstance_name, "makeInstance") \ template(initialize_name, "initialize") \ template(getInstance_signature, "()Lcom/oracle/graal/hotspot/HotSpotGraalRuntime;") \ @@ -1145,7 +1148,7 @@ do_name( Double_valueOf_signature, "(D)Ljava/lang/Double;") \ \ do_intrinsic(_CompilerToVMImpl_executeCompiledMethod, com_oracle_graal_hotspot_bridge_CompilerToVMImpl, executeCompiledMethod_name, CompilerToVMImpl_executeCompiledMethod_signature, F_SN)\ - do_name( CompilerToVMImpl_executeCompiledMethod_signature, "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;J)Ljava/lang/Object;") \ + do_name( CompilerToVMImpl_executeCompiledMethod_signature, "(Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/Object;Lcom/oracle/graal/hotspot/meta/HotSpotInstalledCode;)Ljava/lang/Object;") \ do_name( executeCompiledMethod_name, "executeCompiledMethodIntrinsic") \ /*end*/ diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/code/nmethod.cpp --- a/src/share/vm/code/nmethod.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/code/nmethod.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -1397,9 +1397,10 @@ if (!is_osr_method() && !is_not_entrant()) { address stub = SharedRuntime::get_handle_wrong_method_stub(); #ifdef GRAAL - if (_graal_installed_code != NULL && !HotSpotNmethod::isDefault(_graal_installed_code)) { - // This was manually installed machine code. Patch entry with stub that throws an exception. - stub = SharedRuntime::get_deoptimized_installed_code_stub(); + if (_graal_installed_code != NULL) { + // Break the link between nmethod and HotSpotInstalledCode such that the nmethod can subsequently be flushed safely. + HotSpotInstalledCode::set_codeBlob(_graal_installed_code, 0); + _graal_installed_code = NULL; } #endif NativeJump::patch_verified_entry(entry_point(), verified_entry_point(), stub); diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/graal/graalCompilerToVM.cpp --- a/src/share/vm/graal/graalCompilerToVM.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/graal/graalCompilerToVM.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -1004,10 +1004,11 @@ return JNIHandles::make_local(element); C2V_END -C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jobject args, jlong nmethodValue)) +C2V_VMENTRY(jobject, executeCompiledMethodVarargs, (JNIEnv *env, jobject, jobject args, jobject hotspotInstalledCode)) ResourceMark rm; HandleMark hm; + jlong nmethodValue = HotSpotInstalledCode::codeBlob(hotspotInstalledCode); nmethod* nm = (nmethod*) (address) nmethodValue; methodHandle mh = nm->method(); Symbol* signature = mh->signature(); @@ -1156,9 +1157,10 @@ C2V_END -C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv *env, jobject, jlong nativeMethod)) +C2V_VMENTRY(void, invalidateInstalledCode, (JNIEnv *env, jobject, jobject hotspotInstalledCode)) + jlong nativeMethod = HotSpotInstalledCode::codeBlob(hotspotInstalledCode); nmethod* m = (nmethod*)nativeMethod; - if (!m->is_not_entrant()) { + if (m != NULL && !m->is_not_entrant()) { m->mark_for_deoptimization(); VM_Deoptimize op; VMThread::execute(&op); @@ -1166,11 +1168,6 @@ C2V_END -C2V_VMENTRY(jboolean, isInstalledCodeValid, (JNIEnv *env, jobject, jlong nativeMethod)) - nmethod* m = (nmethod*)nativeMethod; - return m->is_alive() && !m->is_not_entrant(); -C2V_END - #define CC (char*) /*cast a literal from (const char*)*/ #define FN_PTR(f) CAST_FROM_FN_PTR(void*, &(c2v_ ## f)) @@ -1203,7 +1200,6 @@ #define METHOD_DATA "Lcom/oracle/graal/hotspot/meta/HotSpotMethodData;" #define METASPACE_METHOD "J" #define METASPACE_METHOD_DATA "J" -#define NMETHOD "J" JNINativeMethod CompilerToVM_methods[] = { {CC"initializeBytecode", CC"("METASPACE_METHOD"[B)[B", FN_PTR(initializeBytecode)}, @@ -1243,14 +1239,13 @@ {CC"installCode0", CC"("HS_COMPILED_CODE HS_INSTALLED_CODE"[Z)I", FN_PTR(installCode0)}, {CC"getCode", CC"(J)[B", FN_PTR(getCode)}, {CC"disassembleCodeBlob", CC"(J)"STRING, FN_PTR(disassembleCodeBlob)}, - {CC"executeCompiledMethodVarargs", CC"(["OBJECT NMETHOD")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, + {CC"executeCompiledMethodVarargs", CC"(["OBJECT HS_INSTALLED_CODE")"OBJECT, FN_PTR(executeCompiledMethodVarargs)}, {CC"getDeoptedLeafGraphIds", CC"()[J", FN_PTR(getDeoptedLeafGraphIds)}, {CC"getLineNumberTable", CC"("HS_RESOLVED_METHOD")[J", FN_PTR(getLineNumberTable)}, {CC"getLocalVariableTable", CC"("HS_RESOLVED_METHOD")["LOCAL, FN_PTR(getLocalVariableTable)}, {CC"getFileName", CC"("HS_RESOLVED_JAVA_TYPE")"STRING, FN_PTR(getFileName)}, {CC"reprofile", CC"("METASPACE_METHOD")V", FN_PTR(reprofile)}, - {CC"invalidateInstalledCode", CC"(J)V", FN_PTR(invalidateInstalledCode)}, - {CC"isInstalledCodeValid", CC"(J)Z", FN_PTR(isInstalledCodeValid)}, + {CC"invalidateInstalledCode", CC"("HS_INSTALLED_CODE")V", FN_PTR(invalidateInstalledCode)}, }; int CompilerToVM_methods_count() { diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/graal/graalJavaAccess.cpp --- a/src/share/vm/graal/graalJavaAccess.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/graal/graalJavaAccess.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -63,6 +63,7 @@ void graal_compute_offsets() { COMPILER_CLASSES_DO(START_CLASS, END_CLASS, CHAR_FIELD, INT_FIELD, BOOLEAN_FIELD, LONG_FIELD, FLOAT_FIELD, OOP_FIELD, STATIC_OOP_FIELD) + guarantee(HotSpotInstalledCode::_codeBlob_offset == sizeof(oopDesc), "codeBlob must be first field!"); } #define EMPTY0 diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/graal/graalRuntime.cpp --- a/src/share/vm/graal/graalRuntime.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/graal/graalRuntime.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -474,3 +474,8 @@ JVM_ENTRY(jobject, JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass)) return VMToCompiler::graalRuntimePermObject(); JVM_END + +// JVM_InitializeTruffleRuntime +JVM_ENTRY(jobject, JVM_InitializeTruffleRuntime(JNIEnv *env, jclass graalclass)) + return JNIHandles::make_local(VMToCompiler::truffleRuntime()()); +JVM_END diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/graal/graalVMToCompiler.cpp --- a/src/share/vm/graal/graalVMToCompiler.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/graal/graalVMToCompiler.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -46,6 +46,16 @@ return _vmToCompilerPermKlass; } +Handle VMToCompiler::truffleRuntime() { + Symbol* name = vmSymbols::com_oracle_graal_truffle_GraalTruffleRuntime(); + KlassHandle klass = loadClass(name); + + JavaValue result(T_OBJECT); + JavaCalls::call_static(&result, klass, vmSymbols::makeInstance_name(), vmSymbols::getTruffleRuntimeInstance_signature(), Thread::current()); + check_pending_exception("Couldn't initialize GraalTruffleRuntime"); + return Handle((oop) result.get_jobject()); +} + Handle VMToCompiler::graalRuntime() { if (JNIHandles::resolve(_graalRuntimePermObject) == NULL) { #ifdef AMD64 @@ -292,3 +302,4 @@ } + diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/graal/graalVMToCompiler.hpp --- a/src/share/vm/graal/graalVMToCompiler.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/graal/graalVMToCompiler.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -44,6 +44,7 @@ public: static Handle graalRuntime(); + static Handle truffleRuntime(); static jobject graalRuntimePermObject() { graalRuntime(); diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/interpreter/interpreterRuntime.cpp --- a/src/share/vm/interpreter/interpreterRuntime.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/interpreter/interpreterRuntime.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -501,6 +501,10 @@ IRT_END +IRT_ENTRY(void, InterpreterRuntime::throw_InvalidInstalledCodeException(JavaThread* thread)) + THROW(vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException()); +IRT_END + //------------------------------------------------------------------------------------------------------------------------ // Fields // diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/interpreter/interpreterRuntime.hpp --- a/src/share/vm/interpreter/interpreterRuntime.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/interpreter/interpreterRuntime.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -89,6 +89,7 @@ // Exceptions thrown by the interpreter static void throw_AbstractMethodError(JavaThread* thread); static void throw_IncompatibleClassChangeError(JavaThread* thread); + static void throw_InvalidInstalledCodeException(JavaThread* thread); static void throw_StackOverflowError(JavaThread* thread); static void throw_ArrayIndexOutOfBoundsException(JavaThread* thread, char* name, jint index); static void throw_ClassCastException(JavaThread* thread, oopDesc* obj); diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/prims/nativeLookup.cpp --- a/src/share/vm/prims/nativeLookup.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/prims/nativeLookup.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -125,6 +125,7 @@ void JNICALL JVM_RegisterWhiteBoxMethods(JNIEnv *env, jclass wbclass); #ifdef GRAAL jobject JNICALL JVM_InitializeGraalRuntime(JNIEnv *env, jclass graalclass); + jobject JNICALL JVM_InitializeTruffleRuntime(JNIEnv *env, jclass graalclass); #endif } @@ -142,6 +143,7 @@ { CC"Java_sun_hotspot_WhiteBox_registerNatives", NULL, FN_PTR(JVM_RegisterWhiteBoxMethods) }, #ifdef GRAAL { CC"Java_com_oracle_graal_api_runtime_Graal_initializeRuntime", NULL, FN_PTR(JVM_InitializeGraalRuntime) }, + { CC"Java_com_oracle_truffle_api_Truffle_initializeRuntime", NULL, FN_PTR(JVM_InitializeTruffleRuntime) }, #endif }; diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/runtime/sharedRuntime.cpp --- a/src/share/vm/runtime/sharedRuntime.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/runtime/sharedRuntime.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -752,6 +752,11 @@ throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_IncompatibleClassChangeError(), "vtable stub"); JRT_END +JRT_ENTRY(void, SharedRuntime::throw_InvalidInstalledCodeException(JavaThread* thread)) + // These errors occur only at call sites + throw_and_post_jvmti_exception(thread, vmSymbols::com_oracle_graal_api_code_InvalidInstalledCodeException()); +JRT_END + JRT_ENTRY(void, SharedRuntime::throw_ArithmeticException(JavaThread* thread)) throw_and_post_jvmti_exception(thread, vmSymbols::java_lang_ArithmeticException(), "/ by zero"); JRT_END diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/runtime/sharedRuntime.hpp --- a/src/share/vm/runtime/sharedRuntime.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/runtime/sharedRuntime.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -186,6 +186,7 @@ }; static void throw_AbstractMethodError(JavaThread* thread); static void throw_IncompatibleClassChangeError(JavaThread* thread); + static void throw_InvalidInstalledCodeException(JavaThread* thread); static void throw_ArithmeticException(JavaThread* thread); static void throw_NullPointerException(JavaThread* thread); static void throw_NullPointerException_at_call(JavaThread* thread); diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/runtime/stubRoutines.cpp --- a/src/share/vm/runtime/stubRoutines.cpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/runtime/stubRoutines.cpp Sun Jun 23 15:49:09 2013 +0200 @@ -51,6 +51,7 @@ address StubRoutines::_forward_exception_entry = NULL; address StubRoutines::_throw_AbstractMethodError_entry = NULL; address StubRoutines::_throw_IncompatibleClassChangeError_entry = NULL; +address StubRoutines::_throw_InvalidInstalledCodeException_entry = NULL; address StubRoutines::_throw_NullPointerException_at_call_entry = NULL; address StubRoutines::_throw_StackOverflowError_entry = NULL; address StubRoutines::_handler_for_unsafe_access_entry = NULL; diff -r 53ba9df05fa2 -r aa685bff0926 src/share/vm/runtime/stubRoutines.hpp --- a/src/share/vm/runtime/stubRoutines.hpp Fri Jun 21 11:58:39 2013 -0700 +++ b/src/share/vm/runtime/stubRoutines.hpp Sun Jun 23 15:49:09 2013 +0200 @@ -128,6 +128,7 @@ static address _catch_exception_entry; static address _throw_AbstractMethodError_entry; static address _throw_IncompatibleClassChangeError_entry; + static address _throw_InvalidInstalledCodeException_entry; static address _throw_NullPointerException_at_call_entry; static address _throw_StackOverflowError_entry; static address _handler_for_unsafe_access_entry; @@ -261,6 +262,7 @@ // Implicit exceptions static address throw_AbstractMethodError_entry() { return _throw_AbstractMethodError_entry; } static address throw_IncompatibleClassChangeError_entry(){ return _throw_IncompatibleClassChangeError_entry; } + static address throw_InvalidInstalledCodeException_entry(){ return _throw_InvalidInstalledCodeException_entry; } static address throw_NullPointerException_at_call_entry(){ return _throw_NullPointerException_at_call_entry; } static address throw_StackOverflowError_entry() { return _throw_StackOverflowError_entry; }