commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tcu...@apache.org
Subject svn commit: r699948 - in /commons/sandbox/javaflow/trunk: ./ src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ src/test/org/apache/commons/javaflow/bytecode/transform...
Date Mon, 29 Sep 2008 01:19:18 GMT
Author: tcurdt
Date: Sun Sep 28 18:19:18 2008
New Revision: 699948

URL: http://svn.apache.org/viewvc?rev=699948&view=rev
Log:
https://issues.apache.org/jira/browse/SANDBOX-255
https://issues.apache.org/jira/browse/SANDBOX-254

needs further review of the asserts


Added:
    commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
  (with props)
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
  (with props)
Modified:
    commons/sandbox/javaflow/trunk/.project
    commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
    commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ClassAccess2.java
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractSimpleTestCase.java
    commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractStackTestCase.java

Modified: commons/sandbox/javaflow/trunk/.project
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/.project?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/.project (original)
+++ commons/sandbox/javaflow/trunk/.project Sun Sep 28 18:19:18 2008
@@ -1,23 +1,30 @@
-<?xml version="1.0" encoding="UTF-8"?>
 <projectDescription>
-	<name>commons-javaflow</name>
-	<comment></comment>
-	<projects>
-	</projects>
-	<buildSpec>
-		<buildCommand>
-			<name>org.eclipse.jdt.core.javabuilder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-		<buildCommand>
-			<name>org.maven.ide.eclipse.maven2Builder</name>
-			<arguments>
-			</arguments>
-		</buildCommand>
-	</buildSpec>
-	<natures>
-		<nature>org.eclipse.jdt.core.javanature</nature>
-		<nature>org.maven.ide.eclipse.maven2Nature</nature>
-	</natures>
-</projectDescription>
+  <name>javaflow</name>
+  <comment>The Apache Software Foundation provides support for the Apache community
of open-source software projects.
+    The Apache projects are characterized by a collaborative, consensus based development
process, an open and
+    pragmatic software license, and a desire to create high quality software that leads the
way in its field.
+    We consider ourselves not simply a group of projects sharing a server, but rather a community
of developers
+    and users.</comment>
+  <projects/>
+  <buildSpec>
+    <buildCommand>
+      <name>org.eclipse.jdt.core.javabuilder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.maven.ide.eclipse.maven2Builder</name>
+    </buildCommand>
+    <buildCommand>
+      <name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
+      <arguments>
+        <dictionary>
+          <key>LaunchConfigHandle</key>
+          <value>&lt;project&gt;/.externalToolBuilders/Maven_Ant_Builder.launch</value>
+        </dictionary>
+      </arguments>
+    </buildCommand>
+  </buildSpec>
+  <natures>
+    <nature>org.eclipse.jdt.core.javanature</nature>
+    <nature>org.maven.ide.eclipse.maven2Nature</nature>
+  </natures>
+</projectDescription>
\ No newline at end of file

Modified: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
(original)
+++ commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
Sun Sep 28 18:19:18 2008
@@ -74,17 +74,20 @@
         // verify if restoring
         Label l0 = new Label();
 
+        // PC: StackRecorder stackRecorder = StackRecorder.get();
         mv.visitMethodInsn(INVOKESTATIC, STACK_RECORDER, "get", "()L" + STACK_RECORDER +
";");
         mv.visitInsn(DUP);
         mv.visitVarInsn(ASTORE, stackRecorderVar);
         mv.visitLabel(startLabel);
 
+        // PC: if (stackRecorder != null && !stackRecorder.isRestoring) {  
         mv.visitJumpInsn(IFNULL, l0);
         mv.visitVarInsn(ALOAD, stackRecorderVar);
         mv.visitFieldInsn(GETFIELD, STACK_RECORDER, "isRestoring", "Z");
         mv.visitJumpInsn(IFEQ, l0);
 
         mv.visitVarInsn(ALOAD, stackRecorderVar);
+        // PC:    stackRecorder.popInt();
         mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, POP_METHOD + "Int", "()I");
         mv.visitTableSwitchInsn(0, fsize - 1, l0, restoreLabels);
 
@@ -97,6 +100,7 @@
 
             Frame frame = analyzer.getFrames()[analyzer.getIndex(mnode)];
 
+            // for each local variable store the value in locals popping it from the stack!
             // locals
             int lsize = frame.getLocals();
             for (int j = lsize - 1; j >= 0; j--) {
@@ -129,6 +133,16 @@
                 }
             }
 
