Skip to content

Commit

Permalink
Multiple changes an build fix. Closes #131, closes #132, closes #135, c…
Browse files Browse the repository at this point in the history
…loses #137.
  • Loading branch information
michbarsinai committed Jan 3, 2021
1 parent a28ff6e commit 7669fa6
Show file tree
Hide file tree
Showing 18 changed files with 419 additions and 150 deletions.
59 changes: 7 additions & 52 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,61 +44,16 @@ a link to this page somewhere in the documentation/system about section.

## Change Log for the BPjs Library.

### 2020-12-06
* :sparkles: BProgram data storage ready (closes[#123](https://github.com/bThink-BGU/BPjs/issues/123)).
### 2021-01

### 2020-12-04
* :bug: Forking now handles b-thread data properly.
* :arrow_up: Logging now allows formatting, using Java's MessageFormat.
* :arrow_up: Expressive `toString` on JavaScript sets ([#135](https://github.com/bThink-BGU/BPjs/issues/135)).
* :arrow_up: Improved logging consistency ([#132](https://github.com/bThink-BGU/BPjs/issues/132)).
* :bug: Fixed the note color issue in the documentation ([#137](https://github.com/bThink-BGU/BPjs/issues/137)).
* :arrow_up: Error messages when passing non-events to a synchronization statement are more informative (([#131](https://github.com/bThink-BGU/BPjs/issues/131)).

### 2020-11-15
* :sparkles: A B-Program can have multiple b-threads with the same name (closes[#112](https://github.com/bThink-BGU/BPjs/issues/112)).

### 2020-11-09
* :arrow_up: Trace's `getLastEvent` now return an `Optional<Event>` rather than an `Event`. This is because some traces may not have a last event (part of the fix to [#122](https://github.com/bThink-BGU/BPjs/issues/122)).

### 2020-10-20
* :arrows_counterclockwise: `BEvent::toString` is more JS-like.

### 2020-10-10
* :arrows_counterclockwise: Internal refactorings.
* :bug: JavaScript errors (regarding syntax and references) are reported, and halt both execution and analysis [#94](https://github.com/bThink-BGU/BPjs/issues/94).


### 2020-09-23
* :tada: B-Threads have a data object, available to b-thread code via `bp.thread.data`. This object can be set, updated, and
replaced during execution. It can also be pre-set on b-thread creation [#106](https://github.com/bThink-BGU/BPjs/issues/106).
* :sparkles: DFS scan that uses forgetful state storage is not resilient to cyclic state graphs [#95](https://github.com/bThink-BGU/BPjs/issues/95).

### 2020-09-22
* :arrow_up: Added a b-thread name for the self-blocking warning [#103](https://github.com/bThink-BGU/BPjs/issues/103).
* :arrow_up: Logging supports compound objects [#102](https://github.com/bThink-BGU/BPjs/issues/102).
* :sparkles: B-thread name is available to JavaScript code.
* :bug: All JS code is evaluated as ES6 (formerly, evaluations where optimized ES1.8).
* :bug: Improved self-blocking warning logic.

### 2020-08-10
* :put_litter_in_its_place: Unification of some simple event sets, e.g. `[es1]` is identical to `es1`, `[]` to `bp.none`, etc.
* :put_litter_in_its_place: Removed some printouts.

### 2020-08-09
* :arrow_up: Updated to use Rhino 1.7.13
* :arrow_up: Updated to Java 11
* :sparkles: A new type of violation: hot run, which looks at hot runs of a subset of a b-program b-threads.
Previously, BPjs supported all b-threads ("hot system run") or just a single one ("hot b-thread run").
* :part_alternation_mark: Liveness verification parts now aligned semantically with current theory.
* :put_litter_in_its_place: Code and documentation clean-ups.

### 2020-04-22
* :arrow_up: Updated to use Rhino 1.7.12
* :arrow_up: :tada: Can use ES6 syntax, such as `let` and `const`.
* No arrow functions yet, there are some issues with continuations and arrow functions.
* :arrow_up: Synchronization statements are created more efficiently.
* :bug: `ComposableEventSet` checks arguments on creation, so that it can't be instantiated with `null` events (this later causes NPEs).
* :bug: `PrioritizedBThread` ESS fixed ([#70](https://github.com/bThink-BGU/BPjs/issues/70).
* :put_litter_in_its_place: Various small code clean-ups.
* :put_litter_in_its_place: Removed extraneous dependencies from `pom.xml`

[Earlier Changes](changelog-2019.md)
[Earlier Changes](changelog-2020.md)

Legend:
* :arrows_counterclockwise: Change
Expand Down
66 changes: 66 additions & 0 deletions changelog-2020.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Changelog for 2020

### 2020-12-06
* :sparkles: BProgram data storage ready (closes[#123](https://github.com/bThink-BGU/BPjs/issues/123)).

### 2020-12-04
* :bug: Forking now handles b-thread data properly.

### 2020-11-15
* :sparkles: A B-Program can have multiple b-threads with the same name (closes[#112](https://github.com/bThink-BGU/BPjs/issues/112)).

### 2020-11-09
* :arrow_up: Trace's `getLastEvent` now return an `Optional<Event>` rather than an `Event`. This is because some traces may not have a last event (part of the fix to [#122](https://github.com/bThink-BGU/BPjs/issues/122)).

### 2020-10-20
* :arrows_counterclockwise: `BEvent::toString` is more JS-like.

### 2020-10-10
* :arrows_counterclockwise: Internal refactorings.
* :bug: JavaScript errors (regarding syntax and references) are reported, and halt both execution and analysis [#94](https://github.com/bThink-BGU/BPjs/issues/94).


### 2020-09-23
* :tada: B-Threads have a data object, available to b-thread code via `bp.thread.data`. This object can be set, updated, and
replaced during execution. It can also be pre-set on b-thread creation [#106](https://github.com/bThink-BGU/BPjs/issues/106).
* :sparkles: DFS scan that uses forgetful state storage is not resilient to cyclic state graphs [#95](https://github.com/bThink-BGU/BPjs/issues/95).

### 2020-09-22
* :arrow_up: Added a b-thread name for the self-blocking warning [#103](https://github.com/bThink-BGU/BPjs/issues/103).
* :arrow_up: Logging supports compound objects [#102](https://github.com/bThink-BGU/BPjs/issues/102).
* :sparkles: B-thread name is available to JavaScript code.
* :bug: All JS code is evaluated as ES6 (formerly, evaluations where optimized ES1.8).
* :bug: Improved self-blocking warning logic.

### 2020-08-10
* :put_litter_in_its_place: Unification of some simple event sets, e.g. `[es1]` is identical to `es1`, `[]` to `bp.none`, etc.
* :put_litter_in_its_place: Removed some printouts.

### 2020-08-09
* :arrow_up: Updated to use Rhino 1.7.13
* :arrow_up: Updated to Java 11
* :sparkles: A new type of violation: hot run, which looks at hot runs of a subset of a b-program b-threads.
Previously, BPjs supported all b-threads ("hot system run") or just a single one ("hot b-thread run").
* :part_alternation_mark: Liveness verification parts now aligned semantically with current theory.
* :put_litter_in_its_place: Code and documentation clean-ups.

### 2020-04-22
* :arrow_up: Updated to use Rhino 1.7.12
* :arrow_up: :tada: Can use ES6 syntax, such as `let` and `const`.
* No arrow functions yet, there are some issues with continuations and arrow functions.
* :arrow_up: Synchronization statements are created more efficiently.
* :bug: `ComposableEventSet` checks arguments on creation, so that it can't be instantiated with `null` events (this later causes NPEs).
* :bug: `PrioritizedBThread` ESS fixed ([#70](https://github.com/bThink-BGU/BPjs/issues/70).
* :put_litter_in_its_place: Various small code clean-ups.
* :put_litter_in_its_place: Removed extraneous dependencies from `pom.xml`

[Earlier Changes](changelog-2019.md)

Legend:
* :arrows_counterclockwise: Change
* :sparkles: New feature
* :tada: New feature, but more exciting
* :part_alternation_mark: Refactor (turns out this sign is called "part alternation mark" and not "weird 'M'", so it fits).
* :put_litter_in_its_place: Deprecation
* :arrow_up: Upgrade
* :bug: Bug fix
11 changes: 11 additions & 0 deletions docs/source/BPjsTutorial/code/logging-with-data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const obj = {hello: "World", idioms:["request","waitFor","block"]};
const stuff = new Set();
stuff.add("thing 1");
stuff.add("thing 2");
stuff.add("thing 42");

bp.log.info("Here is field hello: {0} of object {1}", obj.hello, obj);
bp.log.info("Here is are some {1}: {0}", stuff, "stuff");

bp.log.info("I have a {0,number} reasons to block this event.", 1000000);
bp.log.info("{0} {0,number,#.##} {0,number,#.####}", 3.14159);
4 changes: 2 additions & 2 deletions docs/source/BPjsTutorial/code/logging.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
bp.log.info("registering bthreads - start");
bp.log.info("registering b-threads - start");
var LOG_LEVELS = ["Fine", "Info", "Warn", "Off"];

bp.registerBThread( "event generator", function(){
Expand All @@ -19,4 +19,4 @@ bp.registerBThread( "event logging", function() {
}
})

bp.log.info("registering bthreads - done");
bp.log.info("registering b-threads - done");
23 changes: 19 additions & 4 deletions docs/source/BPjsTutorial/logging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ As our programs become more complex, some logging/``printf`` capabilities are ne

The "event generator" creates four events, one for each logging level. The "event logging" b-thread waits for all events (note the use of ``bp.all``), sets the logger level (line 14), and attempts to log in all three log methods (lines 15-17). Here is the program output. Note that after event 3, where the level is set to ``"Off"``, no messages are emitted at all.

.. code:: bash
.. code::
# [READ] /.../logging.js
[JS][Info] registering bthreads - start
[JS][Info] registering b-threads - start
-:BPjs Added event generator
-:BPjs Added event logging
[JS][Info] registering bthreads - done
[JS][Info] registering b-threads - done
# [ OK ] logging.js
---:BPjs Started
--:BPjs Event [BEvent name:event 0]
Expand All @@ -35,11 +35,26 @@ The "event generator" creates four events, one for each logging level. The "even
---:BPjs Ended
.. caution :: Later versions might integrate BPjs with a full-blown logging system, such as `logback`_ or `log4j2`_. Programs relying on the exact logging format may need to change once the logging is updated. If you need to write a program that relies on accurate interpretation a b-program life cycle and selected events, consider implementing a `BProgramRunnerListener`_.
Message Formatting
------------------

The BPjs logger formats messages using Java's `MessageFormat`_. Under the hood, JavaScript objects are printed using a special formatter, which gives more information that the default cryptic ``[object object]``. The code below contains some formatting examples:

.. caution :: Later versions might integrate BPjs with a full-blown logging system, such as `logback`_ or `log4j2`_. Programs relying on the exact logging format may need to change once the logging is updated. If you need to write a program that relies on accurate interpretation a b-program life cycle and selected events, consider implementing a `BProgramRunnerListener`_.
.. literalinclude:: code/logging-with-data.js
:linenos:
:language: javascript


.. code::
[BP][Info] Here is field hello: World of object {JS_Obj hello:"World", idioms:[JS_Array 0:"request" | 1:"waitFor" | 2:"block"]}
[BP][Info] Here is are some stuff: {JS_Set "thing 1", "thing 2", "thing 42"}
[BP][Info] I have a 1,000,000 reasons to block this event.
[BP][Info] 3.142 3.14 3.1416
.. _logback: https://logback.qos.ch
.. _log4j2: http://logging.apache.org/log4j/2.x/index.html
.. _BProgramRunnerListener: http://javadoc.io/page/com.github.bthink-bgu/BPjs/latest/il/ac/bgu/cs/bp/bpjs/execution/listeners/BProgramRunnerListener.html
.. _MessageFormat: https://docs.oracle.com/javase/8/docs/api/java/text/MessageFormat.html
4 changes: 2 additions & 2 deletions docs/source/_static/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ th {
}

.danger {
background-color: rgba(255,100,100,.8);
color: rgb(146, 146, 0);
background-color: rgba(255, 58, 58, 0.8);
color: rgb(255, 255, 0);
}

.admonition-todo {
Expand Down
63 changes: 32 additions & 31 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.github.bthink-bgu</groupId>
<artifactId>BPjs</artifactId>
<version>0.11.0</version>
<version>0.11.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>BPjs</name>
Expand Down Expand Up @@ -40,8 +40,9 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>11</java.version>
<exec.mainClass>il.ac.bgu.cs.bp.bpjs.mains.BPJsCliRunner</exec.mainClass>
<exec.mainClass>il.ac.bgu.cs.bp.bpjs.mains.BPjsCliRunner</exec.mainClass>
<javax.activation.version>1.2.0</javax.activation.version>
<jaxb.api.version>2.3.0</jaxb.api.version>
</properties>
Expand Down Expand Up @@ -112,42 +113,15 @@
<target>11</target>
</configuration>
</plugin>

<!-- Code Coverage -->
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- / Code Coverage -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<mainClass>il.ac.bgu.cs.bp.bpjs.mains.BPJsCliRunner</mainClass>
<mainClass>${project.properties.exec.mainClass}</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
</manifest>
</archive>
</configuration>
Expand All @@ -168,6 +142,33 @@
</execution>
</executions>
</plugin>
<!-- Code Coverage -->
<plugin>
<groupId>org.eluder.coveralls</groupId>
<artifactId>coveralls-maven-plugin</artifactId>
<version>4.3.0</version>
<dependencies>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.6</version>
<executions>
<execution>
<id>prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- / Code Coverage -->
</plugins>
</build>
<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import il.ac.bgu.cs.bp.bpjs.model.eventsets.JsEventSet;
import il.ac.bgu.cs.bp.bpjs.exceptions.BPjsRuntimeException;
import il.ac.bgu.cs.bp.bpjs.execution.tasks.FailedAssertionException;
import il.ac.bgu.cs.bp.bpjs.internal.ScriptableUtils;
import il.ac.bgu.cs.bp.bpjs.model.BProgramSyncSnapshot;
import il.ac.bgu.cs.bp.bpjs.model.SyncStatement;
import il.ac.bgu.cs.bp.bpjs.model.ForkStatement;
Expand Down Expand Up @@ -240,18 +241,22 @@ void synchronizationPoint( NativeObject jsRWB, Boolean hot, Object data ) {
}
Object req = jRWB.get("request");
if ( req != null ) {
if ( req instanceof BEvent ) {
stmt = stmt.request((BEvent)req);
} else if ( req instanceof NativeArray ) {
NativeArray arr = (NativeArray) req;
stmt = stmt.request(arr.getIndexIds().stream()
.map( i -> (BEvent)arr.get(i) )
.collect( toList() ));
}
try {
if ( req instanceof NativeArray ) {
NativeArray arr = (NativeArray) req;
stmt = stmt.request(arr.getIndexIds().stream()
.map( i -> (BEvent)arr.get(i) )
.collect( toList() ));
} else {
stmt = stmt.request((BEvent)req);
}
} catch (ClassCastException cce ) {
throw new BPjsRuntimeException("A non-event object requested in a sync statement. Offending object:'" + ScriptableUtils.stringify(req) + "'");
}
}

EventSet waitForSet = convertToEventSet(jRWB.get("waitFor"));
EventSet blockSet = convertToEventSet(jRWB.get("block"));
EventSet waitForSet = convertToEventSet(jRWB.get("waitFor"));
EventSet blockSet = convertToEventSet(jRWB.get("block"));
EventSet interruptSet = convertToEventSet(jRWB.get("interrupt"));
stmt = stmt.waitFor( waitForSet )
.block( blockSet )
Expand Down Expand Up @@ -284,8 +289,7 @@ private EventSet convertToEventSet( Object jsObject ) {
.collect( toSet() ) );
} else {
final String errorMessage = "Cannot convert " + jsObject + " of class " + jsObject.getClass() + " to an event set";
Logger.getLogger(BThreadSyncSnapshot.class.getName()).log(Level.SEVERE, errorMessage);
throw new IllegalArgumentException(errorMessage);
throw new BPjsRuntimeException(errorMessage);
}
}

Expand Down
Loading

0 comments on commit 7669fa6

Please sign in to comment.