1 /* 2 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 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 24 25 package org.graalvm.compiler.replacements.amd64; 26 27 import static org.graalvm.compiler.nodeinfo.InputType.Memory; 28 import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN; 29 import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_512; 30 31 import org.graalvm.compiler.core.common.type.StampFactory; 32 import org.graalvm.compiler.graph.NodeClass; 33 import org.graalvm.compiler.lir.gen.LIRGeneratorTool; 34 import org.graalvm.compiler.nodeinfo.NodeInfo; 35 import org.graalvm.compiler.nodes.FixedWithNextNode; 36 import org.graalvm.compiler.nodes.NamedLocationIdentity; 37 import org.graalvm.compiler.nodes.ValueNode; 38 import org.graalvm.compiler.nodes.ValueNodeUtil; 39 import org.graalvm.compiler.nodes.memory.MemoryAccess; 40 import org.graalvm.compiler.nodes.memory.MemoryCheckpoint; 41 import org.graalvm.compiler.nodes.memory.MemoryNode; 42 import org.graalvm.compiler.nodes.spi.LIRLowerable; 43 import org.graalvm.compiler.nodes.spi.NodeLIRBuilderTool; 44 import jdk.internal.vm.compiler.word.LocationIdentity; 45 import jdk.internal.vm.compiler.word.Pointer; 46 47 import jdk.vm.ci.meta.JavaKind; 48 49 @NodeInfo(allowedUsageTypes = Memory, size = SIZE_512, cycles = CYCLES_UNKNOWN) 50 51 public final class AMD64StringLatin1InflateNode extends FixedWithNextNode 52 implements LIRLowerable, MemoryCheckpoint.Multi, MemoryAccess { 53 54 public static final NodeClass<AMD64StringLatin1InflateNode> TYPE = NodeClass.create(AMD64StringLatin1InflateNode.class); 55 56 @Input private ValueNode src; 57 @Input private ValueNode dst; 58 @Input private ValueNode len; 59 60 private final JavaKind writeKind; 61 62 @OptionalInput(Memory) private MemoryNode lla; // Last access location registered. 63 64 // java.lang.StringLatin1.inflate([BI[CII)V 65 // 66 // void inflate(byte[] src, int src_indx, char[] dst, int dst_indx, int len) 67 // 68 // Represented as a graph node by: 69 70 public AMD64StringLatin1InflateNode(ValueNode src, ValueNode dst, ValueNode len, JavaKind writeKind) { 71 super(TYPE, StampFactory.forVoid()); 72 this.src = src; 73 this.dst = dst; 74 this.len = len; 75 this.writeKind = writeKind; 76 } 77 78 @Override 79 public LocationIdentity getLocationIdentity() { 80 // Model read access via 'src' using: 81 return NamedLocationIdentity.getArrayLocation(JavaKind.Byte); 82 } 83 84 @Override 85 public LocationIdentity[] getLocationIdentities() { 86 // Model write access via 'dst' using: 87 return new LocationIdentity[]{NamedLocationIdentity.getArrayLocation(writeKind)}; 88 } 89 90 @Override 91 public void generate(NodeLIRBuilderTool gen) { 92 LIRGeneratorTool lgt = gen.getLIRGeneratorTool(); 93 lgt.emitStringLatin1Inflate(gen.operand(src), gen.operand(dst), gen.operand(len)); 94 } 95 96 @Override 97 public MemoryNode getLastLocationAccess() { 98 return lla; 99 } 100 101 @Override 102 public void setLastLocationAccess(MemoryNode newlla) { 103 updateUsages(ValueNodeUtil.asNode(lla), ValueNodeUtil.asNode(newlla)); 104 lla = newlla; 105 } 106 107 @NodeIntrinsic 108 public static native void inflate(Pointer src, Pointer dst, int len, @ConstantNodeParameter JavaKind writeKind); 109 }