001/*
002 * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation.
008 *
009 * This code is distributed in the hope that it will be useful, but WITHOUT
010 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
011 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
012 * version 2 for more details (a copy is included in the LICENSE file that
013 * accompanied this code).
014 *
015 * You should have received a copy of the GNU General Public License version
016 * 2 along with this work; if not, write to the Free Software Foundation,
017 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
018 *
019 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
020 * or visit www.oracle.com if you need additional information or have any
021 * questions.
022 */
023package com.oracle.graal.nodes.extended;
024
025import jdk.internal.jvmci.meta.*;
026
027import com.oracle.graal.compiler.common.type.*;
028import com.oracle.graal.graph.*;
029import com.oracle.graal.nodeinfo.*;
030import com.oracle.graal.nodes.*;
031
032/**
033 * Copy a value at a location specified as an offset relative to a source object to another location
034 * specified as an offset relative to destination object. No null checks are performed.
035 *
036 * This node must be replaced during processing of node intrinsics with an {@link UnsafeLoadNode}
037 * and {@link UnsafeStoreNode} pair.
038 */
039@NodeInfo
040public final class UnsafeCopyNode extends FixedWithNextNode implements StateSplit {
041
042    public static final NodeClass<UnsafeCopyNode> TYPE = NodeClass.create(UnsafeCopyNode.class);
043    @Input ValueNode sourceObject;
044    @Input ValueNode destinationObject;
045    @Input ValueNode sourceOffset;
046    @Input ValueNode destinationOffset;
047    protected final Kind accessKind;
048    protected final LocationIdentity locationIdentity;
049    @OptionalInput(InputType.State) FrameState stateAfter;
050
051    public UnsafeCopyNode(ValueNode sourceObject, ValueNode sourceOffset, ValueNode destinationObject, ValueNode destinationOffset, Kind accessKind, LocationIdentity locationIdentity) {
052        this(sourceObject, sourceOffset, destinationObject, destinationOffset, accessKind, locationIdentity, null);
053    }
054
055    public UnsafeCopyNode(ValueNode sourceObject, ValueNode sourceOffset, ValueNode destinationObject, ValueNode destinationOffset, Kind accessKind, LocationIdentity locationIdentity,
056                    FrameState stateAfter) {
057        super(TYPE, StampFactory.forVoid());
058        this.sourceObject = sourceObject;
059        this.sourceOffset = sourceOffset;
060        this.destinationObject = destinationObject;
061        this.destinationOffset = destinationOffset;
062        this.accessKind = accessKind;
063        this.locationIdentity = locationIdentity;
064        this.stateAfter = stateAfter;
065        assert accessKind != Kind.Void && accessKind != Kind.Illegal;
066    }
067
068    public ValueNode sourceObject() {
069        return sourceObject;
070    }
071
072    public ValueNode destinationObject() {
073        return destinationObject;
074    }
075
076    public LocationIdentity getLocationIdentity() {
077        return locationIdentity;
078    }
079
080    public ValueNode sourceOffset() {
081        return sourceOffset;
082    }
083
084    public ValueNode destinationOffset() {
085        return destinationOffset;
086    }
087
088    public Kind accessKind() {
089        return accessKind;
090    }
091
092    public FrameState stateAfter() {
093        return stateAfter;
094    }
095
096    public void setStateAfter(FrameState x) {
097        assert x == null || x.isAlive() : "frame state must be in a graph";
098        updateUsages(stateAfter, x);
099        stateAfter = x;
100    }
101
102    public boolean hasSideEffect() {
103        return true;
104    }
105
106    public FrameState getState() {
107        return stateAfter;
108    }
109
110    @NodeIntrinsic
111    public static native void copy(Object srcObject, long srcOffset, Object destObject, long destOffset, @ConstantNodeParameter Kind kind, @ConstantNodeParameter LocationIdentity locationIdentity);
112}