author | kvn |
Wed, 01 May 2019 12:31:29 -0700 | |
changeset 54669 | ad45b3802d4e |
parent 52645 | 74cf02d5f6e2 |
permissions | -rw-r--r-- |
43972 | 1 |
/* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
2 |
* Copyright (c) 2011, 2019, Oracle and/or its affiliates. All rights reserved. |
43972 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
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 jdk.vm.ci.hotspot; |
|
24 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
25 |
import static jdk.vm.ci.hotspot.HotSpotJVMCIRuntime.runtime; |
43972 | 26 |
import static jdk.vm.ci.hotspot.HotSpotVMConfig.config; |
52645
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
27 |
import static jdk.vm.ci.hotspot.UnsafeAccess.UNSAFE; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
28 |
import static jdk.internal.misc.Unsafe.ADDRESS_SIZE; |
43972 | 29 |
|
30 |
import java.lang.annotation.Annotation; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
31 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
32 |
import jdk.internal.vm.annotation.Stable; |
43972 | 33 |
|
50858 | 34 |
import jdk.vm.ci.meta.JavaConstant; |
43972 | 35 |
import jdk.vm.ci.meta.JavaType; |
36 |
import jdk.vm.ci.meta.ResolvedJavaType; |
|
50858 | 37 |
import jdk.vm.ci.meta.UnresolvedJavaType; |
43972 | 38 |
|
39 |
/** |
|
40 |
* Represents a field in a HotSpot type. |
|
41 |
*/ |
|
42 |
class HotSpotResolvedJavaFieldImpl implements HotSpotResolvedJavaField { |
|
43 |
||
44 |
private final HotSpotResolvedObjectTypeImpl holder; |
|
45 |
private JavaType type; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
46 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
47 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
48 |
* Value of {@code fieldDescriptor::access_flags()}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
49 |
*/ |
43972 | 50 |
private final int offset; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
51 |
|
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
52 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
53 |
* Value of {@code fieldDescriptor::index()}. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
54 |
*/ |
43972 | 55 |
private final short index; |
56 |
||
57 |
/** |
|
58 |
* This value contains all flags as stored in the VM including internal ones. |
|
59 |
*/ |
|
60 |
private final int modifiers; |
|
61 |
||
62 |
HotSpotResolvedJavaFieldImpl(HotSpotResolvedObjectTypeImpl holder, JavaType type, long offset, int modifiers, int index) { |
|
63 |
this.holder = holder; |
|
64 |
this.type = type; |
|
65 |
this.index = (short) index; |
|
66 |
assert this.index == index; |
|
67 |
assert offset != -1; |
|
68 |
assert offset == (int) offset : "offset larger than int"; |
|
69 |
this.offset = (int) offset; |
|
70 |
this.modifiers = modifiers; |
|
71 |
} |
|
72 |
||
73 |
@Override |
|
74 |
public boolean equals(Object obj) { |
|
75 |
if (this == obj) { |
|
76 |
return true; |
|
77 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
78 |
if (obj instanceof HotSpotResolvedJavaFieldImpl) { |
43972 | 79 |
HotSpotResolvedJavaFieldImpl that = (HotSpotResolvedJavaFieldImpl) obj; |
80 |
if (that.offset != this.offset || that.isStatic() != this.isStatic()) { |
|
81 |
return false; |
|
82 |
} else if (this.holder.equals(that.holder)) { |
|
83 |
return true; |
|
84 |
} |
|
85 |
} |
|
86 |
return false; |
|
87 |
} |
|
88 |
||
89 |
@Override |
|
90 |
public int hashCode() { |
|
47893
ef2e9b041e32
8178048: [JVMCI] improve HotSpotResolvedJavaFieldImpl.hashCode()
chaeubl
parents:
47216
diff
changeset
|
91 |
return holder.hashCode() ^ offset; |
43972 | 92 |
} |
93 |
||
94 |
@Override |
|
95 |
public int getModifiers() { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
96 |
return modifiers & HotSpotModifiers.jvmFieldModifiers(); |
43972 | 97 |
} |
98 |
||
99 |
@Override |
|
100 |
public boolean isInternal() { |
|
101 |
return (modifiers & config().jvmAccFieldInternal) != 0; |
|
102 |
} |
|
103 |
||
104 |
/** |
|
105 |
* Determines if a given object contains this field. |
|
106 |
* |
|
107 |
* @return true iff this is a non-static field and its declaring class is assignable from |
|
108 |
* {@code object}'s class |
|
109 |
*/ |
|
50858 | 110 |
@Override |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
111 |
public boolean isInObject(JavaConstant object) { |
43972 | 112 |
if (isStatic()) { |
113 |
return false; |
|
114 |
} |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
115 |
HotSpotObjectConstant constant = (HotSpotObjectConstant) object; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
116 |
return getDeclaringClass().isAssignableFrom(constant.getType()); |
43972 | 117 |
} |
118 |
||
119 |
@Override |
|
120 |
public HotSpotResolvedObjectTypeImpl getDeclaringClass() { |
|
121 |
return holder; |
|
122 |
} |
|
123 |
||
124 |
@Override |
|
125 |
public String getName() { |
|
126 |
return holder.createFieldInfo(index).getName(); |
|
127 |
} |
|
128 |
||
129 |
@Override |
|
130 |
public JavaType getType() { |
|
131 |
// Pull field into local variable to prevent a race causing |
|
132 |
// a ClassCastException below |
|
133 |
JavaType currentType = type; |
|
50858 | 134 |
if (currentType instanceof UnresolvedJavaType) { |
43972 | 135 |
// Don't allow unresolved types to hang around forever |
50858 | 136 |
UnresolvedJavaType unresolvedType = (UnresolvedJavaType) currentType; |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
137 |
JavaType resolved = HotSpotJVMCIRuntime.runtime().lookupType(unresolvedType.getName(), holder, false); |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
138 |
if (resolved instanceof ResolvedJavaType) { |
43972 | 139 |
type = resolved; |
140 |
} |
|
141 |
} |
|
142 |
return type; |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
143 |
|
43972 | 144 |
} |
145 |
||
50858 | 146 |
@Override |
147 |
public int getOffset() { |
|
43972 | 148 |
return offset; |
149 |
} |
|
150 |
||
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
151 |
/** |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
152 |
* Gets the value of this field's index (i.e. {@code fieldDescriptor::index()} in the encoded |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
153 |
* fields of the declaring class. |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
154 |
*/ |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
155 |
int getIndex() { |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
156 |
return index; |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
157 |
} |
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
158 |
|
43972 | 159 |
@Override |
160 |
public String toString() { |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
161 |
return format("HotSpotResolvedJavaFieldImpl<%H.%n %t:") + offset + ">"; |
43972 | 162 |
} |
163 |
||
164 |
@Override |
|
165 |
public boolean isSynthetic() { |
|
166 |
return (config().jvmAccSynthetic & modifiers) != 0; |
|
167 |
} |
|
168 |
||
169 |
/** |
|
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
170 |
* Checks if this field has the {@link Stable} annotation. |
43972 | 171 |
* |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
172 |
* @return true if field has {@link Stable} annotation, false otherwise |
43972 | 173 |
*/ |
50858 | 174 |
@Override |
43972 | 175 |
public boolean isStable() { |
176 |
return (config().jvmAccFieldStable & modifiers) != 0; |
|
177 |
} |
|
178 |
||
52645
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
179 |
private boolean hasAnnotations() { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
180 |
if (!isInternal()) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
181 |
HotSpotVMConfig config = config(); |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
182 |
final long metaspaceAnnotations = UNSAFE.getAddress(holder.getMetaspaceKlass() + config.instanceKlassAnnotationsOffset); |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
183 |
if (metaspaceAnnotations != 0) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
184 |
long fieldsAnnotations = UNSAFE.getAddress(metaspaceAnnotations + config.annotationsFieldAnnotationsOffset); |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
185 |
if (fieldsAnnotations != 0) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
186 |
long fieldAnnotations = UNSAFE.getAddress(fieldsAnnotations + config.fieldsAnnotationsBaseOffset + (ADDRESS_SIZE * index)); |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
187 |
return fieldAnnotations != 0; |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
188 |
} |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
189 |
} |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
190 |
} |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
191 |
return false; |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
192 |
} |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
193 |
|
43972 | 194 |
@Override |
195 |
public Annotation[] getAnnotations() { |
|
52645
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
196 |
if (!hasAnnotations()) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
197 |
return new Annotation[0]; |
43972 | 198 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
199 |
return runtime().reflection.getFieldAnnotations(this); |
43972 | 200 |
} |
201 |
||
202 |
@Override |
|
203 |
public Annotation[] getDeclaredAnnotations() { |
|
52645
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
204 |
if (!hasAnnotations()) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
205 |
return new Annotation[0]; |
43972 | 206 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
207 |
return runtime().reflection.getFieldDeclaredAnnotations(this); |
43972 | 208 |
} |
209 |
||
210 |
@Override |
|
211 |
public <T extends Annotation> T getAnnotation(Class<T> annotationClass) { |
|
52645
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
212 |
if (!hasAnnotations()) { |
74cf02d5f6e2
8213907: [JVMCI] avoid Class.getDeclared* methods when converting JVMCI objects to reflection objects
dnsimon
parents:
52433
diff
changeset
|
213 |
return null; |
43972 | 214 |
} |
54669
ad45b3802d4e
8220623: [JVMCI] Update JVMCI to support JVMCI based Compiler compiled into shared library
kvn
parents:
52645
diff
changeset
|
215 |
return runtime().reflection.getFieldAnnotation(this, annotationClass); |
43972 | 216 |
} |
217 |
} |