Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/ClassRef.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
26
import org.w3c.dom.Element;
27
28
public class ClassRef extends PrimaryItem implements Constants {
29
30
private static final class Alias extends PrimaryItem.Alias {
31
final J9UTF8 name;
32
33
Alias(VersionRange[] versions, String[] flags, J9UTF8 name) {
34
super(versions, flags);
35
this.name = name;
36
}
37
38
protected boolean isIncluded() {
39
return true;
40
}
41
42
void writeSecondaryItems(ConstantPoolStream ds) {
43
ds.writeSecondaryItem(name);
44
}
45
46
void write(ConstantPoolStream ds) {
47
ds.alignTo(4);
48
ds.markClass();
49
ds.writeInt(ds.getOffset(name) - ds.getOffset());
50
51
Main.JCLRuntimeFlag flag;
52
if (flags.length == 0) {
53
flag = Main.getRuntimeFlag("default");
54
} else {
55
if (flags.length > 1) {
56
System.err.println("Error: tool cannot handle complex flag expressions");
57
System.exit(-1);
58
}
59
flag = Main.getRuntimeFlag(flags[0]);
60
}
61
ds.writeInt(flag.value);
62
}
63
}
64
65
public ClassRef(Element e) {
66
super(e, CLASSALIAS, new Alias.Factory() {
67
public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) {
68
Alias p = (Alias) proto;
69
return new Alias(ClassRef.versions(e, p), ClassRef.flags(e, p),
70
new J9UTF8(ClassRef.attribute(e, "name", p != null ? p.name.data : "")));
71
}
72
});
73
}
74
75
protected String cMacroName() {
76
char[] buf = ((Alias) primary).name.data.toCharArray();
77
int j = 0;
78
79
for (int i = 0; i < buf.length; i++) {
80
if (buf[i] != '/' && buf[i] != '$') {
81
buf[j++] = buf[i];
82
}
83
}
84
return new String(buf, 0, j).toUpperCase();
85
}
86
87
public void writeMacros(ConstantPool pool, PrintWriter out) {
88
super.writeMacros(pool, out);
89
90
String macroName = cMacroName();
91
out.println("#define J9VM" + macroName + "(vm) J9VMCONSTANTPOOL_CLASS_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")");
92
out.println("#define J9VM" + macroName + "_OR_NULL(vm) (J9VMCONSTANTPOOL_CLASSREF_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")->value)");
93
}
94
95
public String getClassName() {
96
return ((Alias) primary).name.data;
97
}
98
99
public String commentText() {
100
return "ClassRef[" + getClassName() + "]";
101
}
102
103
}
104
105