[Jython-checkins] jython: Adding the changes related to the ASM4 update.

frank.wierzbicki jython-checkins at python.org
Wed Mar 14 04:09:30 CET 2012


http://hg.python.org/jython/rev/751fc2258335
changeset:   6335:751fc2258335
user:        Shashank Bharadwaj <shanka.mns at gmail.com>
date:        Mon Mar 12 16:17:00 2012 -0700
summary:
  Adding the changes related to the ASM4 update.
This changeset does not contain CodeCompiler change since I think that is only required when we change the generated class file version to Java7
The changes made under the jffi module are just so that jython builds, maybe we shoud modify the jffi upstream?
Also updating the build and classpath files

files:
  .classpath                                                        |   4 +-
  build.xml                                                         |  16 +-
  src/org/python/compiler/Code.java                                 |  13 +-
  src/org/python/core/AnnotationReader.java                         |  11 +-
  src/org/python/expose/generate/ExposedFieldFinder.java            |   4 +-
  src/org/python/expose/generate/ExposedMethodFinder.java           |   9 +-
  src/org/python/expose/generate/ExposedTypeProcessor.java          |   8 +-
  src/org/python/expose/generate/RestrictiveAnnotationVisitor.java  |  11 +-
  src/org/python/modules/jffi/AsmClassBuilder.java                  |   1 -
  src/org/python/modules/jffi/EmptyVisitor.java                     |  93 ++++++++++
  src/org/python/modules/jffi/SkinnyMethodAdapter.java              |  15 +-
  tests/java/org/python/expose/generate/ExposeMethodFinderTest.java |   6 +-
  12 files changed, 154 insertions(+), 37 deletions(-)


diff --git a/.classpath b/.classpath
--- a/.classpath
+++ b/.classpath
@@ -12,9 +12,9 @@
 	<classpathentry kind="lib" path="extlibs/mysql-connector-java-5.1.6.jar"/>
 	<classpathentry kind="lib" path="extlibs/postgresql-8.3-603.jdbc4.jar"/>
 	<classpathentry kind="lib" path="extlibs/servlet-api-2.5.jar"/>
-	<classpathentry kind="lib" path="extlibs/asm-4.0.jar"/>
+	<classpathentry kind="lib" path="extlibs/asm-4.0.jar" />
 	<classpathentry kind="lib" path="extlibs/asm-commons-4.0.jar"/>
-	<classpathentry kind="lib" path="extlibs/asm-util-4.0.jar"/>
+	<classpathentry kind="lib" path="extlibs/asm-util-4.0.jar" />
 	<classpathentry kind="var" path="ANT_HOME/lib/ant.jar"/>
 	<classpathentry kind="lib" path="extlibs/antlr-runtime-3.1.3.jar"/>
 	<classpathentry kind="lib" path="extlibs/asm-3.1.jar"/>
diff --git a/build.xml b/build.xml
--- a/build.xml
+++ b/build.xml
@@ -186,9 +186,9 @@
             <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" />
             <pathelement path="${extlibs.dir}/livetribe-jsr223-2.0.5.jar" />
 
-            <pathelement path="${extlibs.dir}/asm-3.1.jar" />
-            <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" />
-            <pathelement path="${extlibs.dir}/asm-util-3.1.jar" />
+            <pathelement path="${extlibs.dir}/asm-4.0.jar" />
+            <pathelement path="${extlibs.dir}/asm-commons-4.0.jar" />
+            <pathelement path="${extlibs.dir}/asm-util-4.0.jar" />
             <pathelement path="${extlibs.dir}/constantine.jar" />
             <pathelement path="${extlibs.dir}/guava-r07.jar" />
             <pathelement path="${extlibs.dir}/jaffl.jar"/>
@@ -219,8 +219,8 @@
 
         <path id="test.classpath">
             <path refid="main.classpath"/>
