harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r423851 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main: java/org/apache/harmony/luni/platform/ native/luni/linux/ native/luni/windows/
Date Thu, 20 Jul 2006 09:31:20 GMT
Author: pyang
Date: Thu Jul 20 02:31:19 2006
New Revision: 423851

URL: http://svn.apache.org/viewvc?rev=423851&view=rev
Log:
Refactor the mmap related functions:
1. add MappedPlatformAddress as subclass of PlatformAddress, which is used by MappedByteBuffer,
move the mmap related functions out of PlatformAddress to MappedPlatformAddress
2. add size parameter to IMemorySystem.unmap(), fix the memory leak problem on Linux
3. add size field to PlatformAddress to simplify AbstractMemorySpy
3. refactor the parameter of IMemorySystem's mmap related functions, change PlatformAddress
to primitive long to keep consistency with other functions
4. other minor changes to fix some potential bugs

Added:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/AbstractMemorySpy.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/DebugMemorySpy.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySpy.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySystem.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddress.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemory.h
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemoryLinux32.c
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/AbstractMemorySpy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/AbstractMemorySpy.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/AbstractMemorySpy.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/AbstractMemorySpy.java
Thu Jul 20 02:31:19 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -40,16 +40,13 @@
 	final class AddressWrapper {
 		final PlatformAddress shadow;
 
-		final long size;
-
 		final PhantomReference<PlatformAddress> wrAddress;
 
 		volatile boolean autoFree = false;
 
-		AddressWrapper(PlatformAddress address, long size) {
+		AddressWrapper(PlatformAddress address) {
 			super();
-			this.shadow = PlatformAddress.on(address);
-			this.size = size;
+			this.shadow = address.duplicate();
 			this.wrAddress = new PhantomReference<PlatformAddress>(address, notifyQueue);
 		}
 	}
@@ -58,8 +55,8 @@
 		super();
 	}
 
