annotate graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/VirtualObject.java @ 14160:fd7fcd2d2072

replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
author Doug Simon <doug.simon@oracle.com>
date Wed, 12 Mar 2014 21:47:35 +0100
parents 8c4a3d9308a7
children c0b8d395368b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
1 /*
4182
de7b3e7ae528 Simplify CiValue
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4169
diff changeset
2 * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
4 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
8 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
13 * accompanied this code).
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
14 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
18 *
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
21 * questions.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
22 */
5510
426c605c9d3c Move cri.ci to api.code.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5507
diff changeset
23 package com.oracle.graal.api.code;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
8289
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
25 import static com.oracle.graal.api.meta.MetaUtil.*;
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
26
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
27 import java.util.*;
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
28
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5506
diff changeset
29 import com.oracle.graal.api.meta.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31 /**
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
32 * An instance of this class represents an object whose allocation was removed by escape analysis.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
33 * The information stored in the {@link VirtualObject} is used during deoptimization to recreate the
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
34 * object.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35 */
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
36 public final class VirtualObject extends Value {
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
37
4169
f5328dda9714 Initial commit of SSA-based spill-all register assignment
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4142
diff changeset
38 private static final long serialVersionUID = -2907197776426346021L;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
39
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
40 private final ResolvedJavaType type;
5539
bc647d8b0080 Renaming RiValue => Value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
41 private Value[] values;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
42 private final int id;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
44 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
45 * Creates a new {@link VirtualObject} for the given type, with the given fields. If
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
46 * {@code type} is an instance class then {@code values} provides the values for the fields
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
47 * returned by {@link ResolvedJavaType#getInstanceFields(boolean) getInstanceFields(true)}. If
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
48 * {@code type} is an array then the length of the values array determines the reallocated array
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
49 * length.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
50 *
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
51 * @param type the type of the object whose allocation was removed during compilation. This can
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
52 * be either an instance of an array type.
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
53 * @param values an array containing all the values to be stored into the object when it is
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
54 * recreated
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
55 * @param id a unique id that identifies the object within the debug information for one
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
56 * position in the compiled code.
5774
a1db0ea58b53 Removed left over Ci* prefixed identifiers
Doug Simon <doug.simon@oracle.com>
parents: 5550
diff changeset
57 * @return a new {@link VirtualObject} instance.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
58 */
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
59 public static VirtualObject get(ResolvedJavaType type, Value[] values, int id) {
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
60 return new VirtualObject(type, values, id);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
61 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
62
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
63 private VirtualObject(ResolvedJavaType type, Value[] values, int id) {
5540
a891c53a295b Renaming RiKind => Kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5539
diff changeset
64 super(Kind.Object);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
65 this.type = type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
66 this.values = values;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
67 this.id = id;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
68 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
69
8289
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
70 private static StringBuilder appendValue(StringBuilder buf, Value value, Set<VirtualObject> visited) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
71 if (value instanceof VirtualObject) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
72 VirtualObject vo = (VirtualObject) value;
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
73 buf.append("vobject:").append(toJavaName(vo.type, false)).append(':').append(vo.id);
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
74 if (!visited.contains(vo)) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
75 visited.add(vo);
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
76 buf.append('{');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
77 if (vo.values == null) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
78 buf.append("<uninitialized>");
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
79 } else {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
80 if (vo.type.isArray()) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
81 for (int i = 0; i < vo.values.length; i++) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
82 if (i != 0) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
83 buf.append(',');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
84 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
85 buf.append(i).append('=');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
86 appendValue(buf, vo.values[i], visited);
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
87 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
88 } else {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
89 ResolvedJavaField[] fields = vo.type.getInstanceFields(true);
14157
8c4a3d9308a7 fixed FindBugs bugs
twisti
parents: 12617
diff changeset
90 assert fields.length == vo.values.length : vo.type + ", fields=" + Arrays.toString(fields) + ", values=" + Arrays.toString(vo.values);
8289
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
91 for (int i = 0; i < vo.values.length; i++) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
92 if (i != 0) {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
93 buf.append(',');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
94 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
95 buf.append(fields[i].getName()).append('=');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
96 appendValue(buf, vo.values[i], visited);
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
97 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
98 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
99 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
100 buf.append('}');
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
101 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
102 } else {
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
103 buf.append(value);
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
104 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
105 return buf;
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
106 }
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
107
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
108 @Override
4169
f5328dda9714 Initial commit of SSA-based spill-all register assignment
Christian Wimmer <Christian.Wimmer@Oracle.com>
parents: 4142
diff changeset
109 public String toString() {
8289
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
110 Set<VirtualObject> visited = Collections.newSetFromMap(new IdentityHashMap<VirtualObject, Boolean>());
59bd299750a8 fixed StackOverflowError in VirtualObject.toString()
Doug Simon <doug.simon@oracle.com>
parents: 7530
diff changeset
111 return appendValue(new StringBuilder(), this, visited).toString();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
113
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
115 * Returns the type of the object whose allocation was removed during compilation. This can be
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
116 * either an instance of an array type.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 */
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
118 public ResolvedJavaType getType() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
119 return type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
120 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
121
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
122 /**
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6329
diff changeset
123 * Returns an array containing all the values to be stored into the object when it is recreated.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
124 */
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6329
diff changeset
125 public Value[] getValues() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 return values;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
127 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
128
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
129 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
130 * Returns the unique id that identifies the object within the debug information for one
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
131 * position in the compiled code.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132 */
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6329
diff changeset
133 public int getId() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 return id;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
135 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
137 private static boolean checkValues(ResolvedJavaType type, Value[] values) {
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
138 if (values != null) {
7060
06d5f450f32b rename: ResolvedJavaType.isArrayClass() -> ResolvedJavaType.isArray()
Doug Simon <doug.simon@oracle.com>
parents: 6959
diff changeset
139 if (!type.isArray()) {
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
140 ResolvedJavaField[] fields = type.getInstanceFields(true);
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
141 int fieldIndex = 0;
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
142 for (int i = 0; i < values.length; i++) {
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
143 ResolvedJavaField field = fields[fieldIndex++];
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
144 Kind valKind = values[i].getKind().getStackKind();
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
145 if ((valKind == Kind.Double || valKind == Kind.Long) && field.getKind() == Kind.Int) {
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
146 assert fields[fieldIndex].getKind() == Kind.Int;
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
147 fieldIndex++;
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
148 } else {
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
149 assert valKind == field.getKind().getStackKind() : field + ": " + valKind + " != " + field.getKind().getStackKind();
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
150 }
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
151 }
12617
bca33c3135de PEA: support for unsafe stores of mismatching sizes, cleanup, documentation
Lukas Stadler <lukas.stadler@jku.at>
parents: 9785
diff changeset
152 assert fields.length == fieldIndex : type + ": fields=" + Arrays.toString(fields) + ", field values=" + Arrays.toString(values);
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
153 } else {
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
154 Kind componentKind = type.getComponentType().getKind().getStackKind();
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
155 for (int i = 0; i < values.length; i++) {
9785
ecd5cd2806e8 Relax assertion for virtual array component kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9422
diff changeset
156 assert values[i].getKind().getStackKind() == componentKind || componentKind.getBitCount() >= values[i].getKind().getStackKind().getBitCount() : values[i].getKind() + " != " +
ecd5cd2806e8 Relax assertion for virtual array component kind.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 9422
diff changeset
157 componentKind;
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
158 }
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
159 }
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
160
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
161 }
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
162 return true;
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
163 }
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
164
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 * Overwrites the current set of values with a new one.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
167 *
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
168 * @param values an array containing all the values to be stored into the object when it is
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7060
diff changeset
169 * recreated.
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
170 */
5539
bc647d8b0080 Renaming RiValue => Value.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5538
diff changeset
171 public void setValues(Value[] values) {
6959
9c71ad0a0652 extra assertion checking when initializing the values of a VirtualObject
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
172 assert checkValues(type, values);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
173 this.values = values;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 public int hashCode() {
9422
149fe42411df Use platform specific kind in backend.
Roland Schatz <roland.schatz@oracle.com>
parents: 8289
diff changeset
178 return getPlatformKind().hashCode() + type.hashCode();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
179 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
180
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
181 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
182 public boolean equals(Object o) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
183 if (o == this) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
184 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
185 }
5547
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
186 if (o instanceof VirtualObject) {
b6617d13ea44 Dropping Ci* prefixes. Some additional renamings in the api.code interface.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5541
diff changeset
187 VirtualObject l = (VirtualObject) o;
14160
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14157
diff changeset
188 if (!l.type.equals(type) || l.values.length != values.length) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
189 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
190 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
191 for (int i = 0; i < values.length; i++) {
14160
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14157
diff changeset
192 if (!Objects.equals(values[i], l.values[i])) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
193 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
194 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
195 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
196 return true;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
197 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
198 return false;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
199 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
200 }