diff options
author | Jeroen Frijters <jeroen@sumatra.nl> | 2006-01-06 15:05:56 +0000 |
---|---|---|
committer | Jeroen Frijters <jeroen@sumatra.nl> | 2006-01-06 15:05:56 +0000 |
commit | dea0ce9d87a9fd7ba377a614bb73e5f246839156 (patch) | |
tree | 858d2ba0e4c427a8602cda7bbc09f5d72482ea7e /java | |
parent | 18bf94cdf57ede34155e50e19f505237b31bb71f (diff) | |
download | classpath-dea0ce9d87a9fd7ba377a614bb73e5f246839156.tar.gz |
2006-01-06 Jeroen Frijters <jeroen@frijters.net>
PR classpath/24858
* gnu/java/util/WeakIdentityHashMap.java: New file.
* java/lang/InheritableThreadLocal.java
(newChildThread): Modified to remove key indirection.
* java/lang/Thread.java
(locals): Changed type to WeakIdentityHashMap.
(getThreadLocals): Instantiate WeakIdentityHashMap instead of
WeakHashMap.
* java/lang/ThreadLocal.java
(key, Key): Removed.
(get, set): Changed to use "this" instead of "key".
Diffstat (limited to 'java')
-rw-r--r-- | java/lang/InheritableThreadLocal.java | 11 | ||||
-rw-r--r-- | java/lang/Thread.java | 6 | ||||
-rw-r--r-- | java/lang/ThreadLocal.java | 23 |
3 files changed, 13 insertions, 27 deletions
diff --git a/java/lang/InheritableThreadLocal.java b/java/lang/InheritableThreadLocal.java index 69ff6138d..ea2307138 100644 --- a/java/lang/InheritableThreadLocal.java +++ b/java/lang/InheritableThreadLocal.java @@ -1,5 +1,5 @@ /* InheritableThreadLocal -- a ThreadLocal which inherits values across threads - Copyright (C) 2000, 2001, 2002, 2003, 2005 Free Software Foundation, Inc. + Copyright (C) 2000, 2001, 2002, 2003, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -37,6 +37,7 @@ exception statement from your version. */ package java.lang; +import gnu.java.util.WeakIdentityHashMap; import java.util.Iterator; import java.util.WeakHashMap; @@ -98,15 +99,15 @@ public class InheritableThreadLocal extends ThreadLocal Iterator keys = parentThread.locals.keySet().iterator(); while (keys.hasNext()) { - Key key = (Key)keys.next(); - if (key.get() instanceof InheritableThreadLocal) + Object key = keys.next(); + if (key instanceof InheritableThreadLocal) { - InheritableThreadLocal local = (InheritableThreadLocal)key.get(); + InheritableThreadLocal local = (InheritableThreadLocal)key; Object parentValue = parentThread.locals.get(key); Object childValue = local.childValue(parentValue == NULL ? null : parentValue); if (childThread.locals == null) - childThread.locals = new WeakHashMap(); + childThread.locals = new WeakIdentityHashMap(); childThread.locals.put(key, (childValue == null ? NULL : childValue)); } diff --git a/java/lang/Thread.java b/java/lang/Thread.java index 763228c16..9afde5bfd 100644 --- a/java/lang/Thread.java +++ b/java/lang/Thread.java @@ -38,9 +38,9 @@ exception statement from your version. */ package java.lang; +import gnu.java.util.WeakIdentityHashMap; import java.security.Permission; import java.util.Map; -import java.util.WeakHashMap; /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3 * "The Java Language Specification", ISBN 0-201-63451-1 @@ -137,7 +137,7 @@ public class Thread implements Runnable /** Thread local storage. Package accessible for use by * InheritableThreadLocal. */ - WeakHashMap locals; + WeakIdentityHashMap locals; /** * Allocates a new <code>Thread</code> object. This constructor has @@ -996,7 +996,7 @@ public class Thread implements Runnable Map locals = thread.locals; if (locals == null) { - locals = thread.locals = new WeakHashMap(); + locals = thread.locals = new WeakIdentityHashMap(); } return locals; } diff --git a/java/lang/ThreadLocal.java b/java/lang/ThreadLocal.java index bc8390445..aceb2557a 100644 --- a/java/lang/ThreadLocal.java +++ b/java/lang/ThreadLocal.java @@ -1,5 +1,5 @@ /* ThreadLocal -- a variable with a unique value per thread - Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. + Copyright (C) 2000, 2002, 2003, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -96,21 +96,6 @@ public class ThreadLocal static final Object NULL = new Object(); /** - * Serves as a key for the Thread.locals WeakHashMap. - * We can't use "this", because a subclass may override equals/hashCode - * and we need to use object identity for the map. - */ - final Key key = new Key(); - - class Key - { - ThreadLocal get() - { - return ThreadLocal.this; - } - } - - /** * Creates a ThreadLocal object without associating any value to it yet. */ public ThreadLocal() @@ -143,11 +128,11 @@ public class ThreadLocal Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will // ever modify the map. - Object value = map.get(key); + Object value = map.get(this); if (value == null) { value = initialValue(); - map.put(key, value == null ? NULL : value); + map.put(this, value == null ? NULL : value); } return value == NULL ? null : value; } @@ -165,6 +150,6 @@ public class ThreadLocal Map map = Thread.getThreadLocals(); // Note that we don't have to synchronize, as only this thread will // ever modify the map. - map.put(key, value == null ? NULL : value); + map.put(this, value == null ? NULL : value); } } |