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



Similar documents
02 B The Java Virtual Machine

The Java Virtual Machine (JVM) Pat Morin COMP 3002

picojava TM : A Hardware Implementation of the Java Virtual Machine

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

Java Virtual Machine, JVM

1 The Java Virtual Machine

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

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

Mobile Operating Systems. Week I

Habanero Extreme Scale Software Research Project

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

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

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

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

Crash Course in Java

General Introduction

Fachbereich Informatik und Elektrotechnik SunSPOT. Ubiquitous Computing. Ubiquitous Computing, Helmut Dispert

Chapter 7D The Java Virtual Machine

Central Processing Unit (CPU)

The Hotspot Java Virtual Machine: Memory and Architecture

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

Real-time Java Processor for Monitoring and Test

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

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

STM32JAVA. Embedded Java Solutions for STM32

System Structures. Services Interface Structure

An Overview of Stack Architecture and the PSC 1000 Microprocessor

Development of Java ME

qwertyuiopasdfghjklzxcvbnmqwerty uiopasdfghjklzxcvbnmqwertyuiopasd fghjklzxcvbnmqwertyuiopasdfghjklzx cvbnmqwertyuiopasdfghjklzxcvbnmq

ADVANCED PROCESSOR ARCHITECTURES AND MEMORY ORGANISATION Lesson-12: ARM

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

Mobile Application Languages XML, Java, J2ME and JavaCard Lesson 04 Java

HVM TP : A Time Predictable and Portable Java Virtual Machine for Hard Real-Time Embedded Systems JTRES 2014

Jonathan Worthington Scarborough Linux User Group

Java Card. Smartcards. Demos. . p.1/30

Chapter 4 Lecture 5 The Microarchitecture Level Integer JAVA Virtual Machine

Example of Standard API

CSE 452: Programming Languages. Acknowledgements. Contents. Java and its Evolution

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

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

Java Programming Fundamentals

VisualJVM: A Visual Tool for Teaching Java Technology

Hardware/Software Co-Design of a Java Virtual Machine

Java Virtual Machine Locks

What Perl Programmers Should Know About Java

Java and Real Time Storage Applications

Restraining Execution Environments

Characteristics of Java (Optional) Y. Daniel Liang Supplement for Introduction to Java Programming

C# and Other Languages

Introduction to Java

Instruction Set Architecture (ISA)

An Overview of Java. overview-1

Cloud Computing. Up until now

Lecture 1 Introduction to Android

LSN 2 Computer Processors

The BSN Hardware and Software Platform: Enabling Easy Development of Body Sensor Network Applications

Contents. Java - An Introduction. Java Milestones. Java and its Evolution

Lecture 7: Machine-Level Programming I: Basics Mohamed Zahran (aka Z)

CSC 8505 Handout : JVM & Jasmin

Computer Architecture Lecture 3: ISA Tradeoffs. Prof. Onur Mutlu Carnegie Mellon University Spring 2013, 1/18/2013

CS3600 SYSTEMS AND NETWORKS

Nokia 9210i/9290 Communicators and PersonalJava TM Application Development

Instrumentation Software Profiling

Java CPD (I) Frans Coenen Department of Computer Science

ELEC 377. Operating Systems. Week 1 Class 3

CS 106 Introduction to Computer Science I

Tutorial: Getting Started

Java Language Tools COPYRIGHTED MATERIAL. Part 1. In this part...

The Design of the Inferno Virtual Machine. Introduction

JPURE - A PURIFIED JAVA EXECUTION ENVIRONMENT FOR CONTROLLER NETWORKS 1

Introduction to programming

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

C Compiler Targeting the Java Virtual Machine

Free Java textbook available online. Introduction to the Java programming language. Compilation. A simple java program

PERFORMANCE ENHANCEMENTS IN TreeAge Pro 2014 R1.0

CPU Organization and Assembly Language

A JAVA VIRTUAL MACHINE FOR THE ARM PROCESSOR

CSC 551: Web Programming. Spring 2004

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

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

Built-in Concurrency Primitives in Java Programming Language. by Yourii Martiak and Mahir Atmis

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

Chapter 5, The Instruction Set Architecture Level

