Skip to content

Commit 7affe5a

Browse files
authored
Fix virtual invoke tracking in bytecode translator (#4299)
1 parent 787e238 commit 7affe5a

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/CustomInvoke.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ public boolean appendExpression(StringBuilder b) {
159159
}
160160

161161
StringBuilder bld = new StringBuilder();
162+
boolean isVirtualCall = false;
162163
if(origOpcode == Opcodes.INVOKEINTERFACE || origOpcode == Opcodes.INVOKEVIRTUAL) {
163164
b.append(" ");
164165

@@ -179,6 +180,7 @@ public boolean appendExpression(StringBuilder b) {
179180
}
180181
if (isVirtual) {
181182
bld.append("virtual_");
183+
isVirtualCall = true;
182184
}
183185
} else {
184186
b.append(" ");
@@ -207,6 +209,9 @@ public boolean appendExpression(StringBuilder b) {
207209
bld.append("__");
208210
ArrayList<String> args = new ArrayList<String>();
209211
String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args);
212+
if (isVirtualCall) {
213+
BytecodeMethod.addVirtualMethodsInvoked(bld.substring("virtual_".length()));
214+
}
210215
int numLiteralArgs = this.getNumLiteralArgs();
211216
if (numLiteralArgs > 0) {
212217
b.append("/* CustomInvoke */");

vm/ByteCodeTranslator/src/com/codename1/tools/translator/bytecodes/Invoke.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,10 @@ public void appendInstruction(StringBuilder b) {
142142
}
143143

144144
StringBuilder bld = new StringBuilder();
145+
boolean isVirtualCall = false;
145146
if(opcode == Opcodes.INVOKEINTERFACE || opcode == Opcodes.INVOKEVIRTUAL) {
146147
b.append(" ");
147-
148+
148149
// Well, it is actually legal to call private methods with invoke virtual, and kotlin
149150
// generates such calls. But ParparVM strips out these virtual method definitions
150151
// so we need to check if the method is private, and remove the virtual invocation
@@ -162,6 +163,7 @@ public void appendInstruction(StringBuilder b) {
162163
}
163164
if (isVirtual) {
164165
bld.append("virtual_");
166+
isVirtualCall = true;
165167
}
166168
} else {
167169
b.append(" ");
@@ -195,6 +197,9 @@ public void appendInstruction(StringBuilder b) {
195197
bld.append("__");
196198
ArrayList<String> args = new ArrayList<String>();
197199
String returnVal = BytecodeMethod.appendMethodSignatureSuffixFromDesc(desc, bld, args);
200+
if (isVirtualCall) {
201+
BytecodeMethod.addVirtualMethodsInvoked(bld.substring("virtual_".length()));
202+
}
198203
boolean noPop = false;
199204
if(returnVal == null) {
200205
b.append(bld);

0 commit comments

Comments
 (0)