Update to ASM5

This commit is contained in:
Nikolay Krasko
2014-03-26 15:07:05 +04:00
parent 95fd870988
commit 4aa3dff2a2
21 changed files with 64 additions and 65 deletions
@@ -22,8 +22,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.*;
public abstract class AbstractClassBuilder implements ClassBuilder {
protected static final MethodVisitor EMPTY_METHOD_VISITOR = new MethodVisitor(Opcodes.ASM4) {};
protected static final FieldVisitor EMPTY_FIELD_VISITOR = new FieldVisitor(Opcodes.ASM4) {};
protected static final MethodVisitor EMPTY_METHOD_VISITOR = new MethodVisitor(Opcodes.ASM5) {};
protected static final FieldVisitor EMPTY_FIELD_VISITOR = new FieldVisitor(Opcodes.ASM5) {};
private String thisName;
@@ -48,7 +48,7 @@ import static org.jetbrains.jet.lang.resolve.BindingContextUtils.descriptorToDec
public abstract class AnnotationCodegen {
public static final FqName VOLATILE_FQ_NAME = new FqName("kotlin.volatile");
private static final AnnotationVisitor NO_ANNOTATION_VISITOR = new AnnotationVisitor(Opcodes.ASM4) {};
private static final AnnotationVisitor NO_ANNOTATION_VISITOR = new AnnotationVisitor(Opcodes.ASM5) {};
private final JetTypeMapper typeMapper;
private final BindingContext bindingContext;
@@ -970,7 +970,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
mv.visitCode();
mv.visitFieldInsn(GETSTATIC, classAsmType.getInternalName(), VALUES, type.getDescriptor());
mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;");
mv.visitMethodInsn(INVOKEVIRTUAL, type.getInternalName(), "clone", "()Ljava/lang/Object;", false);
mv.visitTypeInsn(CHECKCAST, type.getInternalName());
mv.visitInsn(ARETURN);
FunctionCodegen.endVisit(mv, "values()", myClass);
@@ -984,7 +984,7 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
mv.visitCode();
mv.visitLdcInsn(classAsmType);
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;");
mv.visitMethodInsn(INVOKESTATIC, "java/lang/Enum", "valueOf", "(Ljava/lang/Class;Ljava/lang/String;)Ljava/lang/Enum;", false);
mv.visitTypeInsn(CHECKCAST, classAsmType.getInternalName());
mv.visitInsn(ARETURN);
FunctionCodegen.endVisit(mv, "valueOf()", myClass);
@@ -35,7 +35,7 @@ public class InlineAdapter extends InstructionAdapter {
private int nextLocalIndexBeforeInline = -1;
public InlineAdapter(MethodVisitor mv, int localsSize) {
super(mv);
super(InlineCodegenUtil.API, mv);
nextLocalIndex = localsSize;
}
@@ -20,13 +20,6 @@ import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
import org.jetbrains.org.objectweb.asm.util.Textifier;
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.context.CodegenContext;
import org.jetbrains.jet.codegen.context.MethodContext;
@@ -48,6 +41,13 @@ import org.jetbrains.jet.lang.resolve.java.AsmTypeConstants;
import org.jetbrains.jet.lang.types.lang.InlineStrategy;
import org.jetbrains.jet.lang.types.lang.InlineUtil;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
import org.jetbrains.org.objectweb.asm.util.Textifier;
import org.jetbrains.org.objectweb.asm.util.TraceMethodVisitor;
import java.io.IOException;
import java.io.PrintWriter;
@@ -176,7 +176,7 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
JvmMethodSignature jvmSignature = typeMapper.mapSignature(functionDescriptor, context.getContextKind());
Method asmMethod = jvmSignature.getAsmMethod();
node = new MethodNode(Opcodes.ASM4,
node = new MethodNode(InlineCodegenUtil.API,
getMethodAsmFlags(functionDescriptor, context.getContextKind()),
asmMethod.getName(),
asmMethod.getDescriptor(),
@@ -236,7 +236,7 @@ public class InlineCodegen implements ParentCodegenAware, CallGenerator {
JvmMethodSignature jvmMethodSignature = typeMapper.mapSignature(descriptor);
Method asmMethod = jvmMethodSignature.getAsmMethod();
MethodNode methodNode = new MethodNode(Opcodes.ASM4, getMethodAsmFlags(descriptor, context.getContextKind()), asmMethod.getName(), asmMethod.getDescriptor(), jvmMethodSignature.getGenericsSignature(), null);
MethodNode methodNode = new MethodNode(InlineCodegenUtil.API, getMethodAsmFlags(descriptor, context.getContextKind()), asmMethod.getName(), asmMethod.getDescriptor(), jvmMethodSignature.getGenericsSignature(), null);
MethodVisitor adapter = InlineCodegenUtil.wrapWithMaxLocalCalc(methodNode);
@@ -53,7 +53,7 @@ import static org.jetbrains.jet.lang.resolve.DescriptorUtils.isTrait;
public class InlineCodegenUtil {
public final static int API = Opcodes.ASM4;
public final static int API = Opcodes.ASM5;
public final static String INVOKE = "invoke";
@@ -20,21 +20,20 @@ import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.OutputFile;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import org.jetbrains.org.objectweb.asm.*;
import org.jetbrains.org.objectweb.asm.commons.Method;
import org.jetbrains.org.objectweb.asm.tree.AbstractInsnNode;
import org.jetbrains.org.objectweb.asm.tree.FieldInsnNode;
import org.jetbrains.org.objectweb.asm.tree.MethodNode;
import org.jetbrains.org.objectweb.asm.tree.VarInsnNode;
import org.jetbrains.jet.OutputFile;
import org.jetbrains.jet.codegen.*;
import org.jetbrains.jet.codegen.state.GenerationState;
import org.jetbrains.jet.codegen.state.JetTypeMapper;
import java.io.IOException;
import java.util.*;
import static org.jetbrains.org.objectweb.asm.Opcodes.ASM4;
import static org.jetbrains.org.objectweb.asm.Opcodes.V1_6;
public class LambdaTransformer {
@@ -139,13 +138,13 @@ public class LambdaTransformer {
if (bridge != null) {
MethodVisitor invokeBridge = newMethod(classBuilder, bridge);
bridge.accept(new MethodVisitor(ASM4, invokeBridge) {
bridge.accept(new MethodVisitor(InlineCodegenUtil.API, invokeBridge) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (owner.equals(oldLambdaType.getInternalName())) {
super.visitMethodInsn(opcode, newLambdaType.getInternalName(), name, desc);
super.visitMethodInsn(opcode, newLambdaType.getInternalName(), name, desc, itf);
} else {
super.visitMethodInsn(opcode, owner, name, desc);
super.visitMethodInsn(opcode, owner, name, desc, itf);
}
}
});
@@ -31,7 +31,7 @@ public class MaxCalcNode extends MethodVisitor {
private final MethodNode node;
public MaxCalcNode(MethodNode node) {
super(Opcodes.ASM4, node);
super(InlineCodegenUtil.API, node);
this.node = node;
int paramsSize = (node.access & Opcodes.ACC_STATIC) == 0 ? 1 : 0;
@@ -144,7 +144,7 @@ public class MethodInliner {
}
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (/*INLINE_RUNTIME.equals(owner) &&*/ isInvokeOnLambda(owner, name)) { //TODO add method
assert !currentInvokes.isEmpty();
InvokeCall invokeCall = currentInvokes.remove();
@@ -152,7 +152,7 @@ public class MethodInliner {
if (info == null) {
//noninlinable lambda
super.visitMethodInsn(opcode, owner, name, desc);
super.visitMethodInsn(opcode, owner, name, desc, itf);
return;
}
@@ -187,14 +187,14 @@ public class MethodInliner {
for (CapturedParamInfo capturedParamInfo : invocation.getAllRecapturedParameters()) {
visitFieldInsn(Opcodes.GETSTATIC, capturedParamInfo.getContainingLambdaName(), "$$$" + capturedParamInfo.getOriginalFieldName(), capturedParamInfo.getType().getDescriptor());
}
super.visitMethodInsn(opcode, invocation.getNewLambdaType().getInternalName(), name, invocation.getNewConstructorDescriptor());
super.visitMethodInsn(opcode, invocation.getNewLambdaType().getInternalName(), name, invocation.getNewConstructorDescriptor(), itf);
invocation = null;
} else {
super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc);
super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc, itf);
}
}
else {
super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc);
super.visitMethodInsn(opcode, changeOwnerForExternalPackage(owner, opcode), name, desc, itf);
}
}
@@ -227,7 +227,7 @@ public class MethodInliner {
Type[] allTypes = ArrayUtil.mergeArrays(types, capturedTypes.toArray(new Type[capturedTypes.size()]));
node.instructions.resetLabels();
MethodNode transformedNode = new MethodNode(node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {
MethodNode transformedNode = new MethodNode(InlineCodegenUtil.API, node.access, node.name, Type.getMethodDescriptor(returnType, allTypes), node.signature, null) {
private final boolean isInliningLambda = nodeRemapper.isInsideInliningLambda();
@@ -41,7 +41,7 @@ public class HashCode extends IntrinsicMethod {
StackValue receiver
) {
receiver.put(AsmTypeConstants.OBJECT_TYPE, v);
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I");
v.visitMethodInsn(Opcodes.INVOKEVIRTUAL, "java/lang/Object", "hashCode", "()I", false);
return Type.INT_TYPE;
}
}
@@ -22,18 +22,18 @@ import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.ClassReader;
import org.jetbrains.org.objectweb.asm.ClassVisitor;
import org.jetbrains.org.objectweb.asm.FieldVisitor;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import org.jetbrains.jet.lang.resolve.java.JvmClassName;
import org.jetbrains.jet.lang.resolve.kotlin.header.KotlinClassHeader;
import org.jetbrains.jet.lang.resolve.kotlin.header.ReadKotlinClassHeaderAnnotationVisitor;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.utils.UtilsPackage;
import org.jetbrains.org.objectweb.asm.ClassReader;
import org.jetbrains.org.objectweb.asm.ClassVisitor;
import org.jetbrains.org.objectweb.asm.FieldVisitor;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
import static org.jetbrains.org.objectweb.asm.ClassReader.*;
import static org.jetbrains.org.objectweb.asm.Opcodes.ASM4;
import static org.jetbrains.org.objectweb.asm.Opcodes.ASM5;
public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
private final static Logger LOG = Logger.getInstance(VirtualFileKotlinClass.class);
@@ -52,7 +52,7 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
private static Pair<JvmClassName, KotlinClassHeader> readClassNameAndHeader(@NotNull byte[] fileContents) {
final ReadKotlinClassHeaderAnnotationVisitor readHeaderVisitor = new ReadKotlinClassHeaderAnnotationVisitor();
final Ref<JvmClassName> classNameRef = Ref.create();
new ClassReader(fileContents).accept(new ClassVisitor(ASM4) {
new ClassReader(fileContents).accept(new ClassVisitor(ASM5) {
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
classNameRef.set(JvmClassName.byInternalName(name));
@@ -121,7 +121,7 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
@Override
public void loadClassAnnotations(@NotNull final AnnotationVisitor annotationVisitor) {
try {
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM4) {
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM5) {
@Override
public org.jetbrains.org.objectweb.asm.AnnotationVisitor visitAnnotation(String desc, boolean visible) {
return convertAnnotationVisitor(annotationVisitor, desc);
@@ -147,7 +147,7 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
@NotNull
private static org.jetbrains.org.objectweb.asm.AnnotationVisitor convertAnnotationVisitor(@NotNull final AnnotationArgumentVisitor v) {
return new org.jetbrains.org.objectweb.asm.AnnotationVisitor(ASM4) {
return new org.jetbrains.org.objectweb.asm.AnnotationVisitor(ASM5) {
@Override
public void visit(String name, Object value) {
v.visit(name == null ? null : Name.identifier(name), value);
@@ -174,13 +174,13 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
@Override
public void visitMembers(@NotNull final MemberVisitor memberVisitor) {
try {
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM4) {
new ClassReader(file.contentsToByteArray()).accept(new ClassVisitor(ASM5) {
@Override
public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) {
final AnnotationVisitor v = memberVisitor.visitField(Name.guess(name), desc, value);
if (v == null) return null;
return new FieldVisitor(ASM4) {
return new FieldVisitor(ASM5) {
@Override
public org.jetbrains.org.objectweb.asm.AnnotationVisitor visitAnnotation(String desc, boolean visible) {
return convertAnnotationVisitor(v, desc);
@@ -198,7 +198,7 @@ public class VirtualFileKotlinClass implements KotlinJvmBinaryClass {
final MethodAnnotationVisitor v = memberVisitor.visitMethod(Name.guess(name), desc);
if (v == null) return null;
return new MethodVisitor(ASM4) {
return new MethodVisitor(ASM5) {
@Override
public org.jetbrains.org.objectweb.asm.AnnotationVisitor visitAnnotation(String desc, boolean visible) {
return convertAnnotationVisitor(v, desc);
@@ -275,7 +275,7 @@ public class InterceptionInstrumenter {
private byte[] instrument(byte[] classData, final List<MethodInstrumenter> instrumenters) {
final ClassReader cr = new ClassReader(classData);
ClassWriter cw = new ClassWriter(cr, 0);
cr.accept(new ClassVisitor(ASM4, cw) {
cr.accept(new ClassVisitor(ASM5, cw) {
private final Map<MethodInstrumenter, String> matchedMethods = new HashMap<MethodInstrumenter, String>();
@Override
@@ -326,7 +326,7 @@ public class InterceptionInstrumenter {
final int maxStackDepth = getMaxStackDepth(name, desc, normalReturnData, enterData, exceptionData);
final boolean isConstructor = "<init>".equals(name);
return new MethodVisitor(ASM4, mv) {
return new MethodVisitor(ASM5, mv) {
private InstructionAdapter ia = null;
@@ -181,13 +181,13 @@ public abstract class AbstractCheckLocalVariablesTableTest extends TestCaseWithT
List<LocalVariable> readVariables = new ArrayList<LocalVariable>();
public Visitor() {
super(Opcodes.ASM4);
super(Opcodes.ASM5);
}
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (methodName.equals(name + desc)) {
return new MethodVisitor(Opcodes.ASM4) {
return new MethodVisitor(Opcodes.ASM5) {
@Override
public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) {
readVariables.add(new LocalVariable(name, desc, index));
@@ -164,14 +164,14 @@ public class GenerateNotNullAssertionsTest extends CodegenTestCase {
assertNotNull(file);
ClassReader reader = new ClassReader(file.asByteArray());
reader.accept(new ClassVisitor(Opcodes.ASM4) {
reader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public MethodVisitor visitMethod(
int access, final String callerName, final String callerDesc, String signature, String[] exceptions
) {
return new MethodVisitor(Opcodes.ASM4) {
return new MethodVisitor(Opcodes.ASM5) {
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
assertFalse(
"Intrinsics method is called: " + name + desc + " Caller: " + callerName + callerDesc,
"kotlin/jvm/internal/Intrinsics".equals(owner)
@@ -97,7 +97,7 @@ public class InnerClassInfoGenTest extends CodegenTestCase {
ClassReader reader = new ClassReader(bytes);
final List<InnerClassAttribute> result = new ArrayList<InnerClassAttribute>();
reader.accept(new ClassVisitor(ASM4) {
reader.accept(new ClassVisitor(ASM5) {
@Override
public void visitInnerClass(String name, String outerName, String innerName, int access) {
result.add(new InnerClassAttribute(name, outerName, innerName, access));
@@ -175,14 +175,14 @@ public class LineNumberTest extends TestCaseWithTmpdir {
final List<Label> labels = Lists.newArrayList();
final Map<Label, Integer> labels2LineNumbers = Maps.newHashMap();
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM4) {
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(Opcodes.ASM4) {
return new MethodVisitor(Opcodes.ASM5) {
private Label lastLabel;
@Override
public void visitMethodInsn(int opcode, String owner, String name, String desc) {
public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) {
if (LINE_NUMBER_FUN.equals(name)) {
assert lastLabel != null : "A function call with no preceding label";
labels.add(lastLabel);
@@ -218,10 +218,10 @@ public class LineNumberTest extends TestCaseWithTmpdir {
@NotNull
private static List<Integer> readAllLineNumbers(@NotNull ClassReader reader) {
final List<Integer> result = new ArrayList<Integer>();
reader.accept(new ClassVisitor(Opcodes.ASM4) {
reader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
return new MethodVisitor(Opcodes.ASM4) {
return new MethodVisitor(Opcodes.ASM5) {
@Override
public void visitLineNumber(int line, Label label) {
result.add(line);
@@ -125,7 +125,7 @@ public class OuterClassGenTest extends CodegenTestCase {
public OuterClassInfo getOuterClassInfo(ClassReader reader) {
final OuterClassInfo info = new OuterClassInfo();
reader.accept(new ClassVisitor(Opcodes.ASM4) {
reader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public void visitOuterClass(String owner, String name, String desc) {
info.owner = owner;
@@ -51,8 +51,8 @@ public class SourceInfoGenTest extends CodegenTestCase {
ClassReader classReader = new ClassReader(file.asByteArray());
final String [] producer = new String [1];
classReader.accept(new ClassVisitor(Opcodes.ASM4) {
final String [] producer = new String[1];
classReader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public void visitSource(String source, String debug) {
@@ -180,7 +180,7 @@ public abstract class AbstractWriteFlagsTest extends UsefulTestCase {
protected boolean isExists;
public TestClassVisitor() {
super(Opcodes.ASM4);
super(Opcodes.ASM5);
}
abstract public int getAccess();
@@ -110,7 +110,7 @@ public abstract class AbstractWriteSignatureTest extends TestCaseWithTmpdir {
ActualSignature readSignature;
public Visitor() {
super(Opcodes.ASM4);
super(Opcodes.ASM5);
}
@Override
@@ -126,7 +126,7 @@ public abstract class AbstractWriteSignatureTest extends TestCaseWithTmpdir {
public MethodVisitor visitMethod(int access, String name, final String desc, final String signature, String[] exceptions) {
if (name.equals(methodName)) {
return new MethodVisitor(Opcodes.ASM4) {
return new MethodVisitor(Opcodes.ASM5) {
@Override
public void visitEnd() {
Assert.assertNull(readSignature);
@@ -77,14 +77,14 @@ public class KotlinAbiVersionIndex extends ScalarIndexExtension<Integer> {
try {
ClassReader classReader = new ClassReader(inputData.getContent());
classReader.accept(new ClassVisitor(Opcodes.ASM4) {
classReader.accept(new ClassVisitor(Opcodes.ASM5) {
@Override
public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
if (!kotlinAnnotationsDesc.contains(desc)) {
return null;
}
annotationPresent.set(true);
return new AnnotationVisitor(Opcodes.ASM4) {
return new AnnotationVisitor(Opcodes.ASM5) {
@Override
public void visit(String name, Object value) {
if (ABI_VERSION_FIELD_NAME.equals(name)) {