Skip to content

Commit

Permalink
Minor renamings.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 15, 2016
1 parent 966347f commit 9bd9143
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Expand Up @@ -664,27 +664,16 @@ protected interface StackMapFrameHandler {
*/ */
void translateFrame(MethodVisitor methodVisitor, int frameType, int localVariableLength, Object[] localVariable, int stackSize, Object[] stack); void translateFrame(MethodVisitor methodVisitor, int frameType, int localVariableLength, Object[] localVariable, int stackSize, Object[] stack);


/** void injectExceptionFrame(MethodVisitor methodVisitor);
* Injects a frame for a method's exception handler.
*
* @param methodVisitor The method visitor to write the frame to.
*/
void injectHandlerFrame(MethodVisitor methodVisitor);


/**
* Injects a frame after a method's completion.
*
* @param methodVisitor The method visitor to write the frame to.
* @param secondary {@code true} if the frame is written a second time.
*/
void injectCompletionFrame(MethodVisitor methodVisitor, boolean secondary); void injectCompletionFrame(MethodVisitor methodVisitor, boolean secondary);


/** /**
* A stack map frame handler for an instrumented method. * A stack map frame handler for an instrumented method.
*/ */
interface ForInstrumentedMethod extends StackMapFrameHandler { interface ForInstrumentedMethod extends StackMapFrameHandler {


void injectReturnFrame(MethodVisitor methodVisitor, TypeDescription returnType); void injectReturnFrame(MethodVisitor methodVisitor);


/** /**
* Binds this meta data handler for the entry advice. * Binds this meta data handler for the entry advice.
Expand Down Expand Up @@ -754,12 +743,12 @@ public void translateFrame(MethodVisitor methodVisitor,




@Override @Override
public void injectReturnFrame(MethodVisitor methodVisitor, TypeDescription returnType) { public void injectReturnFrame(MethodVisitor methodVisitor) {
/* do nothing */ /* do nothing */
} }


@Override @Override
public void injectHandlerFrame(MethodVisitor methodVisitor) { public void injectExceptionFrame(MethodVisitor methodVisitor) {
/* do nothing */ /* do nothing */
} }


Expand Down Expand Up @@ -968,22 +957,22 @@ protected void translateFrame(MethodVisitor methodVisitor,
} }


@Override @Override
public void injectReturnFrame(MethodVisitor methodVisitor, TypeDescription returnType) { public void injectReturnFrame(MethodVisitor methodVisitor) {
if (!expandFrames && currentFrameDivergence == 0 && !instrumentedMethod.isConstructor()) { if (!expandFrames && currentFrameDivergence == 0 && !instrumentedMethod.isConstructor()) {
if (returnType.represents(void.class)) { if (instrumentedMethod.getReturnType().represents(void.class)) {
methodVisitor.visitFrame(Opcodes.F_SAME, 0, EMPTY, 0, EMPTY); methodVisitor.visitFrame(Opcodes.F_SAME, 0, EMPTY, 0, EMPTY);
} else { } else {
methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{toFrame(returnType)}); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{toFrame(instrumentedMethod.getReturnType().asErasure())});
} }
} else { } else {
injectFullFrame(methodVisitor, requiredTypes, returnType.represents(void.class) injectFullFrame(methodVisitor, requiredTypes, instrumentedMethod.getReturnType().represents(void.class)
? Collections.emptyList() ? Collections.emptyList()
: Collections.singletonList(returnType)); : Collections.singletonList(instrumentedMethod.getReturnType().asErasure()));
} }
} }


