< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.nodes/src/org/graalvm/compiler/nodes/virtual/VirtualInstanceNode.java

Print this page




  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.nodes.virtual;
  24 
  25 import org.graalvm.compiler.graph.NodeClass;
  26 import org.graalvm.compiler.nodeinfo.NodeInfo;
  27 import org.graalvm.compiler.nodeinfo.Verbosity;
  28 import org.graalvm.compiler.nodes.FixedNode;
  29 import org.graalvm.compiler.nodes.ValueNode;
  30 
  31 import jdk.vm.ci.meta.JavaKind;
  32 import jdk.vm.ci.meta.ResolvedJavaField;
  33 import jdk.vm.ci.meta.ResolvedJavaType;
  34 
  35 @NodeInfo(nameTemplate = "VirtualInstance {p#type/s}")
  36 public class VirtualInstanceNode extends VirtualObjectNode {
  37 
  38     public static final NodeClass<VirtualInstanceNode> TYPE = NodeClass.create(VirtualInstanceNode.class);
  39     protected final ResolvedJavaType type;
  40     protected final ResolvedJavaField[] fields;
  41 
  42     public VirtualInstanceNode(ResolvedJavaType type, boolean hasIdentity) {
  43         this(type, type.getInstanceFields(true), hasIdentity);
  44     }
  45 
  46     public VirtualInstanceNode(ResolvedJavaType type, ResolvedJavaField[] fields, boolean hasIdentity) {
  47         this(TYPE, type, fields, hasIdentity);
  48     }
  49 
  50     protected VirtualInstanceNode(NodeClass<? extends VirtualInstanceNode> c, ResolvedJavaType type, boolean hasIdentity) {
  51         this(c, type, type.getInstanceFields(true), hasIdentity);
  52     }
  53 
  54     protected VirtualInstanceNode(NodeClass<? extends VirtualInstanceNode> c, ResolvedJavaType type, ResolvedJavaField[] fields, boolean hasIdentity) {
  55         super(c, type, hasIdentity);


  61     public ResolvedJavaType type() {
  62         return type;
  63     }
  64 
  65     @Override
  66     public int entryCount() {
  67         return fields.length;
  68     }
  69 
  70     public ResolvedJavaField field(int index) {
  71         return fields[index];
  72     }
  73 
  74     public ResolvedJavaField[] getFields() {
  75         return fields;
  76     }
  77 
  78     @Override
  79     public String toString(Verbosity verbosity) {
  80         if (verbosity == Verbosity.Name) {
  81             return super.toString(Verbosity.Name) + " " + type.toJavaName(false);
  82         } else {
  83             return super.toString(verbosity);
  84         }
  85     }
  86 
  87     @Override
  88     public String entryName(int index) {
  89         return fields[index].getName();
  90     }
  91 
  92     public int fieldIndex(ResolvedJavaField field) {
  93         // on average fields.length == ~6, so a linear search is fast enough
  94         for (int i = 0; i < fields.length; i++) {
  95             if (fields[i].equals(field)) {
  96                 return i;
  97             }
  98         }
  99         return -1;
 100     }
 101 




  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.nodes.virtual;
  24 
  25 import org.graalvm.compiler.graph.NodeClass;
  26 import org.graalvm.compiler.nodeinfo.NodeInfo;
  27 import org.graalvm.compiler.nodeinfo.Verbosity;
  28 import org.graalvm.compiler.nodes.FixedNode;
  29 import org.graalvm.compiler.nodes.ValueNode;
  30 
  31 import jdk.vm.ci.meta.JavaKind;
  32 import jdk.vm.ci.meta.ResolvedJavaField;
  33 import jdk.vm.ci.meta.ResolvedJavaType;
  34 
  35 @NodeInfo(nameTemplate = "VirtualInstance({p#objectId}) {p#type/s}")
  36 public class VirtualInstanceNode extends VirtualObjectNode {
  37 
  38     public static final NodeClass<VirtualInstanceNode> TYPE = NodeClass.create(VirtualInstanceNode.class);
  39     protected final ResolvedJavaType type;
  40     protected final ResolvedJavaField[] fields;
  41 
  42     public VirtualInstanceNode(ResolvedJavaType type, boolean hasIdentity) {
  43         this(type, type.getInstanceFields(true), hasIdentity);
  44     }
  45 
  46     public VirtualInstanceNode(ResolvedJavaType type, ResolvedJavaField[] fields, boolean hasIdentity) {
  47         this(TYPE, type, fields, hasIdentity);
  48     }
  49 
  50     protected VirtualInstanceNode(NodeClass<? extends VirtualInstanceNode> c, ResolvedJavaType type, boolean hasIdentity) {
  51         this(c, type, type.getInstanceFields(true), hasIdentity);
  52     }
  53 
  54     protected VirtualInstanceNode(NodeClass<? extends VirtualInstanceNode> c, ResolvedJavaType type, ResolvedJavaField[] fields, boolean hasIdentity) {
  55         super(c, type, hasIdentity);


  61     public ResolvedJavaType type() {
  62         return type;
  63     }
  64 
  65     @Override
  66     public int entryCount() {
  67         return fields.length;
  68     }
  69 
  70     public ResolvedJavaField field(int index) {
  71         return fields[index];
  72     }
  73 
  74     public ResolvedJavaField[] getFields() {
  75         return fields;
  76     }
  77 
  78     @Override
  79     public String toString(Verbosity verbosity) {
  80         if (verbosity == Verbosity.Name) {
  81             return super.toString(Verbosity.Name) + "(" + getObjectId() + ") " + type.toJavaName(false);
  82         } else {
  83             return super.toString(verbosity);
  84         }
  85     }
  86 
  87     @Override
  88     public String entryName(int index) {
  89         return fields[index].getName();
  90     }
  91 
  92     public int fieldIndex(ResolvedJavaField field) {
  93         // on average fields.length == ~6, so a linear search is fast enough
  94         for (int i = 0; i < fields.length; i++) {
  95             if (fields[i].equals(field)) {
  96                 return i;
  97             }
  98         }
  99         return -1;
 100     }
 101 


< prev index next >