You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by WHIRLYCOTT <ph...@whirlycott.com> on 2005/02/01 02:41:01 UTC

Re: svn commit: r149313 - in jakarta/commons/sandbox/javaflow/trunk/src: java/org/apache/commons/javaflow/ java/org/apache/commons/javaflow/bytecode/bcel/ test/org/apache/commons/javaflow/ test/org/apache/commons/javaflow/testcode/

Closing an OutputStream twice is a bug or is it indeed nitpicking? ;)

I was thinking that it might make sense for me to work on some docs as 
well... might be a good opportunity for me to dig deeper through things 
as well as put down in words what I'm seeing and learn a few things from 
you about the overall design.  Thoughts?

phil.

tcurdt@apache.org wrote:
> Author: tcurdt
> Date: Mon Jan 31 14:53:31 2005
> New Revision: 149313
> 
> URL: http://svn.apache.org/viewcvs?view=rev&rev=149313
> Log:
> improved the testcase as suggested by phil http://issues.apache.org/bugzilla/show_bug.cgi?id=33313
> some nitpicking
> 
> 
> Modified:
>     jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
>     jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java
>     jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java
>     jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java
>     jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java
> 
> Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java?view=diff&r1=149312&r2=149313
> ==============================================================================
> --- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java (original)
> +++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/Continuation.java Mon Jan 31 14:53:31 2005
> @@ -30,7 +30,7 @@
>   *
>   * @author <a href="mailto:stephan@apache.org">Stephan Michels</a>
>   * @author <a href="mailto:tcurdt@apache.org">Torsten Curdt</a>
> - * @version CVS $Id:$
> + * @version CVS $Id$
>   */
>  public class Continuation implements Serializable {
>  
> @@ -96,6 +96,7 @@
>          final Method method = context.getMethod();
>  
>          try {
> +
>              method.invoke(instance, new Object[0]);
>  
>          } catch (final Exception e) {
> 
> Modified: jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java?view=diff&r1=149312&r2=149313
> ==============================================================================
> --- jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java (original)
> +++ jakarta/commons/sandbox/javaflow/trunk/src/java/org/apache/commons/javaflow/bytecode/bcel/BcelClassTransformer.java Mon Jan 31 14:53:31 2005
> @@ -16,6 +16,7 @@
>  package org.apache.commons.javaflow.bytecode.bcel;
>  
>  import java.io.FileOutputStream;
> +import java.io.IOException;
>  import java.util.ArrayList;
>  import java.util.Vector;
>  
> @@ -105,24 +106,46 @@
>          final ClassGen clazzGen = new ClassGen(javaClazz);
>          final ConstantPoolGen cp = clazzGen.getConstantPool();
>  
> -        final String path = clazzGen.getClassName(); //.replace('.', '/');
> +        final String path = clazzGen.getClassName();
>  
> +        FileOutputStream out = null;
> +        
>          final byte[] orig = clazzGen.getJavaClass().getBytes();
>          try {
> -            final FileOutputStream out = new FileOutputStream(path + ".orig");
> +            out = new FileOutputStream(path + ".orig");
>              out.write(orig);
>              out.flush();
>              out.close();
> -        } catch (java.io.IOException ioe) {
> -            ioe.printStackTrace();
> +        } catch (final IOException e) {
> +            e.printStackTrace();
> +
> +            try {
> +                if (out != null) {
> +                    out.close();
> +                }
> +            } catch (final IOException e1) {
> +                log.error(e1.getMessage(), e1);
> +            } finally {
> +                out = null;
> +            }
>          }
>  
>          try {
> -            final FileOutputStream fos = new FileOutputStream(path + ".orig.java");
> -            final DecompilingVisitor v = new DecompilingVisitor(javaClazz, fos);
> +            out = new FileOutputStream(path + ".orig.java");
> +            final DecompilingVisitor v = new DecompilingVisitor(javaClazz, out);
>              v.start();
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              e.printStackTrace();
> +
> +            try {
> +                if (out != null) {
> +                    out.close();
> +                }
> +            } catch (final IOException e1) {
> +                log.error(e1.getMessage(), e1);
> +            } finally {
> +                out = null;
> +            }
>          }
>  
>          // vistor to build the frame information
> @@ -157,22 +180,42 @@
>  
>          clazzGen.addInterface(CONTINUATIONCAPABLE_CLASS);
>  
> -        byte[] changed = clazzGen.getJavaClass().getBytes();
> +        final byte[] changed = clazzGen.getJavaClass().getBytes();
>          try {
> -            java.io.FileOutputStream out = new java.io.FileOutputStream(clazzGen.getClassName() + ".rewritten");
> +            out = new FileOutputStream(clazzGen.getClassName() + ".rewritten");
>              out.write(changed);
>              out.flush();
>              out.close();
> -        } catch (java.io.IOException ioe) {
> -            ioe.printStackTrace();
> +        } catch (final IOException e) {
> +            e.printStackTrace();
> +
> +            try {
> +                if (out != null) {
> +                    out.close();
> +                }
> +            } catch (final IOException e1) {
> +                log.error(e1.getMessage(), e1);
> +            } finally {
> +                out = null;
> +            }
>          }
>  
>          try {
> -            final FileOutputStream fos = new FileOutputStream(path + ".rewritten.java");
> -            final DecompilingVisitor v = new DecompilingVisitor(clazzGen.getJavaClass(), fos);
> +            out = new FileOutputStream(path + ".rewritten.java");
> +            final DecompilingVisitor v = new DecompilingVisitor(clazzGen.getJavaClass(), out);
>              v.start();
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              e.printStackTrace();
> +
> +            try {
> +                if (out != null) {
> +                    out.close();
> +                }
> +            } catch (final IOException e1) {
> +                log.error(e1.getMessage(), e1);
> +            } finally {
> +                out = null;
> +            }
>          }
>  
>          return changed;
> @@ -194,7 +237,7 @@
>          log.debug("analyse " + method.getName());
>  
>          // build the initial frame situation for this method.
> -        Frame vanillaFrame = new Frame(method.getMaxLocals(), method.getMaxStack());
> +        final Frame vanillaFrame = new Frame(method.getMaxLocals(), method.getMaxStack());
>          if (!method.isStatic()) {
>              if (method.getName().equals(Constants.CONSTRUCTOR_NAME)) {
>                  Frame._this = new UninitializedObjectType(new ObjectType(clazz.getClassName()));
> @@ -205,7 +248,7 @@
>              }
>          }
>          // fill local variables with parameter types
> -        Type[] argtypes = method.getArgumentTypes();
> +        final Type[] argtypes = method.getArgumentTypes();
>          int twoslotoffset = 0;
>          for (int j = 0; j < argtypes.length; j++) {
>              if ((argtypes[j] == Type.SHORT) || (argtypes[j] == Type.BYTE) || (argtypes[j] == Type.CHAR) || (argtypes[j] == Type.BOOLEAN)) {
> 
> Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java?view=diff&r1=149312&r2=149313
> ==============================================================================
> --- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java (original)
> +++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationClassLoaderTestCase.java Mon Jan 31 14:53:31 2005
> @@ -20,6 +20,7 @@
>  
>  import junit.framework.TestCase;
>  
> +import org.apache.commons.javaflow.testcode.Calculator;
>  import org.apache.commons.javaflow.utils.ReflectionUtils;
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
> @@ -31,14 +32,11 @@
>   */
>  public final class ContinuationClassLoaderTestCase extends TestCase {
>  
> -    /**
> -     * Logger.
> -     */
>      private final static Log log = LogFactory.getLog(ContinuationClassLoaderTestCase.class);
>  
>      public void testCalculator() throws Exception {
> -        log.debug("Doing testCalculator()");
> -        
> +        log.debug("Testing Calculator...");
> +
>          final String calculatorTestClass = "org.apache.commons.javaflow.testcode.Calculator";
>  
>          // creating object instance
> @@ -62,9 +60,11 @@
>          context.setMethod(method);
>          context.setInstance(instance);
>          
> +        assertTrue(instance.toString(), "0.0".equals(instance.toString()));        
> +
>          log.debug("Continuation 1");
>          continuation = Continuation.continueWith(continuation, context);
> -        
> +        assertTrue(instance.toString(), "1.1".equals(instance.toString()));                
>          
>          final Continuation parent = continuation;
>  
> @@ -74,14 +74,36 @@
>  
>          log.debug("Continuation 1.1");
>          final Continuation continuation11 = Continuation.continueWith(parent, context);
> -
> +        assertTrue("" + instance, "2.2".equals(instance.toString()));
> +        
>          log.debug("Continuation 1.2");
>          final Continuation continuation12 = Continuation.continueWith(parent, context);
> +        assertTrue("" + instance, "3.2".equals(instance.toString()));
>          
>      }
>      
>      
>      /**
> +     * Verifies that an IllegalStateException gets thrown when a continuable class 
> +     * is used incorrectly (i.e. without the ContinuationClassLoader).
> +     * @throws Exception
> +     */
> +    public void testIncorrectUsageWithNormalClassLoader() throws Exception {
> +        log.debug("Testing incorrect use of continuation...");
> +        boolean exceptionThrown = false;
> +        try {
> +            final Calculator c = new Calculator();
> +            c.main();
> +        } catch (final Exception e) {
> +            log.debug("Catching a " + e);
> +            assertTrue(e instanceof IllegalStateException);
> +            exceptionThrown = true;
> +        }
> +        assertTrue(exceptionThrown);
> +    }
> +    
> +    
> +    /**
>       * The junit tests are preferred over running this main() method.
>       * @param args
>       * @throws Exception
> @@ -89,5 +111,6 @@
>      public static void main(final String[] args) throws Exception {
>          final ContinuationClassLoaderTestCase t = new ContinuationClassLoaderTestCase();
>          t.testCalculator();
> +        t.testIncorrectUsageWithNormalClassLoader();
>      }
>  }
> 
> Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java?view=diff&r1=149312&r2=149313
> ==============================================================================
> --- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java (original)
> +++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/ContinuationCompilingClassLoaderTestCase.java Mon Jan 31 14:53:31 2005
> @@ -22,15 +22,19 @@
>  import org.apache.commons.logging.LogFactory;
>  import org.apache.jci.CompilingClassLoader;
>  
> +import junit.framework.TestCase;
> +
>  
>  /**
>   * @author tcurdt
>   *
>   */
> -public final class ContinuationCompilingClassLoaderTestCase {
> +public final class ContinuationCompilingClassLoaderTestCase extends TestCase {
> +
>      private final static Log log = LogFactory.getLog(ContinuationCompilingClassLoaderTestCase.class);
>  
> -    private void testReloading() throws Exception {
> +    public void testReloading() throws Exception {
> +/*
>          final CompilingClassLoader cl = new ContinuationCompilingClassLoader(
>                  this.getClass().getClassLoader(),
>                  new File("/home/tcurdt/dev/jci/classes")
> @@ -50,7 +54,7 @@
>              
>              Thread.sleep(2000);
>          }
> -        
> +  */      
>      }
>      
>      public static void main(String[] args) throws Exception {
> 
> Modified: jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java
> URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java?view=diff&r1=149312&r2=149313
> ==============================================================================
> --- jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java (original)
> +++ jakarta/commons/sandbox/javaflow/trunk/src/test/org/apache/commons/javaflow/testcode/Calculator.java Mon Jan 31 14:53:31 2005
> @@ -28,18 +28,33 @@
>   */
>  public final class Calculator implements Continuable, Serializable {
>      
> -    /**
> -     * Logger.
> -     */
>      private static final Log log = LogFactory.getLog(Calculator.class);
> +
> +    private int global = 0;
> +    private int local = 0;
>      
>      public void main() {
>  
> -        log.debug("Calculator1");
> +        int l = 0;
> +        
> +        log.debug("Start of Calculator: g=" + global + " l=" + local);
> +
> +        global++;
> +        local = ++l;
>  
> -        Continuation.suspend();
> +        log.debug("Calculator Step 1: g=" + global + " l=" + local);
>          
> -        log.debug("Calculator2");
> +        Continuation.suspend();
>          
> +        log.debug("Calculator Step 2: g=" + global + " l=" + local);
> +
> +        global++;
> +        local = ++l;
> +
> +        log.debug("End of Calculator: g=" + global + " l=" + local);        
> +    }
> +    
> +    public String toString() {
> +        return "" + global + "." + local;
>      }
>  }
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 

-- 
                                   Whirlycott
                                   Philip Jacob
                                   phil@whirlycott.com
                                   http://www.whirlycott.com/phil/

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


[javaflow] patches

Posted by Torsten Curdt <tc...@apache.org>.
WHIRLYCOTT wrote:
> Torsten Curdt wrote:
>
>> Well, the point is that the file writing code is
>> temporary anyway. I should go away in the near future.
>> That's why fixing it is not that important.
>
>
> Yes, I was going to ask about that one... can you let me in on your
> plans for this?  I agree that it should go away, but I haven't spent any
> time rethinking this.

...not sure whether it's worth having it
configurable for debugging purposes.

WDYT?

>> Btw: for some reason I've some problem applying
>> your patches with eclipse :-/ ...most of the
>> hunks are not being found.
>
>
> How goofy.  The subclipse client isn't as painfree as the cvs one from
> what I can tell.  The team synchronizing perspective occasionally
> indicates to me that there differences between local and remote when
> there are none.  I'm not sure what could cause this... will investigate.

I am talking about the apply patch dialog that comes
with eclipse.

cheers
--
Torsten

Re: svn commit: r149313 - in jakarta/commons/sandbox/javaflow/trunk/src: java/org/apache/commons/javaflow/ java/org/apache/commons/javaflow/bytecode/bcel/ test/org/apache/commons/javaflow/ test/org/apache/commons/javaflow/testcode/

Posted by WHIRLYCOTT <ph...@whirlycott.com>.
Torsten Curdt wrote:
> Well, the point is that the file writing code is
> temporary anyway. I should go away in the near future.
> That's why fixing it is not that important.

Yes, I was going to ask about that one... can you let me in on your 
plans for this?  I agree that it should go away, but I haven't spent any 
time rethinking this.

> Btw: for some reason I've some problem applying
> your patches with eclipse :-/ ...most of the
> hunks are not being found.

How goofy.  The subclipse client isn't as painfree as the cvs one from 
what I can tell.  The team synchronizing perspective occasionally 
indicates to me that there differences between local and remote when 
there are none.  I'm not sure what could cause this... will investigate.

phil.


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


Re: svn commit: r149313 - in jakarta/commons/sandbox/javaflow/trunk/src: java/org/apache/commons/javaflow/ java/org/apache/commons/javaflow/bytecode/bcel/ test/org/apache/commons/javaflow/ test/org/apache/commons/javaflow/testcode/

Posted by Torsten Curdt <tc...@apache.org>.
> Closing an OutputStream twice is a bug or is it indeed nitpicking? ;)

Bummer missed that one :)

That nitpicking was not aimed at your submission.
...it was on a new line on the commit message ;)

Well, the point is that the file writing code is
temporary anyway. I should go away in the near future.
That's why fixing it is not that important.

Btw: for some reason I've some problem applying
your patches with eclipse :-/ ...most of the
hunks are not being found.

> I was thinking that it might make sense for me to work on some docs as
> well... might be a good opportunity for me to dig deeper through things
> as well as put down in words what I'm seeing and learn a few things from
> you about the overall design.  Thoughts?

Sounds awesome!

cheers
--
Torsten