Java ME & NetBeans Mobility. Petr Suchomel Architect, NetBeans Mobility Sun Microsystems

Mobile Devices and Systems Lesson 02 Handheld Pocket Computers and Mobile System Operating Systems

Advanced Computer Architecture-CS501. Computer Systems Design and Architecture 2.1, 2.2, 3.2

CHAPTER 7: The CPU and Memory

Mobile application development J2ME U N I T I I

Objectives. Chapter 2: Operating-System Structures. Operating System Services (Cont.) Operating System Services. Operating System Services (Cont.

Mobile Devices - An Introduction to the Android Operating Environment. Design, Architecture, and Performance Implications

Chapter 3 Operating-System Structures

Computer Organization and Architecture

Specialized Android APP Development Program with Java (SAADPJ) Duration 2 months

Android Basics. Xin Yang

Chapter 3: Operating-System Structures. Common System Components

Can You Trust Your JVM Diagnostic Tools?

Bypassing Browser Memory Protections in Windows Vista

Java Cheatsheet. Tim Coppieters Laure Philips Elisa Gonzalez Boix

Replication on Virtual Machines

Transcription:

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

Objectives Review virtual machine concept Introduce stack machine architecture and relate it to CISC and RISC architectures Present key features of Java VM Describe use of JVM technology in mobile device area

Virtual Machine A processor specification implemented in a software interpreter with the following characteristics: intended to execute programs written in some high level language includes an instruction set, a register set, and a memory model usually designed for portability frequently used inside compilers as an intermediate language to which generic optimizations are made Historical examples: Pascal P-Code, Smalltalk, Portable Scheme, etc. Current examples: Java VM, Microsoft.NET Common Language Runtime

Virtual Machine A specification of a machine language and the CPU and memory organization Typically designed as a generic model a stack machine is one such a generic model Inside view a machine that can be simulated in software application program opcodes stored in files produced by compiler VM reads opcodes into an array VM interprets each opcode one-by-one just as a hardware CPU would Each opcode is interpreted; the execution of the opcode causes changes to other data structures in the program that represent other parts of the machine organization

Stack Machine A CPU architecture where all operations are performed on a stack Most instructions use implied addressing mode so instruction size is short compared with other architectures But more instructions are needed for a complex operation than in other designs Use of stack machines in some early computers Burroughs B 5000 (circa 1960s) HP3000 minicomputers (circa 1970s) Stack machine has been more popular as a virtual machine than as an actual hardware design Software implementation relatively easy Most computers have a hardware stack Why not use an abstract RISC VM instead of a stack machine? object ref 4 a[0] MAX TOS MIN

Implied Addressing Mode Register addressing mode (Intel) ADD AX,BX Direct address mode ADD Var1, Var2 Implied mode PUSH Var1 // destination is implied PUSH Var2 // destination is implied ADD // addends are implied Implied addressing gives shorter instructions, but generally more instructions for given operation

Stack vs CISC vs RISC You re building a new distributed agent software platform that will run on every future computing device. You ve decided to use a virtual machine. How would you compare the architectural choices: CISC RISC Stack machine

Java Virtual Machine 32-bit stack machine Floating point and integer data types ~200 instructions Most instructions are generic, but some are related to the Java object model

Typical Java Runtime System Applet or Application Class Files Standard Built-in Java Classes Dynamic Class Loader and Verifier Class and Method Area Garbage Collected Heap Support Code: Exceptions Threads Security... Native Methods.dll or.so Native Method Linker Native Method Area Execution Engine Operating System

Execution Engine System Thread Event Loop Object Heap MAX MAX Allocated Free Being Reclaimed object ref TOS object ref TOS 4 a[0] Application Thread 1 MIN 4 a[0] Application Thread N MIN Classes MAX MAX Constant Pool object ref TOS object ref TOS 4 a[0] MIN 4 a[0] MIN

Instruction Categories Arithmetic Logical Conversion operations Control transfer Function return Stack operations Pushing constants on to the stack Loading/storing local variables on to/from the stack Managing arrays Method invocation Manipulating object fields Exception handling Miscellaneous object operations Monitors

Examples Add Two values 16 05 bipush 5 => 5 16 06 bipush 6..., 5 => 5, 6 96 iadd 5, 6 => 11 HelloWorld public class HelloWorld { public static void main(string args[ ] ) { } } System.out.println( Hello world! );

Inside HelloWorld javap -c HelloWorld Compiled from HelloWorld.java public class HelloWorld extends java.lang.object /* ACC_SUPER bit set */ { public static void main(java.lang.string []); public HelloWorld(); ; call Object's constructor Method void main(java.lang.string []) 0 getstatic #7 <Field java.lang.system.out Ljava/io/PrintStream;> ; #7 = index into the constant pool 3 ldc #1 <String "Hello World!"> ; push item which is a constant 5 invokevirtual #8 <Method java.io.printstream.println(ljava/lang/string;)v> ; invoke the instance method 8 return ; Push the output stream and the string "Hello World" onto the stack, ; then invoke the println method: Method HelloWorld() 0 aload_0 ; load the object ref onto the stack 1 invokespecial #6 <Method java.lang.object.<init>()v> ; invoke the object initializer method 4 return }

JVM Organization 32-bit operand stack Longs and doubles take 2 entries Stack frame, one for each executing method Local variables Execution environment Operand stack Local variables Stored in 32-bit cells 64-bit types use two cells Execution environment Copies of registers prior to new call frame (PC, frame ptr, TOS) private data (implementation specific, e.g. method and object ref, class table, etc) Registers Program counter (PC) Optop (TOS pointer) Frame Ptr: reference to the execution environment for the currently executing method Vars: reference to the local variables for the currently executing method Stack PC vars FramePtr Optop local vars prev PC prev TOS prev frame ptr prev method s stack area prev frame MAX MIN

JVM Organization (cont d) Constant pool Each class has a constant pool Constants are stored in the class file produced by compiler There are constants for each method and field referenced by an object of this class Method area Stores method byte code Example graphical simulator for VM at http://www.artima.com/insidejvm/applets/index.html

Basic Structure of JVM Interpreter read machine code from file initialize state of vm while(true) { opcode = machine_code[pc]; pc += 1; switch(opcode) { case BIPUSH: break; case SIPUSH: break; /* etc. */ } }

Questions What issues are there in dealing with mixed datatypes in a fixed-width stack? How could stack corruption (accidental or otherwise) effect VM integrity and security? How could bytecode be written to adversely effect VM integrity and security? How does the VM prevent inadvertant stack corruption and bytecode errors? How does this impact performance?

Java on Embedded and Mobile Devices

Cell Phones See http://www.mobiletechnews.com/ PDAs Telematics and Info Appliances

Features of Mobile Platforms PDAs OS: Palm, PocketPC, Embedded Linux, Symbian Processor: ARM, StrongARM, OMAP, Xscale, 68K Memory: 16MB to 64MB IO: WiFi, mini-keyboard/touch screen, display Cell Phones OS: various real-time embedded OS and proprietary software, Qualcomm BREW Processor: ARM; Motorola, SHx Memory: IO: flash memory, keypad, audio, video Large variety of systems software and hardware Java offers portability for applications to run But J2SE is too resource intensive

Java 2 Microedition

Java 2 Microedition Edition http://jcp.org Optional JSRs CDC JSR 135 Mobile Media JSR 179 Location API JSR 205 WMA 2.0 JSR 209 Adv Graphics and UI JSR 211 Content Handler JSR 184 Mobile 3D Graphics JSR 229 Payment API CLDC/MIDP PP 1.0 PP 1.1 JTWI PBP 1.0 PBP 1.1 WMA 1.0 FP 1.0 FP 1.1 MIDP 1.0 MIDP 2.0 MIDP 2.0 CDC 1.0 CDC 1.1 CLDC 1.0 CLDC 1.1 CLDC 1.1

Further Information Java VM Specifications http://java.sun.com/docs/books/vmspec/2nd-edition/html/vmspectoc.doc.html Java VM resources http://www.artima.com/insidejvm/resources/index.html Open source JVM implementations Kaffe (http://www.kaffe.org) Wonka (http://www.acunia.com/wonka/001_about.php)

Summary Review virtual machine concept Introduce stack machine architecture and relate it to CISC and RISC architectures Present key features of Java VM Describe use of JVM technology in mobile device area

Discussion