# HG changeset patch # User Thomas Wuerthinger # Date 1423867516 -3600 # Node ID 4d9ff841882c4f3754d9c63c27174b0410938962 # Parent f9ccdf258dd40b35bcd8ccfbaa57d6bbf2ef7d26# Parent afe80ca4b0f02a213d67d2f037089f05b33c2db3 Merge. diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IllegalStamp.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IllegalStamp.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/IllegalStamp.java Fri Feb 13 23:45:16 2015 +0100 @@ -94,7 +94,7 @@ throw GraalInternalError.shouldNotReachHere("can't read values of illegal stamp"); } - private static IllegalStamp instance = new IllegalStamp(); + private static final IllegalStamp instance = new IllegalStamp(); static IllegalStamp getInstance() { return instance; diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/VoidStamp.java --- a/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/VoidStamp.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.compiler.common/src/com/oracle/graal/compiler/common/type/VoidStamp.java Fri Feb 13 23:45:16 2015 +0100 @@ -112,7 +112,7 @@ throw GraalInternalError.shouldNotReachHere("void stamp has no value"); } - private static VoidStamp instance = new VoidStamp(); + private static final VoidStamp instance = new VoidStamp(); static VoidStamp getInstance() { return instance; diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java --- a/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.compiler/src/com/oracle/graal/compiler/match/MatchProcessor.java Fri Feb 13 23:45:16 2015 +0100 @@ -74,7 +74,7 @@ } } - private static Pattern tokenizer = Pattern.compile("\\s*([()=]|[A-Za-z][A-Za-z0-9]*)\\s*"); + private static final Pattern tokenizer = Pattern.compile("\\s*([()=]|[A-Za-z][A-Za-z0-9]*)\\s*"); private class RuleParser { private ArrayList capturedTypes = new ArrayList<>(); diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/DebugValueMap.java Fri Feb 13 23:45:16 2015 +0100 @@ -29,7 +29,7 @@ */ public class DebugValueMap { - private static List topLevelMaps = new ArrayList<>(); + private static final List topLevelMaps = new ArrayList<>(); private long[] values; private List children; diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/KeyRegistry.java --- a/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/KeyRegistry.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.debug/src/com/oracle/graal/debug/internal/KeyRegistry.java Fri Feb 13 23:45:16 2015 +0100 @@ -29,12 +29,12 @@ */ public class KeyRegistry { - private static Map keyMap = new HashMap<>(); - private static List debugValues = new ArrayList<>(); + private static final Map keyMap = new HashMap<>(); + private static final List debugValues = new ArrayList<>(); /** * Ensures a given debug value is registered. - * + * * @return the globally unique id for {@code value} */ public static synchronized int register(DebugValue value) { @@ -48,7 +48,7 @@ /** * Gets a immutable view of the registered debug values. - * + * * @return a list where {@code get(i).getIndex() == i} */ public static synchronized List getDebugValues() { diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/NodeIntrinsificationPhase.java Fri Feb 13 23:45:16 2015 +0100 @@ -171,34 +171,41 @@ } ConstantNode constantNode = (ConstantNode) argument; Constant constant = constantNode.asConstant(); - ResolvedJavaType type = providers.getConstantReflection().asJavaType(constant); + /* + * For intrinsification (but not for folding) if we have a Class object we want + * the corresponding ResolvedJavaType. + */ + ResolvedJavaType type = folding ? null : providers.getConstantReflection().asJavaType(constant); + Object arg; if (type != null) { - reflectionCallArguments[i] = type; + /* If we found such a type then it's our arg */ + arg = type; parameterTypes[i] = providers.getMetaAccess().lookupJavaType(ResolvedJavaType.class); } else { JavaConstant javaConstant = (JavaConstant) constant; - if (parameterTypes[i].getKind() == Kind.Boolean) { - reflectionCallArguments[i] = Boolean.valueOf(javaConstant.asInt() != 0); - } else if (parameterTypes[i].getKind() == Kind.Byte) { - reflectionCallArguments[i] = Byte.valueOf((byte) javaConstant.asInt()); - } else if (parameterTypes[i].getKind() == Kind.Short) { - reflectionCallArguments[i] = Short.valueOf((short) javaConstant.asInt()); - } else if (parameterTypes[i].getKind() == Kind.Char) { - reflectionCallArguments[i] = Character.valueOf((char) javaConstant.asInt()); - } else if (parameterTypes[i].getKind() == Kind.Object) { - if (!folding) { - reflectionCallArguments[i] = snippetReflection.asObject(parameterTypes[i], javaConstant); + if (folding) { + /* For folding we want JavaConstants */ + arg = javaConstant; + } else { + /* For intrinsification we want want corresponding objects */ + if (parameterTypes[i].getKind() == Kind.Boolean) { + arg = Boolean.valueOf(javaConstant.asInt() != 0); + } else if (parameterTypes[i].getKind() == Kind.Byte) { + arg = Byte.valueOf((byte) javaConstant.asInt()); + } else if (parameterTypes[i].getKind() == Kind.Short) { + arg = Short.valueOf((short) javaConstant.asInt()); + } else if (parameterTypes[i].getKind() == Kind.Char) { + arg = Character.valueOf((char) javaConstant.asInt()); + } else if (parameterTypes[i].getKind() == Kind.Object) { + arg = snippetReflection.asObject(parameterTypes[i], javaConstant); } else { - reflectionCallArguments[i] = javaConstant; + arg = javaConstant.asBoxedPrimitive(); } - } else { - reflectionCallArguments[i] = javaConstant.asBoxedPrimitive(); } } - if (folding && reflectionCallArguments[i] != constant) { - assert !(reflectionCallArguments[i] instanceof JavaConstant); - reflectionCallArguments[i] = snippetReflection.forObject(reflectionCallArguments[i]); - } + + assert folding || !(arg instanceof JavaConstant); + reflectionCallArguments[i] = arg; } else { reflectionCallArguments[i] = argument; parameterTypes[i] = providers.getMetaAccess().lookupJavaType(ValueNode.class); @@ -241,7 +248,7 @@ } try { - ValueNode intrinsicNode = (ValueNode) snippetReflection.invoke(constructor, null, arguments); + ValueNode intrinsicNode = (ValueNode) invokeConstructor(constructor, arguments); if (setStampFromReturnType) { intrinsicNode.setStamp(invokeStamp); @@ -252,6 +259,10 @@ } } + protected Object invokeConstructor(ResolvedJavaMethod constructor, Object[] arguments) { + return snippetReflection.invoke(constructor, null, arguments); + } + private static String sigString(ResolvedJavaType[] types) { StringBuilder sb = new StringBuilder("("); for (int i = 0; i < types.length; i++) { diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/GraphEffectList.java Fri Feb 13 23:45:16 2015 +0100 @@ -108,14 +108,14 @@ add("add virtual mapping", new Effect() { @Override public void apply(StructuredGraph graph, ArrayList obsoleteNodes) { - assert node.isAlive() && !state.isAlive() && !state.isDeleted(); + assert node.isAlive() && !state.isDeleted(); FrameState stateAfter = node; for (int i = 0; i < stateAfter.virtualObjectMappingCount(); i++) { if (stateAfter.virtualObjectMappingAt(i).object() == state.object()) { stateAfter.virtualObjectMappings().remove(i); } } - stateAfter.addVirtualObjectMapping(graph.unique(state)); + stateAfter.addVirtualObjectMapping(state.isAlive() ? state : graph.unique(state)); } @Override diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ObjectState.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ObjectState.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/ObjectState.java Fri Feb 13 23:45:16 2015 +0100 @@ -24,11 +24,13 @@ import java.util.*; +import com.oracle.graal.debug.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.java.*; import com.oracle.graal.nodes.spi.*; import com.oracle.graal.nodes.spi.Virtualizable.EscapeState; import com.oracle.graal.nodes.virtual.*; +import com.oracle.graal.virtual.nodes.*; /** * This class describes the state of a virtual object while iterating over the graph. It describes @@ -37,6 +39,9 @@ */ public class ObjectState extends Virtualizable.State { + public static final DebugMetric CREATE_ESCAPED_OBJECT_STATE = Debug.metric("CreateEscapeObjectState"); + public static final DebugMetric GET_ESCAPED_OBJECT_STATE = Debug.metric("GetEscapeObjectState"); + final VirtualObjectNode virtual; private EscapeState state; @@ -44,6 +49,8 @@ private ValueNode materializedValue; private LockState locks; + private EscapeObjectState cachedState; + public ObjectState(VirtualObjectNode virtual, ValueNode[] entries, EscapeState state, List locks) { this(virtual, entries, state, (LockState) null); for (int i = locks.size() - 1; i >= 0; i--) { @@ -71,12 +78,23 @@ materializedValue = other.materializedValue; locks = other.locks; state = other.state; + cachedState = other.cachedState; } public ObjectState cloneState() { return new ObjectState(this); } + public EscapeObjectState createEscapeObjectState() { + GET_ESCAPED_OBJECT_STATE.increment(); + if (cachedState == null) { + CREATE_ESCAPED_OBJECT_STATE.increment(); + cachedState = isVirtual() ? new VirtualObjectState(virtual, entries) : new MaterializedObjectState(virtual, materializedValue); + } + return cachedState; + + } + @Override public EscapeState getState() { return state; @@ -104,7 +122,10 @@ public void setEntry(int index, ValueNode value) { assert isVirtual(); - entries[index] = value; + if (entries[index] != value) { + cachedState = null; + entries[index] = value; + } } public void escape(ValueNode materialized, EscapeState newState) { @@ -112,6 +133,7 @@ state = newState; materializedValue = materialized; entries = null; + cachedState = null; assert !isVirtual(); } @@ -123,7 +145,10 @@ public void updateMaterializedValue(ValueNode value) { assert !isVirtual(); - materializedValue = value; + if (value != materializedValue) { + cachedState = null; + materializedValue = value; + } } @Override diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java --- a/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.graal.virtual/src/com/oracle/graal/virtual/phases/ea/PartialEscapeClosure.java Fri Feb 13 23:45:16 2015 +0100 @@ -38,7 +38,6 @@ import com.oracle.graal.nodes.spi.Virtualizable.EscapeState; import com.oracle.graal.nodes.virtual.*; import com.oracle.graal.phases.schedule.*; -import com.oracle.graal.virtual.nodes.*; public abstract class PartialEscapeClosure> extends EffectsClosure { @@ -162,7 +161,7 @@ frameState.applyToNonVirtual(new CollectVirtualObjectsClosure(virtual, effects, state)); collectLockedVirtualObjects(state, virtual); collectReferencedVirtualObjects(state, virtual); - addVirtualMappings(state, effects, frameState, virtual); + addVirtualMappings(effects, frameState, virtual); } } @@ -176,15 +175,9 @@ return frameState; } - private void addVirtualMappings(final BlockT state, final GraphEffectList effects, FrameState frameState, Set virtual) { + private static void addVirtualMappings(GraphEffectList effects, FrameState frameState, Set virtual) { for (ObjectState obj : virtual) { - EscapeObjectState v; - if (obj.isVirtual()) { - v = createVirtualObjectState(state, obj); - } else { - v = new MaterializedObjectState(obj.virtual, obj.getMaterializedValue()); - } - effects.addVirtualMapping(frameState, v); + effects.addVirtualMapping(frameState, obj.createEscapeObjectState()); } } @@ -206,24 +199,7 @@ } } - private EscapeObjectState createVirtualObjectState(final BlockT state, ObjectState obj) { - EscapeObjectState v; - ValueNode[] fieldState = obj.getEntries().clone(); - for (int i = 0; i < fieldState.length; i++) { - ObjectState valueObj = getObjectState(state, fieldState[i]); - if (valueObj != null) { - if (valueObj.isVirtual()) { - fieldState[i] = valueObj.virtual; - } else { - fieldState[i] = valueObj.getMaterializedValue(); - } - } - } - v = new VirtualObjectState(obj.virtual, fieldState); - return v; - } - - private void collectLockedVirtualObjects(final BlockT state, final Set virtual) { + private void collectLockedVirtualObjects(final BlockT state, Set virtual) { for (ObjectState obj : state.getStates()) { if (obj.isVirtual() && obj.hasLocks()) { virtual.add(obj); @@ -239,6 +215,7 @@ if (obj.getState() == EscapeState.Virtual) { metric.increment(); state.materializeBefore(materializeBefore, obj.virtual, EscapeState.Materialized, effects); + updateStatesForMaterialized(state, obj); assert !obj.isVirtual(); return true; } else { @@ -247,6 +224,20 @@ } } + private static void updateStatesForMaterialized(PartialEscapeBlockState state, ObjectState obj) { + // update all existing states with the newly materialized object + for (ObjectState objState : state.objectStates.values()) { + if (objState.isVirtual()) { + ValueNode[] entries = objState.getEntries(); + for (int i = 0; i < entries.length; i++) { + if (entries[i] == obj.virtual) { + objState.setEntry(i, obj.getMaterializedValue()); + } + } + } + } + } + private boolean replaceWithMaterialized(Node value, Node usage, FixedNode materializeBefore, BlockT state, ObjectState obj, GraphEffectList effects, DebugMetric metric) { boolean materialized = ensureMaterialized(state, obj, materializeBefore, effects, metric); effects.replaceFirstInput(usage, value, obj.getMaterializedValue()); @@ -538,8 +529,8 @@ int valueIndex = 0; while (valueIndex < values.length) { for (int i = 1; i < objStates.length; i++) { - ValueNode[] fields = objStates[i].getEntries(); - if (phis[valueIndex] == null && values[valueIndex] != fields[valueIndex]) { + ValueNode field = objStates[i].getEntry(valueIndex); + if (phis[valueIndex] == null && values[valueIndex] != field) { phis[valueIndex] = new ValuePhiNode(values[valueIndex].stamp().unrestricted(), merge); } } @@ -596,14 +587,16 @@ if (!objStates[i].isVirtual()) { break; } - ValueNode[] entries = objStates[i].getEntries(); - if (entries[entryIndex] instanceof VirtualObjectNode) { - ObjectState obj = blockStates.get(i).getObjectState((VirtualObjectNode) entries[entryIndex]); + ValueNode entry = objStates[i].getEntry(entryIndex); + if (entry instanceof VirtualObjectNode) { + ObjectState obj = blockStates.get(i).getObjectState((VirtualObjectNode) entry); Block predecessor = mergeBlock.getPredecessors().get(i); materialized |= ensureMaterialized(blockStates.get(i), obj, predecessor.getEndNode(), blockEffects.get(predecessor), METRIC_MATERIALIZATIONS_MERGE); - entries[entryIndex] = obj.getMaterializedValue(); + if (objStates[i].isVirtual()) { + objStates[i].setEntry(entryIndex, entry = obj.getMaterializedValue()); + } } - afterMergeEffects.addPhiInput(phi, entries[entryIndex]); + afterMergeEffects.addPhiInput(phi, entry); } return materialized; } @@ -617,7 +610,7 @@ if (!state.isVirtual()) { break; } - afterMergeEffects.addPhiInput(phi, state.getEntries()[entryIndex]); + afterMergeEffects.addPhiInput(phi, state.getEntry(entryIndex)); } } diff -r f9ccdf258dd4 -r 4d9ff841882c graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java --- a/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java Fri Feb 13 23:35:38 2015 +0100 +++ b/graal/com.oracle.truffle.api/src/com/oracle/truffle/api/TruffleOptions.java Fri Feb 13 23:45:16 2015 +0100 @@ -38,14 +38,14 @@ *

