# HG changeset patch # User Tom Rodriguez # Date 1415050630 28800 # Node ID 70df63b02309bfc5c3903958701762216502dbd0 # Parent e04712c8928a8861215249b5c146c98dc6b2876c Use LocationIdentity.isImmutable instead of testing against FINAL_LOCATION diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/LocationIdentity.java Mon Nov 03 13:37:10 2014 -0800 @@ -37,12 +37,20 @@ LocationIdentity ANY_LOCATION = new NamedLocationIdentity("ANY_LOCATION"); /** - * Denotes the location of a value that is guaranteed to be final. + * Denotes the location of a value that is guaranteed to be unchanging. */ - LocationIdentity FINAL_LOCATION = new NamedLocationIdentity("FINAL_LOCATION"); + LocationIdentity FINAL_LOCATION = new NamedLocationIdentity("FINAL_LOCATION", true); /** * Denotes the location of the length field of a Java array. */ - LocationIdentity ARRAY_LENGTH_LOCATION = new NamedLocationIdentity("[].length"); + LocationIdentity ARRAY_LENGTH_LOCATION = new NamedLocationIdentity("[].length", true); + + /** + * Denotes a location is unchanging in all cases. Not that this is different than the Java + * notion of final which only requires definite assignment. + */ + default boolean isImmutable() { + return false; + } } diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/NamedLocationIdentity.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/NamedLocationIdentity.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/NamedLocationIdentity.java Mon Nov 03 13:37:10 2014 -0800 @@ -31,13 +31,26 @@ protected final String name; + protected final boolean immutable; + /** * Creates a named unique location identity for read and write operations. - * + * * @param name the name of the new location identity */ public NamedLocationIdentity(String name) { this.name = name; + this.immutable = false; + } + + /** + * Creates a named unique location identity for read and write operations. + * + * @param name the name of the new location identity + */ + public NamedLocationIdentity(String name, boolean immutable) { + this.name = name; + this.immutable = immutable; } @Override @@ -45,6 +58,10 @@ return name; } + public boolean isImmutable() { + return immutable; + } + /** * Returns the named location identity for an array of the given element kind. Array accesses of * the same kind must have the same location identity unless an alias analysis guarantees that diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java --- a/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.compiler.test/src/com/oracle/graal/compiler/test/ReadAfterCheckCastTest.java Mon Nov 03 13:37:10 2014 -0800 @@ -25,7 +25,6 @@ import org.junit.*; import com.oracle.graal.api.code.*; -import com.oracle.graal.api.meta.*; import com.oracle.graal.debug.*; import com.oracle.graal.debug.Debug.Scope; import com.oracle.graal.nodes.*; @@ -95,7 +94,7 @@ for (FloatingReadNode node : graph.getNodes(ParameterNode.class).first().usages().filter(FloatingReadNode.class)) { // Checking that the parameter a is not directly used for the access to field // x10 (because x10 must be guarded by the checkcast). - Assert.assertTrue(node.location().getLocationIdentity() == LocationIdentity.FINAL_LOCATION); + Assert.assertTrue(node.location().getLocationIdentity().isImmutable()); } } catch (Throwable e) { throw Debug.handle(e); diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMapNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMapNode.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMapNode.java Mon Nov 03 13:37:10 2014 -0800 @@ -73,7 +73,7 @@ } public MemoryNode getLastLocationAccess(LocationIdentity locationIdentity) { - if (locationIdentity == FINAL_LOCATION) { + if (locationIdentity.isImmutable()) { return null; } else { int index = locationIdentities.indexOf(locationIdentity); diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/extended/ReadNode.java Mon Nov 03 13:37:10 2014 -0800 @@ -120,8 +120,7 @@ MetaAccessProvider metaAccess = tool.getMetaAccess(); if (tool.canonicalizeReads()) { if (metaAccess != null && object != null && object.isConstant()) { - if ((location.getLocationIdentity() == LocationIdentity.FINAL_LOCATION || location.getLocationIdentity() == LocationIdentity.ARRAY_LENGTH_LOCATION) && - location instanceof ConstantLocationNode) { + if ((location.getLocationIdentity().isImmutable()) && location instanceof ConstantLocationNode) { long displacement = ((ConstantLocationNode) location).getDisplacement(); JavaConstant base = object.asJavaConstant(); if (base != null) { diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java --- a/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Mon Nov 03 13:37:10 2014 -0800 @@ -67,7 +67,7 @@ @Override public MemoryNode getLastLocationAccess(LocationIdentity locationIdentity) { MemoryNode lastLocationAccess; - if (locationIdentity == FINAL_LOCATION) { + if (locationIdentity.isImmutable()) { return null; } else { lastLocationAccess = lastMemorySnapshot.get(locationIdentity); @@ -157,7 +157,7 @@ for (MemoryMap other : states) { keys.addAll(other.getLocations()); } - assert !keys.contains(FINAL_LOCATION); + assert checkNoImmutableLocations(keys); Map existingPhis = null; if (updateExistingPhis) { @@ -209,6 +209,13 @@ } + private static boolean checkNoImmutableLocations(Set keys) { + keys.forEach(t -> { + assert !t.isImmutable(); + }); + return true; + } + public static class CollectMemoryCheckpointsClosure extends NodeIteratorClosure> { private final Map> modifiedInLoops; @@ -254,7 +261,7 @@ exit.addAll(modifiedLocations); exit.addAll(initialState); } - assert !modifiedLocations.contains(FINAL_LOCATION); + assert checkNoImmutableLocations(modifiedLocations); modifiedInLoops.put(loop, modifiedLocations); return loopInfo.exitStates; } diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java --- a/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.phases/src/com/oracle/graal/phases/schedule/SchedulePhase.java Mon Nov 03 13:37:10 2014 -0800 @@ -437,7 +437,7 @@ break; case LATEST: case LATEST_OUT_OF_LOOPS: - boolean scheduleRead = memsched == MemoryScheduling.OPTIMAL && node instanceof FloatingReadNode && ((FloatingReadNode) node).location().getLocationIdentity() != FINAL_LOCATION; + boolean scheduleRead = memsched == MemoryScheduling.OPTIMAL && node instanceof FloatingReadNode && !((FloatingReadNode) node).location().getLocationIdentity().isImmutable(); if (scheduleRead) { FloatingReadNode read = (FloatingReadNode) node; block = optimalBlock(read, strategy); @@ -508,7 +508,7 @@ assert memsched == MemoryScheduling.OPTIMAL; LocationIdentity locid = n.location().getLocationIdentity(); - assert locid != FINAL_LOCATION; + assert !locid.isImmutable(); Block upperBoundBlock = blockForMemoryNode(n.getLastLocationAccess()); Block earliestBlock = earliestBlock(n); @@ -996,7 +996,7 @@ for (ScheduledNode i : instructions) { if (i instanceof FloatingReadNode) { FloatingReadNode frn = (FloatingReadNode) i; - if (frn.location().getLocationIdentity() != FINAL_LOCATION) { + if (!frn.location().getLocationIdentity().isImmutable()) { state.addRead(frn); if (nodesFor(b).contains(frn.getLastLocationAccess())) { assert !state.isBeforeLastLocation(frn); @@ -1043,7 +1043,7 @@ private void processKillLocation(Node node, LocationIdentity identity, SortState state) { for (FloatingReadNode frn : state.readsSnapshot()) { LocationIdentity readLocation = frn.location().getLocationIdentity(); - assert readLocation != FINAL_LOCATION; + assert !readLocation.isImmutable(); if (frn.getLastLocationAccess() == node) { assert identity == ANY_LOCATION || readLocation == identity || node instanceof MemoryCheckpoint.Multi : "location doesn't match: " + readLocation + ", " + identity; state.clearBeforeLastLocation(frn); diff -r e04712c8928a -r 70df63b02309 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon Nov 03 10:31:39 2014 -0800 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Mon Nov 03 13:37:10 2014 -0800 @@ -952,7 +952,7 @@ for (Node usage : oldNode.usages().snapshot()) { LocationIdentity identity = getLocationIdentity(usage); boolean usageReplaced = false; - if (identity != null && identity != FINAL_LOCATION) { + if (identity != null && !identity.isImmutable()) { // lastLocationAccess points into the snippet graph. find a proper // MemoryCheckPoint inside the snippet graph MemoryNode lastAccess = mmap.getLastLocationAccess(identity);