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