[cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Roman Kennke

Hi there,

we are having problems here with java.io.File on Windows CE. Which 
handles files different again than other Windows and of course different 
than Unix. I could have hacked some more special casing in there. But 
I'd like to propose to pull some more methods into VMFile. See ChangeLog 
and attached patch. Basically this moves the impl of getAbsolutePath(), 
isAbsolute() and toURL() to VMFile.


Maybe we should get rid of all the special casing anyway and provide a 
default straightforward impl for Posixy systems, for the sake of 
efficiency and cleanness.


2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* java/io/File.java
(getAbsolutePath): Fetch absolute path from
VMFile.getAbsolutePath(). Moved actual impl to there.
(isAbsolute): Let VMFile determine the absoluteness.
(toURL): Let VMFile convert the filename.
* vm/reference/java/io/VMFile.java
(getAbsolutePath): New method.
(isAbsolute): New method.
(toURL): New method.


/Roman
Index: java/io/File.java
===
RCS file: /cvsroot/classpath/classpath/java/io/File.java,v
retrieving revision 1.65
diff -u -1 -2 -r1.65 File.java
--- java/io/File.java	29 Jun 2006 09:59:57 -	1.65
+++ java/io/File.java	15 Aug 2006 08:52:05 -
@@ -418,63 +418,26 @@
* This method returns the path of this file as an absolute path name.
* If the path name is already absolute, then it is returned.  Otherwise
* the value returned is the current directory plus the separatory
* string plus the path of the file.  The current directory is determined
* from the codeuser.dir/code system property.
*
* @return The absolute path of this file
*/
   public String getAbsolutePath()
   {
 if (isAbsolute())
   return path;
-else if (separatorChar == '\\' 
-  path.length()  0  path.charAt (0) == '\\')
-  {
-// On Windows, even if the path starts with a '\\' it is not
-// really absolute until we prefix the drive specifier from
-// the current working directory to it.
-return System.getProperty (user.dir).substring (0, 2) + path;
-  }
-else if (separatorChar == '\\' 
-  path.length()  1  path.charAt (1) == ':'
-  ((path.charAt (0) = 'a'  path.charAt (0) = 'z')
- || (path.charAt (0) = 'A'  path.charAt (0) = 'Z')))
-  {
-// On Windows, a process has a current working directory for
-// each drive and a path like G:foo\bar would mean the 
-// absolute path G:\wombat\foo\bar if \wombat is the 
-// working directory on the G drive.
-String drvDir = null;
-try
-  {
-drvDir = new File (path.substring (0, 2)).getCanonicalPath();
-  }
-catch (IOException e)
-  {
-drvDir = path.substring (0, 2) + \\;
-  }
-
-// Note: this would return C:\\. for the path C:., if \
-// is the working folder on the C drive, but this is 
-// consistent with what Sun's JRE 1.4.1.01 actually returns!
-if (path.length()  2)
-  return drvDir + '\\' + path.substring (2, path.length());
-else
-  return drvDir;
-  }
-else if (path.equals())
-  return System.getProperty (user.dir);
 else
-  return System.getProperty (user.dir) + separatorChar + path;
+  return VMFile.getAbsolutePath(path);
   }
 
   /**
* This method returns a codeFile/code object representing the
* absolute path of this object.
*
* @return A codeFile/code with the absolute path of the object.
*
* @since 1.2
*/
   public File getAbsoluteFile()
   {
@@ -648,33 +611,25 @@
 
   /**
* This method returns true if this object represents an absolute file
* path and false if it does not.  The definition of an absolute path varies
* by system.  As an example, on GNU systems, a path is absolute if it starts
* with a /.
*
* @return codetrue/code if this object represents an absolute 
* file name, codefalse/code otherwise.
*/
   public boolean isAbsolute()
   {
-if (separatorChar == '\\')
-	return path.startsWith(dupSeparator) || 
-	(path.length()  2  
-	 ((path.charAt(0) = 'a'  path.charAt(0) = 'z') ||
-	  (path.charAt(0) = 'A'  path.charAt(0) = 'Z')) 
-	 path.charAt(1) == ':' 
-	 path.charAt(2) == '\\');
-else
-	return path.startsWith(separator);
+return VMFile.isAbsolute(path);
   }
 
   /**
* This method tests whether or not the file represented by this object
* is a directory.  In order for this method to return codetrue/code,
* the file represented by this object must exist and be a directory.
* 
* @return codetrue/code if this file is a directory, codefalse/code
* otherwise
*
* @exception SecurityException If reading of the file is not permitted
*/
@@ -989,32 +944,25 

[cp-patches] FYI: Vector fixlet

2006-08-15 Thread Roman Kennke
This removes 2 explicit null checks in Vector. The Mauve test that I'll 
commit right after this shows that the RI allows null arguments when the 
Vector is empty. In the other case we throw an NPE implicitly anyway.


2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* java/util/Vector.java
(removeAll): Don't explicitly null-check here. The RI allows
null arguments when Vector is empty. In other cases we
implicitly throw an NPE.
(retainAll): Don't explicitly null-check here. The RI allows
null arguments when Vector is empty. In other cases we
implicitly throw an NPE.

/Roman
Index: java/util/Vector.java
===
RCS file: /cvsroot/classpath/classpath/java/util/Vector.java,v
retrieving revision 1.27
diff -u -1 -2 -r1.27 Vector.java
--- java/util/Vector.java	26 Jul 2006 06:48:47 -	1.27
+++ java/util/Vector.java	15 Aug 2006 09:42:46 -
@@ -711,27 +711,24 @@
   }
 
   /**
* Remove from this vector all elements contained in the given collection.
*
* @param c the collection to filter out
* @return true if this vector changed
* @throws NullPointerException if c is null
* @since 1.2
*/
   public synchronized boolean removeAll(Collection c)
   {
-if (c == null)
-  throw new NullPointerException();
-
 int i;
 int j;
 for (i = 0; i  elementCount; i++)
   if (c.contains(elementData[i]))
 break;
 if (i == elementCount)
   return false;
 
 modCount++;
 for (j = i++; i  elementCount; i++)
   if (! c.contains(elementData[i]))
 elementData[j++] = elementData[i];
@@ -740,27 +737,24 @@
   }
 
   /**
* Retain in this vector only the elements contained in the given collection.
*
* @param c the collection to filter by
* @return true if this vector changed
* @throws NullPointerException if c is null
* @since 1.2
*/
   public synchronized boolean retainAll(Collection c)
   {
-if (c == null)
-  throw new NullPointerException();
-
 int i;
 int j;
 for (i = 0; i  elementCount; i++)
   if (! c.contains(elementData[i]))
 break;
 if (i == elementCount)
   return false;
 
 modCount++;
 for (j = i++; i  elementCount; i++)
   if (c.contains(elementData[i]))
 elementData[j++] = elementData[i];


[cp-patches] FYI: ZipFile performance improvement

2006-08-15 Thread Roman Kennke
Here comes a significant performance improvement for Zipfile, done by 
Ingo. It avoids expensive UTF8 decoding when possible (most cases, for 
ASCII) and optimizes readLeShort() and readLeInt() for the case when the 
buffer has enough bytes. Mauve shows no regressions.


2006-08-15  Ingo Proetel  [EMAIL PROTECTED]

* java/util/zip/ZipFile.java
(PartialInputStream.UTF8DECODER): New constant field, used
for decoding UTF8 strings.
(readLeShort): Access buffer directly if it has enough bytes
available.
(readLeInt): Access buffer directly if it has enough bytes
available.
(decodeChars): New helper method for decoding UTF8 strings.
(readString): Avoid NIO charset decoder if possible.

/Roman
Index: java/util/zip/ZipFile.java
===
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipFile.java,v
retrieving revision 1.35
diff -u -1 -2 -r1.35 ZipFile.java
--- java/util/zip/ZipFile.java	12 Jul 2006 17:00:34 -	1.35
+++ java/util/zip/ZipFile.java	15 Aug 2006 11:27:08 -
@@ -39,24 +39,27 @@
 
 package java.util.zip;
 
 import gnu.java.util.EmptyEnumeration;
 
 import java.io.EOFException;
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.RandomAccessFile;
 import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
 import java.util.Enumeration;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 
 /**
  * This class represents a Zip archive.  You can ask for the contained
  * entries, or get an input stream for a file entry.  The entry is
  * automatically decompressed.
  *
  * This class is thread safe:  You can open input streams for arbitrary
  * entries in different threads.
  *
@@ -507,24 +510,30 @@
 
 public Object nextElement()
 {
   /* We return a clone, just to be safe that the user doesn't
* change the entry.  
*/
   return ((ZipEntry)elements.next()).clone();
 }
   }
 
   private static final class PartialInputStream extends InputStream
   {
+/**
+ * The UTF-8 decoder use for decoding the filenames.
+ */
+private static final CharsetDecoder UTF8DECODER =
+  Charset.forName(UTF-8).newDecoder();
+
 private final RandomAccessFile raf;
 private final byte[] buffer;
 private long bufferOffset;
 private int pos;
 private long end;
 // We may need to supply an extra dummy byte to our reader.
 // See Inflater.  We use a count here to simplify the logic
 // elsewhere in this class.  Note that we ignore the dummy
 // byte in methods where we know it is not needed.
 private int dummyByteCount;
 
 public PartialInputStream(RandomAccessFile raf, int bufferSize)
@@ -643,63 +652,125 @@
   if (read(buf, 0, buf.length) != buf.length)
 throw new EOFException();
 }
 
 void readFully(byte[] buf, int off, int len) throws IOException
 {
   if (read(buf, off, len) != len)
 throw new EOFException();
 }
 
 int readLeShort() throws IOException
 {
-  int b0 = read();
-  int b1 = read();
-  if (b1 == -1)
-throw new EOFException();
-  return (b0  0xff) | (b1  0xff)  8;
+  int result;
+  if(pos + 1  buffer.length)
+{
+  result = ((buffer[pos + 0]  0xff) | (buffer[pos + 1]  0xff)  8);
+  pos += 2;
+}
+  else
+{
+  int b0 = read();
+  int b1 = read();
+  if (b1 == -1)
+throw new EOFException();
+  result = (b0  0xff) | (b1  0xff)  8;
+}
+  return result;
 }
 
 int readLeInt() throws IOException
 {
-  int b0 = read();
-  int b1 = read();
-  int b2 = read();
-  int b3 = read();
-  if (b3 == -1)
-throw new EOFException();
-  return ((b0  0xff) | (b1  0xff)  8)
-| ((b2  0xff) | (b3  0xff)  8)  16;
+  int result;
+  if(pos + 3  buffer.length)
+{
+  result = (((buffer[pos + 0]  0xff) | (buffer[pos + 1]  0xff)  8)
+   | ((buffer[pos + 2]  0xff)
+   | (buffer[pos + 3]  0xff)  8)  16);
+  pos += 4;
+}
+  else
+{
+  int b0 = read();
+  int b1 = read();
+  int b2 = read();
+  int b3 = read();
+  if (b3 == -1)
+throw new EOFException();
+  result =  (((b0  0xff) | (b1  0xff)  8) | ((b2  0xff)
+| (b3  0xff)  8)  16);
+}
+  return result;
+}
+
+/**
+ * Decode chars from byte buffer using UTF8 encoding.  This
+ * operation is performance-critical since a jar file contains a
+ * large number of strings for the name of each file in the
+ * archive.  This routine therefore avoids using the expensive
+

RE: [cp-patches] FYI: ZipFile performance improvement

2006-08-15 Thread Jeroen Frijters
Roman Kennke wrote:
 Here comes a significant performance improvement for Zipfile, done by 
 Ingo. It avoids expensive UTF8 decoding when possible (most 
 cases, for ASCII) and optimizes readLeShort() and readLeInt() for the 
 case when the buffer has enough bytes. Mauve shows no regressions.

This looks like it isn't thread safe:
+  UTF8DECODER.reset();
+  char [] characters =
UTF8DECODER.decode(bufferBuffer).array();

Regards,
Jeroen



[cp-patches] FYI: java.io fixlets

2006-08-15 Thread Roman Kennke

This:
- Provides a default for the system property line.separator in PrintStream.
- Creates a local copy of the channels field in FileDescriptor.valid() 
to improve threading safety.


2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* java/io/PrintStream.java
(line_separator): Provide default for system property.
* java/io/FileDescriptor.java
(valid): Create local copy of channel field for better
threading safetly.

/Roman
Index: java/io/FileDescriptor.java
===
RCS file: /cvsroot/classpath/classpath/java/io/FileDescriptor.java,v
retrieving revision 1.25
diff -u -1 -2 -r1.25 FileDescriptor.java
--- java/io/FileDescriptor.java	2 Jul 2005 20:32:37 -	1.25
+++ java/io/FileDescriptor.java	15 Aug 2006 11:34:55 -
@@ -124,16 +124,17 @@
 	  }
   }
   }
 
   /**
* This methods tests whether or not this object represents a valid open
* native file handle.
*
* @return codetrue/code if this object represents a valid 
* native file handle, codefalse/code otherwise
*/
   public boolean valid ()
