annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaFieldImpl.java @ 19005:a64863622854

Shorter comparison of HotSpotResolvedFieldImpl instances.
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Wed, 28 Jan 2015 12:03:00 +0100
parents 7f4cb7587f4c
children 0d7302ddcc90
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 /*
15023
652564fe42d5 Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
2 * Copyright (c) 2011, 2014, 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 */
5548
8872bc0eebdf Renaming hotspot.ri => hotspot.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5547
diff changeset
23 package com.oracle.graal.hotspot.meta;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
24
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
25 import static com.oracle.graal.compiler.common.GraalOptions.*;
9289
261a43921c5e rename: HotSpotGraalRuntime.getInstance() -> graalRuntime()
Doug Simon <doug.simon@oracle.com>
parents: 8960
diff changeset
26 import static com.oracle.graal.hotspot.HotSpotGraalRuntime.*;
18223
17c98fad6980 converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
27 import static com.oracle.graal.hotspot.meta.HotSpotResolvedObjectTypeImpl.*;
8949
da5140eedfa1 made format of toString() consistent across HotSpot subclasses of JavaField and JavaMethod
Doug Simon <doug.simon@oracle.com>
parents: 8415
diff changeset
28
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
29 import java.lang.annotation.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
30 import java.lang.reflect.*;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
31
5507
dc71b06d09f8 Moving classes from cri.ri to api.meta.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5503
diff changeset
32 import com.oracle.graal.api.meta.*;
18508
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
33 import com.oracle.graal.compiler.common.*;
5060
4ed4295ce15f Update import statements.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5059
diff changeset
34 import com.oracle.graal.hotspot.*;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
35
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
36 /**
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
37 * Represents a field in a HotSpot type.
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
38 */
18867
7f4cb7587f4c localized replay compilation marker interface to HotSpot specific code
Doug Simon <doug.simon@oracle.com>
parents: 18583
diff changeset
39 public class HotSpotResolvedJavaFieldImpl extends CompilerObject implements HotSpotResolvedJavaField, HotSpotProxified {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
40
4142
bc8527f3071c Adjust code base to new level of warnings.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 3733
diff changeset
41 private static final long serialVersionUID = 7692985878836955683L;
18223
17c98fad6980 converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
42 private final HotSpotResolvedObjectTypeImpl holder;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
43 private final String name;
14047
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
44 private JavaType type;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
45 private final int offset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
46
13823
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
47 /**
14012
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
48 * This value contains all flags as stored in the VM including internal ones.
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
49 */
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
50 private final int modifiers;
13823
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
51
18264
e28aa8468d5e converted HotSpotResolvedJavaField to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18262
diff changeset
52 public HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, String name, JavaType type, long offset, int modifiers) {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
53 this.holder = holder;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
54 this.name = name;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
55 this.type = type;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
56 assert offset != -1;
13263
81055aacb98d removed CompilerToVM.getJavaField
twisti
parents: 12628
diff changeset
57 assert offset == (int) offset : "offset larger than int";
81055aacb98d removed CompilerToVM.getJavaField
twisti
parents: 12628
diff changeset
58 this.offset = (int) offset;
14012
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
59 this.modifiers = modifiers;
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
60 }
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 @Override
14158
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
63 public boolean equals(Object obj) {
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
64 if (this == obj) {
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
65 return true;
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
66 }
14525
5e55de0379d9 fixed bug in HotSpotResolvedJavaField.equals
Doug Simon <doug.simon@oracle.com>
parents: 14158
diff changeset
67 if (obj instanceof HotSpotResolvedJavaField) {
18264
e28aa8468d5e converted HotSpotResolvedJavaField to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18262
diff changeset
68 HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj;
19005
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
69 if (that.offset != this.offset) {
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
70 return false;
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
71 } else if (this.holder.equals(that.holder)) {
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
72 assert this.name.equals(that.name) && this.type.equals(that.type);
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
73 return true;
a64863622854 Shorter comparison of HotSpotResolvedFieldImpl instances.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 18867
diff changeset
74 }
14158
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
75 }
14525
5e55de0379d9 fixed bug in HotSpotResolvedJavaField.equals
Doug Simon <doug.simon@oracle.com>
parents: 14158
diff changeset
76 return false;
14158
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
77 }
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
78
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
79 @Override
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
80 public int hashCode() {
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
81 return name.hashCode();
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
82 }
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
83
fd7fcd2d2072 replaced == with .equals() for comparisons between JavaMethod/JavaField/JavaType values
Doug Simon <doug.simon@oracle.com>
parents: 14138
diff changeset
84 @Override
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: 6525
diff changeset
85 public int getModifiers() {
14012
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
86 return modifiers & getReflectionFieldModifiers();
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
87 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
88
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
89 @Override
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
90 public boolean isInternal() {
14012
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
91 return (modifiers & runtime().getConfig().jvmAccFieldInternal) != 0;
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
92 }
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6539
diff changeset
93
10065
5ba3763d6986 HotSpotResolvedJavaField: check if method is called from snippet/replacements (GRAAL-290)
Bernhard Urban <bernhard.urban@jku.at>
parents: 10063
diff changeset
94 /**
12628
c36bdee8ca29 added type check for object before reading a field value from it during compilation
Doug Simon <doug.simon@oracle.com>
parents: 12559
diff changeset
95 * Determines if a given object contains this field.
15023
652564fe42d5 Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
96 *
13823
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
97 * @return true iff this is a non-static field and its declaring class is assignable from
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
98 * {@code object}'s class
12628
c36bdee8ca29 added type check for object before reading a field value from it during compilation
Doug Simon <doug.simon@oracle.com>
parents: 12559
diff changeset
99 */
c36bdee8ca29 added type check for object before reading a field value from it during compilation
Doug Simon <doug.simon@oracle.com>
parents: 12559
diff changeset
100 public boolean isInObject(Object object) {
15311
820c6d353358 added ModifiersProvider as superinterface for ResolvedJava[Method|Field|Type] and implemented all checks against modifiers as default methods
Doug Simon <doug.simon@oracle.com>
parents: 15259
diff changeset
101 if (isStatic()) {
13823
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
102 return false;
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
103 }
18223
17c98fad6980 converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
104 return getDeclaringClass().isAssignableFrom(HotSpotResolvedObjectTypeImpl.fromObjectClass(object.getClass()));
12628
c36bdee8ca29 added type check for object before reading a field value from it during compilation
Doug Simon <doug.simon@oracle.com>
parents: 12559
diff changeset
105 }
c36bdee8ca29 added type check for object before reading a field value from it during compilation
Doug Simon <doug.simon@oracle.com>
parents: 12559
diff changeset
106
5629
26a060cc58ca Initial implementation of closed world analysis by iteratively expanding the universe starting at method entry points.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents: 5554
diff changeset
107 @Override
18223
17c98fad6980 converted HotSpotResolvedObjectType to an interface
Doug Simon <doug.simon@oracle.com>
parents: 18187
diff changeset
108 public HotSpotResolvedObjectTypeImpl getDeclaringClass() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
109 return holder;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
110 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
111
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
112 @Override
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: 6525
diff changeset
113 public String getName() {
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
114 return name;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
115 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
116
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
117 @Override
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: 6525
diff changeset
118 public JavaType getType() {
14047
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
119 if (!(type instanceof ResolvedJavaType)) {
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
120 // Don't allow unresolved types to hang around forever
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
121 ResolvedJavaType resolved = type.resolve(holder);
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
122 if (resolved != null) {
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
123 type = resolved;
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
124 }
fde464340755 don't allow unresolved field types to hang around
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 14012
diff changeset
125 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
126 return type;
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 public int offset() {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
130 return offset;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
131 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
132
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
133 @Override
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
134 public String toString() {
16481
e7fc65330742 moved format(String format, JavaField field) from MetaUtil to be a default method in JavaField
Doug Simon <doug.simon@oracle.com>
parents: 16383
diff changeset
135 return format("HotSpotField<%H.%n %t:") + offset + ">";
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
136 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
137
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
138 @Override
9984
f3330a4487eb added ResolvedJava[Field|Method].isSynthetic()
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
139 public boolean isSynthetic() {
14012
1f34717ccafa remove CompilerToVM.getInstanceFields
twisti
parents: 13823
diff changeset
140 return (runtime().getConfig().syntheticFlag & modifiers) != 0;
9984
f3330a4487eb added ResolvedJava[Field|Method].isSynthetic()
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
141 }
f3330a4487eb added ResolvedJava[Field|Method].isSynthetic()
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
142
12559
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
143 /**
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
144 * Checks if this field has the {@link Stable} annotation.
15023
652564fe42d5 Use CompressionNode for accessing compressed Klass pointers.
Roland Schatz <roland.schatz@oracle.com>
parents: 15018
diff changeset
145 *
12559
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
146 * @return true if field has {@link Stable} annotation, false otherwise
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
147 */
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
148 public boolean isStable() {
17334
0563b652c052 Unify parsing of graal and hotspot Stable annotations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16481
diff changeset
149 if ((runtime().getConfig().jvmAccFieldStable & modifiers) != 0) {
0563b652c052 Unify parsing of graal and hotspot Stable annotations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16481
diff changeset
150 return true;
0563b652c052 Unify parsing of graal and hotspot Stable annotations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16481
diff changeset
151 }
0563b652c052 Unify parsing of graal and hotspot Stable annotations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16481
diff changeset
152 assert getAnnotation(Stable.class) == null;
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
153 if (ImplicitStableValues.getValue() && isImplicitStableField()) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
154 return true;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
155 }
17334
0563b652c052 Unify parsing of graal and hotspot Stable annotations
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 16481
diff changeset
156 return false;
12559
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
157 }
ae412befde21 read HotSpotVMConfig fields from HotSpot's vmStructs via annotations
twisti
parents: 12456
diff changeset
158
9984
f3330a4487eb added ResolvedJava[Field|Method].isSynthetic()
Doug Simon <doug.simon@oracle.com>
parents: 9914
diff changeset
159 @Override
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
160 public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
161 Field javaField = toJava();
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
162 if (javaField != null) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
163 return javaField.getAnnotation(annotationClass);
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
164 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
165 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
166 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
167
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
168 private Field toJava() {
13823
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
169 if (isInternal()) {
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
170 return null;
6dd8b95a7fbb fixed HotSpotResolvedJavaField.getModifiers() to mask out FIELD_INTERNAL_FLAG
Doug Simon <doug.simon@oracle.com>
parents: 13818
diff changeset
171 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
172 try {
7053
014727292ae0 removed more usages of ResolvedJavaType.toJava()
Doug Simon <doug.simon@oracle.com>
parents: 6950
diff changeset
173 return holder.mirror().getDeclaredField(name);
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
174 } catch (NoSuchFieldException e) {
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
175 return null;
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
176 }
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
177 }
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
178
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
179 private boolean isArray() {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
180 JavaType fieldType = getType();
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
181 return fieldType instanceof ResolvedJavaType && ((ResolvedJavaType) fieldType).isArray();
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
182 }
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
183
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
184 private boolean isImplicitStableField() {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
185 if (isSynthetic()) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
186 if (isSyntheticImplicitStableField()) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
187 return true;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
188 }
18508
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
189 } else if (isWellKnownImplicitStableField()) {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
190 return true;
18507
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
191 }
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
192 return false;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
193 }
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
194
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
195 private boolean isSyntheticImplicitStableField() {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
196 assert this.isSynthetic();
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
197 if (isStatic() && isArray()) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
198 if (isFinal() && name.equals("$VALUES") || name.equals("ENUM$VALUES")) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
199 // generated int[] field for EnumClass::values()
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
200 return true;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
201 } else if (name.startsWith("$SwitchMap$") || name.startsWith("$SWITCH_TABLE$")) {
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
202 // javac and ecj generate a static field in an inner class for a switch on an enum
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
203 // named $SwitchMap$p$k$g$EnumClass and $SWITCH_TABLE$p$k$g$EnumClass, respectively
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
204 return true;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
205 }
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
206 }
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
207 return false;
c2b45b536677 Constant fold elements of switch table and enum values() arrays
Andreas Woess <andreas.woess@jku.at>
parents: 18465
diff changeset
208 }
18508
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
209
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
210 private boolean isWellKnownImplicitStableField() {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
211 return WellKnownImplicitStableField.test(this);
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
212 }
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
213
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
214 static class WellKnownImplicitStableField {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
215 /**
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
216 * @return {@code true} if the field is a well-known stable field.
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
217 */
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
218 public static boolean test(HotSpotResolvedJavaField field) {
18583
12bd2b344b08 replace usages of == with .equals()
Doug Simon <doug.simon@oracle.com>
parents: 18530
diff changeset
219 return field.equals(STRING_VALUE_FIELD);
18508
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
220 }
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
221
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
222 private static final ResolvedJavaField STRING_VALUE_FIELD;
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
223 static {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
224 try {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
225 MetaAccessProvider metaAccess = runtime().getHostProviders().getMetaAccess();
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
226 STRING_VALUE_FIELD = metaAccess.lookupJavaField(String.class.getDeclaredField("value"));
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
227 } catch (SecurityException | NoSuchFieldException e) {
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
228 throw new GraalInternalError(e);
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
229 }
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
230 }
f56a5c4cd859 Treat String.value as implicit stable field
Andreas Woess <andreas.woess@jku.at>
parents: 18507
diff changeset
231 }
3733
e233f5660da4 Added Java files from Maxine project.
Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
parents:
diff changeset
232 }