From c349227e46d142874d511395356e61c245c074ef Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Tue, 12 Dec 2023 14:53:42 +0200 Subject: [PATCH 1/2] Fix transforming record types --- .../javaagent/tooling/field/RealFieldInjector.java | 2 +- .../javaagent/tooling/field/VirtualFieldFindRewriter.java | 4 ++-- .../tooling/muzzle/ReferenceCollectingClassVisitor.java | 6 +++--- .../tooling/muzzle/generation/MuzzleCodeGenerator.java | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java index 60e14b57fbc0..40d66f84adaf 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java @@ -66,7 +66,7 @@ public ClassVisitor wrap( int writerFlags, int readerFlags) { - return new ClassVisitor(Opcodes.ASM7, classVisitor) { + return new ClassVisitor(Opcodes.ASM9, classVisitor) { // We are using Object class name instead of fieldTypeName here because this gets // injected onto the bootstrap class loader where context class may be unavailable private final TypeDescription fieldType = TypeDescription.ForLoadedType.of(Object.class); diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java index a7a7446eca72..9465b0722974 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java @@ -81,12 +81,12 @@ public ClassVisitor wrap( int writerFlags, int readerFlags) { - return new ClassVisitor(Opcodes.ASM7, classVisitor) { + return new ClassVisitor(Opcodes.ASM9, classVisitor) { @Override public MethodVisitor visitMethod( int access, String name, String descriptor, String signature, String[] exceptions) { MethodVisitor mv = super.visitMethod(access, name, descriptor, signature, exceptions); - return new MethodVisitor(Opcodes.ASM7, mv) { + return new MethodVisitor(api, mv) { /** The most recent objects pushed to the stack. */ private final Object[] stack = {null, null}; diff --git a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java index f411d12e4dc1..be4a521afd70 100644 --- a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java +++ b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java @@ -126,7 +126,7 @@ private static Type underlyingType(Type type) { ReferenceCollectingClassVisitor( HelperClassPredicate helperClassPredicate, boolean isAdviceClass) { - super(Opcodes.ASM7); + super(Opcodes.ASM9); this.helperClassPredicate = helperClassPredicate; this.isAdviceClass = isAdviceClass; } @@ -312,7 +312,7 @@ private class AdviceReferenceMethodVisitor extends MethodVisitor { private int currentLineNumber = -1; public AdviceReferenceMethodVisitor(MethodVisitor methodVisitor) { - super(Opcodes.ASM7, methodVisitor); + super(Opcodes.ASM9, methodVisitor); } @Override @@ -526,7 +526,7 @@ private class VirtualFieldCollectingMethodVisitor extends MethodVisitor { private final EvictingQueue lastTwoClassConstants = EvictingQueue.create(2); VirtualFieldCollectingMethodVisitor(MethodVisitor methodVisitor) { - super(Opcodes.ASM7, methodVisitor); + super(Opcodes.ASM9, methodVisitor); } @Override diff --git a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java index bc1345831300..f78a9e0f7c73 100644 --- a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java +++ b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java @@ -98,7 +98,7 @@ private static class GenerateMuzzleMethodsAndFields extends ClassVisitor { private boolean generateVirtualFieldsMethod = true; public GenerateMuzzleMethodsAndFields(ClassVisitor classVisitor, URLClassLoader classLoader) { - super(Opcodes.ASM7, classVisitor); + super(Opcodes.ASM9, classVisitor); this.classLoader = classLoader; } From 102eff848f9afdedb0fe517be307843d8fbcd0e0 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Wed, 13 Dec 2023 14:18:03 +0200 Subject: [PATCH 2/2] add shaderd constant for asm api version --- ...rClassLambdaMetafactoryInstrumentation.java | 3 ++- .../reflection/ClassInstrumentation.java | 3 ++- .../ExpandFramesClassVisitor.java | 5 +++-- .../WithSpanInstrumentation.java | 6 ++++-- .../payara/StandardWrapperInstrumentation.java | 3 ++- .../instrumentation/internal/AsmApi.java | 18 ++++++++++++++++++ .../javaagent/tooling/AgentStarterImpl.java | 3 ++- .../tooling/field/RealFieldInjector.java | 3 ++- .../field/VirtualFieldFindRewriter.java | 3 ++- .../VirtualFieldImplementationsGenerator.java | 3 ++- .../indy/AdviceTransformer.java | 15 ++++++++------- .../ReferenceCollectingClassVisitor.java | 9 +++++---- .../muzzle/generation/MuzzleCodeGenerator.java | 3 ++- 13 files changed, 54 insertions(+), 23 deletions(-) create mode 100644 javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/AsmApi.java diff --git a/instrumentation/internal/internal-lambda/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/InnerClassLambdaMetafactoryInstrumentation.java b/instrumentation/internal/internal-lambda/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/InnerClassLambdaMetafactoryInstrumentation.java index a45dd155bd69..07d444913afa 100644 --- a/instrumentation/internal/internal-lambda/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/InnerClassLambdaMetafactoryInstrumentation.java +++ b/instrumentation/internal/internal-lambda/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/lambda/InnerClassLambdaMetafactoryInstrumentation.java @@ -12,6 +12,7 @@ import io.opentelemetry.javaagent.bootstrap.DefineClassHelper.Handler.DefineClassContext; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import net.bytebuddy.asm.Advice; import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.description.field.FieldDescription; @@ -89,7 +90,7 @@ private static class MetaFactoryClassVisitor extends ClassVisitor { private final String slashClassName; MetaFactoryClassVisitor(ClassVisitor cv, String slashClassName) { - super(Opcodes.ASM7, cv); + super(AsmApi.VERSION, cv); this.slashClassName = slashClassName; } diff --git a/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ClassInstrumentation.java b/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ClassInstrumentation.java index 3d6758370fcd..9dda5d174640 100644 --- a/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ClassInstrumentation.java +++ b/instrumentation/internal/internal-reflection/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/internal/reflection/ClassInstrumentation.java @@ -10,6 +10,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.description.field.FieldDescription; import net.bytebuddy.description.field.FieldList; @@ -65,7 +66,7 @@ public ClassVisitor wrap( private static class ClassClassVisitor extends ClassVisitor { ClassClassVisitor(ClassVisitor cv) { - super(Opcodes.ASM7, cv); + super(AsmApi.VERSION, cv); } @Override diff --git a/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java b/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java index 39359c4d7978..71a7dcd55c52 100644 --- a/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java +++ b/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/ExpandFramesClassVisitor.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.kotlinxcoroutines.instrumentationannotations; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import java.lang.reflect.Modifier; import java.util.ArrayList; import java.util.Iterator; @@ -22,7 +23,7 @@ class ExpandFramesClassVisitor extends ClassVisitor { private String className; ExpandFramesClassVisitor(ClassVisitor classVisitor) { - super(Opcodes.ASM9, classVisitor); + super(AsmApi.VERSION, classVisitor); } @Override @@ -50,7 +51,7 @@ private static class ExpandFramesMethodVisitor extends MethodVisitor { ExpandFramesMethodVisitor( MethodVisitor mv, String className, String methodName, int access, String descriptor) { - super(Opcodes.ASM9, mv); + super(AsmApi.VERSION, mv); if ("".equals(methodName)) { currentLocals.add(Opcodes.UNINITIALIZED_THIS); } else if (!Modifier.isStatic(access)) { diff --git a/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java b/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java index 6335cede421b..1995d5f14de9 100644 --- a/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java +++ b/instrumentation/kotlinx-coroutines/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/kotlinxcoroutines/instrumentationannotations/WithSpanInstrumentation.java @@ -19,6 +19,7 @@ import io.opentelemetry.javaagent.bootstrap.internal.InstrumentationConfig; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.instrumentation.instrumentationannotations.AnnotationExcludedMethods; import io.opentelemetry.javaagent.instrumentation.kotlinxcoroutines.instrumentationannotations.SpanAttributeUtil.Parameter; import java.util.Arrays; @@ -136,7 +137,7 @@ private static class WithSpanClassVisitor extends ClassVisitor { String className; WithSpanClassVisitor(ClassVisitor cv) { - super(Opcodes.ASM9, cv); + super(AsmApi.VERSION, cv); } @Override @@ -213,7 +214,8 @@ private static MethodVisitor instrument( source.signature, source.exceptions.toArray(new String[0])); GeneratorAdapter generatorAdapter = - new GeneratorAdapter(Opcodes.ASM9, methodNode, source.access, source.name, source.desc) { + new GeneratorAdapter( + AsmApi.VERSION, methodNode, source.access, source.name, source.desc) { int requestLocal; int ourContinuationLocal; int contextLocal; diff --git a/instrumentation/payara/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/payara/StandardWrapperInstrumentation.java b/instrumentation/payara/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/payara/StandardWrapperInstrumentation.java index 5930012009f0..93f3e6a034d1 100644 --- a/instrumentation/payara/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/payara/StandardWrapperInstrumentation.java +++ b/instrumentation/payara/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/payara/StandardWrapperInstrumentation.java @@ -10,6 +10,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import net.bytebuddy.asm.AsmVisitorWrapper; import net.bytebuddy.description.field.FieldDescription; import net.bytebuddy.description.field.FieldList; @@ -64,7 +65,7 @@ public ClassVisitor wrap( private static class StandardWrapperClassVisitor extends ClassVisitor { StandardWrapperClassVisitor(ClassVisitor cv) { - super(Opcodes.ASM7, cv); + super(AsmApi.VERSION, cv); } @Override diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/AsmApi.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/AsmApi.java new file mode 100644 index 000000000000..b76f4e3c1508 --- /dev/null +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/instrumentation/internal/AsmApi.java @@ -0,0 +1,18 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.extension.instrumentation.internal; + +import org.objectweb.asm.Opcodes; + +/** + * This class is internal and is hence not for public use. Its APIs are unstable and can change at + * any time. + */ +public final class AsmApi { + public static final int VERSION = Opcodes.ASM9; + + private AsmApi() {} +} diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentStarterImpl.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentStarterImpl.java index 83d01a2398d3..7f12889be6b7 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentStarterImpl.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/AgentStarterImpl.java @@ -9,6 +9,7 @@ import io.opentelemetry.instrumentation.api.internal.cache.weaklockfree.WeakConcurrentMapCleaner; import io.opentelemetry.javaagent.bootstrap.AgentInitializer; import io.opentelemetry.javaagent.bootstrap.AgentStarter; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.config.EarlyInitAgentConfig; import java.io.File; import java.lang.instrument.ClassFileTransformer; @@ -151,7 +152,7 @@ public byte[] transform( ClassReader cr = new ClassReader(classfileBuffer); ClassWriter cw = new ClassWriter(cr, 0); ClassVisitor cv = - new ClassVisitor(Opcodes.ASM7, cw) { + new ClassVisitor(AsmApi.VERSION, cw) { @Override public MethodVisitor visitMethod( int access, String name, String descriptor, String signature, String[] exceptions) { diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java index 40d66f84adaf..f58d4201efb4 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/RealFieldInjector.java @@ -11,6 +11,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.javaagent.bootstrap.VirtualFieldInstalledMarker; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.Utils; import java.util.Arrays; import java.util.LinkedHashSet; @@ -66,7 +67,7 @@ public ClassVisitor wrap( int writerFlags, int readerFlags) { - return new ClassVisitor(Opcodes.ASM9, classVisitor) { + return new ClassVisitor(AsmApi.VERSION, classVisitor) { // We are using Object class name instead of fieldTypeName here because this gets // injected onto the bootstrap class loader where context class may be unavailable private final TypeDescription fieldType = TypeDescription.ForLoadedType.of(Object.class); diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java index 9465b0722974..ea1f2c5e5248 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldFindRewriter.java @@ -9,6 +9,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.TransformSafeLogger; import io.opentelemetry.javaagent.tooling.Utils; import io.opentelemetry.javaagent.tooling.muzzle.VirtualFieldMappings; @@ -81,7 +82,7 @@ public ClassVisitor wrap( int writerFlags, int readerFlags) { - return new ClassVisitor(Opcodes.ASM9, classVisitor) { + return new ClassVisitor(AsmApi.VERSION, classVisitor) { @Override public MethodVisitor visitMethod( int access, String name, String descriptor, String signature, String[] exceptions) { diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldImplementationsGenerator.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldImplementationsGenerator.java index 46c77d1878ba..46f73f4e1a43 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldImplementationsGenerator.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/field/VirtualFieldImplementationsGenerator.java @@ -12,6 +12,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.instrumentation.api.internal.cache.Cache; import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.Utils; import io.opentelemetry.javaagent.tooling.muzzle.VirtualFieldMappings; import java.util.HashMap; @@ -109,7 +110,7 @@ public ClassVisitor wrap( MethodList methods, int writerFlags, int readerFlags) { - return new ClassVisitor(Opcodes.ASM7, classVisitor) { + return new ClassVisitor(AsmApi.VERSION, classVisitor) { private final TypeDescription accessorInterface = fieldAccessorInterfaces.find(typeName, fieldTypeName); diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceTransformer.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceTransformer.java index 26f3323c0de5..2cf9722b46a5 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceTransformer.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/instrumentation/indy/AdviceTransformer.java @@ -5,6 +5,7 @@ package io.opentelemetry.javaagent.tooling.instrumentation.indy; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; @@ -63,7 +64,7 @@ static byte[] transform(byte[] bytes) { TransformationContext context = new TransformationContext(); ClassVisitor cv = - new ClassVisitor(Opcodes.ASM9, cw) { + new ClassVisitor(AsmApi.VERSION, cw) { @Override public MethodVisitor visitMethod( @@ -282,7 +283,7 @@ private static MethodVisitor instrumentWritableArguments( List writableArguments, int returnIndex) { MethodVisitor result = - new MethodVisitor(Opcodes.ASM9, target) { + new MethodVisitor(AsmApi.VERSION, target) { @Override public void visitCode() { AnnotationVisitor av = @@ -348,7 +349,7 @@ public void visitInsn(int opcode) { private static MethodVisitor instrumentWritableReturn( MethodVisitor target, MethodNode source, OutputArgument writableReturn, int returnIndex) { MethodVisitor result = - new MethodVisitor(Opcodes.ASM9, target) { + new MethodVisitor(AsmApi.VERSION, target) { @Override public void visitCode() { AnnotationVisitor av = @@ -421,7 +422,7 @@ private static MethodVisitor instrumentAdviceLocals( AtomicInteger dataIndex = new AtomicInteger(); target = - new MethodVisitor(Opcodes.ASM9, target) { + new MethodVisitor(AsmApi.VERSION, target) { @Override public AnnotationVisitor visitParameterAnnotation( int parameter, String descriptor, boolean visible) { @@ -738,7 +739,7 @@ private static Object getAnnotationValue(AnnotationNode annotationNode) { private static MethodVisitor addReturnArray( TransformationContext context, MethodVisitor target, int returnArraySize) { - return new MethodVisitor(Opcodes.ASM9, target) { + return new MethodVisitor(AsmApi.VERSION, target) { @Override public void visitInsn(int opcode) { if (Opcodes.RETURN == opcode) { @@ -777,7 +778,7 @@ public void visitInsn(int opcode) { * annotation to {@code 0}. */ private static MethodVisitor delegateAdvice(TransformationContext context, MethodVisitor target) { - return new MethodVisitor(Opcodes.ASM9, target) { + return new MethodVisitor(AsmApi.VERSION, target) { @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { AnnotationVisitor av = super.visitAnnotation(descriptor, visible); @@ -818,7 +819,7 @@ public void visitEnd() { /** If annotation has {@code readOnly} attribute set it to {@code true}. */ private static MethodVisitor makeReadOnly(Class annotationType, MethodVisitor target) { - return new MethodVisitor(Opcodes.ASM9, target) { + return new MethodVisitor(AsmApi.VERSION, target) { @Override public AnnotationVisitor visitParameterAnnotation( diff --git a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java index be4a521afd70..7ac429efa628 100644 --- a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java +++ b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/ReferenceCollectingClassVisitor.java @@ -7,6 +7,7 @@ import com.google.common.collect.EvictingQueue; import io.opentelemetry.instrumentation.api.util.VirtualField; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef; import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRefBuilder; import io.opentelemetry.javaagent.tooling.muzzle.references.Flag; @@ -126,7 +127,7 @@ private static Type underlyingType(Type type) { ReferenceCollectingClassVisitor( HelperClassPredicate helperClassPredicate, boolean isAdviceClass) { - super(Opcodes.ASM9); + super(AsmApi.VERSION); this.helperClassPredicate = helperClassPredicate; this.isAdviceClass = isAdviceClass; } @@ -252,7 +253,7 @@ public MethodVisitor visitMethod( MethodVisitor methodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions); MethodVisitor methodNode = - new MethodNode(Opcodes.ASM9, access, name, descriptor, signature, exceptions) { + new MethodNode(AsmApi.VERSION, access, name, descriptor, signature, exceptions) { @Override public void visitEnd() { super.visitEnd(); @@ -312,7 +313,7 @@ private class AdviceReferenceMethodVisitor extends MethodVisitor { private int currentLineNumber = -1; public AdviceReferenceMethodVisitor(MethodVisitor methodVisitor) { - super(Opcodes.ASM9, methodVisitor); + super(AsmApi.VERSION, methodVisitor); } @Override @@ -526,7 +527,7 @@ private class VirtualFieldCollectingMethodVisitor extends MethodVisitor { private final EvictingQueue lastTwoClassConstants = EvictingQueue.create(2); VirtualFieldCollectingMethodVisitor(MethodVisitor methodVisitor) { - super(Opcodes.ASM9, methodVisitor); + super(AsmApi.VERSION, methodVisitor); } @Override diff --git a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java index f78a9e0f7c73..0fdccccb9a67 100644 --- a/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java +++ b/muzzle/src/main/java/io/opentelemetry/javaagent/tooling/muzzle/generation/MuzzleCodeGenerator.java @@ -10,6 +10,7 @@ import com.google.errorprone.annotations.CanIgnoreReturnValue; import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule; import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; +import io.opentelemetry.javaagent.extension.instrumentation.internal.AsmApi; import io.opentelemetry.javaagent.tooling.muzzle.HelperResource; import io.opentelemetry.javaagent.tooling.muzzle.HelperResourceBuilderImpl; import io.opentelemetry.javaagent.tooling.muzzle.InstrumentationModuleMuzzle; @@ -98,7 +99,7 @@ private static class GenerateMuzzleMethodsAndFields extends ClassVisitor { private boolean generateVirtualFieldsMethod = true; public GenerateMuzzleMethodsAndFields(ClassVisitor classVisitor, URLClassLoader classLoader) { - super(Opcodes.ASM9, classVisitor); + super(AsmApi.VERSION, classVisitor); this.classLoader = classLoader; }