diff options
author | schinz <schinz@epfl.ch> | 2004-01-13 15:52:03 +0000 |
---|---|---|
committer | schinz <schinz@epfl.ch> | 2004-01-13 15:52:03 +0000 |
commit | 0362d6e25548f8f5c644af8eca34c6c7de47f246 (patch) | |
tree | c17cf1ba919cace5db522ebb2381ab7f79a4bbca | |
parent | 4464fd3c978ac87619c1c0d2181e1ba1bd353b1e (diff) | |
download | scala-0362d6e25548f8f5c644af8eca34c6c7de47f246.tar.gz scala-0362d6e25548f8f5c644af8eca34c6c7de47f246.tar.bz2 scala-0362d6e25548f8f5c644af8eca34c6c7de47f246.zip |
- finished implementation for "synchronized"
-rw-r--r-- | sources/scalac/backend/jvm/GenJVM.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/sources/scalac/backend/jvm/GenJVM.java b/sources/scalac/backend/jvm/GenJVM.java index c538755754..c7d4cad7ae 100644 --- a/sources/scalac/backend/jvm/GenJVM.java +++ b/sources/scalac/backend/jvm/GenJVM.java @@ -990,7 +990,8 @@ class GenJVM { } /** - * Generate code to throw the value returned by the argument. + * Generate code to synchronise on the object and evaluate the + * code fragment. */ protected void genSynchronized(Context ctx, Tree object, @@ -1003,9 +1004,21 @@ class GenJVM { ctx.code.emitSTORE(monitorVar); ctx.code.emitLOAD(monitorVar); ctx.code.emitMONITORENTER(); + int startPC = ctx.code.getPC(); genLoad(ctx, code, expectedType); + int endPC = ctx.code.getPC(); + ctx.code.emitLOAD(monitorVar); + ctx.code.emitMONITOREXIT(); + + JCode.Label afterLabel = ctx.code.newLabel(); + ctx.code.emitGOTO(afterLabel); + int handlerPC = ctx.code.getPC(); ctx.code.emitLOAD(monitorVar); ctx.code.emitMONITOREXIT(); + ctx.code.emitATHROW(); + afterLabel.anchorToNext(); + + ctx.code.addFinallyHandler(startPC, endPC, handlerPC); } /// Arrays |