The Java Virtual Machine (JVM) Pat Morin COMP 3002

Similar documents
Chapter 7D The Java Virtual Machine

02 B The Java Virtual Machine

The Java Virtual Machine and Mobile Devices. John Buford, Ph.D. Oct 2003 Presented to Gordon College CS 311

picojava TM : A Hardware Implementation of the Java Virtual Machine

1 The Java Virtual Machine

Habanero Extreme Scale Software Research Project

The Java Virtual Machine Specification. Java SE 8 Edition

Interpreters and virtual machines. Interpreters. Interpreters. Why interpreters? Tree-based interpreters. Text-based interpreters

The Java Virtual Machine Specification

AVR 32-bit Microcontroller. Java Technical Reference. 1. Introduction. 1.1 Intended audience. 1.2 The AVR32 Java Extension Module

Platform Independent Dynamic Java Virtual Machine Analysis: the Java Grande Forum Benchmark Suite

University of Twente. A simulation of the Java Virtual Machine using graph grammars

language 1 (source) compiler language 2 (target) Figure 1: Compiling a program

Java Virtual Machine, JVM

Java Programming. Binnur Kurt Istanbul Technical University Computer Engineering Department. Java Programming. Version 0.0.

CSC 8505 Handout : JVM & Jasmin

Under the Hood: The Java Virtual Machine. Lecture 24 CS 2110 Fall 2011

Handout 1. Introduction to Java programming language. Java primitive types and operations. Reading keyboard Input using class Scanner.

Introduction to Java

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

C Compiler Targeting the Java Virtual Machine

Introduction to Programming

An Overview of Java. overview-1

CS 106 Introduction to Computer Science I

Introduction to Java Applications Pearson Education, Inc. All rights reserved.

Lecture 32: The Java Virtual Machine. The Java Virtual Machine

Topics. Introduction. Java History CS 146. Introduction to Programming and Algorithms Module 1. Module Objectives

- Applet java appaiono di frequente nelle pagine web - Come funziona l'interprete contenuto in ogni browser di un certo livello? - Per approfondire

Crash Course in Java

Java Crash Course Part I

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

The Java Series. Java Essentials I What is Java? Basic Language Constructs. Java Essentials I. What is Java?. Basic Language Constructs Slide 1

Instruction Set Architecture (ISA)

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

Virtual Machines. Case Study: JVM. Virtual Machine, Intermediate Language. JVM Case Study. JVM: Java Byte-Code. JVM: Type System

Instrumenting Java bytecode

Java Card 2.2 Virtual Machine Specification. Sun Microsystems, Inc. 901 San Antonio Road Palo Alto, CA USA fax

CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 20: Stack Frames 7 March 08

a storage location directly on the CPU, used for temporary storage of small amounts of data during processing.

Object Oriented Software Design

X86-64 Architecture Guide

JAVA - QUICK GUIDE. Java SE is freely available from the link Download Java. So you download a version based on your operating system.

Object Oriented Software Design

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine

Hardware/Software Co-Design of a Java Virtual Machine

Jonathan Worthington Scarborough Linux User Group

Real-time Java Processor for Monitoring and Test

Instruction Set Design

Inside the Java Virtual Machine

Pemrograman Dasar. Basic Elements Of Java

CS1020 Data Structures and Algorithms I Lecture Note #1. Introduction to Java

Java Virtual Machine Locks

Java Programming Fundamentals

Stack machines The MIPS assembly language A simple source language Stack-machine implementation of the simple language Readings:

Structural Typing on the Java Virtual. Machine with invokedynamic

Armed E-Bunny: A Selective Dynamic Compiler for Embedded Java Virtual Machine Targeting ARM Processors

Number Representation

CPU Organization and Assembly Language

CS 141: Introduction to (Java) Programming: Exam 1 Jenny Orr Willamette University Fall 2013

Java Basics: Data Types, Variables, and Loops

C# and Other Languages

Variables, Constants, and Data Types

COS 217: Introduction to Programming Systems

Introduction to programming

Java Interview Questions and Answers

General Introduction

7.1 Our Current Model

2 Introduction to Java. Introduction to Programming 1 1

1.00 Lecture 1. Course information Course staff (TA, instructor names on syllabus/faq): 2 instructors, 4 TAs, 2 Lab TAs, graders

Chapter 2: Elements of Java

Chapter 2 Introduction to Java programming

CHAPTER 7: The CPU and Memory

Cloud Computing. Up until now

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

An Introduction to Assembly Programming with the ARM 32-bit Processor Family

Sources: On the Web: Slides will be available on:

CSC 551: Web Programming. Fall 2001

The Hotspot Java Virtual Machine: Memory and Architecture

From Eiffel to the Java Virtual Machine

HOTPATH VM. An Effective JIT Compiler for Resource-constrained Devices

Example of a Java program

Java Card 3 Platform. Virtual Machine Specification, Classic Edition. Version May 2015

1) Which of the following is a constant, according to Java naming conventions? a. PI b. Test c. x d. radius

Programming in Java Course Technology, a part of Cengage Learning.

Lecture 1 Introduction to Java

