src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.replacements/src/org/graalvm/compiler/replacements/arraycopy/ArrayCopyCallNode.java
author dlong
Thu, 31 Oct 2019 16:54:16 -0700
changeset 58877 aec7bf35d6f5
parent 58299 6df94ce3ab2f
permissions -rw-r--r--
8233273: Update Graal Reviewed-by: kvn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     1
/*
58299
6df94ce3ab2f 8229201: Update Graal
dlong
parents: 54601
diff changeset
     2
 * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     4
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     7
 * published by the Free Software Foundation.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     8
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    13
 * accompanied this code).
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    14
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    18
 *
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    21
 * questions.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    22
 */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    23
//JaCoCo Exclude
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    24
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    25
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    26
package org.graalvm.compiler.replacements.arraycopy;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    27
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    28
import static org.graalvm.compiler.nodeinfo.InputType.Memory;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    29
import static org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_UNKNOWN;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    30
import static org.graalvm.compiler.nodeinfo.NodeSize.SIZE_UNKNOWN;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    31
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    32
import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    33
import org.graalvm.compiler.core.common.type.Stamp;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    34
import org.graalvm.compiler.core.common.type.StampFactory;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    35
import org.graalvm.compiler.graph.Node;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    36
import org.graalvm.compiler.graph.NodeClass;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    37
import org.graalvm.compiler.graph.spi.Canonicalizable;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    38
import org.graalvm.compiler.graph.spi.CanonicalizerTool;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    39
import org.graalvm.compiler.nodeinfo.InputType;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    40
import org.graalvm.compiler.nodeinfo.NodeInfo;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    41
import org.graalvm.compiler.nodes.ConstantNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    42
import org.graalvm.compiler.nodes.FixedWithNextNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    43
import org.graalvm.compiler.nodes.GetObjectAddressNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    44
import org.graalvm.compiler.nodes.NamedLocationIdentity;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    45
import org.graalvm.compiler.nodes.NodeView;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    46
import org.graalvm.compiler.nodes.StructuredGraph;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    47
import org.graalvm.compiler.nodes.ValueNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    48
import org.graalvm.compiler.nodes.calc.AddNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    49
import org.graalvm.compiler.nodes.calc.IntegerConvertNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    50
import org.graalvm.compiler.nodes.calc.LeftShiftNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    51
import org.graalvm.compiler.nodes.extended.ForeignCallNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    52
import org.graalvm.compiler.nodes.memory.AbstractMemoryCheckpoint;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    53
import org.graalvm.compiler.nodes.memory.MemoryAccess;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    54
import org.graalvm.compiler.nodes.memory.MemoryCheckpoint;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    55
import org.graalvm.compiler.nodes.memory.MemoryNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    56
import org.graalvm.compiler.nodes.memory.address.OffsetAddressNode;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    57
import org.graalvm.compiler.nodes.spi.Lowerable;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    58
import org.graalvm.compiler.nodes.spi.LoweringTool;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    59
import org.graalvm.compiler.word.WordTypes;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    60
import jdk.internal.vm.compiler.word.LocationIdentity;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    61
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    62
import jdk.vm.ci.code.CodeUtil;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    63
import jdk.vm.ci.meta.JavaConstant;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    64
import jdk.vm.ci.meta.JavaKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    65
import jdk.vm.ci.meta.MetaAccessProvider;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    66
import jdk.vm.ci.meta.PrimitiveConstant;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    67
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    68
@NodeInfo(allowedUsageTypes = {Memory}, cycles = CYCLES_UNKNOWN, size = SIZE_UNKNOWN)
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    69
public final class ArrayCopyCallNode extends AbstractMemoryCheckpoint implements Lowerable, MemoryCheckpoint.Single, MemoryAccess, Canonicalizable {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    70
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    71
    public static final NodeClass<ArrayCopyCallNode> TYPE = NodeClass.create(ArrayCopyCallNode.class);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    72
    @Input protected ValueNode src;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    73
    @Input protected ValueNode srcPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    74
    @Input protected ValueNode dest;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    75
    @Input protected ValueNode destPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    76
    @Input protected ValueNode length;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    77
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    78
    @OptionalInput(Memory) MemoryNode lastLocationAccess;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    79
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    80
    private final JavaKind elementKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    81
    private final LocationIdentity locationIdentity;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    82
    private final ArrayCopyForeignCalls foreignCalls;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    83
    private final JavaKind wordJavaKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    84
    private final int heapWordSize;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    85
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    86
    /**
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    87
     * Aligned means that the offset of the copy is heap word aligned.
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    88
     */
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    89
    private boolean aligned;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    90
    private boolean disjoint;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    91
    private boolean uninitialized;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    92
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    93
    public ArrayCopyCallNode(@InjectedNodeParameter ArrayCopyForeignCalls foreignCalls, @InjectedNodeParameter WordTypes wordTypes,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    94
                    ValueNode src, ValueNode srcPos, ValueNode dest, ValueNode destPos,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    95
                    ValueNode length, JavaKind elementKind, boolean aligned, boolean disjoint, boolean uninitialized, int heapWordSize) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    96
        this(foreignCalls, wordTypes, src, srcPos, dest, destPos, length, elementKind, null, aligned, disjoint, uninitialized, heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    97
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    98
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
    99
    protected ArrayCopyCallNode(@InjectedNodeParameter ArrayCopyForeignCalls foreignCalls, @InjectedNodeParameter WordTypes wordTypes,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   100
                    ValueNode src, ValueNode srcPos, ValueNode dest,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   101
                    ValueNode destPos, ValueNode length, JavaKind elementKind,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   102
                    LocationIdentity locationIdentity, boolean aligned, boolean disjoint, boolean uninitialized, int heapWordSize) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   103
        super(TYPE, StampFactory.forVoid());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   104
        assert elementKind != null;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   105
        this.src = src;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   106
        this.srcPos = srcPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   107
        this.dest = dest;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   108
        this.destPos = destPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   109
        this.length = length;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   110
        this.elementKind = elementKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   111
        this.locationIdentity = (locationIdentity != null ? locationIdentity : NamedLocationIdentity.getArrayLocation(elementKind));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   112
        this.aligned = aligned;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   113
        this.disjoint = disjoint;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   114
        this.uninitialized = uninitialized;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   115
        this.foreignCalls = foreignCalls;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   116
        this.wordJavaKind = wordTypes.getWordKind();
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   117
        this.heapWordSize = heapWordSize;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   118
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   119
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   120
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   121
    public ValueNode getSource() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   122
        return src;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   123
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   124
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   125
    public ValueNode getSourcePosition() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   126
        return srcPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   127
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   128
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   129
    public ValueNode getDestination() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   130
        return dest;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   131
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   132
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   133
    public ValueNode getDestinationPosition() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   134
        return destPos;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   135
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   136
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   137
    public ValueNode getLength() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   138
        return length;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   139
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   140
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   141
    public JavaKind getElementKind() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   142
        return elementKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   143
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   144
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   145
    private ValueNode computeBase(LoweringTool tool, ValueNode base, ValueNode pos) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   146
        FixedWithNextNode basePtr = graph().add(new GetObjectAddressNode(base));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   147
        graph().addBeforeFixed(this, basePtr);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   148
        Stamp wordStamp = StampFactory.forKind(wordJavaKind);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   149
        ValueNode wordPos = IntegerConvertNode.convert(pos, wordStamp, graph(), NodeView.DEFAULT);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   150
        int shift = CodeUtil.log2(tool.getMetaAccess().getArrayIndexScale(elementKind));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   151
        ValueNode scaledIndex = graph().unique(new LeftShiftNode(wordPos, ConstantNode.forInt(shift, graph())));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   152
        ValueNode offset = graph().unique(new AddNode(scaledIndex, ConstantNode.forIntegerStamp(wordStamp, tool.getMetaAccess().getArrayBaseOffset(elementKind), graph())));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   153
        return graph().unique(new OffsetAddressNode(basePtr, offset));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   154
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   155
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   156
    @Override
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   157
    public void lower(LoweringTool tool) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   158
        if (graph().getGuardsStage().areFrameStatesAtDeopts()) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   159
            updateAlignedDisjoint(tool.getMetaAccess());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   160
            ForeignCallDescriptor desc = foreignCalls.lookupArraycopyDescriptor(elementKind, isAligned(), isDisjoint(), isUninitialized(),
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   161
                            locationIdentity.equals(LocationIdentity.any()));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   162
            StructuredGraph graph = graph();
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   163
            ValueNode srcAddr = computeBase(tool, getSource(), getSourcePosition());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   164
            ValueNode destAddr = computeBase(tool, getDestination(), getDestinationPosition());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   165
            ValueNode len = getLength();
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   166
            if (len.stamp(NodeView.DEFAULT).getStackKind() != JavaKind.Long) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   167
                len = IntegerConvertNode.convert(len, StampFactory.forKind(JavaKind.Long), graph(), NodeView.DEFAULT);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   168
            }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   169
            ForeignCallNode call = graph.add(new ForeignCallNode(foreignCalls, desc, srcAddr, destAddr, len));
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   170
            call.setStateAfter(stateAfter());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   171
            graph.replaceFixedWithFixed(this, call);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   172
        }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   173
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   174
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   175
    @Override
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   176
    public MemoryNode getLastLocationAccess() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   177
        return lastLocationAccess;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   178
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   179
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   180
    @Override
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   181
    public void setLastLocationAccess(MemoryNode lla) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   182
        updateUsagesInterface(lastLocationAccess, lla);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   183
        lastLocationAccess = lla;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   184
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   185
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   186
    @Override
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   187
    public LocationIdentity getLocationIdentity() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   188
        return locationIdentity;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   189
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   190
58877
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
   191
    @Override
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
   192
    public LocationIdentity getKilledLocationIdentity() {
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
   193
        return getLocationIdentity();
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
   194
    }
