@@ -4887,16 +4887,17 @@ public interface PostProcessor {
4887
4887
/**
4888
4888
* Resolves this post processor for a given instrumented method.
4889
4889
*
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.
4894
4894
* @return The stack manipulation to apply.
4895
4895
*/
4896
4896
StackManipulation resolve(TypeDescription instrumentedType,
4897
4897
MethodDescription instrumentedMethod,
4898
4898
Assigner assigner,
4899
- ArgumentHandler argumentHandler);
4899
+ ArgumentHandler argumentHandler,
4900
+ StackMapFrameHandler stackMapFrameHandler);
4900
4901
4901
4902
/**
4902
4903
* A factory for creating a {@link PostProcessor}.
@@ -4977,7 +4978,8 @@ enum NoOp implements PostProcessor, Factory {
4977
4978
public StackManipulation resolve(TypeDescription instrumentedType,
4978
4979
MethodDescription instrumentedMethod,
4979
4980
Assigner assigner,
4980
- ArgumentHandler argumentHandler) {
4981
+ ArgumentHandler argumentHandler,
4982
+ StackMapFrameHandler stackMapFrameHandler) {
4981
4983
return StackManipulation.Trivial.INSTANCE;
4982
4984
}
4983
4985
@@ -5015,10 +5017,11 @@ protected Compound(List<PostProcessor> postProcessors) {
5015
5017
public StackManipulation resolve(TypeDescription instrumentedType,
5016
5018
MethodDescription instrumentedMethod,
5017
5019
Assigner assigner,
5018
- ArgumentHandler argumentHandler) {
5020
+ ArgumentHandler argumentHandler,
5021
+ StackMapFrameHandler stackMapFrameHandler) {
5019
5022
List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(postProcessors.size());
5020
5023
for (PostProcessor postProcessor : postProcessors) {
5021
- stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler));
5024
+ stackManipulations.add(postProcessor.resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler ));
5022
5025
}
5023
5026
return new StackManipulation.Compound(stackManipulations);
5024
5027
}
@@ -5597,7 +5600,7 @@ public void recordMaxima(int stackSize, int localVariableLength) {
5597
5600
/**
5598
5601
* A handler for computing and translating stack map frames.
5599
5602
*/
5600
- protected interface StackMapFrameHandler {
5603
+ public interface StackMapFrameHandler {
5601
5604
5602
5605
/**
5603
5606
* Translates a frame.
@@ -6740,6 +6743,7 @@ public void injectCompletionFrame(MethodVisitor methodVisitor) {
6740
6743
}
6741
6744
} else if (currentFrameDivergence < 3 && endTypes.isEmpty()) {
6742
6745
methodVisitor.visitFrame(Opcodes.F_CHOP, currentFrameDivergence, EMPTY, EMPTY.length, EMPTY);
6746
+ currentFrameDivergence = 0; // TODO: ?
6743
6747
} else {
6744
6748
injectFullFrame(methodVisitor, initialization, CompoundList.of(startTypes, endTypes), Collections.<TypeDescription>emptyList());
6745
6749
}
@@ -9199,7 +9203,7 @@ public void visitEnd() {
9199
9203
methodVisitor.visitVarInsn(Opcodes.ASTORE, exit ? argumentHandler.exit() : argumentHandler.enter());
9200
9204
}
9201
9205
methodSizeHandler.requireStackSize(postProcessor
9202
- .resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
9206
+ .resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler )
9203
9207
.apply(methodVisitor, implementationContext).getMaximalSize());
9204
9208
methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, exit ? argumentHandler.exit() : argumentHandler.enter()));
9205
9209
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
@@ -9553,7 +9557,7 @@ public void apply() {
9553
9557
methodVisitor.visitVarInsn(Opcodes.ASTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter());
9554
9558
}
9555
9559
methodSizeHandler.requireStackSize(postProcessor
9556
- .resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler)
9560
+ .resolve(instrumentedType, instrumentedMethod, assigner, argumentHandler, stackMapFrameHandler )
9557
9561
.apply(methodVisitor, implementationContext).getMaximalSize());
9558
9562
methodSizeHandler.requireStackSize(relocationHandler.apply(methodVisitor, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()));
9559
9563
stackMapFrameHandler.injectCompletionFrame(methodVisitor);
@@ -11687,7 +11691,8 @@ protected AssignReturned(TypeDescription.Generic type, boolean exit, boolean ski
11687
11691
public StackManipulation resolve(TypeDescription instrumentedType,
11688
11692
MethodDescription instrumentedMethod,
11689
11693
Assigner assigner,
11690
- ArgumentHandler argumentHandler) {
11694
+ ArgumentHandler argumentHandler,
11695
+ StackMapFrameHandler stackMapFrameHandler) {
11691
11696
List<StackManipulation> stackManipulations = new ArrayList<StackManipulation>(getHandlers().size());
11692
11697
for (Handler handler : getHandlers()) {
11693
11698
stackManipulations.add(handler.resolve(instrumentedType,
@@ -11697,9 +11702,10 @@ public StackManipulation resolve(TypeDescription instrumentedType,
11697
11702
getType(),
11698
11703
toLoadInstruction(handler, exit ? argumentHandler.exit() : argumentHandler.enter())));
11699
11704
}
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);
11703
11709
}
11704
11710
11705
11711
/**
@@ -12852,6 +12858,11 @@ protected static class DefaultValueSkip implements StackManipulation {
12852
12858
*/
12853
12859
private final StackManipulation stackManipulation;
12854
12860
12861
+ /**
12862
+ * The stack map frame handler to use.
12863
+ */
12864
+ private final StackMapFrameHandler stackMapFrameHandler;
12865
+
12855
12866
/**
12856
12867
* The offset of the value of the returned type.
12857
12868
*/
@@ -12866,24 +12877,27 @@ protected static class DefaultValueSkip implements StackManipulation {
12866
12877
* Creates a null-check wrapper.
12867
12878
*
12868
12879
* @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.
12869
12881
* @param offset The offset of the value of the returned type.
12870
12882
* @param dispatcher The dispatcher to use.
12871
12883
*/
12872
- protected DefaultValueSkip(StackManipulation stackManipulation, int offset, Dispatcher dispatcher) {
12884
+ protected DefaultValueSkip(StackManipulation stackManipulation, StackMapFrameHandler stackMapFrameHandler, int offset, Dispatcher dispatcher) {
12873
12885
this.stackManipulation = stackManipulation;
12886
+ this.stackMapFrameHandler = stackMapFrameHandler;
12874
12887
this.offset = offset;
12875
12888
this.dispatcher = dispatcher;
12876
12889
}
12877
12890
12878
12891
/**
12879
12892
* Resolves a skipping stack manipulation for the supplied type.
12880
12893
*
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.
12884
12898
* @return A suitable stack manipulation.
12885
12899
*/
12886
- protected static StackManipulation of(StackManipulation stackManipulation, int offset, TypeDefinition typeDefinition) {
12900
+ protected static StackManipulation of(StackManipulation stackManipulation, StackMapFrameHandler stackMapFrameHandler, int offset, TypeDefinition typeDefinition) {
12887
12901
Dispatcher dispatcher;
12888
12902
if (typeDefinition.isPrimitive()) {
12889
12903
if (typeDefinition.represents(boolean.class)
@@ -12904,7 +12918,7 @@ protected static StackManipulation of(StackManipulation stackManipulation, int o
12904
12918
} else {
12905
12919
dispatcher = Dispatcher.REFERENCE;
12906
12920
}
12907
- return new DefaultValueSkip(stackManipulation, offset, dispatcher);
12921
+ return new DefaultValueSkip(stackManipulation, stackMapFrameHandler, offset, dispatcher);
12908
12922
}
12909
12923
12910
12924
/**
@@ -12921,6 +12935,7 @@ public Size apply(MethodVisitor methodVisitor, Context implementationContext) {
12921
12935
Label label = new Label();
12922
12936
Size size = dispatcher.apply(methodVisitor, offset, label).aggregate(stackManipulation.apply(methodVisitor, implementationContext));
12923
12937
methodVisitor.visitLabel(label);
12938
+ stackMapFrameHandler.injectCompletionFrame(methodVisitor);
12924
12939
return size;
12925
12940
}
12926
12941
@@ -13220,13 +13235,13 @@ public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit)
13220
13235
}
13221
13236
}
13222
13237
}
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
+ // }
13230
13245
}
13231
13246
}
13232
13247
}
0 commit comments