Author: kohsuke
Date: Tue Dec 27 20:56:00 2005
New Revision: 359395

URL: http://svn.apache.org/viewcvs?rev=359395&view=rev
Log:
eliminated isCapturing() and isRestoring() in favor of the direct field access.
The problem with having methods was that it causes debugger to go into those 
methods
(when debugging instrumented code.) This makes it awkward for our users to debug
their own code. direct field access doesn't have this problem.


Modified:
    
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
    
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
    
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java

Modified: 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java?rev=359395&r1=359394&r2=359395&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
 (original)
+++ 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/StackRecorder.java
 Tue Dec 27 20:56:00 2005
@@ -26,14 +26,30 @@
  * @author Kohsuke Kawaguchi
  */
 public final class StackRecorder extends Stack {
-    
-    private static final Log log = LogFactory.getLog(StackRecorder.class);    
+
+    private static final Log log = LogFactory.getLog(StackRecorder.class);
     private static final long serialVersionUID = 2L;
-    
+
     private static final ThreadLocal threadMap = new ThreadLocal();
 
-    private transient boolean restoring = false;
-    private transient boolean capturing = false;
+    /**
+     * True, if the continuation restores the previous stack trace to the last
+     * invocation of suspend().
+     *
+     * <p>
+     * This field is accessed from the byte code injected into application 
code,
+     * and therefore defining a wrapper get method makes it awkward to
+     * step through the user code. That's why this field is public.
+     */
+    public transient boolean isRestoring = false;
+
+    /**
+     * True, is the continuation freeze the strack trace, and stops the
+     * continuation.
+     *
+     * @see #isRestoring
+     */
+    public transient boolean isCapturing = false;
 
     /** Context object given by the user */
     private transient Object context;
@@ -60,40 +76,24 @@
             throw new IllegalStateException("No continuation is running");
         }
 
-        stackRecorder.capturing = !stackRecorder.restoring;
-        stackRecorder.restoring = false;
-    }
-
-    /**
-     * True, if the continuation restores the previous stack trace to the last
-     * invocation of suspend().
-     */
-    public boolean isRestoring() {
-        return restoring;
-    }
-
-    /**
-     * True, is the continuation freeze the strack trace, and stops the
-     * continuation.
-     */
-    public boolean isCapturing() {
-        return capturing;
+        stackRecorder.isCapturing = !stackRecorder.isRestoring;
+        stackRecorder.isRestoring = false;
     }
 
     public StackRecorder execute(final Object context) {
         final StackRecorder old = registerThread();
         try {
-            restoring = !isEmpty(); // start restoring if we have a filled 
stack
+            isRestoring = !isEmpty(); // start restoring if we have a filled 
stack
             this.context = context;
             
-            if (restoring) {
+            if (isRestoring) {
                 log.debug("Restoring state of " + 
ReflectionUtils.getClassName(runnable) + "/" + 
ReflectionUtils.getClassLoaderName(runnable));
             }
             
             log.debug("calling runnable");
             runnable.run();
 
-            if (capturing) {
+            if (isCapturing) {
                 if(isEmpty()) {
                     // if we were really capturing the stack, at least we 
should have
                     // one object in the reference stack. Otherwise, it 
usually means

Modified: 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java?rev=359395&r1=359394&r2=359395&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
 (original)
+++ 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/asm/ContinuationMethodAdapter.java
 Tue Dec 27 20:56:00 2005
@@ -80,7 +80,7 @@
 
     mv.visitJumpInsn(IFNULL, l0);
     mv.visitVarInsn(ALOAD, stackRecorderVar);
-    mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, "isRestoring", "()Z");
+    mv.visitFieldInsn(GETFIELD, STACK_RECORDER, "isRestoring", "Z");
     mv.visitJumpInsn(IFEQ, l0);
     
     mv.visitVarInsn(ALOAD, stackRecorderVar);
@@ -189,7 +189,7 @@
       mv.visitVarInsn(ALOAD, stackRecorderVar);
       mv.visitJumpInsn(IFNULL, fl);
       mv.visitVarInsn(ALOAD, stackRecorderVar);
-      mv.visitMethodInsn(INVOKEVIRTUAL, STACK_RECORDER, "isCapturing", "()Z");
+      mv.visitFieldInsn(GETFIELD, STACK_RECORDER, "isCapturing", "Z");
       mv.visitJumpInsn(IFEQ, fl);
       
       // save stack

Modified: 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
URL: 
http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java?rev=359395&r1=359394&r2=359395&view=diff
==============================================================================
--- 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
 (original)
+++ 
jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/transformation/bcel/BcelClassTransformer.java
 Tue Dec 27 20:56:00 2005
@@ -90,8 +90,8 @@
     private static final String STACK_METHOD = "get";
     private static final String POP_METHOD = "pop";
     private static final String PUSH_METHOD = "push";
-    private static final String RESTORING_METHOD = "isRestoring";
-    private static final String CAPURING_METHOD = "isCapturing";
+    private static final String RESTORING_FIELD = "isRestoring";
+    private static final String CAPTURING_FIELD = "isCapturing";
 
     private boolean currentMethodStatic = false;
     public static boolean debug = false;
@@ -459,7 +459,7 @@
 
             // test if the continuation should be restored
             insList.insert(new IFEQ(firstIns));
-            insList.insert(insFactory.createInvoke(STACK_RECORDER_CLASS, 
RESTORING_METHOD, Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
+            insList.insert(insFactory.createFieldAccess(STACK_RECORDER_CLASS, 
RESTORING_FIELD, Type.BOOLEAN, Constants.GETFIELD));
             insList.insert(loadStackRecorder);
 
             // test if no current continuation exists
@@ -624,7 +624,7 @@
         insList.insert(new IFEQ(handle.getNext()));
 
         // test if the continuation should be captured after the invocation
-        insList.insert(insFactory.createInvoke(STACK_RECORDER_CLASS, 
CAPURING_METHOD, Type.BOOLEAN, Type.NO_ARGS, Constants.INVOKEVIRTUAL));
+        insList.insert(insFactory.createFieldAccess(STACK_RECORDER_CLASS, 
CAPTURING_FIELD, Type.BOOLEAN, Constants.GETFIELD));
         insList.insert(loadStackRecorder);
 
         // test if continuation exists



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to