aec7bf35d6f5 8233273: Update Graal
dlong
parents: 58299
diff changeset
   195
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents: 54084
diff changeset
   196
    @NodeIntrinsic(hasSideEffect = true)
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   197
    private static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter boolean aligned,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   198
                    @ConstantNodeParameter boolean disjoint, @ConstantNodeParameter boolean uninitialized, @ConstantNodeParameter int heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   199
54601
c40b2a190173 8221598: Update Graal
jwilhelm
parents: 54084
diff changeset
   200
    @NodeIntrinsic(hasSideEffect = true)
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   201
    private static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   202
                    @ConstantNodeParameter LocationIdentity locationIdentity, @ConstantNodeParameter boolean aligned, @ConstantNodeParameter boolean disjoint,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   203
                    @ConstantNodeParameter boolean uninitialized, @ConstantNodeParameter int heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   204
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   205
    public static void arraycopyObjectKillsAny(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter int heapWordSize) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   206
        arraycopy(src, srcPos, dest, destPos, length, JavaKind.Object, LocationIdentity.any(), false, false, false, heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   207
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   208
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   209
    public static void arraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter LocationIdentity locationIdentity,
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   210
                    @ConstantNodeParameter int heapWordSize) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   211
        arraycopy(src, srcPos, dest, destPos, length, elementKind, locationIdentity, false, false, false, heapWordSize);
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   212
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   213
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   214
    public static void disjointArraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter int heapWordSize) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   215
        arraycopy(src, srcPos, dest, destPos, length, elementKind, false, true, false, heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   216
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   217
54084
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   218
    public static void disjointArraycopyKillsAny(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind, @ConstantNodeParameter int heapWordSize) {
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   219
        arraycopy(src, srcPos, dest, destPos, length, elementKind, LocationIdentity.any(), false, true, false, heapWordSize);
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   220
    }
84f10bbf993f 8218074: Update Graal
jwilhelm
parents: 52910
diff changeset
   221
52910
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   222
    public static void disjointUninitializedArraycopy(Object src, int srcPos, Object dest, int destPos, int length, @ConstantNodeParameter JavaKind elementKind,
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   223
                    @ConstantNodeParameter int heapWordSize) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   224
        arraycopy(src, srcPos, dest, destPos, length, elementKind, false, true, true, heapWordSize);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   225
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   226
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   227
    public boolean isAligned() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   228
        return aligned;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   229
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   230
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   231
    public boolean isDisjoint() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   232
        return disjoint;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   233
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   234
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   235
    public boolean isUninitialized() {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   236
        return uninitialized;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   237
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   238
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   239
    boolean isHeapWordAligned(MetaAccessProvider metaAccess, JavaConstant value, JavaKind kind) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   240
        return (metaAccess.getArrayBaseOffset(kind) + (long) value.asInt() * metaAccess.getArrayIndexScale(kind)) % heapWordSize == 0;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   241
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   242
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   243
    public void updateAlignedDisjoint(MetaAccessProvider metaAccess) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   244
        JavaKind componentKind = elementKind;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   245
        if (srcPos == destPos) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   246
            // Can treat as disjoint
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   247
            disjoint = true;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   248
        }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   249
        PrimitiveConstant constantSrc = (PrimitiveConstant) srcPos.stamp(NodeView.DEFAULT).asConstant();
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   250
        PrimitiveConstant constantDst = (PrimitiveConstant) destPos.stamp(NodeView.DEFAULT).asConstant();
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   251
        if (constantSrc != null && constantDst != null) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   252
            if (!aligned) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   253
                aligned = isHeapWordAligned(metaAccess, constantSrc, componentKind) && isHeapWordAligned(metaAccess, constantDst, componentKind);
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   254
            }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   255
            if (constantSrc.asInt() >= constantDst.asInt()) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   256
                // low to high copy so treat as disjoint
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   257
                disjoint = true;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   258
            }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   259
        }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   260
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   261
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   262
    @Override
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   263
    public Node canonical(CanonicalizerTool tool) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   264
        if (getLength().isConstant() && getLength().asConstant().isDefaultForKind()) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   265
            if (lastLocationAccess != null) {
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   266
                replaceAtUsages(InputType.Memory, lastLocationAccess.asNode());
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   267
            }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   268
            return null;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   269
        }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   270
        return this;
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   271
    }
583fd71c47d6 8214023: Update Graal
dlong
parents:
diff changeset
   272
}