harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject 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/
Date Fri, 07 Jul 2006 16:07:22 GMT
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() {



Mime
View raw message