From a785d247c772af9e282191cae23cbf61d909a7c0 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 09:31:59 +0100 Subject: [PATCH 01/19] Add test for erased bootstrap. --- .../main/java/net/bytebuddy/asm/Advice.java | 18 +++++----- .../precompiled/v7/AdviceBootstrapErased.java | 33 ++++++++++++++++++ .../java/net/bytebuddy/asm/AdviceTest.java | 31 ++++++++++++++++ .../v7/AdviceBootstrapErased.class | Bin 0 -> 1595 bytes 4 files changed, 73 insertions(+), 9 deletions(-) create mode 100644 byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java create mode 100644 byte-buddy-dep/src/test/precompiled-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.class diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 0b6f4779803..d6f7e49d1a4 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5909,16 +5909,16 @@ protected ForDefaultValues(MethodDescription.InDefinedShape adviceMethod, boolea */ public List resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod) { if (instrumentedMethod.isTypeInitializer()) { - return Arrays.asList(net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()), - net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(exit ? 1 : 0), - net.bytebuddy.utility.JavaConstant.Simple.of(instrumentedType), - net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(instrumentedMethod.getInternalName())); + return Arrays.asList(JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()), + JavaConstant.Simple.ofLoaded(exit ? 1 : 0), + JavaConstant.Simple.of(instrumentedType), + JavaConstant.Simple.ofLoaded(instrumentedMethod.getInternalName())); } else { - return Arrays.asList(net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()), - net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(exit ? 1 : 0), - net.bytebuddy.utility.JavaConstant.Simple.of(instrumentedType), - net.bytebuddy.utility.JavaConstant.Simple.ofLoaded(instrumentedMethod.getInternalName()), - net.bytebuddy.utility.JavaConstant.MethodHandle.of(instrumentedMethod.asDefined())); + return Arrays.asList(JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()), + JavaConstant.Simple.ofLoaded(exit ? 1 : 0), + JavaConstant.Simple.of(instrumentedType), + JavaConstant.Simple.ofLoaded(instrumentedMethod.getInternalName()), + JavaConstant.MethodHandle.of(instrumentedMethod.asDefined())); } } diff --git a/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java b/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java new file mode 100644 index 00000000000..46092205cd6 --- /dev/null +++ b/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java @@ -0,0 +1,33 @@ +/* + * Copyright 2014 - Present Rafael Winterhalter + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package net.bytebuddy.test.precompiled.v7; + +import java.lang.invoke.ConstantCallSite; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; + +public class AdviceBootstrapErased { + + public static ConstantCallSite bootstrap(MethodHandles.Lookup lookup, + String invokedMethodName, + MethodType erasedInvokedMethodType, + String invokedClassName, + String invokedMethodDescriptor) throws Exception { + return new ConstantCallSite(lookup.findStatic(Class.forName(invokedClassName, false, lookup.lookupClass().getClassLoader()), + invokedMethodName, + MethodType.fromMethodDescriptorString(invokedMethodDescriptor, lookup.lookupClass().getClassLoader()))); + } +} \ No newline at end of file diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java index cf1c40a32b7..9a652bac132 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java @@ -21,6 +21,7 @@ import net.bytebuddy.pool.TypePool; import net.bytebuddy.test.packaging.AdviceTestHelper; import net.bytebuddy.test.utility.JavaVersionRule; +import net.bytebuddy.utility.JavaConstant; import net.bytebuddy.utility.JavaType; import org.junit.Rule; import org.junit.Test; @@ -272,6 +273,36 @@ public void testTrivialAdviceWithDelegationBootstrapped() throws Exception { assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1)); } + @Test + @JavaVersionRule.Enforce(value = 7, target = TrivialAdviceDelegation.class) + public void testErasedAdviceWithDelegationBootstrapped() throws Exception { + Class bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.AdviceBootstrapErased"); + Class type = new ByteBuddy() + .redefine(TrivialAdviceDelegation.class) + .visit(Advice.withCustomMapping().bootstrap(bootstrap.getMethod("bootstrap", + JavaType.METHOD_HANDLES_LOOKUP.load(), + String.class, + JavaType.METHOD_TYPE.load(), + String.class, + String.class), new Advice.BootstrapArgumentResolver.Factory() { + public Advice.BootstrapArgumentResolver resolve(final MethodDescription.InDefinedShape adviceMethod, boolean exit) { + return new Advice.BootstrapArgumentResolver() { + public List resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod) { + return Arrays.asList( + JavaConstant.Simple.ofLoaded(adviceMethod.getName()), + JavaConstant.Simple.ofLoaded(adviceMethod.getDescriptor())); + } + }; + } + }, TypeDescription.Generic.Visitor.Generalizing.INSTANCE).to(TrivialAdviceDelegation.class).on(named(FOO))) + .make() + .load(bootstrap.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST) + .getLoaded(); + assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO)); + assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1)); + assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1)); + } + @Test public void testTrivialAdviceWithSuppression() throws Exception { Class type = new ByteBuddy() diff --git a/byte-buddy-dep/src/test/precompiled-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.class b/byte-buddy-dep/src/test/precompiled-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.class new file mode 100644 index 0000000000000000000000000000000000000000..f48686e011f987b22f35132c88d81c3d74bb5a04 GIT binary patch literal 1595 zcmbVM+fvg|6kVq+jfBWmtu2CpR7w$|f+7~YRUDY9_)vx!eM^%A1k$9FoOa~NPw^M@ z1st961NJwJYa{SIIm&t%BBC1F;^7>Y7(W6obnGUieC zZ3{9|xFcav!V*Jv-Ly^dgdts;-($#B9fLCr)l8f3w3`j??rIH-ETc6?*Q`CwHT`pB z%!otNV_2)%T&Rr`!5eMEI8g=ngxYes?lfDb#SOKysy;V5rp{kDj_`!5wKiSN<3@#{ zzwz57;VzX^bDZOLi$U48ZSGbr&GR@>d@R+Dw2r1)nth;}cE>s9>T50z9b-$g4U2oT zVPYi_Ru`^mA0#d35_eBpJn8HXk1X>E%m|_C*q+dAQPnJ~ZVFC9vQ||2Tz7cSN*P8% zG$VBHXw9I{vCfE}A;*JuZ3nueaKC(piHpbrbqvE1MbOBQA$N}TCHHjKYzfC@kT>7! zyd_K$C*dBQ>rUI%`74?sL!svcm;7oK3_xL+jw=r-)W6%L;69cmtSESZhYD8lNWz+e z$EYY+$A*tXH*xhpZxgAFD|pj5;<}LVl%W_~qq=&{gJCR=`_l-9fpD%t11YAIybXbo zWPU0%2Xq^m5 zRze`;aGiVvi98AcaS`LVL7Bd7f^2?nk+KTN;3n-e6g5TuY1*eSL#QC7beT!p736;b D7~sZf literal 0 HcmV?d00001 From c2874ea512ef8545e7929d98f651c78f3f1c33e8 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 09:36:40 +0100 Subject: [PATCH 02/19] Add basic test. --- byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java index 9a652bac132..b3ae4242635 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java @@ -289,7 +289,7 @@ public Advice.BootstrapArgumentResolver resolve(final MethodDescription.InDefine return new Advice.BootstrapArgumentResolver() { public List resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod) { return Arrays.asList( - JavaConstant.Simple.ofLoaded(adviceMethod.getName()), + JavaConstant.Simple.ofLoaded(adviceMethod.getDeclaringType().getName()), JavaConstant.Simple.ofLoaded(adviceMethod.getDescriptor())); } }; From 58d3a65164a7c51879107cd080cd10780803d588 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 09:43:24 +0100 Subject: [PATCH 03/19] Create test that fails for erasure. --- .../precompiled/v7/AdviceBootstrapErased.java | 4 +- .../java/net/bytebuddy/asm/AdviceTest.java | 36 ++++++++++++++++-- .../v7/AdviceBootstrapErased.class | Bin 1595 -> 1719 bytes 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java b/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java index 46092205cd6..852616b1f73 100644 --- a/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java +++ b/byte-buddy-dep/src/test/java-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.java @@ -23,11 +23,11 @@ public class AdviceBootstrapErased { public static ConstantCallSite bootstrap(MethodHandles.Lookup lookup, String invokedMethodName, - MethodType erasedInvokedMethodType, + MethodType erasedMethodType, String invokedClassName, String invokedMethodDescriptor) throws Exception { return new ConstantCallSite(lookup.findStatic(Class.forName(invokedClassName, false, lookup.lookupClass().getClassLoader()), invokedMethodName, - MethodType.fromMethodDescriptorString(invokedMethodDescriptor, lookup.lookupClass().getClassLoader()))); + MethodType.fromMethodDescriptorString(invokedMethodDescriptor, lookup.lookupClass().getClassLoader())).asType(erasedMethodType)); } } \ No newline at end of file diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java index b3ae4242635..6532bf57174 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java @@ -274,11 +274,11 @@ public void testTrivialAdviceWithDelegationBootstrapped() throws Exception { } @Test - @JavaVersionRule.Enforce(value = 7, target = TrivialAdviceDelegation.class) + @JavaVersionRule.Enforce(value = 7, target = TypedAdviceDelegation.class) public void testErasedAdviceWithDelegationBootstrapped() throws Exception { Class bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.AdviceBootstrapErased"); Class type = new ByteBuddy() - .redefine(TrivialAdviceDelegation.class) + .redefine(TypedAdviceDelegation.class) .visit(Advice.withCustomMapping().bootstrap(bootstrap.getMethod("bootstrap", JavaType.METHOD_HANDLES_LOOKUP.load(), String.class, @@ -294,11 +294,11 @@ public List resolve(TypeDescription instrumentedType, MethodDescri } }; } - }, TypeDescription.Generic.Visitor.Generalizing.INSTANCE).to(TrivialAdviceDelegation.class).on(named(FOO))) + }, TypeDescription.Generic.Visitor.Generalizing.INSTANCE).to(TypedAdviceDelegation.class).on(named(FOO))) .make() .load(bootstrap.getClassLoader(), ClassLoadingStrategy.Default.CHILD_FIRST) .getLoaded(); - assertThat(type.getDeclaredMethod(FOO).invoke(type.getDeclaredConstructor().newInstance()), is((Object) FOO)); + assertThat(type.getDeclaredMethod(FOO, String.class).invoke(type.getDeclaredConstructor().newInstance(), FOO), is((Object) FOO)); assertThat(type.getDeclaredField(ENTER).get(null), is((Object) 1)); assertThat(type.getDeclaredField(EXIT).get(null), is((Object) 1)); } @@ -2498,6 +2498,34 @@ private static void exit() { } } + + @SuppressWarnings("unused") + public static class TypedAdviceDelegation { + + public static int enter, exit; + + public String foo(String argument) { + return argument; + } + + @Advice.OnMethodEnter(inline = false) + private static String enter(@Advice.Argument(0) String argument) { + if (!FOO.equals(argument)) { + throw new AssertionError(); + } + enter++; + return BAR; + } + + @Advice.OnMethodExit(inline = false, onThrowable = Exception.class) + private static void exit(@Advice.Enter String enter) { + if (!BAR.equals(enter)) { + throw new AssertionError(); + } + exit++; + } + } + @SuppressWarnings("unused") public static class EmptyMethod { diff --git a/byte-buddy-dep/src/test/precompiled-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.class b/byte-buddy-dep/src/test/precompiled-7/net/bytebuddy/test/precompiled/v7/AdviceBootstrapErased.class index f48686e011f987b22f35132c88d81c3d74bb5a04..5e4fcad74d9b36ce34c1d7a34b1b19eaa0fc2bc6 100644 GIT binary patch delta 428 zcmXAj%Ps?96vuzxOvmW>O3_w}mKN1ktFA5TetQ71w6Tz|6J6O5Yl)=h1w4XAq6uPW z;}vXdy#&rozs31q&N=_{z3Nt|_WAqr4$QOf(8ajTghPa^!z4Mc#I%D! z*=ELOwo$oL^UaUAvce}9$94BdovH=*z$luUkb7ffON&%&s+uL1H7nF?RyAv^Yc|-l z+0tyYqtWats*S6vYnsu(o?_zON;dvFpSH|5rII4FqT{%JczJ%JSZ{nM+^}J}UxBkD z@6+BhP!bc8+AXRqs06J-3)S@7JyJV-Ge%grZV%8)pQs@H3`mH#e2a}Gn0Ftn^mXx> z&KAK(F$}zrnBPniWrP$-GJ-ilFLa^3NSuTyiC~Z+|4^P`nK67XC7$WC5n%yFg$HCR UE&YsegE6@Rj(B#2IXRX12Xaj@I{*Lx delta 369 zcmXAl%PvDv6o$XOdpUZ#TXpRPy>W^vMXN4F&BTZYFp+2?5hNrACVc~moEOm;G$HW- zop=d}w-9R|d+@Kd{`LQV_TGcUhiMIe-#>u{M=mb&4ht?5crFzdEiAb#Q?=ZRi>BtV z>ah0Gepc)KVMdvB_x|FcdwFvEcz5mps4KPMpXpjCj`4fCQr@KD&@^n(GHkQsuxr?( zZP@3)5a-bU(xqfxRpf(e=GQkB$5b%5#z>!e^bAk&OWZ>1t2 z#hBC><4jA4HTQ6Y2hUGMOHTtvUS-hOfFvQoJW~_}^FdJaUrd^e?8HWvToCRt!>l+h hHz%C+dg96vrXYP-R7KgBq}P-s6?u)4&#N;@_78{VCfxu4 From 92318a3ef71b9136e0250f479ddb8ea81c731452 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 09:55:25 +0100 Subject: [PATCH 04/19] Retain array structure on erasure. --- .../description/type/TypeDescription.java | 26 ++++++++++++++----- ...ionGenericVisitorTypeGeneralizingTest.java | 23 +++++++++++----- 2 files changed, 37 insertions(+), 12 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java index e6884137920..ae5d65d9285 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/description/type/TypeDescription.java @@ -793,7 +793,8 @@ public Generic onNonGenericType(Generic typeDescription) { } /** - * A visitor that generalizes all reference types to {@link Object} but retains primitive types. + * A visitor that generalizes all reference types to {@link Object} but retains primitive types. Arrays + * are retained as such. */ enum Generalizing implements Visitor { @@ -805,8 +806,14 @@ enum Generalizing implements Visitor { /** * {@inheritDoc} */ + @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Assuming component type for array type.") public Generic onGenericArray(Generic genericArray) { - return Sort.describe(Object.class); + int arity = 0; + do { + arity++; + genericArray = genericArray.getComponentType(); + } while (genericArray.isArray()); + return ArrayProjection.of(TypeDescription.ForLoadedType.of(Object.class), arity).asGenericType(); } /** @@ -820,23 +827,30 @@ public Generic onWildcard(Generic wildcard) { * {@inheritDoc} */ public Generic onParameterizedType(Generic parameterizedType) { - return Sort.describe(Object.class); + return TypeDescription.ForLoadedType.of(Object.class).asGenericType(); } /** * {@inheritDoc} */ public Generic onTypeVariable(Generic typeVariable) { - return Sort.describe(Object.class); + return TypeDescription.ForLoadedType.of(Object.class).asGenericType(); } /** * {@inheritDoc} */ + @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Assuming component type for array type.") public Generic onNonGenericType(Generic typeDescription) { - return typeDescription.isPrimitive() + int arity = 0; + Generic componentType = typeDescription; + while (componentType.isArray()) { + arity++; + componentType = componentType.getComponentType(); + } + return componentType.isPrimitive() ? typeDescription - : Sort.describe(Object.class); + : ArrayProjection.of(TypeDescription.ForLoadedType.of(Object.class), arity).asGenericType(); } } diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorTypeGeneralizingTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorTypeGeneralizingTest.java index 98282e58fa7..ff38dae0f74 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorTypeGeneralizingTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/description/type/TypeDescriptionGenericVisitorTypeGeneralizingTest.java @@ -17,17 +17,14 @@ public class TypeDescriptionGenericVisitorTypeGeneralizingTest { public MethodRule mockitoRule = MockitoJUnit.rule().silent(); @Mock - private TypeDescription.Generic typeDescription, rawType; + private TypeDescription.Generic typeDescription, componentType; - @Before - public void setUp() throws Exception { - when(typeDescription.asRawType()).thenReturn(rawType); - } @Test public void testGenericArray() throws Exception { + when(typeDescription.getComponentType()).thenReturn(componentType); assertThat(TypeDescription.Generic.Visitor.Generalizing.INSTANCE.onGenericArray(typeDescription), - is(TypeDefinition.Sort.describe(Object.class))); + is(TypeDefinition.Sort.describe(Object[].class))); } @Test(expected = IllegalArgumentException.class) @@ -53,9 +50,23 @@ public void testNonGeneric() throws Exception { is(TypeDefinition.Sort.describe(Object.class))); } + @Test + public void testNonGenericArray() throws Exception { + when(typeDescription.isArray()).thenReturn(true); + when(typeDescription.getComponentType()).thenReturn(componentType); + assertThat(TypeDescription.Generic.Visitor.Generalizing.INSTANCE.onNonGenericType(typeDescription), + is(TypeDefinition.Sort.describe(Object[].class))); + } + @Test public void testNonGenericPrimitive() throws Exception { assertThat(TypeDescription.Generic.Visitor.Generalizing.INSTANCE.onNonGenericType(TypeDefinition.Sort.describe(int.class)), is(TypeDefinition.Sort.describe(int.class))); } + + @Test + public void testNonGenericPrimitiveArray() throws Exception { + assertThat(TypeDescription.Generic.Visitor.Generalizing.INSTANCE.onNonGenericType(TypeDefinition.Sort.describe(int[].class)), + is(TypeDefinition.Sort.describe(int[].class))); + } } From 70833d43648674dab4192523a1732e773cb000b6 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 10:31:31 +0100 Subject: [PATCH 05/19] Improve erasure mechanism. --- .../main/java/net/bytebuddy/asm/Advice.java | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index d6f7e49d1a4..ddf44408ff7 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -6729,7 +6729,7 @@ protected static ForInstrumentedMethod of(TypeDescription instrumentedType, * {@inheritDoc} */ public StackMapFrameHandler.ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod, initialTypes, latentTypes, preMethodTypes, TranslationMode.ENTER, instrumentedMethod.isConstructor() + return new ForAdvice(adviceMethod.asTypeToken(), initialTypes, latentTypes, preMethodTypes, TranslationMode.ENTER, instrumentedMethod.isConstructor() ? Initialization.UNITIALIZED : Initialization.INITIALIZED); } @@ -6748,7 +6748,7 @@ public int getReaderHint() { * * @param methodVisitor The method visitor to write the frame to. * @param translationMode The translation mode to apply. - * @param methodDescription The method description for which the frame is written. + * @param typeToken A type token for the method description for which the frame is written. * @param additionalTypes The additional types to consider part of the instrumented method's parameters. * @param type The frame's type. * @param localVariableLength The local variable length. @@ -6758,7 +6758,8 @@ public int getReaderHint() { */ protected void translateFrame(MethodVisitor methodVisitor, TranslationMode translationMode, - MethodDescription methodDescription, + boolean isStatic, + MethodDescription.TypeToken typeToken, List additionalTypes, int type, int localVariableLength, @@ -6775,41 +6776,41 @@ protected void translateFrame(MethodVisitor methodVisitor, case Opcodes.F_CHOP: currentFrameDivergence -= localVariableLength; if (currentFrameDivergence < 0) { - throw new IllegalStateException(methodDescription + " dropped " + Math.abs(currentFrameDivergence) + " implicit frames"); + throw new IllegalStateException(typeToken + " dropped " + Math.abs(currentFrameDivergence) + " implicit frames"); } break; case Opcodes.F_FULL: case Opcodes.F_NEW: - if (methodDescription.getParameters().size() + (methodDescription.isStatic() ? 0 : 1) > localVariableLength) { - throw new IllegalStateException("Inconsistent frame length for " + methodDescription + ": " + localVariableLength); + if (typeToken.getParameterTypes().size() + (isStatic ? 0 : 1) > localVariableLength) { + throw new IllegalStateException("Inconsistent frame length for " + typeToken + ": " + localVariableLength); } int offset; - if (methodDescription.isStatic()) { + if (isStatic) { offset = 0; } else { if (!translationMode.isPossibleThisFrameValue(instrumentedType, instrumentedMethod, localVariable[0])) { - throw new IllegalStateException(methodDescription + " is inconsistent for 'this' reference: " + localVariable[0]); + throw new IllegalStateException(typeToken + " is inconsistent for 'this' reference: " + localVariable[0]); } offset = 1; } - for (int index = 0; index < methodDescription.getParameters().size(); index++) { - if (!Initialization.INITIALIZED.toFrame(methodDescription.getParameters().get(index).getType().asErasure()).equals(localVariable[index + offset])) { - throw new IllegalStateException(methodDescription + " is inconsistent at " + index + ": " + localVariable[index + offset]); + for (int index = 0; index < typeToken.getParameterTypes().size(); index++) { + if (!Initialization.INITIALIZED.toFrame(typeToken.getParameterTypes().get(index)).equals(localVariable[index + offset])) { + throw new IllegalStateException(typeToken + " is inconsistent at " + index + ": " + localVariable[index + offset]); } } Object[] translated = new Object[localVariableLength - - (methodDescription.isStatic() ? 0 : 1) - - methodDescription.getParameters().size() + - (isStatic ? 0 : 1) + - typeToken.getParameterTypes().size() + (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() + additionalTypes.size()]; - int index = translationMode.copy(instrumentedType, instrumentedMethod, methodDescription, localVariable, translated); + int index = translationMode.copy(instrumentedType, instrumentedMethod, typeToken, localVariable, translated); for (TypeDescription typeDescription : additionalTypes) { translated[index++] = Initialization.INITIALIZED.toFrame(typeDescription); } if (translated.length != index) { System.arraycopy(localVariable, - methodDescription.getParameters().size() + (methodDescription.isStatic() ? 0 : 1), + typeToken.getParameterTypes().size() + (isStatic ? 0 : 1), translated, index, translated.length - index); @@ -6870,7 +6871,7 @@ protected enum TranslationMode { @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription methodDescription, + MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int length = instrumentedMethod.getParameters().size() + (instrumentedMethod.isStatic() ? 0 : 1); @@ -6891,7 +6892,7 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription methodDescription, + MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int index = 0; @@ -6921,7 +6922,7 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription methodDescription, + MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int index = 0; @@ -6945,14 +6946,14 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met * * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. - * @param methodDescription The method for which a frame is created. + * @param typeToken The method for which a frame is created. * @param localVariable The original local variable array. * @param translated The array containing the translated frames. * @return The amount of frames added to the translated frame array. */ protected abstract int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription methodDescription, + MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated); @@ -7145,7 +7146,8 @@ protected WithPreservedArguments(TypeDescription instrumentedType, @SuppressFBWarnings(value = "RC_REF_COMPARISON_BAD_PRACTICE", justification = "ASM models frames by reference identity.") protected void translateFrame(MethodVisitor methodVisitor, TranslationMode translationMode, - MethodDescription methodDescription, + boolean isStatic, + MethodDescription.TypeToken typeToken, List additionalTypes, int type, int localVariableLength, @@ -7155,14 +7157,14 @@ protected void translateFrame(MethodVisitor methodVisitor, if (type == Opcodes.F_FULL && localVariableLength > 0 && localVariable[0] != Opcodes.UNINITIALIZED_THIS) { allowCompactCompletionFrame = true; } - super.translateFrame(methodVisitor, translationMode, methodDescription, additionalTypes, type, localVariableLength, localVariable, stackSize, stack); + super.translateFrame(methodVisitor, translationMode, isStatic, typeToken, additionalTypes, type, localVariableLength, localVariable, stackSize, stack); } /** * {@inheritDoc} */ public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod, + return new ForAdvice(adviceMethod.asTypeToken(), CompoundList.of(initialTypes, preMethodTypes, postMethodTypes), Collections.emptyList(), Collections.emptyList(), @@ -7315,8 +7317,9 @@ public void translateFrame(MethodVisitor methodVisitor, int stackSize, @MaybeNull Object[] stack) { translateFrame(methodVisitor, - TranslationMode.COPY, - instrumentedMethod, + TranslationMode.COPY, // TODO: needs token? + instrumentedMethod.isStatic(), + instrumentedMethod.asTypeToken(), CompoundList.of(initialTypes, preMethodTypes), type, localVariableLength, @@ -7476,9 +7479,9 @@ public void translateFrame(MethodVisitor methodVisitor, protected class ForAdvice implements StackMapFrameHandler.ForAdvice { /** - * The method description for which frames are translated. + * A token for the method description for which frames are translated. */ - protected final MethodDescription.InDefinedShape adviceMethod; + protected final MethodDescription.TypeToken typeToken; /** * The types provided before execution of the advice code. @@ -7511,9 +7514,9 @@ protected class ForAdvice implements StackMapFrameHandler.ForAdvice { private boolean intermedate; /** - * Creates a new meta data handler for an advice method. + * Creates a new metadata handler for an advice method. * - * @param adviceMethod The method description for which frames are translated. + * @param typeToken A token for the method description for which frames are translated. * @param startTypes The types provided before execution of the advice code. * @param intermediateTypes The types that are given post execution of the advice. * @param endTypes The types provided after execution of the advice code. @@ -7521,13 +7524,13 @@ protected class ForAdvice implements StackMapFrameHandler.ForAdvice { * either {@link TranslationMode#ENTER} or {@link TranslationMode#EXIT}. * @param initialization The initialization to apply when resolving a reference to the instance on which a non-static method is invoked. */ - protected ForAdvice(MethodDescription.InDefinedShape adviceMethod, + protected ForAdvice(MethodDescription.TypeToken typeToken, List startTypes, List intermediateTypes, List endTypes, TranslationMode translationMode, Initialization initialization) { - this.adviceMethod = adviceMethod; + this.typeToken = typeToken; this.startTypes = startTypes; this.intermediateTypes = intermediateTypes; this.endTypes = endTypes; @@ -7547,7 +7550,8 @@ public void translateFrame(MethodVisitor methodVisitor, @MaybeNull Object[] stack) { Default.this.translateFrame(methodVisitor, translationMode, - adviceMethod, + true, + typeToken, startTypes, type, localVariableLength, @@ -7561,19 +7565,19 @@ public void translateFrame(MethodVisitor methodVisitor, */ public void injectReturnFrame(MethodVisitor methodVisitor) { if (!expandFrames && currentFrameDivergence == 0) { - if (adviceMethod.getReturnType().represents(void.class)) { + if (typeToken.getReturnType().represents(void.class)) { methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY); } else { methodVisitor.visitFrame(Opcodes.F_SAME1, EMPTY.length, EMPTY, 1, - new Object[]{Initialization.INITIALIZED.toFrame(adviceMethod.getReturnType().asErasure())}); + new Object[]{Initialization.INITIALIZED.toFrame(typeToken.getReturnType())}); } } else { - injectFullFrame(methodVisitor, initialization, startTypes, adviceMethod.getReturnType().represents(void.class) + injectFullFrame(methodVisitor, initialization, startTypes, typeToken.getReturnType().represents(void.class) ? Collections.emptyList() - : Collections.singletonList(adviceMethod.getReturnType().asErasure())); + : Collections.singletonList(typeToken.getReturnType())); } } From 2a40e1e8d7eebb29b57b4f0cfb0be4437e6644fe Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 10:41:35 +0100 Subject: [PATCH 06/19] Refactor towards erasure. --- .../main/java/net/bytebuddy/asm/Advice.java | 52 +++++++++---------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index ddf44408ff7..6b67f64ca93 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -6450,20 +6450,20 @@ interface ForPostProcessor { interface ForInstrumentedMethod extends StackMapFrameHandler { /** - * Binds this meta data handler for the enter advice. + * Binds this metadata handler for the enter advice. * - * @param adviceMethod The enter advice method. - * @return An appropriate meta data handler for the enter method. + * @param typeToken The type token representing the advice method. + * @return An appropriate metadata handler for the enter method. */ - ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod); + ForAdvice bindEnter(MethodDescription.TypeToken typeToken); /** - * Binds this meta data handler for the exit advice. + * Binds this metadata handler for the exit advice. * - * @param adviceMethod The exit advice method. - * @return An appropriate meta data handler for the enter method. + * @param typeToken The type token representing the advice method. + * @return An appropriate metadata handler for the enter method. */ - ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod); + ForAdvice bindExit(MethodDescription.TypeToken typeToken); /** * Returns a hint to supply to a {@link ClassReader} when parsing an advice method. @@ -6514,14 +6514,14 @@ enum NoOp implements ForInstrumentedMethod, ForAdvice { /** * {@inheritDoc} */ - public StackMapFrameHandler.ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindEnter(MethodDescription.TypeToken typeToken) { return this; } /** * {@inheritDoc} */ - public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { + public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.TypeToken typeToken) { return this; } @@ -6728,8 +6728,8 @@ protected static ForInstrumentedMethod of(TypeDescription instrumentedType, /** * {@inheritDoc} */ - public StackMapFrameHandler.ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod.asTypeToken(), initialTypes, latentTypes, preMethodTypes, TranslationMode.ENTER, instrumentedMethod.isConstructor() + public StackMapFrameHandler.ForAdvice bindEnter(MethodDescription.TypeToken typeToken) { + return new ForAdvice(typeToken, initialTypes, latentTypes, preMethodTypes, TranslationMode.ENTER, instrumentedMethod.isConstructor() ? Initialization.UNITIALIZED : Initialization.INITIALIZED); } @@ -7061,8 +7061,8 @@ public void translateFrame(MethodVisitor methodVisitor, /** * {@inheritDoc} */ - public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { - throw new IllegalStateException("Did not expect exit advice " + adviceMethod + " for " + instrumentedMethod); + public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.TypeToken typeToken) { + throw new IllegalStateException("Did not expect exit advice " + typeToken + " for " + instrumentedMethod); } /** @@ -7163,8 +7163,8 @@ protected void translateFrame(MethodVisitor methodVisitor, /** * {@inheritDoc} */ - public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod.asTypeToken(), + public StackMapFrameHandler.ForAdvice bindExit(MethodDescription.TypeToken typeToken) { + return new ForAdvice(typeToken, CompoundList.of(initialTypes, preMethodTypes, postMethodTypes), Collections.emptyList(), Collections.emptyList(), @@ -7511,7 +7511,7 @@ protected class ForAdvice implements StackMapFrameHandler.ForAdvice { /** * {@code true} if an intermediate frame was yielded. */ - private boolean intermedate; + private boolean intermediate; /** * Creates a new metadata handler for an advice method. @@ -7536,7 +7536,7 @@ protected ForAdvice(MethodDescription.TypeToken typeToken, this.endTypes = endTypes; this.translationMode = translationMode; this.initialization = initialization; - intermedate = false; + intermediate = false; } /** @@ -7598,8 +7598,8 @@ public void injectExceptionFrame(MethodVisitor methodVisitor) { public void injectCompletionFrame(MethodVisitor methodVisitor) { if (expandFrames) { injectFullFrame(methodVisitor, initialization, CompoundList.of(startTypes, endTypes), Collections.emptyList()); - } else if (currentFrameDivergence == 0 && (intermedate || endTypes.size() < 4)) { - if (intermedate || endTypes.isEmpty()) { + } else if (currentFrameDivergence == 0 && (intermediate || endTypes.size() < 4)) { + if (intermediate || endTypes.isEmpty()) { methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY); } else { Object[] local = new Object[endTypes.size()]; @@ -7623,7 +7623,7 @@ public void injectCompletionFrame(MethodVisitor methodVisitor) { public void injectIntermediateFrame(MethodVisitor methodVisitor, List stack) { if (expandFrames) { injectFullFrame(methodVisitor, initialization, CompoundList.of(startTypes, intermediateTypes), stack); - } else if (intermedate && stack.size() < 2) { + } else if (intermediate && stack.size() < 2) { if (stack.isEmpty()) { methodVisitor.visitFrame(Opcodes.F_SAME, EMPTY.length, EMPTY, EMPTY.length, EMPTY); } else { @@ -7652,7 +7652,7 @@ public void injectIntermediateFrame(MethodVisitor methodVisitor, List Date: Fri, 17 Jan 2025 10:59:58 +0100 Subject: [PATCH 07/19] More refactoring. --- .../main/java/net/bytebuddy/asm/Advice.java | 78 ++++++++++++------- .../java/net/bytebuddy/asm/AdviceTest.java | 2 + 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 6b67f64ca93..a6397581670 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -4924,19 +4924,19 @@ interface ForInstrumentedMethod extends ArgumentHandler { /** * Binds an advice method as enter advice for this handler. * - * @param adviceMethod The resolved enter advice handler. + * @param typeToken The type token of the advice method. * @return The resolved argument handler for enter advice. */ - ForAdvice bindEnter(MethodDescription adviceMethod); + ForAdvice bindEnter(MethodDescription.TypeToken typeToken); /** * Binds an advice method as exit advice for this handler. * - * @param adviceMethod The resolved exit advice handler. + * @param typeToken The type token of the advice method. * @param skipThrowable {@code true} if no throwable is stored. * @return The resolved argument handler for enter advice. */ - ForAdvice bindExit(MethodDescription adviceMethod, boolean skipThrowable); + ForAdvice bindExit(MethodDescription.TypeToken typeToken, boolean skipThrowable); /** * Returns {@code true} if the original arguments are copied before invoking the instrumented method. @@ -5044,16 +5044,16 @@ public int thrown() { /** * {@inheritDoc} */ - public ForAdvice bindEnter(MethodDescription adviceMethod) { - return new ForAdvice.Default.ForMethodEnter(instrumentedMethod, adviceMethod, exitType, namedTypes); + public ForAdvice bindEnter(MethodDescription.TypeToken typeToken) { + return new ForAdvice.Default.ForMethodEnter(instrumentedMethod, typeToken, exitType, namedTypes); } /** * {@inheritDoc} */ - public ForAdvice bindExit(MethodDescription adviceMethod, boolean skipThrowable) { + public ForAdvice bindExit(MethodDescription.TypeToken typeToken, boolean skipThrowable) { return new ForAdvice.Default.ForMethodExit(instrumentedMethod, - adviceMethod, + typeToken, exitType, namedTypes, enterType, @@ -5210,9 +5210,9 @@ abstract class Default implements ForAdvice { protected final MethodDescription instrumentedMethod; /** - * The advice method. + * The type token of the advice method. */ - protected final MethodDescription adviceMethod; + protected final MethodDescription.TypeToken typeToken; /** * The enter type or {@code void} if no enter type is defined. @@ -5228,16 +5228,16 @@ abstract class Default implements ForAdvice { * Creates a new argument handler for an enter advice. * * @param instrumentedMethod The instrumented method. - * @param adviceMethod The advice method. + * @param typeToken The type token of the advice method. * @param exitType The exit type or {@code void} if no exit type is defined. * @param namedTypes A mapping of all available local variables by their name to their type. */ protected Default(MethodDescription instrumentedMethod, - MethodDescription adviceMethod, + MethodDescription.TypeToken typeToken, TypeDefinition exitType, SortedMap namedTypes) { this.instrumentedMethod = instrumentedMethod; - this.adviceMethod = adviceMethod; + this.typeToken = typeToken; this.exitType = exitType; this.namedTypes = namedTypes; } @@ -5284,15 +5284,15 @@ protected static class ForMethodEnter extends Default { * Creates a new argument handler for an enter advice method. * * @param instrumentedMethod The instrumented method. - * @param adviceMethod The advice method. + * @param typeToken The type token of the advice method. * @param exitType The exit type or {@code void} if no exit type is defined. * @param namedTypes A mapping of all available local variables by their name to their type. */ protected ForMethodEnter(MethodDescription instrumentedMethod, - MethodDescription adviceMethod, + MethodDescription.TypeToken typeToken, TypeDefinition exitType, SortedMap namedTypes) { - super(instrumentedMethod, adviceMethod, exitType, namedTypes); + super(instrumentedMethod, typeToken, exitType, namedTypes); } /** @@ -5316,7 +5316,7 @@ public int mapped(int offset) { return instrumentedMethod.getStackSize() + exitType.getStackSize().getSize() + StackSize.of(namedTypes.values()) - - adviceMethod.getStackSize() + offset; + - StackSize.of(typeToken.getParameterTypes()) + offset; } } @@ -5340,19 +5340,19 @@ protected static class ForMethodExit extends Default { * Creates a new argument handler for an exit advice method. * * @param instrumentedMethod The instrumented method. - * @param adviceMethod The advice method. + * @param typeToken The type token of the advice method. * @param exitType The exit type or {@code void} if no exit type is defined. * @param namedTypes A mapping of all available local variables by their name to their type. * @param enterType The enter type or {@code void} if no enter type is defined. * @param throwableSize The stack size of a possibly stored throwable. */ protected ForMethodExit(MethodDescription instrumentedMethod, - MethodDescription adviceMethod, + MethodDescription.TypeToken typeToken, TypeDefinition exitType, SortedMap namedTypes, TypeDefinition enterType, StackSize throwableSize) { - super(instrumentedMethod, adviceMethod, exitType, namedTypes); + super(instrumentedMethod, typeToken, exitType, namedTypes); this.enterType = enterType; this.throwableSize = throwableSize; } @@ -5388,7 +5388,7 @@ public int mapped(int offset) { + enterType.getStackSize().getSize() + instrumentedMethod.getReturnType().getStackSize().getSize() + throwableSize.getSize() - - adviceMethod.getStackSize() + - StackSize.of(typeToken.getParameterTypes()) + offset; } } @@ -5636,6 +5636,8 @@ protected interface Delegator { */ StackManipulation apply(TypeDescription instrumentedType, MethodDescription instrumentedMethod); + TypeDescription.Generic.Visitor getVisitor(); + /** * A factory for creating a {@link Delegator}. */ @@ -5678,6 +5680,13 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti return MethodInvocation.invoke(adviceMethod); } + /** + * {@inheritDoc} + */ + public TypeDescription.Generic.Visitor getVisitor() { + return TypeDescription.Generic.Visitor.NoOp.INSTANCE; + } + /** * A factory for a regular method invocation delegator. */ @@ -5784,6 +5793,13 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti constants); } + /** + * {@inheritDoc} + */ + public TypeDescription.Generic.Visitor getVisitor() { + return visitor; + } + /** * A factory for creating a dynamic invocation dispatcher. */ @@ -6946,7 +6962,7 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met * * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. - * @param typeToken The method for which a frame is created. + * @param typeToken The method for which a frame is created. * @param localVariable The original local variable array. * @param translated The array containing the translated frames. * @return The amount of frames added to the translated frame array. @@ -9580,7 +9596,7 @@ protected MethodVisitor apply(MethodVisitor methodVisitor, return doApply(methodVisitor, implementationContext, assigner, - argumentHandler.bindEnter(adviceMethod), + argumentHandler.bindEnter(adviceMethod.asTypeToken()), methodSizeHandler.bindEnter(adviceMethod), stackMapFrameHandler.bindEnter(adviceMethod.asTypeToken()), instrumentedType, @@ -9860,7 +9876,7 @@ protected MethodVisitor apply(MethodVisitor methodVisitor, return doApply(methodVisitor, implementationContext, assigner, - argumentHandler.bindExit(adviceMethod, getThrowable().represents(NoExceptionHandler.class)), + argumentHandler.bindExit(adviceMethod.asTypeToken(), getThrowable().represents(NoExceptionHandler.class)), methodSizeHandler.bindExit(adviceMethod), stackMapFrameHandler.bindExit(adviceMethod.asTypeToken()), instrumentedType, @@ -11003,14 +11019,17 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { + MethodDescription.TypeToken typeToken = new MethodDescription.TypeToken( + adviceMethod.getReturnType().accept(delegator.getVisitor()).asErasure(), + adviceMethod.getParameters().asTypeList().accept(delegator.getVisitor()).asErasures()); // TODO: retain initial? return doResolve(instrumentedType, instrumentedMethod, methodVisitor, implementationContext, assigner, - argumentHandler.bindEnter(adviceMethod), + argumentHandler.bindEnter(typeToken), methodSizeHandler.bindEnter(adviceMethod), - stackMapFrameHandler.bindEnter(adviceMethod.asTypeToken()), // TODO: visitor + stackMapFrameHandler.bindEnter(typeToken), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), exceptionHandler); @@ -11249,14 +11268,17 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { + MethodDescription.TypeToken typeToken = new MethodDescription.TypeToken( + adviceMethod.getReturnType().accept(delegator.getVisitor()).asErasure(), + adviceMethod.getParameters().asTypeList().accept(delegator.getVisitor()).asErasures()); return doResolve(instrumentedType, instrumentedMethod, methodVisitor, implementationContext, assigner, - argumentHandler.bindExit(adviceMethod, getThrowable().represents(NoExceptionHandler.class)), + argumentHandler.bindExit(typeToken, getThrowable().represents(NoExceptionHandler.class)), methodSizeHandler.bindExit(adviceMethod), - stackMapFrameHandler.bindExit(adviceMethod.asTypeToken()), + stackMapFrameHandler.bindExit(typeToken), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), exceptionHandler); diff --git a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java index 6532bf57174..72733d73638 100644 --- a/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java +++ b/byte-buddy-dep/src/test/java/net/bytebuddy/asm/AdviceTest.java @@ -20,6 +20,7 @@ import net.bytebuddy.matcher.ElementMatchers; import net.bytebuddy.pool.TypePool; import net.bytebuddy.test.packaging.AdviceTestHelper; +import net.bytebuddy.test.utility.DebuggingWrapper; import net.bytebuddy.test.utility.JavaVersionRule; import net.bytebuddy.utility.JavaConstant; import net.bytebuddy.utility.JavaType; @@ -279,6 +280,7 @@ public void testErasedAdviceWithDelegationBootstrapped() throws Exception { Class bootstrap = Class.forName("net.bytebuddy.test.precompiled.v7.AdviceBootstrapErased"); Class type = new ByteBuddy() .redefine(TypedAdviceDelegation.class) + .visit(DebuggingWrapper.makeDefault()) .visit(Advice.withCustomMapping().bootstrap(bootstrap.getMethod("bootstrap", JavaType.METHOD_HANDLES_LOOKUP.load(), String.class, From 0af6d38ce930dbcff502da81586839c68869b27e Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 11:05:37 +0100 Subject: [PATCH 08/19] Fix type token. --- .../src/main/java/net/bytebuddy/asm/Advice.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index a6397581670..8ba65bb14f0 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -10416,8 +10416,8 @@ public boolean isBinary() { /** * {@inheritDoc} */ - public TypeDescription getAdviceType() { - return adviceMethod.getReturnType().asErasure(); + public TypeDefinition getAdviceType() { + return adviceMethod.getReturnType(); } /** @@ -11113,7 +11113,7 @@ protected WithRetainedEnterType(MethodDescription.InDefinedShape adviceMethod, * {@inheritDoc} */ public TypeDefinition getAdviceType() { - return adviceMethod.getReturnType(); + return adviceMethod.getReturnType().accept(delegator.getVisitor()); // TODO: replace method with field? } } @@ -11349,7 +11349,7 @@ public ArgumentHandler.Factory getArgumentHandlerFactory() { * {@inheritDoc} */ public TypeDefinition getAdviceType() { - return adviceMethod.getReturnType(); + return adviceMethod.getReturnType().accept(delegator.getVisitor()); } /** From 25cf22eb633db61be87418759fd7c736825f7cbd Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 11:12:13 +0100 Subject: [PATCH 09/19] Refactor last support API to use of type token. --- .../main/java/net/bytebuddy/asm/Advice.java | 54 ++++++++++--------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 8ba65bb14f0..b25a7c79cd8 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5340,7 +5340,7 @@ protected static class ForMethodExit extends Default { * Creates a new argument handler for an exit advice method. * * @param instrumentedMethod The instrumented method. - * @param typeToken The type token of the advice method. + * @param typeToken The type token of the advice method. * @param exitType The exit type or {@code void} if no exit type is defined. * @param namedTypes A mapping of all available local variables by their name to their type. * @param enterType The enter type or {@code void} if no enter type is defined. @@ -5990,18 +5990,18 @@ interface ForInstrumentedMethod extends MethodSizeHandler { /** * Binds a method size handler for the enter advice. * - * @param adviceMethod The method representing the enter advice. + * @param typeToken The type token representing the enter advice. * @return A method size handler for the enter advice. */ - ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod); + ForAdvice bindEnter(MethodDescription.TypeToken typeToken); /** * Binds the method size handler for the exit advice. * - * @param adviceMethod The method representing the exit advice. + * @param typeToken The type token representing the exit advice. * @return A method size handler for the exit advice. */ - ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod); + ForAdvice bindExit(MethodDescription.TypeToken typeToken); /** * Computes a compound stack size for the advice and the translated instrumented method. @@ -6062,14 +6062,14 @@ enum NoOp implements ForInstrumentedMethod, ForAdvice { /** * {@inheritDoc} */ - public ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod) { + public ForAdvice bindEnter(MethodDescription.TypeToken typeToken) { return this; } /** * {@inheritDoc} */ - public ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { + public ForAdvice bindExit(MethodDescription.TypeToken typeToken) { return this; } @@ -6205,8 +6205,8 @@ protected static MethodSizeHandler.ForInstrumentedMethod of(MethodDescription in /** * {@inheritDoc} */ - public MethodSizeHandler.ForAdvice bindEnter(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod, instrumentedMethod.getStackSize() + StackSize.of(initialTypes)); + public MethodSizeHandler.ForAdvice bindEnter(MethodDescription.TypeToken typeToken) { + return new ForAdvice(typeToken, instrumentedMethod.getStackSize() + StackSize.of(initialTypes)); } /** @@ -6263,8 +6263,8 @@ protected WithRetainedArguments(MethodDescription instrumentedMethod, /** * {@inheritDoc} */ - public MethodSizeHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod, instrumentedMethod.getStackSize() + public MethodSizeHandler.ForAdvice bindExit(MethodDescription.TypeToken typeToken) { + return new ForAdvice(typeToken, instrumentedMethod.getStackSize() + StackSize.of(postMethodTypes) + StackSize.of(initialTypes) + StackSize.of(preMethodTypes)); @@ -6304,8 +6304,8 @@ protected WithCopiedArguments(MethodDescription instrumentedMethod, /** * {@inheritDoc} */ - public MethodSizeHandler.ForAdvice bindExit(MethodDescription.InDefinedShape adviceMethod) { - return new ForAdvice(adviceMethod, 2 * instrumentedMethod.getStackSize() + public MethodSizeHandler.ForAdvice bindExit(MethodDescription.TypeToken typeToken) { + return new ForAdvice(typeToken, 2 * instrumentedMethod.getStackSize() + StackSize.of(initialTypes) + StackSize.of(preMethodTypes) + StackSize.of(postMethodTypes)); @@ -6331,7 +6331,7 @@ protected class ForAdvice implements MethodSizeHandler.ForAdvice { /** * The advice method. */ - private final MethodDescription.InDefinedShape adviceMethod; + private final MethodDescription.TypeToken typeToken; /** * The base of the local variable length that is implied by the method instrumentation prior to applying this advice method. @@ -6351,12 +6351,12 @@ protected class ForAdvice implements MethodSizeHandler.ForAdvice { /** * Creates a default method size handler for an advice method. * - * @param adviceMethod The advice method. + * @param typeToken The type token representing the advice. * @param baseLocalVariableLength The base of the local variable length that is implied by the method instrumentation * prior to applying this advice method. */ - protected ForAdvice(MethodDescription.InDefinedShape adviceMethod, int baseLocalVariableLength) { - this.adviceMethod = adviceMethod; + protected ForAdvice(MethodDescription.TypeToken typeToken, int baseLocalVariableLength) { + this.typeToken = typeToken; this.baseLocalVariableLength = baseLocalVariableLength; } @@ -6394,7 +6394,7 @@ public void requireLocalVariableLengthPadding(int localVariableLengthPadding) { public void recordMaxima(int stackSize, int localVariableLength) { Default.this.requireStackSize(stackSize + stackSizePadding); Default.this.requireLocalVariableLength(localVariableLength - - adviceMethod.getStackSize() + - StackSize.of(typeToken.getParameterTypes()) + baseLocalVariableLength + localVariableLengthPadding); } @@ -9593,12 +9593,13 @@ protected MethodVisitor apply(MethodVisitor methodVisitor, SuppressionHandler.Bound suppressionHandler, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler) { + MethodDescription.TypeToken typeToken = adviceMethod.asTypeToken(); return doApply(methodVisitor, implementationContext, assigner, - argumentHandler.bindEnter(adviceMethod.asTypeToken()), - methodSizeHandler.bindEnter(adviceMethod), - stackMapFrameHandler.bindEnter(adviceMethod.asTypeToken()), + argumentHandler.bindEnter(typeToken), + methodSizeHandler.bindEnter(typeToken), + stackMapFrameHandler.bindEnter(typeToken), instrumentedType, instrumentedMethod, suppressionHandler, @@ -9873,12 +9874,13 @@ protected MethodVisitor apply(MethodVisitor methodVisitor, SuppressionHandler.Bound suppressionHandler, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler) { + MethodDescription.TypeToken typeToken = adviceMethod.asTypeToken(); return doApply(methodVisitor, implementationContext, assigner, - argumentHandler.bindExit(adviceMethod.asTypeToken(), getThrowable().represents(NoExceptionHandler.class)), - methodSizeHandler.bindExit(adviceMethod), - stackMapFrameHandler.bindExit(adviceMethod.asTypeToken()), + argumentHandler.bindExit(typeToken, getThrowable().represents(NoExceptionHandler.class)), + methodSizeHandler.bindExit(typeToken), + stackMapFrameHandler.bindExit(typeToken), instrumentedType, instrumentedMethod, suppressionHandler, @@ -11028,7 +11030,7 @@ protected Bound resolve(TypeDescription instrumentedType, implementationContext, assigner, argumentHandler.bindEnter(typeToken), - methodSizeHandler.bindEnter(adviceMethod), + methodSizeHandler.bindEnter(typeToken), stackMapFrameHandler.bindEnter(typeToken), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), @@ -11277,7 +11279,7 @@ protected Bound resolve(TypeDescription instrumentedType, implementationContext, assigner, argumentHandler.bindExit(typeToken, getThrowable().represents(NoExceptionHandler.class)), - methodSizeHandler.bindExit(adviceMethod), + methodSizeHandler.bindExit(typeToken), stackMapFrameHandler.bindExit(typeToken), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), From 5dcb6ee00c9398d80ab4c50c22cd72c4f09dab58 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 12:02:56 +0100 Subject: [PATCH 10/19] More refactoring. --- .../main/java/net/bytebuddy/asm/Advice.java | 134 ++++++++---------- 1 file changed, 60 insertions(+), 74 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index b25a7c79cd8..e62c968b99a 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5636,7 +5636,12 @@ protected interface Delegator { */ StackManipulation apply(TypeDescription instrumentedType, MethodDescription instrumentedMethod); - TypeDescription.Generic.Visitor getVisitor(); + /** + * Returns the advice method's type token. + * + * @return The advice method's type token. + */ + MethodDescription.TypeToken toTypeToken(); /** * A factory for creating a {@link Delegator}. @@ -5683,8 +5688,8 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti /** * {@inheritDoc} */ - public TypeDescription.Generic.Visitor getVisitor() { - return TypeDescription.Generic.Visitor.NoOp.INSTANCE; + public MethodDescription.TypeToken toTypeToken() { + return adviceMethod.asTypeToken(); } /** @@ -5720,42 +5725,26 @@ class ForDynamicInvocation implements Delegator { /** * The advice method. */ - private final MethodDescription.InDefinedShape adviceMethod; + private final MethodDescription.SignatureToken signatureToken; /** * A resolver to provide the arguments to the bootstrap method. */ private final BootstrapArgumentResolver resolver; - /** - * A visitor to apply to the parameter types prior to resolving the {@code MethodType} that - * is passed to the bootstrap method. The supplied types might not be available to the - * instrumented type what might make it necessary to camouflage them to avoid class loading - * errors. The actual type should then rather be passed in a different format by the - * supplied {@link BootstrapArgumentResolver}. - */ - private final TypeDescription.Generic.Visitor visitor; - /** * Creates a delegator for a dynamic method invocation. * * @param bootstrapMethod The bootstrap method. - * @param adviceMethod The advice method. + * @param signatureToken The advice method's signature token. * @param resolver A resolver to provide the arguments to the bootstrap method. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link BootstrapArgumentResolver}. */ protected ForDynamicInvocation(MethodDescription.InDefinedShape bootstrapMethod, - MethodDescription.InDefinedShape adviceMethod, - BootstrapArgumentResolver resolver, - TypeDescription.Generic.Visitor visitor) { + MethodDescription.SignatureToken signatureToken, + BootstrapArgumentResolver resolver) { this.bootstrapMethod = bootstrapMethod; - this.adviceMethod = adviceMethod; + this.signatureToken = signatureToken; this.resolver = resolver; - this.visitor = visitor; } /** @@ -5787,17 +5776,17 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti if (!bootstrapMethod.isInvokeBootstrap(TypeList.Explicit.of(constants))) { throw new IllegalStateException("Cannot invoke " + bootstrapMethod + " with arguments: " + constants); } - return MethodInvocation.invoke(bootstrapMethod).dynamic(adviceMethod.getInternalName(), - adviceMethod.getReturnType().accept(visitor).asErasure(), - adviceMethod.getParameters().asTypeList().accept(visitor).asErasures(), + return MethodInvocation.invoke(bootstrapMethod).dynamic(signatureToken.getName(), + signatureToken.getReturnType(), + signatureToken.getParameterTypes(), constants); } /** * {@inheritDoc} */ - public TypeDescription.Generic.Visitor getVisitor() { - return visitor; + public MethodDescription.TypeToken toTypeToken() { + return signatureToken.asTypeToken(); } /** @@ -5849,9 +5838,10 @@ protected Factory(MethodDescription.InDefinedShape bootstrapMethod, */ public Delegator make(MethodDescription.InDefinedShape adviceMethod, boolean exit) { return new ForDynamicInvocation(bootstrapMethod, - adviceMethod, - resolverFactory.resolve(adviceMethod, exit), - visitor); + new MethodDescription.SignatureToken(adviceMethod.getInternalName(), + adviceMethod.getReturnType().accept(visitor).asErasure(), + adviceMethod.getParameters().asTypeList().accept(visitor).asErasures()), + resolverFactory.resolve(adviceMethod, exit)); } } } @@ -8782,7 +8772,7 @@ protected AbstractBase(MethodDescription.InDefinedShape adviceMethod, : offsetMapping); } suppressionHandler = SuppressionHandler.Suppressing.of(throwableType); - relocationHandler = RelocationHandler.ForType.of(relocatableType, relocatableIndex, adviceMethod.getReturnType()); + relocationHandler = RelocationHandler.ForType.of(relocatableType, relocatableIndex, adviceMethod.getReturnType()); // TODO } /** @@ -10579,7 +10569,7 @@ protected abstract static class AdviceMethodWriter implements Bound { /** * The advice method. */ - protected final MethodDescription.InDefinedShape adviceMethod; + protected final MethodDescription.TypeToken typeToken; /** * The instrumented type. @@ -10654,7 +10644,7 @@ protected abstract static class AdviceMethodWriter implements Bound { /** * Creates a new advice method writer. * - * @param adviceMethod The advice method. + * @param typeToken The advice method's type token. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. * @param assigner The assigner to use. @@ -10670,7 +10660,7 @@ protected abstract static class AdviceMethodWriter implements Bound { * @param exceptionHandler The exception handler that is resolved for the instrumented method. * @param delegator The delegator to use. */ - protected AdviceMethodWriter(MethodDescription.InDefinedShape adviceMethod, + protected AdviceMethodWriter(MethodDescription.TypeToken typeToken, TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, @@ -10685,7 +10675,7 @@ protected AdviceMethodWriter(MethodDescription.InDefinedShape adviceMethod, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler, Delegator delegator) { - this.adviceMethod = adviceMethod; + this.typeToken = typeToken; this.instrumentedType = instrumentedType; this.instrumentedMethod = instrumentedMethod; this.assigner = assigner; @@ -10716,7 +10706,7 @@ public void apply() { suppressionHandler.onStart(methodVisitor); int index = 0, currentStackSize = 0, maximumStackSize = 0; for (OffsetMapping.Target offsetMapping : offsetMappings) { - currentStackSize += adviceMethod.getParameters().get(index++).getType().getStackSize().getSize(); + currentStackSize += typeToken.getParameterTypes().get(index++).getStackSize().getSize(); maximumStackSize = Math.max(maximumStackSize, currentStackSize + offsetMapping.resolveRead() .apply(methodVisitor, implementationContext) .getMaximalSize()); @@ -10728,20 +10718,20 @@ public void apply() { implementationContext, methodSizeHandler, stackMapFrameHandler, - adviceMethod.getReturnType()); - if (adviceMethod.getReturnType().represents(boolean.class) - || adviceMethod.getReturnType().represents(byte.class) - || adviceMethod.getReturnType().represents(short.class) - || adviceMethod.getReturnType().represents(char.class) - || adviceMethod.getReturnType().represents(int.class)) { + typeToken.getReturnType()); + if (typeToken.getReturnType().represents(boolean.class) + || typeToken.getReturnType().represents(byte.class) + || typeToken.getReturnType().represents(short.class) + || typeToken.getReturnType().represents(char.class) + || typeToken.getReturnType().represents(int.class)) { methodVisitor.visitVarInsn(Opcodes.ISTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()); - } else if (adviceMethod.getReturnType().represents(long.class)) { + } else if (typeToken.getReturnType().represents(long.class)) { methodVisitor.visitVarInsn(Opcodes.LSTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()); - } else if (adviceMethod.getReturnType().represents(float.class)) { + } else if (typeToken.getReturnType().represents(float.class)) { methodVisitor.visitVarInsn(Opcodes.FSTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()); - } else if (adviceMethod.getReturnType().represents(double.class)) { + } else if (typeToken.getReturnType().represents(double.class)) { methodVisitor.visitVarInsn(Opcodes.DSTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()); - } else if (adviceMethod.getReturnType().represents(void.class)) { + } else if (typeToken.getReturnType().represents(void.class)) { methodVisitor.visitInsn(Opcodes.NOP); } else { methodVisitor.visitVarInsn(Opcodes.ASTORE, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter()); @@ -10753,8 +10743,8 @@ public void apply() { implementationContext, isExitAdvice() ? argumentHandler.exit() : argumentHandler.enter())); stackMapFrameHandler.injectCompletionFrame(methodVisitor); - methodSizeHandler.requireStackSize(Math.max(maximumStackSize, adviceMethod.getReturnType().getStackSize().getSize())); - methodSizeHandler.requireLocalVariableLength(instrumentedMethod.getStackSize() + adviceMethod.getReturnType().getStackSize().getSize()); + methodSizeHandler.requireStackSize(Math.max(maximumStackSize, typeToken.getReturnType().getStackSize().getSize())); + methodSizeHandler.requireLocalVariableLength(instrumentedMethod.getStackSize() + typeToken.getReturnType().getStackSize().getSize()); } /** @@ -10772,7 +10762,7 @@ protected static class ForMethodEnter extends AdviceMethodWriter { /** * Creates a new advice method writer. * - * @param adviceMethod The advice method. + * @param typeToken The advice method's type token. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. * @param assigner The assigner to use. @@ -10788,7 +10778,7 @@ protected static class ForMethodEnter extends AdviceMethodWriter { * @param exceptionHandler The exception handler that is resolved for the instrumented method. * @param delegator The delegator to use. */ - protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, + protected ForMethodEnter(MethodDescription.TypeToken typeToken, TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, @@ -10803,7 +10793,7 @@ protected ForMethodEnter(MethodDescription.InDefinedShape adviceMethod, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler, Delegator delegator) { - super(adviceMethod, + super(typeToken, instrumentedType, instrumentedMethod, assigner, @@ -10857,7 +10847,7 @@ protected static class ForMethodExit extends AdviceMethodWriter { * @param exceptionHandler The exception handler that is resolved for the instrumented method. * @param delegator The delegator to use. */ - protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, + protected ForMethodExit(MethodDescription.TypeToken typeToken, TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, @@ -10872,7 +10862,7 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler, Delegator delegator) { - super(adviceMethod, + super(typeToken, instrumentedType, instrumentedMethod, assigner, @@ -10893,27 +10883,27 @@ protected ForMethodExit(MethodDescription.InDefinedShape adviceMethod, * {@inheritDoc} */ public void initialize() { - if (adviceMethod.getReturnType().represents(boolean.class) - || adviceMethod.getReturnType().represents(byte.class) - || adviceMethod.getReturnType().represents(short.class) - || adviceMethod.getReturnType().represents(char.class) - || adviceMethod.getReturnType().represents(int.class)) { + if (typeToken.getReturnType().represents(boolean.class) + || typeToken.getReturnType().represents(byte.class) + || typeToken.getReturnType().represents(short.class) + || typeToken.getReturnType().represents(char.class) + || typeToken.getReturnType().represents(int.class)) { methodVisitor.visitInsn(Opcodes.ICONST_0); methodVisitor.visitVarInsn(Opcodes.ISTORE, argumentHandler.exit()); - } else if (adviceMethod.getReturnType().represents(long.class)) { + } else if (typeToken.getReturnType().represents(long.class)) { methodVisitor.visitInsn(Opcodes.LCONST_0); methodVisitor.visitVarInsn(Opcodes.LSTORE, argumentHandler.exit()); - } else if (adviceMethod.getReturnType().represents(float.class)) { + } else if (typeToken.getReturnType().represents(float.class)) { methodVisitor.visitInsn(Opcodes.FCONST_0); methodVisitor.visitVarInsn(Opcodes.FSTORE, argumentHandler.exit()); - } else if (adviceMethod.getReturnType().represents(double.class)) { + } else if (typeToken.getReturnType().represents(double.class)) { methodVisitor.visitInsn(Opcodes.DCONST_0); methodVisitor.visitVarInsn(Opcodes.DSTORE, argumentHandler.exit()); - } else if (!adviceMethod.getReturnType().represents(void.class)) { + } else if (!typeToken.getReturnType().represents(void.class)) { methodVisitor.visitInsn(Opcodes.ACONST_NULL); methodVisitor.visitVarInsn(Opcodes.ASTORE, argumentHandler.exit()); } - methodSizeHandler.requireStackSize(adviceMethod.getReturnType().getStackSize().getSize()); + methodSizeHandler.requireStackSize(typeToken.getReturnType().getStackSize().getSize()); } @Override @@ -11008,7 +10998,7 @@ public boolean isPrependLineNumber() { */ public TypeDefinition getActualAdviceType() { return adviceMethod.getReturnType(); - } + } // TODO: rework? @Override protected Bound resolve(TypeDescription instrumentedType, @@ -11021,9 +11011,7 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { - MethodDescription.TypeToken typeToken = new MethodDescription.TypeToken( - adviceMethod.getReturnType().accept(delegator.getVisitor()).asErasure(), - adviceMethod.getParameters().asTypeList().accept(delegator.getVisitor()).asErasures()); // TODO: retain initial? + MethodDescription.TypeToken typeToken = delegator.toTypeToken(); return doResolve(instrumentedType, instrumentedMethod, methodVisitor, @@ -11115,7 +11103,7 @@ protected WithRetainedEnterType(MethodDescription.InDefinedShape adviceMethod, * {@inheritDoc} */ public TypeDefinition getAdviceType() { - return adviceMethod.getReturnType().accept(delegator.getVisitor()); // TODO: replace method with field? + return delegator.toTypeToken().getReturnType(); } } @@ -11270,9 +11258,7 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { - MethodDescription.TypeToken typeToken = new MethodDescription.TypeToken( - adviceMethod.getReturnType().accept(delegator.getVisitor()).asErasure(), - adviceMethod.getParameters().asTypeList().accept(delegator.getVisitor()).asErasures()); + MethodDescription.TypeToken typeToken = delegator.toTypeToken(); return doResolve(instrumentedType, instrumentedMethod, methodVisitor, @@ -11351,7 +11337,7 @@ public ArgumentHandler.Factory getArgumentHandlerFactory() { * {@inheritDoc} */ public TypeDefinition getAdviceType() { - return adviceMethod.getReturnType().accept(delegator.getVisitor()); + return delegator.toTypeToken().getReturnType(); } /** From df47a45f62ebe6ab74d8e192445bc1045056a563 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 12:14:42 +0100 Subject: [PATCH 11/19] More refactoring. --- .../src/main/java/net/bytebuddy/asm/Advice.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index e62c968b99a..9ee910999e6 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -8772,7 +8772,7 @@ protected AbstractBase(MethodDescription.InDefinedShape adviceMethod, : offsetMapping); } suppressionHandler = SuppressionHandler.Suppressing.of(throwableType); - relocationHandler = RelocationHandler.ForType.of(relocatableType, relocatableIndex, adviceMethod.getReturnType()); // TODO + relocationHandler = RelocationHandler.ForType.of(relocatableType, relocatableIndex, adviceMethod.getReturnType()); } /** @@ -10831,7 +10831,7 @@ protected static class ForMethodExit extends AdviceMethodWriter { /** * Creates a new advice method writer. * - * @param adviceMethod The advice method. + * @param typeToken The advice method's type token. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. * @param assigner The assigner to use. @@ -10997,8 +10997,8 @@ public boolean isPrependLineNumber() { * {@inheritDoc} */ public TypeDefinition getActualAdviceType() { - return adviceMethod.getReturnType(); - } // TODO: rework? + return delegator.toTypeToken().getReturnType(); + } @Override protected Bound resolve(TypeDescription instrumentedType, @@ -11060,7 +11060,7 @@ protected Bound doResolve(TypeDescription instrumentedType, argumentHandler, OffsetMapping.Sort.ENTER)); } - return new AdviceMethodWriter.ForMethodEnter(adviceMethod, + return new AdviceMethodWriter.ForMethodEnter(delegator.toTypeToken(), instrumentedType, instrumentedMethod, assigner, @@ -11307,7 +11307,7 @@ private Bound doResolve(TypeDescription instrumentedType, argumentHandler, OffsetMapping.Sort.EXIT)); } - return new AdviceMethodWriter.ForMethodExit(adviceMethod, + return new AdviceMethodWriter.ForMethodExit(adviceMethod.asTypeToken(), instrumentedType, instrumentedMethod, assigner, From f1b87185c19d4ccc257d059e4be1afd93c31eb3d Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 12:20:36 +0100 Subject: [PATCH 12/19] Fix up checkstyle. --- .../src/main/java/net/bytebuddy/asm/Advice.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 9ee910999e6..1e8b4e4811a 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -6754,6 +6754,7 @@ public int getReaderHint() { * * @param methodVisitor The method visitor to write the frame to. * @param translationMode The translation mode to apply. + * @param isStatic {@code true} if the targeted type token represents a static method. * @param typeToken A type token for the method description for which the frame is written. * @param additionalTypes The additional types to consider part of the instrumented method's parameters. * @param type The frame's type. @@ -6810,7 +6811,7 @@ protected void translateFrame(MethodVisitor methodVisitor, + (instrumentedMethod.isStatic() ? 0 : 1) + instrumentedMethod.getParameters().size() + additionalTypes.size()]; - int index = translationMode.copy(instrumentedType, instrumentedMethod, typeToken, localVariable, translated); + int index = translationMode.copy(instrumentedType, instrumentedMethod, localVariable, translated); for (TypeDescription typeDescription : additionalTypes) { translated[index++] = Initialization.INITIALIZED.toFrame(typeDescription); } @@ -6877,7 +6878,6 @@ protected enum TranslationMode { @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int length = instrumentedMethod.getParameters().size() + (instrumentedMethod.isStatic() ? 0 : 1); @@ -6898,7 +6898,6 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int index = 0; @@ -6928,7 +6927,6 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met @Override protected int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated) { int index = 0; @@ -6952,14 +6950,12 @@ protected boolean isPossibleThisFrameValue(TypeDescription instrumentedType, Met * * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. - * @param typeToken The method for which a frame is created. * @param localVariable The original local variable array. * @param translated The array containing the translated frames. * @return The amount of frames added to the translated frame array. */ protected abstract int copy(TypeDescription instrumentedType, MethodDescription instrumentedMethod, - MethodDescription.TypeToken typeToken, Object[] localVariable, Object[] translated); @@ -7323,7 +7319,7 @@ public void translateFrame(MethodVisitor methodVisitor, int stackSize, @MaybeNull Object[] stack) { translateFrame(methodVisitor, - TranslationMode.COPY, // TODO: needs token? + TranslationMode.COPY, instrumentedMethod.isStatic(), instrumentedMethod.asTypeToken(), CompoundList.of(initialTypes, preMethodTypes), @@ -10831,7 +10827,7 @@ protected static class ForMethodExit extends AdviceMethodWriter { /** * Creates a new advice method writer. * - * @param typeToken The advice method's type token. + * @param typeToken The advice method's type token. * @param instrumentedType The instrumented type. * @param instrumentedMethod The instrumented method. * @param assigner The assigner to use. From 612fff5cf0bf75646afaee0c960234747f9b111d Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 12:40:14 +0100 Subject: [PATCH 13/19] More cleanup. --- .../main/java/net/bytebuddy/asm/Advice.java | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 1e8b4e4811a..f380a79e294 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5643,6 +5643,13 @@ protected interface Delegator { */ MethodDescription.TypeToken toTypeToken(); + /** + * Asserts the visibility of the delegation target. + * + * @param instrumentedType The instrumented type. + */ + void assertVisibility(TypeDescription instrumentedType); + /** * A factory for creating a {@link Delegator}. */ @@ -5692,6 +5699,15 @@ public MethodDescription.TypeToken toTypeToken() { return adviceMethod.asTypeToken(); } + /** + * {@inheritDoc} + */ + public void assertVisibility(TypeDescription instrumentedType) { + if (!adviceMethod.isVisibleTo(instrumentedType)) { + throw new IllegalStateException(adviceMethod + " is not visible to " + instrumentedType); + } + } + /** * A factory for a regular method invocation delegator. */ @@ -5789,6 +5805,15 @@ public MethodDescription.TypeToken toTypeToken() { return signatureToken.asTypeToken(); } + /** + * {@inheritDoc} + */ + public void assertVisibility(TypeDescription instrumentedType) { + if (!bootstrapMethod.isVisibleTo(instrumentedType)) { + throw new IllegalStateException(bootstrapMethod + " is not visible to " + instrumentedType); + } + } + /** * A factory for creating a dynamic invocation dispatcher. */ @@ -8697,11 +8722,6 @@ interface ForMethodExit extends Resolved { @HashCodeAndEqualsPlugin.Enhance abstract class AbstractBase implements Resolved { - /** - * The represented advice method. - */ - protected final MethodDescription.InDefinedShape adviceMethod; - /** * The post processor to apply. */ @@ -8740,7 +8760,6 @@ protected AbstractBase(MethodDescription.InDefinedShape adviceMethod, TypeDescription relocatableType, int relocatableIndex, OffsetMapping.Factory.AdviceType adviceType) { - this.adviceMethod = adviceMethod; this.postProcessor = postProcessor; Map> offsetMappings = new HashMap>(); for (OffsetMapping.Factory factory : factories) { @@ -9039,6 +9058,11 @@ public String toString() { */ protected abstract static class Resolved extends Dispatcher.Resolved.AbstractBase { + /** + * The represented advice method. + */ + protected final MethodDescription.InDefinedShape adviceMethod; + /** * A class reader to query for the class file of the advice method. */ @@ -9063,6 +9087,7 @@ protected Resolved(MethodDescription.InDefinedShape adviceMethod, int relocatableIndex, AsmClassReader classReader) { super(adviceMethod, postProcessor, factories, throwableType, relocatableType, relocatableIndex, OffsetMapping.Factory.AdviceType.INLINING); + this.adviceMethod = adviceMethod; this.classReader = classReader; } @@ -10515,9 +10540,7 @@ public Bound bind(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { - if (!adviceMethod.isVisibleTo(instrumentedType)) { - throw new IllegalStateException(adviceMethod + " is not visible to " + instrumentedMethod.getDeclaringType()); - } + delegator.assertVisibility(instrumentedType); return resolve(instrumentedType, instrumentedMethod, methodVisitor, @@ -11146,7 +11169,7 @@ protected Bound doResolve(TypeDescription instrumentedType, SuppressionHandler.Bound suppressionHandler, RelocationHandler.Bound relocationHandler, StackManipulation exceptionHandler) { - methodSizeHandler.requireLocalVariableLengthPadding(adviceMethod.getReturnType().getStackSize().getSize()); + methodSizeHandler.requireLocalVariableLengthPadding(delegator.toTypeToken().getReturnType().getStackSize().getSize()); return super.doResolve(instrumentedType, instrumentedMethod, methodVisitor, @@ -11303,7 +11326,7 @@ private Bound doResolve(TypeDescription instrumentedType, argumentHandler, OffsetMapping.Sort.EXIT)); } - return new AdviceMethodWriter.ForMethodExit(adviceMethod.asTypeToken(), + return new AdviceMethodWriter.ForMethodExit(delegator.toTypeToken(), instrumentedType, instrumentedMethod, assigner, From 3a92dd4c2b7cba14e6c51155a19a627683a6383f Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 12:44:03 +0100 Subject: [PATCH 14/19] Remove visitor from member substitution. --- .../net/bytebuddy/asm/MemberSubstitution.java | 113 ++---------------- 1 file changed, 10 insertions(+), 103 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/MemberSubstitution.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/MemberSubstitution.java index 154de9a230f..6b372dc8b40 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/MemberSubstitution.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/MemberSubstitution.java @@ -5657,35 +5657,19 @@ class ForDynamicInvocation implements Dispatcher { */ private final BootstrapArgumentResolver resolver; - /** - * A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. - */ - private final TypeDescription.Generic.Visitor visitor; - /** * Creates a dispatcher for a dynamic method invocation. * * @param bootstrapMethod The bootstrap method. * @param delegate The delegation method. * @param resolver A resolver for supplying arguments to the bootstrap method. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. */ protected ForDynamicInvocation(MethodDescription.InDefinedShape bootstrapMethod, MethodDescription.InDefinedShape delegate, - BootstrapArgumentResolver resolver, - TypeDescription.Generic.Visitor visitor) { + BootstrapArgumentResolver resolver) { this.bootstrapMethod = bootstrapMethod; this.delegate = delegate; this.resolver = resolver; - this.visitor = visitor; } /** @@ -5693,27 +5677,21 @@ protected ForDynamicInvocation(MethodDescription.InDefinedShape bootstrapMethod, * * @param bootstrapMethod The bootstrap method. * @param resolverFactory A resolver for supplying arguments to the bootstrap method. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. * @return An appropriate dispatcher factory. */ protected static Dispatcher.Factory of(MethodDescription.InDefinedShape bootstrapMethod, - BootstrapArgumentResolver.Factory resolverFactory, - TypeDescription.Generic.Visitor visitor) { + BootstrapArgumentResolver.Factory resolverFactory) { if (!bootstrapMethod.isInvokeBootstrap()) { throw new IllegalStateException("Not a bootstrap method: " + bootstrapMethod); } - return new ForDynamicInvocation.Factory(bootstrapMethod, resolverFactory, visitor); + return new ForDynamicInvocation.Factory(bootstrapMethod, resolverFactory); } /** * {@inheritDoc} */ public Dispatcher.Resolved resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod) { - return new ForDynamicInvocation.Resolved(bootstrapMethod, delegate, resolver.resolve(instrumentedType, instrumentedMethod), visitor); + return new ForDynamicInvocation.Resolved(bootstrapMethod, delegate, resolver.resolve(instrumentedType, instrumentedMethod)); } /** @@ -5737,37 +5715,19 @@ protected static class Resolved implements Dispatcher.Resolved { */ private final BootstrapArgumentResolver.Resolved resolver; - /** - * A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. - */ - private final TypeDescription.Generic.Visitor visitor; - /** * Creates a resolved dispatcher of a dynamic method dispatcher. * * @param bootstrapMethod The bootstrap method. * @param delegate The delegation target. * @param resolver The bootstrap argument resolver to use. - * @param visitor A visitor to apply to the parameter types prior to resolving - * the {@code MethodType} that is passed to the bootstrap method. - * The supplied types might not be available to the instrumented - * type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be - * passed in a different format by the supplied - * {@link Advice.BootstrapArgumentResolver}. */ protected Resolved(MethodDescription.InDefinedShape bootstrapMethod, MethodDescription.InDefinedShape delegate, - BootstrapArgumentResolver.Resolved resolver, - TypeDescription.Generic.Visitor visitor) { + BootstrapArgumentResolver.Resolved resolver) { this.bootstrapMethod = bootstrapMethod; this.delegate = delegate; this.resolver = resolver; - this.visitor = visitor; } /** @@ -5786,8 +5746,8 @@ public StackManipulation apply(TypeDescription receiver, ByteCodeElement.Member throw new IllegalArgumentException(bootstrapMethod + " is not accepting advice bootstrap arguments: " + constants); } return MethodInvocation.invoke(bootstrapMethod).dynamic(delegate.getInternalName(), - delegate.getReturnType().accept(visitor).asErasure(), - delegate.getParameters().asTypeList().accept(visitor).asErasures(), + delegate.getReturnType().asErasure(), + delegate.getParameters().asTypeList().asErasures(), constants); } } @@ -5808,40 +5768,23 @@ protected static class Factory implements Dispatcher.Factory { */ private final BootstrapArgumentResolver.Factory resolverFactory; - /** - * - * A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. - */ - private final TypeDescription.Generic.Visitor visitor; - /** * Creates a new factory for a dispatcher using a dynamic method invocation. * * @param bootstrapMethod The bootstrap method. * @param resolverFactory A factory for a bootstrap argument resolver. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. */ protected Factory(MethodDescription.InDefinedShape bootstrapMethod, - BootstrapArgumentResolver.Factory resolverFactory, - TypeDescription.Generic.Visitor visitor) { + BootstrapArgumentResolver.Factory resolverFactory) { this.bootstrapMethod = bootstrapMethod; this.resolverFactory = resolverFactory; - this.visitor = visitor; } /** * {@inheritDoc} */ public Dispatcher make(MethodDescription.InDefinedShape delegate) { - return new ForDynamicInvocation(bootstrapMethod, delegate, resolverFactory.make(delegate), visitor); + return new ForDynamicInvocation(bootstrapMethod, delegate, resolverFactory.make(delegate)); } } } @@ -6485,24 +6428,6 @@ public WithCustomMapping bootstrap(Method method, BootstrapArgumentResolver.Fact return bootstrap(new MethodDescription.ForLoadedMethod(method), resolverFactory); } - /** - * Defines the supplied method as a dynamic invocation bootstrap target for delegating advice methods. - * - * @param method The bootstrap method or constructor. - * @param resolverFactory A factory for resolving the arguments to the bootstrap method. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. - * @return A new builder for a delegation within a member substitution that uses the supplied method for bootstrapping. - */ - public WithCustomMapping bootstrap(Method method, - BootstrapArgumentResolver.Factory resolverFactory, - TypeDescription.Generic.Visitor visitor) { - return bootstrap(new MethodDescription.ForLoadedMethod(method), resolverFactory, visitor); - } - /** * Defines the supplied method description as a dynamic invocation bootstrap target for delegating advice methods. The bootstrap * method arguments are: @@ -6534,25 +6459,7 @@ public WithCustomMapping bootstrap(MethodDescription.InDefinedShape bootstrap) { * @return A new builder for a delegation within a member substitution that uses the supplied method or constructor for bootstrapping. */ public WithCustomMapping bootstrap(MethodDescription.InDefinedShape bootstrap, BootstrapArgumentResolver.Factory resolverFactory) { - return bootstrap(bootstrap, resolverFactory, TypeDescription.Generic.Visitor.NoOp.INSTANCE); - } - - /** - * Defines the supplied method description as a dynamic invocation bootstrap target for delegating advice methods. - * - * @param bootstrap The bootstrap method or constructor. - * @param resolverFactory A factory for resolving the arguments to the bootstrap method. - * @param visitor A visitor to apply to the parameter types prior to resolving the {@code MethodType} - * that is passed to the bootstrap method. The supplied types might not be available - * to the instrumented type what might make it necessary to camouflage them to avoid - * class loading errors. The actual type should then rather be passed in a different - * format by the supplied {@link Advice.BootstrapArgumentResolver}. - * @return A new builder for a delegation within a member substitution that uses the supplied method or constructor for bootstrapping. - */ - public WithCustomMapping bootstrap(MethodDescription.InDefinedShape bootstrap, - BootstrapArgumentResolver.Factory resolverFactory, - TypeDescription.Generic.Visitor visitor) { - return new WithCustomMapping(Dispatcher.ForDynamicInvocation.of(bootstrap, resolverFactory, visitor), offsetMappings); + return new WithCustomMapping(Dispatcher.ForDynamicInvocation.of(bootstrap, resolverFactory), offsetMappings); } /** From 2cfaaac62828a754015a949bbcd11298ac4a58f2 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 13:28:26 +0100 Subject: [PATCH 15/19] Clean up return handler. --- .../main/java/net/bytebuddy/asm/Advice.java | 160 +++++++++--------- 1 file changed, 81 insertions(+), 79 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index f380a79e294..e110e82fdf3 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5493,11 +5493,11 @@ interface Factory { /** * Creates a post processor for a given advice method. * - * @param advice The advice method to create the post processor for. - * @param exit {@code true} if the advice is exit advice. + * @param returnType The advice method's return type that is being post-processed. + * @param exit {@code true} if the advice is exit advice. * @return The created post processor. */ - PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit); + PostProcessor make(List annotations, TypeDescription returnType, boolean exit); /** * A compound factory for a post processor. @@ -5538,10 +5538,10 @@ public Compound(List factories) { /** * {@inheritDoc} */ - public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) { + public PostProcessor make(List annotations, TypeDescription returnType, boolean exit) { List postProcessors = new ArrayList(factories.size()); for (Factory factory : factories) { - postProcessors.add(factory.make(advice, exit)); + postProcessors.add(factory.make(annotations, returnType, exit)); } return new PostProcessor.Compound(postProcessors); } @@ -5573,7 +5573,7 @@ public StackManipulation resolve(TypeDescription instrumentedType, /** * {@inheritDoc} */ - public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) { + public PostProcessor make(List annotations, TypeDescription returnType, boolean exit) { return this; } } @@ -5641,7 +5641,7 @@ protected interface Delegator { * * @return The advice method's type token. */ - MethodDescription.TypeToken toTypeToken(); + MethodDescription.TypeToken getTypeToken(); /** * Asserts the visibility of the delegation target. @@ -5695,7 +5695,7 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti /** * {@inheritDoc} */ - public MethodDescription.TypeToken toTypeToken() { + public MethodDescription.TypeToken getTypeToken() { return adviceMethod.asTypeToken(); } @@ -5801,7 +5801,7 @@ public StackManipulation apply(TypeDescription instrumentedType, MethodDescripti /** * {@inheritDoc} */ - public MethodDescription.TypeToken toTypeToken() { + public MethodDescription.TypeToken getTypeToken() { return signatureToken.asTypeToken(); } @@ -9019,7 +9019,7 @@ public Dispatcher.Resolved.ForMethodEnter asMethodEnter(List getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { List handlers = new ArrayList(); for (AnnotationDescription argument : annotation.getValue(TO_ARGUMENTS_VALUE).resolve(AnnotationDescription[].class)) { int value = argument.getValue(TO_ARGUMENT_VALUE).resolve(Integer.class); if (value < 0) { - throw new IllegalStateException("An argument cannot have a negative index for " + advice); + throw new IllegalStateException("An argument cannot have a negative index for " + returnType); } handlers.add(new Handler(value, argument.getValue(TO_ARGUMENT_INDEX).resolve(Integer.class), @@ -13424,19 +13427,19 @@ public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value) { List stackManipulations = new ArrayList(instrumentedMethod.getParameters().size()); if (!type.isArray()) { - StackManipulation assignment = assigner.assign(type, TypeDefinition.Sort.describe(Object[].class), typing); + StackManipulation assignment = assigner.assign(type.asGenericType(), TypeDefinition.Sort.describe(Object[].class), typing); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + type + " to " + Object[].class); } - type = TypeDefinition.Sort.describe(Object[].class); + type = TypeDescription.ForLoadedType.of(Object[].class); value = new StackManipulation.Compound(value, assignment); } for (ParameterDescription parameterDescription : instrumentedMethod.getParameters()) { - StackManipulation assignment = assigner.assign(type.getComponentType(), parameterDescription.getType(), typing); + StackManipulation assignment = assigner.assign(type.getComponentType().asGenericType(), parameterDescription.getType(), typing); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + type.getComponentType() + " to " + parameterDescription); } @@ -13485,7 +13488,7 @@ public Class getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription typeDescription, boolean exit, AnnotationDescription.Loadable annotation) { return Collections.singletonList(new Handler(annotation.getValue(TO_ALL_ARGUMENTS_INDEX).resolve(Integer.class), @@ -13573,14 +13576,14 @@ public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value) { if (instrumentedMethod.isStatic()) { throw new IllegalStateException("Cannot assign this reference for static method " + instrumentedMethod); } else if (!exit && instrumentedMethod.isConstructor()) { throw new IllegalStateException("Cannot assign this reference in constructor prior to initialization for " + instrumentedMethod); } - StackManipulation assignment = assigner.assign(type, + StackManipulation assignment = assigner.assign(type.asGenericType(), instrumentedType.asGenericType(), typing); if (!assignment.isValid()) { @@ -13631,7 +13634,7 @@ public Class getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { return Collections.singletonList(new Handler(annotation.getValue(TO_THIS_INDEX).resolve(Integer.class), @@ -13768,7 +13771,7 @@ public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value) { FieldLocator locator = declaringType.represents(void.class) ? new FieldLocator.ForClassHierarchy(instrumentedType) @@ -13790,7 +13793,7 @@ public StackManipulation resolve(TypeDescription instrumentedType, } else { stackManipulation = MethodVariableAccess.loadThis(); } - StackManipulation assignment = assigner.assign(type, + StackManipulation assignment = assigner.assign(type.asGenericType(), resolution.getField().getType(), typing); if (!assignment.isValid()) { @@ -13862,7 +13865,7 @@ public Class getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { List handlers = new ArrayList(); @@ -13950,12 +13953,12 @@ public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value) { if (instrumentedMethod.getReturnType().represents(void.class)) { return StackManipulation.Trivial.INSTANCE; } - StackManipulation assignment = assigner.assign(type, instrumentedMethod.getReturnType(), typing); + StackManipulation assignment = assigner.assign(type.asGenericType(), instrumentedMethod.getReturnType(), typing); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + type + " to " + instrumentedMethod.getReturnType()); } @@ -14003,11 +14006,11 @@ public Class getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { if (!exit) { - throw new IllegalStateException("Cannot write returned value from enter advice " + advice); + throw new IllegalStateException("Cannot write returned value from enter advice for " + returnType); } return Collections.singletonList(new ToReturned.Handler(annotation.getValue(TO_RETURNED_INDEX).resolve(Integer.class), annotation.getValue(TO_RETURNED_TYPING).resolve(EnumerationDescription.class).load(Assigner.Typing.class))); @@ -14090,9 +14093,9 @@ public StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value) { - StackManipulation assignment = assigner.assign(type, TypeDefinition.Sort.describe(Throwable.class), typing); + StackManipulation assignment = assigner.assign(type.asGenericType(), TypeDefinition.Sort.describe(Throwable.class), typing); if (!assignment.isValid()) { throw new IllegalStateException("Cannot assign " + type + " to " + Throwable.class.getName()); } @@ -14141,14 +14144,11 @@ public Class getAnnotationType() { * {@inheritDoc} */ @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Assuming annotation for exit advice.") - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { if (!exit) { - throw new IllegalStateException("Cannot assign thrown value from enter advice " + advice); - } else if (advice.getDeclaredAnnotations().ofType(OnMethodExit.class).getValue(ON_THROWABLE).resolve(TypeDescription.class) - .represents(NoExceptionHandler.class)) { - throw new IllegalStateException("Cannot assign thrown value for non-catching exit advice " + advice); + throw new IllegalStateException("Cannot assign thrown value from enter advice for " + returnType); // TODO } return Collections.singletonList(new ToThrown.Handler(annotation.getValue(TO_THROWN_INDEX).resolve(Integer.class), annotation.getValue(TO_THROWN_TYPING).resolve(EnumerationDescription.class).load(Assigner.Typing.class))); @@ -14171,16 +14171,16 @@ protected static class ForArray extends AssignReturned { /** * Creates a post processor to assign a returned array value by index. * - * @param type The array type that is returned by the advice method. + * @param typeDescription The array type that is returned by the advice method. * @param exceptionHandlerFactory The exception handler factory to use. * @param exit {@code true} if the post processor is applied to exit advice. * @param handlers The handlers to apply. */ - protected ForArray(TypeDescription.Generic type, + protected ForArray(TypeDescription typeDescription, ExceptionHandler.Factory exceptionHandlerFactory, boolean exit, Collection> handlers) { - super(type, exceptionHandlerFactory, exit, true); + super(typeDescription, exceptionHandlerFactory, exit, true); this.handlers = new LinkedHashMap(); for (List collection : handlers) { for (Handler handler : collection) { @@ -14195,8 +14195,8 @@ protected ForArray(TypeDescription.Generic type, @Override @SuppressFBWarnings(value = "NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE", justification = "Assuming component type for array type.") - protected TypeDescription.Generic getType() { - return type.getComponentType(); + protected TypeDescription getType() { + return typeDescription.getComponentType(); } @Override @@ -14209,7 +14209,7 @@ protected Collection getHandlers() { protected StackManipulation toLoadInstruction(Handler handler, int offset) { return new StackManipulation.Compound(MethodVariableAccess.REFERENCE.loadFrom(offset), IntegerConstant.forValue(handlers.get(handler)), - ArrayAccess.of(type.getComponentType()).load()); + ArrayAccess.of(typeDescription.getComponentType()).load()); } } @@ -14227,18 +14227,18 @@ protected static class ForScalar extends AssignReturned { /** * Creates a post processor to assign a returned scalar value. * - * @param type The type of the advice method. + * @param typeDescription The type of the advice method. * @param exceptionHandlerFactory The exception handler factory to use. * @param exit {@code true} if the post processor is applied to exit advice. * @param skipOnDefaultValue {@code true} if a default value indicates that no assignment should be conducted. * @param handlers The handlers to apply. */ - protected ForScalar(TypeDescription.Generic type, + protected ForScalar(TypeDescription typeDescription, ExceptionHandler.Factory exceptionHandlerFactory, boolean exit, boolean skipOnDefaultValue, Collection> handlers) { - super(type, exceptionHandlerFactory, exit, skipOnDefaultValue); + super(typeDescription, exceptionHandlerFactory, exit, skipOnDefaultValue); this.handlers = new ArrayList(); for (List collection : handlers) { for (Handler handler : collection) { @@ -14252,8 +14252,8 @@ protected ForScalar(TypeDescription.Generic type, } @Override - protected TypeDescription.Generic getType() { - return type; + protected TypeDescription getType() { + return typeDescription; } @Override @@ -14263,7 +14263,7 @@ protected Collection getHandlers() { @Override protected StackManipulation toLoadInstruction(Handler handler, int offset) { - return MethodVariableAccess.of(type).loadFrom(offset); + return MethodVariableAccess.of(typeDescription).loadFrom(offset); } } @@ -14618,7 +14618,7 @@ StackManipulation resolve(TypeDescription instrumentedType, MethodDescription instrumentedMethod, Assigner assigner, ArgumentHandler argumentHandler, - TypeDescription.Generic type, + TypeDescription type, StackManipulation value); /** @@ -14638,12 +14638,12 @@ interface Factory { /** * Resolves a list of handlers for this factory. * - * @param advice The advice method for which to resolve handlers. + * @param returnType The advice method's return type for which to resolve handlers. * @param exit {@code true} if this factory is applied for exit advice. * @param annotation The annotation that activated this handler factory. * @return A list of handlers to apply. */ - List make(MethodDescription.InDefinedShape advice, + List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation); @@ -14686,7 +14686,7 @@ public Class getAnnotationType() { /** * {@inheritDoc} */ - public List make(MethodDescription.InDefinedShape advice, + public List make(TypeDescription returnType, boolean exit, AnnotationDescription.Loadable annotation) { return handlers; @@ -14804,8 +14804,10 @@ public PostProcessor.Factory withSuppressed(TypeDescription exceptionType) { * {@inheritDoc} */ @SuppressWarnings("unchecked") - public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) { - if (advice.getReturnType().represents(void.class)) { + public PostProcessor make(List annotations, + TypeDescription returnType, + boolean exit) { + if (returnType.represents(void.class)) { return NoOp.INSTANCE; } Map> factories = new HashMap>(); @@ -14816,7 +14818,7 @@ public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) } Map, List> handlers = new LinkedHashMap, List>(); boolean scalar = false, skipOnDefaultValue = true; - for (AnnotationDescription annotation : advice.getDeclaredAnnotations()) { + for (AnnotationDescription annotation : annotations) { if (annotation.getAnnotationType().represents(AsScalar.class)) { scalar = true; skipOnDefaultValue = annotation.getValue(SKIP_ON_DEFAULT_VALUE).resolve(Boolean.class); @@ -14824,7 +14826,7 @@ public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) } Handler.Factory factory = factories.get(annotation.getAnnotationType().getName()); if (factory != null) { - if (handlers.put(factory.getAnnotationType(), factory.make(advice, + if (handlers.put(factory.getAnnotationType(), factory.make(returnType, exit, (AnnotationDescription.Loadable) annotation.prepare(factory.getAnnotationType()))) != null) { throw new IllegalStateException("Duplicate handler registration for " + annotation.getAnnotationType()); @@ -14834,9 +14836,9 @@ public PostProcessor make(MethodDescription.InDefinedShape advice, boolean exit) if (handlers.isEmpty()) { return NoOp.INSTANCE; } else { - return !scalar && advice.getReturnType().isArray() - ? new ForArray(advice.getReturnType(), exceptionHandlerFactory, exit, handlers.values()) - : new ForScalar(advice.getReturnType(), exceptionHandlerFactory, exit, skipOnDefaultValue, handlers.values()); + return !scalar && returnType.isArray() + ? new ForArray(returnType, exceptionHandlerFactory, exit, handlers.values()) + : new ForScalar(returnType, exceptionHandlerFactory, exit, skipOnDefaultValue, handlers.values()); } } } From 3484da42a546f75531c632474c36e7ae0c1b741a Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 13:29:28 +0100 Subject: [PATCH 16/19] Add missing javadoc. --- byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index e110e82fdf3..2c8896077e8 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -5493,8 +5493,9 @@ interface Factory { /** * Creates a post processor for a given advice method. * - * @param returnType The advice method's return type that is being post-processed. - * @param exit {@code true} if the advice is exit advice. + * @param annotations The annotations of the advice method. + * @param returnType The advice method's return type that is being post-processed. + * @param exit {@code true} if the advice is exit advice. * @return The created post processor. */ PostProcessor make(List annotations, TypeDescription returnType, boolean exit); @@ -13077,7 +13078,7 @@ public abstract static class AssignReturned implements PostProcessor { /** * Creates a new post processor for assigning an advice method's return value. * - * @param typeDescription The advice method's return type. + * @param typeDescription The advice method's return type. * @param exceptionHandlerFactory The exception handler factory to use. * @param exit {@code true} if this post processor is used within exit advice. * @param skipOnDefaultValue {@code true} if a default value indicates that no assignment should be conducted. From 26b840fbe0d4b0c1a8d98424f4f7e109390bd2df Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 13:33:05 +0100 Subject: [PATCH 17/19] Avoid intermediate store of type token. --- .../src/main/java/net/bytebuddy/asm/Advice.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java index 2c8896077e8..68e081a0c28 100644 --- a/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java +++ b/byte-buddy-dep/src/main/java/net/bytebuddy/asm/Advice.java @@ -11034,15 +11034,14 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { - MethodDescription.TypeToken typeToken = delegator.getTypeToken(); return doResolve(instrumentedType, instrumentedMethod, methodVisitor, implementationContext, assigner, - argumentHandler.bindEnter(typeToken), - methodSizeHandler.bindEnter(typeToken), - stackMapFrameHandler.bindEnter(typeToken), + argumentHandler.bindEnter(delegator.getTypeToken()), + methodSizeHandler.bindEnter(delegator.getTypeToken()), + stackMapFrameHandler.bindEnter(delegator.getTypeToken()), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), exceptionHandler); @@ -11281,15 +11280,14 @@ protected Bound resolve(TypeDescription instrumentedType, StackMapFrameHandler.ForInstrumentedMethod stackMapFrameHandler, StackManipulation exceptionHandler, RelocationHandler.Relocation relocation) { - MethodDescription.TypeToken typeToken = delegator.getTypeToken(); return doResolve(instrumentedType, instrumentedMethod, methodVisitor, implementationContext, assigner, - argumentHandler.bindExit(typeToken, getThrowable().represents(NoExceptionHandler.class)), - methodSizeHandler.bindExit(typeToken), - stackMapFrameHandler.bindExit(typeToken), + argumentHandler.bindExit(delegator.getTypeToken(), getThrowable().represents(NoExceptionHandler.class)), + methodSizeHandler.bindExit(delegator.getTypeToken()), + stackMapFrameHandler.bindExit(delegator.getTypeToken()), suppressionHandler.bind(exceptionHandler), relocationHandler.bind(instrumentedMethod, relocation), exceptionHandler); From fc69636a108f4496bfd12e23415db80b1c590509 Mon Sep 17 00:00:00 2001 From: Rafael Winterhalter Date: Fri, 17 Jan 2025 13:33:52 +0100 Subject: [PATCH 18/19] Increase version number. --- byte-buddy-agent/pom.xml | 2 +- byte-buddy-android-test/pom.xml | 2 +- byte-buddy-android/pom.xml | 2 +- byte-buddy-benchmark/pom.xml | 2 +- byte-buddy-dep/pom.xml | 2 +- byte-buddy-gradle-plugin/pom.xml | 2 +- byte-buddy-maven-plugin/pom.xml | 2 +- byte-buddy/pom.xml | 2 +- pom.xml | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/byte-buddy-agent/pom.xml b/byte-buddy-agent/pom.xml index f506e876779..1fd03a5a314 100644 --- a/byte-buddy-agent/pom.xml +++ b/byte-buddy-agent/pom.xml @@ -5,7 +5,7 @@ net.bytebuddy byte-buddy-parent - 1.15.12-SNAPSHOT + 1.16.0-SNAPSHOT byte-buddy-agent diff --git a/byte-buddy-android-test/pom.xml b/byte-buddy-android-test/pom.xml index 24ed626dfe0..15db2124178 100644 --- a/byte-buddy-android-test/pom.xml +++ b/byte-buddy-android-test/pom.xml @@ -5,7 +5,7 @@ net.bytebuddy byte-buddy-parent - 1.15.12-SNAPSHOT + 1.16.0-SNAPSHOT byte-buddy-android-test diff --git a/byte-buddy-android/pom.xml b/byte-buddy-android/pom.xml index 39af4d25e9b..0cc829e7157 100644 --- a/byte-buddy-android/pom.xml +++ b/byte-buddy-android/pom.xml @@ -5,7 +5,7 @@ net.bytebuddy byte-buddy-parent - 1.15.12-SNAPSHOT + 1.16.0-SNAPSHOT byte-buddy-android diff --git a/byte-buddy-benchmark/pom.xml b/byte-buddy-benchmark/pom.xml index 1e6ecb5360b..c493d974a6f 100644 --- a/byte-buddy-benchmark/pom.xml +++ b/byte-buddy-benchmark/pom.xml @@ -5,7 +5,7 @@ net.bytebuddy byte-buddy-parent - 1.15.12-SNAPSHOT + 1.16.0-SNAPSHOT byte-buddy-benchmark diff --git a/byte-buddy-dep/pom.xml b/byte-buddy-dep/pom.xml index 975beaa1a8d..8fc7e7307e4 100644 --- a/byte-buddy-dep/pom.xml +++ b/byte-buddy-dep/pom.xml @@ -5,7 +5,7 @@ net.bytebuddy byte-buddy-parent - 1.15.12-SNAPSHOT + 1.16.0-SNAPSHOT