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/01/25 14:19:06 UTC
svn commit: r372204 - in
/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct:
AbstractMemorySpy.java RuntimeMemorySpy.java
Author: tellison
Date: Wed Jan 25 05:19:01 2006
New Revision: 372204
URL: http://svn.apache.org/viewcvs?rev=372204&view=rev
Log:
Fix for HARMONY-38 (AbstractMemorySpy doesn't actually autoFree native memory)
- use phantom reference rather than weak reference as the address may be reborn in finalization
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/AbstractMemorySpy.java
incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/RuntimeMemorySpy.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/AbstractMemorySpy.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/AbstractMemorySpy.java?rev=372204&r1=372203&r2=372204&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/AbstractMemorySpy.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/AbstractMemorySpy.java Wed Jan 25 05:19:01 2006
@@ -17,7 +17,8 @@
import java.lang.ref.ReferenceQueue;
-import java.lang.ref.WeakReference;
+import java.lang.ref.Reference;
+import java.lang.ref.PhantomReference;
import java.util.HashMap;
import java.util.Map;
@@ -41,7 +42,7 @@
final long size;
- final WeakReference wrAddress;
+ final PhantomReference wrAddress;
volatile boolean autoFree = false;
@@ -49,7 +50,7 @@
super();
this.shadow = PlatformAddress.on(address);
this.size = size;
- this.wrAddress = new WeakReference(address, notifyQueue);
+ this.wrAddress = new PhantomReference(address, notifyQueue);
}
}
@@ -98,12 +99,13 @@
}
}
- protected void orphanedMemory(Object ref) {
+ protected void orphanedMemory(Reference ref) {
AddressWrapper wrapper;
synchronized (lock) {
Object shadow = refToShadow.remove(ref);
wrapper = (AddressWrapper) memoryInUse.remove(shadow);
}
+ ref.clear();
if (wrapper != null) {
// There is a leak if we were not auto-freeing this memory.
if (!wrapper.autoFree) {
Modified: incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/RuntimeMemorySpy.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/RuntimeMemorySpy.java?rev=372204&r1=372203&r2=372204&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/RuntimeMemorySpy.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/nio/src/main/java/com/ibm/platform/struct/RuntimeMemorySpy.java Wed Jan 25 05:19:01 2006
@@ -15,6 +15,7 @@
package com.ibm.platform.struct;
+import java.lang.ref.Reference;
public final class RuntimeMemorySpy extends AbstractMemorySpy {
@@ -25,7 +26,7 @@
public void alloc(PlatformAddress address, long size) {
super.alloc(address, size);
// Pay a tax on the allocation to see if there are any frees pending.
- Object ref = notifyQueue.poll(); // non-blocking check
+ Reference ref = notifyQueue.poll(); // non-blocking check
while (ref != null) {
orphanedMemory(ref);
ref = notifyQueue.poll();