Skip to content

Commit

Permalink
ignore monitorenter and monitorexit from synchronized blocks. see #5
Browse files Browse the repository at this point in the history
  • Loading branch information
Horcrux7 committed Mar 10, 2019
1 parent cd729d1 commit 2e7370d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@ protected void writeBlockCode( @Nonnull WasmBlockOperator op, @Nullable Object d
codeStream.writeVaruint32( (Integer)data ); // break depth
codeStream.writeVaruint32( 0 ); // event/exception ever 0 because currently there is only one with signature anyref
break;
case MONITOR_ENTER:
case MONITOR_EXIT:
codeStream.writeOpCode( DROP );
break;
default:
throw new Error( "Unknown block: " + op );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,12 @@ private void writeCode( CodeInputStream byteCode, ConstantPool constantPool, boo
break;
//TODO case 192: // checkcast
//TODO case 193: // instanceof
//TODO case 194: // monitorenter
//TODO case 195: // monitorexit
case 194: // monitorenter
addBlockInstruction( WasmBlockOperator.MONITOR_ENTER, null, codePos );
break;
case 195: // monitorexit
addBlockInstruction( WasmBlockOperator.MONITOR_EXIT, null, codePos );
break;
//TODO case 196: // wide
//TODO case 197: // multianewarray
case 198: // ifnull
Expand Down
4 changes: 4 additions & 0 deletions src/de/inetsoftware/jwebassembly/text/TextModuleWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ protected void writeBlockCode( @Nonnull WasmBlockOperator op, @Nullable Object d
case BR_ON_EXN:
name = "br_on_exn " + data + " 0"; // br_on_exn, break depth, event; // currently there is only one event/exception with anyref
break;
case MONITOR_ENTER:
case MONITOR_EXIT:
name = "drop";
break;
default:
throw new Error( "Unknown block: " + op );
}
Expand Down
2 changes: 2 additions & 0 deletions src/de/inetsoftware/jwebassembly/wasm/WasmBlockOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,6 @@ public enum WasmBlockOperator {
THROW,
RETHROW,
BR_ON_EXN,
MONITOR_ENTER,
MONITOR_EXIT,
}
12 changes: 12 additions & 0 deletions test/de/inetsoftware/jwebassembly/runtime/Exceptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,18 @@ static int complex() {
private static int divNull() {
return 5 / 0;
}

// a synchronized also add an try/finally internally
@Export
static int sync() {
int v = 1;
Object monitor = new Object();
synchronized( monitor ) {
v++;
}
return v;
}

// @Export
// static int npe() {
// Object obj = new NullPointerException();
Expand Down

0 comments on commit 2e7370d

Please sign in to comment.