|
From: <ls...@us...> - 2008-10-26 21:52:37
|
Revision: 4654
http://jnode.svn.sourceforge.net/jnode/?rev=4654&view=rev
Author: lsantha
Date: 2008-10-26 21:52:06 +0000 (Sun, 26 Oct 2008)
Log Message:
-----------
Clarified isolate exit reason.
Modified Paths:
--------------
trunk/core/src/classpath/vm/java/lang/VMRuntime.java
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
Modified: trunk/core/src/classpath/vm/java/lang/VMRuntime.java
===================================================================
--- trunk/core/src/classpath/vm/java/lang/VMRuntime.java 2008-10-26 21:38:26 UTC (rev 4653)
+++ trunk/core/src/classpath/vm/java/lang/VMRuntime.java 2008-10-26 21:52:06 UTC (rev 4654)
@@ -18,7 +18,7 @@
* along with this library; If not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-
+
package java.lang;
import java.io.File;
@@ -162,6 +162,19 @@
}
}
+ /**
+ * Native method that actually shuts down the virtual machine.
+ *
+ * @param status the status to end the process with
+ */
+ static void halt(int status) {
+ if(VmIsolate.getRoot() == VmIsolate.currentIsolate()){
+ throw new VmExit(status);
+ } else {
+ VmIsolate.currentIsolate().systemHalt(Isolate.currentIsolate(), status);
+ }
+ }
+
/**
* Load a file. If it has already been loaded, do nothing. The name has
* already been mapped to a true filename.
@@ -181,7 +194,7 @@
* it to the path.
* XXX This method is being replaced by System.mapLibraryName.
*
- * @param pathname the path
+ * @param libname the path
* @param libname the short version of the library name
* @return the full filename
*/
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-26 21:38:26 UTC (rev 4653)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2008-10-26 21:52:06 UTC (rev 4654)
@@ -384,6 +384,19 @@
stopAllThreads();
}
+ public final void isolateHalt(int status) {
+ changeState(State.EXITING);
+
+ this.exitCode = status;
+ if (currentIsolate() == this) {
+ this.exitReason = IsolateStatus.ExitReason.SELF_HALT;
+ } else {
+ this.exitReason = IsolateStatus.ExitReason.OTHER_HALT;
+ }
+
+ stopAllThreads();
+ }
+
public final void systemExit(Isolate isolate, int status) {
//only this isolate may call this method
testIsolate(isolate);
@@ -396,6 +409,18 @@
stopAllThreads();
}
+ public final void systemHalt(Isolate isolate, int status) {
+ //only this isolate may call this method
+ testIsolate(isolate);
+
+ changeState(State.EXITING);
+
+ this.exitReason = IsolateStatus.ExitReason.SELF_HALT;
+ this.exitCode = status;
+
+ stopAllThreads();
+ }
+
private void stopAllThreads() {
int ac = threadGroup.activeCount();
if (ac > 0) {
@@ -407,7 +432,7 @@
Thread thread = ta[i];
if (current != thread) {
thread.getVmThread().stopForced(null);
- } else {
+ } else {
found = true;
}
}
@@ -417,7 +442,8 @@
doExit();
}
} else {
- //todo analyze this case
+ //todo analyze this case
+ doExit();
}
}
@@ -746,6 +772,10 @@
}
});
+ //create the appcontext for this isolate
+ //todo improve this
+ Class.forName("sun.awt.SunToolkit").getMethod("createNewAppContext").invoke(null);
+
// Update the state of this isolate.
changeState(State.STARTED);
//add to parent
Modified: trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java
===================================================================
--- trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java 2008-10-26 21:38:26 UTC (rev 4653)
+++ trunk/core/src/test/org/jnode/test/core/StatusLinkTest.java 2008-10-26 21:52:06 UTC (rev 4654)
@@ -35,17 +35,27 @@
} finally {
child.exit(0);
}
+
+ child = new Isolate(ChildClass7.class.getName());
+ new Thread(new StatusMonitor(child.newStatusLink()), "status-monitor").start();
+ child.start();
+
+ try {
+ Thread.sleep(100);
+ } finally {
+ child.halt(0);
+ }
+
}
- private static void runChild(Class<?> clazz)
+ private static Isolate runChild(Class<?> clazz)
throws ClosedLinkException, IsolateStartupException, InterruptedException {
- Isolate child;
- Thread moni;
- child = new Isolate(clazz.getName());
- moni = new Thread(new StatusMonitor(child.newStatusLink()), "status-monitor");
+ Isolate child = new Isolate(clazz.getName());
+ Thread moni = new Thread(new StatusMonitor(child.newStatusLink()), "status-monitor");
moni.start();
child.start();
moni.join();
+ return child;
}
public static class StatusMonitor implements Runnable {
@@ -198,12 +208,12 @@
public void run() {
System.out.println("Child thread: started");
System.out.println("Child thread: working ...");
- for(int i = 0; i < 100000; i ++) {
+ for (int i = 0; i < 100000; i++) {
// System.out.println("Child thread: " + i);
Math.sin(i);
- if(i % 100 == 0) {
- //org.jnode.vm.Unsafe.debug("i=" + i + "\n");
- System.out.println("i=" + i);
+ if (i % 100 == 0) {
+ org.jnode.vm.Unsafe.debug("i=" + i + "\n");
+ //System.out.println("i=" + i);
}
}
System.out.println("Child thread: exiting");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|