* Can be set with {@code -Dtruffle.ForceInterpreter=true}. */ - public static boolean ForceInterpreter = Boolean.getBoolean("truffle.ForceInterpreter"); + public static final boolean ForceInterpreter = Boolean.getBoolean("truffle.ForceInterpreter"); /** * Enables/disables the rewriting of traces in the Truffle runtime to stdout. *

* Can be set with {@code -Dtruffle.TraceRewrites=true}. */ - public static boolean TraceRewrites; + public static final boolean TraceRewrites; /** * Enables the generation of detailed rewrite reasons. Enabling this may introduce some overhead @@ -97,20 +97,20 @@ } static { - final boolean[] values = {false, false}; + final boolean[] values = new boolean[3]; AccessController.doPrivileged(new PrivilegedAction() { public Void run() { - TraceRewrites = Boolean.getBoolean("truffle.TraceRewrites"); + values[0] = Boolean.getBoolean("truffle.TraceRewrites"); TraceRewritesFilterClass = System.getProperty("truffle.TraceRewritesFilterClass"); TraceRewritesFilterFromCost = parseNodeInfoKind(System.getProperty("truffle.TraceRewritesFilterFromCost")); TraceRewritesFilterToCost = parseNodeInfoKind(System.getProperty("truffle.TraceRewritesFilterToCost")); - values[0] = Boolean.getBoolean("truffle.DetailedRewriteReasons"); - values[1] = Boolean.getBoolean("truffle.TraceASTJSON"); + values[1] = Boolean.getBoolean("truffle.DetailedRewriteReasons"); + values[2] = Boolean.getBoolean("truffle.TraceASTJSON"); return null; } }); - - DetailedRewriteReasons = values[0]; - TraceASTJSON = values[1]; + TraceRewrites = values[0]; + DetailedRewriteReasons = values[1]; + TraceASTJSON = values[2]; } }