Skip to content

Commit

Permalink
Adjusted inline advice to generate easier return dispatchers.
Browse files Browse the repository at this point in the history
  • Loading branch information
raphw committed Jun 15, 2016
1 parent 6ee23f0 commit 74344c8
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java
Expand Up @@ -6330,16 +6330,16 @@ public void apply() {
adviceMethod.getInternalName(),
adviceMethod.getDescriptor(),
false);
onAfterCall();
onMethodReturn();
suppressionHandler.onEndSkipped(methodVisitor, stackMapFrameHandler, this);
onMethodExit();
stackMapFrameHandler.injectCompletionFrame(methodVisitor, false);
methodSizeHandler.recordMaxima(Math.max(maximumStackSize, adviceMethod.getReturnType().getStackSize().getSize()), EMPTY);
}

/**
* Invoked after the advise method was invoked.
*/
protected abstract void onAfterCall();
protected abstract void onMethodReturn();

protected abstract void onMethodExit();

@Override
public String toString() {
Expand Down Expand Up @@ -6379,7 +6379,12 @@ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod,
}

@Override
protected void onAfterCall() {
protected void onMethodReturn() {
/* do nothing */
}

@Override
protected void onMethodExit() {
if (adviceMethod.getReturnType().represents(boolean.class)
|| adviceMethod.getReturnType().represents(byte.class)
|| adviceMethod.getReturnType().represents(short.class)
Expand All @@ -6405,19 +6410,14 @@ public void storeDefaultValue(MethodVisitor methodVisitor) {
|| adviceMethod.getReturnType().represents(char.class)
|| adviceMethod.getReturnType().represents(int.class)) {
methodVisitor.visitInsn(Opcodes.ICONST_0);
methodVisitor.visitVarInsn(Opcodes.ISTORE, instrumentedMethod.getStackSize());
} else if (adviceMethod.getReturnType().represents(long.class)) {
methodVisitor.visitInsn(Opcodes.LCONST_0);
methodVisitor.visitVarInsn(Opcodes.LSTORE, instrumentedMethod.getStackSize());
} else if (adviceMethod.getReturnType().represents(float.class)) {
methodVisitor.visitInsn(Opcodes.FCONST_0);
methodVisitor.visitVarInsn(Opcodes.FSTORE, instrumentedMethod.getStackSize());
} else if (adviceMethod.getReturnType().represents(double.class)) {
methodVisitor.visitInsn(Opcodes.DCONST_0);
methodVisitor.visitVarInsn(Opcodes.DSTORE, instrumentedMethod.getStackSize());
} else if (!adviceMethod.getReturnType().represents(void.class)) {
methodVisitor.visitInsn(Opcodes.ACONST_NULL);
methodVisitor.visitVarInsn(Opcodes.ASTORE, instrumentedMethod.getStackSize());
}
}

Expand Down Expand Up @@ -6457,7 +6457,7 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod,
}

@Override
protected void onAfterCall() {
protected void onMethodReturn() {
switch (adviceMethod.getReturnType().getStackSize()) {
case ZERO:
return;
Expand All @@ -6472,6 +6472,11 @@ protected void onAfterCall() {
}
}

@Override
protected void onMethodExit() {
/* do nothing */
}

@Override
public void storeDefaultValue(MethodVisitor methodVisitor) {
/* do nothing */
Expand Down

0 comments on commit 74344c8

Please sign in to comment.