Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
826 views
in Technique[技术] by (71.8m points)

jvm - How is scala generating byte code? Using some libraries like ASM, or write binary directly?

I'm wondering how is scala generating byte code, does it use some libraries like ASM? Or just write binary to .class files for performance?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Starting with 2.10 the Scala compiler uses ASM 4 to emit bytecode, supporting -target:jvm-1.5 , -target:jvm-1.6 , and -target:jvm-1.7

Implementation aspects of the backend are described in:

The bytecode emitter (GenASM, source linked below) visits a Control Flow Graph (CFG) built by a previous phase, and uses the Streaming ASM API to directly emit classfiles:

https://github.com/scala/scala/blob/master/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala

That's how things work now. In the realm of experimental possibilities, I've been working on an experimental bytecode emitted that is faster, in part because it skips building the CFG and visits Scala Abstract Syntax Trees directly (using then the Tree ASM API to build classfiles in memory). Details in:

https://github.com/magarciaEPFL/scala/blob/GenBCodeOpt/src/compiler/scala/tools/nsc/backend/jvm/GenBCode.scala


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...