Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change DEFAULT_PRIORITY of Prioritized event selection strategies #147

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/main/java/il/ac/bgu/cs/bp/bpjs/internal/ScriptableUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,31 +241,30 @@ public static int jsColHashCode( Iterable<?> aSet ) {
}

/**
* A problematic-yet-working way of getting a meanningful toString
* A problematic-yet-working way of getting a meaningful toString
* on a NativeSet.
* @param ns
* @return a textual description of {@code ns}.
*/
private static String toString(NativeSet ns) {

String code = "const arr=[]; ns.forEach(e=>arr.push(e)); arr";

try {
Context curCtx = Context.enter();
curCtx.setLanguageVersion(Context.VERSION_ES6);
ImporterTopLevel importer = new ImporterTopLevel(curCtx);
Scriptable tlScope = curCtx.initStandardObjects(importer);
ImporterTopLevel tlScope = new ImporterTopLevel(curCtx);
tlScope.put("ns", tlScope, ns);
Object resultObj = curCtx.evaluateString(
tlScope, code,
tlScope, code,
"", 1, null);

NativeArray arr = (NativeArray) resultObj;
return arr.getIndexIds().stream().map( id -> stringify(arr.get(id), true) ).collect(joining(", "));

} finally {
Context.exit();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
*/
public class PrioritizedBSyncEventSelectionStrategy extends AbstractEventSelectionStrategy {

public static final int DEFAULT_PRIORITY = 0;

public PrioritizedBSyncEventSelectionStrategy(long seed) {
super(seed);
}
Expand Down Expand Up @@ -94,7 +96,7 @@ public Set<BEvent> selectableEvents(BProgramSyncSnapshot bpss) {

private int getValue( SyncStatement stmt ) {
return (stmt.hasData() && (stmt.getData() instanceof Number))?
((Number)stmt.getData()).intValue() : Integer.MIN_VALUE;
((Number)stmt.getData()).intValue() : DEFAULT_PRIORITY;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
*/
public class PrioritizedBThreadsEventSelectionStrategy extends AbstractEventSelectionStrategy {

public static final int DEFAULT_PRIORITY = -1;
public static final int DEFAULT_PRIORITY = 0;

/** A mapping of b-thread names to their priorities. */
final private Map<String, Integer> priorities = new HashMap<>();
Expand Down