Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e10b409

Browse files
committed
First change set.
1 parent 4d34198 commit e10b409

File tree

3 files changed

+51
-32
lines changed

3 files changed

+51
-32
lines changed

byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java

Lines changed: 43 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4887,16 +4887,17 @@ public interface PostProcessor {
48874887
/**
48884888
* Resolves this post processor for a given instrumented method.
48894889
*
4890-
* @param instrumentedType The instrumented type.
4891-
* @param instrumentedMethod The instrumented method.
4892-
* @param assigner The assigner to use.
4893-
* @param argumentHandler The argument handler for the instrumented method.
4890+
* @param instrumentedType The instrumented type.
4891+
* @param instrumentedMethod The instrumented method.
4892+
* @param assigner The assigner to use.
4893+
* @param stackMapFrameHandler The argument handler for the instrumented method.
48944894
* @return The stack manipulation to apply.
48954895
*/
48964896
StackManipulation resolve(TypeDescription instrumentedType,
48974897
MethodDescription instrumentedMethod,
48984898
Assigner assigner,
4899-
ArgumentHandler argumentHandler);
4899+
ArgumentHandler argumentHandler,
4900+
StackMapFrameHandler stackMapFrameHandler);
49004901

49014902
/**
49024903
* A factory for creating a {@link PostProcessor}.
@@ -4977,7 +4978,8 @@ enum NoOp implements PostProcessor, Factory {
49774978
public StackManipulation resolve(TypeDescription instrumentedType,
49784979
MethodDescription instrumentedMethod,
49794980
Assigner assigner,
4980-
ArgumentHandler argumentHandler) {
4981+
ArgumentHandler argumentHandler,
4982+
StackMapFrameHandler stackMapFrameHandler) {
49814983
return StackManipulation.Trivial.INSTANCE;
49824984
}
49834985

@@ -5015,10 +5017,11 @@ protected Compound(List<PostProcessor> postProcessors) {
50155017
public StackManipulation resolve(TypeDescription instrumentedType,
50165018
MethodDescription instrumentedMethod,
50175019
Assigner assigner,
5018-
ArgumentHandler argumentHandler) {
5020+
ArgumentHandler argumentHandler,
5021+
StackMapFrameHandler stackMapFrameHandler) {
50195022
List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(postProcessors.size());
50205023
for (PostProcessor postProcessor : postProcessors) {
5021-
stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler));
5024+
stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler));
50225025
}
50235026
return new StackManipulation.Compound(stackManipulations);
50245027
}
@@ -5597,7 +5600,7 @@ public void recordMaxima(int stackSize, int localVariableLength) {
55975600
/**
55985601
* A handler for computing and translating stack map frames.
55995602
*/
5600-
protected interface StackMapFrameHandler {
5603+
public interface StackMapFrameHandler {
56015604

56025605
/**
56035606
* Translates a frame.
@@ -6740,6 +6743,7 @@ public void injectCompletionFrame(MethodVisitor methodVisitor) {
67406743
}
67416744
} else if (currentFrameDivergence < 3 && endTypes.isEmpty()) {
67426745
methodVisitor.visitFrame(Opcodes.F_CHOP, currentFrameDivergence, EMPTY, EMPTY.length, EMPTY);
6746+
currentFrameDivergence = 0; // TODO: ?
67436747
} else {
67446748
injectFullFrame(methodVisitor, initialization, CompoundList.of(startTypes, endTypes), Collections.<TypeDescription>emptyList());
67456749
}
@@ -9199,7 +9203,7 @@ public void visitEnd() {
91999203
methodVisitor.visitVarInsn(Opcodes.ASTORE, exit ? argumentHandler.exit() : argumentHandler.enter());
92009204
}
92019205
methodSizeHandler.requireStackSize(postProcessor
9202-
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
9206+
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler)
92039207
.apply(methodVisitor, implementationContext).getMaximalSize());
92049208
methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, exit ? argumentHandler.exit() : argumentHandler.enter()));
92059209
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
@@ -9553,7 +9557,7 @@ public void apply() {
95539557
methodVisitor.visitVarInsn(Opcodes.ASTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter());
95549558
}
95559559
methodSizeHandler.requireStackSize(postProcessor
9556-
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
9560+
.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler)
95579561
.apply(methodVisitor, implementationContext).getMaximalSize());
95589562
methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()));
95599563
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
@@ -11687,7 +11691,8 @@ protected AssignReturned(TypeDescription.Generic type, boolean exit, boolean ski
1168711691
public StackManipulation resolve(TypeDescription instrumentedType,
1168811692
MethodDescription instrumentedMethod,
1168911693
Assigner assigner,
11690-
ArgumentHandler argumentHandler) {
11694+
ArgumentHandler argumentHandler,
11695+
StackMapFrameHandler stackMapFrameHandler) {
1169111696
List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(getHandlers().size());
1169211697
for (Handler handler : getHandlers()) {
1169311698
stackManipulations.add(handler.resolve(instrumentedType,
@@ -11697,9 +11702,10 @@ public StackManipulation resolve(TypeDescription instrumentedType,
1169711702
getType(),
1169811703
toLoadInstruction(handler, exit ? argumentHandler.exit() : argumentHandler.enter())));
1169911704
}
11700-
return skipOnDefaultValue
11701-
? DefaultValueSkip.of(new StackManipulation.Compound(stackManipulations), exit ? argumentHandler.exit() : argumentHandler.enter(), type)
11702-
: new StackManipulation.Compound(stackManipulations);
11705+
return skipOnDefaultValue ? DefaultValueSkip.of(new StackManipulation.Compound(stackManipulations),
11706+
stackMapFrameHandler,
11707+
exit ? argumentHandler.exit() : argumentHandler.enter(),
11708+
type) : new StackManipulation.Compound(stackManipulations);
1170311709
}
1170411710

1170511711
/**
@@ -12852,6 +12858,11 @@ protected static class DefaultValueSkip implements StackManipulation {
1285212858
*/
1285312859
private final StackManipulation stackManipulation;
1285412860

12861+
/**
12862+
* The stack map frame handler to use.
12863+
*/
12864+
private final StackMapFrameHandler stackMapFrameHandler;
12865+
1285512866
/**
1285612867
* The offset of the value of the returned type.
1285712868
*/
@@ -12866,24 +12877,27 @@ protected static class DefaultValueSkip implements StackManipulation {
1286612877
* Creates a null-check wrapper.
1286712878
*
1286812879
* @param stackManipulation The wrapped stack manipulation in case the value is not a default value.
12880+
* @param stackMapFrameHandler The stack map frame handler to use.
1286912881
* @param offset The offset of the value of the returned type.
1287012882
* @param dispatcher The dispatcher to use.
1287112883
*/
12872-
protected DefaultValueSkip(StackManipulation stackManipulation, int offset, Dispatcher dispatcher) {
12884+
protected DefaultValueSkip(StackManipulation stackManipulation, StackMapFrameHandler stackMapFrameHandler, int offset, Dispatcher dispatcher) {
1287312885
this.stackManipulation = stackManipulation;
12886+
this.stackMapFrameHandler = stackMapFrameHandler;
1287412887
this.offset = offset;
1287512888
this.dispatcher = dispatcher;
1287612889
}
1287712890

1287812891
/**
1287912892
* Resolves a skipping stack manipulation for the supplied type.
1288012893
*
12881-
* @param stackManipulation The stack manipulation to wrap.
12882-
* @param offset The offset of the value of the returned type.
12883-
* @param typeDefinition The type that is returned by the advice method.
12894+
* @param stackManipulation The stack manipulation to wrap.
12895+
* @param stackMapFrameHandler The stack map frame handler to use.
12896+
* @param offset The offset of the value of the returned type.
12897+
* @param typeDefinition The type that is returned by the advice method.
1288412898
* @return A suitable stack manipulation.
1288512899
*/
12886-
protected static StackManipulation of(StackManipulation stackManipulation, int offset, TypeDefinition typeDefinition) {
12900+
protected static StackManipulation of(StackManipulation stackManipulation, StackMapFrameHandler stackMapFrameHandler, int offset, TypeDefinition typeDefinition) {
1288712901
Dispatcher dispatcher;
1288812902
if (typeDefinition.isPrimitive()) {
1288912903
if (typeDefinition.represents(boolean.class)
@@ -12904,7 +12918,7 @@ protected static StackManipulation of(StackManipulation stackManipulation, int o
1290412918
} else {
1290512919
dispatcher = Dispatcher.REFERENCE;
1290612920
}
12907-
return new DefaultValueSkip(stackManipulation, offset, dispatcher);
12921+
return new DefaultValueSkip(stackManipulation, stackMapFrameHandler, offset, dispatcher);
1290812922
}
1290912923

1291012924
/**
@@ -12921,6 +12935,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
1292112935
Label label = new Label();
1292212936
Size size = dispatcher.apply(methodVisitor, offset, label).aggregate(stackManipulation.apply(methodVisitor, implementationContext));
1292312937
methodVisitor.visitLabel(label);
12938+
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
1292412939
return size;
1292512940
}
1292612941

@@ -13220,13 +13235,13 @@ public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit)
1322013235
}
1322113236
}
1322213237
}
13223-
if (handlers.isEmpty()) {
13224-
return NoOp.INSTANCE;
13225-
} else {
13226-
return !scalar && advice.getReturnType().isArray()
13227-
? new ForArray(advice.getReturnType(), exit, handlers.values())
13228-
: new ForScalar(advice.getReturnType(), exit, skipOnDefaultValue, handlers.values());
13229-
}
13238+
//if (handlers.isEmpty()) {
13239+
// return NoOp.INSTANCE;
13240+
//} else {
13241+
return !scalar && advice.getReturnType().isArray()
13242+
? new ForArray(advice.getReturnType(), exit, handlers.values())
13243+
: new ForScalar(advice.getReturnType(), exit, skipOnDefaultValue, handlers.values());
13244+
//}
1323013245
}
1323113246
}
1323213247
}

byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceAssignReturnedTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.bytebuddy.ByteBuddy;
44
import net.bytebuddy.dynamic.loading.ClassLoadingStrategy;
55
import net.bytebuddy.implementation.bytecode.assign.Assigner;
6+
import net.bytebuddy.test.utility.DebuggingWrapper;
67
import org.junit.Test;
78

89
import java.lang.reflect.InvocationTargetException;
@@ -295,6 +296,7 @@ public void testAssignReturnedToFieldStaticFromStatic() throws Exception {
295296
public void testAssignReturnedNoHandler() throws Exception {
296297
Class<?> type = new ByteBuddy()
297298
.redefine(Sample.class)
299+
.visit(DebuggingWrapper.makeDefault())
298300
.visit(Advice.withCustomMapping()
299301
.with(new Advice.AssignReturned.Factory())
300302
.to(ToNothing.class)
@@ -815,15 +817,15 @@ public static String enter(@Advice.FieldValue(BAR) String field) {
815817

816818
public static class ToNothing {
817819

818-
@Advice.OnMethodEnter
820+
@Advice.OnMethodEnter(suppress = Throwable.class)
819821
public static String enter(@Advice.Argument(0) String argument) {
820822
if (!FOO.equals(argument)) {
821823
throw new AssertionError();
822824
}
823825
return BAR;
824826
}
825827

826-
@Advice.OnMethodExit
828+
@Advice.OnMethodExit(suppress = Throwable.class, repeatOn = Object.class)
827829
public static String exit(@Advice.Argument(0) String argument) {
828830
if (!FOO.equals(argument)) {
829831
throw new AssertionError();

byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1493,7 +1493,8 @@ public Advice.PostProcessor make(final MethodDescription.InDefinedShape advice,
14931493
public StackManipulation resolve(TypeDescription instrumentedType,
14941494
MethodDescription instrumentedMethod,
14951495
Assigner assigner,
1496-
Advice.ArgumentHandler argumentHandler) {
1496+
Advice.ArgumentHandler argumentHandler,
1497+
Advice.StackMapFrameHandler stackMapFrameHandler) {
14971498
return new StackManipulation.Compound(
14981499
MethodVariableAccess.of(advice.getReturnType()).loadFrom(argumentHandler.enter()),
14991500
MethodVariableAccess.store(instrumentedMethod.getParameters().get(0))
@@ -1520,7 +1521,8 @@ public Advice.PostProcessor make(final MethodDescription.InDefinedShape advice,
15201521
public StackManipulation resolve(TypeDescription instrumentedType,
15211522
MethodDescription instrumentedMethod,
15221523
Assigner assigner,
1523-
Advice.ArgumentHandler argumentHandler) {
1524+
Advice.ArgumentHandler argumentHandler,
1525+
Advice.StackMapFrameHandler stackMapFrameHandler) {
15241526
return new StackManipulation.Compound(
15251527
MethodVariableAccess.of(advice.getReturnType()).loadFrom(argumentHandler.enter()),
15261528
MethodVariableAccess.store(instrumentedMethod.getParameters().get(0))

0 commit comments

Comments
 (0)