L24cs211sp07-6up - Compiling for Different Platforms...

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

View Full Document Right Arrow Icon
Lecture 24 – CS211 – Spring 2007 Under the Hood: The Java Virtual Machine 2 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 3 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, . .. • Architectures – Pentium, PowerPC, Alpha, SPARC, MIPS, . .. 4 Compiling for Different Platforms High-Level Program Intermediate-Level Program Compiler Code Gen 1 Code Gen 2 Code Gen 3 Machine Code 1 Machine Code 2 Machine Code 3 producer consumers 5 Dream: Platform Independence • Compiler produces one low - level program for all platforms • Executed on a virtual machine (VM) • A different VM implementation needed for each platform, but installed once and for all 6 Platform Independence with Java Java Program Bytecode Program Compiler JVM 1 JVM 2 JVM 3 producer consumers Java Virtual Machines
Background image of page 1

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

View Full DocumentRight Arrow Icon
7 Platform Independence with Java Java Program Bytecode Program Compiler JIT 1 JIT 2 JIT 3 Machine Code 1 Machine Code 2 Machine Code 3 producer consumers Just -i n -T ime Compilers 8 Java 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 9 Class Files class Foo { ... } class Bar { ... } class Baz { ... } ... Compiler InputFile.java Foo.class ... Bar.class ... Baz.class 10 What is 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, . ..) 11 Class File Format 0x0000 2 bytes minor version 0x0021 2 bytes major version 0xCAFEBABE 4 bytes magic number • magic number identifies the file as a Java class file • version numbers inform the JVM whether it is able to execute the code in the file 12 Constant Pool (variable) CP entry 2 ... ...
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/20/2008 for the course COM S 211 taught by Professor Kozen during the Spring '06 term at Cornell University (Engineering School).

Page1 / 6

L24cs211sp07-6up - Compiling for Different Platforms...

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