7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.replacements.nodes; 24 25 import static org.graalvm.compiler.nodeinfo.InputType.Memory; 26 import static org.graalvm.compiler.nodeinfo.InputType.State; 27 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_256; 28 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_64; 29 import static org.graalvm.word.LocationIdentity.any; 30 31 import org.graalvm.compiler.core.common.type.StampFactory; 32 import org.graalvm.compiler.debug.DebugContext; 33 import org.graalvm.compiler.graph.NodeClass; 34 import org.graalvm.compiler.graph.NodeInputList; 35 import org.graalvm.compiler.nodeinfo.NodeInfo; 36 import org.graalvm.compiler.nodes.ConstantNode; 37 import org.graalvm.compiler.nodes.DeoptimizingNode; 38 import org.graalvm.compiler.nodes.FrameState; 39 import org.graalvm.compiler.nodes.NamedLocationIdentity; 40 import org.graalvm.compiler.nodes.ValueNode; 41 import org.graalvm.compiler.nodes.java.LoadIndexedNode; 42 import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint; 43 import org.graalvm.compiler.nodes.memory.MemoryAccess; 44 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint; 45 import org.graalvm.compiler.nodes.memory.MemoryNode; 46 import org.graalvm.compiler.nodes.spi.Lowerable; 47 import org.graalvm.compiler.nodes.spi.LoweringTool; 48 import org.graalvm.compiler.nodes.spi.Virtualizable; 49 import org.graalvm.compiler.nodes.spi.VirtualizerTool; 50 import org.graalvm.compiler.nodes.type.StampTool; 51 import org.graalvm.compiler.nodes.virtual.VirtualArrayNode; 52 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; 53 import org.graalvm.word.LocationIdentity; 54 55 import jdk.vm.ci.code.BytecodeFrame; 56 import jdk.vm.ci.meta.JavaKind; 57 import jdk.vm.ci.meta.ResolvedJavaType; 58 59 @NodeInfo(cycles = CYCLES_256, size = SIZE_64) 60 public class BasicArrayCopyNode extends AbstractMemoryCheckpoint implements Virtualizable, MemoryCheckpoint.Single, MemoryAccess, Lowerable, DeoptimizingNode.DeoptDuring { 61 62 public static final NodeClass<BasicArrayCopyNode> TYPE = NodeClass.create(BasicArrayCopyNode.class); 63 64 static final int SRC_ARG = 0; 65 static final int SRC_POS_ARG = 1; 66 static final int DEST_ARG = 2; 67 static final int DEST_POS_ARG = 3; 68 static final int LENGTH_ARG = 4; 69 70 @Input NodeInputList<ValueNode> args; 71 72 @OptionalInput(State) FrameState stateDuring; 73 74 @OptionalInput(Memory) protected MemoryNode lastLocationAccess; 75 76 protected JavaKind elementKind; 77 78 protected int bci; 79 198 if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) { 199 return; 200 } 201 ValueNode srcAlias = tool.getAlias(getSource()); 202 203 if (srcAlias instanceof VirtualObjectNode) { 204 if (!(srcAlias instanceof VirtualArrayNode)) { 205 return; 206 } 207 VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias; 208 if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) { 209 return; 210 } 211 if (!checkBounds(srcPosInt, len, srcVirtual)) { 212 return; 213 } 214 if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) { 215 return; 216 } 217 for (int i = 0; i < len; i++) { 218 tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i), false); 219 } 220 tool.delete(); 221 DebugContext debug = getDebug(); 222 if (debug.isLogEnabled()) { 223 debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len); 224 } 225 } else { 226 ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias); 227 if (sourceType == null || !sourceType.isArray()) { 228 return; 229 } 230 ResolvedJavaType sourceComponentType = sourceType.getComponentType(); 231 ResolvedJavaType destComponentType = destVirtual.type().getComponentType(); 232 if (!sourceComponentType.equals(destComponentType)) { 233 return; 234 } 235 for (int i = 0; i < len; i++) { 236 LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind()); 237 tool.addNode(load); 238 tool.setVirtualEntry(destVirtual, destPosInt + i, load, false); 239 } 240 tool.delete(); 241 } 242 } 243 } 244 } 245 246 @Override 247 public boolean canDeoptimize() { 248 return true; 249 } 250 251 @Override 252 public FrameState stateDuring() { 253 return stateDuring; 254 } 255 256 @Override 257 public void setStateDuring(FrameState stateDuring) { 258 updateUsages(this.stateDuring, stateDuring); | 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 package org.graalvm.compiler.replacements.nodes; 24 25 import static org.graalvm.compiler.nodeinfo.InputType.Memory; 26 import static org.graalvm.compiler.nodeinfo.InputType.State; 27 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_64; 28 import static org.graalvm.word.LocationIdentity.any; 29 30 import org.graalvm.compiler.core.common.type.StampFactory; 31 import org.graalvm.compiler.debug.DebugContext; 32 import org.graalvm.compiler.graph.NodeClass; 33 import org.graalvm.compiler.graph.NodeInputList; 34 import org.graalvm.compiler.nodeinfo.NodeCycles; 35 import org.graalvm.compiler.nodeinfo.NodeInfo; 36 import org.graalvm.compiler.nodes.ConstantNode; 37 import org.graalvm.compiler.nodes.DeoptimizingNode; 38 import org.graalvm.compiler.nodes.FrameState; 39 import org.graalvm.compiler.nodes.NamedLocationIdentity; 40 import org.graalvm.compiler.nodes.ValueNode; 41 import org.graalvm.compiler.nodes.java.LoadIndexedNode; 42 import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint; 43 import org.graalvm.compiler.nodes.memory.MemoryAccess; 44 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint; 45 import org.graalvm.compiler.nodes.memory.MemoryNode; 46 import org.graalvm.compiler.nodes.spi.Lowerable; 47 import org.graalvm.compiler.nodes.spi.LoweringTool; 48 import org.graalvm.compiler.nodes.spi.Virtualizable; 49 import org.graalvm.compiler.nodes.spi.VirtualizerTool; 50 import org.graalvm.compiler.nodes.type.StampTool; 51 import org.graalvm.compiler.nodes.virtual.VirtualArrayNode; 52 import org.graalvm.compiler.nodes.virtual.VirtualObjectNode; 53 import org.graalvm.word.LocationIdentity; 54 55 import jdk.vm.ci.code.BytecodeFrame; 56 import jdk.vm.ci.meta.JavaKind; 57 import jdk.vm.ci.meta.ResolvedJavaType; 58 59 @NodeInfo(cycles = NodeCycles.CYCLES_UNKNOWN, size = SIZE_64) 60 public class BasicArrayCopyNode extends AbstractMemoryCheckpoint implements Virtualizable, MemoryCheckpoint.Single, MemoryAccess, Lowerable, DeoptimizingNode.DeoptDuring { 61 62 public static final NodeClass<BasicArrayCopyNode> TYPE = NodeClass.create(BasicArrayCopyNode.class); 63 64 static final int SRC_ARG = 0; 65 static final int SRC_POS_ARG = 1; 66 static final int DEST_ARG = 2; 67 static final int DEST_POS_ARG = 3; 68 static final int LENGTH_ARG = 4; 69 70 @Input NodeInputList<ValueNode> args; 71 72 @OptionalInput(State) FrameState stateDuring; 73 74 @OptionalInput(Memory) protected MemoryNode lastLocationAccess; 75 76 protected JavaKind elementKind; 77 78 protected int bci; 79 198 if (len < 0 || !checkBounds(destPosInt, len, destVirtual)) { 199 return; 200 } 201 ValueNode srcAlias = tool.getAlias(getSource()); 202 203 if (srcAlias instanceof VirtualObjectNode) { 204 if (!(srcAlias instanceof VirtualArrayNode)) { 205 return; 206 } 207 VirtualArrayNode srcVirtual = (VirtualArrayNode) srcAlias; 208 if (destVirtual.componentType().getJavaKind() != srcVirtual.componentType().getJavaKind()) { 209 return; 210 } 211 if (!checkBounds(srcPosInt, len, srcVirtual)) { 212 return; 213 } 214 if (!checkEntryTypes(srcPosInt, len, srcVirtual, destVirtual.type().getComponentType(), tool)) { 215 return; 216 } 217 for (int i = 0; i < len; i++) { 218 tool.setVirtualEntry(destVirtual, destPosInt + i, tool.getEntry(srcVirtual, srcPosInt + i)); 219 } 220 tool.delete(); 221 DebugContext debug = getDebug(); 222 if (debug.isLogEnabled()) { 223 debug.log("virtualized arraycopy(%s, %d, %s, %d, %d)", getSource(), srcPosInt, getDestination(), destPosInt, len); 224 } 225 } else { 226 ResolvedJavaType sourceType = StampTool.typeOrNull(srcAlias); 227 if (sourceType == null || !sourceType.isArray()) { 228 return; 229 } 230 ResolvedJavaType sourceComponentType = sourceType.getComponentType(); 231 ResolvedJavaType destComponentType = destVirtual.type().getComponentType(); 232 if (!sourceComponentType.equals(destComponentType)) { 233 return; 234 } 235 for (int i = 0; i < len; i++) { 236 LoadIndexedNode load = new LoadIndexedNode(graph().getAssumptions(), srcAlias, ConstantNode.forInt(i + srcPosInt, graph()), destComponentType.getJavaKind()); 237 tool.addNode(load); 238 tool.setVirtualEntry(destVirtual, destPosInt + i, load); 239 } 240 tool.delete(); 241 } 242 } 243 } 244 } 245 246 @Override 247 public boolean canDeoptimize() { 248 return true; 249 } 250 251 @Override 252 public FrameState stateDuring() { 253 return stateDuring; 254 } 255 256 @Override 257 public void setStateDuring(FrameState stateDuring) { 258 updateUsages(this.stateDuring, stateDuring); |