Skip to content

Commit

Permalink
Update ASM API to 9
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik committed Dec 23, 2022
1 parent 5378a90 commit ed6c69a
Show file tree
Hide file tree
Showing 18 changed files with 48 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -766,12 +766,12 @@ private Object getDTraceSource(String fileName, byte[] code) {
ClassReader reader = new ClassReader(code);
Object[] result = new Object[1];
reader.accept(
new ClassVisitor(Opcodes.ASM7) {
new ClassVisitor(Opcodes.ASM9) {

@Override
public AnnotationVisitor visitAnnotation(String desc, boolean vis) {
if (desc.equals(DTRACE_DESC)) {
return new AnnotationVisitor(Opcodes.ASM7) {
return new AnnotationVisitor(Opcodes.ASM9) {

@Override
public void visit(String name, Object value) {
Expand All @@ -781,7 +781,7 @@ public void visit(String name, Object value) {
}
};
} else if (desc.equals(DTRACE_REF_DESC)) {
return new AnnotationVisitor(Opcodes.ASM7) {
return new AnnotationVisitor(Opcodes.ASM9) {

@Override
public void visit(String name, Object value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class Postprocessor extends ClassVisitor {
private String className = "";

public Postprocessor(ClassVisitor cv) {
super(Opcodes.ASM7, cv);
super(Opcodes.ASM9, cv);
}

@Override
Expand Down Expand Up @@ -119,14 +119,14 @@ public FieldVisitor visitField(
if (!shortSyntax) return super.visitField(access, name, desc, signature, value);

List<Attribute> attrs = new ArrayList<>();
return new FieldVisitor(Opcodes.ASM7) {
return new FieldVisitor(Opcodes.ASM9) {
private final List<AnnotationDef> annotations = new ArrayList<>();

@Override
public AnnotationVisitor visitAnnotation(String type, boolean visible) {
AnnotationDef ad = new AnnotationDef(type);
annotations.add(ad);
return new AnnotationVisitor(Opcodes.ASM7, super.visitAnnotation(type, visible)) {
return new AnnotationVisitor(Opcodes.ASM9, super.visitAnnotation(type, visible)) {
@Override
public void visit(String name, Object val) {
ad.addValue(name, val);
Expand Down Expand Up @@ -242,7 +242,7 @@ private class MethodConvertor extends MethodVisitor {
private boolean copyEnabled = false;

public MethodConvertor(int localVarOffset, boolean isConstructor, MethodVisitor mv) {
super(Opcodes.ASM7, mv);
super(Opcodes.ASM9, mv);
this.localVarOffset = localVarOffset;
this.isConstructor = isConstructor;
copyEnabled = !isConstructor; // copy is enabled by default for all methods except constructor
Expand Down Expand Up @@ -728,12 +728,12 @@ public void visitMethodInsn(
public AnnotationVisitor visitAnnotation(String string, boolean bln) {
return copyEnabled
? super.visitAnnotation(string, bln)
: new AnnotationVisitor(Opcodes.ASM7) {};
: new AnnotationVisitor(Opcodes.ASM9) {};
}

@Override
public AnnotationVisitor visitAnnotationDefault() {
return copyEnabled ? super.visitAnnotationDefault() : new AnnotationVisitor(Opcodes.ASM7) {};
return copyEnabled ? super.visitAnnotationDefault() : new AnnotationVisitor(Opcodes.ASM9) {};
}

@Override
Expand All @@ -758,7 +758,7 @@ public void visitMultiANewArrayInsn(String string, int i) {
public AnnotationVisitor visitParameterAnnotation(int i, String string, boolean bln) {
return copyEnabled
? super.visitParameterAnnotation(i, string, bln)
: new AnnotationVisitor(Opcodes.ASM7) {};
: new AnnotationVisitor(Opcodes.ASM9) {};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public byte[] instrument() {

Instrumentor top = instrumentors.peekLast();
ClassVisitor cv =
new ClassVisitor(Opcodes.ASM7, top != null ? top : this) {
new ClassVisitor(Opcodes.ASM9, top != null ? top : this) {
@Override
public void visitEnd() {
if (top != null && top.hasCushionMethods()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class BTraceMethodNode extends MethodNode {

BTraceMethodNode(MethodNode from, BTraceProbeNode cn, boolean initBTraceHandler) {
super(
Opcodes.ASM7,
Opcodes.ASM9,
from.access,
from.name,
from.desc,
Expand Down Expand Up @@ -90,7 +90,7 @@ public AnnotationVisitor visitAnnotation(String type, boolean visible) {
om = new OnMethod(this);
om.setTargetName(name);
om.setTargetDescriptor(desc);
return new AnnotationVisitor(Opcodes.ASM7, av) {
return new AnnotationVisitor(Opcodes.ASM9, av) {
@Override
public void visit(String name, Object value) {
super.visit(name, value);
Expand Down Expand Up @@ -120,7 +120,7 @@ public AnnotationVisitor visitAnnotation(String name, String desc) {
AnnotationVisitor av1 = super.visitAnnotation(name, desc);
if (desc.equals(Constants.LOCATION_DESC)) {
loc = new Location();
return new AnnotationVisitor(Opcodes.ASM7, av1) {
return new AnnotationVisitor(Opcodes.ASM9, av1) {
@Override
public void visitEnum(String name, String desc, String value) {
super.visitEnum(name, desc, value);
Expand Down Expand Up @@ -164,7 +164,7 @@ public void visitEnd() {
}
};
} else if (desc.equals(Constants.LEVEL_DESC)) {
return new AnnotationVisitor(Opcodes.ASM7, av1) {
return new AnnotationVisitor(Opcodes.ASM9, av1) {
@Override
public void visit(String name, Object value) {
super.visit(name, value);
Expand All @@ -182,7 +182,7 @@ public void visit(String name, Object value) {
op = new OnProbe(this);
op.setTargetName(name);
op.setTargetDescriptor(desc);
return new AnnotationVisitor(Opcodes.ASM7, av) {
return new AnnotationVisitor(Opcodes.ASM9, av) {
@Override
public void visit(String name, Object value) {
super.visit(name, value);
Expand All @@ -200,7 +200,7 @@ public void visit(String name, Object value) {
} else if (type.equals(Constants.SAMPLED_DESC)) {
if (om != null) {
om.setSamplerKind(Sampled.Sampler.Adaptive);
return new AnnotationVisitor(Opcodes.ASM7, av) {
return new AnnotationVisitor(Opcodes.ASM9, av) {
private boolean meanSet = false;

@Override
Expand Down Expand Up @@ -319,7 +319,7 @@ private AnnotationVisitor setSpecialParameters(
} else if (desc.equals(Constants.BTRACE_PROBEMETHODNAME_DESC)) {
ph.setMethodParameter(parameter);
av =
new AnnotationVisitor(Opcodes.ASM7, av) {
new AnnotationVisitor(Opcodes.ASM9, av) {
@Override
public void visit(String name, Object val) {
if (name.equals("fqn")) {
Expand All @@ -334,7 +334,7 @@ public void visit(String name, Object val) {
ph.setTargetMethodOrFieldParameter(parameter);

av =
new AnnotationVisitor(Opcodes.ASM7, av) {
new AnnotationVisitor(Opcodes.ASM9, av) {
@Override
public void visit(String name, Object val) {
if (name.equals("fqn")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class BTraceMethodVisitor extends MethodVisitor {
private final MethodInstrumentorHelper mHelper;

public BTraceMethodVisitor(MethodVisitor mv, MethodInstrumentorHelper mHelper) {
super(Opcodes.ASM7, mv);
super(Opcodes.ASM9, mv);
this.mHelper = mHelper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public final class BTraceProbeNode extends ClassNode implements BTraceProbe {
private VerifierException verifierException = null;

private BTraceProbeNode(BTraceProbeFactory factory) {
super(Opcodes.ASM7);
super(Opcodes.ASM9);
this.factory = factory;
bcpResourceClassLoader = new BTraceBCPClassLoader(factory.getSettings());
debug = new DebugSupport(factory.getSettings());
Expand Down Expand Up @@ -124,7 +124,7 @@ public MethodVisitor visitMethod(
@Override
public FieldVisitor visitField(
int access, String name, String desc, String signature, Object value) {
return new FieldVisitor(Opcodes.ASM7, super.visitField(access, name, desc, signature, value)) {
return new FieldVisitor(Opcodes.ASM9, super.visitField(access, name, desc, signature, value)) {
@Override
public AnnotationVisitor visitAnnotation(String type, boolean aVisible) {
AnnotationVisitor av = super.visitAnnotation(type, aVisible);
Expand Down Expand Up @@ -225,7 +225,7 @@ private byte[] getBytecode(boolean onlyBcpMethods) {
ClassVisitor cv = cw;
if (onlyBcpMethods) {
cv =
new ClassVisitor(Opcodes.ASM7, cw) {
new ClassVisitor(Opcodes.ASM9, cw) {
@Override
public MethodVisitor visitMethod(
int access, String name, String desc, String sig, String[] exceptions) {
Expand Down Expand Up @@ -482,7 +482,7 @@ private Set<BTraceMethodNode> fromIdSet(Set<String> ids) {

private MethodNode copy(MethodNode n) {
String[] exceptions = n.exceptions != null ? n.exceptions.toArray(new String[0]) : null;
MethodNode mn = new MethodNode(Opcodes.ASM7, n.access, n.name, n.desc, n.signature, exceptions);
MethodNode mn = new MethodNode(Opcodes.ASM9, n.access, n.name, n.desc, n.signature, exceptions);
n.accept(mn);
mn.access = Opcodes.ACC_STATIC | Opcodes.ACC_PRIVATE;
mn.desc = mn.desc.replace(Constants.ANYTYPE_DESC, Constants.OBJECT_DESC);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ public void copyHandlers(ClassVisitor copyingVisitor) {
}
}
cr.accept(
new ClassVisitor(ASM7) {
new ClassVisitor(ASM9) {
@Override
public void visit(
int version,
Expand Down Expand Up @@ -581,7 +581,7 @@ private void upgradeBytecode() {
private void verifyBytecode() throws VerifierException {
ClassReader cr = new ClassReader(fullData);
cr.accept(
new ClassVisitor(ASM7) {
new ClassVisitor(ASM9) {
private String className;

@Override
Expand Down Expand Up @@ -652,7 +652,7 @@ public MethodVisitor visitMethod(
}

return new MethodVisitor(
ASM7, super.visitMethod(access, methodName, desc, sig, exceptions)) {
ASM9, super.visitMethod(access, methodName, desc, sig, exceptions)) {
private final Map<Label, Label> labels = new HashMap<>();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public final void unregister(BTraceProbe p) {
filter.remove(om);
MethodNode cushionMethod =
new MethodNode(
Opcodes.ASM7,
Opcodes.ASM9,
Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC,
Instrumentor.getActionMethodName(p, om.getTargetName()),
om.getTargetDescriptor(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.openjdk.btrace.instr;

import static org.objectweb.asm.Opcodes.ASM7;
import static org.objectweb.asm.Opcodes.ASM9;

import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.MethodVisitor;
Expand Down Expand Up @@ -36,7 +36,7 @@ public void visit(
public MethodVisitor visitMethod(
int access, String name, String desc, String sig, String[] exceptions) {
return new MethodVisitor(
ASM7,
ASM9,
super.visitMethod(
Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, getMethodName(name), desc, sig, exceptions)) {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public final class InstrumentingMethodVisitor extends MethodVisitor

public InstrumentingMethodVisitor(
int access, String owner, String desc, MethodVisitor mv) {
super(ASM7, mv);
super(ASM9, mv);
this.owner = owner;
this.desc = desc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public class Instrumentor extends ClassVisitor {

private Instrumentor(
ClassLoader cl, BTraceProbe bcn, Collection<OnMethod> applicables, ClassVisitor cv) {
super(ASM7, cv);
super(ASM9, cv);
this.cl = cl;
this.bcn = bcn;
BTraceRuntime.Impl rt = bcn.getRuntime();
Expand Down Expand Up @@ -183,7 +183,7 @@ && typeMatches(om.getType(), desc, om.isExactTypeMatch())) {
methodVisitor = instrumentorFor(om, methodVisitor, mHelper, access, name, desc);
}

return new MethodVisitor(ASM7, methodVisitor) {
return new MethodVisitor(ASM9, methodVisitor) {
@Override
public AnnotationVisitor visitAnnotation(String annoDesc, boolean visible) {
for (OnMethod om : annotationMatchers) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private void addLevelField(ClassNode cn) {
}
cn.fields.add(
new FieldNode(
Opcodes.ASM7,
Opcodes.ASM9,
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_VOLATILE,
Constants.BTRACE_LEVEL_FLD,
Constants.INT_DESC,
Expand Down Expand Up @@ -764,7 +764,7 @@ private void recalculateVars(MethodNode mn) {
}
StackTrackingMethodVisitor v =
new StackTrackingMethodVisitor(
new MethodVisitor(Opcodes.ASM7) {
new MethodVisitor(Opcodes.ASM9) {
@Override
public void visitMaxs(int maxStack, int maxLocals) {
super.visitMaxs(maxStack, maxLocals);
Expand All @@ -788,7 +788,7 @@ private void processClinit(ClassNode cn) {
if (clinit == null) {
clinit =
new MethodNode(
Opcodes.ASM7,
Opcodes.ASM9,
(Opcodes.ACC_STATIC | Opcodes.ACC_PUBLIC),
"<clinit>",
"()V",
Expand Down Expand Up @@ -1101,7 +1101,7 @@ private InsnList getRuntimeExit(ClassNode cn) {
private void addRuntimeNode(ClassNode cn) {
rtField =
new FieldNode(
Opcodes.ASM7,
Opcodes.ASM9,
(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC),
"runtime",
Type.getDescriptor(BTraceRuntimeImplBase.class),
Expand Down Expand Up @@ -1221,7 +1221,7 @@ private void addJfrHandlerField(ClassNode cn, MethodNode mn) {
String fldName = JFR_HANDLER_FIELD_PREFIX + mn.name;
cn.fields.add(
new FieldNode(
Opcodes.ASM7,
Opcodes.ASM9,
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC,
fldName,
Constants.JFREVENTFACTORY_DESC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ final class ProbeRenameVisitor extends ClassVisitor {
private final String newClassName;

ProbeRenameVisitor(ClassVisitor classVisitor, String newClassName) {
super(Opcodes.ASM7, classVisitor);
super(Opcodes.ASM9, classVisitor);
this.newClassName = newClassName.replace('.', '/');
}

Expand All @@ -38,7 +38,7 @@ public void visit(
public MethodVisitor visitMethod(
int access, String name, String descriptor, String signature, String[] exceptions) {
return new MethodVisitor(
Opcodes.ASM7, super.visitMethod(access, name, descriptor, signature, exceptions)) {
Opcodes.ASM9, super.visitMethod(access, name, descriptor, signature, exceptions)) {
@Override
public void visitTypeInsn(int opcode, String type) {
super.visitTypeInsn(opcode, type.equals(oldClassName) ? newClassName : type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class ProbeUpgradeVisitor_1_2 extends ClassVisitor {
private static final String ANNOTATIONS_PREFIX_NEW = "Lorg/openjdk/btrace/core/annotations/";

ProbeUpgradeVisitor_1_2(ClassVisitor cv) {
super(ASM7, cv);
super(ASM9, cv);
}

private String cName = null;
Expand Down Expand Up @@ -52,7 +52,7 @@ public FieldVisitor visitField(
if (desc.contains("BTraceRuntime")) {
desc = Constants.BTRACERTACCESS_DESC;
}
return new FieldVisitor(ASM7, super.visitField(access, name, desc, signature, value)) {
return new FieldVisitor(ASM9, super.visitField(access, name, desc, signature, value)) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (desc.startsWith(ANNOTATIONS_PREFIX_OLD)) {
Expand All @@ -66,7 +66,7 @@ public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
@Override
public MethodVisitor visitMethod(
int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(ASM7, super.visitMethod(access, name, desc, signature, exceptions)) {
return new MethodVisitor(ASM9, super.visitMethod(access, name, desc, signature, exceptions)) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (desc.startsWith(ANNOTATIONS_PREFIX_OLD)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class StackTrackingMethodVisitor extends MethodVisitor {

public StackTrackingMethodVisitor(
MethodVisitor mv, String className, String desc, boolean isStatic) {
super(Opcodes.ASM7, mv);
super(Opcodes.ASM9, mv);
Type[] args = Type.getArgumentTypes(desc);
state = new State(isStatic ? null : new InstanceItem(Type.getObjectType(className)), args);
}
Expand Down
Loading

0 comments on commit ed6c69a

Please sign in to comment.