xmlbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From p...@apache.org
Subject cvs commit: xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam JamTestBase.java
Date Mon, 12 Apr 2004 21:06:58 GMT
pcal        2004/04/12 14:06:57

  Modified:    v2/jam/src/org/apache/xmlbeans/impl/jam
                        JamClassIterator.java JamServiceParams.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal
                        JamClassLoaderImpl.java JamLoggerImpl.java
                        JamServiceContextImpl.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/classrefs
                        QualifiedJClassRef.java
               v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements
                        AnnotationValueImpl.java
               v2/jam/test/tests/org/apache/xmlbeans/test/jam
                        JamTestBase.java
  Log:
  JAM: cache JClasses via weak references to allow them to gc
  
  Revision  Changes    Path
  1.3       +5 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamClassIterator.java
  
  Index: JamClassIterator.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamClassIterator.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JamClassIterator.java	10 Mar 2004 20:37:05 -0000	1.2
  +++ JamClassIterator.java	12 Apr 2004 21:06:57 -0000	1.3
  @@ -88,6 +88,11 @@
     public Object next() { return nextClass(); }
   
     // ========================================================================
  +  // Public methods
  +
  +  public int getSize() { return mClassNames.length; }
  +
  +  // ========================================================================
     // Unsupported methods
   
     /**
  
  
  
  1.10      +1 -1      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamServiceParams.java
  
  Index: JamServiceParams.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/JamServiceParams.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JamServiceParams.java	26 Mar 2004 00:15:38 -0000	1.9
  +++ JamServiceParams.java	12 Apr 2004 21:06:57 -0000	1.10
  @@ -190,7 +190,7 @@
      * @param out a PrintWriter to write to
      * @throws IllegalArgumentException if the argument is null
      */
  -//  public void setLogger(PrintWriter out);
  +  public void setLoggerWriter(PrintWriter out);
   
     /**
      * </p>Enables verbose debugging output from all instances of the given
  
  
  
  1.10      +28 -7     xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamClassLoaderImpl.java
  
  Index: JamClassLoaderImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamClassLoaderImpl.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- JamClassLoaderImpl.java	26 Mar 2004 00:15:39 -0000	1.9
  +++ JamClassLoaderImpl.java	12 Apr 2004 21:06:57 -0000	1.10
  @@ -24,6 +24,7 @@
   import org.apache.xmlbeans.impl.jam.provider.JamClassBuilder;
   
   import java.util.*;
  +import java.lang.ref.WeakReference;
   
   /**
    *
  @@ -35,7 +36,7 @@
     // Variables
   
     private Map mName2Package = new HashMap();
  -  private Map mFd2ClassCache = null;
  +  private Map mFd2ClassCache = new HashMap();
     private JamClassBuilder mBuilder;
     private MVisitor mInitializer = null;
     private ElementContext mContext;
  @@ -62,8 +63,7 @@
   
     public final JClass loadClass(String fd)
     {
  -    fd = fd.trim();//REVIEW is this paranoid?
  -    MClass out = (MClass)mFd2ClassCache.get(fd);
  +    MClass out = cacheGet(fd);
       if (out != null) return out;
       if (fd.startsWith("[")) {
         return ArrayClassImpl.createClassForFD(fd,this);
  @@ -87,10 +87,10 @@
         //or something for them which returns null rather than UnresolvedClass.
         out = new UnresolvedClassImpl(pkg,name,mContext);
         mContext.warning("failed to resolve class "+fd);
  -      mFd2ClassCache.put(fd,out);
  +      cachePut(out);
         return out;
       }
  -    mFd2ClassCache.put(fd,out);
  +    cachePut(out);
       ((ClassImpl)out).setState(ClassImpl.POPULATING);
       mBuilder.populate(out);
       if (mInitializer == null) {
  @@ -132,11 +132,32 @@
      * <p>Stuff the primitives and void into the cache.</p>
      */
     private void initCache() {
  -    mFd2ClassCache = new HashMap();
       PrimitiveClassImpl.mapNameToPrimitive(mContext,mFd2ClassCache);
       mFd2ClassCache.put("void",new VoidClassImpl(mContext));
     }
   
  +  private void cachePut(MClass clazz) {
  +    mFd2ClassCache.put(new String(clazz.getFieldDescriptor().trim()),
  +                       new WeakReference(clazz));
  +  }
  +
  +  private MClass cacheGet(String fd) {
  +    Object out = mFd2ClassCache.get(fd.trim());
  +    if (out == null) return null;
  +    if (out instanceof MClass) return (MClass)out;
  +    if (out instanceof WeakReference) {
  +      out = ((WeakReference)out).get();
  +      if (out == null) {
  +        mFd2ClassCache.remove(fd.trim());
  +        return null;
  +      } else {
  +//        System.out.println("got "+fd+" from cache");
  +        return (MClass)out;
  +      }
  +    }
  +    throw new IllegalStateException();
  +  }
  +
     // ========================================================================
     // Public methods?
   
  @@ -150,7 +171,7 @@
   
     public void addToCache(JClass c) {
       //FIXME hack for mutable classes for now
  -    mFd2ClassCache.put(c.getQualifiedName(),c);
  +    cachePut((MClass)c);
     }
   
     //ok, the best thinking here is that when you are in an initializer
  
  
  
  1.3       +3 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamLoggerImpl.java
  
  Index: JamLoggerImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamLoggerImpl.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- JamLoggerImpl.java	26 Mar 2004 00:15:39 -0000	1.2
  +++ JamLoggerImpl.java	12 Apr 2004 21:06:57 -0000	1.3
  @@ -33,6 +33,9 @@
     private Set mVerboseClasses = null;
     private PrintWriter mOut = new PrintWriter(System.out,true);
   
  +  //FIXME temp until JamServiceContextImpl is no longer a subclass
  +  protected void setOut(PrintWriter out) { mOut= out; }
  +
     // ========================================================================
     // JamLogger implementation
   
  
  
  
  1.13      +5 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceContextImpl.java
  
  Index: JamServiceContextImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/JamServiceContextImpl.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- JamServiceContextImpl.java	26 Mar 2004 00:15:39 -0000	1.12
  +++ JamServiceContextImpl.java	12 Apr 2004 21:06:57 -0000	1.13
  @@ -30,6 +30,7 @@
   
   import java.io.File;
   import java.io.IOException;
  +import java.io.PrintWriter;
   import java.lang.reflect.Constructor;
   import java.lang.reflect.Modifier;
   import java.util.*;
  @@ -360,6 +361,10 @@
         if (mClasspath.contains(classpathElement)) return;
       }
       mClasspath.add(classpathElement);
  +  }
  +
  +  public void setLoggerWriter(PrintWriter out) {
  +    super.setOut(out);//FIXME
     }
   
   
  
  
  
  1.4       +9 -0      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/classrefs/QualifiedJClassRef.java
  
  Index: QualifiedJClassRef.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/classrefs/QualifiedJClassRef.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- QualifiedJClassRef.java	26 Mar 2004 00:15:39 -0000	1.3
  +++ QualifiedJClassRef.java	12 Apr 2004 21:06:57 -0000	1.4
  @@ -40,6 +40,15 @@
     /**
      * Creates a new JClassRef for a qualified class or type name.
      */
  +  public static JClassRef create(JClass clazz) {
  +    if (clazz == null) throw new IllegalArgumentException("null clazz");
  +    return new QualifiedJClassRef(clazz.getFieldDescriptor(),
  +                                  clazz.getClassLoader());
  +  }
  +
  +  /**
  +   * Creates a new JClassRef for a qualified class or type name.
  +   */
     public static JClassRef create(String qcname,
                                    JClassRefContext ctx) {
       if (qcname == null) throw new IllegalArgumentException("null qcname");
  
  
  
  1.7       +6 -4      xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java
  
  Index: AnnotationValueImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/src/org/apache/xmlbeans/impl/jam/internal/elements/AnnotationValueImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- AnnotationValueImpl.java	7 Apr 2004 23:20:01 -0000	1.6
  +++ AnnotationValueImpl.java	12 Apr 2004 21:06:57 -0000	1.7
  @@ -17,6 +17,9 @@
   import org.apache.xmlbeans.impl.jam.JAnnotation;
   import org.apache.xmlbeans.impl.jam.JClass;
   import org.apache.xmlbeans.impl.jam.JAnnotationValue;
  +import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRef;
  +import org.apache.xmlbeans.impl.jam.internal.classrefs.QualifiedJClassRef;
  +import org.apache.xmlbeans.impl.jam.internal.classrefs.JClassRefContext;
   
   
   /**
  @@ -30,7 +33,7 @@
     // Variables
   
     private Object mValue = null;
  -  private JClass mType = null;
  +  private JClassRef mType = null;
     private String mName;
     private ElementContext mContext;
     private boolean mIsDefaultUsed = false;
  @@ -53,7 +56,7 @@
       }
       mContext = ctx;
       mName = name;
  -    mType = type;
  +    mType = QualifiedJClassRef.create(type);
     }
   
     // ========================================================================
  @@ -66,8 +69,7 @@
   
     public String getName() { return mName; }
   
  -  public JClass getType() { return mType; }
  -
  +  public JClass getType() { return mType.getRefClass(); }
   
   
     public JAnnotation asAnnotation() {
  
  
  
  1.23      +2 -2      xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam/JamTestBase.java
  
  Index: JamTestBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xmlbeans/v2/jam/test/tests/org/apache/xmlbeans/test/jam/JamTestBase.java,v
  retrieving revision 1.22
  retrieving revision 1.23
  diff -u -r1.22 -r1.23
  --- JamTestBase.java	8 Apr 2004 19:44:44 -0000	1.22
  +++ JamTestBase.java	12 Apr 2004 21:06:57 -0000	1.23
  @@ -97,8 +97,8 @@
     // ========================================================================
     // Constants
   
  -  private static final boolean CONTINUE_ON_COMPARE_FAIL = false;
  -  private static final boolean WRITE_RESULT_ON_FAIL = false;
  +  private static final boolean CONTINUE_ON_COMPARE_FAIL = true;
  +  private static final boolean WRITE_RESULT_ON_FAIL = true;
   
     private static final String WRITE_RESULT_PREFIX = "result-";
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org


Mime
View raw message