commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kohs...@apache.org
Subject svn commit: r360309 - /jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
Date Sat, 31 Dec 2005 16:08:21 GMT
Author: kohsuke
Date: Sat Dec 31 08:08:18 2005
New Revision: 360309

URL: http://svn.apache.org/viewcvs?rev=360309&view=rev
Log:
SimpleVerifier assumes that the types involved in the computation is loadable through Class.forName(),
which isn't true when we are running inside Ant.

The correct computation would require us to parse referenced types (through a pluggable resolver.)
For now, I'm just replacing it with BasicVerifier.

Given that the purpose of this part of the code is just to check that we generated the right
code, perhaps we can remove it altogether in the production system?

i.e.,

if(DEBUG) {
   ... run a verifier
}

Modified:
    jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java

Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java?rev=360309&r1=360308&r2=360309&view=diff
==============================================================================
--- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
(original)
+++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
Sat Dec 31 08:08:18 2005
@@ -39,6 +39,7 @@
 import org.objectweb.asm.tree.analysis.DataflowValue;
 import org.objectweb.asm.tree.analysis.Frame;
 import org.objectweb.asm.tree.analysis.SimpleVerifier;
+import org.objectweb.asm.tree.analysis.BasicVerifier;
 
 
 /**
@@ -50,22 +51,22 @@
     protected final String className;
     protected final ClassVisitor cv;
     protected final MethodVisitor mv;
-    
+
     protected final List labels = new ArrayList();
     protected final List nodes = new ArrayList();
     protected final List methods = new ArrayList();
-    
+
     protected Analyzer analyzer;
-    
-    
-    public ContinuationMethodAnalyzer(String className, ClassVisitor cv, 
-            MethodVisitor mv, int access, String name, String desc, String signature, String[]
exceptions) {
+
+
+    public ContinuationMethodAnalyzer(String className, ClassVisitor cv,
+                                      MethodVisitor mv, int access, String name, String desc,
String signature, String[] exceptions) {
         super( access, name, desc, signature, exceptions);
         this.className = className;
         this.cv = cv;
         this.mv = mv;
     }
-    
+
     public void visitMethodInsn( int opcode, String owner, String name, String desc) {
       MethodInsnNode mnode = new MethodInsnNode(opcode, owner, name, desc);
       if(opcode == INVOKESPECIAL || "<init>".equals(name)) {
@@ -79,7 +80,7 @@
       }
       instructions.add(mnode);
     }
-    
+
     public void visitEnd() {
         if(instructions.size()==0 || labels.size()==0) {
           accept(mv);
@@ -89,10 +90,10 @@
         try {
           moveNew();
 
-          analyzer = new Analyzer(new SimpleVerifier());
+          analyzer = new Analyzer(new BasicVerifier());
           analyzer.analyze(className, this);
           accept(new ContinuationMethodAdapter(this));
-        
+
         } catch(AnalyzerException ex) {
           // TODO log the error or fail?
           ex.printStackTrace();
@@ -105,9 +106,9 @@
       DataflowInterpreter i = new DataflowInterpreter();
       Analyzer a = new Analyzer(i);
       a.analyze(className, this);
-      
+
       HashMap movable = new HashMap();
-      
+
       Frame[] frames = a.getFrames();
       for( int j = 0; j < methods.size(); j++) {
           MethodInsnNode mnode = (MethodInsnNode) methods.get(j);
@@ -115,7 +116,7 @@
           int n = a.getIndex(mnode);
           Frame f = frames[n];
           Type[] args = Type.getArgumentTypes(mnode.desc);
-          
+
           DataflowValue v = (DataflowValue) f.getStack(f.getStackSize()-args.length-1);
           Set insns = v.insns;
           for( Iterator it = insns.iterator(); it.hasNext();) {
@@ -131,19 +132,19 @@
             }
           }
       }
-      
+
       for( Iterator it = movable.entrySet().iterator(); it.hasNext();) {
-          Map.Entry e = (Map.Entry) it.next();            
-          AbstractInsnNode node1 = (AbstractInsnNode) e.getKey(); 
+          Map.Entry e = (Map.Entry) it.next();
+          AbstractInsnNode node1 = (AbstractInsnNode) e.getKey();
           int n1 = instructions.indexOf(node1);
           AbstractInsnNode node2 = (AbstractInsnNode) instructions.get(n1+1);
           boolean hasCopy = node2.getOpcode()==DUP;
-          
+
           instructions.remove(node1);  // NEW              
           if(hasCopy) {
               instructions.remove(node2);  // DUP
           }
-          
+
           MethodInsnNode mnode = (MethodInsnNode) e.getValue();
           int nm = instructions.indexOf(mnode);
 
@@ -157,7 +158,7 @@
               varOffset += type.getSize();
           }
           maxLocals = varOffset;
-          
+
           instructions.add(nm++, node1);  // NEW
           if(hasCopy) {
               instructions.add(nm++, node2);  // DUP
@@ -176,7 +177,7 @@
           }
       }
     }
-    
+
     // TODO
     boolean needsFrameGuard( int opcode, String owner, String name, String desc ) {
       if (opcode == Opcodes.INVOKEINTERFACE ||



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message