You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/07/07 18:07:22 UTC

svn commit: r419915 - in /incubator/harmony/enhanced/classlib/trunk/modules: luni/src/main/java/org/apache/harmony/luni/platform/ nio/src/main/java/java/nio/ nio/src/test/java/common/org/apache/harmony/tests/java/nio/

Author: tellison
Date: Fri Jul  7 09:07:21 2006
New Revision: 419915

URL: http://svn.apache.org/viewvc?rev=419915&view=rev
Log:
Fix for HARMONY-802 ([classlib][nio] java.nio.ByteBuffer.compareTo( ByteBuffer) returns wrong value)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
    incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java?rev=419915&r1=419914&r2=419915&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java Fri Jul  7 09:07:21 2006
@@ -58,12 +58,34 @@
 		return addr;
 	}
 
+    /**
+     * Allocates a contiguous block of OS heap memory.
+     * 
+     * @param size The number of bytes to allocate from the system heap.
+     * @return PlatformAddress representing the memory block.
+     */
 	public static PlatformAddress alloc(long size) {
 		long osAddress = osMemory.malloc(size);
 		PlatformAddress newMemory = PlatformAddress.on(osAddress);
 		memorySpy.alloc(newMemory, size);
 		return newMemory;
 	}
+    
+    /**
+     * Allocates a contiguous block of OS heap memory and initializes it to
+     * a given value.
+     * 
+     * @param size The number of bytes to allocate from the system heap.
+     * @param init The value to initialize the memory.
+     * @return PlatformAddress representing the memory block.
+     */
+    public static PlatformAddress alloc(long size, byte init) {
+        long osAddress = osMemory.malloc(size);
+        osMemory.memset(osAddress, init, size);
+        PlatformAddress newMemory = PlatformAddress.on(osAddress);
+        memorySpy.alloc(newMemory, size);
+        return newMemory;
+    }
 
 	public PlatformAddress(long address) {
 		this(address, false);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java?rev=419915&r1=419914&r2=419915&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/java/nio/DirectByteBuffer.java Fri Jul  7 09:07:21 2006
@@ -52,8 +52,15 @@
 	// starts.
 	protected final int offset;
 
+    /*
+     * Constructs a new direct byte buffer of the given capacity on newly
+     * allocatd OS memory.  The memory will have been zeroed.  When the
+     * instance is discarded the OS memory will be freed if it has not
+     * already been done so by an explicit call to #free().  Callers are
+     * encouraged to explicitly free the memory where possible.
+     */
 	DirectByteBuffer(int capacity) {
-		this(new SafeAddress(PlatformAddress.alloc(capacity)), capacity, 0);
+		this(new SafeAddress(PlatformAddress.alloc(capacity, (byte)0)), capacity, 0);
 		safeAddress.address.autoFree();
 	}
 

Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java?rev=419915&r1=419914&r2=419915&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/test/java/common/org/apache/harmony/tests/java/nio/ByteBufferTest.java Fri Jul  7 09:07:21 2006
@@ -233,6 +233,8 @@
             assertTrue(buf.compareTo(other) > 0);
             assertTrue(other.compareTo(buf) < 0);
         }
+        
+        assertTrue(ByteBuffer.wrap(new byte[21]).compareTo(ByteBuffer.allocateDirect(21)) == 0);
     }
 
     public void testDuplicate() {