-            <pathelement path="${extlibs.dir}/asm-commons-3.1.jar" />
-            <pathelement path="${extlibs.dir}/asm-util-3.1.jar" />
+            <pathelement path="${extlibs.dir}/asm-commons-4.0.jar" />
+            <pathelement path="${extlibs.dir}/asm-util-4.0.jar" />
             <pathelement path="${extlibs.dir}/junit-3.8.2.jar" />
             <pathelement path="${exposed.dir}" />
             <pathelement path="${compile.dir}" />
@@ -618,9 +618,9 @@
             <zipfileset src="${dist.dir}/${jython.dev.jar}"/>
             <zipfileset src="extlibs/antlr-runtime-3.1.3.jar"/>
             <rule pattern="org.antlr.runtime.**" result="org.python.antlr.runtime. at 1"/>
-            <zipfileset src="extlibs/asm-3.1.jar"/>
-            <zipfileset src="extlibs/asm-commons-3.1.jar"/>
-            <zipfileset src="extlibs/asm-util-3.1.jar"/>
+            <zipfileset src="extlibs/asm-4.0.jar"/>
+            <zipfileset src="extlibs/asm-commons-4.0.jar"/>
+            <zipfileset src="extlibs/asm-util-4.0.jar"/>
             <rule pattern="org.objectweb.asm.**" result="org.python.objectweb.asm. at 1"/>
             <zipfileset src="extlibs/guava-r07.jar"/>
             <rule pattern="com.google.**" result="org.python.google. at 1"/>
diff --git a/src/org/python/compiler/Code.java b/src/org/python/compiler/Code.java
--- a/src/org/python/compiler/Code.java
+++ b/src/org/python/compiler/Code.java
@@ -5,11 +5,12 @@
 
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
+import org.objectweb.asm.Handle;
 import org.objectweb.asm.Label;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 
