1 The Java Virtual Machine Yearly Programming Project.

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.
Names and Bindings.
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 6.
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.
Lab Information Security Using Java (Review) Lab#0 Omaima Al-Matrafi.
Lab#1 (14/3/1431h) Introduction To java programming cs425
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
George Blank University Lecturer. CS 602 Java and the Web Object Oriented Software Development Using Java Chapter 4.
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.
JETT 2003 Java.compareTo(C++). JAVA Java Platform consists of 4 parts: –Java Language –Java API –Java class format –Java Virtual Machine.
Encapsulation by Subprograms and Type Definitions
Run-Time Storage Organization
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Session 1 CS-240 Data Structures Binghamton University Dick Steflik.
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.
1 Languages and Compilers (SProg og Oversættere) Lecture 9 (2) Bent Thomsen Department of Computer Science Aalborg University With acknowledgement to Norm.
1 Further OO Concepts II – Java Program at run-time Overview l Steps in Executing a Java Program. l Loading l Linking l Initialization l Creation of Objects.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
Peter Juszczyk CS 492/493 - ISGS. // Is this C# or Java? class TestApp { static void Main() { int counter = 0; counter++; } } The answer is C# - In C#
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.
David Evans CS201j: Engineering Software University of Virginia Computer Science Lecture 18: 0xCAFEBABE (Java Byte Codes)
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
UNDER THE HOOD: THE JAVA VIRTUAL MACHINE Lecture 24 – CS2110 – Fall 2009.
Types and Inheritances Compiler Design Lecture (03/04//98) Computer Science Rensselaer Polytechnic.
1 Java.class File Format 陳正佳. 2 Java Virtual Machine the cornerstone of Sun's Java programming language. a component of the Java technology responsible.
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.
IT253: Computer Organization Lecture 4: Instruction Set Architecture Tonga Institute of Higher Education.
Lecture 10 : Introduction to Java Virtual Machine
Runtime Environments Compiler Construction Chapter 7.
10/12/2015© Hal Perkins & UW CSEV-1 CSE P 501 – Compilers Java Implementation – JVMs, JITs &c Hal Perkins Winter 2008.
1 Introduction to JVM Based on material produced by Bill Venners.
Compiler Construction
Geoff Holmes and Bernhard Pfahringer COMP206-08S General Programming 2.
12/10/2002© 2002 Hal Perkins & UW CSET-1 CSE 582 – Compilers Java Implementation – JVMs, JITs &c Hal Perkins Autumn 2002.
Page: 1 การโปรแกรมเชิงวัตถุด้วยภาษา JAVA บุรินทร์ รุจจนพันธุ์.. ปรับปรุง 15 มิถุนายน 2552 Keyword & Data Type มหาวิทยาลัยเนชั่น.
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
CSCE 314 Programming Languages JVM Dr. Hyunyoung Lee 1.
1 Lecture 12 Java Virtual Machine:.class file Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung Institute.
Programming Languages and Paradigms Activation Records in Java.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chap. 10, Intermediate Representations J. H. Wang Dec. 27, 2011.
UNDER THE HOOD: THE JAVA VIRTUAL MACHINE II CS2110 Fall 200 Lecture 25 1.
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
RealTimeSystems Lab Jong-Koo, Lim
(Not too) Real-Time JVM (Progress Report)
Design issues for Object-Oriented Languages
Lecture 3 Translation.
The Java Virtual Machine (JVM)
CS216: Program and Data Representation
Java Primer 1: Types, Classes and Operators
Java security (in a nutshell)
Topic: JAVA .Class File Structure
Java Virtual Machine Complete subject details are available at:
Java Virtual Machine (JVM)
Java Byte Codes (0xCAFEBABE) cs205: engineering software
Byte Code Verification
Java Implementation – JVMs, JITs &c Hal Perkins Summer 2004
Java Basics Data Types in Java.
Presentation transcript:

1 The Java Virtual Machine Yearly Programming Project

2 Introduction An abstract computing machine. An instruction set Various memory areas Knows: –Nothing of the Java programming language –Only a “class” file format: Java Virtual Machine instructions (bytecodes) a symbol table other ancillary information. Secure!

3 Data Types Two kinds of types: primitive and reference. –Primitive: byte, short, int, long, char, float, double, returnAddress Two kinds of values: primitive and reference. All type checking is done at compile time: –data is not tagged –data is not inspectable to determine types. Security: the JVM checks prior to loading that the instructions are type correct

4 Objects Explicit support for objects: instance or array. All objects: JVM type reference. –Can be thought of as pointers to objects. –More than one reference may exist to an object. – Objects are only operated on via values of type reference. Reference Types –Kinds: class, interface, array

5 Stack Each thread has a private stack –No direct operations –Can be implemented as a heap –Either fixed or varying size A stack stores frames. Each frame has: local variables partial results operand stack data for method invocation and return. There is always a current frame for each thread Frames use only words. Two words for long and double.

6 Other Areas of Memory Heap –Shared among all threads –Pool for all classes and arrays. –Reclaimed by an automatic storage management system Method area –Similar to text segment –Shared among all threads –Subject to memory management! Constant Pool Native methods stack

7 Operand Stack –A stack machine: No registers! –Computation: operations on operand stack –IADD instruction: pop first value pop second value push their sum –Type checked: Illegal to push two ints and pop a long

8 Local Variables Serve as registers Indexed by numbers: 0, 1, 2, 3,... Operation (also for constant pool) –Loaded (pushed) into the stack –Stored from a stack Similar operations for the constant pool

9 Instruction Set Stack manipulation: Load/Store/Pop/Dup Arithmetic, type conversion Control: goto, if, call, exception, syncornization Object creation: new, newarray Object manipulation: –field access (static and instance) –array access –typing: check cast and object type, get array length

10 The class File Contains one Java type, either a class or an interface. A stream of 8-bit bytes Described using C like structures –Uses types u1, u2, and u4 for represent an unsigned one-, two-, or four-byte quantity. –No alignment or padding –Can be read using readUnsignedByte, readUnsignedShort, and readInt –Uses pseudo-array notation, even for varying size records

11 The Class File Structure ClassFile { u4 magic; u2 minor_version; u2 major_version; u2 constant_pool_count; cp_info constant_pool[constant_pool_count-1]; u2 access_flags; // is-abstract, private, and other flags u2 this_class; // index to constant pool u2 super_class; // index to constant pool u2 interfaces_count; u2 interfaces[interfaces_count]; // indices of constant pool u2 fields_count; field_info fields[fields_count]; u2 methods_count; method_info methods[methods_count]; u2 attributes_count; attribute_info attributes[attributes_count]; // Currently only source file information }

12 The Constant Pool cp_info { u1 tag; u1 info[]; } Tags for: class name, field and method references, strings of two kinds, various numerical constants, etc. The info field varies accordingly, may also include other constant pool references.

13 Methods Include both regular and construction methods method_info { u2 access_flags; // is-private, is-final, etc. u2 name_index; // index into the constant pool u2 descriptor_index; // index into the constant pool, giving method signature u2 attributes_count; attribute_info attributes[attributes_count]; // currently, only Code and Exceptions are required // optional: line number information }

14 The Code Attribute Code_attribute { u2 attribute_name_index; // Always the word “Code” u4 attribute_length; // Size of this structure u2 max_stack; // The maximal # words in the operand stack u2 max_locals; // Max # of registers used u4 code_length; u1 code[code_length]; // The byte codes, finally! u2 exception_table_length; { u2 start_pc; u2 end_pc; u2 handler_pc; u2 catch_type; } exception_table[exception_table_length]; u2 attributes_count; attribute_info attributes[attributes_count]; }

15 Verification of Class Files Compiler: generate only valid class file JVM: verify that the class file is valid –Security –Version skew Verification: –Static: basic structure –Static or Dynamic: type checking Static implementation by Sun’s JVM

16 The Verification Process Pass 1: ensures basic format integrity: magic number, lengths, etc. Pass 2: All additional verification that can be done without looking at the code array of the Code attribute. –Final class is not subclassed. –Has a super class. –References to constant pool. Pass 3: Data-flow analysis on each method.

17 Data Flow Analysis: 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.

18 Pass 4 Only for efficiency reasons Example: another method that returns an instance of class A. –Instance is only assigned to a field of the same type- No need to check that class A exists. –If instance is assigned to type B, the definitions of both A and B must be loaded in to ensure that A is a subclass of B. Implemented dynamically, at the first time a method is invoked or a field is accessed.