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.virtual;
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.*;
031import com.oracle.graal.nodes.spi.*;
032
033@NodeInfo
034public abstract class VirtualObjectNode extends ValueNode implements LIRLowerable, IterableNodeType {
035
036    public static final NodeClass<VirtualObjectNode> TYPE = NodeClass.create(VirtualObjectNode.class);
037    protected boolean hasIdentity;
038    private int objectId = -1;
039
040    protected VirtualObjectNode(NodeClass<? extends VirtualObjectNode> c, ResolvedJavaType type, boolean hasIdentity) {
041        super(c, StampFactory.exactNonNull(type));
042        this.hasIdentity = hasIdentity;
043    }
044
045    public final int getObjectId() {
046        return objectId;
047    }
048
049    public final void resetObjectId() {
050        this.objectId = -1;
051    }
052
053    public final void setObjectId(int objectId) {
054        assert objectId != -1;
055        this.objectId = objectId;
056    }
057
058    @Override
059    protected void afterClone(Node other) {
060        super.afterClone(other);
061        resetObjectId();
062    }
063
064    /**
065     * The type of object described by this {@link VirtualObjectNode}. In case of arrays, this is
066     * the array type (and not the component type).
067     */
068    public abstract ResolvedJavaType type();
069
070    /**
071     * The number of entries this virtual object has. Either the number of fields or the number of
072     * array elements.
073     */
074    public abstract int entryCount();
075
076    /**
077     * Returns the name of the entry at the given index. Only used for debugging purposes.
078     */
079    public abstract String entryName(int i);
080
081    /**
082     * If the given index denotes an entry in this virtual object, the index of this entry is
083     * returned. If no such entry can be found, this method returns -1.
084     *
085     * @param constantOffset offset, where the value is placed.
086     * @param expectedEntryKind Specifies which type is expected at this offset (Is important when
087     *            doing implicit casts, especially on big endian systems.
088     */
089    public abstract int entryIndexForOffset(long constantOffset, Kind expectedEntryKind);
090
091    /**
092     * Returns the {@link Kind} of the entry at the given index.
093     */
094    public abstract Kind entryKind(int index);
095
096    /**
097     * Returns an exact duplicate of this virtual object node, which has not been added to the graph
098     * yet.
099     */
100    public abstract VirtualObjectNode duplicate();
101
102    /**
103     * Specifies whether this virtual object has an object identity. If not, then the result of a
104     * comparison of two virtual objects is determined by comparing their contents.
105     */
106    public boolean hasIdentity() {
107        return hasIdentity;
108    }
109
110    public void setIdentity(boolean identity) {
111        this.hasIdentity = identity;
112    }
113
114    /**
115     * Returns a node that can be used to materialize this virtual object. If this returns an
116     * {@link AllocatedObjectNode} then this node will be attached to a {@link CommitAllocationNode}
117     * , otherwise the node will just be added to the graph.
118     */
119    public abstract ValueNode getMaterializedRepresentation(FixedNode fixed, ValueNode[] entries, LockState locks);
120
121    @Override
122    public void generate(NodeLIRBuilderTool gen) {
123        // nothing to do...
124    }
125}