清华大学软件学院编译原理课件

清华大学软件学院编译原理课件

ID:4147870

大小:461.59 KB

页数:30页

时间:2017-11-29

清华大学软件学院编译原理课件_第1页
清华大学软件学院编译原理课件_第2页
清华大学软件学院编译原理课件_第3页
清华大学软件学院编译原理课件_第4页
清华大学软件学院编译原理课件_第5页
资源描述:

《清华大学软件学院编译原理课件》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库

1、THSS341001622009/4301Chap.2JAVAC王朝坤chaokun@tsinghua.edu.cnOutlineTHSS341001622009/4301•ImplementationofJava•Bytecode•TheJavaClassfileformat•JVM•RelatedTools(demo)22.1Java的解释THSS341001622009/4301•Java语言的一种实现编译,没有绝对地址调入包含:继承所用到的所有类,内存分配确定等Java源程序Bytecode载入器(.java文件)限定对象存取权限Bytecode校验器预防系统堆栈溢出

2、Java编译器保持参数类型一致Bytecode解释器JavaBytecode程序执行系统(.class文件)系统平台3Java的实现THSS341001622009/4301•Java虚拟机不同的操作系统有不同的虚拟机.它类似一个小巧而高效的CPU.JavaJust-in-timebyte-code代码是与平台无关的interpretercompiler是虚拟机的机器指令.Java字节代码运行的几种方式:RuntimeSysteminterpreter(解释方式)Ahead-of-time(预先编译)Just-in-time(即时编译):由代码OperatingSystem生

3、成器将字节代码转换成本机的机器代码,然后可以以较高速度执行.HardwareDynamicAdaptiveCompiler(动态自适应编译)4JavaVirtualMachineFrameTHSS341001622009/4301•JVMisastack-basedmachine•EachthreadhasastackthatstoresframesJVMFrameTHSS341001622009/4301•Aframeiscreatedforeachmethodinvoked•Eachframehas:1.An“operandstack”tousetoexecuteinst

4、ructionsinthemethod,itssizeshouldbespecified2.Arrayoflocalvariablesthatactasregistersandtheirnumbershouldbefixedasthestartofthemethod3.Referencetotheconstantpoolofthecurrentclass4.Argumentsaresuppliedinthelocalvariablesarrayandtheirnumberisgiven(thisvariableisusuallyinposition0)2.2BytecodeT

5、HSS341001622009/4301classTest{publicintf(intx){inty=x*2;returny+x;}}UsingjavapTHSS341001622009/4301•javapisaprogramthatcangiveyouinformationon.classfiles.•Ifyougetaclassfilewithoutdocumentation,javapcantellyouwhatmethodsyoucancall.•javapcanshowyouhowjavaccompilesyourprogramintosimpleinstruc

6、tions.•Goodforhigh-performanceoptimizationsorifyoudon’thaveaccesstoanApplicationProgrammingInterface(API).BytecodeTHSS341001622009/4301classTest{publicintf(int);publicintf(intx){Code:inty=x*2;0:iload_1returny+x;1:iconst_2}2:imul}3:istore_24:iload_25:iload_16:iadd7:ireturnjavap–cTestJVMBytec

7、odeTHSS341001622009/4301•JVMloadsaclassfile:1streamofbytecodesforeachmethod•Aninstructionis1-byteopcodefollowedby0ormoreoperands•Eachtypeofopcodehasamnemonic•Thebytecodeinstructionsetwasdesignedtobecompact•256bytecodeinstructions(0~255)•Thetotalnumberofo

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。