Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/StaticFieldRef.java
6004 views
1
/*******************************************************************************
2
* Copyright (c) 2004, 2021 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* 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
21
*******************************************************************************/
22
package com.ibm.oti.VMCPTool;
23
24
import java.io.PrintWriter;
25
import java.util.Map;
26
27
import org.w3c.dom.Element;
28
29
public class StaticFieldRef extends FieldRef implements Constants {
30
31
private static class Alias extends FieldRef.Alias {
32
Alias(VersionRange[] versions, String[] flags, ClassRef classRef, NameAndSignature nas, String cast) {
33
super(versions, flags, classRef, nas, cast);
34
}
35
36
void write(ConstantPoolStream ds) {
37
if (checkClassForWrite(ds)) {
38
ds.alignTo(4);
39
ds.markStaticField();
40
ds.writeInt(ds.getIndex(classRef));
41
ds.writeInt(ds.getOffset(nas) - ds.getOffset());
42
}
43
}
44
}
45
46
private static class Factory extends FieldRef.Factory {
47
48
Factory(Map<String, ClassRef> classes) {
49
super(classes);
50
}
51
52
public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) {
53
Alias p = (Alias) proto;
54
return new Alias(
55
versions(e, p),
56
flags(e, p),
57
classRef(e),
58
new NameAndSignature(
59
attribute(e, "name", p != null ? p.nas.name.data : ""),
60
attribute(e, "signature", p != null ? p.nas.signature.data : "")),
61
attribute(e, "cast", p != null ? p.cast : ""));
62
}
63
64
}
65
66
public StaticFieldRef(Element e, Map<String, ClassRef> classes) {
67
super(e, FIELDALIAS, new Factory(classes));
68
}
69
70
public void writeMacros(ConstantPool pool, PrintWriter out) {
71
superWriteMacros(pool, out);
72
String type = fieldType();
73
String cast = ((FieldRef.Alias) primary).cast;
74
String castTo = cast.length() == 0 ? "" : "(" + cast + ")";
75
String macroName = cMacroName();
76
String fieldOffset = "J9VMCONSTANTPOOL_STATICFIELD_ADDRESS(J9VMTHREAD_JAVAVM(vmThread), J9VMCONSTANTPOOL_" + macroName + ")";
77
78
out.println("#define J9VM" + macroName + "_ADDRESS(vmThread) " + fieldOffset);
79
out.println("#define J9VM" + macroName + "(vmThread, clazz) ((void)0, \\");
80
out.println("\t" + castTo + "J9STATIC_" + type + "_LOAD(vmThread, clazz, J9VM" + macroName + "_ADDRESS(vmThread)))");
81
out.println("#define J9VM" + cSetterMacroName() + "(vmThread, clazz, value) ((void)0, \\");
82
out.println("\tJ9STATIC_" + type + "_STORE(vmThread, clazz, J9VM" + macroName + "_ADDRESS(vmThread), (value)))");
83
84
/* Generate a second set of macros that take a J9JavaVM parameter instead of a J9VMThread */
85
86
fieldOffset = "J9VMCONSTANTPOOL_STATICFIELD_ADDRESS_VM(javaVM, J9VMCONSTANTPOOL_" + macroName + ")";
87
88
out.println("#define J9VM" + macroName + "_ADDRESS_VM(javaVM) " + fieldOffset);
89
out.println("#define J9VM" + macroName + "_VM(javaVM, clazz) ((void)0, \\");
90
out.println("\t" + castTo + "J9STATIC_" + type + "_LOAD_VM(javaVM, clazz, J9VM" + macroName + "_ADDRESS_VM(javaVM)))");
91
out.println("#define J9VM" + cSetterMacroName() + "_VM(javaVM, clazz, value) ((void)0, \\");
92
out.println("\tJ9STATIC_" + type + "_STORE_VM(javaVM, clazz, J9VM" + macroName + "_ADDRESS_VM(javaVM), (value)))");
93
}
94
95
}
96
97