Skip to content

Commit

Permalink
Always support frame expansions.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Aug 20, 2022
1 parent 5118f3c commit f83e348
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 12 deletions.
Expand Up @@ -513,8 +513,21 @@ public void visitCode() {
false);
mv.visitInsn(Type.getType(token.getReturnType().getDescriptor()).getOpcode(Opcodes.IRETURN));
mv.visitLabel(label);
if (frameGeneration.isActive()) { // TODO
mv.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
switch (frameGeneration) {
case GENERATE:
mv.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
break;
case EXPAND:
Object[] localVariable = new Object[token.getParameterTypes().size()];
for (int index = 0; index < localVariable.length; index++) {
localVariable[index] = token.getParameterTypes().get(index).getInternalName();
}
mv.visitFrame(Opcodes.F_NEW, localVariable.length, localVariable, EMPTY.length, EMPTY);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
}

Expand Down
Expand Up @@ -498,19 +498,58 @@ protected class AfterInstruction extends StackManipulation.AbstractBase {
public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
methodVisitor.visitJumpInsn(Opcodes.GOTO, endOfBlock);
methodVisitor.visitLabel(secondValueNull);
if (implementationContext.getFrameGeneration().isActive()) { // TODO
methodVisitor.visitFrame(Opcodes.F_SAME1, EMPTY.length, EMPTY, REFERENCE.length, REFERENCE);
switch (implementationContext.getFrameGeneration()) {
case GENERATE:
methodVisitor.visitFrame(Opcodes.F_SAME1, EMPTY.length, EMPTY, REFERENCE.length, REFERENCE);
break;
case EXPAND:
methodVisitor.visitFrame(Opcodes.F_NEW,
2,
new Object[]{implementationContext.getInstrumentedType().getInternalName(), Type.getInternalName(Object.class)},
REFERENCE.length,
REFERENCE);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
methodVisitor.visitJumpInsn(Opcodes.IFNULL, endOfBlock);
methodVisitor.visitLabel(firstValueNull);
if (implementationContext.getFrameGeneration().isActive()) {
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
switch (implementationContext.getFrameGeneration()) {
case GENERATE:
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
break;
case EXPAND:
methodVisitor.visitFrame(Opcodes.F_NEW,
2,
new Object[]{implementationContext.getInstrumentedType().getInternalName(), Type.getInternalName(Object.class)},
EMPTY.length,
EMPTY);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
methodVisitor.visitInsn(Opcodes.ICONST_0);
methodVisitor.visitInsn(Opcodes.IRETURN);
methodVisitor.visitLabel(endOfBlock);
if (implementationContext.getFrameGeneration().isActive()) {
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
switch (implementationContext.getFrameGeneration()) {
case GENERATE:
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
break;
case EXPAND:
methodVisitor.visitFrame(Opcodes.F_NEW,
2,
new Object[]{implementationContext.getInstrumentedType().getInternalName(), Type.getInternalName(Object.class)},
EMPTY.length,
EMPTY);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
return Size.ZERO;
}
Expand Down Expand Up @@ -910,8 +949,21 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
methodVisitor.visitInsn(value);
methodVisitor.visitInsn(Opcodes.IRETURN);
methodVisitor.visitLabel(label);
if (implementationContext.getFrameGeneration().isActive()) { // TODO
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
switch (implementationContext.getFrameGeneration()) {
case GENERATE:
methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY);
break;
case EXPAND:
methodVisitor.visitFrame(Opcodes.F_NEW,
2,
new Object[]{implementationContext.getInstrumentedType().getInternalName(), Type.getInternalName(Object.class)},
EMPTY.length,
EMPTY);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
return new Size(-1, 1);
}
Expand Down
Expand Up @@ -462,8 +462,21 @@ protected class AfterInstruction extends StackManipulation.AbstractBase {
*/
public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
methodVisitor.visitLabel(label);
if (implementationContext.getFrameGeneration().isActive()) { // TODO
methodVisitor.visitFrame(Opcodes.F_SAME1, EMPTY.length, EMPTY, INTEGER.length, INTEGER);
switch (implementationContext.getFrameGeneration()) {
case GENERATE:
methodVisitor.visitFrame(Opcodes.F_SAME1, EMPTY.length, EMPTY, INTEGER.length, INTEGER);
break;
case EXPAND:
methodVisitor.visitFrame(Opcodes.F_NEW,
1,
new Object[]{implementationContext.getInstrumentedType().getInternalName()},
INTEGER.length,
INTEGER);
break;
case DISABLED:
break;
default:
throw new IllegalStateException();
}
return Size.ZERO;
}
Expand Down

0 comments on commit f83e348

Please sign in to comment.