Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/sourcetools/j9constantpool/com/ibm/oti/VMCPTool/InterfaceMethodRef.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 InterfaceMethodRef extends PrimaryItem implements Constants {
30
31
private static class Alias extends PrimaryItem.AliasWithClass {
32
final NameAndSignature nas;
33
34
Alias(VersionRange[] versions, String[] flags, ClassRef classRef, NameAndSignature nas) {
35
super(versions, flags, classRef);
36
this.nas = nas;
37
}
38
39
void writeSecondaryItems(ConstantPoolStream ds) {
40
if (checkClassForWriteSecondary(ds)) {
41
ds.writeSecondaryItem(nas);
42
}
43
}
44
45
void write(ConstantPoolStream ds) {
46
if (checkClassForWrite(ds)) {
47
ds.alignTo(4);
48
ds.markInterfaceMethod();
49
ds.writeInt(ds.getIndex(classRef));
50
ds.writeInt(ds.getOffset(nas) - ds.getOffset());
51
}
52
}
53
}
54
55
private static class Factory implements Alias.Factory {
56
private final Map<String, ClassRef> classes;
57
private ClassRef classRef;
58
59
Factory(Map<String, ClassRef> classes) {
60
this.classes = classes;
61
this.classRef = null;
62
}
63
64
public PrimaryItem.Alias alias(Element e, PrimaryItem.Alias proto) {
65
Alias p = (Alias) proto;
66
return new Alias(
67
versions(e, p),
68
flags(e, p),
69
classRef(e),
70
new NameAndSignature(
71
attribute(e, "name", p != null ? p.nas.name.data : ""),
72
attribute(e, "signature", p != null ? p.nas.signature.data : "")));
73
}
74
75
private ClassRef classRef(Element e) {
76
String name = attribute(e, "class", null);
77
if (name == null) {
78
return classRef;
79
}
80
if (classRef == null) {
81
classRef = classes.get(name);
82
}
83
return classes.get(name);
84
}
85
}
86
87
public InterfaceMethodRef(Element e, Map<String, ClassRef> classes) {
88
super(e, METHODALIAS, new Factory(classes));
89
}
90
91
protected String cMacroName() {
92
String methodName = ((Alias) primary).nas.name.data.toUpperCase();
93
if (methodName.indexOf('<') != -1) {
94
StringBuilder newName = new StringBuilder();
95
for (int i = 0; i < methodName.length(); i++) {
96
char ch = methodName.charAt(i);
97
if (ch != '<' && ch != '>') {
98
newName.append(ch);
99
}
100
}
101
methodName = newName.toString();
102
}
103
return ((Alias) primary).classRef.cMacroName() + "_" + methodName;
104
}
105
106
public void writeMacros(ConstantPool pool, PrintWriter out) {
107
super.writeMacros(pool, out);
108
String macroName = cMacroName();
109
out.println("#define J9VM" + macroName + "_REF(vm) J9VMCONSTANTPOOL_INTERFACEMETHODREF_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")");
110
out.println("#define J9VM" + macroName + "_INDEX_AND_ARGS(vm) J9VMCONSTANTPOOL_INTERFACEMETHOD_AT(vm, J9VMCONSTANTPOOL_" + macroName + ")");
111
}
112
113
}
114
115