Revision: 3365
http://jnode.svn.sourceforge.net/jnode/?rev=3365&view=rev
Author: lsantha
Date: 2007-07-26 04:02:26 -0700 (Thu, 26 Jul 2007)
Log Message:
-----------
Progress with isolates.
Modified Paths:
--------------
trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
Modified: trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java
===================================================================
--- trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-07-26 09:39:03 UTC (rev 3364)
+++ trunk/core/src/core/org/jnode/vm/isolate/VmIsolate.java 2007-07-26 11:02:26 UTC (rev 3365)
@@ -26,6 +26,7 @@
import java.io.PrintStream;
import java.lang.reflect.Method;
import java.util.Properties;
+import java.util.Vector;
import javax.isolate.Isolate;
import javax.isolate.IsolateStartupException;
@@ -35,6 +36,8 @@
import org.jnode.naming.InitialNaming;
import org.jnode.plugin.PluginManager;
import org.jnode.util.BootableHashMap;
+import org.jnode.util.QueueProcessor;
+import org.jnode.util.QueueProcessorThread;
import org.jnode.vm.Unsafe;
import org.jnode.vm.Vm;
import org.jnode.vm.VmArchitecture;
@@ -120,6 +123,7 @@
*
* @author Ewout Prangsma (ep...@us...)
*/
+ @SharedStatics
private enum State {
CREATED, STARTING, STARTED, EXITED, TERMINATED
}
@@ -199,7 +203,7 @@
/**
* Is the current thread running in the root isolate
*/
- public final static boolean isRoot() {
+ public static boolean isRoot() {
VmIsolate result = IsolatedStaticData.current;
if (result != null) {
return (result == StaticData.getRoot());
@@ -210,7 +214,7 @@
/**
* Is the current thread running in the root isolate
*/
- public final static VmIsolate getRoot() {
+ public static VmIsolate getRoot() {
return StaticData.getRoot();
}
@@ -219,7 +223,7 @@
*
* @return
*/
- public final static VmIsolate currentIsolate() {
+ public static VmIsolate currentIsolate() {
VmIsolate result = IsolatedStaticData.current;
if (result == null) {
result = StaticData.getRoot();
@@ -422,11 +426,70 @@
mainThread.start();
}
+ private Vector<Runnable> taskList = new Vector<Runnable>();
+ private final Object taskSync = new Object();
+ private Thread executorThread;
+
+ public void invokeAndWait(final Runnable task){
+ if(this == StaticData.rootIsolate){
+ task.run();
+ return;
+ }
+
+ synchronized(taskSync){
+ taskList.add(task);
+ taskSync.notifyAll();
+ }
+
+ synchronized(task){
+ while(taskList.contains(task)){
+ try {
+ task.wait();
+ }catch(InterruptedException e){
+ //
+ }
+ }
+ }
+ }
+
+ private class TaskExecutor implements Runnable{
+ public void run() {
+ //while(!VmIsolate.this.hasTerminated()){
+ do {
+ Runnable task = null;
+ synchronized(taskSync){
+ try {
+ while(taskList.isEmpty()){
+ taskSync.wait();
+ }
+ try {
+ task = taskList.get(0);
+ task.run();
+ taskList.remove(0);
+ } catch(Throwable t){
+ System.err.println("Error during task execution, dropping task");
+ t.printStackTrace();
+ taskList.remove(0);
+ }
+ }catch(InterruptedException ie){
+ //
+ }
+ }
+ if(task != null)
+ synchronized(task){
+ task.notifyAll();
+ }
+ } while(!hasExited());
+ //} while(true);
+ }
+ }
+
/**
* Run this isolate. This method is called from IsolateThread.
*/
@PrivilegedActionPragma
final void run(IsolateThread thread) {
+ VmIsolate o_current = IsolatedStaticData.current;
try {
Unsafe.debug("isolated run ");
// Set current
@@ -448,6 +511,10 @@
// Load the main class
final Class< ? > cls = loader.loadClass(mainClass);
+ //start executor
+ executorThread = new Thread(new TaskExecutor(), "isolate-executor");
+ executorThread.start();
+
// Find main method
final Method mainMethod = cls.getMethod("main",
IsolatedStaticData.mainTypes);
@@ -477,6 +544,8 @@
Unsafe.debug("Exception in catch block.. giving up: ");
Unsafe.debug(ex2.getMessage());
}
+ } finally {
+ IsolatedStaticData.current = o_current;
}
}
@@ -502,6 +571,7 @@
/**
* Gets the classname of the main class.
+ * @return the main class name
*/
final String getMainClassName() {
return mainClass;
@@ -523,7 +593,7 @@
}
}
- private final void testIsolate(Isolate isolate) {
+ private void testIsolate(Isolate isolate) {
if (this.isolate != isolate) {
throw new SecurityException("Method called by invalid isolate");
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|