You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by "Mikhail Markov (JIRA)" <ji...@apache.org> on 2007/02/15 16:28:05 UTC

[jira] Updated: (HARMONY-3085) [classlib][nio] FileChannel.transferTo() and FileChannel.map() throws IOException when used file is large and position is equal or greater than 4096

     [ https://issues.apache.org/jira/browse/HARMONY-3085?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Mikhail Markov updated HARMONY-3085:
------------------------------------

    Attachment: H-3085.patch

Here is the patch for the code and a regression test.

Fix description: For mapping file to memory MapViewOfFile() function from Windows API is used. It requires the offset aligned to allocation granularity, which is 64K for Windows on the contrary to page size (4K). So the fix modifies the procedure of getting this value for Windows (and adds the appropriate comments for the java method). Note that on Linux another mechanizm (mmap() function) is used and allocation granularity is equal to page size so no modification is needed there.

> [classlib][nio] FileChannel.transferTo() and FileChannel.map() throws IOException when used file is large and position is equal or greater than 4096
> ----------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HARMONY-3085
>                 URL: https://issues.apache.org/jira/browse/HARMONY-3085
>             Project: Harmony
>          Issue Type: Bug
>          Components: Classlib
>         Environment: Windows
>            Reporter: Vera Petrashkova
>         Attachments: H-3085.patch, testFileChannel.zip
>
>
> Reliability tests
>     api.nio.channels.filechannel.CopyFilesTest
>     api.nio.channels.filechannel.FileChannelMapTest
> fail with IOException when "position" parameter in 
>     FileChannel.tansferTo(long position, long count, WritableByteChannel target)    and 
>     FileChannel.map(FileChannel.MapMode mode,  long position, long size)
> methods is equal or greater than 4096.
> The following test demonstrates this issue:
> ----------------testFileChannel.java-------------------
> import java.io.*;
> import java.nio.channels.FileChannel;
> public class testFileChannel {
>     public static void main (String[] argv) {
>         FileChannel from = null;
>         FileChannel to = null;
>         long pp = Integer.parseInt(argv[1]); 
>         long size = Integer.parseInt(argv[2]); 
>         try {
>             from = new FileInputStream(argv[0]).getChannel();
>             to = new FileOutputStream("to.txt").getChannel();
>         } catch (Throwable e) {
>             e.printStackTrace();
>             return;
>         }
>         System.err.println("=====transferTo test=====");
>         try {
>             from.position(pp); 
>             long transfered = from.transferTo(pp , size,  to);        
>             System.err.println("Test passed: trasfered == " +transfered);
>         } catch (Throwable e) {
>             System.err.println("Test failed ");
>             e.printStackTrace();
>         }
>         System.err.println("=====map test=====");
>         try {
>             from.position(pp); 
>             from.map(FileChannel.MapMode.READ_ONLY, pp,size);
>             System.err.println("Test passed ");
>         } catch (Throwable e) {
>             System.err.println("Test failed ");
>             e.printStackTrace();
>         }
>     }
> }
> ----------------------------
> 1) Create testFileChannel class
> 2) Run test using from.txt file from attachment and define position as 4095 and size parameter
>      java -cp . testFileChannel from .txt 4095 10
> =====transferTo test=====
> Test passed: trasfered == 10
> =====map test=====
> Test passed
> 3) Run test using from.txt file from attachment and define position as 4096 and size parameter
>      java -cp . testFileChannel from .txt 4096 10
> =====transferTo test=====
> Test failed
> java.io.IOException
>         at org.apache.harmony.luni.platform.OSMemory.mmap(OSMemory.java:544)
>         at org.apache.harmony.luni.platform.PlatformAddressFactory.allocMap(PlatformAddressFactory.java:37)
>         at org.apache.harmony.nio.internal.FileChannelImpl.mapImpl(FileChannelImpl.java:194)
>         at org.apache.harmony.nio.internal.ReadOnlyFileChannel.map(ReadOnlyFileChannel.java:87)
>         at org.apache.harmony.nio.internal.FileChannelImpl.transferTo(FileChannelImpl.java:446)
>         at testFileChannel.main(testFileChannel.java:20)
> =====map test=====
> Test failed
> java.io.IOException
>         at org.apache.harmony.luni.platform.OSMemory.mmap(OSMemory.java:544)
>         at org.apache.harmony.luni.platform.PlatformAddressFactory.allocMap(PlatformAddressFactory.java:37)
>         at org.apache.harmony.nio.internal.FileChannelImpl.mapImpl(FileChannelImpl.java:194)
>         at org.apache.harmony.nio.internal.ReadOnlyFileChannel.map(ReadOnlyFileChannel.java:87)
>         at testFileChannel.main(testFileChannel.java:31)

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.