Patch: Moving native methods fo java.io.File into java.io.VMFile

Bryce McKinlay mckinlay@redhat.com
Tue Sep 21 11:23:00 GMT 2004


Michael Koch wrote:

>I have written the attached patch to move the native methods from 
>java.io.File to java.ioVMFile. This allows us merging java.io.File 
>with GNU classpath. This is important to merge fixes fast in both 
>directions. GNU classpath has some fixes (security and file 
>truncation) which are still not completely merge because of the 
>current differences.
>
>Mohan Embar has helped with the Win32 part of the code. He bugfixed 
>and tested my changes to it.
>
>Andreas Tobler has tested the patch on his multiple platforms with 
>mauve. Some Mauve tests are sometimes failing and sometimes passes 
>(Even before this patch). I will investigate this when the patch is 
>in.
>
>Okay to commit to trunk ?
>  
>
I think this patch should be deferred for now, and revisited after 4.0 
branches.

It would add significant overhead to all file access in libgcj. An extra 
layer of indirection added for many of the File methods, and because the 
calls (and field access) are static, this will result in additional 
class initialization checks being emitted. Conjecturally, File 
performance is important for many applications and we should take care 
to make it as fast as possible.

I'm not opposed to VMFile in general, if it means we can merge fully 
with classpath and clean up the File code. But, I'd prefer an 
implementation that allows us to directly call the native methods from 
File rather than going through an additional layer of calls. I guess the 
VMFile interface could be improved after the initial change, but it 
still will result in a slowdown, and possible regressions, initially.

Also, in the past, we've considered optimizing File by caching the 
platform-encoded version of the path string so that it doesn't need to 
be encoded again for every call. This would become more important if we 
ever decided to support native encodings other than our fast Utf8 
converter. VMFile might make that more difficult, because there isn't 
anywhere to store the cached copy.


>@@ -179,11 +142,33 @@
>    */
>   public boolean canWrite()
>   {
>+    // First do a SecurityCheck before doing anything else.
>     checkWrite();
>-    return _access (WRITE);
>+     
>+    // Test for existence.  This is required by the spec
>+    if (! VMFile.exists(path))
>+      return false;
>+
>+    if (!VMFile.isDirectory(path))
>+      return VMFile.canWrite(path);
>+    else
>+      try
>+        {
>+          /* If the separator is '\' a DOS-style-filesystem is assumed
>+             and a short name is used, otherwise use a long name.
>+             WARNING: some implementation of DOS-style-filesystems also
>+             accept '/' as separator. In that case the following code
>+             will fail.
>+          */
>+          String filename = (separatorChar!='\\')?"test-dir-write":"tst";
>+  	  File test = createTempFile(filename, null, this);
>+  	  return (test != null && test.delete());
>+        }
>+      catch (IOException ioe)
>+        {
>+  	  return false;
>+        }
>   }
>  
>
This canWrite() implementation looks a lot less efficient than what we 
had before! Surely the createTempFile() call is a platform-specific 
requirement, and thus should be in VMFile?

Regards

Bryce




More information about the Java-patches mailing list