You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ar...@apache.org on 2006/06/11 00:40:53 UTC
svn commit: r413372 - in /incubator/harmony/enhanced/classlibadapter/trunk:
build.sh jc_run.sh modules/kernel/src/main/java/java/lang/Thread.java
modules/kernel/src/main/java/java/lang/ThreadGroup.java
modules/kernel/src/main/java/java/lang/VMThread.java
Author: archie
Date: Sat Jun 10 15:40:52 2006
New Revision: 413372
URL: http://svn.apache.org/viewvc?rev=413372&view=rev
Log:
- Inherit priority, daemon status, and context class loader from parent.
- Implement more unimplemented [VM]Thread methods.
- Fix ThreadLocal support.
- Build fixes to the old build.sh script.
- Other minor cleanups and simplifications.
Modified:
incubator/harmony/enhanced/classlibadapter/trunk/build.sh
incubator/harmony/enhanced/classlibadapter/trunk/jc_run.sh
incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/Thread.java
incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/ThreadGroup.java
incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/VMThread.java
Modified: incubator/harmony/enhanced/classlibadapter/trunk/build.sh
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/build.sh?rev=413372&r1=413371&r2=413372&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/build.sh (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/build.sh Sat Jun 10 15:40:52 2006
@@ -34,10 +34,10 @@
BOOT=$CLASSLIB_HOME/deploy/jdk/jre/lib/boot
CP=$BOOT/nio.jar:$BOOT/luni.jar:$BOOT/annotation.jar:$KERNEL
-JAVAC="java -jar $CLASSLIB_HOME/depends/jars/ecj_3.2RC5/ecj_3.2RC5.jar -source 1.5 -target jsr14"
+#JAVAC="java -jar $CLASSLIB_HOME/depends/jars/ecj_3.2RC5/ecj_3.2RC5.jar -source 1.5 -target jsr14"
+JAVAC="javac -source 1.5 -target jsr14"
(cd $KERNEL; $JAVAC -classpath $CP $(find . -name *.java)) || die
(cd $NIO; $JAVAC -classpath $CP $(find . -name *.java)) || die
-
-g++ -Wall -shared -o libvmi.so vmi/*.cpp -I$CLASSLIB_HOME/deploy/include -I$CLASSLIB_HOME/native-src/linux.IA32/include -I$CLASSLIB_HOME/native-src/shared/include -DLINUX -L$CLASSLIB_HOME/deploy/jdk/jre/bin -lhyprt -lhythr -lhysig -L$CLASSLIB_HOME/native-src/linux.IA32/lib -lhyzip -lhypool
+g++ -Wall -shared -o libvmi.so vmi/*.cpp -I$CLASSLIB_HOME/deploy/include -I$CLASSLIB_HOME/deploy/jdk/include -I$CLASSLIB_HOME/native-src/linux.IA32/include -I$CLASSLIB_HOME/native-src/shared/include -DLINUX -L$CLASSLIB_HOME/deploy/jdk/jre/bin -lhyprt -lhythr -lhysig -L$CLASSLIB_HOME/native-src/linux.IA32/lib -lhyzip -lhypool
Modified: incubator/harmony/enhanced/classlibadapter/trunk/jc_run.sh
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/jc_run.sh?rev=413372&r1=413371&r2=413372&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/jc_run.sh (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/jc_run.sh Sat Jun 10 15:40:52 2006
@@ -1,7 +1,18 @@
#!/bin/bash
-export JCHEVM_HOME=/home/ivan/experiments/harmony/jchevm/inst
-export CLASSLIB_HOME=/home/ivan/experiments/harmony/CLASSLIB/deploy/jdk/jre
+if [ "${CLASSLIB_HOME}" = "" ]; then
+ echo "Please define CLASSLIB_HOME" 2>&1
+ exit 1
+fi
+CLASSLIB_HOME="${CLASSLIB_HOME}/deploy/jdk/jre"
+
+if [ "${JCHEVM_HOME}" = "" ]; then
+ JCHEVM_HOME=/usr/local
+fi
+
+echo Using CLASSLIB_HOME = "${CLASSLIB_HOME}"
+echo Using JCHEVM_HOME = "${JCHEVM_HOME}"
+
ADAPTER=$(dirname $0)
JC=$JCHEVM_HOME/bin/jc
Modified: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/Thread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/Thread.java?rev=413372&r1=413371&r2=413372&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/Thread.java (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/Thread.java Sat Jun 10 15:40:52 2006
@@ -15,6 +15,8 @@
package java.lang;
+import java.util.WeakHashMap;
+
/**
* This class must be implemented by the vm vendor. The documented methods must
* be implemented to support other provided class implementations in this
@@ -40,6 +42,8 @@
// a thread
public final static int NORM_PRIORITY = 5; // Normal priority for a thread
+ static int threadCounter;
+
Runnable runnableSlot;
//////String threadNameSlot; //maybe same as next one
String name;
@@ -49,18 +53,19 @@
final VMThread vmThread;
///boolean isDaemonSlot; //maybe this is the same as daemon
boolean daemon;
- ThreadLocal threadLocalSlot;
+ WeakHashMap threadLocals;
+ ClassLoader contextClassLoader;
long stackSlot;
int priority;
- public Thread(VMThread vmt1, String s1, int i1, boolean b1)
- {
- super();
- vmThread = vmt1;
- name = s1;
- priority = i1;
- daemon = b1;
+ public Thread(VMThread vmThread, String name,
+ int priority, boolean daemon) {
+ this.vmThread = vmThread;
+ this.name = name;
+ this.priority = priority;
+ this.daemon = daemon;
+ contextClassLoader = ClassLoader.getSystemClassLoader();
}
/**
@@ -71,8 +76,15 @@
* @see java.lang.ThreadGroup
*/
public Thread() {
- super();
vmThread = new VMThread(this);
+ Thread current = currentThread();
+ priority = current.priority;
+ daemon = current.daemon;
+ int threadNumber = ++Thread.threadCounter; // race condition
+ name = "Thread-" + threadNumber;
+ //group = current.group;
+ //group.addThread(this);
+ contextClassLoader = current.contextClassLoader;
}
/**
@@ -87,9 +99,8 @@
* @see java.lang.Runnable
*/
public Thread(Runnable runnable) {
- super();
+ this();
runnableSlot = runnable;
- vmThread = new VMThread(this);
}
/**
@@ -106,11 +117,9 @@
* @see java.lang.Runnable
*/
public Thread(Runnable runnable, String threadName) {
- super();
+ this();
runnableSlot = runnable;
name = threadName;
- vmThread = new VMThread(this);
-
}
/**
@@ -124,9 +133,8 @@
* @see java.lang.Runnable
*/
public Thread(String threadName) {
- super();
+ this();
name = threadName;
- vmThread = new VMThread(this);
}
/**
@@ -149,10 +157,9 @@
* @see java.lang.SecurityManager
*/
public Thread(ThreadGroup gr, Runnable runnable) {
- super();
+ this();
group = gr;
runnableSlot = runnable;
- vmThread = new VMThread(this);
}
/**
@@ -180,11 +187,10 @@
*/
public Thread(ThreadGroup gr, Runnable runnable, String threadName,
long stack) {
- super();
+ this();
group = gr;
runnableSlot = runnable;
name = threadName;
- vmThread = new VMThread(this);
}
/**
@@ -209,11 +215,10 @@
* @see java.lang.SecurityManager
*/
public Thread(ThreadGroup gr, Runnable runnable, String threadName) {
- super();
+ this();
group = gr;
runnableSlot = runnable;
name = threadName;
- vmThread = new VMThread(this);
}
/**
@@ -234,10 +239,9 @@
* @see java.lang.SecurityManager
*/
public Thread(ThreadGroup gr, String threadName) {
- super();
+ this();
group = gr;
name = threadName;
- vmThread = new VMThread(this);
}
/**
@@ -288,10 +292,9 @@
/**
* Destroys the receiver without any monitor cleanup. Not implemented.
- *
*/
public void destroy() {
- return; //fixit -- a "nop" is a reasonable implementation of a seldom used API, its never called for simple "hello world" app
+ throw new NoSuchMethodError();
}
/**
@@ -299,11 +302,7 @@
*
*/
public static void dumpStack() {
- try {
- throw new Exception("stack dump");
- } catch (Throwable t) {
- t.printStackTrace();
- }
+ new Throwable("stack dump").printStackTrace();
}
/**
@@ -322,7 +321,7 @@
* @see java.lang.SecurityManager
*/
public static int enumerate(Thread[] threads) {
- return 0; //fixit -- returning zero is good enough for simple "hello world" demo
+ return currentThread().group.enumerate(threads);
}
/**
@@ -333,8 +332,7 @@
* @see #getContextClassLoader()
*/
public ClassLoader getContextClassLoader() {
- //fixit -- returning null is good enough for simple "hello world" demo
- return null;
+ return contextClassLoader;
}
/**
@@ -343,8 +341,7 @@
* @return the receiver's name (a java.lang.String)
*/
public final String getName() {
- //String ss = name + this.toString();
- return this.toString(); // fixit -- find out the proper construction for thread names
+ return name;
}
/**
@@ -354,7 +351,7 @@
* @see Thread#setPriority
*/
public final int getPriority() {
- return 0; //fixit -- correct thread priority is not essential to demoing simple "hello world"
+ return priority;
}
/**
@@ -363,7 +360,7 @@
* @return the receiver's ThreadGroup
*/
public final ThreadGroup getThreadGroup() {
- return group; //fixit -- ThreadGroups are not essential to demoing simple "hello world"
+ return group;
}
/**
@@ -378,7 +375,9 @@
* @see #setThreadLocal
*/
Object getThreadLocal(ThreadLocal local) {
- return threadLocalSlot.get(); //fixit -- this code looks correct. It needs to be verified/confirmed it is correct
+ if (threadLocals == null)
+ return null;
+ return threadLocals.get(local);
}
/**
@@ -463,8 +462,7 @@
* @see java.lang.ThreadDeath
*/
public final void join() throws InterruptedException {
- //fixit -- obviously incorrect but it seems OK for simple "hello world" demo
- return;
+ join(0, 0);
}
/**
@@ -482,8 +480,7 @@
*/
public final void join(long timeoutInMilliseconds)
throws InterruptedException {
- //fixit -- obviously incorrect but it seems OK for simple "hello world" demo
- return;
+ join(timeoutInMilliseconds, 0);
}
/**
@@ -501,10 +498,11 @@
* @see Object#notifyAll
* @see java.lang.ThreadDeath
*/
- public final void join(long timeoutInMilliseconds, int nanos)
- throws InterruptedException {
- //fixit -- obviously incorrect but it seems OK for simple "hello world" demo
- return;
+ public final void join(long millis, int nanos) throws InterruptedException {
+ if (millis < 0 || nanos < 0 || nanos > 999999)
+ throw new IllegalArgumentException();
+ if (vmThread != null)
+ vmThread.join(millis, nanos);
}
/**
@@ -519,8 +517,8 @@
* @deprecated Used with deprecated method Thread.suspend().
*/
public final void resume() {
- //fixit -- obviously incorrect but it seems OK for simple "hello world" demo
- return;
+ if (vmThread != null)
+ vmThread.resume();
}
/**
@@ -544,8 +542,7 @@
* @see #getContextClassLoader()
*/
public void setContextClassLoader(ClassLoader cl) {
- //fixit -- this incorrect code is good enough to allow simple "hello world" demo to run
- return;
+ this.contextClassLoader = cl;
}
/**
@@ -559,8 +556,8 @@
* SecurityException
* @see Thread#isDaemon
*/
- public final void setDaemon(boolean isDaemon) {
- daemon = isDaemon;
+ public final void setDaemon(boolean daemon) {
+ this.daemon = daemon;
}
/**
@@ -573,8 +570,8 @@
* SecurityException
* @see Thread#getName
*/
- public final void setName(String threadName) {
- name = threadName;
+ public final void setName(String name) {
+ this.name = name;
}
/**
@@ -595,7 +592,6 @@
*/
public final void setPriority(int priority) {
vmThread.nativeSetPriority(priority);
- return; //fixit -- this is incorrect code but its good enough for simple "hello world" demo
}
/**
@@ -611,8 +607,9 @@
* @see #getThreadLocal
*/
void setThreadLocal(ThreadLocal local, Object value) {
- threadLocalSlot.set(value);
- return;
+ if (threadLocals == null)
+ threadLocals = new WeakHashMap();
+ threadLocals.put(local, value);
}
/**
@@ -628,9 +625,8 @@
* @see Thread#interrupt()
*/
- public static void sleep(long time) throws InterruptedException {
- //fixit -- this is incorrect code that is good enough to allow simple "hello world" demo to run
- return;
+ public static void sleep(long millis) throws InterruptedException {
+ sleep(millis, 0);
}
/**
@@ -647,10 +643,11 @@
* while it was sleeping
* @see Thread#interrupt()
*/
- public static void sleep(long time, int nanos) throws InterruptedException {
- //fixit -- this is incorrect code that is good enough to allow simple "hello world" demo to run
- return;
- };
+ public static void sleep(long millis, int nanos) throws InterruptedException {
+ if (millis < 0 || nanos < 0 || nanos > 999999)
+ throw new IllegalArgumentException();
+ VMThread.sleep(millis, nanos);
+ }
/**
* Starts the new Thread of execution. The <code>run()</code> method of
@@ -691,8 +688,7 @@
* @deprecated
*/
public final void stop() {
- //fixit -- doing a "nop" will allow simple "hello world" app to run
- return;
+ stop(new ThreadDeath());
}
/**
@@ -711,8 +707,10 @@
* @deprecated
*/
public final void stop(Throwable throwable) {
- //fixit -- doing a "nop" will allow simple "hello world" app to run
- return;
+ if (throwable == null)
+ throw new NullPointerException();
+ if (vmThread != null)
+ vmThread.stop(throwable);
}
/**
@@ -729,8 +727,8 @@
* @deprecated May cause deadlocks.
*/
public final void suspend() {
- //fixit -- doing a "nop" will allow simple "hello world" app to run
- return;
+ if (vmThread != null)
+ vmThread.suspend();
}
/**
@@ -740,7 +738,7 @@
* @return a printable representation for the receiver.
*/
public String toString() {
- return name.toString();
+ return name;
}
/**
@@ -763,8 +761,12 @@
* object
*/
public static boolean holdsLock(Object object) {
- return false; //fixit -- simply returning "false" is good enough to get simple "hello world" demo going
+ try {
+ object.notify();
+ } catch (IllegalMonitorStateException e) {
+ return false;
+ }
+ return true;
};
-
}
Modified: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/ThreadGroup.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/ThreadGroup.java?rev=413372&r1=413371&r2=413372&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/ThreadGroup.java (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/ThreadGroup.java Sat Jun 10 15:40:52 2006
@@ -111,12 +111,8 @@
* @throws IllegalThreadStateException if <code>parent<code> has been destroyed already
*/
public ThreadGroup(ThreadGroup parent, String name) {
- super();
- if (Thread.currentThread() != null) {
- // If parent is null we must throw NullPointerException, but that
- // will be done "for free" with the message send below
+ if (parent != null)
parent.checkAccess();
- }
this.name = name;
this.setParent(parent);
Modified: incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/VMThread.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/VMThread.java?rev=413372&r1=413371&r2=413372&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/VMThread.java (original)
+++ incubator/harmony/enhanced/classlibadapter/trunk/modules/kernel/src/main/java/java/lang/VMThread.java Sat Jun 10 15:40:52 2006
@@ -14,7 +14,7 @@
*/
package java.lang;
-class VMThread
+final class VMThread
{
VMThread(Thread t1)
{
@@ -39,47 +39,91 @@
thread.run();
+ } catch (Throwable t) {
+ try {
+ if (thread.group != null)
+ thread.group.uncaughtException(thread, t);
+ } catch(Throwable ignore) {
+ // ignore double fault
+ }
+ } finally {
synchronized (this) {
running = false;
notifyAll();
}
- } catch (Throwable t) {
- System.err.println("Thread dead with exception:");
- t.printStackTrace();
- }
+ }
destroy();
}
- final boolean isAlive() {
+ boolean isAlive() {
synchronized (this) {
return running;
}
}
- private final native void attach();
- private final native void destroy();
-
-
- final native int countStackFrames();
-
- static final native Thread currentThread();
-
- final native void interrupt();
+ void stop(Throwable t) {
+ nativeStop(t);
+ }
+
+ synchronized void join(long millis, int nanos) throws InterruptedException {
+ if (nanos != 0)
+ millis++; // we only use millisecond precision
+ long finish = 0;
+ if (millis != 0) {
+ long now = System.currentTimeMillis();
+ finish = now + millis;
+ if (finish < now)
+ finish = Long.MAX_VALUE; // handle overflow
+ }
+ for (long remain = millis; !started || running; ) {
+ wait(remain);
+ if (finish != 0) {
+ remain = finish - System.currentTimeMillis();
+ if (remain <= 0)
+ break;
+ }
+ }
+ }
+
+ static void sleep(long millis, int nanos) throws InterruptedException {
+ if (nanos != 0)
+ millis++; // we only use millisecond precision
+ long now = System.currentTimeMillis();
+ long finish = now + millis;
+ if (finish < now)
+ finish = Long.MAX_VALUE; // handle overflow
+ Object sleeper = new Object();
+ synchronized (sleeper) {
+ while (now < finish) {
+ sleeper.wait(finish - now, 0);
+ now = System.currentTimeMillis();
+ }
+ }
+ }
+
+ private native void attach();
+ private native void destroy();
+
+ native int countStackFrames();
+
+ static native Thread currentThread();
+
+ native void interrupt();
+
+ static native boolean interrupted();
+
+ native boolean isInterrupted();
+
+ native void nativeSetPriority(int pri);
+
+ native void nativeStop(Throwable thr);
- static final native boolean interrupted();
+ native void resume();
- final native boolean isInterrupted();
+ native void start(long stacklength);
- final native void nativeSetPriority(int pri);
-
- final native void nativeStop(Throwable thr);
-
- final native void resume();
-
- final native void start(long stacklength);
-
- final native void suspend();
-
- static final native void yield();
+ native void suspend();
+ static native void yield();
}
+