History

Fixed JCL threads to match the jvm code

Dmitry Kabak (userdima committed 13 years ago

Commit 9ad5c4b1 parent c0b82062 files · +71 −6Browse files

Showing the changes to java (2 of 2 files). Show all

Unified · Split

2 files
  1. java/pkg/java/lang/Thread.java +45 −3
  2. java/pkg/java/lang/ThreadLocal.java +26 −3
java/pkg/java/lang/Thread.java+45−3
@@ -145,11 +145,16 @@ class Thread implements Runnable { · 144 unmodified lines
145145
146146 private char name[];
147147 private int priority;
148− private Thread threadQ;
149− private long eetop;
148+ // [Inferno] <
149+ //private Thread threadQ;
150+ //private long eetop;
151+ // [Inferno] =
152+ private Object PrivateInfo;
153+ private boolean was_interrupted;
154+ // [Inferno] >
150155
151156 /* Whether or not to single_step this thread. */
152− private boolean single_step;
157+ // [Inferno] // private boolean single_step;
153158
154159 /* Whether or not the thread is a daemon thread. */
155160 private boolean daemon = false;
@@ -2032,4 +2037,41 @@ class Thread implements Runnable { · 1876 unmodified lines
20322037 private native void suspend0();
20332038 private native void resume0();
20342039 private native void interrupt0();
2040+
2041+ // [Inferno] <
2042+ private native static void lowinit(Thread thd);
2043+
2044+ //
2045+ // this constructor is only used for the creation of the root
2046+ // thread. This root thread is special, as it is already running.
2047+ // The parameter is only there to make the constructor unique from
2048+ // the public constructors.
2049+ //
2050+ private Thread( int i )
2051+ {
2052+ if ( threadInitNumber != 0 )
2053+ throw new InternalError( "redundant root thread creation" );
2054+
2055+ name = new char[] {'m','a','i','n'};
2056+ priority = NORM_PRIORITY;
2057+ daemon = false;
2058+ stillborn = false;
2059+ target = null;
2060+ group = null; //this is set later
2061+ PrivateInfo = null; //set later to lowerlevel structure
2062+ }
2063+
2064+ static
2065+ {
2066+ // create the "first" thread object and
2067+ // associate it with the thread executing
2068+ // this initializer.
2069+ threadInitNumber = 0; //0 is reserved
2070+ Thread thd = new Thread(0); // use private constructor
2071+ lowinit(thd);
2072+ thd.group.add(thd);
2073+ threadInitNumber = 1; //next thread id
2074+ }
2075+
2076+ // [Inferno] >
20352077 }
java/pkg/java/lang/ThreadLocal.java+26−3
@@ -80,14 +80,37 @@ public class ThreadLocal<T> { · 79 unmodified lines
8080 * are used by the same threads, while remaining well-behaved in
8181 * less common cases.
8282 */
83+ // [Inferno] <
84+ //private final int threadLocalHashCode = nextHashCode();
85+//
86+ ///**
87+ // * The next hash code to be given out. Updated atomically. Starts at
88+ // * zero.
89+ // */
90+ //private static AtomicInteger nextHashCode =
91+ // new AtomicInteger();
92+//
93+ ///**
94+ // * The difference between successively generated hash codes - turns
95+ // * implicit sequential thread-local IDs into near-optimally spread
96+ // * multiplicative hash values for power-of-two-sized tables.
97+ // */
98+ //private static final int HASH_INCREMENT = 0x61c88647;
99+//
100+ ///**
101+ // * Returns the next hash code.
102+ // */
103+ //private static int nextHashCode() {
104+ // return nextHashCode.getAndAdd(HASH_INCREMENT);
105+ //}
106+// ================
83107 private final int threadLocalHashCode = nextHashCode();
84108
85109 /**
86110 * The next hash code to be given out. Updated atomically. Starts at
87111 * zero.
88112 */
89− private static AtomicInteger nextHashCode =
90− new AtomicInteger();
113+ private static int nextHashCode = 0;
91114
92115 /**
93116 * The difference between successively generated hash codes - turns
@@ -100,7 +123,7 @@ public class ThreadLocal<T> { · 6 unmodified lines
100123 * Returns the next hash code.
101124 */
102125 private static int nextHashCode() {
103− return nextHashCode.getAndAdd(HASH_INCREMENT);
126+ return nextHashCode += HASH_INCREMENT;
104127 }
105128
106129 /**