+            if (frame instanceof MonitoringFrame) {
+                int[] monitoredLocals = ((MonitoringFrame) frame).getMonitored();
+                System.out.println(System.identityHashCode(frame)+" AMonitored locals "+monitoredLocals.length);
+                for (int j = 0; j < monitoredLocals.length; j++) {
+                    System.out.println(System.identityHashCode(frame)+" AMonitored local
"+monitoredLocals[j]);
+                    mv.visitVarInsn(ALOAD, monitoredLocals[j]);
+                    mv.visitInsn(MONITORENTER);
+                }
+            }
+
             // stack
             int argSize = Type.getArgumentTypes(mnode.desc).length;
             int ownerSize = mnode.getOpcode() == INVOKESTATIC ? 0 : 1;  // TODO
@@ -169,6 +183,7 @@
             mv.visitJumpInsn(GOTO, frameLabel);
         }
 
+        // PC: }
         // end of start block
         mv.visitLabel(l0);
     }
@@ -260,6 +275,16 @@
             mv.visitIntInsn(BIPUSH, currentIndex);  // TODO optimize to iconst_0...
             mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, "pushInt", "(I)V");
 
+            if (currentFrame instanceof MonitoringFrame) {
+                int[] monitoredLocals = ((MonitoringFrame) currentFrame).getMonitored();
+                System.out.println(System.identityHashCode(currentFrame)+" Monitored locals
"+monitoredLocals.length);
+                for (int j = 0; j < monitoredLocals.length; j++) {
+                    System.out.println(System.identityHashCode(currentFrame)+" Monitored
local "+monitoredLocals[j]);
+                    mv.visitVarInsn(ALOAD, monitoredLocals[j]);
+                    mv.visitInsn(MONITOREXIT);
+                }
+            }
+
             Type methodReturnType = Type.getReturnType(methodDesc);
             pushDefault(methodReturnType);
             mv.visitInsn(methodReturnType.getOpcode(IRETURN));

Modified: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
(original)
+++ commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAnalyzer.java
Sun Sep 28 18:19:18 2008
@@ -112,7 +112,31 @@
                         throw new RuntimeException(e.toString());
                     }
                 }
-            });
+            }) {
+
+
+                protected Frame newFrame(final int nLocals, final int nStack) {
+                    return new MonitoringFrame(nLocals, nStack);
+                }
+
+                protected Frame newFrame(final Frame src) {
+                    return new MonitoringFrame(src);
+                }
+
+                public Frame[] analyze(String owner, MethodNode m)
+                        throws AnalyzerException {
+                    System.out.println("Analyze: "+owner+"|"+m.name+"|"+m.signature+"|"+m.tryCatchBlocks);
+                    Frame[] framesa = super.analyze(owner, m);
+                    for (int i = 0; i < m.instructions.size(); i++) {
+                        int opcode = ((AbstractInsnNode) m.instructions.get(i)).getOpcode();
+                        if (opcode == MONITORENTER || opcode == MONITOREXIT) {
+                            System.out.println(i);
+                        }
+                        
+                    }
+                    return framesa;
+                }
+            };
             analyzer.analyze(className, this);
             accept(new ContinuationMethodAdapter(this));
 

Added: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java?rev=699948&view=auto
==============================================================================
--- commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
(added)
+++ commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
Sun Sep 28 18:19:18 2008
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.commons.javaflow.bytecode.transformation.asm;
+
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.tree.AbstractInsnNode;
+import org.objectweb.asm.tree.analysis.AnalyzerException;
+import org.objectweb.asm.tree.analysis.Frame;
+import org.objectweb.asm.tree.analysis.Interpreter;
+import org.objectweb.asm.tree.analysis.Value;
+
+import java.util.LinkedList;
+import java.util.List;
+
+public class MonitoringFrame extends Frame {
+    
+    // keeps track of monitored locals
+    private List monitored;
+
+    public MonitoringFrame(Frame arg0) {
+        super(arg0);
+    }
+
+    public MonitoringFrame(int arg0, int arg1) {
+        super(arg0, arg1);
+        monitored = new LinkedList();
+    }
+
+    public void execute(AbstractInsnNode insn, Interpreter interpreter)
+            throws AnalyzerException {
+        
+        if (false) {
+            super.execute(insn, interpreter);
+            return;
+        }
+        int insnOpcode = insn.getOpcode();
+        
+        if (insnOpcode == Opcodes.MONITORENTER || insnOpcode == Opcodes.MONITOREXIT) {
+            Value pop = pop();
+            interpreter.unaryOperation(insn, pop);
+
+            int local = -1;
+            for (int i = 0; i < getLocals(); i++) {
+                if (getLocal(i) == pop) local = i;
+            }
+            
+            if (local > -1) {
+                if (insnOpcode == Opcodes.MONITORENTER) {
+                    monitorEnter(local);
+                } else {
+                    monitorExit(local);
+                }
+            }
+
+        } else {
+            super.execute(insn, interpreter);
+        }
+    }
+
+    public Frame init(Frame arg0) {
+        super.init(arg0);
+        if (arg0 instanceof MonitoringFrame) {
+            monitored = new LinkedList(((MonitoringFrame)arg0).monitored);
+        } else {
+            monitored = new LinkedList();
+        }
+        return this;
+    }
+    
+    public int[] getMonitored() {
+        int[] res = new int[monitored.size()];
+        for (int i = 0; i < monitored.size(); i++) {
+            res[i] = ((Integer) monitored.get(i)).intValue();
+        }
+        return res;
+    }
+    
+    public void monitorEnter(int local) {
+        monitored.add(new Integer(local));
+    }
+    
+    public void monitorExit(int local) {
+        int index = monitored.lastIndexOf(new Integer(local));
+        if (index == -1) {
+            // throw new IllegalStateException("Monitor Exit never entered");
+        } else {
+            monitored.remove(index);
+        }
+    }
+
+}