@Override @Override
public void injectHandlerFrame(MethodVisitor methodVisitor) { public void injectExceptionFrame(MethodVisitor methodVisitor) {
if (!expandFrames && currentFrameDivergence == 0) { if (!expandFrames && currentFrameDivergence == 0) {
methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{Type.getInternalName(Throwable.class)}); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{Type.getInternalName(Throwable.class)});
} else { } else {
Expand Down Expand Up @@ -1191,7 +1180,7 @@ public void translateFrame(MethodVisitor methodVisitor,
} }


@Override @Override
public void injectHandlerFrame(MethodVisitor methodVisitor) { public void injectExceptionFrame(MethodVisitor methodVisitor) {
if (!expandFrames && currentFrameDivergence == 0) { if (!expandFrames && currentFrameDivergence == 0) {
methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{Type.getInternalName(Throwable.class)}); methodVisitor.visitFrame(Opcodes.F_SAME1, 0, EMPTY, 1, new Object[]{Type.getInternalName(Throwable.class)});
} else { } else {
Expand Down Expand Up @@ -1474,12 +1463,12 @@ protected void onVisitInsn(int opcode) {
@Override @Override
protected void onUserEnd() { protected void onUserEnd() {
mv.visitLabel(returnHandler); mv.visitLabel(returnHandler);
stackMapFrameHandler.injectReturnFrame(mv, instrumentedMethod.getReturnType().asErasure()); stackMapFrameHandler.injectReturnFrame(mv);
Type returnType = Type.getType(instrumentedMethod.getReturnType().asErasure().getDescriptor()); Type returnType = Type.getType(instrumentedMethod.getReturnType().asErasure().getDescriptor());
if (!returnType.equals(Type.VOID_TYPE)) { if (!returnType.equals(Type.VOID_TYPE)) {
variable(returnType.getOpcode(Opcodes.ISTORE)); variable(returnType.getOpcode(Opcodes.ISTORE));
} }
onUserReturn(); // TODO: Need to reset completion frame if returned onUserReturn();
methodExit.apply(); methodExit.apply();
onExitAdviceReturn(); onExitAdviceReturn();
if (returnType.equals(Type.VOID_TYPE)) { if (returnType.equals(Type.VOID_TYPE)) {
Expand All @@ -1488,18 +1477,6 @@ protected void onUserEnd() {
variable(returnType.getOpcode(Opcodes.ILOAD)); variable(returnType.getOpcode(Opcodes.ILOAD));
mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN)); mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
} }

// onUserExit();
// mv.visitLabel(endOfMethod);
// stackMapFrameHandler.injectCompletionFrame(mv, false);
// methodExit.apply();
// if (instrumentedMethod.getReturnType().represents(void.class)) {
// mv.visitInsn(Opcodes.RETURN);
// } else {
// variable(returnType.getOpcode(Opcodes.ILOAD));
// mv.visitInsn(returnType.getOpcode(Opcodes.IRETURN));
// }
// onMethodExit();
} }


protected abstract void onUserReturn(); protected abstract void onUserReturn();
Expand Down Expand Up @@ -1640,7 +1617,7 @@ protected void onUserReturn() {
Label endOfHandler = new Label(); Label endOfHandler = new Label();
mv.visitJumpInsn(Opcodes.GOTO, endOfHandler); mv.visitJumpInsn(Opcodes.GOTO, endOfHandler);
mv.visitLabel(exceptionHandler); mv.visitLabel(exceptionHandler);
stackMapFrameHandler.injectHandlerFrame(mv); stackMapFrameHandler.injectExceptionFrame(mv);
variable(Opcodes.ASTORE, instrumentedMethod.getReturnType().getStackSize().getSize()); variable(Opcodes.ASTORE, instrumentedMethod.getReturnType().getStackSize().getSize());
storeDefaultReturn(); storeDefaultReturn();
mv.visitLabel(endOfHandler); mv.visitLabel(endOfHandler);
Expand Down Expand Up @@ -4930,7 +4907,7 @@ public void onStart(MethodVisitor methodVisitor, MethodSizeHandler.ForAdvice met
@Override @Override
public void onEnd(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) { public void onEnd(MethodVisitor methodVisitor, StackMapFrameHandler.ForAdvice stackMapFrameHandler, ReturnValueProducer returnValueProducer) {
methodVisitor.visitLabel(endOfMethod); methodVisitor.visitLabel(endOfMethod);
stackMapFrameHandler.injectHandlerFrame(methodVisitor); stackMapFrameHandler.injectExceptionFrame(methodVisitor);
methodVisitor.visitInsn(Opcodes.POP); methodVisitor.visitInsn(Opcodes.POP);
returnValueProducer.storeDefaultValue(methodVisitor); returnValueProducer.storeDefaultValue(methodVisitor);
} }
Expand Down

0 comments on commit 9bd9143

Please sign in to comment.