Search in sources :

Example 11 with BProgramSyncSnapshot

use of il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot in project BPjs by bThink-BGU.

the class BProgramSyncSnapshotIO method deserialize.

public BProgramSyncSnapshot deserialize(byte[] bytes) throws IOException, ClassNotFoundException {
    try {
        Context ctxt = ContextFactory.getGlobal().enterContext();
        // must use interpreter mode
        ctxt.setOptimizationLevel(-1);
        final ScriptableObject globalScope = ctxt.initStandardObjects();
        try (ScriptableInputStream sis = new ScriptableInputStream(new ByteArrayInputStream(bytes), globalScope)) {
            Header header = (Header) sis.readObject();
            Set<BThreadSyncSnapshot> bthreads = new HashSet<>(header.bthreadCount);
            for (int i = 0; i < header.bthreadCount; i++) {
                bthreads.add(readBThreadSnapshot(sis, globalScope));
            }
            List<BEvent> events = new ArrayList<>(header.externalEventCount);
            for (int i = 0; i < header.externalEventCount; i++) {
                events.add((BEvent) sis.readObject());
            }
            return new BProgramSyncSnapshot(bprogram, bthreads, events, header.fa);
        }
    } finally {
        Context.exit();
    }
}
Also used : Context(org.mozilla.javascript.Context) ScriptableObject(org.mozilla.javascript.ScriptableObject) ScriptableInputStream(org.mozilla.javascript.serialize.ScriptableInputStream) ArrayList(java.util.ArrayList) ByteArrayInputStream(java.io.ByteArrayInputStream) BEvent(il.ac.bgu.cs.bp.bpjs.model.BEvent) BProgramSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot) BThreadSyncSnapshot(il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot) HashSet(java.util.HashSet)

Aggregations

BProgramSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot)11 BProgram (il.ac.bgu.cs.bp.bpjs.model.BProgram)10 BThreadSyncSnapshot (il.ac.bgu.cs.bp.bpjs.model.BThreadSyncSnapshot)9 StringBProgram (il.ac.bgu.cs.bp.bpjs.model.StringBProgram)8 Test (org.junit.Test)8 NativeContinuation (org.mozilla.javascript.NativeContinuation)7 BEvent (il.ac.bgu.cs.bp.bpjs.model.BEvent)5 ExecutorServiceMaker (il.ac.bgu.cs.bp.bpjs.internal.ExecutorServiceMaker)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 Context (org.mozilla.javascript.Context)2 ScriptableInputStream (org.mozilla.javascript.serialize.ScriptableInputStream)2 DfsBProgramVerifier (il.ac.bgu.cs.bp.bpjs.analysis.DfsBProgramVerifier)1 VerificationResult (il.ac.bgu.cs.bp.bpjs.analysis.VerificationResult)1 BProgramRunner (il.ac.bgu.cs.bp.bpjs.execution.BProgramRunner)1 BProgramJsProxy (il.ac.bgu.cs.bp.bpjs.execution.jsproxy.BProgramJsProxy)1 BProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.BProgramRunnerListener)1 InMemoryEventLoggingListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.InMemoryEventLoggingListener)1 PrintBProgramRunnerListener (il.ac.bgu.cs.bp.bpjs.execution.listeners.PrintBProgramRunnerListener)1