1.00/ Session 2 Fall Basic Java Data Types, Control Structures. Java Data Types. 8 primitive or built-in data types

CSE 1223: Introduction to Computer Programming in Java Chapter 2 Java Fundamentals

Java CPD (I) Frans Coenen Department of Computer Science

Chapter 1 Java Program Design and Development

Restraining Execution Environments

public static void main(string[] args) { System.out.println("hello, world"); } }

DNA Data and Program Representation. Alexandre David

7. Virtual Machine I: Stack Arithmetic 1

Performance Improvement In Java Application

Caml Virtual Machine File & data formats Document version: 1.4

Transcription:

The Java Virtual Machine (JVM) Pat Morin COMP 3002

Outline Topic 1 Topic 2 Subtopic 2.1 Subtopic 2.2 Topic 3 2

What is the JVM? The JVM is a specification of a computing machine Instruction set Primitive data types Memory layout of primitive data types The JVM allows portable binary software Authors need only write code for the JVM and it will run on any machine that has a JVM interpreter Hardware implementations of the JVM also exist picojava 3

Bytecodes: JVM Instructions A JVM instruction is a opcode followed by a variable number of operands An opcode is one byte 225 different opcodes JVM byte codes are small compared to other instruction sets On average, a JVM instruction is 1.8 bytes long RISC instructions typically require 4 bytes 4

Distribution of Bytecode Lengths Source: Sun Microsystems 5

JVM Datatypes Integers: byte (8 bits) short (16 bits) int (32 bits) long (64 bits) Floating point float (32 bits) double (64 bits) Others char (16 bits!) reference (not defined) returnaddress (not defined) 6

Parts of the JVM pc Register Keeps track of the current instruction Stack Stores stack frames Heap Stores dynamically allocated memory (garbage collected) Method area Stores program code (JVM instructions) Runtime constant pool Stores constants and method/field references 7

What, no registers? The JVM has only one register, used to keep track of the program counter The JVM is a stack machine All operations operate on the top few elements of the stack This is what allows for such short bytecodes Eg. An integer division operation in a 32 register RISC machine requires 32*31=992 different opcodes (one for each pair of registers) in a stack machine requires only 1 opcode (it always operates on the top 2 elements) 8

The Jasmin Assembler Rather than manipulate bytecodes directly, we generate assembly language and use an assembler to assemble the byte codes The assembler we use is Jasmin http://jasmin.sourceforge.net/ 9

Hello World ; public static void main(string args[]) { ; System.out.println( Hello World! ); ; }.method public static main([ljava/lang/string;)v.limit stack 50 ; push System.out onto the stack getstatic java/lang/system/out Ljava/io/PrintStream; ; push a string constant onto the stack ldc "Hello World!" ; Call System.out.println invokevirtual java/io/printstream/println(ljava/lang/string;)v return.end method

Observe.method defines a new method The parameters and return value are defined.limit stack defines the size (in 32 bit words) of the stack frame for this method getstatic loads a static (class) variable onto the stack invokevirtual calls a virtual (instance) method We return with an explicit return statement 11

Printing a Float ; public static void printfloat(float x) { ; System.out.println( Float.toString(x) ); ; }.method public static printfloat(f)v.limit stack 2.limit locals 2 getstatic java/lang/system/out Ljava/io/PrintStream; fload 0 invokestatic java/lang/float/tostring(f)ljava/lang/string; invokevirtual java/io/printstream/println(ljava/lang/string;)v return.end method

Local Variables.locals specifies the number of local variables This includes function parameters Each local variable is a 32 bit quantity, indexed starting at 0 Local variables are loaded onto and stored from the stack using *load and *store instructions 13

load and store operations The JVM has several load and store operations xload <index> x defines the type of operand (f, i, l, d, a...) index defines its index in the current stack frame The stack frame is indexed starting at 0 Starting with function arguments Each index specifies a 4 byte quantity byte, char, short, int, float, reference wide data types are loaded in 2 steps E.g., dload_0 0 dload_1 1 store operations store the top element into the specified local variable 14

Operations The JVM includes many operations for arithmetic and logic Add: iadd, ladd, fadd, dadd. Subtract: isub, lsub, fsub, dsub. Multiply: imul, lmul, fmul, dmul. Divide: idiv, ldiv, fdiv, ddiv. Remainder: irem, lrem, frem, drem. Negate: ineg, lneg, fneg, dneg. Comparison: dcmpg, dcmpl, fcmpg, fcmpl, lcmp. and more... They all operate on the top 1 or 2 stack elements and leave their result on the top of the stack 15

Labels and Jump Instructions ;;; return true (1) if arg1 >= arg2 and false (0) otherwise.method public static cmpge(ff)i.limit locals 4.limit stack 4 fload 0 fload 1 fcmpl ifge true_label ldc 0 goto done true_label: ldc 1 done: ireturn.end method

Summary The JVM is a stack-based virtual machine Being stack-based allows for compact instruction encoding Being a virtual machine makes it portable Hardware implementations exist, but are not the fastest computers around We have not covered Array instructions Dynamic memory allocation Exceptions Interfaces Type conversions Threads 17