Commit 46bfb5af authored by Lukáš Marek's avatar Lukáš Marek
Browse files

Fix: Added boxing for dynamic context only when needed

parent c7632b6f
......@@ -381,6 +381,10 @@ public abstract class AsmHelper {
return instr;
}
public static boolean isReferenceType(Type type) {
return type.getSort() == Type.OBJECT || type.getSort() == Type.ARRAY;
}
public static boolean isVirtualInstr(AbstractInsnNode instr) {
return instr.getOpcode() == -1;
......
......@@ -10,6 +10,7 @@ import org.objectweb.asm.Type;
import org.objectweb.asm.commons.AdviceAdapter;
import ch.usi.dag.disl.localvar.ThreadLocalVar;
import ch.usi.dag.disl.util.AsmHelper;
import ch.usi.dag.disl.util.Constants;
public final class TLVInserter extends ClassVisitor {
......@@ -109,10 +110,8 @@ public final class TLVInserter extends ClassVisitor {
}
else {
int tlvSort = tlv.getType().getSort();
// if object or array
if(tlvSort == Type.OBJECT || tlvSort == Type.ARRAY) {
if(AsmHelper.isReferenceType(tlv.getType())) {
// insert null
visitInsn(ACONST_NULL);
}
......
......@@ -250,7 +250,13 @@ public class WeavingCode {
int size = StackUtil.dupStack(sourceframe, method, operand,
sopcode, method.maxLocals + max);
// load the stack value
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
// box value if applicable
// boxing is removed by partial evaluator if not needed
if(! AsmHelper.isReferenceType(t)) {
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
}
iList.insert(instr, new VarInsnNode(lopcode, max));
max += size;
}
......@@ -276,7 +282,11 @@ public class WeavingCode {
+ targetType + "\", while user needs \"" + t + "\"");
}
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
// box value if applicable
// boxing is removed by partial evaluator if not needed
if(! AsmHelper.isReferenceType(t)) {
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
}
iList.insert(instr, new VarInsnNode(t.getOpcode(Opcodes.ILOAD),
slot - method.maxLocals));
} else if (invoke.name.equals("localVariableValue")) {
......@@ -296,7 +306,11 @@ public class WeavingCode {
+ targetType + "\", while user needs \"" + t + "\"");
}
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
// box value if applicable
// boxing is removed by partial evaluator if not needed
if(! AsmHelper.isReferenceType(t)) {
iList.insert(instr, AsmHelper.boxValueOnStack(targetType));
}
iList.insert(instr, new VarInsnNode(t.getOpcode(Opcodes.ILOAD),
operand - method.maxLocals));
}
......@@ -524,7 +538,7 @@ public class WeavingCode {
insnList.add(new VarInsnNode(loadOpcode, argIndex));
// box non-reference type
if (!(argType.getSort() == Type.OBJECT || argType.getSort() == Type.ARRAY)) {
if (! AsmHelper.isReferenceType(argType)) {
insnList.add(AsmHelper.boxValueOnStack(argType));
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment