Bug 137336 - Request for update.core to avoid nio transferTo
Summary: Request for update.core to avoid nio transferTo
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Update (deprecated - use Eclipse>Equinox>p2) (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P1 major (vote)
Target Milestone: 3.2 RC3   Edit
Assignee: Branko Tripkovic CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-04-18 15:14 EDT by Phil Loats CLA
Modified: 2006-05-03 17:48 EDT (History)
6 users (show)

See Also:


Attachments
patch for requested change (1.58 KB, patch)
2006-04-18 15:18 EDT, Phil Loats CLA
no flags Details | Diff
alternate patch to test for NIO classes (3.77 KB, patch)
2006-04-20 17:41 EDT, Phil Loats CLA
no flags Details | Diff
updated patch to test for NIO classes (3.87 KB, patch)
2006-04-20 18:29 EDT, Phil Loats CLA
no flags Details | Diff
final patch to test for NIO classes (3.77 KB, patch)
2006-04-20 19:10 EDT, Phil Loats CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Phil Loats CLA 2006-04-18 15:14:38 EDT
We've got one single instance in WED & sametime from org.eclipse.update.core that is using FileChannel#transferTo() to copy a file.  Would there be any chance we could get a change  for 3.2GM for update.core to copy a file using standard streams?  The NIO buffer APIs drag in ICU code that is a major problem for jcl platforms.  I provide a patch.
Comment 1 Phil Loats CLA 2006-04-18 15:18:48 EDT
Created attachment 38839 [details]
patch for requested change

Note, I did not test this patch in the Eclipse code context.
Comment 2 Dejan Glozic CLA 2006-04-18 15:31:05 EDT
Phil, there is probably a reason why we used NIO class in this context. What is the performance downside of reverting to IO here?
Comment 3 Phil Loats CLA 2006-04-18 15:33:39 EDT
I assumed it was used because it was convenient.  If there is a performance concern, a better fix will be required to test for the NIO package first.
Comment 4 Dejan Glozic CLA 2006-04-18 15:59:10 EDT
Dorian, I think you used NIO in certain places in Update. Was it for performance reasons or just for fun? Will the attached patch affect the performance in some way?
Comment 5 Dejan Glozic CLA 2006-04-18 16:34:41 EDT
Branko, Konrad, do you remember why this particular section of code uses NIO?
Comment 6 Jeff McAffer CLA 2006-04-18 22:19:20 EDT
yeah, I gotta imagine that the patch code will run slower but Phil's point in comment 3 was that the patch should then simply do a Class.forName("java.nio.FileChannel) and then depending on the outcome, either run the slow java.io code or the fast java.nio code.  We have coded this pattern in several places (e.g., related to locking).

Perhaps Phil can provide an updated patch to this effect?
Comment 7 Branko Tripkovic CLA 2006-04-18 22:25:05 EDT
No, as far as i know it was there before i came on board. Konrad or Dorian should know more
Comment 8 Dorian Birsan CLA 2006-04-18 22:31:31 EDT
That's what happen when you have too much work on your plate, you don't remember what you did :-)


Check this link:

http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.update.core/src/org/eclipse/update/internal/core/JarDeltaInstallHandler.java
Comment 9 Branko Tripkovic CLA 2006-04-19 09:50:38 EDT
yes, i am sorry it is me. I will check it out
Comment 10 Phil Loats CLA 2006-04-20 17:41:09 EDT
Created attachment 39116 [details]
alternate patch to test for NIO classes

Here is an alternate patch that tests for the NIO package and falls back to 
the standard stream method. Note this patch requires putting the NIO calls into 
another class to prevent the verifier from complaining about the original class.

I'd still prefer to have the original patch if we can understand if there is really a performance issues in this code. Can someone explain the context this code get utilized?

Note, I did not test this code in the update code context. The code was tested against jclMax 2.3.
Comment 11 Phil Loats CLA 2006-04-20 18:29:26 EDT
Created attachment 39119 [details]
updated patch to test for NIO classes

