changeset 9026:22851e342f0e

Make calling the installed code from compiled code possible.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Fri, 12 Apr 2013 04:49:07 +0200
parents ff5a32117e02
children e0e85d78843b
files graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotInstalledCodeTest.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotInstalledCode.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotRuntime.java src/share/vm/compiler/compileBroker.cpp src/share/vm/oops/method.cpp
diffstat 5 files changed, 27 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- 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;
--- 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;
     }
--- 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;
--- 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;
--- 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) {