Changeset 729
- Timestamp:
- 08/17/07 08:28:18 (2 years ago)
- Location:
- trunk/ProjectFortress
- Files:
-
- 11 modified
-
junit (modified) (1 diff)
-
src/com/sun/fortress/interpreter/drivers/Driver.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/Evaluator.java (modified) (5 diffs)
-
src/com/sun/fortress/interpreter/evaluator/EvaluatorJUTest.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/evaluator/tasks/BaseTask.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/tasks/EvaluatorTask.java (modified) (3 diffs)
-
src/com/sun/fortress/interpreter/evaluator/tasks/FortressTaskRunner.java (modified) (16 diffs)
-
src/com/sun/fortress/interpreter/evaluator/tasks/SpawnTask.java (modified) (1 diff)
-
src/com/sun/fortress/interpreter/evaluator/tasks/ThreadState.java (modified) (4 diffs)
-
src/com/sun/fortress/interpreter/evaluator/tasks/TupleTask.java (modified) (2 diffs)
-
src/com/sun/fortress/interpreter/evaluator/values/FThread.java (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ProjectFortress/junit
r605 r729 21 21 22 22 if (uname | egrep -q CYGWIN) ; then 23 CP="build;third_party/junit/junit.jar;third_party/xtc/xtc.jar;third_party/ FJ/concurrent.jar;third_party/plt/plt.jar"23 CP="build;third_party/junit/junit.jar;third_party/xtc/xtc.jar;third_party/jsr166y/jsr166y.jar;third_party/plt/plt.jar" 24 24 else 25 CP="build:third_party/junit/junit.jar:third_party/xtc/xtc.jar:third_party/ FJ/concurrent.jar:third_party/plt/plt.jar"25 CP="build:third_party/junit/junit.jar:third_party/xtc/xtc.jar:third_party/jsr166y/jsr166y.jar:third_party/plt/plt.jar" 26 26 fi 27 27 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/drivers/Driver.java
r722 r729 42 42 import com.sun.fortress.interpreter.evaluator.InterpreterBug; 43 43 import com.sun.fortress.interpreter.evaluator.ProgramError; 44 import com.sun.fortress.interpreter.evaluator.types.FType; 45 import com.sun.fortress.interpreter.evaluator.tasks.BaseTask; 44 46 import com.sun.fortress.interpreter.evaluator.tasks.EvaluatorTask; 45 import com.sun.fortress.interpreter.evaluator.t ypes.FType;47 import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunner; 46 48 import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunnerGroup; 47 49 import com.sun.fortress.interpreter.evaluator.values.Closure; … … 686 688 group = new FortressTaskRunnerGroup(numThreads); 687 689 688 EvaluatorTask evTask = new EvaluatorTask(p, runTests, args , null);690 EvaluatorTask evTask = new EvaluatorTask(p, runTests, args); 689 691 try { 690 692 group.invoke(evTask); … … 694 696 } 695 697 if (evTask.causedException()) { 696 throw evTask. getTaskException();698 throw evTask.taskException(); 697 699 } 698 700 } -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/Evaluator.java
r720 r729 167 167 public class Evaluator extends EvaluatorBase<FValue> { 168 168 boolean debug = false; 169 int transactionNestingCount = 0;170 171 169 final public static FVoid evVoid = FVoid.V; 172 170 … … 210 208 super(e2.e); 211 209 debug = e2.debug; 212 transactionNestingCount = e2.transactionNestingCount;213 210 } 214 211 … … 304 301 final Expr expr = x.getExpr(); 305 302 final Evaluator current = new Evaluator(this); 306 transactionNestingCount += 1;307 303 308 304 FValue res = FortressTaskRunner.doIt ( … … 314 310 } 315 311 ); 316 transactionNestingCount -= 1;317 312 return res; 318 313 } … … 424 419 if (sz==1) { 425 420 resList.add(exprs.get(0).accept(this)); 426 } else if (transactionNestingCount > 0) { 427 for (Expr exp : exprs) { 428 resList.add(exp.accept(this)); 429 } 421 /* If we are already in a transaction, don't evaluate in parallel */ 422 } else if (BaseTask.getThreadState().transactionNesting() > 0) { 423 for (Expr exp : exprs) { 424 resList.add(exp.accept(this)); 425 } 430 426 } else if (sz > 1) { 431 427 TupleTask[] tasks = new TupleTask[exprs.size()]; 432 428 int count = 0; 433 BaseTask currentTask = BaseTask.getCurrentTask();434 429 for (Expr e : exprs) { 435 tasks[count++] = new TupleTask(e, this, currentTask); 436 } 430 tasks[count++] = new TupleTask(e, this); 431 } 432 FortressTaskRunner runner = (FortressTaskRunner) Thread.currentThread(); 433 BaseTask currentTask = runner.getCurrentTask(); 437 434 TupleTask.coInvoke(tasks); 435 runner.setCurrentTask(currentTask); 436 438 437 for (int i = 0; i < count; i++) { 439 if (tasks[i].causedException ) {440 Throwable t = tasks[i]. getTaskException();438 if (tasks[i].causedException()) { 439 Throwable t = tasks[i].taskException(); 441 440 if (t instanceof Error) { 442 441 throw (Error)t; -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/EvaluatorJUTest.java
r721 r729 26 26 27 27 import com.sun.fortress.interpreter.env.BetterEnv; 28 import com.sun.fortress.interpreter.evaluator.tasks.BaseTask; 28 29 import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunner; 29 30 import com.sun.fortress.interpreter.evaluator.tasks.FortressTaskRunnerGroup; … … 47 48 } 48 49 49 FortressTaskRunnerGroup group; 50 class TestTask extends BaseTask { 51 public void print() { 52 System.out.println("TestTask"); 53 } 54 55 public void compute() { 56 FortressTaskRunner runner = (FortressTaskRunner) Thread.currentThread(); 57 runner.setCurrentTask(this); 58 59 try { 60 BetterEnv e = BetterEnv.primitive(); 61 e.bless(); 62 BetterEnv s = new BetterEnv(e, "s"); 63 s.bless(); 64 BetterEnv s1 = new BetterEnv(s, "s1"); 65 s1.putVariable("x", FInt.make(0)); 66 s1.bless(); 67 BetterEnv s2 = new BetterEnv(s1, "s2"); 68 s2.putValue("y", FInt.make(10)); 69 s2.bless(); 70 BetterEnv s3 = new BetterEnv(s2, "s3"); 71 s3.bless(); 72 HasAt at = new HasAt.FromString("EvaluatorJUTest assignValue"); 73 s3.assignValue(at,"x", FInt.make(1)); 74 assertTrue(s2.getValue("x").getInt() == 1); 75 s3.dump(System.out); 76 } catch (IOException e) { 77 throw new RuntimeException(e); 78 } 79 } 80 } 50 81 51 82 public void testEnvironment2() throws IOException { 52 group = new FortressTaskRunnerGroup(1); 53 54 BetterEnv e = BetterEnv.primitive(); 55 e.bless(); 56 BetterEnv s = new BetterEnv(e, "s"); 57 s.bless(); 58 BetterEnv s1 = new BetterEnv(s, "s1"); 59 s1.putVariable("x", FInt.make(0)); 60 s1.bless(); 61 BetterEnv s2 = new BetterEnv(s1, "s2"); 62 s2.putValue("y", FInt.make(10)); 63 s2.bless(); 64 BetterEnv s3 = new BetterEnv(s2, "s3"); 65 s3.bless(); 66 HasAt at = new HasAt.FromString("EvaluatorJUTest assignValue"); 67 s3.assignValue(at,"x", FInt.make(1)); 68 assertTrue(s2.getValue("x").getInt() == 1); 69 s3.dump(System.out); 83 FortressTaskRunnerGroup group = new FortressTaskRunnerGroup(1); 84 TestTask testTask = new TestTask(); 85 group.invoke(testTask); 70 86 } 71 87 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/BaseTask.java
r717 r729 26 26 import com.sun.fortress.interpreter.evaluator.transactions.exceptions.SnapshotException; 27 27 import java.util.concurrent.Callable; 28 import com.sun.fortress.interpreter.evaluator.tasks.ThreadState; 28 29 29 30 public abstract class BaseTask extends RecursiveAction { 30 public boolean causedException;31 public Throwable err;32 public BaseTask currentTask;33 int transactionCount;31 Throwable err; 32 boolean causedException; 33 ThreadState threadState; 34 BaseTask parent; 34 35 35 public void initTask() { 36 setCurrentTask(this); 37 transactionCount = 0; 38 } 36 public BaseTask() { 37 causedException = false; 38 threadState = new ThreadState(); 39 parent = getCurrentTask(); 40 } 39 41 40 public void finalizeTask() { 41 setCurrentTask(parent); 42 if (parent != null) { 43 if (causedException) { 44 parent.causedException = true; 45 parent.err = err; 46 } 47 } 48 } 49 50 public BaseTask(BaseTask parent) { 51 causedException = false; 52 setParentTask(parent); 42 public void recordException(Throwable t) { 43 causedException = true; 44 err = t; 53 45 } 54 46 55 47 public boolean causedException() {return causedException;} 56 public Throwable getTaskException() {return err;}48 public Throwable taskException() {return err;} 57 49 58 50 public static BaseTask getCurrentTask() { 59 FortressTaskRunner taskrunner = (FortressTaskRunner) Thread.currentThread(); 60 return (BaseTask) taskrunner.getCurrentTask(); 51 /* This may get called before we've started our FortressTaskGroup so in 52 that case we have no current task and need to return null */ 53 Thread t = Thread.currentThread(); 54 BaseTask result = null; 55 if (t instanceof FortressTaskRunner) { 56 FortressTaskRunner taskrunner = (FortressTaskRunner) t; 57 result = (BaseTask) taskrunner.getCurrentTask(); 58 } 59 return result; 61 60 } 62 61 … … 66 65 } 67 66 68 BaseTask parent;69 public BaseTask getParentTask() { return parent;}70 public void setParentTask(BaseTask task) { parent = task;}71 72 73 67 public abstract void print(); 74 68 … … 77 71 while (currentTask != null) { 78 72 currentTask.print(); 79 currentTask = currentTask. getParentTask();73 currentTask = currentTask.parent; 80 74 } 81 75 } 82 76 83 Object tag; 84 // Finds the current task and tags it 85 public static void tagCurrentTask(Object obj) { 86 BaseTask currentTask = getCurrentTask(); 87 currentTask.setTag(obj); 77 public ThreadState threadState() { return threadState();} 78 79 public static ThreadState getThreadState() { 80 BaseTask task = getCurrentTask(); 81 if (task == null) 82 throw new RuntimeException("Not in a task!"); 83 return task.threadState; 88 84 } 89 90 // Get the tag from the current task91 public static Object getCurrentTag() {92 BaseTask currentTask = getCurrentTask();93 return currentTask.getTag();94 }95 96 public void setTag(Object obj) { tag = obj;}97 public Object getTag() { return tag;}98 85 } -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/EvaluatorTask.java
r703 r729 34 34 35 35 public EvaluatorTask(CompilationUnit prog, boolean tests, 36 List<String> args_, BaseTask parent) { 37 super(parent); 36 List<String> args_) { 38 37 p = prog; 39 38 runTests = tests; … … 46 45 47 46 public void compute() { 48 initTask(); 47 FortressTaskRunner runner = (FortressTaskRunner) Thread.currentThread(); 48 runner.setCurrentTask(this); 49 49 try { 50 50 Driver.runProgramTask(p, runTests, args); … … 53 53 causedException = true; 54 54 err = e; 55 //System.err.println("\nGot exception:\n" + e);56 e.printStackTrace();55 e.printStackTrace(); 56 throw new RuntimeException(e); 57 57 } 58 finalizeTask();59 58 } 60 61 59 } 62 60 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/FortressTaskRunner.java
r711 r729 52 52 public static long totalTotalMemRefs = 0; 53 53 54 static ThreadLocal<ThreadState> _threadState = new ThreadLocal<ThreadState>() {55 protected synchronized ThreadState initialValue() {56 return new ThreadState();57 58 }59 };60 static ThreadLocal<Thread> _thread = new ThreadLocal<Thread>() {61 protected synchronized Thread initialValue() {62 return null;63 }64 };65 66 54 private static int MAX_NESTING_DEPTH = 100; 67 55 … … 71 59 72 60 public BaseTask getCurrentTask() {return currentTask;} 73 public void setCurrentTask(BaseTask task) {currentTask = task;} 61 62 public void setCurrentTask(BaseTask task) { 63 currentTask = task; 64 } 74 65 75 66 public FortressTaskRunner(FortressTaskRunnerGroup group) { … … 117 108 */ 118 109 static public boolean validate() { 119 ThreadState threadState = _threadState.get();110 ThreadState threadState = BaseTask.getThreadState(); 120 111 return threadState.validate(); 121 112 } … … 128 119 */ 129 120 static public Transaction getTransaction() { 130 return _threadState.get().transaction; 121 ThreadState threadState = BaseTask.getThreadState(); 122 return threadState.transaction(); 131 123 } 132 124 … … 137 129 */ 138 130 static public ContentionManager getContentionManager() { 139 return _threadState.get().manager; 131 ThreadState threadState = BaseTask.getThreadState(); 132 return threadState.manager(); 140 133 } 141 134 … … 146 139 */ 147 140 public static <T> T doIt(Callable<T> xaction) { 148 ThreadState threadState = _threadState.get();149 ContentionManager manager = threadState.manager ;141 ThreadState threadState = BaseTask.getThreadState(); 142 ContentionManager manager = threadState.manager(); 150 143 T result = null; 151 144 try { … … 167 160 throw new PanicException("Error " + e); 168 161 } 169 threadState.totalMemRefs += threadState.transaction.memRefs;162 threadState.addToTotalMemRefs(threadState.memRefs()); 170 163 if (threadState.commitTransaction()) { 171 threadState. committedMemRefs += threadState.transaction.memRefs;164 threadState.addToCommittedMemRefs(threadState.memRefs()); 172 165 return result; 173 166 } 174 threadState. transaction.attempts++;167 threadState.incAttempts(); 175 168 // transaction aborted 176 169 } … … 221 214 */ 222 215 public static void onValidate(Callable<Boolean> c) { 223 _threadState.get().onValidate.add(c); 216 ThreadState threadState = BaseTask.getThreadState(); 217 threadState.onValidate.add(c); 224 218 } 225 219 /** … … 228 222 */ 229 223 public static void onValidateOnce(Callable<Boolean> c) { 230 _threadState.get().onValidateOnce.add(c); 224 ThreadState threadState = BaseTask.getThreadState(); 225 threadState.onValidateOnce.add(c); 231 226 } 232 227 /** … … 235 230 */ 236 231 public static void onBegin(Runnable r) { 237 _threadState.get().onBegin.add(r); 232 ThreadState threadState = BaseTask.getThreadState(); 233 threadState.onBegin.add(r); 238 234 } 239 235 /** … … 242 238 */ 243 239 public static void onBeginOnce(Runnable r) { 244 _threadState.get().onBeginOnce.add(r); 240 ThreadState threadState = BaseTask.getThreadState(); 241 threadState.onBeginOnce.add(r); 245 242 } 246 243 /** … … 249 246 */ 250 247 public static void onCommit(Runnable r) { 251 _threadState.get().onCommit.add(r); 248 ThreadState threadState = BaseTask.getThreadState(); 249 threadState.onCommit.add(r); 252 250 } 253 251 /** … … 256 254 */ 257 255 public static void onCommitOnce(Runnable r) { 258 _threadState.get().onCommitOnce.add(r); 256 ThreadState threadState = BaseTask.getThreadState(); 257 threadState.onCommitOnce.add(r); 259 258 } 260 259 /** … … 263 262 */ 264 263 public static void onAbort(Runnable r) { 265 _threadState.get().onAbort.add(r); 264 ThreadState threadState = BaseTask.getThreadState(); 265 threadState.onAbort.add(r); 266 266 } 267 267 /** … … 270 270 */ 271 271 public static void onAbortOnce(Runnable r) { 272 _threadState.get().onAbortOnce.add(r); 272 ThreadState threadState = BaseTask.getThreadState(); 273 threadState.onAbortOnce.add(r); 273 274 } 274 275 /** … … 277 278 */ 278 279 public static int getID() { 279 return _threadState.get().hashCode(); 280 ThreadState threadState = BaseTask.getThreadState(); 281 return threadState.hashCode(); 280 282 } 281 283 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/SpawnTask.java
r703 r729 35 35 36 36 public void compute() { 37 initTask(); 38 try { 39 val = new Evaluator(eval, expr).eval(expr); 40 } 41 catch (Throwable e) { 42 causedException = true; 43 err = e; 44 } 45 finalizeTask(); 37 FortressTaskRunner runner = (FortressTaskRunner) Thread.currentThread(); 38 runner.setCurrentTask(this); 39 val = new Evaluator(eval, expr).eval(expr); 46 40 } 47 41 48 public SpawnTask(Expr b, Evaluator e, BaseTask task) { 49 super(task); 42 public SpawnTask(Expr b, Evaluator e) { 50 43 expr = b; 51 44 eval = e; -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/ThreadState.java
r609 r729 31 31 ContentionManager manager; 32 32 33 publiclong committed = 0; // number of committed transactions34 publiclong total = 0; // total number of transactions35 publiclong committedMemRefs = 0; // number of committed reads and writes36 publiclong totalMemRefs = 0; // total number of reads and writes33 long committed = 0; // number of committed transactions 34 long total = 0; // total number of transactions 35 long committedMemRefs = 0; // number of committed reads and writes 36 long totalMemRefs = 0; // total number of reads and writes 37 37 38 38 Set<Callable<Boolean>> onValidate = new HashSet<Callable<Boolean>>(); … … 59 59 } 60 60 } 61 62 /* Are we in a transaction? */ 63 public int transactionNesting() { return depth;} 61 64 62 65 /** … … 69 72 totalMemRefs = 0; // total number of reads and writes 70 73 } 74 75 public void incCommitted(int num) { committed += num;} 76 public void incTotal(int num) {total+= num;} 77 public void incCommittedMemRefs(int num) { committedMemRefs += num;} 78 public void incTotalMemRefs(int num) {totalMemRefs += num;} 71 79 72 80 /** … … 81 89 "]"; 82 90 } 83 91 92 public Transaction transaction() { return transaction;} 93 public ContentionManager manager() { return manager;} 94 public void addToTotalMemRefs(long num) { totalMemRefs += num;} 95 public long memRefs() { return totalMemRefs;} 96 public void addToCommittedMemRefs(long num) { committedMemRefs += num;} 97 public long commitedMemRefs() { return committedMemRefs;} 98 public void incAttempts() { transaction.attempts++;} 99 public long attempts() { return transaction.attempts;} 100 84 101 /** 85 102 * Can this transaction still commit? -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/tasks/TupleTask.java
r703 r729 31 31 FValue res; 32 32 33 public TupleTask(Expr ex, Evaluator ev, BaseTask parent) { 34 super(parent); 33 public TupleTask(Expr ex, Evaluator ev) { 35 34 expr = ex; 36 35 eval = ev; … … 38 37 39 38 public void compute() { 40 initTask(); 41 try { 42 res = new Evaluator(eval, expr).eval(expr); 43 } 44 catch (Throwable e) { 45 causedException = true; 46 err = e; 47 } 48 finalizeTask(); 39 FortressTaskRunner runner = (FortressTaskRunner) Thread.currentThread(); 40 runner.setCurrentTask(this); 41 res = new Evaluator(eval, expr).eval(expr); 49 42 } 50 43 -
trunk/ProjectFortress/src/com/sun/fortress/interpreter/evaluator/values/FThread.java
r593 r729 33 33 34 34 public FThread(Expr b, Evaluator e) { 35 st = new SpawnTask(b,e , BaseTask.getCurrentTask());35 st = new SpawnTask(b,e); 36 36 } 37 37

