1 / 19

Java Virtual Machine (JVM)

Java Virtual Machine (JVM). Reasons for learning JVM Resource The Java TM Virtual Machine Specification (2 nd Ed), by Tim Lindholm & Frank Yellin, Addison-Wesley,1999 http://java.sun.com/docs/books/vmspec/. JVM Types and Words.

mschwab mschwab
Download Presentation

Java Virtual Machine (JVM)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Java Virtual Machine (JVM) • Reasons for learning JVM • Resource • The Java TM Virtual Machine Specification (2 nd Ed), by Tim Lindholm & Frank Yellin, Addison-Wesley,1999http://java.sun.com/docs/books/vmspec/ by Neng-Fa Zhou

  2. JVM Types and Words • byte, char, short, int, float, reference, and returnAddress in one word • boolean, byte, char, and short are converted to int • Special representations for byte, char, and short arrays are possible • long and double in two words by Neng-Fa Zhou

  3. JVM Architecture PC Method area OPTOP Operand stack EP Environment Heap Local vars LVARS ….. Registers Stack by Neng-Fa Zhou

  4. Data Areas of JVM • Method area (shared by all threads) • One record for each loaded class that contains: • Constant pool • Code for methods and constructors • Heap (shared by all threads) • One record for each class instance or array • Stack (one per thread) • Hold frames associated with method invocations by Neng-Fa Zhou

  5. Stack Frame Structure Operand stack: Evaluate expressions Pass method arguments and receive results Local variables: Addressed as word offsets Constant pool: Dynamic linking Operand stack Environment Constant pool PC EP LVARSLocal variables by Neng-Fa Zhou

  6. The class File Format ClassFile {     u4 magic;     u2 minor_version;     u2 major_version;     u2 constant_pool_count;     cp_info constant_pool[constant_pool_count-1];     u2 access_flags;     u2 this_class;     u2 super_class;     u2 interfaces_count;     u2 interfaces[interfaces_count];     u2 fields_count;     field_info fields[fields_count];     u2 methods_count;     method_info methods[methods_count];     u2 attributes_count;     attribute_info attributes[attributes_count];     } by Neng-Fa Zhou

  7. Names and Descriptors • Class, method, and field names are all stored symbolically as strings • A descriptor is a string representing the type of a field or method • Class names • Class names are always fully qualified • Use forward slash rather than dot as the delimeter • Ex: Java.util.Vector =>java/util/Vector by Neng-Fa Zhou

  8. Descriptors • Primitive types • B, C, D, F, I,J(long), S, Z(boolean), V(void) • Arrays • Use [ • Classes • Lclassname • Ex: • Type:String valueOf(char[] , int offset, int count) • Descriptor:([CII)Ljava/lang/String; by Neng-Fa Zhou

  9. Constants • CONSTANT_Class • CONSTANT_Fieldref • CONSTANT_Methodref • CONSTANT_InterfaceMthodref • CONSTANT_String, • CONSTANT_Integer • CONSTANT_Float • CONSTANT_Long • CONSTANT_Double • CONSTANT_NameAndType • CONSTANT_Utf8 by Neng-Fa Zhou

  10. field_info Access flags Name Descriptor Static values method_info Access flags Name Descriptor Code field_info and method_info by Neng-Fa Zhou

  11. Instruction Set • Load and store (e.g., iload, istore ldc, iconst_<i>) • Arithmetic (e.g., iadd, isub, imul, idiv, irem) • Type conversion (e.g., i2b, i2f, i2d) • Object creation and manipulation(e.g, new, newarray, iaload, iastore , getfield, putfield) • Operand stack manipulation (e.g., pop, dup, dup_x1, swap) • Control transfer (e.g., goto, ifeq, tableswitch) • Method invocation and return (invokevirtual, invokeinterface, invokespecial, invokestatic, ireturn) • Exception handling and synchronization (e.g.,athrow) by Neng-Fa Zhou

  12. Compiling for JVMConstants, Local Variables, and Controlconstructs void spin() { int i; for (i = 0;i<100;i++) ; } Method void spin() 0 iconst_0 // Push int constant 0 1 istore_1 // Store into local variable 1 (i=0) 2 goto 8 // First time through don't increment 5 iinc 1 1 // Increment local variable 1 by 1 (i++) 8 iload_1 // Push local variable 1 (i) 9 bipush 100 // Push int constant 100 11 if_icmplt 5 // Compare and loop if less than (i < 100) 14 return // Return void when done by Neng-Fa Zhou

  13. Compiling for JVMReceiving Arguments and Invoking Methods int m1(int a1, int a2) { return m2(2,3,a1,a2);} Method int m1() 0 aload_0 // Push local variable 0 (this) 1 bipush 2 // Push int constant 2 3 bipush 3 // Push int constant 3 5 iload_1 // Push local var a16 iload_2 // Push local var a27 invokevirtual #4 // Method Example.m(IIII)I 10 ireturn // Return int on top of operand stack by Neng-Fa Zhou

  14. Compiling for JVMWorking with Class Instances MyObj example() { MyObj o = new MyObj(); return silly(o); } Method MyObj example() 0 new #2 // Class MyObj 3 dup 4 invokespecial #5 // Method MyObj.<init>()V 7 astore_1 8 aload_0 9 aload_1 10 invokevirtual #4 // Method Example.silly(LMyObj;)LMyObj; 13 areturn by Neng-Fa Zhou

  15. Compiling for JVMArrays Creating arrays Manupulating arrays int x[] = new int[3];0 iconst_31 newarray int3 astore_1 x[2] = 0;4 aload_1 5 iconst_2 6 iconst_0 7 iastore x[0] = x[2]; 8 aload_1 9 iconst_010 aload_111 iconst_2 12 iaload13 iastore by Neng-Fa Zhou

  16. Compiling for JVMSwitches Method int chooseNear(int) 0 iload_1 1 tableswitch 0 to 2: 0: 28 1: 30 2: 32 default:34 28 iconst_0 29 ireturn 30 iconst_1 31 ireturn 32 iconst_2 33 ireturn 34 iconst_m1 35 ireturn int chooseNear(int i) { switch (i) { case 0: return 0; case 1: return 1; case 2: return 2; default: return -1; } } by Neng-Fa Zhou

  17. Compiling for JVMManipulation of the Operand Stack public long nextIndex(){ return index++; } private long index = 0; Method long nextIndex() 0 aload_0 // Push this 1 dup // Make a copy of it 2 getfield #4 // One of the copies of this is consumed // pushing long field index, // above the original this 5 dup2_x1 // The long on top of the operand stack is // inserted into the operand stack below the // original this 6 lconst_1 // Push long constant 1 7 ladd // The index value is incremented... 8 putfield #4 // ...and the result stored back in the field 11 lreturn // The original value of index is left on // top of the operand stack, ready to be returned by Neng-Fa Zhou

  18. Compiling for JVMException Handling void catchOne() { try { tryItOut(); } catch (TestExc e) { handleExc(e); } } Method void catchOne() 0 aload_0 // Beginning of try block 1 invokevirtual #6 // Method Example.tryItOut()V 4 return // End of try block; normal return 5 astore_1 // Store thrown value in local var 1 6 aload_0 // Push this 7 aload_1 // Push thrown value 8 invokevirtual #5 // Invoke handler method: // Example.handleExc(LTestExc;)V 11 return // Return after handling TestExc Exception table: From To Target Type 0 4 5 Class TestExc by Neng-Fa Zhou

  19. Review Questions • Does the efficiency of a program change after an int variable is changed to byte? • When does dynamic loading take place? • When does dynamic linking take place? • Why are run-time byte-code verification and type checking necessary? • How are exceptions handled in JVM? • How different is the JVM from a stack machine for Pascal? by Neng-Fa Zhou

More Related

深圳SEO优化公司镇江营销网站推荐伊犁网站改版报价沧州SEO按效果付费推荐厦门模板推广报价淮北百度爱采购推荐许昌英文网站建设海南网络营销多少钱宿迁网站建设白城网站搜索优化哪家好马鞍山企业网站建设报价大浪网页制作多少钱梅州网站优化价格宝安营销型网站建设公司内江网站推广工具价格河源高端网站设计推荐安阳网站优化推广多少钱衢州网站优化按天扣费公司黄冈网站seo优化多少钱泸州网站优化推广塘坑百度竞价公司长春网站推广方案多少钱铜陵网站搭建价格邯郸品牌网站设计哪家好汕头网站设计模板昌都网站开发哪家好黄冈关键词排名多少钱济宁网页设计多少钱郴州百姓网标王推荐上海至尊标王多少钱盐田网站设计公司歼20紧急升空逼退外机英媒称团队夜以继日筹划王妃复出草木蔓发 春山在望成都发生巨响 当地回应60岁老人炒菠菜未焯水致肾病恶化男子涉嫌走私被判11年却一天牢没坐劳斯莱斯右转逼停直行车网传落水者说“没让你救”系谣言广东通报13岁男孩性侵女童不予立案贵州小伙回应在美国卖三蹦子火了淀粉肠小王子日销售额涨超10倍有个姐真把千机伞做出来了近3万元金手镯仅含足金十克呼北高速交通事故已致14人死亡杨洋拄拐现身医院国产伟哥去年销售近13亿男子给前妻转账 现任妻子起诉要回新基金只募集到26元还是员工自购男孩疑遭霸凌 家长讨说法被踢出群充个话费竟沦为间接洗钱工具新的一天从800个哈欠开始单亲妈妈陷入热恋 14岁儿子报警#春分立蛋大挑战#中国投资客涌入日本东京买房两大学生合买彩票中奖一人不认账新加坡主帅:唯一目标击败中国队月嫂回应掌掴婴儿是在赶虫子19岁小伙救下5人后溺亡 多方发声清明节放假3天调休1天张家界的山上“长”满了韩国人?开封王婆为何火了主播靠辱骂母亲走红被批捕封号代拍被何赛飞拿着魔杖追着打阿根廷将发行1万与2万面值的纸币库克现身上海为江西彩礼“减负”的“试婚人”因自嘲式简历走红的教授更新简介殡仪馆花卉高于市场价3倍还重复用网友称在豆瓣酱里吃出老鼠头315晚会后胖东来又人满为患了网友建议重庆地铁不准乘客携带菜筐特朗普谈“凯特王妃P图照”罗斯否认插足凯特王妃婚姻青海通报栏杆断裂小学生跌落住进ICU恒大被罚41.75亿到底怎么缴湖南一县政协主席疑涉刑案被控制茶百道就改标签日期致歉王树国3次鞠躬告别西交大师生张立群任西安交通大学校长杨倩无缘巴黎奥运

深圳SEO优化公司 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化