Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.

Slides:



Advertisements
Similar presentations
Chapter 16 Java Virtual Machine. To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode.
Advertisements

Virtual Machines Matthew Dwyer 324E Nichols Hall
1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Names and Bindings.
BA1 JVM arkitektur BA2 Specifikation I The Java Virtual Machine Specification specificeres bl.a.: –De grundlæggende datatyper.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
Memory Allocation. Three kinds of memory Fixed memory Stack memory Heap memory.
Procedure calls (1) The fact: Most programming languages support the concept of procedures (methods). Each method has its own local variables that are.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Chapter 4 H1 Assembly Language: Part 2. Direct instruction Contains the absolute address of the memory location it accesses. ld instruction:
Consider With x = 10 we may proceed as (10-1) = 9 (10-7) = 3 (9*3) = 27 (10-11) = -1 27/(-1) = -27 Writing intermediates on paper.
5/6/99 Ashish Sabharwal1 JVM Architecture n Local storage area –Randomly accessible –Just like standard RAM –Stores variables (eg. an array) –Have to specify.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Code Generation Introduction. Compiler (scalac, gcc) Compiler (scalac, gcc) machine code (e.g. x86, arm, JVM) efficient to execute i=0 while (i < 10)
Intro to Java The Java Virtual Machine. What is the JVM  a software emulation of a hypothetical computing machine that runs Java bytecodes (Java compiler.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Compiler Construction Lecture 17 Mapping Variables to Memory.
Application Security Tom Chothia Computer Security, Lecture 14.
JVM And CLR Dan Agar April 16, Outline Java and.NET Design Philosophies Overview of Virtual Machines Technical Look at JVM and CLR Comparison of.
Arpit Jain Mtech1. Outline Introduction Dalvik VM Java VM Examples Comparisons Experimental Evaluation.
1 The Java Virtual Machine Yearly Programming Project.
The Java Virtual Machine 1 Course Overview PART I: overview material 1Introduction 2Language processors (tombstone diagrams, bootstrapping) 3Architecture.
Krakatoa: Decompilation in Java “Does Bytecode Reveal Source?” Todd A. Proebsting Scott A. Watterson The University of Arizona Presented by Karl von Randow.
A Simple Two-Pass Assembler
Implement High-level Program Language on JVM CSCE 531 ZHONGHAO LIU ZHONGHAO LIU XIAO LIN.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
4-1 Chapter 4 - The Instruction Set Architecture Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of.
ITEC 352 Lecture 20 JVM Intro. Functions + Assembly Review Questions? Project due today Activation record –How is it used?
Lecture 10 : Introduction to Java Virtual Machine
Java Programming Introduction & Concepts. Introduction to Java Developed at Sun Microsystems by James Gosling in 1991 Object Oriented Free Compiled and.
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1 Introduction to JVM Based on material produced by Bill Venners.
Roopa.T PESIT, Bangalore. Source and Credits Dalvik VM, Dan Bornstein Google IO 2008 The Dalvik virtual machine Architecture by David Ehringer.
An Efficient Stack Machine Martin Schöberl. JOP Stack Architecture2 Overview JVM stack machine Parameter passing Stack access patterns Common stack caches.
4-1 Chapter 4 - The Instruction Set Architecture Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
12/10/2002© 2002 Hal Perkins & UW CSET-1 CSE 582 – Compilers Java Implementation – JVMs, JITs &c Hal Perkins Autumn 2002.
5-1 Chapter 5 - Languages and the Machine Principles of Computer Architecture by M. Murdocca and V. Heuring © 1999 M. Murdocca and V. Heuring Principles.
More on MIPS programs n SPIM does not support everything supported by a general MIPS assembler. For example, –.end doesn’t work Use j $ra –.macro doesn’t.
ECEG-3202 Computer Architecture and Organization Chapter 6 Instruction Sets: Addressing Modes and Formats.
Chap. 10, Intermediate Representations J. H. Wang Dec. 14, 2015.
Programming Languages and Paradigms Activation Records in Java.
More Examples of Abstract Interpretation Register Allocation.
Review on Program Challenge CSc3210 Yuan Long.
Hello world !!! ASCII representation of hello.c.
Operating Systems A Biswas, Dept. of Information Technology.
RealTimeSystems Lab Jong-Koo, Lim
CS 536 © CS 536 Spring Introduction to Programming Languages and Compilers Charles N. Fischer Lecture 15.
CS 432: Compiler Construction Lecture 15
Computer Architecture Instruction Set Architecture
The Java Virtual Machine (JVM)
A Closer Look at Instruction Set Architectures
CS216: Program and Data Representation
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
CS 153: Concepts of Compiler Design November 2 Class Meeting
William Stallings Computer Organization and Architecture 8th Edition
Java Virtual Machine (JVM)
Java Byte Codes (0xCAFEBABE) cs205: engineering software
CSc 453 Interpreters & Interpretation
Lecture 19: 0xCAFEBABE (Java Byte Codes) CS201j: Engineering Software
Processor Organization and Architecture
ECEG-3202 Computer Architecture and Organization
Understanding Program Address Space
Byte Code Verification
Course Overview PART I: overview material PART II: inside a compiler
Java Implementation – JVMs, JITs &c Hal Perkins Summer 2004
CS 153: Concepts of Compiler Design November 6 Class Meeting
CMPE 152: Compiler Design April 11 Class Meeting
CMPE 152: Compiler Design April 16 Class Meeting
CSc 453 Interpreters & Interpretation
Presentation transcript:

Chapter 16 Java Virtual Machine

To compile a java program in Simple.java, enter javac Simple.java javac outputs Simple.class, a file that contains bytecode (machine language for the Java Virtual Machine (JVM). To run Simple.class, enter java Simple

java (the Java interpreter) makes your computer act like the JVM so it can execute bytecode.

Why is Java slow? Interpretation of bytecode can involve a lot of overhead. JVM dynamically links classes. JVM performs checks during loading, linking, and executing bytecode.

Why is Java good for the Web? Bytecode is space efficient. Bytecode is portable to any system with a java interpreter. Java applets are safe to run.

Four parts of the JVM Execution engine (contains pc register) Method area (contains information on each class: bytecode, static variables, information needed for verification and linking). Java stack (the run time stack). Each frame of the Java stack contains a local variable array and an operand stack. heap (contains data associated with objects). Periodically, garbage collection deallocates objects in the heap that are no longer referenced.

There are two types of stacks in the JVM The Java stack The Java stack consists of frames, one frame for each method invocation. Each frame contains an operand stack and a local variable array.

Local variable array Contains local variables numbered starting from 0. For example, the first slot of the local variable array is called local variable 0.

Operand stack Used to hold operands and results during the execution of instructions.

Some instructions consist of an opcode only. For example, iconst_0, iconst_1, iconst_2, iconst_3, iconst_4, iconst_5 which push 0, 1, 2, 3, 4, and 5, respectively, onto the operand stack. The more common operations are performed by such opcode-only instructions.

Some instructions require an operand. For example, bipush 6 which pushes 6. This instruction consists of the opcode for bipush followed by a byte containing 6. To push a number greater than 127, use sipush (short int push). For example, sipush 130

Symbolic bytecode that adds three numbers

The initial letter of some mnemonics indicates the data type. For example, iadd, dadd, fadd, ladd. a: reference d: double f: float i: integer ia: integer array l: long

iload_0 pushes the value in local variable 0 (i.e., it pushes the value from the first slot of the local variable array onto the operand stack.) iload 4 pushes the value in local variable 4. Load instructions on the JVM

istore_0 pops and stores the value on top of the operand stack into local variable 0. istore 4 pops and stores the value on top of the operand stack into local variable 4. Store instructions on the JVM

A static variable in Java is a variable associated with a class rather than an object. It is shared by all objects of its class. A static method in Java is a method that can be called via its class.

The getstatic and putstatic instructions transfer values between the top of the operand stack and static variables. The operand that appears in getstatic and putstatic instructions is an index into the constant pool. For example, getstatic 2 2 is a constant pool index.

Invoking a static method with invokestatic instruction Creates frame for the called method and pushes it onto the Java stack. Pops the arguments from the caller’s operand stack and places them in the called method’s local variable array starting from local variable 0. Transfers control to the called method.

Returning a value to the calling method with the ireturn instruction The value returned is pushed onto the calling method’s operand stack.

Implementation of the execution engine

The wisdom of using a stack architecture for the JVM A stack architecture on a simulated machine is no slower than a register architecture. Bytecode is very compact which is important for a web programs.

A simple Java program follows, along with its bytecode

A formatted display of the constant pool for our simple program follows.

Information in the constant pool for index 3

An attribute in a class file The first entry is the constant pool index of the attribute name. The second entry is the length of what follows.

A hex display of the complete class file for our simple program follows.

Sizes of comparable programs

Some comparison and control instructions goto unconditional jump if_cmplt compares top two stack items if_icmpge compares top two stack items iflt compares top of stack with 0 if_acmpeq compares references if_acmpne compares references See the illustrative program on the next slide.

Instructions that jump use pc- relative addressing A70006 (the machine code for goto 6) jumps to the location whose address is 6 + the contents of the pc register (before incrementation).

Unassembling the Simple class file javap –c Simple

Unassemble this program to see its bytecode

Arrays and objects

Now that you know the basics of the JVM, you can enjoy (and understand) some more advanced discussions of the JVM.