use of abs.backend.java.lib.runtime.ABSException in project abstools by abstools.
the class JavaBackendTest method assertValidJavaExecution.
void assertValidJavaExecution(boolean withStdLib, String... codeLines) throws Exception {
StringBuilder absCode = new StringBuilder();
for (String line : codeLines) {
absCode.append(line);
absCode.append("\n");
}
JavaCode javaCode = getJavaCode(absCode.toString(), withStdLib ? Config.WITH_STD_LIB : null);
try {
String genDir = javaCode.getSrcDir().getAbsolutePath() + "/gen/test";
javaCode.compile("-classpath", "bin", "-d", genDir);
final ABSRuntime r = makeAbsRuntime();
r.enableDebugging(true);
final boolean[] finished = new boolean[] { false };
final List<ABSException> exceptions = Collections.synchronizedList(new ArrayList<ABSException>());
r.addSystemObserver(new SystemObserver() {
@Override
public void systemStarted() {
}
@Override
public void systemFinished() {
synchronized (finished) {
finished[0] = true;
finished.notifyAll();
}
}
@Override
public void systemError(ABSException e) {
exceptions.add(e);
}
@Override
public void newCOGCreated(COGView cog, ObjectView initialObject) {
}
});
r.start(new File(genDir), "Test.Main");
while (!finished[0]) {
synchronized (finished) {
finished.wait(100);
}
}
r.shutdown();
for (ABSException e : exceptions) {
throw e;
}
} catch (Exception e) {
System.out.println(javaCode);
throw e;
} finally {
javaCode.deleteCode();
}
}
use of abs.backend.java.lib.runtime.ABSException in project abstools by abstools.
the class DebugModel method taskFinished.
@Override
public synchronized void taskFinished(TaskView task) {
TaskState newState = TaskState.FINISHED;
if (task.hasException()) {
ABSException e = task.getException();
if (e.isAssertion()) {
newState = TaskState.ASSERTION_FAILED;
} else {
newState = TaskState.EXCEPTION;
}
}
updateTaskState(task, newState, null, null);
}
use of abs.backend.java.lib.runtime.ABSException in project abstools by abstools.
the class GlobalScheduler method doNextScheduleStep.
public void doNextScheduleStep() {
if (isShutdown)
return;
int i = counter.incrementAndGet();
logger.finest("===" + i + ": Do next step...");
ScheduleAction next = null;
synchronized (this) {
if (nextStepWaitStack.size() > 0) {
SimpleLock l = nextStepWaitStack.remove(nextStepWaitStack.size() - 1);
logger.finest("===" + i + ": Ignored step, awaking thread ");
l.unlock();
return;
}
if (options.isEmpty()) {
List<SimpleSchedulerThread> activeThreads = runtime.getThreadManager().getAllCopyOf(SimpleSchedulerThread.class);
if (!activeThreads.isEmpty()) {
Set<Task<?>> suspendedTasks = new HashSet<>();
for (SimpleSchedulerThread st : activeThreads) {
Task<?> t = st.getExecutingTask().task;
if (t != null && !t.isFinished()) {
suspendedTasks.add(t);
}
}
// Need to filter out currentTask (that is finishing)
Thread tt = Thread.currentThread();
if (tt instanceof SimpleSchedulerThread) {
Task<?> currT = ((SimpleSchedulerThread) tt).getExecutingTask().task;
suspendedTasks.remove(currT);
}
if (!suspendedTasks.isEmpty()) {
ABSException ex = new ABSDeadlockException();
for (Task<?> t : suspendedTasks) {
t.setException(ex);
}
runtime.handleABSException(suspendedTasks.iterator().next(), ex);
return;
}
}
logger.info("No steps left. Program finished");
logger.info("Total number of global choices: " + totalNumChoices);
if (totalNumChoices == 0) {
logger.info("Program is deterministic!");
}
return;
}
totalNumChoices += options.numOptions() - 1;
logger.finest("===" + i + " Choose next action...");
next = strategy.choose(options);
logger.finest("===" + i + " Action " + next + " choosen");
options.removeOption(next);
logger.finest("===" + i + " Executing Action " + next);
}
if (isShutdown)
return;
int j = counter.intValue();
if (i != j)
logger.warning("#### Interleaving detected " + i + " != " + j);
next.execute();
logger.finest("===" + i + " Action " + next + " was executed.");
}
Aggregations