-class Code implements MethodVisitor, Opcodes {
+class Code extends MethodVisitor implements Opcodes {
     MethodVisitor mv;
     String sig;
     String locals[];
@@ -21,6 +22,7 @@
     //XXX: I'd really like to get sig and access out of here since MethodVistitor
     //     should already have this information.
     public Code(MethodVisitor mv, String sig, int access) {
+        super(ASM4);
         this.mv = mv;
         this.sig = sig;
         nlocals = -sigSize(sig, false);
@@ -163,7 +165,7 @@
         return mv.visitParameterAnnotation(arg0, arg1, arg2);
     }
 
-    public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label[] arg3) {
+    public void visitTableSwitchInsn(int arg0, int arg1, Label arg2, Label... arg3) {
         mv.visitTableSwitchInsn(arg0, arg1, arg2, arg3);
     }
 
@@ -598,4 +600,11 @@
     public void setline(int line) {
         mv.visitLineNumber(line, new Label());
     }
+
+    @Override
+    public void visitInvokeDynamicInsn(String name, String descriptor, Handle bsmHandle, 
+                                       Object... bmsArgs) {
+        mv.visitInvokeDynamicInsn(name, descriptor, bsmHandle, bmsArgs);
+    }
+    
 }
diff --git a/src/org/python/core/AnnotationReader.java b/src/org/python/core/AnnotationReader.java
--- a/src/org/python/core/AnnotationReader.java
+++ b/src/org/python/core/AnnotationReader.java
@@ -8,7 +8,8 @@
 
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.ClassReader;
-import org.objectweb.asm.commons.EmptyVisitor;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.Opcodes;
 
 /**
  * This class reads a classfile from a byte array and pulls out the value of the class annotation
@@ -19,7 +20,7 @@
  * cost too much, we will want to implement a special purpose ClassReader that only reads out the
  * APIVersion annotation I think.
  */
-public class AnnotationReader extends EmptyVisitor {
+public class AnnotationReader extends ClassVisitor {
 
     private boolean nextVisitIsVersion = false;
     private boolean nextVisitIsMTime = false;
@@ -32,6 +33,7 @@
      * @throws IOException - if the classfile is malformed.
      */
     public AnnotationReader(byte[] data) throws IOException {
+        super(Opcodes.ASM4);
         ClassReader r;
         try {
             r = new ClassReader(data);
@@ -43,11 +45,12 @@
         }
         r.accept(this, 0);
     }
-
+    
+    @Override
     public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
         nextVisitIsVersion = desc.equals("Lorg/python/compiler/APIVersion;");
         nextVisitIsMTime = desc.equals("Lorg/python/compiler/MTime;");
-        return this;
+        return super.visitAnnotation(desc, visible);
     }
 
     public void visit(String name, Object value) {
diff --git a/src/org/python/expose/generate/ExposedFieldFinder.java b/src/org/python/expose/generate/ExposedFieldFinder.java
--- a/src/org/python/expose/generate/ExposedFieldFinder.java
+++ b/src/org/python/expose/generate/ExposedFieldFinder.java
@@ -3,8 +3,9 @@
 import org.objectweb.asm.AnnotationVisitor;
 import org.objectweb.asm.Attribute;
 import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.Opcodes;
 
-public abstract class ExposedFieldFinder implements FieldVisitor, PyTypes {
+public abstract class ExposedFieldFinder extends FieldVisitor implements PyTypes {
 
     private String fieldName;
 
@@ -13,6 +14,7 @@
     private String doc;
 
     public ExposedFieldFinder(String name, FieldVisitor delegate) {
+        super(Opcodes.ASM4, delegate);
         fieldName = name;
         this.delegate = delegate;
     }
diff --git a/src/org/python/expose/generate/ExposedMethodFinder.java b/src/org/python/expose/generate/ExposedMethodFinder.java
--- a/src/org/python/expose/generate/ExposedMethodFinder.java
+++ b/src/org/python/expose/generate/ExposedMethodFinder.java
@@ -4,7 +4,6 @@
 
 import org.python.expose.MethodType;
 import org.objectweb.asm.AnnotationVisitor;
-import org.objectweb.asm.MethodAdapter;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
@@ -15,7 +14,7 @@
  * annotation is visited, calls handleResult with the exposer constructed with that annotation. Only
  * one of the handleResult methods will be called, if any.
  */
-public abstract class ExposedMethodFinder extends MethodAdapter implements PyTypes, Opcodes {
+public abstract class ExposedMethodFinder extends MethodVisitor implements PyTypes, Opcodes {
 
     private Exposer newExp;
 
@@ -36,7 +35,7 @@
                                String desc,
                                String[] exceptions,
                                MethodVisitor delegate) {
-        super(delegate);
+        super(Opcodes.ASM4, delegate);
         this.typeName = typeName;
         this.onType = onType;
         this.access = access;
@@ -136,6 +135,10 @@
 
     class ExposedMethodVisitor extends RestrictiveAnnotationVisitor {
 
+        public ExposedMethodVisitor() {
+            super();
+        }
+
         @Override
         public void visit(String name, Object value) {
             if (name.equals("doc")) {
diff --git a/src/org/python/expose/generate/ExposedTypeProcessor.java b/src/org/python/expose/generate/ExposedTypeProcessor.java
--- a/src/org/python/expose/generate/ExposedTypeProcessor.java
+++ b/src/org/python/expose/generate/ExposedTypeProcessor.java
@@ -8,12 +8,10 @@
 
 import org.python.expose.ExposedType;
 import org.objectweb.asm.AnnotationVisitor;
-import org.objectweb.asm.ClassAdapter;
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.FieldVisitor;
-import org.objectweb.asm.MethodAdapter;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
@@ -105,7 +103,7 @@
     /**
      * The actual visitor that runs over the bytecode and figures out what to expose.
      */
-    private final class TypeProcessor extends ClassAdapter {
+    private final class TypeProcessor extends ClassVisitor {
 
         private Type baseType = OBJECT;
 
@@ -116,7 +114,7 @@
         private boolean generatedStaticBlock;
 
         private TypeProcessor(ClassVisitor cv) {
-            super(cv);
+            super(Opcodes.ASM4, cv);
         }
 
         @Override
@@ -227,7 +225,7 @@
                                                                            desc,
                                                                            signature,
                                                                            exceptions);
-                return new MethodAdapter(passthroughVisitor) {
+                return new MethodVisitor(Opcodes.ASM4, passthroughVisitor) {
 
                     @Override
                     public void visitCode() {
diff --git a/src/org/python/expose/generate/RestrictiveAnnotationVisitor.java b/src/org/python/expose/generate/RestrictiveAnnotationVisitor.java
--- a/src/org/python/expose/generate/RestrictiveAnnotationVisitor.java
+++ b/src/org/python/expose/generate/RestrictiveAnnotationVisitor.java
@@ -1,12 +1,21 @@
 package org.python.expose.generate;
 
 import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.Opcodes;
 
 /**
  * An Annotation visitor that throws an IllegalArgumentException if it visits anything other than
  * visitEnd. Should be subclasses by something interested in only certain events.
  */
-public class RestrictiveAnnotationVisitor implements AnnotationVisitor {
+public class RestrictiveAnnotationVisitor extends AnnotationVisitor {
+
+    public RestrictiveAnnotationVisitor(int arg0) {
+        super(arg0);
+    }
+
+    public RestrictiveAnnotationVisitor() {
+        this(Opcodes.ASM4);
+    }
 
     public AnnotationVisitor visitAnnotation(String name, String desc) {
         throw new IllegalArgumentException("Unknown annotation field '" + name + "'");
diff --git a/src/org/python/modules/jffi/AsmClassBuilder.java b/src/org/python/modules/jffi/AsmClassBuilder.java
--- a/src/org/python/modules/jffi/AsmClassBuilder.java
+++ b/src/org/python/modules/jffi/AsmClassBuilder.java
@@ -3,7 +3,6 @@
 import org.objectweb.asm.ClassReader;
 import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.ClassWriter;
-import org.objectweb.asm.commons.EmptyVisitor;
 
 import java.io.PrintWriter;
 import java.lang.reflect.Constructor;
diff --git a/src/org/python/modules/jffi/EmptyVisitor.java b/src/org/python/modules/jffi/EmptyVisitor.java
new file mode 100644
--- /dev/null
+++ b/src/org/python/modules/jffi/EmptyVisitor.java
@@ -0,0 +1,93 @@
+package org.python.modules.jffi;
+
+import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.FieldVisitor;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+
+
+public class EmptyVisitor extends ClassVisitor {
+
+    AnnotationVisitor av = new AnnotationVisitor(Opcodes.ASM4) {
+
+        @Override
+        public AnnotationVisitor visitAnnotation(
+            String name,
+            String desc)
+        {
+            return this;
+        }
+
+        @Override
+        public AnnotationVisitor visitArray(String name) {
+            return this;
+        }
+    };
+
+    public EmptyVisitor() {
+        super(Opcodes.ASM4);
+    }
+
+    @Override
+    public AnnotationVisitor visitAnnotation(
+        String desc,
+        boolean visible)
+    {
+        return av;
+    }
+
+    @Override
+    public FieldVisitor visitField(
+        int access,
+        String name,
+        String desc,
+        String signature,
+        Object value)
+    {
+        return new FieldVisitor(Opcodes.ASM4) {
+
+            @Override
+            public AnnotationVisitor visitAnnotation(
+                String desc,
+                boolean visible)
+            {
+                return av;
+            }
+        };
+    }
+
+    @Override
+    public MethodVisitor visitMethod(
+        int access,
+        String name,
+        String desc,
+        String signature,
+        String[] exceptions)
+    {
+        return new MethodVisitor(Opcodes.ASM4) {
+
+            @Override
+            public AnnotationVisitor visitAnnotationDefault() {
+                return av;
+            }
+
+            @Override
+            public AnnotationVisitor visitAnnotation(
+                String desc,
+                boolean visible)
+            {
+                return av;
+            }
+
+            @Override
+            public AnnotationVisitor visitParameterAnnotation(
+                int parameter,
+                String desc,
+                boolean visible)
+            {
+                return av;
+            }
+        };
+    }
+}
\ No newline at end of file
diff --git a/src/org/python/modules/jffi/SkinnyMethodAdapter.java b/src/org/python/modules/jffi/SkinnyMethodAdapter.java
--- a/src/org/python/modules/jffi/SkinnyMethodAdapter.java
+++ b/src/org/python/modules/jffi/SkinnyMethodAdapter.java
@@ -10,11 +10,11 @@
 package org.python.modules.jffi;
 
 import org.objectweb.asm.*;
+import org.objectweb.asm.util.ASMifier;
 import org.objectweb.asm.util.TraceMethodVisitor;
 
 import java.io.PrintStream;
 import java.io.PrintWriter;
-import java.util.Map;
 
 import static org.python.modules.jffi.CodegenUtils.*;
 
@@ -22,7 +22,7 @@
  *
  * @author headius
  */
-public class SkinnyMethodAdapter implements MethodVisitor, Opcodes {
+public class SkinnyMethodAdapter extends MethodVisitor implements Opcodes {
     private final static boolean DEBUG = Boolean.getBoolean("jython.compile.dump");
     private MethodVisitor method;
     private String name;
@@ -30,16 +30,19 @@
     
     /** Creates a new instance of SkinnyMethodAdapter */
     public SkinnyMethodAdapter(MethodVisitor method) {
+    	super(Opcodes.ASM4);
         setMethodVisitor(method);
     }
 
     public SkinnyMethodAdapter(ClassVisitor cv, int flags, String name, String signature, String something, String[] exceptions) {
+    	super(Opcodes.ASM4);
         setMethodVisitor(cv.visitMethod(flags, name, signature, something, exceptions));
         this.cv = cv;
         this.name = name;
     }
     
     public SkinnyMethodAdapter() {
+    	super(Opcodes.ASM4);
     }
     
     public MethodVisitor getMethodVisitor() {
@@ -48,7 +51,7 @@
     
     public void setMethodVisitor(MethodVisitor mv) {
         if (DEBUG) {
-            this.method = new TraceMethodVisitor(mv);
+            this.method = new TraceMethodVisitor(mv, new ASMifier());
         } else {
             this.method = mv;
         }
@@ -530,7 +533,7 @@
             } else {
                 pw.write("*** Dumping ***\n");
             }
-            ((TraceMethodVisitor)getMethodVisitor()).print(pw);
+            ((TraceMethodVisitor)getMethodVisitor()).p.print(pw);
             pw.flush();
         }
         getMethodVisitor().visitMaxs(1, 1);
@@ -865,7 +868,7 @@
     }
 
     public void visitTableSwitchInsn(int arg0, int arg1, Label arg2,
-                                     Label[] arg3) {
+                                     Label... arg3) {
         getMethodVisitor().visitTableSwitchInsn(arg0, arg1, arg2, arg3);
     }
 
@@ -895,7 +898,7 @@
         if (DEBUG) {
             PrintWriter pw = new PrintWriter(System.out);
             pw.write("*** Dumping ***\n");
-            ((TraceMethodVisitor)getMethodVisitor()).print(pw);
+            ((TraceMethodVisitor)getMethodVisitor()).p.print(pw);
             pw.flush();
         }
         getMethodVisitor().visitMaxs(arg0, arg1);
diff --git a/tests/java/org/python/expose/generate/ExposeMethodFinderTest.java b/tests/java/org/python/expose/generate/ExposeMethodFinderTest.java
--- a/tests/java/org/python/expose/generate/ExposeMethodFinderTest.java
+++ b/tests/java/org/python/expose/generate/ExposeMethodFinderTest.java
@@ -3,11 +3,9 @@
 import junit.framework.TestCase;
 
 import org.objectweb.asm.AnnotationVisitor;
+import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.Type;
-import org.objectweb.asm.commons.EmptyVisitor;
-import org.python.expose.ExposedMethod;
-import org.python.expose.ExposedNew;
 
 public class ExposeMethodFinderTest extends TestCase implements Opcodes, PyTypes {
 
@@ -18,7 +16,7 @@
                                        methodName,
                                        descriptor,
                                        null,
-                                       new EmptyVisitor()) {
+                                       new MethodVisitor(Opcodes.ASM4) {}) {
 
             @Override
             public void handleResult(InstanceMethodExposer exposer) {

-- 
Repository URL: http://hg.python.org/jython


More information about the Jython-checkins mailing list