diff options
author | James Iry <jamesiry@gmail.com> | 2013-02-25 16:30:46 -0800 |
---|---|---|
committer | James Iry <jamesiry@gmail.com> | 2013-02-26 08:26:43 -0800 |
commit | 5f3cd8683d8b2e7429e73c2fa7199232ea7c46ca (patch) | |
tree | 276fcd18c0eb45639ff4c29cf3bffa23df0dada7 /src/compiler | |
parent | 28a716190c5faf549ed302a1c19d9611c32d2010 (diff) | |
download | scala-5f3cd8683d8b2e7429e73c2fa7199232ea7c46ca.tar.gz scala-5f3cd8683d8b2e7429e73c2fa7199232ea7c46ca.tar.bz2 scala-5f3cd8683d8b2e7429e73c2fa7199232ea7c46ca.zip |
SI-7181 Eliminate unnecessary duplication of finally blocks
The main body of a try and each exception handler were getting a copy of
the finally block for the "normal" flow case (i.e. where they don't
throw an uncaught exception or use "return" to exit early). But that's
not necessary.
With this commit the try body and each exception handler can all jump
to the same copy of the finally block on a normal exit.
A byte code test is included to ensure we're getting fewer copies of
the finally block.
inline-ex-handlers.check is updated because the icode is a bit different
without the extra finally block copies.
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/icode/GenICode.scala | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala index 8881650a81..5438fd8590 100644 --- a/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala +++ b/src/compiler/scala/tools/nsc/backend/icode/GenICode.scala @@ -1932,12 +1932,10 @@ abstract class GenICode extends SubComponent { * * body: * [ try body ] - * [ finally body ] * JUMP normalExit * * catch[i]: * [ handler[i] body ] - * [ finally body ] * JUMP normalExit * * catchAll: @@ -1946,6 +1944,7 @@ abstract class GenICode extends SubComponent { * THROW exception * * normalExit: + * [ finally body ] * * each catch[i] will cover body. catchAll will cover both body and each catch[i] * Additional finally copies are created on the emission of every RETURN in the try body and exception handlers. @@ -2012,9 +2011,7 @@ abstract class GenICode extends SubComponent { exhStartCtx.addFinalizer(finalizer, finalizerCtx) loadException(exhStartCtx, exh, tree.pos) val exhEndCtx = handler(exhStartCtx) - // emit finalizer - val exhEndCtx2 = emitFinalizer(exhEndCtx) - exhEndCtx2.bb.closeWith(JUMP(normalExitCtx.bb)) + exhEndCtx.bb.closeWith(JUMP(normalExitCtx.bb)) outerCtx.endHandler() } @@ -2022,14 +2019,13 @@ abstract class GenICode extends SubComponent { if (finalizer != EmptyTree) bodyCtx.addFinalizer(finalizer, finalizerCtx) - var bodyEndCtx = body(bodyCtx) - bodyEndCtx = emitFinalizer(bodyEndCtx) + val bodyEndCtx = body(bodyCtx) outerCtx.bb.closeWith(JUMP(bodyCtx.bb)) bodyEndCtx.bb.closeWith(JUMP(normalExitCtx.bb)) - normalExitCtx + emitFinalizer(normalExitCtx) } } } |