harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Artem Aliev (JIRA)" <j...@apache.org>
Subject [jira] Created: (HARMONY-2417) [luni] java.nio.MappedByteBuffer.isLoaded() returns true while RI returns false
Date Mon, 04 Dec 2006 12:47:21 GMT
[luni] java.nio.MappedByteBuffer.isLoaded() returns true while RI returns false
-------------------------------------------------------------------------------

                 Key: HARMONY-2417
                 URL: http://issues.apache.org/jira/browse/HARMONY-2417
             Project: Harmony
          Issue Type: Bug
          Components: Classlib
            Reporter: Artem Aliev
            Priority: Minor


According to J2SE API specifications of java.nio.MappedByteBuffer class

public final boolean isLoaded()
    Tells whether or not this buffer's content is resident in physical memory. 
    A return value of true implies that it is highly likely that all of the 
    data in this buffer is resident in physical memory and may therefore be 
    accessed without incurring any virtual-memory page faults or I/O 
    operations. A return value of false does not necessarily imply that the 
    buffer's content is not resident in physical memory. 
    The returned value is a hint, rather than a guarantee, because the 
    underlying operating system may have paged out some of the buffer's data by 
    the time that an invocation of this method returns. 
Returns: 
    true if it is likely that this buffer's content is resident in physical 
    memory


When some MappedByteBuffer was created by FaileChannel.map(...) method then 
all bytes from the file are put to the buffer but
MappedByteBuffer.isloaded() returns on Harmony different results on Windows
and Linux.
This method returns:
    - On Harmony: false on Windows and true - on Linux
    - On RI: always returns false (on Windows and Linux)

Code for reproducing:
---------------------HT.java--------------
import java.nio.*;
import java.nio.channels.*;
import java.io.*;
import junit.framework.TestCase;

public class HT extends TestCase {
    public void testMap() {
        File tempFile = new File("./", "tempFile.txt");
        tempFile.deleteOnExit();

        String testString = "1234567890 - Proba pera";
        try {
            FileOutputStream fos = new FileOutputStream(tempFile);
            for (int i = 0; i < testString.length(); i++) {
                fos.write(testString.charAt(i));
            }
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
            fail("Unexpected error on file initialization");
        }

        FileInputStream fis = null;
        MappedByteBuffer mappedBuf = null;
        int fileLength = 0;
        try {
            fis = new FileInputStream(tempFile);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            fail("Unexpected exception: Can't open file");
        }

        FileChannel channel = fis.getChannel();

        try {
            fileLength = (int) channel.size();

            mappedBuf = channel.map(FileChannel.MapMode.READ_ONLY, 0,
fileLength);

        } catch (IOException e) {
           e.printStackTrace();
           fail("Unexpected exception: "+e );
        }

        System.out.println("File length: "+fileLength+"  Buf capacity:
"+mappedBuf.capacity());
        if (fileLength != mappedBuf.capacity()) {
            fail("Incorrect capacity");
        }
        for (int i = 0; i < fileLength; i++) {
            int c1 = mappedBuf.get();
            int c2 = (int)testString.charAt(i);
            if (c1 != c2) {
                System.out.println("Incorrect char ("+i+") : "+c1 +"  must be:
"+c2);
                return;
            }
        }
        System.out.println("File and Buffer contain the same chars");

        System.out.println("isLoaded(): "+mappedBuf.isLoaded());

    }
}
---------------------------------------
Steps to Reproduce:
Create HT class and run it

java -cp .:junit.jar junit.textui.TestRunner HT


Output:
- On Linux (RI)
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-b64)
BEA WebLogic JRockit(R) (build dra-38972-20041208-2001-linux-ia32, R25.0.0-75,
GC: System optimized over throughput (initial strategy singleparpar))

.File length: 23  Buf capacity: 23
File and Buffer contain the same chars
isLoaded(): false

Time: 0.037

OK (1 test)


- On Linux (Harmony)
Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
Foundation or its licensors, as applicable.
java version "1.5.0" 
pre-alpha : not complete or compatible
svn = rsvn: '.' is not a working copy, (Sep 26 2006), Linux/ia32/gcc 3.3.3,
release build
http://incubator.apache.org/harmony
.File length: 23  Buf capacity: 23
File and Buffer contain the same chars
isLoaded(): true
F
Time: 0.029
There was 1 failure:
1) testMap(HT)junit.framework.AssertionFailedError: isLoaded()
        at HT.testMap(HT.java:60)
        at java.lang.reflect.VMReflection.invokeMethod(Native Method)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0

Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
Foundation or its licensors, as applicable.
.File length: 23  Buf capacity: 23
File and Buffer contain the same chars
isLoaded(): true
F
Time: 0.015
There was 1 failure:
1) testMap(HT)junit.framework.AssertionFailedError: isLoaded()
        at HT.testMap(HT.java:60)
        at java.lang.reflect.AccessibleObject.invokeV(AccessibleObject.java:25)

FAILURES!!!
Tests run: 1,  Failures: 1,  Errors: 0




- On Windows ( RI )
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Client VM (build 1.5.0_06-b05, mixed mode)

.File length: 23  Buf capacity: 23
File and Buffer contain the same chars
isLoaded(): false

Time: 0.032

OK (1 test)

- On Windows (Harmony)
Apache Harmony Launcher : (c) Copyright 1991, 2006 The Apache Software
Foundation or its l
icensors, as applicable.
java version "1.5.0"
pre-alpha : not complete or compatible
svn = rsvn: '.' is not a working copy, (Sep 26 2006), Windows/ia32/msvc 1310,
release buil
d
http://incubator.apache.org/harmony
.File length: 23  Buf capacity: 23
File and Buffer contain the same chars
isLoaded(): false

Time: 0.031

OK (1 test)




-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Mime
View raw message