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/FieldGetterHandle.java
12520 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
import static java.lang.invoke.MethodHandleResolver.UNSAFE;
29
30
/*
31
* MethodHandle subclass that is able to return the value of
32
* an instance field.
33
* <p>
34
* vmSlot will hold the field offset in the instance.
35
*
36
*/
37
final class FieldGetterHandle extends FieldHandle {
38
39
FieldGetterHandle(Class<?> referenceClass, String fieldName, Class<?> fieldClass, Class<?> accessClass) throws IllegalAccessException, NoSuchFieldException {
40
super(fieldMethodType(fieldClass, referenceClass), referenceClass, fieldName, fieldClass, KIND_GETFIELD, accessClass);
41
}
42
43
FieldGetterHandle(Field field) throws IllegalAccessException {
44
super(fieldMethodType(field.getType(), field.getDeclaringClass()), field, KIND_GETFIELD, false);
45
}
46
47
FieldGetterHandle(FieldGetterHandle originalHandle, MethodType newType) {
48
super(originalHandle, newType);
49
}
50
51
/* Create the MethodType to be passed to the constructor */
52
private final static MethodType fieldMethodType(Class<?> returnType, Class<?> argument) {
53
return MethodType.methodType(returnType, argument);
54
}
55
56
// {{{ JIT support
57
@FrameIteratorSkip
58
private final int invokeExact_thunkArchetype_I(Object receiver, int argPlaceholder) {
59
if (isVolatile) {
60
return UNSAFE.getIntVolatile(receiver, vmSlot + HEADER_SIZE);
61
} else {
62
return UNSAFE.getInt(receiver, vmSlot + HEADER_SIZE);
63
}
64
}
65
66
@FrameIteratorSkip
67
private final long invokeExact_thunkArchetype_J(Object receiver, int argPlaceholder) {
68
if (isVolatile) {
69
return UNSAFE.getLongVolatile(receiver, vmSlot + HEADER_SIZE);
70
} else {
71
return UNSAFE.getLong(receiver, vmSlot + HEADER_SIZE);
72
}
73
}
74
75
@FrameIteratorSkip
76
private final float invokeExact_thunkArchetype_F(Object receiver, int argPlaceholder) {
77
if (isVolatile) {
78
return UNSAFE.getFloatVolatile(receiver, vmSlot + HEADER_SIZE);
79
} else {
80
return UNSAFE.getFloat(receiver, vmSlot + HEADER_SIZE);
81
}
82
}
83
84
@FrameIteratorSkip
85
private final double invokeExact_thunkArchetype_D(Object receiver, int argPlaceholder) {
86
if (isVolatile) {
87
return UNSAFE.getDoubleVolatile(receiver, vmSlot + HEADER_SIZE);
88
} else {
89
return UNSAFE.getDouble(receiver, vmSlot + HEADER_SIZE);
90
}
91
}
92
93
@FrameIteratorSkip
94
private final Object invokeExact_thunkArchetype_L(Object receiver, int argPlaceholder) {
95
if (isVolatile) {
96
return UNSAFE.getObjectVolatile(receiver, vmSlot + HEADER_SIZE);
97
} else {
98
return UNSAFE.getObject(receiver, vmSlot + HEADER_SIZE);
99
}
100
}
101
102
private static final ThunkTable _thunkTable = new ThunkTable();
103
protected final ThunkTable thunkTable(){ return _thunkTable; }
104
// }}} JIT support
105
106
@Override
107
MethodHandle cloneWithNewType(MethodType newType) {
108
return new FieldGetterHandle(this, newType);
109
}
110
111
final void compareWith(MethodHandle right, Comparator c) {
112
if (right instanceof FieldGetterHandle) {
113
((FieldGetterHandle)right).compareWithFieldGetter(this, c);
114
} else {
115
c.fail();
116
}
117
}
118
119
final void compareWithFieldGetter(FieldGetterHandle left, Comparator c) {
120
compareWithField(left, c);
121
}
122
}
123
124
125