Search in sources :

Example 1 with ABSException

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();
    }
}
Also used : COGView(abs.backend.java.observing.COGView) SystemObserver(abs.backend.java.observing.SystemObserver) JavaCode(abs.backend.java.codegeneration.JavaCode) ObjectView(abs.backend.java.observing.ObjectView) JavaCodeGenerationException(abs.backend.java.codegeneration.JavaCodeGenerationException) ABSException(abs.backend.java.lib.runtime.ABSException) ABSRuntime(abs.backend.java.lib.runtime.ABSRuntime) ABSException(abs.backend.java.lib.runtime.ABSException)

Example 2 with ABSException

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);
}
Also used : ABSException(abs.backend.java.lib.runtime.ABSException)

Example 3 with ABSException

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.");
}
Also used : Task(abs.backend.java.lib.runtime.Task) ABSDeadlockException(abs.backend.java.lib.runtime.ABSDeadlockException) SimpleSchedulerThread(abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread) HashSet(java.util.HashSet) SimpleSchedulerThread(abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread) ABSException(abs.backend.java.lib.runtime.ABSException)

Aggregations

ABSException (abs.backend.java.lib.runtime.ABSException)3 JavaCode (abs.backend.java.codegeneration.JavaCode)1 JavaCodeGenerationException (abs.backend.java.codegeneration.JavaCodeGenerationException)1 ABSDeadlockException (abs.backend.java.lib.runtime.ABSDeadlockException)1 ABSRuntime (abs.backend.java.lib.runtime.ABSRuntime)1 Task (abs.backend.java.lib.runtime.Task)1 COGView (abs.backend.java.observing.COGView)1 ObjectView (abs.backend.java.observing.ObjectView)1 SystemObserver (abs.backend.java.observing.SystemObserver)1 SimpleSchedulerThread (abs.backend.java.scheduling.SimpleTaskScheduler.SimpleSchedulerThread)1 HashSet (java.util.HashSet)1