Skip to content

Commit a0690e8

Browse files
committed
optimization - migrate from INVOKEINTERFACE to INVOKEVIRTUAL
1 parent 6381015 commit a0690e8

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

src/main/java/org/perlonjava/codegen/EmitLiteral.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ public static void emitArrayLiteral(EmitterVisitor emitterVisitor, ArrayLiteralN
8989
}
9090

9191
// Convert the array to a reference (array literals produce references)
92-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider",
93-
"createReference", "()Lorg/perlonjava/runtime/RuntimeScalar;", true);
92+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity",
93+
"createReference", "()Lorg/perlonjava/runtime/RuntimeScalar;", false);
9494

9595
emitterVisitor.ctx.logDebug("visit(ArrayLiteralNode) end");
9696
}

src/main/java/org/perlonjava/codegen/EmitLogicalOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void emitLogicalAssign(EmitterVisitor emitterVisitor, BinaryOperatorNode
6565
// Stack is [left, left]
6666

6767
// Convert the result to a boolean
68-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", getBoolean, "()Z", true);
68+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", getBoolean, "()Z", false);
6969
// Stack is [left, boolean]
7070

7171
// If the boolean value is true, jump to endLabel (we keep the left operand)
@@ -121,7 +121,7 @@ static void emitLogicalOperator(EmitterVisitor emitterVisitor, BinaryOperatorNod
121121
// Stack is [left, left]
122122

123123
// Convert the result to a boolean
124-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "org/perlonjava/runtime/RuntimeDataProvider", getBoolean, "()Z", true);
124+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "org/perlonjava/runtime/RuntimeBaseEntity", getBoolean, "()Z", false);
125125
// Stack is [left, boolean]
126126

127127
// If the left operand boolean value is true, return left operand

src/main/java/org/perlonjava/codegen/EmitOperator.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static void emitOperator(Node node, EmitterVisitor emitterVisitor) {
4040
operatorHandler.getClassName(),
4141
operatorHandler.getMethodName(),
4242
operatorHandler.getDescriptor(),
43-
operatorHandler.getMethodType() == Opcodes.INVOKEINTERFACE
43+
false
4444
);
4545

4646
// Handle context
@@ -269,10 +269,10 @@ static void handleChompBuiltin(EmitterVisitor emitterVisitor, OperatorNode node)
269269
// Accept the operand in LIST context.
270270
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
271271
// Invoke the interface method for the operator.
272-
mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
273-
"org/perlonjava/runtime/RuntimeDataProvider",
272+
mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
273+
"org/perlonjava/runtime/RuntimeBaseEntity",
274274
node.operator,
275-
"()Lorg/perlonjava/runtime/RuntimeScalar;", true);
275+
"()Lorg/perlonjava/runtime/RuntimeScalar;", false);
276276
// If the context is VOID, pop the result from the stack.
277277
handleVoidContext(emitterVisitor);
278278
}
@@ -660,11 +660,11 @@ static void handleCreateReference(EmitterVisitor emitterVisitor, OperatorNode no
660660
}
661661
} else {
662662
node.operand.accept(emitterVisitor.with(RuntimeContextType.LIST));
663-
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
664-
"org/perlonjava/runtime/RuntimeDataProvider",
663+
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
664+
"org/perlonjava/runtime/RuntimeBaseEntity",
665665
"createReference",
666666
"()Lorg/perlonjava/runtime/RuntimeScalar;",
667-
true);
667+
false);
668668
}
669669
handleVoidContext(emitterVisitor);
670670
}

src/main/java/org/perlonjava/codegen/EmitOperatorChained.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ static public void emitChainedComparison(EmitterVisitor emitterVisitor, BinaryOp
7070
for (int i = 1; i < operators.size(); i++) {
7171
// Check previous result
7272
emitterVisitor.ctx.mv.visitInsn(Opcodes.DUP);
73-
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEINTERFACE,
74-
"org/perlonjava/runtime/RuntimeDataProvider",
73+
emitterVisitor.ctx.mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
74+
"org/perlonjava/runtime/RuntimeBaseEntity",
7575
"getBoolean",
7676
"()Z",
77-
true);
77+
false);
7878
emitterVisitor.ctx.mv.visitJumpInsn(Opcodes.IFEQ, falseLabel);
7979

8080
// Previous was true, do next comparison

0 commit comments

Comments
 (0)