# HG changeset patch # User Michael Van De Vanter # Date 1380637413 25200 # Node ID 73a2f5fc8625787aca92c999b249be2369152a24 # Parent 099af41815ea95c2b8e6be6b0dbb7400011ca44f# Parent f5faf49a86dd4bfd8e5ff6b9d6beedd280ea3f69 Merge with f5faf49a86dd4bfd8e5ff6b9d6beedd280ea3f69 diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MemoryMap.java --- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/MemoryMap.java Mon Sep 30 20:47:41 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,28 +0,0 @@ -/* - * 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.api.meta; - -public interface MemoryMap { - - T getLastLocationAccess(LocationIdentity locationIdentity); -} diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java --- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Mon Sep 30 20:47:41 2013 -0700 +++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/NewObjectSnippets.java Tue Oct 01 07:23:33 2013 -0700 @@ -58,7 +58,6 @@ public class NewObjectSnippets implements Snippets { public static final LocationIdentity INIT_LOCATION = new NamedLocationIdentity("Initialization"); - public static final LocationIdentity ARRAY_LENGTH_LOCATION = new NamedLocationIdentity("ArrayLength"); @Snippet public static Word allocate(int size) { @@ -222,7 +221,7 @@ * Formats some allocated memory with an object header and zeroes out the rest. */ public static Object formatArray(Word hub, int allocationSize, int length, int headerSize, Word memory, Word prototypeMarkWord, boolean fillContents) { - memory.writeInt(arrayLengthOffset(), length, ARRAY_LENGTH_LOCATION); + memory.writeInt(arrayLengthOffset(), length, INIT_LOCATION); /* * store hub last as the concurrent garbage collectors assume length is valid if hub field * is not null diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMapNode.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryMapNode.java Tue Oct 01 07:23:33 2013 -0700 @@ -0,0 +1,37 @@ +/* + * 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.nodes; + +import com.oracle.graal.api.meta.*; +import com.oracle.graal.graph.*; +import com.oracle.graal.nodes.calc.*; +import com.oracle.graal.nodes.type.*; + +public abstract class MemoryMapNode extends FloatingNode { + + public MemoryMapNode() { + super(StampFactory.forVoid()); + } + + public abstract Node getLastLocationAccess(LocationIdentity locationIdentity); +} diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryState.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/MemoryState.java Mon Sep 30 20:47:41 2013 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,65 +0,0 @@ -/* - * 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.nodes; - -import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; - -public class MemoryState extends VirtualState { - - private MemoryMap memoryMap; - @Input private Node object; - - public MemoryState(MemoryMap memoryMap, FixedNode object) { - this.memoryMap = memoryMap; - this.object = object; - } - - public Node object() { - return object; - } - - public MemoryMap getMemoryMap() { - return memoryMap; - } - - @Override - public VirtualState duplicateWithVirtualState() { - throw new GraalInternalError("should not reach here"); - } - - @Override - public void applyToNonVirtual(NodeClosure closure) { - throw new GraalInternalError("should not reach here"); - } - - @Override - public void applyToVirtual(VirtualClosure closure) { - throw new GraalInternalError("should not reach here"); - } - - @Override - public boolean isPartOfThisState(VirtualState state) { - throw new GraalInternalError("should not reach here"); - } -} diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ReturnNode.java --- a/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ReturnNode.java Mon Sep 30 20:47:41 2013 -0700 +++ b/graal/com.oracle.graal.nodes/src/com/oracle/graal/nodes/ReturnNode.java Tue Oct 01 07:23:33 2013 -0700 @@ -28,6 +28,7 @@ public final class ReturnNode extends ControlSinkNode implements LIRLowerable { @Input private ValueNode result; + @Input private MemoryMapNode memoryMap; public ValueNode result() { return result; @@ -40,8 +41,13 @@ * void return */ public ReturnNode(ValueNode result) { + this(result, null); + } + + public ReturnNode(ValueNode result, MemoryMapNode memoryMap) { super(StampFactory.forVoid()); this.result = result; + this.memoryMap = memoryMap; } @Override @@ -53,4 +59,13 @@ public void generate(LIRGeneratorTool gen) { gen.visitReturn(this); } + + public void setMemoryMap(MemoryMapNode memoryMap) { + updateUsages(this.memoryMap, memoryMap); + this.memoryMap = memoryMap; + } + + public MemoryMapNode getMemoryMap() { + return memoryMap; + } } diff -r 099af41815ea -r 73a2f5fc8625 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 Sep 30 20:47:41 2013 -0700 +++ b/graal/com.oracle.graal.phases.common/src/com/oracle/graal/phases/common/FloatingReadPhase.java Tue Oct 01 07:23:33 2013 -0700 @@ -27,7 +27,6 @@ import java.util.*; import com.oracle.graal.api.meta.*; -import com.oracle.graal.graph.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.PhiNode.PhiType; import com.oracle.graal.nodes.extended.*; @@ -42,7 +41,7 @@ ANALYSIS_ONLY, CREATE_FLOATING_READS } - public static class MemoryMapImpl implements MemoryMap { + public static class MemoryMapImpl extends MemoryMapNode { private IdentityHashMap lastMemorySnapshot; @@ -74,11 +73,6 @@ } } - @Override - public String toString() { - return "Map=" + lastMemorySnapshot.toString(); - } - public boolean isEmpty() { if (lastMemorySnapshot.size() == 0) { return true; @@ -92,7 +86,7 @@ } public Set getLocations() { - return new HashSet<>(lastMemorySnapshot.keySet()); + return lastMemorySnapshot.keySet(); } } @@ -192,7 +186,7 @@ assert MemoryCheckpoint.TypeAssertion.correctType(node) : node; if (execmode == ExecutionMode.ANALYSIS_ONLY && node instanceof ReturnNode) { - node.graph().add(new MemoryState(new MemoryMapImpl(state), node)); + ((ReturnNode) node).setMemoryMap(node.graph().unique(new MemoryMapImpl(state))); } return state; } diff -r 099af41815ea -r 73a2f5fc8625 graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java --- a/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Mon Sep 30 20:47:41 2013 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/InstanceOfSnippetsTemplates.java Tue Oct 01 07:23:33 2013 -0700 @@ -206,7 +206,7 @@ } @Override - public void replace(ValueNode oldNode, ValueNode newNode, MemoryMap mmap) { + public void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap) { assert newNode instanceof PhiNode; assert oldNode == instanceOf; newNode.inferStamp(); @@ -238,7 +238,7 @@ } @Override - public void replace(ValueNode oldNode, ValueNode newNode, MemoryMap mmap) { + public void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap) { assert newNode instanceof PhiNode; assert oldNode == instanceOf; newNode.inferStamp(); diff -r 099af41815ea -r 73a2f5fc8625 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 Sep 30 20:47:41 2013 -0700 +++ b/graal/com.oracle.graal.replacements/src/com/oracle/graal/replacements/SnippetTemplate.java Tue Oct 01 07:23:33 2013 -0700 @@ -34,6 +34,7 @@ import com.oracle.graal.debug.*; import com.oracle.graal.debug.internal.*; import com.oracle.graal.graph.*; +import com.oracle.graal.graph.iterators.*; import com.oracle.graal.loop.*; import com.oracle.graal.nodes.*; import com.oracle.graal.nodes.StructuredGraph.GuardsStage; @@ -540,7 +541,6 @@ } new DeadCodeEliminationPhase().apply(snippetCopy); - new CanonicalizerPhase(true).apply(snippetCopy, context); assert checkAllVarargPlaceholdersAreDeleted(parameterCount, placeholders); @@ -552,7 +552,7 @@ StartNode entryPointNode = snippet.start(); nodes = new ArrayList<>(snippet.getNodeCount()); boolean seenReturn = false; - boolean containsMemoryState = false; + boolean containsMemoryMap = false; for (Node node : snippet.getNodes()) { if (node == entryPointNode || node == entryPointNode.stateAfter()) { // Do nothing. @@ -560,18 +560,20 @@ nodes.add(node); if (node instanceof ReturnNode) { retNode = (ReturnNode) node; - for (MemoryState memstate : retNode.usages().filter(MemoryState.class).snapshot()) { - this.memoryMap = memstate.getMemoryMap(); - memstate.safeDelete(); - } + NodeIterable memstates = retNode.inputs().filter(MemoryMapNode.class); + assert memstates.count() == 1; + memoryMap = memstates.first(); + retNode.replaceFirstInput(memoryMap, null); + memoryMap.safeDelete(); + assert !seenReturn : "can handle only one ReturnNode"; seenReturn = true; - } else if (node instanceof MemoryState) { - containsMemoryState = true; + } else if (node instanceof MemoryMapNode) { + containsMemoryMap = true; } } } - assert !containsMemoryState; + assert !containsMemoryMap; this.sideEffectNodes = curSideEffectNodes; this.deoptNodes = curDeoptNodes; @@ -657,7 +659,7 @@ /** * map of killing locations to memory checkpoints (nodes). */ - private MemoryMap memoryMap; + private MemoryMapNode memoryMap; /** * Gets the instantiation-time bindings to this template's parameters. @@ -751,7 +753,7 @@ /** * Replaces all usages of {@code oldNode} with direct or indirect usages of {@code newNode}. */ - void replace(ValueNode oldNode, ValueNode newNode, MemoryMap mmap); + void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap); } /** @@ -761,7 +763,7 @@ public static final UsageReplacer DEFAULT_REPLACER = new UsageReplacer() { @Override - public void replace(ValueNode oldNode, ValueNode newNode, MemoryMap mmap) { + public void replace(ValueNode oldNode, ValueNode newNode, MemoryMapNode mmap) { oldNode.replaceAtUsages(newNode); if (mmap == null || newNode == null) { return; @@ -792,7 +794,7 @@ return true; } - Set kills = ((MemoryMapImpl) memoryMap).getLocations(); + Set kills = new HashSet<>(((MemoryMapImpl) memoryMap).getLocations()); if (replacee instanceof MemoryCheckpoint.Single) { // check if some node in snippet graph also kills the same location @@ -828,7 +830,7 @@ return true; } - private class DuplicateMapper implements MemoryMap { + private class DuplicateMapper extends MemoryMapNode { Map duplicates; StartNode replaceeStart; @@ -915,7 +917,7 @@ returnValue = (ValueNode) duplicates.get(returnNode.result()); } Node returnDuplicate = duplicates.get(returnNode); - MemoryMap mmap = new DuplicateMapper(duplicates, replaceeGraph.start()); + MemoryMapNode mmap = new DuplicateMapper(duplicates, replaceeGraph.start()); if (returnValue == null && replacee.usages().isNotEmpty() && replacee instanceof MemoryCheckpoint) { replacer.replace(replacee, (ValueNode) returnDuplicate.predecessor(), mmap); } else {