Oop The JVM. oop What’s a JVM uA computing machine (just like 8086, but not produced by Intel) lAbstract: machine is specified in a book. lConcrete: anyone.

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

1 Lecture 10 Intermediate Representations. 2 front end »produces an intermediate representation (IR) for the program. optimizer »transforms the code in.
Compilation 2007 Code Generation Michael I. Schwartzbach BRICS, University of Aarhus.
BA1 JVM arkitektur BA2 Specifikation I The Java Virtual Machine Specification specificeres bl.a.: –De grundlæggende datatyper.
Java security (in a nutshell)
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
1 1 Lecture 14 Java Virtual Machine Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute of Technology.
CERTIFICATION OBJECTIVES Use Class Members Develop Wrapper Code & Autoboxing Code Determine the Effects of Passing Variables into Methods Recognize when.
Chapter 5: Elementary Data Types Properties of types and objects –Data objects, variables and constants –Data types –Declarations –Type checking –Assignment.
Cmput Lecture 8 Department of Computing Science University of Alberta ©Duane Szafron 2000 Revised 1/26/00 The Java Memory Model.
Oop JVM in Context. oop What’s a JVM uPlatform-independent execution environment lA different JVM is required for each operating system lAny JVM can run.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Java Virtual Machine (JVM). Lecture Objectives Learn about the Java Virtual Machine (JVM) Understand the functionalities of the class loader subsystem.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
CSCE 121, Sec 200, 507, 508 Fall 2010 Prof. Jennifer L. Welch.
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.
Oop The JVM. oop What’s a JVM uA computing machine (just like 8086, but not produced by Intel) lAbstract: machine is specified in a book. lConcrete: anyone.
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.
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.
Unit 061 Java Virtual Machine (JVM) What is Java Virtual Machine? The Class Loader Subsystem Linking oVerification oPreparation oResolution Class Initialization.
Oop The JVM. oop What’s a JVM uA computing machine (just like 8086, but not produced by Intel) lAbstract: machine is specified in a book. lConcrete: anyone.
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)
Java Security Updated May Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security.
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.
OOP Languages: Java vs C++
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
1 The Java Virtual Machine Yearly Programming Project.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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.
ITEC 352 Lecture 20 JVM Intro. Functions + Assembly Review Questions? Project due today Activation record –How is it used?
DEPARTMENT OF COMPUTER SCIENCE & TECHNOLOGY FACULTY OF SCIENCE & TECHNOLOGY UNIVERSITY OF UWA WELLASSA 1 CST 221 OBJECT ORIENTED PROGRAMMING(OOP) ( 2 CREDITS.
Lecture 10 : Introduction to Java Virtual Machine
Introduction to the Java Virtual Machine 井民全. JVM (Java Virtual Machine) the environment in which the java programs execute The specification define an.
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.
CS 147 June 13, 2001 Levels of Programming Languages Svetlana Velyutina.
Java 2 security model Valentina Casola. Components of Java the development environment –development lifecycle –Java language features –class files and.
5-1 Chapter 5 - Languages and the Machine Department of Information Technology, Radford University ITEC 352 Computer Organization Principles of Computer.
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.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
More on Hierarchies 1. When an object of a subclass is instantiated, is memory allocated for only the data members of the subclass or also for the members.
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.
Programming Languages
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
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.
Instruction Sets: Addressing modes and Formats Group #4  Eloy Reyes  Rafael Arevalo  Julio Hernandez  Humood Aljassar Computer Design EEL 4709c Prof:
Programming Languages and Paradigms Activation Records in Java.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
(C) 2010 Pearson Education, Inc. All rights reserved.  Best way to develop and maintain a large program is to construct it from small, simple pieces,
RealTimeSystems Lab Jong-Koo, Lim
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
 Pearson Education, Inc. All rights reserved Methods: A Deeper Look.
Design issues for Object-Oriented Languages
CS 432: Compiler Construction Lecture 15
The Java Virtual Machine (JVM)
A Closer Look at Instruction Set Architectures
CS216: Program and Data Representation
Java Primer 1: Types, Classes and Operators
Java security (in a nutshell)
Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 4 – The Instruction Set Architecture.
2.1. Compilers and Interpreters
Java Virtual Machine (JVM)
Java Byte Codes (0xCAFEBABE) cs205: engineering software
Presentation transcript:

oop The JVM

oop What’s a JVM uA computing machine (just like 8086, but not produced by Intel) lAbstract: machine is specified in a book. lConcrete: anyone can implement uInput: lA “class” file a binary file with lots of numbers and instructions. lA search path (to find more class files) uOutput lThe “execution” of the class file. uHow? lIt is all in The Java Virtual Machine Specification, by Tim Lindholm and Frank Yellin uStart with? lA method named “main” in a given class file. The method must have certain properties lContinue execution in other methods as necessary.

oop Class File? uThe binary form for Java programs uRepresents a complete description of one Java class or interface uPlatform independent – bytecodes are the machine language of the JVM uNot necessarily linked to the java language: Compiler Program in Java Lang. Program in Java Lang. Program in other Lang. Program in other Lang. Program in Java Lang. Program in Java Lang. Java class files Java class files Other Binary format Other Binary format

oop JVM in Java Architecture uJava’s architecture main technologies: lThe Java programming language Source files lThe Java class file format Compiled files lThe Java API Provide access to system resources lThe Java virtual machine Runs the class files

oop The Java Programming Environment Compile time environmentrun time environment A.Java B.Java C.Java Java Compiler A.class B.class C.class A.class B.class C.class Java Virtual Machine Object class String class

oop Class File Structure lPart I: Pool Maps strings to integers. Mostly symbolic names. lPart II: instructions for execution Organized in “methods” Each reference to another method, or another class file is through a “small integer” (index to the pool)

oop Basic JVM Components The Java Virtual Machine Class loader Execution engine Host operating system Program Class files The Java API’s class files Native methods invocation

oop Semantics of the Abstract Machine uLow level, Assembly Like: lno expression such as (a + b) *c uNo ordinary memory addressing (cannot access address 1000) lUse symbolic names, as defined in the pool. lGarbage collected! uNo registers (stack semantics) lTo do (a+b)*c: Push a Push b Add Push c Mult lScratch variables (used for storing arguments and local variables) Each method defines how many it needs

oop Typed Assembly uHigh Level Language uClass f(int a, int b, int c, int d) { return (a + b) *c - d; } 0: iload_1 1: iload_2 2: iadd 3: iload_3 4: imul 5: iload 4 6: isub 7: ireturn

oop JVM Types uSimilar (but not identical) to Java uPrimitive data types. lbyte: one byte lshort: two bytes lint: four bytes llong: eight bytes (2 entries on stack) lfloat: four bytes ldouble: eight bytes (2 entries on stack) lchar: two bytes uReference types: lClass reference lInterface reference lArray reference

oop Object Oriented Assembly uNo ordinary memory model lAll memory references are through fields. uA class file defines a class, just like any other object oriented language: lClass has: Fields (also static) Methods (also static) Constructors,... lMulti-threaded language lException support So that constructors can fail

oop Memory Model uAreas: lStacks (no single stack, since we have threads) Usually organized as a linked list Elements: method frames which include Local Variables Array (LVA) Operand stack (OS) Accessible by push/pop instructions. Garbage collected lHeap All objects and all arrays No object is allocated in the stack Each object is associated with a class stored in the method area Garbage collected. lMethod area Information about types, constant pool, fields and method i Inaccessible to programmer Garbage collected

oop Typed Instructions uMost JVM instructions are typed ! lEnables bytecode verification at load time  “xload v” (x ∈ {a, i, l, f, d}) lLoads (i.e. pushes) a variable v on the stack lThe prefix specifies the type lIf x = l (long) or x = d (double) then two words are pushed lOtherwise, the type annotation is only for type checking u“xastore” lStores in an array (the array, the index and the stored value are popped from the operand stack) uThis is the first successful attempt to bring type safety to a lower level language

oop JVM Instruction Set 1.Arithmetic 2.Stack Manipulation 3.Variables and Constants 4.Conversions 5.Arrays 6.Objects (methods and fields) 7.Control

oop Some Instructions uArithmetic: liadd, isub, imul, idiv, ineg, irem lBitwise (ints & longs) : iand, ior, ixor, ishl, ishr, iushr uStack Manipulation: lSwap, pop, dup lVersions that work on two words at a time: pop2, dup2 uLoad and Store: lLocals -> Stack: [i/f/l/d/a]load n l Stack ->Locals: [i/f/l/d/a]store n l Specialized load and store instructions: iload_1 pushes int from local variable position one onto stack

oop Some More Instructions uType Conversions (casts) lThe JVM pops the value at the top of the stack, converts it, and pushes the result back onto the stack. li2f converts int to float uInstructions for Arrays lnewarrray : Allocates an array of primitives lanewarrray : Allocates an array of references uInstructions for Objects lnew Followed (separately) by call to constructor, lgetfield linvokevirtual Stack:... object-reference params ->... returned-value

oop Some More Instructions uControl Instructions lAll control structures (if, switch, while, for, break, continue) are translated to labels and branches to labels Labels have method scope lLabels are translated into offsets from the beginning of the branch instruction to the beginning of the labeled instruction lgoto, if_icmpeq, if_acmpeq, ifnull…

oop Type Checking Strategies uNone (e.g., PDP11 assembly) uCompile time only (e.g., C++) uRuntime only (e.g., Smalltalk) uCompile time and runtime (e.g., C#) uLoad time: JVM lRationale: No compilation process Any hacker can mess with the bytecodes.

oop Type Checking in the JVM uAt each code location (byte offset of the method code) lThe number of cells used in LVA and OS is known. lEach cell has one, and only one type Primitive/reference. lOnly instructions that treat the cells “as they should” are allowed: No arithmetical operations on characters. Cannot push two integers and then pop a long. Only apply methods if the object knows about them.

oop Verification uWhen? lMainly during the load and link process uWhy? lNo guarantee that the class file was generated by a Java compiler lEnhance runtime performance uExamples lThere are no operand stack overflows or underflows. lAll local variable uses and stores are valid. lThe arguments to all the Java Virtual Machine instructions are of valid types.

oop Verification Process uPass 1 – when the class file is loaded lThe file is properly formatted, and all its data is recognized by the JVM uPass 2 – when the class file is linked lAll checks that do not involve instructions final classes are not subclassed, final methods are not overridden. Every class (except Object ) has a superclass. All field references and method references in the constant pool have valid names, valid classes, and a valid type descriptor.

oop Verification Process – cont. uPass 3 – still during linking lData-flow analysis on each method. Ensure that at any given point in the program, no matter what code path is taken to reach that point: The operand stack is always the same size and contains the same types of objects. No local variable is accessed unless it is known to contain a value of an appropriate type. Methods are invoked with the appropriate arguments. Fields are assigned only using values of appropriate types. All opcodes have appropriate type arguments on the operand stack and in the local variables uPass 4 - the first time a method is actually invoked la virtual pass whose checking is done by JVM instructions The referenced method or field exists in the given class. The currently executing method has access to the referenced method or field.

oop The Java Programming Environment Compile time environmentrun time environment A.Java B.Java C.Java Java Compiler A.class B.class C.class A.class B.class C.class Java Virtual Machine Object class String class