# HG changeset patch # User Andreas Woess # Date 1365532626 -7200 # Node ID 0ba33199edc04f1bf09da02facde6cd04dc9aeb6 # Parent 7fee8bd5d2bde33ffd9658b78cfb0a6e39f4bffa invokedynamic: constant fold call site target with assumption; minor fixes diff -r 7fee8bd5d2bd -r 0ba33199edc0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java --- 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; diff -r 7fee8bd5d2bd -r 0ba33199edc0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteSubstitutions.java --- /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); +} diff -r 7fee8bd5d2bd -r 0ba33199edc0 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/CallSiteTargetNode.java --- /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()); + } + } +} diff -r 7fee8bd5d2bd -r 0ba33199edc0 graal/com.oracle.graal.java/src/com/oracle/graal/java/GraphBuilderPhase.java --- 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); } } diff -r 7fee8bd5d2bd -r 0ba33199edc0 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/GraalOptions.java --- 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. */ diff -r 7fee8bd5d2bd -r 0ba33199edc0 src/share/vm/code/dependencies.cpp --- 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 diff -r 7fee8bd5d2bd -r 0ba33199edc0 src/share/vm/graal/graalCompilerToVM.cpp --- 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()) {