-	public void alloc(PlatformAddress address, long size) {
-		AddressWrapper wrapper = new AddressWrapper(address, size);
+	public void alloc(PlatformAddress address) {
+		AddressWrapper wrapper = new AddressWrapper(address);
 		synchronized (lock) {
 			memoryInUse.put(wrapper.shadow, wrapper);
 			refToShadow.put(wrapper.wrAddress, wrapper.shadow);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/DebugMemorySpy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/DebugMemorySpy.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/DebugMemorySpy.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/DebugMemorySpy.java
Thu Jul 20 02:31:19 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -52,7 +52,7 @@
 			PlatformAddress accessStart = address.offsetBytes(offset);
 			PlatformAddress accessEnd = accessStart.offsetBytes(length);
 			PlatformAddress allocStart = wrapper.shadow;
-			PlatformAddress allocEnd = allocStart.offsetBytes(wrapper.size);
+			PlatformAddress allocEnd = allocStart.offsetBytes(address.size);
 			boolean under = (accessStart.compareTo(allocStart)) == -1;
 			boolean over = (accessEnd.compareTo(allocEnd)) == 1;
 			if (under || over) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySpy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySpy.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySpy.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySpy.java
Thu Jul 20 02:31:19 2006
@@ -1,4 +1,4 @@
-/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+/* Copyright 2004, 2006 The Apache Software Foundation or its licensors, as applicable
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,7 +23,7 @@
  */
 public interface IMemorySpy {
 
-	public void alloc(PlatformAddress address, long size);
+	public void alloc(PlatformAddress address);
 
 	// Has a veto: true == do free,false = don't
 	public boolean free(PlatformAddress address);

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySystem.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySystem.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySystem.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/IMemorySystem.java
Thu Jul 20 02:31:19 2006
@@ -411,7 +411,7 @@
 	 * @return
 	 * @throws IOException
 	 */
-	public PlatformAddress mmap(long fileDescriptor, long alignment, long size,
+	public long mmap(long fileDescriptor, long alignment, long size,
 			int mapMode) throws IOException;
 
 	/**
@@ -420,21 +420,21 @@
 	 * @param addr
 	 * @throws IOException
 	 */
-	public void unmap(PlatformAddress addr);
+	public void unmap(long addr, long size);
 
 	/**
 	 * TODO: JavaDoc
 	 */
-	public void load(PlatformAddress addr, long size);
+	public void load(long addr, long size);
 
 	/**
 	 * TODO: JavaDoc
 	 */
-	public boolean isLoaded(PlatformAddress addr, long size);
+	public boolean isLoaded(long addr, long size);
 
 	/**
 	 * TODO : JavaDoc
 	 */
-	public void flush(PlatformAddress addr, long size);
+	public void flush(long addr, long size);
 
 }

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java?rev=423851&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/MappedPlatformAddress.java
Thu Jul 20 02:31:19 2006
@@ -0,0 +1,55 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.luni.platform;
+
+public class MappedPlatformAddress extends PlatformAddress {
+    
+    MappedPlatformAddress(long address, long size) {
+        super(address, size);
+    }
+
+    public final void mmapLoad() {
+        memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
+        osMemory.load(osaddr, size);
+    }
+
+    public final boolean mmapIsLoaded() {
+        memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
+        return osMemory.isLoaded(osaddr, size);
+    }
+
+    public final void mmapFlush() {
+        memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
+        osMemory.flush(osaddr, size);
+    }
+    
+    public final void free(){
+        if(memorySpy.free(this)){
+            osMemory.unmap(osaddr, size);
+        }
+    }
+    
+    public PlatformAddress duplicate(){
+        return PlatformAddressFactory.mapOn(osaddr, size);
+    }
+    
+    public final PlatformAddress offsetBytes(int offset) {
+        return PlatformAddressFactory.mapOn(osaddr + offset, size - offset);
+    }
+
+    public final PlatformAddress offsetBytes(long offset) {
+        return PlatformAddressFactory.mapOn(osaddr + offset, size - offset);
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/OSMemory.java
Thu Jul 20 02:31:19 2006
@@ -535,38 +535,35 @@
 	private native long mmapImpl(long fileDescriptor, long alignment,
 			long size, int mapMode);
 
-	public PlatformAddress mmap(long fileDescriptor, long alignment, long size,
+	public long mmap(long fileDescriptor, long alignment, long size,
 			int mapMode) throws IOException {
 		long address = mmapImpl(fileDescriptor, alignment, size, mapMode);
 		if (address == -1) {
 			throw new IOException();
 		}
-		return PlatformAddress.on(address, true);
+		return address;
 	}
 
-	private native void unmapImpl(long addr);
+	private native void unmapImpl(long addr, long size);
 
-	public void unmap(PlatformAddress addr) {
-		long osAddr = addr.toLong();
-		unmapImpl(osAddr);
+	public void unmap(long addr, long size) {
+		unmapImpl(addr, size);
 	}
 
-	public void load(PlatformAddress addr, long size) {
-		// WIN32: virtualLock, need
-		// Linux:
-		loadImpl(addr.toLong(), size);
+	public void load(long addr, long size) {
+		loadImpl(addr, size);
 	}
 
 	private native int loadImpl(long l, long size);
 
-	public boolean isLoaded(PlatformAddress addr, long size) {
-		return size == 0 ? true : isLoadedImpl(addr.toLong(), size);
+	public boolean isLoaded(long addr, long size) {
+		return size == 0 ? true : isLoadedImpl(addr, size);
 	}
 
 	private native boolean isLoadedImpl(long l, long size);
 
-	public void flush(PlatformAddress addr, long size) {
-		flushImpl(addr.toLong(), size);
+	public void flush(long addr, long size) {
+		flushImpl(addr, size);
 	}
 
 	private native int flushImpl(long l, long size);

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=423851&r1=423850&r2=423851&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
Thu Jul 20 02:31:19 2006
@@ -20,7 +20,7 @@
  * The platform address class is an unsafe virtualization of an OS memory block.
  * 
  */
-public final class PlatformAddress implements ICommonDataTypes, Comparable {
+public class PlatformAddress implements ICommonDataTypes, Comparable {
 
 	/**
 	 * This final field defines the size of an address on this platform.
@@ -30,71 +30,22 @@
 	/**
 	 * NULL is the canonical address with address value zero.
 	 */
-	public static final PlatformAddress NULL = new PlatformAddress(0);
+	public static final PlatformAddress NULL = new PlatformAddress(0, 0);
 
 	public static final IMemorySpy memorySpy = new RuntimeMemorySpy();
 
-	private static final IMemorySystem osMemory = Platform.getMemorySystem();
+	static final IMemorySystem osMemory = Platform.getMemorySystem();
 
-	private final long osaddr;
+    static final long UNKNOWN = -1;
 
-	private final boolean isMappedAddress;
-
-	public static PlatformAddress on(PlatformAddress other) {
-		return new PlatformAddress(other.osaddr, other.isMappedAddress);
-	}
-
-	public static PlatformAddress on(long value) {
-		return (value == 0) ? NULL : new PlatformAddress(value, false);
-	}
-
-	public static PlatformAddress on(long value, boolean isMapped) {
-		PlatformAddress addr = (value == 0) ? NULL : new PlatformAddress(value,
-				isMapped);
-		if (isMapped) {
-			// FIXME: some platform need the size to unmap/free, fix it
-			memorySpy.alloc(addr, 0);
-		}
-		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;
-	}
+	final long osaddr;
     
-    /**
-     * 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;
-    }
+    final long size;
 
-	public PlatformAddress(long address) {
-		this(address, false);
-	}
-
-	public PlatformAddress(long address, boolean isMapped) {
+	PlatformAddress(long address, long size) {
 		super();
 		osaddr = address;
-		isMappedAddress = isMapped;
+        this.size = size;
 	}
 
 	/**
@@ -104,32 +55,36 @@
 	 * freed explicitly.
 	 * 
 	 */
-	public void autoFree() {
+	public final void autoFree() {
 		memorySpy.autoFree(this);
 	}
+    
+    public PlatformAddress duplicate(){
+        return PlatformAddressFactory.on(osaddr, size);
+    }
 
 	public PlatformAddress offsetBytes(int offset) {
-		return PlatformAddress.on(osaddr + offset);
+		return PlatformAddressFactory.on(osaddr + offset, size - offset);
 	}
 
 	public PlatformAddress offsetBytes(long offset) {
-		return PlatformAddress.on(osaddr + offset);
+		return PlatformAddressFactory.on(osaddr + offset, size - offset);
 	}
 
-	public void moveTo(PlatformAddress dest, long numBytes) {
+	public final void moveTo(PlatformAddress dest, long numBytes) {
 		osMemory.memmove(dest.osaddr, osaddr, numBytes);
 	}
 
-	public boolean equals(Object other) {
+	public final boolean equals(Object other) {
 		return (other instanceof PlatformAddress)
 				&& (((PlatformAddress) other).osaddr == osaddr);
 	}
 
-	public int hashCode() {
+	public final int hashCode() {
 		return (int) osaddr;
 	}
 
-	public boolean isNULL() {
+	public final boolean isNULL() {
 		return this == NULL;
 	}
 
@@ -137,176 +92,154 @@
 		// Memory spys can veto the basic free if they determine the memory was
 		// not allocated.
 		if (memorySpy.free(this)) {
-			if (isMappedAddress) {
-				unmap();
-			}else{
-			    osMemory.free(osaddr);
-            }
+		    osMemory.free(osaddr);
 		}
 	}
 
-	public void setAddress(int offset, PlatformAddress address) {
+	public final void setAddress(int offset, PlatformAddress address) {
 		osMemory.setAddress(osaddr + offset, address.osaddr);
 	}
 
-	public PlatformAddress getAddress(int offset) {
+	public final PlatformAddress getAddress(int offset) {
 		int addr = getInt(offset);
-		if (addr == 0) {
-			return NULL;
-		}
-		return PlatformAddress.on(addr);
+		return PlatformAddressFactory.on(addr);
 	}
 
-	public void setByte(int offset, byte value) {
+	public final void setByte(int offset, byte value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JBYTE);
 		osMemory.setByte(osaddr + offset, value);
 	}
 
-	public void setByteArray(int offset, byte[] bytes, int bytesOffset,
+	public final void setByteArray(int offset, byte[] bytes, int bytesOffset,
 			int length) {
 		memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
 		osMemory.setByteArray(osaddr + offset, bytes, bytesOffset, length);
 	}
 
-	public byte getByte(int offset) {
+	public final byte getByte(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JBYTE);
 		return osMemory.getByte(osaddr + offset);
 	}
 
-	public void getByteArray(int offset, byte[] bytes, int bytesOffset,
+	public final void getByteArray(int offset, byte[] bytes, int bytesOffset,
 			int length) {
 		memorySpy.rangeCheck(this, offset, length * SIZEOF_JBYTE);
 		osMemory.getByteArray(osaddr + offset, bytes, bytesOffset, length);
 	}
 
-	public void setShort(int offset, short value, Endianness order) {
+	public final void setShort(int offset, short value, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
 		osMemory.setShort(osaddr + offset, value, order);
 	}
 
-	public void setShort(int offset, short value) {
+	public final void setShort(int offset, short value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
 		osMemory.setShort(osaddr + offset, value);
 	}
 
-	public short getShort(int offset, Endianness order) {
+	public final short getShort(int offset, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
 		return osMemory.getShort(osaddr + offset, order);
 	}
 
-	public short getShort(int offset) {
+	public final short getShort(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JSHORT);
 		return osMemory.getShort(osaddr + offset);
 	}
 
-	public void setInt(int offset, int value, Endianness order) {
+	public final void setInt(int offset, int value, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
 		osMemory.setInt(osaddr + offset, value, order);
 	}
 
-	public void setInt(int offset, int value) {
+	public final void setInt(int offset, int value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
 		osMemory.setInt(osaddr + offset, value);
 	}
 
-	public int getInt(int offset, Endianness order) {
+	public final int getInt(int offset, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
 		return osMemory.getInt(osaddr + offset, order);
 	}
 
-	public int getInt(int offset) {
+	public final int getInt(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JINT);
 		return osMemory.getInt(osaddr + offset);
 	}
 
-	public void setLong(int offset, long value, Endianness order) {
+	public final void setLong(int offset, long value, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
 		osMemory.setLong(osaddr + offset, value, order);
 	}
 
-	public void setLong(int offset, long value) {
+	public final void setLong(int offset, long value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
 		osMemory.setLong(osaddr + offset, value);
 	}
 
-	public long getLong(int offset, Endianness order) {
+	public final long getLong(int offset, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
 		return osMemory.getLong(osaddr + offset, order);
 	}
 
-	public long getLong(int offset) {
+	public final long getLong(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JLONG);
 		return osMemory.getLong(osaddr + offset);
 	}
 
-	public void setFloat(int offset, float value, Endianness order) {
+	public final void setFloat(int offset, float value, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
 		osMemory.setFloat(osaddr + offset, value, order);
 	}
 
-	public void setFloat(int offset, float value) {
+	public final void setFloat(int offset, float value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
 		osMemory.setFloat(osaddr + offset, value);
 	}
 
-	public float getFloat(int offset, Endianness order) {
+	public final float getFloat(int offset, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
 		return osMemory.getFloat(osaddr + offset, order);
 	}
 
-	public float getFloat(int offset) {
+	public final float getFloat(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JFLOAT);
 		return osMemory.getFloat(osaddr + offset);
 	}
 
-	public void setDouble(int offset, double value, Endianness order) {
+	public final void setDouble(int offset, double value, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
 		osMemory.setDouble(osaddr + offset, value, order);
 	}
 
-	public void setDouble(int offset, double value) {
+	public final void setDouble(int offset, double value) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
 		osMemory.setDouble(osaddr + offset, value);
 	}
 
-	public double getDouble(int offset, Endianness order) {
+	public final double getDouble(int offset, Endianness order) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
 		return osMemory.getDouble(osaddr + offset, order);
 	}
 
-	public double getDouble(int offset) {
+	public final double getDouble(int offset) {
 		memorySpy.rangeCheck(this, offset, SIZEOF_JDOUBLE);
 		return osMemory.getDouble(osaddr + offset);
 	}
 
-	public void mmapLoad(long size) {
-		memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
-		osMemory.load(this, size);
-	}
-
-	public boolean mmapIsLoaded(long size) {
-		memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
-		return osMemory.isLoaded(this, size);
-	}
-
-	public void mmapFlush(long size) {
-		memorySpy.rangeCheck(this, 0, (int) size * SIZEOF_JBYTE);
-		osMemory.flush(this, size);
-	}
-
-	public void unmap() {
-		osMemory.unmap(this);
-	}
-
-	public long toLong() {
+	public final long toLong() {
 		return osaddr;
 	}
 
-	public String toString() {
+	public final String toString() {
 		return "PlatformAddress[" + osaddr + "]"; //$NON-NLS-1$ //$NON-NLS-2$
 	}
+    
+    public final long getSize(){
+        return size;
+    }
 
-	public int compareTo(Object other) {
+	public final int compareTo(Object other) {
 		if (other == null) {
 			throw new NullPointerException(); // per spec.
 		}

Added: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java?rev=423851&view=auto
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
(added)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/PlatformAddressFactory.java
Thu Jul 20 02:31:19 2006
@@ -0,0 +1,70 @@
+/* Copyright 2006 The Apache Software Foundation or its licensors, as applicable
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * 
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.harmony.luni.platform;
+
+import java.io.IOException;
+
+public class PlatformAddressFactory {
+
+    public static PlatformAddress on(long value) {
+    	return PlatformAddressFactory.on(value, PlatformAddress.UNKNOWN);
+    }
+
+    public static PlatformAddress on(long value, long size) {
+        PlatformAddress addr = (value == 0) ? PlatformAddress.NULL : new PlatformAddress(value,
size);
+        return addr;
+    }
+
+    public static MappedPlatformAddress mapOn(long value, long size) {
+        MappedPlatformAddress addr = new MappedPlatformAddress(value, size);
+        return addr;
+    }
+    
+    public static PlatformAddress allocMap(long fd, long start, long size, int mode) throws
IOException{
+        long osAddress = PlatformAddress.osMemory.mmap(fd, start, size, mode);
+        PlatformAddress newMemory = mapOn(osAddress, size);
+        PlatformAddress.memorySpy.alloc(newMemory);
+        return newMemory;
+    }
+
+    /**
+     * 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 = PlatformAddress.osMemory.malloc(size);
+    	PlatformAddress newMemory = on(osAddress, size);
+    	PlatformAddress.memorySpy.alloc(newMemory);
+    	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 = PlatformAddress.osMemory.malloc(size);
+        PlatformAddress.osMemory.memset(osAddress, init, size);
+        PlatformAddress newMemory = on(osAddress, size);
+        PlatformAddress.memorySpy.alloc(newMemory);
+        return newMemory;
+    }
+}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/org/apache/harmony/luni/platform/RuntimeMemorySpy.java
Thu Jul 20 02:31:19 2006
@@ -23,8 +23,8 @@
 		super();
 	}
 
-	public void alloc(PlatformAddress address, long size) {
-		super.alloc(address, size);
+	public void alloc(PlatformAddress address) {
+		super.alloc(address);
 		// Pay a tax on the allocation to see if there are any frees pending.
 		Reference ref = notifyQueue.poll(); // non-blocking check
 		while (ref != null) {

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemory.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemory.h?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemory.h
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemory.h
Thu Jul 20 02:31:19 2006
@@ -203,7 +203,7 @@
  * Signature: (J)V
  */
 JNIEXPORT void JNICALL Java_org_apache_harmony_luni_platform_OSMemory_unmapImpl
-  (JNIEnv *, jobject, jlong);
+  (JNIEnv *, jobject, jlong, jlong);
 
 /*
  * Class:     org_apache_harmony_luni_platform_OSMemory

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemoryLinux32.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemoryLinux32.c?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemoryLinux32.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/linux/OSMemoryLinux32.c
Thu Jul 20 02:31:19 2006
@@ -109,9 +109,9 @@
  * Signature: (J)V
  */
 JNIEXPORT void JNICALL Java_org_apache_harmony_luni_platform_OSMemory_unmapImpl
-  (JNIEnv * env, jobject thiz, jlong fd)
+  (JNIEnv * env, jobject thiz, jlong addr, jlong size)
 {
- //FIXME: need buffer size to unmap
+    munmap((void *)addr, (size_t)size); 
 }
 
 /*

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemory.h
Thu Jul 20 02:31:19 2006
@@ -226,7 +226,7 @@
  * Signature: (J)V
  */
 JNIEXPORT void JNICALL Java_org_apache_harmony_luni_platform_OSMemory_unmapImpl
-  (JNIEnv *, jobject, jlong);
+  (JNIEnv *, jobject, jlong, jlong);
 
 #ifdef __cplusplus
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c?rev=423851&r1=423850&r2=423851&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/native/luni/windows/OSMemoryWin32.c
Thu Jul 20 02:31:19 2006
@@ -100,9 +100,9 @@
  * Signature: (J)V
  */
 JNIEXPORT void JNICALL Java_org_apache_harmony_luni_platform_OSMemory_unmapImpl
-  (JNIEnv * env, jobject thiz, jlong fd)
+  (JNIEnv * env, jobject thiz, jlong addr, jlong size)
 {
-  UnmapViewOfFile ((HANDLE)fd);
+  UnmapViewOfFile ((HANDLE)addr);
 }
 
 /*



Mime
View raw message