changeset 8960:0ba33199edc0

invokedynamic: constant fold call site target with assumption; minor fixes
author Andreas Woess <andreas.woess@jku.at>
date Tue, 09 Apr 2013 20:37:06 +0200
parents 7fee8bd5d2bd
children 72425cbbfce3 d3c6755fdb11 977793ed5204
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteSubstitutions.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteTargetNode.java graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java src/share/vm/code/dependencies.cpp src/share/vm/graal/graalCompilerToVM.cpp
diffstat 7 files changed, 147 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Apr 09 19:25:20 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Tue Apr 09 20:37:06 2013 +0200
@@ -26,7 +26,6 @@
 import static com.oracle.graal.api.meta.MetaUtil.*;
 
 import java.lang.annotation.*;
-import java.lang.invoke.*;
 import java.lang.reflect.*;
 
 import com.oracle.graal.api.meta.*;
@@ -100,8 +99,6 @@
                 if (assumeNonStaticFinalFieldsAsFinal(receiver.asObject().getClass()) || !value.isDefaultForKind()) {
                     return value;
                 }
-            } else if (receiver.asObject() instanceof ConstantCallSite) {
-                return readValue(receiver);
             }
         }
         return null;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteSubstitutions.java	Tue Apr 09 20:37:06 2013 +0200
@@ -0,0 +1,64 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.replacements;
+
+import java.lang.invoke.*;
+
+import com.oracle.graal.api.replacements.*;
+import com.oracle.graal.api.runtime.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.phases.*;
+
+@ServiceProvider(ReplacementsProvider.class)
+public class CallSiteSubstitutions implements ReplacementsProvider {
+
+    @Override
+    public void registerReplacements(Replacements replacements) {
+        if (GraalOptions.IntrinsifyCallSiteTarget) {
+            replacements.registerSubstitutions(ConstantCallSiteSubstitutions.class);
+            replacements.registerSubstitutions(MutableCallSiteSubstitutions.class);
+            replacements.registerSubstitutions(VolatileCallSiteSubstitutions.class);
+        }
+    }
+}
+
+@ClassSubstitution(ConstantCallSite.class)
+class ConstantCallSiteSubstitutions {
+
+    @MacroSubstitution(isStatic = false, macro = CallSiteTargetNode.class)
+    public static native MethodHandle getTarget(ConstantCallSite callSite);
+}
+
+@ClassSubstitution(MutableCallSite.class)
+class MutableCallSiteSubstitutions {
+
+    @MacroSubstitution(isStatic = false, macro = CallSiteTargetNode.class)
+    public static native MethodHandle getTarget(MutableCallSite callSite);
+}
+
+@ClassSubstitution(VolatileCallSite.class)
+class VolatileCallSiteSubstitutions {
+
+    @MacroSubstitution(isStatic = false, macro = CallSiteTargetNode.class)
+    public static native MethodHandle getTarget(VolatileCallSite callSite);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteTargetNode.java	Tue Apr 09 20:37:06 2013 +0200
@@ -0,0 +1,78 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package com.oracle.graal.hotspot.replacements;
+
+import java.lang.invoke.*;
+
+import com.oracle.graal.api.code.*;
+import com.oracle.graal.api.meta.*;
+import com.oracle.graal.nodes.*;
+import com.oracle.graal.nodes.spi.*;
+import com.oracle.graal.replacements.nodes.*;
+
+public class CallSiteTargetNode extends MacroNode implements Canonicalizable, Lowerable {
+
+    public CallSiteTargetNode(Invoke invoke) {
+        super(invoke);
+    }
+
+    private ValueNode getCallSite() {
+        return arguments.get(0);
+    }
+
+    private ConstantNode getConstantCallTarget(MetaAccessProvider metaAccessProvider, Assumptions assumptions) {
+        if (getCallSite().isConstant() && !getCallSite().isNullConstant()) {
+            CallSite callSite = (CallSite) getCallSite().asConstant().asObject();
+            if (callSite instanceof ConstantCallSite) {
+                return ConstantNode.forObject(callSite.getTarget(), metaAccessProvider, graph());
+            } else if (callSite instanceof MutableCallSite || callSite instanceof VolatileCallSite && assumptions != null && assumptions.useOptimisticAssumptions()) {
+                MethodHandle target = callSite.getTarget();
+                assumptions.record(new Assumptions.CallSiteTargetValue(callSite, target));
+                return ConstantNode.forObject(target, metaAccessProvider, graph());
+            }
+        }
+        return null;
+    }
+
+    @Override
+    public ValueNode canonical(CanonicalizerTool tool) {
+        ConstantNode target = getConstantCallTarget(tool.runtime(), tool.assumptions());
+        if (target != null) {
+            return target;
+        }
+
+        return this;
+    }
+
+    @Override
+    public void lower(LoweringTool tool) {
+        StructuredGraph graph = (StructuredGraph) graph();
+        ConstantNode target = getConstantCallTarget(tool.getRuntime(), tool.assumptions());
+
+        if (target != null) {
+            graph.replaceFixedWithFloating(this, target);
+        } else {
+            graph.replaceFixedWithFixed(this, createInvoke());
+        }
+    }
+}
--- a/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Tue Apr 09 19:25:20 2013 +0200
+++ b/graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java	Tue Apr 09 20:37:06 2013 +0200
@@ -766,8 +766,7 @@
     }
 
     private void eagerResolvingForSnippets(int cpi, int bytecode) {
-        // (aw) cannot eager-resolve invokedynamic
-        if (graphBuilderConfig.eagerResolving() && bytecode != Bytecodes.INVOKEDYNAMIC) {
+        if (graphBuilderConfig.eagerResolving()) {
             constantPool.loadReferencedType(cpi, bytecode);
         }
     }
--- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java	Tue Apr 09 19:25:20 2013 +0200
+++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java	Tue Apr 09 20:37:06 2013 +0200
@@ -218,6 +218,7 @@
     public static boolean IntrinsifyMathMethods              = true;
     public static boolean IntrinsifyAESMethods               = true;
     public static boolean IntrinsifyInstalledCodeMethods     = true;
+    public static boolean IntrinsifyCallSiteTarget           = true;
     /**
      * Counts the various paths taken through snippets.
      */
--- a/src/share/vm/code/dependencies.cpp	Tue Apr 09 19:25:20 2013 +0200
+++ b/src/share/vm/code/dependencies.cpp	Tue Apr 09 20:37:06 2013 +0200
@@ -171,8 +171,8 @@
   assert_common_2(unique_concrete_method, DepValue(_oop_recorder, ctxk), DepValue(_oop_recorder, uniqm));
 }
 