-  {
-return channel != null  channel.isOpen();
+  { 
+ByteChannel c = channel;
+return (c != null)  (c.isOpen());
   }
 }
Index: java/io/PrintStream.java
===
RCS file: /cvsroot/classpath/classpath/java/io/PrintStream.java,v
retrieving revision 1.27
diff -u -1 -2 -r1.27 PrintStream.java
--- java/io/PrintStream.java	16 Jul 2006 11:57:02 -	1.27
+++ java/io/PrintStream.java	15 Aug 2006 11:34:55 -
@@ -58,25 +58,25 @@
  *
  * @author Aaron M. Renn ([EMAIL PROTECTED])
  * @author Tom Tromey ([EMAIL PROTECTED])
  */
 public class PrintStream extends FilterOutputStream
 {
   /* Notice the implementation is quite similar to OutputStreamWriter.
* This leads to some minor duplication, because neither inherits
* from the other, and we want to maximize performance. */
 
   // Line separator string.
   private static final char[] line_separator
-= SystemProperties.getProperty(line.separator).toCharArray();
+= SystemProperties.getProperty(line.separator, \n).toCharArray();
 
   /**
*  Encoding name
*/
   private String encoding;
 
   /**
* This boolean indicates whether or not an error has ever occurred
* on this stream.
*/
   private boolean error_occurred = false;
 


Re: [cp-patches] FYI: Vector fixlet

2006-08-15 Thread Robert Schuster
Hi Roman,
could you please add a comment to these methods that says that the NPEs are
supposed to be thrown implicitly. Otherwise I find it a bit odd that the javadoc
mentions the exceptions explicitly.

cya
Robert

Roman Kennke wrote:
 This removes 2 explicit null checks in Vector. The Mauve test that I'll
 commit right after this shows that the RI allows null arguments when the
 Vector is empty. In the other case we throw an NPE implicitly anyway.
 
 2006-08-15  Roman Kennke  [EMAIL PROTECTED]
 
 * java/util/Vector.java
 (removeAll): Don't explicitly null-check here. The RI allows
 null arguments when Vector is empty. In other cases we
 implicitly throw an NPE.
 (retainAll): Don't explicitly null-check here. The RI allows
 null arguments when Vector is empty. In other cases we
 implicitly throw an NPE.
 
 /Roman
 


signature.asc
Description: OpenPGP digital signature


Re: [cp-patches] FYI: ZipFile performance improvement

2006-08-15 Thread Roman Kennke

Hi Jeroen, hi list,

Jeroen Frijters schrieb:

Roman Kennke wrote:
Here comes a significant performance improvement for Zipfile, done by 
Ingo. It avoids expensive UTF8 decoding when possible (most 
cases, for ASCII) and optimizes readLeShort() and readLeInt() for the 
case when the buffer has enough bytes. Mauve shows no regressions.


This looks like it isn't thread safe:
+  UTF8DECODER.reset();
+  char [] characters =
UTF8DECODER.decode(bufferBuffer).array();


Fixed using the attached patch.

2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* java/util/zip/ZipFile.java
(UTF8DECODER): Removed.
(UTF8CHARSET): New constant field. Stores the UTF8 charset.
(utf8Decoder): New instance field.
(decodeChars): Lazily create UTF8 decoder. Use instance
field rather than a static field to avoid corruption.

/Roman

Index: java/util/zip/ZipFile.java
===
RCS file: /cvsroot/classpath/classpath/java/util/zip/ZipFile.java,v
retrieving revision 1.36
diff -u -1 -2 -r1.36 ZipFile.java
--- java/util/zip/ZipFile.java	15 Aug 2006 11:28:10 -	1.36
+++ java/util/zip/ZipFile.java	15 Aug 2006 14:22:27 -
@@ -511,28 +511,32 @@
 public Object nextElement()
 {
   /* We return a clone, just to be safe that the user doesn't
* change the entry.  
*/
   return ((ZipEntry)elements.next()).clone();
 }
   }
 
   private static final class PartialInputStream extends InputStream
   {
 /**
- * The UTF-8 decoder use for decoding the filenames.
+ * The UTF-8 charset use for decoding the filenames.
  */
-private static final CharsetDecoder UTF8DECODER =
-  Charset.forName(UTF-8).newDecoder();
+private static final Charset UTF8CHARSET = Charset.forName(UTF-8);
+
+/**
+ * The actual UTF-8 decoder. Created on demand. 
+ */
+private CharsetDecoder utf8Decoder;
 
 private final RandomAccessFile raf;
 private final byte[] buffer;
 private long bufferOffset;
 private int pos;
 private long end;
 // We may need to supply an extra dummy byte to our reader.
 // See Inflater.  We use a count here to simplify the logic
 // elsewhere in this class.  Note that we ignore the dummy
 // byte in methods where we know it is not needed.
 private int dummyByteCount;
 
@@ -725,26 +729,28 @@
   int i=length - 1;
   while ((i = 0)  (buffer[i] = 0x7f))
 {
   i--;
 }
   if (i  0)
 {
   result = new String(buffer, 0, pos, length);
 }
   else
 {
   ByteBuffer bufferBuffer = ByteBuffer.wrap(buffer, pos, length);
-  UTF8DECODER.reset();
-  char [] characters = UTF8DECODER.decode(bufferBuffer).array();
+  if (utf8Decoder == null)
+utf8Decoder = UTF8CHARSET.newDecoder();
+  utf8Decoder.reset();
+  char [] characters = utf8Decoder.decode(bufferBuffer).array();
   result = String.valueOf(characters);
 }
   return result;
 }
 
 String readString(int length) throws IOException
 {
   if (length  end - (bufferOffset + pos))
 throw new EOFException();
 
   String result = null;
   try


Re: [cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Roman Kennke

Hi again,

we are having problems here with java.io.File on Windows CE. Which 
handles files different again than other Windows and of course different 
than Unix. I could have hacked some more special casing in there. But 
I'd like to propose to pull some more methods into VMFile. See ChangeLog 
and attached patch. Basically this moves the impl of getAbsolutePath(), 
isAbsolute() and toURL() to VMFile.


The last patch here had a mistake. Here comes the corrected one.


2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* java/io/File.java
(getAbsolutePath): Fetch absolute path from
VMFile.getAbsolutePath(). Moved actual impl to there.
(isAbsolute): Let VMFile determine the absoluteness.
(toURL): Let VMFile convert the filename.
* vm/reference/java/io/VMFile.java
(getAbsolutePath): New method.
(isAbsolute): New method.
(toURL): New method.


/Roman


RE: [cp-patches] RFC: Object de-/serialization improvement

2006-08-15 Thread Jeroen Frijters
Roman Kennke wrote:
 Friedjof hacked up the Object de-/serialization code for improved 
 performance. It is now an order of magnitude faster.

Thanks. Most of it looks good. A few comments:

This looks funny:
+ {System.err.println(1);


I think this is bad style:
+catch (IllegalArgumentException _)
+  {
+InvalidClassException e = new InvalidClassException
+  (writing fields of class  + osc.forClass().getName());
+e.initCause(_);

I would only use _ if the exception object is not used.

This test is wrong:
+  || (l.getClass().getClassLoader() == null /* application loader
*/);

If an application instantiates URLClassLoader, it should still be
garbage collectable.

I think that he should consider using a cache that uses weak references
instead of this test.

Regards,
Jeroen



RE: [cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Jeroen Frijters
Hi Roman,

The attached patch file is empty.

Regards,
Jeroen 

 -Original Message-
 From: [EMAIL PROTECTED] 
 [mailto:[EMAIL PROTECTED] On Behalf Of Roman Kennke
 Sent: Tuesday, August 15, 2006 17:31
 To: Roman Kennke
 Cc: classpath-patches@gnu.org
 Subject: Re: [cp-patches] RFC: File/VMFile improvement
 
 Hi again,
 
  we are having problems here with java.io.File on Windows CE. Which 
  handles files different again than other Windows and of 
 course different 
  than Unix. I could have hacked some more special casing in 
 there. But 
  I'd like to propose to pull some more methods into VMFile. 
 See ChangeLog 
  and attached patch. Basically this moves the impl of 
 getAbsolutePath(), 
  isAbsolute() and toURL() to VMFile.
 
 The last patch here had a mistake. Here comes the corrected one.
 
 
 2006-08-15  Roman Kennke  [EMAIL PROTECTED]
 
  * java/io/File.java
  (getAbsolutePath): Fetch absolute path from
  VMFile.getAbsolutePath(). Moved actual impl to there.
  (isAbsolute): Let VMFile determine the absoluteness.
  (toURL): Let VMFile convert the filename.
  * vm/reference/java/io/VMFile.java
  (getAbsolutePath): New method.
  (isAbsolute): New method.
  (toURL): New method.
 
 
 /Roman
 



RE: [cp-patches] RFC: Object de-/serialization improvement

2006-08-15 Thread Jeroen Frijters
Roman Kennke wrote:
  This test is wrong:
  +  || (l.getClass().getClassLoader() == null /* 
 application loader
  */);
  
  If an application instantiates URLClassLoader, it should still be
  garbage collectable.
  
  I think that he should consider using a cache that uses 
 weak references
  instead of this test.
 
 AFAICS, the test is maybe a little aggressive and disallows 
 caching for classes that could even be cached (correct me if I'm
wrong).

No, it assumes that class loaders that are loaded by the boot class
loader are cacheable, but that's not the case. For example, an
application can instantiate a URLClassLoader and that would satify the
above caching test.

 I'd rather avoid dealing with WeakReferences unless 
 really needed.

Yeah, it may not be ideal either. Hmm, maybe we should add a caching
mechanism to ClassLoader?

Regards,
Jeroen



RE: [cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Jeroen Frijters
Roman Kennke wrote:
 Jeroen Frijters schrieb:
  Hi Roman,
  
  The attached patch file is empty.
 
 Ugh. My bad. Here it is.

Thanks. Looks like a good change to me.

Regards,
Jeroen



Re: [cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Tom Tromey
 Roman == Roman Kennke [EMAIL PROTECTED] writes:

Roman we are having problems here with java.io.File on Windows CE. Which
Roman handles files different again than other Windows and of course
Roman different than Unix.
[...]
Roman Maybe we should get rid of all the special casing anyway and provide a
Roman default straightforward impl for Posixy systems, for the sake of
Roman efficiency and cleanness.

It seems to me that this is an area we haven't handled very well: this
isn't really a VM thing per se -- the code could very well be
written in pure java -- but rather a platform thing.

I agree that adding special cases in File just makes the code uglier
and uglier.  But, we could delegate to a pure java platform class,
with instances for posixy, Windows, Windows CE, etc, and share the
code across all VMs.

We do something vaguely similar to this in libgcj (though in the
specific case of File we put the platform stuff in native code).

Tom



RE: [cp-patches] RFC: Object de-/serialization improvement

2006-08-15 Thread Jeroen Frijters
Roman Kennke wrote:
 What about
 
 || (l == VMClassLoader.getSystemClassLoader())
 
 instead ?

You shouldn't call VMClassLoader.getSystemClassLoader() (it creates a
new instance of the system class loader), but apart from that comparing
against the system class loader would work, but I'd much rather see a
solution that allows caching for other classes as well. I really would
like to explore the option of adding a field to ClassLoader a little
more (and hear other people's opinions about that).

Regards,
Jeroen



Re: [cp-patches] RFC: File/VMFile improvement

2006-08-15 Thread Casey Marshall
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Tom Tromey wrote:
 Roman == Roman Kennke [EMAIL PROTECTED] writes:
 
 Roman we are having problems here with java.io.File on Windows CE. Which
 Roman handles files different again than other Windows and of course
 Roman different than Unix.
 [...]
 Roman Maybe we should get rid of all the special casing anyway and provide a
 Roman default straightforward impl for Posixy systems, for the sake of
 Roman efficiency and cleanness.
 
 It seems to me that this is an area we haven't handled very well: this
 isn't really a VM thing per se -- the code could very well be
 written in pure java -- but rather a platform thing.
 
 I agree that adding special cases in File just makes the code uglier
 and uglier.  But, we could delegate to a pure java platform class,
 with instances for posixy, Windows, Windows CE, etc, and share the
 code across all VMs.
 
 We do something vaguely similar to this in libgcj (though in the
 specific case of File we put the platform stuff in native code).
 

FWIW I agree. Some of us were chatting about this on IRC, and not only
are these VM interfaces more often than not platform interfaces (or
with some things, all they rely on is JNI and standard C), but they do
lead to performance hits (witness our direct ByteBuffer).

I think putting some design thought into this is a good idea, because
right now I don't think we have any clear idea about what the scope or
purpose of VM/platform interfaces are. Right now, it looks like it's
just an ad-hoc catch-all for anything that can't be done in pure Java --
you slap a VM class on it, and hack up the core class.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.3 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iQEVAwUBROIpJuRILCRAfKHCAQIX5wf/aog1Jk+M1HNBKd7HZ6vzciTuPAynvlZ+
U+v7fvGI4FWaoCMUidB3rwov+gJhTXFpJpBy7ytGRExgpaJNp2Mp3kDpUJiInwYs
pGh4rmzPvEd8dgkRyL7e4ccBF9ze7Ix7DzhXsldgNypOBDN+Bs7e1A9PjClnxQN8
t84Ii6YKeiifusAPRtgkmsS1wKF4PbCZ7YOdtT/BI6PfaERpgI4V/EnKASwx5Zp2
Z43NGTi/vvRb+qeOFbfhs8XA41EK5eb7ODDD6+W88PKcPUGLgaDlWHCP92XZdrS2
I/K4Ca9vluGs94WcMaflz7dFv9ofko4s9LmygqTIY+I8BKaXz2jTTw==
=V2jF
-END PGP SIGNATURE-



[cp-patches] Patch: DropTargetDragEvent fix

2006-08-15 Thread Lillian Angel
Implemented a missing function

2006-08-15  Lillian Angel  [EMAIL PROTECTED]

* java/awt/dnd/DropTargetDragEvent.java
(getTransferable): Implemented.

Index: java/awt/dnd/DropTargetDragEvent.java
===
RCS file: /cvsroot/classpath/classpath/java/awt/dnd/DropTargetDragEvent.java,v
retrieving revision 1.6
diff -u -r1.6 DropTargetDragEvent.java
--- java/awt/dnd/DropTargetDragEvent.java	17 Jul 2006 18:37:19 -	1.6
+++ java/awt/dnd/DropTargetDragEvent.java	15 Aug 2006 20:33:50 -
@@ -147,7 +147,6 @@
*/
   public Transferable getTransferable()
   {
-// FIXME: Not implemented
-return null;
+return context.getTransferable();
   }
 } // class DropTargetDragEvent


[cp-patches] FYI: BasicTreeUI/DefaultTreeCellEditor fixes

2006-08-15 Thread Roman Kennke
This implements the last missing methods in BasicTreeUI and fixes a 
couple of inconsistencies in the handling of JTree editing. I hope I 
didn't introduce any glitches again, please let me know if that's the 
case and I'll fix it.


2006-08-15  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/basic/BasicTreeUI.java
(MouseHandler.selectedOnPress): New field.
(MouseHandler.handleEvent): New helper method for handling
selection and start/stop editing for mouse events.
(MouseHandler.mouseDragged): Commented as no-op method.
(MouseHandler.mouseMoved): Commented as no-op method.
(MouseHandler.mousePressed): Use handleEvent() to handle
selection and editing handling.
(MouseHandler.mouseReleased): Use handleEvent() to handle
selection and editing handling.
(MouseInputHandler.MouseInputHandler): Register itself
as mouse listener on source. Redispatch event to
destination.
(MouseInputHandler.dispatch): New helper method.
(MouseInputHandler.mouseClicked): Dispatch event.
(MouseInputHandler.mouseDragged): Dispatch event.
(MouseInputHandler.mouseEntered): Stop dispatching
if dragging stopped.
(MouseInputHandler.mouseExited): Stop dispatching
if dragging stopped.
(MouseInputHandler.mouseMoved): Stop dispatching.
(MouseInputHandler.mousePressed): Marked as no-op.
(MouseInputHandler.mouseReleased): Dispatch and stop
dispatching afterwards.
(MouseInputHandler.removeFromSource): Implemented.
(PropertyChangeHandler.propertyChange): Also handle
editable property changes by calling setEditable().
(SelectionModelPropertyChangeHandler.propertyChange):
Reset row selection.
(startEditTimer): Removed.
(setCellEditor): Call updateEditor().
(setEditable): Call updateEditor().
(startEditingAtPath): Make path fully visible before starting
editing.
(startEditing): Maybe cancel previous edit session. Add
editing component itself, not its parent container.
Register MouseInputHandler for correctly redispatching
initial events.
(stopEditing): Message cellEditor and only completeEditing()
when approved by cell editor.
(updateCellEditor): Complete editing before updating
the cell editor. Get cell editor from JTree if possible,
otherwise create default editor. Update the listeners
on the editor.
* javax/swing/tree/DefaultTreeCellEditor.java
(CLICK_COUNT_TO_START): Removed.
(DefaultTreeCellEditor): Install correct border. Let setTree()
update the listeners. Don't initialize lastPath and font yet.
(actionPerformed): Implemented to start editing.
(createTreeCellEditor): Set click count to start to 1, rather than
3.
(isCellEditable): Prepare editor here. Determine if we can
start immediately, or if we trigger a timer to do so.
(prepareForEditing): Don't removeAll() (not necessary),
check editingComponent to be non-null.
(setTree): Update listeners.
(shouldStartEditingTimer): Check for left mouse button.
(startEditingTimer): Lazily create timer.

/Roman
Index: javax/swing/plaf/basic/BasicTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTreeUI.java,v
retrieving revision 1.152
diff -u -1 -2 -r1.152 BasicTreeUI.java
--- javax/swing/plaf/basic/BasicTreeUI.java	8 Aug 2006 12:08:58 -	1.152
+++ javax/swing/plaf/basic/BasicTreeUI.java	15 Aug 2006 23:34:10 -
@@ -29,35 +29,35 @@
  modules, and to copy and distribute the resulting executable under
  terms of your choice, provided that you also meet, for each linked
  independent module, the terms and conditions of the license of that
  module.  An independent module is a module which is not derived from
  or based on this library.  If you modify this library, you may extend
  this exception to your version of the library, but you are not
  obligated to do so.  If you do not wish to do so, delete this
  exception statement from your version. */
 
 
 package javax.swing.plaf.basic;
 
-import gnu.classpath.NotImplementedException;
 import gnu.javax.swing.tree.GnuPath;
 
 import java.awt.Color;
 import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.Font;
 import java.awt.FontMetrics;
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Label;
+import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.ComponentAdapter;
 import java.awt.event.ComponentEvent;
 import java.awt.event.ComponentListener;
 import java.awt.event.FocusEvent;
 import java.awt.event.FocusListener;
 import java.awt.event.InputEvent;
 import 

[cp-patches] FYI: MetalTreeUI lineStyle support

2006-08-15 Thread Roman Kennke
This implements the missing pieces in MetalTreeUI, which is support for 
the JTree.lineStyle client propoperty. This is actually well documented 
and was fairly straightforward to implement. I added some bits to the 
TreeDemo to try it out quickly.


2006-08-16  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/plaf/metal/MetalTreeUI.java
(LineStyleListener): New property listener, that updates
the line style setting if the corresponding property
changes.
(lineStyleListener): New field.
(lineStyle): New field.
(LINE_STYLE_ANGLED): New constant field.
(LINE_STYLE_HORIZONTAL): New constant field.
(LINE_STYLE_NONE): New constant field.
(LINE_STYLE_VALUE_ANGLED): New constant field.
(LINE_STYLE_VALUE_HORIZONTAL): New constant field.
(LINE_STYLE_VALUE_NONE): New constant field.
(LINE_STYLE_PROPERTY): New constant field.
(decodeLineStyle): Implemented.
(installUI): Install line style listener. Set initial
lineStyle.
(uninstallUI): Uninstall line style listener.
(paintHorizontalPartOfLeg): Only call super for angled
lineStyle.
(paintVerticalPartOfLeg): Only call super for angled
lineStyle.
(paintHorizontalSeparators): Implemented.
(paint): If lineStyle==HORIZONTAL, call
paintHorizontalSeparators().
* examples/gnu/classpath/examples/swing/TreeDemo.java
(createContent): Add panel for selecting line styles.   


/Roman
Index: javax/swing/plaf/metal/MetalTreeUI.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/metal/MetalTreeUI.java,v
retrieving revision 1.17
diff -u -1 -2 -r1.17 MetalTreeUI.java
--- javax/swing/plaf/metal/MetalTreeUI.java	23 Mar 2006 00:30:14 -	1.17
+++ javax/swing/plaf/metal/MetalTreeUI.java	16 Aug 2006 00:30:30 -
@@ -29,42 +29,105 @@
 modules, and to copy and distribute the resulting executable under
 terms of your choice, provided that you also meet, for each linked
 independent module, the terms and conditions of the license of that
 module.  An independent module is a module which is not derived from
 or based on this library.  If you modify this library, you may extend
 this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
 
 package javax.swing.plaf.metal;
 
-import gnu.classpath.NotImplementedException;
-
 import java.awt.Graphics;
 import java.awt.Insets;
 import java.awt.Rectangle;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
 
 import javax.swing.JComponent;
 import javax.swing.JTree;
+import javax.swing.UIManager;
 import javax.swing.tree.TreePath;
 import javax.swing.plaf.ComponentUI;
 import javax.swing.plaf.basic.BasicTreeUI;
 
 /**
  * A UI delegate for the [EMAIL PROTECTED] JTree} component.
  */
 public class MetalTreeUI extends BasicTreeUI
 {
   /**
+   * Listens for property changes of the line style and updates the
+   * internal setting.
+   */
+  private class LineStyleListener
+implements PropertyChangeListener
+  {
+
+public void propertyChange(PropertyChangeEvent e)
+{
+  if (e.getPropertyName().equals(LINE_STYLE_PROPERTY))
+decodeLineStyle(e.getNewValue());
+}
+  
+  }
+
+  /**
+   * The key to the lineStyle client property.
+   */
+  private static final String LINE_STYLE_PROPERTY = JTree.lineStyle;
+
+  /**
+   * The property value indicating no line style.
+   */
+  private static final String LINE_STYLE_VALUE_NONE = None;
+
+  /**
+   * The property value indicating angled line style.
+   */
+  private static final String LINE_STYLE_VALUE_ANGLED = Angled;
+
+  /**
+   * The property value indicating horizontal line style.
+   */
+  private static final String LINE_STYLE_VALUE_HORIZONTAL = Horizontal;
+
+  /**
+   * The line style for None.
+   */
+  private static final int LINE_STYLE_NONE = 0;
+
+  /**
+   * The line style for Angled.
+   */
+  private static final int LINE_STYLE_ANGLED = 1;
+
+  /**
+   * The line style for Horizontal.
+   */
+  private static final int LINE_STYLE_HORIZONTAL = 2;
+
+  /**
+   * The current line style.
+   */
+  private int lineStyle;
+
+  /**
+   * Listens for changes on the line style property and updates the
+   * internal settings.
+   */
+  private PropertyChangeListener lineStyleListener;
+
+  /**
* Constructs a new instance of codeMetalTreeUI/code.
*/
   public MetalTreeUI()
   {
 super();
   }
 
   /**
* Returns a new instance of codeMetalTreeUI/code.
*
* @param component the component for which we return an UI instance
*
@@ -94,59 +157,72 @@
*opacity, etc. on the component. Whenever possible, property values
*initialized by the client program should not be overridden.
* 2. Install a LayoutManager on the 

[cp-patches] RFC: java.util.regex.Matcher#hitEnd()

2006-08-15 Thread Ito Kazumitsu
From: Ito Kazumitsu [EMAIL PROTECTED]
Subject: Re: [cp-patches] RFC: java.util.regex.Matcher#hitEnd()
Date: Mon, 07 Aug 2006 02:13:34 +0900 (JST)

 I have made a patch and a mauve test for this, and put it at
 http://www.jsdi.or.jp/~maczuka/programs/regex-patched.tar.gz,
 but I will be on vacation soon and have no time to prepare an RFC
 message.

Here it is.

ChangeLog:
2006-08-16  Ito Kazumitsu  [EMAIL PROTECTED]

Fixes bug #28412
* gnu/java/util/regex/CharIndexed.java(move1, setHitEnd, hitEnd):
New methods.
* gnu/java/util/regex/CharIndexedCharSequence.java,
gnu/java/util/regex/CharIndexedInputStream.java: Implemented the
new methods above.
* gnu/java/util/regex/RE.java(REG_FIX_STARTING_POSITION): New flag,
(match): call the new method setHitEnd of the input,
(getMatchImpl): Handle the new flag REG_FIX_STARTING_POSITION,
Some optimization commented out, Use CharIndexed#move1 instead of move.
* gnu/java/util/regex/REMatch.java: Made some debugging methods public.
* gnu/java/util/regex/REToken.java(match): The method body has been
moved to an internal private method, (matchFake): New method,
(setHitEnd): New method.
* gnu/java/util/regex/RETokenChar.java(matchThis): Call setHitEnd
if the match is not complete, (matchOneString): Count the number of
characters which matched the pattern.
* gnu/java/util/regex/RETokenEnd.java(fake): New field,
(setFake): New method, (match): Call super.match or super.matchFake.
* gnu/java/util/regex/RETokenEndSub.java(setHitEnd): New method.
* gnu/java/util/regex/RETokenOneOf.java(match): call the new method
setHitEnd of the input,
* gnu/java/util/regex/RETokenRepeated.java(match): Likewise.
* java/util/regex/Matcher.java(lookingAt, match): Use the new flag
RE.REG_FIX_STARTING_POSITION, (hitEnd, toString): New methods.

Index: classpath/gnu/java/util/regex/CharIndexed.java
===
RCS file: /cvsroot/classpath/classpath/gnu/java/util/regex/CharIndexed.java,v
retrieving revision 1.1
diff -u -r1.1 CharIndexed.java
--- classpath/gnu/java/util/regex/CharIndexed.java  7 Jun 2006 19:30:06 
-   1.1
+++ classpath/gnu/java/util/regex/CharIndexed.java  16 Aug 2006 00:12:58 
-
@@ -77,6 +77,13 @@
 boolean move(int index);
 
 /**
+ * Shifts the input buffer by a given number of positions.  Returns
+ * true if the new cursor position is valid or cursor position is at
+ * the end of input.
+ */
+boolean move1(int index); // I cannot think of a better name for this.
+
+/**
  * Returns true if the most recent move() operation placed the cursor
  * position at a valid position in the input.
  */
@@ -105,6 +112,16 @@
 REMatch getLastMatch();
 
 /**
+ * Sets the information used for hitEnd().
+ */
+void setHitEnd(REMatch match);
+
+/**
+ * Returns whether the matcher has hit the end of input.
+ */
+boolean hitEnd();
+
+/**
  * Returns the anchor.
  */
 int getAnchor();
Index: classpath/gnu/java/util/regex/CharIndexedCharSequence.java
===
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/regex/CharIndexedCharSequence.java,v
retrieving revision 1.1
diff -u -r1.1 CharIndexedCharSequence.java
--- classpath/gnu/java/util/regex/CharIndexedCharSequence.java  7 Jun 2006 
19:30:06 -   1.1
+++ classpath/gnu/java/util/regex/CharIndexedCharSequence.java  16 Aug 2006 
00:12:58 -
@@ -62,6 +62,10 @@
return ((anchor += index)  len);
 }
 
+public boolean move1(int index) {
+   return ((anchor += index) = len);
+}
+
 public CharIndexed lookBehind(int index, int length) {
if (length  (anchor + index)) length = anchor + index;
return new CharIndexedCharSequence(s, anchor + index - length);
@@ -77,6 +81,15 @@
lastMatch.anchor = anchor;
 }
 public REMatch getLastMatch() { return lastMatch; }
+
+private int rightmostTriedPosition = 0;
+public void setHitEnd(REMatch match) {
+int pos = anchor + match.index;
+if (pos  rightmostTriedPosition) rightmostTriedPosition = pos;
+}
+public boolean hitEnd() { return rightmostTriedPosition = len; }
+
 public int getAnchor() { return anchor; }
 public void setAnchor(int anchor) { this.anchor = anchor; }
+
 }
Index: classpath/gnu/java/util/regex/CharIndexedInputStream.java
===
RCS file: 
/cvsroot/classpath/classpath/gnu/java/util/regex/CharIndexedInputStream.java,v
retrieving revision 1.1
diff -u -r1.1 CharIndexedInputStream.java
--- classpath/gnu/java/util/regex/CharIndexedInputStream.java   7 Jun 2006 
19:30:06 -   1.1
+++