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