# HG changeset patch # User Thomas Wuerthinger # Date 1365734947 -7200 # Node ID 22851e342f0ee2f6ec20e9b99da8d670cd32171b # Parent ff5a32117e026a800c623192a0e5574cad2adc18 Make calling the installed code from compiled code possible. diff -r ff5a32117e02 -r 22851e342f0e graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotInstalledCodeTest.java --- a/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotInstalledCodeTest.java Fri Apr 12 01:53:52 2013 +0200 +++ b/graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotInstalledCodeTest.java Fri Apr 12 04:49:07 2013 +0200 @@ -32,8 +32,10 @@ public class HotSpotInstalledCodeTest extends GraalCompilerTest { + private static final int ITERATION_COUNT = 100000; + @Test - public void testInstallCode() { + public void testInstallCodeInvalidation() { final ResolvedJavaMethod testJavaMethod = runtime.lookupJavaMethod(getMethod("foo")); final StructuredGraph graph = parse("otherFoo"); final HotSpotInstalledCode installedCode = (HotSpotInstalledCode) getCode(testJavaMethod, graph); @@ -56,6 +58,21 @@ Assert.assertFalse(installedCode.isValid()); } + @Test + public void testInstalledCodeCalledFromCompiledCode() { + final ResolvedJavaMethod testJavaMethod = runtime.lookupJavaMethod(getMethod("foo")); + final StructuredGraph graph = parse("otherFoo"); + final HotSpotInstalledCode installedCode = (HotSpotInstalledCode) getCode(testJavaMethod, graph); + Assert.assertTrue(installedCode.isValid()); + try { + for (int i = 0; i < ITERATION_COUNT; ++i) { + installedCode.execute("a", "b", "c"); + } + } catch (InvalidInstalledCodeException e) { + Assert.fail("Code was invalidated"); + } + } + @SuppressWarnings("unused") public static Object foo(Object a1, Object a2, Object a3) { return 42; diff -r ff5a32117e02 -r 22851e342f0e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Fri Apr 12 01:53:52 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java Fri Apr 12 04:49:07 2013 +0200 @@ -39,10 +39,11 @@ private final HotSpotResolvedJavaMethod method; private final boolean isDefault; - long nmethod; + private final long nmethod; // This field is set by the runtime upon code installation. long start; public HotSpotInstalledCode(HotSpotResolvedJavaMethod method, boolean isDefault) { + this.nmethod = 0; this.method = method; this.isDefault = isDefault; } diff -r ff5a32117e02 -r 22851e342f0e graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Fri Apr 12 01:53:52 2013 +0200 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java Fri Apr 12 04:49:07 2013 +0200 @@ -905,7 +905,7 @@ public String disassemble(InstalledCode code) { if (code.isValid()) { - long nmethod = ((HotSpotInstalledCode) code).nmethod; + long nmethod = ((HotSpotInstalledCode) code).getnmethod(); return graalRuntime.getCompilerToVM().disassembleNMethod(nmethod); } return null; diff -r ff5a32117e02 -r 22851e342f0e src/share/vm/compiler/compileBroker.cpp --- a/src/share/vm/compiler/compileBroker.cpp Fri Apr 12 01:53:52 2013 +0200 +++ b/src/share/vm/compiler/compileBroker.cpp Fri Apr 12 04:49:07 2013 +0200 @@ -1225,7 +1225,7 @@ assert(method->method_holder()->oop_is_instance(), "not an instance method"); assert(osr_bci == InvocationEntryBci || (0 <= osr_bci && osr_bci < method->code_size()), "bci out of range"); assert(!method->is_abstract() && (osr_bci == InvocationEntryBci || !method->is_native()), "cannot compile abstract/native methods"); - assert(!method->method_holder()->is_not_initialized(), "method holder must be initialized"); + assert(!method->method_holder()->is_not_initialized() || method->intrinsic_id() == vmIntrinsics::_CompilerToVMImpl_executeCompiledMethod, "method holder must be initialized"); if (!TieredCompilation) { comp_level = CompLevel_highest_tier; diff -r ff5a32117e02 -r 22851e342f0e src/share/vm/oops/method.cpp --- a/src/share/vm/oops/method.cpp Fri Apr 12 01:53:52 2013 +0200 +++ b/src/share/vm/oops/method.cpp Fri Apr 12 04:49:07 2013 +0200 @@ -722,7 +722,7 @@ if (number_of_breakpoints() > 0) return true; if (is_method_handle_intrinsic()) - return !is_synthetic(); // the generated adapters must be compiled + return !is_synthetic() && intrinsic_id() != vmIntrinsics::_CompilerToVMImpl_executeCompiledMethod; // the generated adapters must be compiled if (comp_level == CompLevel_any) return is_not_c1_compilable() || is_not_c2_compilable(); if (is_c1_compile(comp_level)) @@ -850,7 +850,10 @@ (void) make_adapters(h_method, CHECK); // ONLY USE the h_method now as make_adapter may have blocked - + if (h_method->intrinsic_id() == vmIntrinsics::_CompilerToVMImpl_executeCompiledMethod) { + CompileBroker::compile_method(h_method, InvocationEntryBci, CompLevel_highest_tier, + methodHandle(), CompileThreshold, "executeCompiledMethod", CHECK); + } } address Method::make_adapters(methodHandle mh, TRAPS) {