Berthold pointed out I should remember class not found and avoid the exception more than once.  Thanks Berthold.  This is an updated patch that includes this.
Comment 12 Phil Loats CLA 2006-04-20 19:10:27 EDT
Created attachment 39123 [details]
final patch to test for NIO classes

After more discussion, catching all other Exceptions would be bad as a null pointer would disable NIO copies in the previos patch. Testing shows that we can only get the errors at runtime.  So this final patch catches just the errors and all other exceptions pass back to the caller.
Comment 13 Jeff McAffer CLA 2006-04-20 21:37:49 EDT
You are making life way to hard.  First, for NIO functionality as follows

try {
  useNioCopy = Class.forName("java.nio.FileChannel") != null;
} catch (ClassNotFoundException e) {
  useNioCopy = false;
}

Just do this once (e.g., in a static initializer.

Then just write copyFile() and nioCopyFile() methods and use
if (useNioCopy)
  nioCopyFile(...);
else
  copyFile(...);

clean and simple.

The issue about having another class is interesting and the subject some debate around here.  I just wrote a simple test that refrences a class in the true part  of an if().  If I run the code such taht the condition is false, the class in the true part is not loaded.  That is, I am not seeing a need to have a separate class.  I wonder
a) if I am missing something and am testing incorrectly
b) there is a VM difference and on some VMs the class is actually loaded at verify time.  Somewhat separate topic but any thoughts?

In any event, if it really is true then the nioCopyFile can be done the way you have in the current patch.  The nio existance check should still be simplified as it eliminates the need to catch some exceptions etc.
Comment 14 Phil Loats CLA 2006-04-20 22:13:25 EDT
The patch supplied is very deliberate.  jclmax will provide the locking methods from java.nio, but not the transfer and char buffer. I feel the patch supplied is not overly difficult and it covers all possible cases where the FileChannel class test does not.
The seperate class for the NIO functions is required, no doubt.  If it is not in a seperate class, the class verify will fail loading the JarDeltaInstallHandler because the class java.nio.channels.WritableByteChannel is not available (which is required because of the implicit type cast of the output FileChannel to WriteableByteChannel). I have verified that this is the only way the code will execute correctly.

Now, I'd still prefer to just remove the NIO code completely.  Anyone know the context this code gets executed?
Comment 15 Phil Loats CLA 2006-04-25 14:58:26 EDT
Any chance of getting this into Eclipse 3.2 yet?
Comment 16 Jeff McAffer CLA 2006-04-26 11:19:57 EDT
Ok, so it looks like this patch is the one that we want to put forward.  The Update team should see what they think.  Hopefully this can go in for RC2
Comment 17 Dejan Glozic CLA 2006-04-26 11:38:11 EDT
Branko, please integrate the patch and do some sanity tests to see if everything is ok with it in place.
Comment 18 Dejan Glozic CLA 2006-05-03 10:33:27 EDT
Need to be done for RC3
Comment 19 John Arthorne CLA 2006-05-03 11:25:44 EDT
For what it's worth, I did fairly extensive performance testing of FileChannel-based copy versus stream-based copy, and I found no performance improvement (and a slight performance hit on Linux).  I admit the implementation of file copying is much cleaner using FileChannel.transferTo, but if you're doing it for the performance, it doesn't buy you anything. See bug 124209 for details.
Comment 20 John Arthorne CLA 2006-05-03 11:26:26 EDT
Sorry, looks like I slammed the priority field - changing back to P1.
Comment 21 Branko Tripkovic CLA 2006-05-03 13:37:05 EDT
Released.
Comment 22 Dejan Glozic CLA 2006-05-03 15:01:21 EDT
Need formal votes.

Dejan adds +1.
Comment 23 Dejan Glozic CLA 2006-05-03 15:02:01 EDT
Jeff, need additional +1 before releasing.
Comment 24 Dejan Glozic CLA 2006-05-03 16:38:58 EDT
Wassim, you can help Jeff to unblock this backlog. This bug is checked and ready to go.
Comment 25 Wassim Melhem CLA 2006-05-03 16:42:17 EDT
+1 for RC3
Comment 26 Branko Tripkovic CLA 2006-05-03 17:48:05 EDT
fixed