You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by jw...@apache.org on 2016/05/03 05:08:26 UTC
[1/3] groovy git commit: Guard against recursive calls to
ReferenceManager#removeStallEntries that could cause a StackOverflowError. A
ManagedReference#finalizeReference method may call ManagedReference#clear on
other references as part of the clean up
Repository: groovy
Updated Branches:
refs/heads/master 78507b121 -> 05e9f5639
Guard against recursive calls to ReferenceManager#removeStallEntries that could cause a StackOverflowError. A ManagedReference#finalizeReference method may call ManagedReference#clear on other references as part of the clean up process and #clear in turns calls #removeStallEntries. This change makes it so that a queue is not re-entered for processing once it has started to be processed.
closes #298
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/01007a38
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/01007a38
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/01007a38
Branch: refs/heads/master
Commit: 01007a38f6ef172d853069697b9712449ed53055
Parents: 78507b1
Author: John Wagenleitner <jw...@apache.org>
Authored: Mon May 2 19:55:41 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Mon May 2 19:55:41 2016 -0700
----------------------------------------------------------------------
.../codehaus/groovy/util/ReferenceManager.java | 70 +++++++++++++-------
.../groovy/util/ReferenceManagerTest.groovy | 17 +++++
2 files changed, 64 insertions(+), 23 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/01007a38/src/main/org/codehaus/groovy/util/ReferenceManager.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/ReferenceManager.java b/src/main/org/codehaus/groovy/util/ReferenceManager.java
index 1059214..6ab6d56 100644
--- a/src/main/org/codehaus/groovy/util/ReferenceManager.java
+++ b/src/main/org/codehaus/groovy/util/ReferenceManager.java
@@ -19,6 +19,7 @@
package org.codehaus.groovy.util;
import java.lang.ref.ReferenceQueue;
+import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
public class ReferenceManager {
@@ -72,33 +73,56 @@ public class ReferenceManager {
return new ReferenceManager(queue);
}
public static ReferenceManager createCallBackedManager(ReferenceQueue queue) {
- return new ReferenceManager(queue){
- @Override
- public void removeStallEntries() {
- ReferenceQueue queue = getReferenceQueue();
- for(;;) {
- java.lang.ref.Reference r = queue.poll();
- if (r==null) break;
-
- if (r instanceof Reference) {
- Reference ref = (Reference) r;
- Finalizable holder = ref.getHandler();
- if (holder!=null) holder.finalizeReference();
- }
- r.clear();
- r=null;
+ return new CallBackedManager(queue);
+ }
+
+ private static class CallBackedManager extends ReferenceManager {
+
+ private static final ConcurrentHashMap<ReferenceQueue, ReferenceManager> queuesInProcess =
+ new ConcurrentHashMap<ReferenceQueue, ReferenceManager>(4, 0.9f, 2);
+
+ public CallBackedManager(ReferenceQueue queue) {
+ super(queue);
+ }
+
+ @Override
+ public void removeStallEntries() {
+ ReferenceQueue queue = getReferenceQueue();
+ if (queuesInProcess.putIfAbsent(queue, this) == null) {
+ try {
+ removeStallEntries0(queue);
+ } finally {
+ queuesInProcess.remove(queue);
}
}
- @Override
- public void afterReferenceCreation(Reference r) {
- removeStallEntries();
- }
- @Override
- public String toString() {
- return "ReferenceManager(callback)";
+ }
+
+ private static void removeStallEntries0(ReferenceQueue queue) {
+ for(;;) {
+ java.lang.ref.Reference r = queue.poll();
+ if (r==null) break;
+
+ if (r instanceof Reference) {
+ Reference ref = (Reference) r;
+ Finalizable holder = ref.getHandler();
+ if (holder!=null) holder.finalizeReference();
+ }
+ r.clear();
+ r=null;
}
- };
+ }
+
+ @Override
+ public void afterReferenceCreation(Reference r) {
+ removeStallEntries();
+ }
+
+ @Override
+ public String toString() {
+ return "ReferenceManager(callback)";
+ }
}
+
public static ReferenceManager createThresholdedIdlingManager(final ReferenceQueue queue, final ReferenceManager callback, final int threshold) {
if (threshold<0) throw new IllegalArgumentException("threshold must not be below 0.");
http://git-wip-us.apache.org/repos/asf/groovy/blob/01007a38/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy b/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
index 070ab59..b0f836b 100644
--- a/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
@@ -97,6 +97,23 @@ class ReferenceManagerTest extends GroovyTestCase {
assert finalizeCounter == 4
}
+ void testCallbackManagerGuardsAgainstRecursiveQueueProcessing() {
+ // Populate queue with enough references that call back into removeStallEntries
+ // so that would normally generate a StackOverflowError
+ 10000.times {
+ TestReference<Object> ref = new TestReference<Object>(new Object(), new Finalizable() {
+ @Override
+ void finalizeReference() {
+ callback.removeStallEntries()
+ }
+ })
+ queue.add(ref)
+ }
+ callback.removeStallEntries()
+ // Success if we made it this far with no StackOverflowError
+ assert queue.size() == 0
+ }
+
private static class TestQueue<T> extends ReferenceQueue<T> {
final List<T> entries = []
[2/3] groovy git commit: Fix for ManagedDoubleKeyMap when there are
hash collisions and entry array must be expanded
Posted by jw...@apache.org.
Fix for ManagedDoubleKeyMap when there are hash collisions and entry array must be expanded
The existing array was having the first element overwritten instead of using the newly allocated array.
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/3bcadcf0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/3bcadcf0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/3bcadcf0
Branch: refs/heads/master
Commit: 3bcadcf063e52232d15e663f1b3f5511ee78285c
Parents: 01007a3
Author: John Wagenleitner <jw...@apache.org>
Authored: Mon May 2 19:59:45 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Mon May 2 20:04:48 2016 -0700
----------------------------------------------------------------------
.../util/AbstractConcurrentDoubleKeyMap.java | 4 ++--
.../groovy/util/ManagedDoubleKeyMapTest.groovy | 17 +++++++++++++++++
2 files changed, 19 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/3bcadcf0/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java b/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
index 6137efc..e83b641 100644
--- a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
+++ b/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
@@ -140,9 +140,9 @@ public abstract class AbstractConcurrentDoubleKeyMap<K1,K2,V> extends AbstractCo
}
final Object[] newArr = new Object[arr.length+1];
final Entry<K1,K2,V> res = createEntry(key1,key2, hash);
- arr [0] = res;
+ newArr[0] = res;
System.arraycopy(arr, 0, newArr, 1, arr.length);
- tab[index] = arr;
+ tab[index] = newArr;
count++; // write-volatile
return res;
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/3bcadcf0/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy b/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
index 82a90d9..a7e1a97 100644
--- a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
@@ -38,4 +38,21 @@ class ManagedDoubleKeyMapTest extends GroovyTestCase {
assert map.fullSize() == 0
}
+ void testPutForSameHashBucket() {
+ Object obj1 = new Object() { @Override public int hashCode() { return 42; } }
+ Object obj2 = new Object() { @Override public int hashCode() { return 42; } }
+ Object obj3 = new Object() { @Override public int hashCode() { return 42; } }
+
+ map.put(obj1, obj2, 'obj1')
+ map.put(obj2, obj1, 'obj2')
+ map.put(obj3, obj2, 'obj3')
+
+ assert map.size() == 3
+ assert map.fullSize() == 3
+
+ assert map.get(obj1, obj2) == 'obj1'
+ assert map.get(obj2, obj1) == 'obj2'
+ assert map.get(obj3, obj2) == 'obj3'
+ }
+
}
[3/3] groovy git commit: refactor(core): remove unused utility
classes (closes #324)
Posted by jw...@apache.org.
refactor(core): remove unused utility classes (closes #324)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/05e9f563
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/05e9f563
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/05e9f563
Branch: refs/heads/master
Commit: 05e9f5639c9fed6fc3406d594b85aca9892faf76
Parents: 3bcadcf
Author: John Wagenleitner <jw...@apache.org>
Authored: Mon May 2 20:00:24 2016 -0700
Committer: John Wagenleitner <jw...@apache.org>
Committed: Mon May 2 20:04:49 2016 -0700
----------------------------------------------------------------------
.../util/AbstractConcurrentDoubleKeyMap.java | 200 -------------------
.../codehaus/groovy/util/DoubleKeyHashMap.java | 93 ---------
.../groovy/util/ManagedDoubleKeyMap.java | 118 -----------
.../groovy/util/ManagedDoubleKeyMapTest.groovy | 58 ------
4 files changed, 469 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/05e9f563/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java b/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
deleted file mode 100644
index e83b641..0000000
--- a/src/main/org/codehaus/groovy/util/AbstractConcurrentDoubleKeyMap.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.codehaus.groovy.util;
-
-public abstract class AbstractConcurrentDoubleKeyMap<K1,K2,V> extends AbstractConcurrentMapBase {
- public AbstractConcurrentDoubleKeyMap(Object segmentInfo) {
- super(segmentInfo);
- }
-
- static <K1,K2> int hash(K1 key1, K2 key2) {
- int h = 31*key1.hashCode() + key2.hashCode();
- h += ~(h << 9);
- h ^= (h >>> 14);
- h += (h << 4);
- h ^= (h >>> 10);
- return h;
- }
-
- public V get(K1 key1, K2 key2) {
- int hash = hash(key1, key2);
- return segmentFor(hash).get(key1, key2, hash);
- }
-
- public Entry<K1,K2,V> getOrPut(K1 key1, K2 key2, V value) {
- int hash = hash(key1,key2);
- return segmentFor(hash).getOrPut(key1, key2, hash, value);
- }
-
- public void put(K1 key1, K2 key2, V value) {
- int hash = hash(key1, key2);
- segmentFor(hash).put(key1, key2, hash).setValue(value);
- }
-
- public void remove(K1 key1, K2 key2) {
- int hash = hash(key1, key2);
- segmentFor(hash).remove(key1, key2, hash);
- }
-
- public final Segment<K1,K2,V> segmentFor(int hash) {
- return (Segment<K1,K2,V>) segments[(hash >>> segmentShift) & segmentMask];
- }
-
- abstract static class Segment<K1,K2,V> extends AbstractConcurrentMapBase.Segment {
- Segment(int initialCapacity) {
- super(initialCapacity);
- }
-
- V get(K1 key1, K2 key2, int hash) {
- Object[] tab = table;
- Object o = tab[hash & (tab.length - 1)];
- if (o != null) {
- if (o instanceof Entry) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) o;
- if (e.isEqual(key1,key2,hash)) {
- return e.getValue();
- }
- }
- else {
- Object arr [] = (Object[]) o;
- for (int i = 0; i != arr.length; ++i) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) arr [i];
- if (e != null && e.isEqual(key1, key2, hash))
- return e.getValue();
- }
- }
- }
- return null;
- }
-
- Entry<K1,K2,V> getOrPut(K1 key1, K2 key2, int hash, V value) {
- Object[] tab = table;
- Object o = tab[hash & (tab.length - 1)];
- if (o != null) {
- if (o instanceof Entry) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) o;
- if (e.isEqual(key1,key2,hash)) {
- return e;
- }
- }
- else {
- Object arr [] = (Object[]) o;
- for (int i = 0; i != arr.length; ++i) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) arr [i];
- if (e != null && e.isEqual(key1, key2, hash))
- return e;
- }
- }
- }
-
- final Entry<K1,K2,V> kvEntry = put(key1, key2, hash);
- kvEntry.setValue(value);
- return kvEntry;
- }
-
- Entry<K1,K2,V> put(K1 key1, K2 key2, int hash) {
- lock();
- try {
- rehashIfThresholdExceeded();
-
- Object[] tab = table;
- final int index = hash & (tab.length - 1);
- final Object o = tab[index];
- if (o != null) {
- if (o instanceof Entry) {
- final Entry<K1,K2,V> e = (Entry<K1,K2,V>) o;
- if (e.isEqual(key1,key2,hash)) {
- return e;
- }
- final Object[] arr = new Object[2];
- final Entry<K1,K2,V> res = createEntry(key1, key2, hash);
- arr [0] = res;
- arr [1] = e;
- tab[index] = arr;
- count++; // write-volatile
- return res;
- }
- else {
- Object arr [] = (Object[]) o;
- for (int i = 0; i != arr.length; ++i) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) arr [i];
- if (e != null && e.isEqual(key1, key2, hash)) {
- return e;
- }
- }
- final Object[] newArr = new Object[arr.length+1];
- final Entry<K1,K2,V> res = createEntry(key1,key2, hash);
- newArr[0] = res;
- System.arraycopy(arr, 0, newArr, 1, arr.length);
- tab[index] = newArr;
- count++; // write-volatile
- return res;
- }
- }
-
- final Entry<K1,K2,V> res = createEntry(key1, key2, hash);
- tab[index] = res;
- count++; // write-volatile
- return res;
-
- } finally {
- unlock();
- }
- }
-
- public void remove(K1 key1, K2 key2, int hash) {
- lock();
- try {
- int c = count-1;
- final Object[] tab = table;
- final int index = hash & (tab.length - 1);
- Object o = tab[index];
-
- if (o != null) {
- if (o instanceof Entry) {
- if (((Entry<K1,K2,V>)o).isEqual(key1, key2, hash)) {
- tab[index] = null;
- count = c;
- }
- }
- else {
- Object arr [] = (Object[]) o;
- for (int i = 0; i < arr.length; i++) {
- Entry<K1,K2,V> e = (Entry<K1,K2,V>) arr[i];
- if (e != null && e.isEqual(key1, key2, hash)) {
- arr [i] = null;
- count = c;
- break;
- }
- }
- }
- }
- }
- finally {
- unlock();
- }
- }
-
- protected abstract Entry<K1,K2,V> createEntry(K1 key1, K2 key2, int hash);
- }
-
- interface Entry<K1, K2, V> extends AbstractConcurrentMapBase.Entry<V>{
- boolean isEqual(K1 key1, K2 key2, int hash);
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/05e9f563/src/main/org/codehaus/groovy/util/DoubleKeyHashMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/DoubleKeyHashMap.java b/src/main/org/codehaus/groovy/util/DoubleKeyHashMap.java
deleted file mode 100644
index 7d67a79..0000000
--- a/src/main/org/codehaus/groovy/util/DoubleKeyHashMap.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.codehaus.groovy.util;
-
-public class DoubleKeyHashMap extends ComplexKeyHashMap
-{
- public static class Entry extends ComplexKeyHashMap.Entry{
- public Object key1, key2;
- }
-
- public final Object get(Object key1, Object key2) {
- int h = hash (31*key1.hashCode()+key2.hashCode());
- ComplexKeyHashMap.Entry e = table [h & (table.length-1)];
- for (; e != null; e = e.next)
- if (e.hash == h && checkEquals(e, key1, key2))
- return e;
-
- return null;
- }
-
- public boolean checkEquals(ComplexKeyHashMap.Entry e, Object key1, Object key2) {
- Entry ee = (Entry) e;
- return ee.key1 == key1 && ee.key2 == key2;
- }
-
- public Entry getOrPut(Object key1, Object key2)
- {
- int h = hash (31*key1.hashCode()+key2.hashCode());
- final int index = h & (table.length - 1);
- ComplexKeyHashMap.Entry e = table [index];
- for (; e != null; e = e.next)
- if (e.hash == h && checkEquals( e, key1, key2))
- return (Entry) e;
-
- ComplexKeyHashMap.Entry entry = createEntry(key1, key2, h, index);
- table [index] = entry;
-
- if ( ++size == threshold )
- resize(2*table.length);
-
- return (Entry) entry;
- }
-
- private ComplexKeyHashMap.Entry createEntry(Object key1, Object key2, int h, int index)
- {
- Entry entry = createEntry ();
- entry.next = table [index];
- entry.hash = h;
- entry.key1 = key1;
- entry.key2 = key2;
- return entry;
- }
-
- public Entry createEntry() {
- return new Entry ();
- }
-
- public final ComplexKeyHashMap.Entry remove(Object key1, Object key2) {
- int h = hash (31*key1.hashCode()+key2.hashCode());
- int index = h & (table.length -1);
- for (ComplexKeyHashMap.Entry e = table [index], prev = null; e != null; prev = e, e = e.next ) {
- if (e.hash == h && checkEquals(e, key1, key2)) {
- if (prev == null)
- table [index] = e.next;
- else
- prev.next = e.next;
- size--;
-
- e.next = null;
- return e;
- }
- }
-
- return null;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/05e9f563/src/main/org/codehaus/groovy/util/ManagedDoubleKeyMap.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/util/ManagedDoubleKeyMap.java b/src/main/org/codehaus/groovy/util/ManagedDoubleKeyMap.java
deleted file mode 100644
index 9dfe170..0000000
--- a/src/main/org/codehaus/groovy/util/ManagedDoubleKeyMap.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.codehaus.groovy.util;
-
-
-public class ManagedDoubleKeyMap<K1,K2,V> extends AbstractConcurrentDoubleKeyMap<K1,K2,V> {
- public ManagedDoubleKeyMap(ReferenceBundle bundle) {
- super(bundle);
- }
-
- protected AbstractConcurrentDoubleKeyMap.Segment<K1,K2,V> createSegment(Object segmentInfo, int cap) {
- ReferenceBundle bundle = (ReferenceBundle) segmentInfo;
- return new Segment<K1,K2,V>(bundle, cap);
- }
-
- static class Segment<K1,K2,V> extends AbstractConcurrentDoubleKeyMap.Segment<K1,K2,V>{
- private ReferenceBundle bundle;
- public Segment(ReferenceBundle bundle, int cap) {
- super(cap);
- this.bundle = bundle;
- }
-
- protected AbstractConcurrentDoubleKeyMap.Entry<K1,K2,V> createEntry(K1 key1, K2 key2, int hash) {
- return new EntryWithValue(bundle, key1, key2, hash, this);
- }
- }
-
- static class Ref<K> extends ManagedReference<K> {
- final Entry entry;
- public Ref(ReferenceBundle bundle, K referent, Entry entry) {
- super(bundle, referent);
- this.entry = entry;
- }
-
- @Override
- public void finalizeReference() {
- this.entry.clean();
- super.finalizeReference();
- }
- }
-
- public static class Entry<K1,K2, V> implements AbstractConcurrentDoubleKeyMap.Entry<K1,K2,V> {
- private final int hash;
- final Ref<K1> ref1;
- final Ref<K2> ref2;
- final Segment segment;
-
- public Entry(ReferenceBundle bundle, K1 key1, K2 key2, int hash, Segment segment) {
- this.hash = hash;
- this.segment = segment;
- ref1 = new Ref(bundle, key1, this);
- ref2 = new Ref(bundle, key2, this);
- }
-
- public boolean isValid() {
- return ref1.get() != null && ref2.get () != null;
- }
-
- public boolean isEqual(K1 key1, K2 key2, int hash) {
- return this.hash == hash && ref1.get() == key1 && ref2.get() == key2;
- }
-
- public V getValue() {
- return (V)this;
- }
-
- public void setValue(V value) {
- }
-
- public int getHash() {
- return hash;
- }
-
- public void clean() {
- segment.removeEntry(this);
- }
- }
-
- private static class EntryWithValue<K1,K2,V> extends Entry<K1,K2,V> {
- private V value;
-
- public EntryWithValue(ReferenceBundle bundle, K1 key1, K2 key2, int hash, Segment segment) {
- super(bundle, key1, key2, hash, segment);
- }
-
- @Override
- public V getValue() {
- return value;
- }
-
- @Override
- public void setValue(V value) {
- this.value = value;
- }
-
- @Override
- public void clean() {
- value = null;
- super.clean();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/groovy/blob/05e9f563/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy b/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
deleted file mode 100644
index a7e1a97..0000000
--- a/src/test/org/codehaus/groovy/util/ManagedDoubleKeyMapTest.groovy
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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.codehaus.groovy.util
-
-class ManagedDoubleKeyMapTest extends GroovyTestCase {
-
- ManagedDoubleKeyMap<Object, Object, String> map =
- new ManagedDoubleKeyMap<Object, Object, String>(ReferenceBundle.getHardBundle())
-
- void testEntriesRemoveSelfFromMapWhenFinalized() {
- def entries = []
- for (int i = 0; i < 5; i++) {
- entries << map.getOrPut(new Object(), new Object(), "Value${i}")
- }
-
- assert map.size() == 5
- assert map.fullSize() == 5
-
- entries*.clean()
-
- assert map.size() == 0
- assert map.fullSize() == 0
- }
-
- void testPutForSameHashBucket() {
- Object obj1 = new Object() { @Override public int hashCode() { return 42; } }
- Object obj2 = new Object() { @Override public int hashCode() { return 42; } }
- Object obj3 = new Object() { @Override public int hashCode() { return 42; } }
-
- map.put(obj1, obj2, 'obj1')
- map.put(obj2, obj1, 'obj2')
- map.put(obj3, obj2, 'obj3')
-
- assert map.size() == 3
- assert map.fullSize() == 3
-
- assert map.get(obj1, obj2) == 'obj1'
- assert map.get(obj2, obj1) == 'obj2'
- assert map.get(obj3, obj2) == 'obj3'
- }
-
-}