-void Dependencies::assert_call_site_target_value(oop cs, oop mh) {
-  assert_common_2(call_site_target_value, DepValue(_oop_recorder, JNIHandles::make_local(cs)), DepValue(_oop_recorder, JNIHandles::make_local(mh)));
+void Dependencies::assert_call_site_target_value(oop call_site, oop method_handle) {
+  assert_common_2(call_site_target_value, DepValue(_oop_recorder, JNIHandles::make_local(call_site)), DepValue(_oop_recorder, JNIHandles::make_local(method_handle)));
 }
 #endif // GRAAL
 
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Tue Apr 09 19:25:20 2013 +0200
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Tue Apr 09 20:37:06 2013 +0200
@@ -463,7 +463,7 @@
   if (opcode != Bytecodes::_checkcast && opcode != Bytecodes::_instanceof && opcode != Bytecodes::_new && opcode != Bytecodes::_anewarray
       && opcode != Bytecodes::_multianewarray && opcode != Bytecodes::_ldc && opcode != Bytecodes::_ldc_w && opcode != Bytecodes::_ldc2_w)
   {
-    index = cp->remap_instruction_operand_from_cache(GraalCompiler::to_cp_index_u2(index));
+    index = cp->remap_instruction_operand_from_cache((opcode == Bytecodes::_invokedynamic) ? GraalCompiler::to_index_u4(index) : GraalCompiler::to_cp_index_u2(index));
   }
   constantTag tag = cp->tag_at(index);
   if (tag.is_field_or_method()) {