24-JVM - 5/3/2011 1 CS/ENGRD 2110 Object-Oriented...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 5/3/2011 1 CS/ENGRD 2110 Object-Oriented Programming and Data Structures Spring 2011 Thorsten Joachims Lecture 24: Java Virtual Machine Compiling for Different Platforms Program written in some high-level language (C, Fortran, ML, ...) Compiled to intermediate form Optimized Code generated for various platforms (machine architecture + operating system) Consumers download code for their platform 2 Problem: Too Many Platforms! Operating systems DOS, Win95, 98, NT, ME, 2K, XP, Vista, ... Unix, Linux, FreeBSD, Aix, ... VM/CMS, OS/2, Solaris, Mac OS X, ... Processor Architectures Pentium, PowerPC, Alpha, SPARC, MIPS, ... 3 Compiling for Different Platforms 4 High-Level Program Intermediate-Level Program Compiler Code Gen 1 Code Gen 2 Code Gen 3 Windows Laptop Linux Server Toaster producer consumers Dream: Platform Independence Compiler produces one low-level program for all platforms (Bytecode) Low-level compiled form of Java Platform-independent Compact Suitable for mobile code, applets Easy to interpret Java virtual machine (JVM) in your browser Simple stack-based semantics Support for objects Executed on a virtual machine (VM) A different VM implementation needed for each platform, but installed once and for all 5 Java Platform Java Platform the Java programming language the Java Application Programming Interface the Java class file format the Java virtual machine 6 5/3/2011 2 Platform Independence with Java 7 Java Program Bytecode Program Compiler JVM Windows JVM Linux JVM ToastOS producer consumers Java Virtual Machines Platform Independence with Java 8 Java Program Bytecode Program Compiler JIT 1 JIT 2 JIT 3 Machine Code 1 Machine Code 2 Machine Code 3 producer consumers Just-in-Time Compilers Class Files 9 class Foo { ... } class Bar { ... } class Baz { ... } ... Compiler InputFile.java Foo.class ... Bar.class ... Baz.class Whats in a Class File? Magic number, version info Constant pool Super class Access flags (public, private, ...) Interfaces Fields Name and type Access flags (public, private, static, ...) Methods Name and signature (argument and return types) Access flags (public, private, static, ...) Bytecode Exception tables Other stuff (source file, line number table, ...) 10 Structure of Class File ClassFile { u4 magic; // 0xCAFEBABE ids class file u2 minor_version; // Check if JVM can execute u2 major_version; // this class file? u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; // public, final, abstract u2 this_class; u2 super_class; u2 interfaces_count; // number of implemented // interfaces 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]; } 11 Class File Format magic number identifies the file as a Java class...
View Full Document

Page1 / 12

24-JVM - 5/3/2011 1 CS/ENGRD 2110 Object-Oriented...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online