Finally blocks are duplicated by the compiler, sim...
# compiler
y
Finally blocks are duplicated by the compiler, similar to what Java does, in at least 2 places (normal return, rethrown exception), but also sometimes more (
break
,
continue
, explicit
return
). Is there a conceivable way that the compiler could avoid such duplication? It results in some issues sometimes when combined with
inline
functions (because duplicating a big block is bad for bytecode size)
j
On native and JVM you could use a local integer to basically select the jump offset for once the instruction block which represents the
finally
completes.
y
I was thinking of that + some
Result<Any?>
local variable, but figured that I must be missing something? such a jump-table will be easy to optimize by further tools (like proguard or the JIT itself) no? I can't see why Java doesn't do it this way, but the problem is definitely more pronounced in Kotlin.
e
there used to be a java bytecode instruction
jsr
https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-3.html#jvms-3.13
it's not permitted in newer classfiles though
I think the extra complexity it added to the verifier was deemed not worth the code deduplication