Scala如何生成字节码?使用某些库(例如ASM)还是直接编写二进制文件? [英] How is scala generating byte code? Using some libraries like ASM, or write binary directly?

查看:265
本文介绍了Scala如何生成字节码?使用某些库(例如ASM)还是直接编写二进制文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道scala是如何生成字节码的,它是否使用了诸如ASM之类的某些库?还是只是将二进制文件写入.class文件以提高性能?

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?

推荐答案

从2.10开始,Scala编译器使用ASM 4发出字节码,支持-target:jvm-1.5,-target:jvm-1.6和-target:jvm -1.7

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:

  • Emitting Scala classfiles via ASM http://lamp.epfl.ch/~magarcia/ScalaCompilerCornerReloaded/2012Q2/GenASM.pdf

字节码发射器(GenASM,下面链接的源)访问由上一个阶段构建的控制流图(CFG),并使用Streaming ASM API直接发射类文件:

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

这就是现在的工作方式.在实验可能性方面,我一直在研究发出更快的实验字节码,部分原因是它跳过了构建CFG并直接访问Scala抽象语法树的过程(然后使用Tree ASM API在内存中构建类文件).详细信息:

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:

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

这篇关于Scala如何生成字节码?使用某些库(例如ASM)还是直接编写二进制文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