Propchange: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/MonitoringFrame.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ClassAccess2.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ClassAccess2.java?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ClassAccess2.java
(original)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/ClassAccess2.java
Sun Sep 28 18:19:18 2008
@@ -1,10 +1,12 @@
 package org.apache.commons.javaflow.bytecode.transformation.rewrite;
 
+import org.apache.commons.javaflow.Continuation;
 
 public final class ClassAccess2 implements Runnable {
 
     public void run() {
         Object o = ClassAccess2.class;
+        Continuation.suspend();
     }
     
 }

Added: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java?rev=699948&view=auto
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
(added)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
Sun Sep 28 18:19:18 2008
@@ -0,0 +1,70 @@
+package org.apache.commons.javaflow.bytecode.transformation.rewrite;
+
+import org.apache.commons.javaflow.Continuation;
+
+public final class NestedSynchronized implements Runnable {
+
+        public boolean a = false;
+        public boolean b = false;
+        public boolean c = false;
+        public boolean d = false;
+        public boolean e = false;
+        public boolean f = false;
+        public boolean g = false;
+        public boolean h = false;
+        public boolean i = false;
+        public boolean j = false;
+        
+        private Object o = new Object();
+
+        public void run() {		
+                try {
+                    o.notify();
+                } catch (IllegalMonitorStateException e) {
+                    a = true;
+                }
+                Continuation.suspend();
+                try {
+                    o.notify();
+                } catch (IllegalMonitorStateException e) {
+                    b = true;
+                }
+                synchronized(o) {
+                        c = true;
+                        o.notify();
+                        method();
+                        o.notify();
+                        h = true;
+                }
+                try {
+                    o.notify();
+                } catch (IllegalMonitorStateException e) {
+                    i = true;
+                }
+                Continuation.suspend();
+                try {
+                    o.notify();
+                } catch (IllegalMonitorStateException e) {
+                    j = true;
+                }
+        }
+
+        public void method() {
+            try {
+                d = true;
+                o.notify();
+                nested();
+            } finally {
+                o.notify();
+                g = true;
+            }
+        }
+
+        public void nested() {
+            e = true;
+            Continuation.suspend();
+            o.notify();
+            f = true;
+        }
+
+}

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/rewrite/NestedSynchronized.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractSimpleTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractSimpleTestCase.java?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractSimpleTestCase.java
(original)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractSimpleTestCase.java
Sun Sep 28 18:19:18 2008
@@ -28,7 +28,7 @@
         assertFalse(r.f);
 
         c = Continuation.continueWith(c);
-        assertTrue(c != null);
+        assertTrue(c == null);
         assertTrue(r.a);
         assertTrue(r.b);
         assertFalse(r.c);
@@ -39,9 +39,19 @@
         c = Continuation.continueWith(c);
         assertTrue(c != null);
         assertTrue(r.a);
-        assertTrue(r.b);
-        assertFalse(r.c);
-        assertFalse(r.d);
+        assertFalse(r.b);
+        assertTrue(r.c);
+        assertTrue(r.d);
+        assertTrue(r.e);
+        assertFalse(r.f);    
+
+
+        c = Continuation.continueWith(c);
+        assertTrue(c == null);
+        assertTrue(r.a);
+        assertFalse(r.b);
+        assertTrue(r.c);
+        assertTrue(r.d);
         assertTrue(r.e);
         assertTrue(r.f);    
     }
@@ -92,7 +102,7 @@
         assertFalse(r.f);
 
         c = Continuation.continueWith(c);
-        assertTrue(c != null);
+        assertTrue(c == null);
         assertTrue(r.a);
         assertTrue(r.b);
         assertTrue(r.c);

Modified: commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractStackTestCase.java
URL: http://svn.apache.org/viewvc/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractStackTestCase.java?rev=699948&r1=699947&r2=699948&view=diff
==============================================================================
--- commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractStackTestCase.java
(original)
+++ commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/bytecode/transformation/tests/AbstractStackTestCase.java
Sun Sep 28 18:19:18 2008
@@ -9,6 +9,6 @@
     public void testStack() throws Exception {
         final Runnable r = new Stack();
         final Continuation c = Continuation.startWith(r);
-        assertTrue(c == null);
+        assertNotNull(c);
     }
 }



Mime
View raw message