From: <zy...@us...> - 2010-09-12 23:08:25
|
Revision: 7120 http://jython.svn.sourceforge.net/jython/?rev=7120&view=rev Author: zyasoft Date: 2010-09-12 23:08:19 +0000 (Sun, 12 Sep 2010) Log Message: ----------- Backed out support for nulling out ThreadState support. We need a better solution that doesn't introduce synchronization issues and a backwards breaking API change. See the discussion in #1327. Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/ThreadStateMapping.java trunk/jython/tests/java/org/python/core/WrappedBooleanTest.java trunk/jython/tests/java/org/python/core/WrappedFloatTest.java trunk/jython/tests/java/org/python/core/WrappedIntegerTest.java trunk/jython/tests/java/org/python/core/WrappedLongTest.java trunk/jython/tests/java/org/python/tests/ExceptionTest.java trunk/jython/tests/java/org/python/tests/SerializationTest.java trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/src/org/python/core/PySystemState.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -1244,10 +1244,6 @@ return f; } - public void registerThreadState(ThreadState[] threadLocal, ThreadState ts) { - closer.registerThreadState(threadLocal, ts); - } - public void registerCloser(Callable resourceCloser) { closer.registerCloser(resourceCloser); } @@ -1281,7 +1277,6 @@ private static class PySystemStateCloser { - private final ArrayList<WeakReference<ThreadState[]>> threadStateList = new ArrayList<WeakReference<ThreadState[]>>(); private final Set<Callable> resourceClosers = new LinkedHashSet<Callable>(); private volatile boolean isCleanup = false; private final Thread shutdownHook; @@ -1301,13 +1296,6 @@ } } - private synchronized void registerThreadState(ThreadState[] threadLocal, ThreadState ts) { - if (!isCleanup) { - threadLocal[0] = ts; - threadStateList.add(new WeakReference<ThreadState[]>(threadLocal)); - } - } - private synchronized void registerCloser(Callable closer) { if (!isCleanup) { resourceClosers.add(closer); @@ -1329,15 +1317,6 @@ Runtime.getRuntime().removeShutdownHook(shutdownHook); } - // clear out existing ThreadStates so that they can be GCed - this resolves ClassLoader issues - for (WeakReference<ThreadState[]> ref : threadStateList) { - ThreadState[] o = ref.get(); - if (o != null) { - o[0] = null; - } - } - threadStateList.clear(); - for (Callable callable : resourceClosers) { try { callable.call(); Modified: trunk/jython/src/org/python/core/ThreadStateMapping.java =================================================================== --- trunk/jython/src/org/python/core/ThreadStateMapping.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/src/org/python/core/ThreadStateMapping.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -1,19 +1,15 @@ package org.python.core; class ThreadStateMapping { - private static final ThreadLocal<ThreadState[]> cachedThreadState = - new ThreadLocal<ThreadState[]>() { - @Override - protected ThreadState[] initialValue() { - return new ThreadState[1]; - } - }; + private static final ThreadLocal<ThreadState> cachedThreadState = new ThreadLocal<ThreadState>(); - public synchronized ThreadState getThreadState(PySystemState newSystemState) { - ThreadState[] threadLocal = cachedThreadState.get(); - if (threadLocal[0] != null) - return threadLocal[0]; + public ThreadState getThreadState(PySystemState newSystemState) { + ThreadState ts = cachedThreadState.get(); + if (ts != null) { + return ts; + } + Thread t = Thread.currentThread(); if (newSystemState == null) { Py.writeDebug("threadstate", "no current system state"); @@ -23,8 +19,8 @@ newSystemState = Py.defaultSystemState; } - ThreadState ts = new ThreadState(t, newSystemState); - newSystemState.registerThreadState(threadLocal, ts); + ts = new ThreadState(t, newSystemState); + cachedThreadState.set(ts); return ts; } } Modified: trunk/jython/tests/java/org/python/core/WrappedBooleanTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/WrappedBooleanTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/core/WrappedBooleanTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -32,7 +32,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); a = new WrappedBoolean(); b = new WrappedBoolean(); Modified: trunk/jython/tests/java/org/python/core/WrappedFloatTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/WrappedFloatTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/core/WrappedFloatTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -32,7 +32,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); a = new WrappedFloat(); b = new WrappedFloat(); Modified: trunk/jython/tests/java/org/python/core/WrappedIntegerTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/WrappedIntegerTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/core/WrappedIntegerTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -32,7 +32,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); a = new WrappedInteger(); b = new WrappedInteger(); Modified: trunk/jython/tests/java/org/python/core/WrappedLongTest.java =================================================================== --- trunk/jython/tests/java/org/python/core/WrappedLongTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/core/WrappedLongTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -34,7 +34,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); a = new WrappedLong(); b = new WrappedLong(); Modified: trunk/jython/tests/java/org/python/tests/ExceptionTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/ExceptionTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/tests/ExceptionTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -28,7 +28,6 @@ " else:\n" + " raise Throwable()\n" + "r = Raiser()"; - PythonInterpreter.initialize(null, null, null); PythonInterpreter interp = new PythonInterpreter(); interp.exec(raiser); t = Py.tojava(interp.get("r"), Thrower.class); Modified: trunk/jython/tests/java/org/python/tests/SerializationTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/SerializationTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/tests/SerializationTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -18,7 +18,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); interp.exec("from java.io import Serializable"); interp.exec("class Test(Serializable): pass"); Modified: trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2010-09-12 23:04:58 UTC (rev 7119) +++ trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2010-09-12 23:08:19 UTC (rev 7120) @@ -12,7 +12,6 @@ @Override protected void setUp() throws Exception { - PythonInterpreter.initialize(null, null, null); interp = new PythonInterpreter(new PyStringMap(), new PySystemState()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |