Proposal: Block Expressions for Java
Neal Gafter
neal at gafter.com
Mon Mar 2 23:43:27 PST 2009
On Mon, Mar 2, 2009 at 9:46 PM, Joseph D. Darcy <Joe.Darcy at sun.com> wrote:
>> Meaning of Expressions: The specification for a parenthesized
>> expression should be modified to describe its new execution semantics:
>> The block statements (if any) are executed in sequence, from left to
>> right, exactly as in a block statement. The result of the
>> parenthesized expression is the result of evaluating its
>> subexpression.
>>
>
> So what about return, break, and continue statements inside the
> BlockStatements?
They behave as already specified in the JLS.
>> Compilation is straightforward, with one minor exception (no pun
>> intended). The compiler must arrange the generated code such that the
>> stack is empty at the beginning of any try statement that can complete
>> normally when the try statement is embedded within a parenthesized
>> expression. That is because the VM empties the stack when exceptions
>> are handled. This can be accommodated by spilling values from the
>> stack into VM locals.
>>
>
> That doesn't necessarily sound minor!
It is because (1) it will be extremely rare in practice, and (2) even
when it happens, the number of additional bytecodes to spill and
unspill the registers is small. I prototyped something close to this
spilling strategy when I implemented stackmaps: I added an option that
causes the stack to be empty at every basic block boundary (which in
expressions occurs because of ?:). It caused an additional fraction
of a percent in code size. This would have an even smaller impact.
More information about the coin-dev
mailing list