harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r813388 - in /harmony/enhanced/classlib/trunk/modules: luni/src/main/java/org/apache/harmony/luni/platform/ nio/src/main/java/common/java/nio/
Date Thu, 10 Sep 2009 11:57:04 GMT
Author: tellison
Date: Thu Sep 10 11:57:04 2009
New Revision: 813388

URL: http://svn.apache.org/viewvc?rev=813388&view=rev
Log:
Remove SafeAddress inner class and replace with generic PlatformAddress and a simpler invalid
address marker.

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/DirectByteBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadOnlyDirectByteBuffer.java
    harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadWriteDirectByteBuffer.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java?rev=813388&r1=813387&r2=813388&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
Thu Sep 10 11:57:04 2009
@@ -24,6 +24,11 @@
  */
 public class PlatformAddress implements ICommonDataTypes, Comparable {
 
+    /**
+     * This final field defines the sentinel for an unknown address value.
+     */
+    static final long UNKNOWN = -1;
+
 	/**
 	 * This final field defines the size of an address on this platform.
 	 */
@@ -33,13 +38,16 @@
 	 * NULL is the canonical address with address value zero.
 	 */
 	public static final PlatformAddress NULL = new PlatformAddress(0, 0);
+	
+	/**
+	 * INVALID is the canonical address with an invalid value (i.e. a non-address).
+	 */
+    public static final PlatformAddress INVALID = new PlatformAddress(UNKNOWN, UNKNOWN);
 
 	public static final IMemorySpy memorySpy = new RuntimeMemorySpy();
 
 	static final IMemorySystem osMemory = Platform.getMemorySystem();
 
-    static final long UNKNOWN = -1;
-
 	final long osaddr;
     
     final long size;

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/DirectByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/DirectByteBuffer.java?rev=813388&r1=813387&r2=813388&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/DirectByteBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/DirectByteBuffer.java
Thu Sep 10 11:57:04 2009
@@ -36,20 +36,8 @@
  */
 abstract class DirectByteBuffer extends BaseByteBuffer implements DirectBuffer {
 
-    // This class will help us track whether the address is valid or not.
-    static final class SafeAddress {
-        protected volatile boolean isValid = true;
-
-        protected final PlatformAddress address;
-
-        protected SafeAddress(PlatformAddress address) {
-            super();
-            this.address = address;
-        }
-    }
-
-    // This is a wrapped reference to the base address of the buffer memory.
-    protected final SafeAddress safeAddress;
+    // This is the base address of the buffer memory.
+    protected PlatformAddress address;
 
     // This is the offset from the base address at which this buffer logically
     // starts.
@@ -63,14 +51,13 @@
      * free the memory where possible.
      */
     DirectByteBuffer(int capacity) {
-        this(new SafeAddress(PlatformAddressFactory.alloc(capacity, (byte) 0)),
-                capacity, 0);
-        safeAddress.address.autoFree();
+        this(PlatformAddressFactory.alloc(capacity, (byte) 0), capacity, 0);
+        address.autoFree();
     }
 
-    DirectByteBuffer(SafeAddress address, int capacity, int offset) {
+    DirectByteBuffer(PlatformAddress address, int capacity, int offset) {
         super(capacity);
-        this.safeAddress = address;
+        this.address = address;
         this.offset = offset;
     }
 
@@ -212,7 +199,7 @@
     }
 
     public final boolean isAddressValid() {
-        return safeAddress.isValid;
+        return address != PlatformAddress.INVALID;
     }
 
     public final void addressValidityCheck() {
@@ -223,16 +210,12 @@
         }
     }
 
-    private void markAddressInvalid() {
-        safeAddress.isValid = false;
-    }
-
     /*
      * Answers the base address of the buffer (i.e. before offset).
      */
     public final PlatformAddress getBaseAddress() {
         addressValidityCheck();
-        return safeAddress.address;
+        return address;
     }
 
     /**
@@ -262,14 +245,15 @@
      * <code>IllegalStateException</code>.
      * <p>
      * Note this is is possible that the memory is freed by code that reaches
-     * into the address and explicitly frees it 'beneith' us -- this is bad
+     * into the address and explicitly frees it 'beneath' us -- this is bad
      * form.
      * </p>
      */
     public final void free() {
         if (isAddressValid()) {
-            markAddressInvalid();
-            safeAddress.address.free();
+            PlatformAddress a = address;
+            address = PlatformAddress.INVALID;
+            a.free();
         }
     }
 

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadOnlyDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadOnlyDirectByteBuffer.java?rev=813388&r1=813387&r2=813388&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadOnlyDirectByteBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadOnlyDirectByteBuffer.java
Thu Sep 10 11:57:04 2009
@@ -35,7 +35,7 @@
 
     static ReadOnlyDirectByteBuffer copy(DirectByteBuffer other, int markOfOther) {
         ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
-                other.safeAddress, other.capacity(), other.offset);
+                other.address, other.capacity(), other.offset);
         buf.limit = other.limit();
         buf.position = other.position();
         buf.mark = markOfOther;
@@ -43,14 +43,9 @@
         return buf;
     }
 
-    protected ReadOnlyDirectByteBuffer(SafeAddress address, int capacity,
-            int offset) {
-        super(address, capacity, offset);
-    }
-
     protected ReadOnlyDirectByteBuffer(PlatformAddress address, int capacity,
             int offset) {
-        super(new SafeAddress(address), capacity, offset);
+        super(address, capacity, offset);
     }
 
     @Override
@@ -146,7 +141,7 @@
     @Override
     public ByteBuffer slice() {
         ReadOnlyDirectByteBuffer buf = new ReadOnlyDirectByteBuffer(
-                safeAddress, remaining(), offset + position);
+                address, remaining(), offset + position);
         buf.order = order;
         return buf;
     }

Modified: harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadWriteDirectByteBuffer.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadWriteDirectByteBuffer.java?rev=813388&r1=813387&r2=813388&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadWriteDirectByteBuffer.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/nio/src/main/java/common/java/nio/ReadWriteDirectByteBuffer.java
Thu Sep 10 11:57:04 2009
@@ -36,7 +36,7 @@
     static ReadWriteDirectByteBuffer copy(DirectByteBuffer other,
             int markOfOther) {
         ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
-                other.safeAddress, other.capacity(), other.offset);
+                other.address, other.capacity(), other.offset);
         buf.limit = other.limit();
         buf.position = other.position();
         buf.mark = markOfOther;
@@ -48,15 +48,10 @@
         super(capacity);
     }
 
-    ReadWriteDirectByteBuffer(SafeAddress address, int capacity, int offset) {
+    ReadWriteDirectByteBuffer(PlatformAddress address, int capacity, int offset) {
         super(address, capacity, offset);
     }
 
-    ReadWriteDirectByteBuffer(PlatformAddress address, int aCapacity,
-            int anOffset) {
-        super(new SafeAddress(address), aCapacity, anOffset);
-    }
-
     @Override
     public ByteBuffer asReadOnlyBuffer() {
         return ReadOnlyDirectByteBuffer.copy(this, mark);
@@ -225,7 +220,7 @@
     @Override
     public ByteBuffer slice() {
         ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
-                safeAddress, remaining(), offset + position);
+                address, remaining(), offset + position);
         buf.order = order;
         return buf;
     }



Mime
View raw message