[Joafip-svn] SF.net SVN: joafip:[2979] trunk
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-11-23 02:54:49
|
Revision: 2979
http://joafip.svn.sourceforge.net/joafip/?rev=2979&view=rev
Author: luc_peuvrier
Date: 2011-11-23 02:54:42 +0000 (Wed, 23 Nov 2011)
Log Message:
-----------
weak management of object corrected
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java
trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java
trunk/joafip/src/main/java/net/sf/joafip/util/DebugUtil.java
trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/rbtree/MainRBTree.java
trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/impl/memory/entity/RBTNode.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java 2011-11-22 06:53:30 UTC (rev 2978)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectAndPersistInfo.java 2011-11-23 02:54:42 UTC (rev 2979)
@@ -119,6 +119,8 @@
private ObjectAndPersistInfoWeakReference weakReference;
+ private boolean weaked;
+
public FieldInfo[] fieldToSetInfo;
private IProxyCallBackToImplement proxyCallBack;
@@ -405,21 +407,24 @@
/**
*
+ * @param queue
+ * @return true if weaked, false if not weaked because already weaked or
+ * acceded
*/
public boolean weakReferenceOnObject(
final ReferenceQueue<? super Object> queue) {
// object!=null may be unreferenced object and statemap not already
// cleared
- final boolean weaked;
- if (isNotAcceded() && weakReference == null && object != null) {
- weakReference = new ObjectAndPersistInfoWeakReference(object, this,
- queue);
+ final boolean wasWeaked = weaked;
+ if (!weaked && isNotAcceded() && object != null) {
+ if (weakReference == null) {
+ weakReference = new ObjectAndPersistInfoWeakReference(object,
+ this, queue);
+ }
clear();// Unreferenced
weaked = true;
- } else {
- weaked = false;
}
- return weaked;
+ return !wasWeaked && weaked;
}
private boolean isNotAcceded() {
@@ -435,37 +440,37 @@
@Override
protected Object getObjectForEquals() {
final Object result;
- if (weakReference == null) {
+ if (weaked) {
+ result = weakReference.get();
+ } else {
result = this.object;
- } else {
- result = weakReference.get();
}
return result;
}
public boolean referenceLost() {
- return weakReference != null && weakReference.get() == null;
+ return weaked && weakReference.get() == null;
}
@Override
public Object getObject() {
final Object result;
- if (weakReference == null) {
- result = this.object;
- } else {
+ if (weaked) {
result = weakReference.get();
assert result != null : "reference lost " + toString();
+ } else {
+ result = this.object;
}
return result;
}
public boolean unWeakReferenceOnObject() {
- if (weakReference != null) {
+ if (weaked) {
assert object == null;
final Object object = weakReference.get();
if (object != null) {
setObject(object);
- weakReference = null;// NOPMD
+ weaked = false;
objectStateMap.unWeakReferenceOnObject(this);
}
}
@@ -473,19 +478,19 @@
}
public boolean isWeak() {
- return weakReference != null;
+ return weaked;
}
public boolean isNotWeak() {
- return weakReference == null;
+ return true ^ weaked;
}
public boolean hasNoReferences() {
- return weakReference != null && weakReference.get() == null;
+ return weaked && weakReference.get() == null;
}
public boolean hasReferences() {
- return weakReference == null || weakReference.get() != null;
+ return !weaked || weakReference.get() != null;
}
public int getJoafipReleaseId() {
@@ -602,7 +607,7 @@
return /**/"object[" +
/**/(object == null ?
/**/"null" :
- /**/((objectClass == null ? "no class" : objectClass.getName()) +
+ /**/(objectClass.getName() +
/**/"@" + hashCode()))
/**/+ "]";
@@ -610,17 +615,18 @@
private String weakToString() {
final Object weak;
- if (weakReference == null) {
+ if (weaked) {
+ weak = weakReference.get();
+ } else {
weak = null;
- } else {
- weak = weakReference.get();
}
return /**/"weakReference["
- /**/+ (weakReference == null ?
- /**/"none" : // NOPMD
- /**/(weak == null ? "null" : (weak.getClass()
- .getName() + "@" + System
- .identityHashCode(weak))))
+ /**/+ (weaked ?
+ /**/(weak == null ? "null"
+ : (weak.getClass().getName() + "@" + System
+ .identityHashCode(weak))) :
+ /**/"none" // NOPMD
+ )
/**/+ "]";
}
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java 2011-11-22 06:53:30 UTC (rev 2978)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/entity/objectio/ObjectStateMap.java 2011-11-23 02:54:42 UTC (rev 2979)
@@ -32,6 +32,7 @@
import net.sf.joafip.store.entity.classinfo.ClassInfo;
import net.sf.joafip.store.service.classinfo.ClassInfoException;
import net.sf.joafip.store.service.objectio.ObjectIOException;
+import net.sf.joafip.util.DebugUtil;
/**
* Maintains link between object in memory and their persistence information<br>
@@ -80,7 +81,7 @@
private boolean stopExpungeThread;
- private final Thread expungeThread;
+ private Thread expungeThread;
/**
* empty object state informations at construction
@@ -88,6 +89,10 @@
*/
public ObjectStateMap() {// NOPMD explicit constructor
super();
+ // startThread();
+ }
+
+ private void startThread() {
expungeThread = new Thread(this, "objectStateExpunge-Thread");
expungeThread.setDaemon(true);
expungeThread.setPriority(Thread.MAX_PRIORITY);
@@ -95,6 +100,12 @@
}
public void close() {
+ if (exclusiveAccessSession) {
+ stopThread();
+ }
+ }
+
+ private void stopThread() {
synchronized (this) {
if (!stopExpungeThread) {
stopExpungeThread = true;
@@ -110,14 +121,19 @@
}
public void setExclusiveAccessSession(final boolean exclusiveAccessSession) {
+ final boolean wasExclusiveAccessSession = this.exclusiveAccessSession;
this.exclusiveAccessSession = exclusiveAccessSession;
+ if (wasExclusiveAccessSession != this.exclusiveAccessSession) {
+ if (this.exclusiveAccessSession) {
+ startThread();
+ } else {
+ stopThread();
+ }
+ }
}
public ObjectAndPersistInfo getObjectPersistenceStateByObjectIdentityKey(
final IObjectIdentityKey objectIdentityKey) {
- // if (exclusiveAccessSession) {
- // expunge();
- // }
synchronized (this) {
return stateMap.get(objectIdentityKey);
}
@@ -125,9 +141,6 @@
public void clearObjectAndPersistInfoByDataRecordIdentifier(
final DataRecordIdentifier dataRecordIdentifier) {
- // if (exclusiveAccessSession) {
- // expunge();
- // }
synchronized (this) {
stateMapByIdentifier.remove(dataRecordIdentifier);
}
@@ -142,9 +155,6 @@
synchronized (this) {
// ASSERTX
assert objectAndPersistInfo.getObjectStateMap() == this;
- // if (exclusiveAccessSession) {
- // expunge();
- // }
// ASSERTX
assert objectAndPersistInfo.isNotWeak();
// ASSERTX
@@ -174,7 +184,6 @@
synchronized (this) {
ObjectAndPersistInfo objectAndPersistInfo;
if (exclusiveAccessSession) {
- // expunge();
objectAndPersistInfo = stateMapByIdentifier.get(identifier);
if (objectAndPersistInfo != null
&& !objectAndPersistInfo.unWeakReferenceOnObject()) {
@@ -204,9 +213,6 @@
synchronized (this) {
// ASSERTX
assert object != null : "null has not persistent state";
- // if (exclusiveAccessSession) {
- // expunge();
- // }
key.setObject(object);
final ObjectAndPersistInfo objectAndPersistInfo = stateMap.get(key);
// key must not more reference object
@@ -266,9 +272,6 @@
objectAndPersistInfo.setObjectStateMap(this);
// ASSERTX
assert objectAndPersistInfo.getObject() != null : "null object";
- // if (exclusiveAccessSession) {
- // expunge();
- // }
if (stateMap.put(objectAndPersistInfo, objectAndPersistInfo) != null) {
throw new ObjectIOException(
"persistence state already exists for "
@@ -316,9 +319,6 @@
public boolean objectHasPersistenceState(
final ObjectAndPersistInfo objectAndPersistInfo) {
synchronized (this) {
- // if (exclusiveAccessSession) {
- // expunge();
- // }
return stateMap.containsKey(objectAndPersistInfo);
}
}
@@ -330,9 +330,6 @@
*/
public void clear() throws ObjectIOException {
synchronized (this) {
- // if (exclusiveAccessSession) {
- // expunge();
- // }
stateMap.clear();
stateMapByIdentifier.clear();
key.clear();
@@ -383,7 +380,6 @@
// objectAndPersistInfo.weakReferenceOnObject();
// }
- // expunge();
// do not clear queueHead and queueTail
ObjectAndPersistInfo current = queueHead;
@@ -421,7 +417,6 @@
public void unWeakReferenceOnObject(final ObjectAndPersistInfo toUnWeak) {
if (exclusiveAccessSession) {
synchronized (this) {
- // expunge();
// final ObjectAndPersistInfo previous = stateMap.put(toUnWeak,
// toUnWeak);
// assert previous == null : "persistence state already set";
@@ -454,21 +449,6 @@
final Collection<ObjectAndPersistInfo> objectHavingStateSet =
/**/new LinkedHashSet<ObjectAndPersistInfo>();
- // if (exclusiveAccessSession) {
- // expunge();
- // for (ObjectAndPersistInfo objectAndPersistInfo :
- // stateMap.values()) {
- // if (objectAndPersistInfo.isNotWeak()) {
- // objectHavingStateSet.add(objectAndPersistInfo);
- // }
- // }
- // } else {
- // for (ObjectAndPersistInfo objectAndPersistInfo :
- // stateMap.values()) {
- // objectHavingStateSet.add(objectAndPersistInfo);
- // }
- // }
-
ObjectAndPersistInfo current = referencedQueueHead;
while (current != null) {
objectHavingStateSet.add(current);
@@ -489,10 +469,9 @@
final ObjectAndPersistInfo objectAndPersistInfoOfObject) {
if (exclusiveAccessSession) {
synchronized (this) {
- // expunge();
final boolean unWeaked = objectAndPersistInfoOfObject
.unWeakReferenceOnObject();
- assert unWeaked;
+ assert unWeaked : objectAndPersistInfoOfObject.toString();
assert stateMap.containsKey(objectAndPersistInfoOfObject) : "not in state map: "
+ objectAndPersistInfoOfObject.toString();
if (trackingOfAccessedObjectEnabled) {
@@ -527,7 +506,6 @@
*/
public Set<ObjectAndPersistInfo> mostAccessedObject(final int quota) {
synchronized (this) {
- // expunge();
final Set<ObjectAndPersistInfo> set = new LinkedHashSet<ObjectAndPersistInfo>();
int count = 0;
ObjectAndPersistInfo current = queueHead;
@@ -545,7 +523,6 @@
@Fortest
public List<ObjectAndPersistInfo> getObjectAndPersistInfoOfObjectFromQueue() {
synchronized (this) {
- // expunge();
final List<ObjectAndPersistInfo> list = new LinkedList<ObjectAndPersistInfo>();
ObjectAndPersistInfo current = queueHead;
while (current != null) {
@@ -562,7 +539,10 @@
while (!stopExpungeThread) {
final ObjectAndPersistInfoWeakReference ref = (ObjectAndPersistInfoWeakReference) referenceQueue
.remove(/* timeout ? */);
- if (ref != null) {/* can be null only if timeout */
+ if (!stopExpungeThread && ref != null) {/*
+ * can be null only if
+ * timeout
+ */
synchronized (ObjectStateMap.this) {
final ObjectAndPersistInfo objectAndPersistInfo = ref
.getObjectAndPersistInfo();
@@ -581,19 +561,23 @@
}
private void removeWeaked(final ObjectAndPersistInfo toRemove) {
- stateMap.remove(toRemove);
- stateMapByIdentifier.remove(toRemove.dataRecordIdentifier);
- // FIXMELUC ?___assert failure, why ?
- // assert x == toRemove : x + "\n" + toRemove;
+ final ObjectAndPersistInfo removed = stateMap.remove(toRemove);
+ assert removed != null : toRemove.toString();
+ /* removed = */stateMapByIdentifier
+ .remove(toRemove.dataRecordIdentifier);
+ // bad assert, may be no data record associated to object
+ // assert removed == toRemove : removed + "\n" + toRemove;
toRemove.clearSubstitution();
removeFromQueue(toRemove);
}
private void removeFromQueue(final ObjectAndPersistInfo toRemove) {
- // FIXMELUC ___may be not needed to clear queue link
toRemove.setObjectStateMap(null);
final ObjectAndPersistInfo previous = toRemove.previous;
- assert previous != null || toRemove == queueHead; // NOPMD
+ assert previous != null || toRemove == queueHead : // NOPMD
+ /**/"previousIsNull=" + (previous == null) + " nextIsNull="
+ + (toRemove.next == null) + // NOPMD
+ /**/" " + toRemove.toString();
final ObjectAndPersistInfo next = toRemove.next;
assert next != null || toRemove == queueTail;// NOPMD
toRemove.next = null;// NOPMD
Modified: trunk/joafip/src/main/java/net/sf/joafip/util/DebugUtil.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/util/DebugUtil.java 2011-11-22 06:53:30 UTC (rev 2978)
+++ trunk/joafip/src/main/java/net/sf/joafip/util/DebugUtil.java 2011-11-23 02:54:42 UTC (rev 2979)
@@ -103,7 +103,7 @@
final Class<?> toClass) {
final String stackTrace;
if (throwable == null) {
- stackTrace = "";
+ stackTrace = "none";
} else {
final StackTraceElement[] stackTraceElements = throwable
.getStackTrace();
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/rbtree/MainRBTree.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/rbtree/MainRBTree.java 2011-11-22 06:53:30 UTC (rev 2978)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/autosave/rbtree/MainRBTree.java 2011-11-23 02:54:42 UTC (rev 2979)
@@ -69,20 +69,26 @@
session.open();
- final RBTree tree = RBTree.newInstance(instanceFactory);
+ try {
+ final RBTree tree = RBTree.newInstance(instanceFactory);
+ session.setObject("tree", tree);
- for (int count = 0; count < 1000000; count++) {
- tree.append("" + count);// NOPMD
- if (count % 1000 == 0) {
- System.out.println("c=" + count);// NOPMD
+ for (int count = 0; count < 1000000; count++) {
+ tree.append("" + count);// NOPMD
+ if (count % 1000 == 0) {
+ System.out.println("c=" + count);// NOPMD
+ }
+ if (count > 8) {
+ tree.remove("" + (count - 8));// NOPMD
+ }
}
- if (count > 8) {
- tree.remove("" + (count - 8));// NOPMD
- }
+ } catch (Exception e) {
+ e.printStackTrace();
+ } finally {
+ session.close();
}
- session.close();
-
+ filePersistence.xmlExport("runtime", "runtime/temp", false);
filePersistence.close();
}
Modified: trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/impl/memory/entity/RBTNode.java
===================================================================
--- trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/impl/memory/entity/RBTNode.java 2011-11-22 06:53:30 UTC (rev 2978)
+++ trunk/joafip-rbtree/src/main/java/net/sf/joafip/redblacktree/impl/memory/entity/RBTNode.java 2011-11-23 02:54:42 UTC (rev 2979)
@@ -195,7 +195,7 @@
public boolean isBlack() throws RBTException {
if (noColorSetted) {
- throw new RBTException(COLOR_NOT_SET);
+ throw new RBTException(COLOR_NOT_SET + "\n" + toString());
}
return color == RedBlackTree.BLACK;
}
@@ -207,7 +207,7 @@
public boolean isRed() throws RBTException {
if (noColorSetted) {
- throw new RBTException(COLOR_NOT_SET);
+ throw new RBTException(COLOR_NOT_SET + "\n" + toString());
}
return color == RedBlackTree.RED;
}
@@ -255,7 +255,7 @@
public boolean getColor() throws RBTException {// NOPMD color is a value
if (noColorSetted) {
- throw new RBTException(COLOR_NOT_SET);
+ throw new RBTException(COLOR_NOT_SET + "\n" + toString());
}
return color;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|