Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/jcl/src/java.base/share/classes/java/lang/invoke/FieldHandle.java
12521 views
1
/*[INCLUDE-IF Sidecar17 & !OPENJDK_METHODHANDLES]*/
2
/*******************************************************************************
3
* Copyright (c) 2009, 2020 IBM Corp. and others
4
*
5
* This program and the accompanying materials are made available under
6
* the terms of the Eclipse Public License 2.0 which accompanies this
7
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
8
* or the Apache License, Version 2.0 which accompanies this distribution and
9
* is available at https://www.apache.org/licenses/LICENSE-2.0.
10
*
11
* This Source Code may also be made available under the following
12
* Secondary Licenses when the conditions for such availability set
13
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
14
* General Public License, version 2 with the GNU Classpath
15
* Exception [1] and GNU General Public License, version 2 with the
16
* OpenJDK Assembly Exception [2].
17
*
18
* [1] https://www.gnu.org/software/classpath/license.html
19
* [2] http://openjdk.java.net/legal/assembly-exception.html
20
*
21
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
22
*******************************************************************************/
23
package java.lang.invoke;
24
25
import java.lang.reflect.Field;
26
import java.lang.reflect.Modifier;
27
28
/*[IF ]*/
29
/*
30
* Note, Static Field getter/setter handles do not ensure that the class has been initialized
31
* prior to returning the handle. This matches the RI's behaviour.
32
*/
33
/*[ENDIF]*/
34
abstract class FieldHandle extends PrimitiveHandle {
35
final Class<?> fieldClass;
36
final boolean isVolatile;
37
38
FieldHandle(MethodType type, Class<?> referenceClass, String fieldName, Class<?> fieldClass, byte kind, Class<?> accessClass) throws IllegalAccessException, NoSuchFieldException {
39
super(type, referenceClass, fieldName, kind, null);
40
this.fieldClass = fieldClass;
41
/* modifiers is set inside the native */
42
this.defc = finishFieldInitialization(accessClass);
43
isVolatile = Modifier.isVolatile(rawModifiers);
44
assert(isVMSlotCorrectlyTagged());
45
}
46
47
FieldHandle(MethodType type, Field field, byte kind, boolean isStatic) throws IllegalAccessException {
48
super(type, field.getDeclaringClass(), field.getName(), kind, field.getModifiers(), null);
49
this.fieldClass = field.getType();
50
assert(isStatic == Modifier.isStatic(field.getModifiers()));
51
52
boolean succeed = setVMSlotAndRawModifiersFromField(this, field);
53
if (!succeed) {
54
throw new IllegalAccessException();
55
}
56
isVolatile = Modifier.isVolatile(rawModifiers);
57
assert(isVMSlotCorrectlyTagged());
58
}
59
60
FieldHandle(FieldHandle originalHandle, MethodType newType) {
61
super(originalHandle, newType);
62
this.fieldClass = originalHandle.fieldClass;
63
this.isVolatile = originalHandle.isVolatile;
64
assert(isVMSlotCorrectlyTagged());
65
}
66
67
final Class<?> finishFieldInitialization(Class<?> accessClass) throws IllegalAccessException, NoSuchFieldException {
68
String signature = MethodTypeHelper.getBytecodeStringName(fieldClass);
69
try {
70
boolean isStaticLookup = ((KIND_GETSTATICFIELD == this.kind) || (KIND_PUTSTATICFIELD == this.kind));
71
return lookupField(referenceClass, name, signature, isStaticLookup, accessClass);
72
} catch (NoSuchFieldError e) {
73
throw new NoSuchFieldException(e.getMessage());
74
} catch (LinkageError e) {
75
throw (IllegalAccessException) new IllegalAccessException(e.getMessage()).initCause(e);
76
}
77
}
78
79
/* Ensure the vmSlot is low tagged if static */
80
boolean isVMSlotCorrectlyTagged() {
81
if ((KIND_PUTSTATICFIELD == this.kind) || (KIND_GETSTATICFIELD == this.kind)) {
82
return (vmSlot & 1) == 1;
83
}
84
return (vmSlot & 1) == 0;
85
}
86
87
@Override
88
boolean canRevealDirect() {
89
return true;
90
}
91
92
final void compareWithField(FieldHandle left, Comparator c) {
93
c.compareStructuralParameter(left.referenceClass, this.referenceClass);
94
c.compareStructuralParameter(left.vmSlot, this.vmSlot);
95
}
96
97
/*[IF JAVA_SPEC_VERSION >= 11]*/
98
boolean isFinal() {
99
return Modifier.isFinal(this.rawModifiers);
100
}
101
/*[ENDIF] JAVA_SPEC_VERSION >= 11 */
102
}
103
104