JVM Internals Douglas Q. Hawkins. JVM Internals Bytecode Garbage Collection Optimizations Compile Time Run Time.

Slides:



Advertisements
Similar presentations
Escape Sequences \n newline \t tab \b backspace \r carriage return
Advertisements

wwwcsif.cs.ucdavis.edu/~jacksoni
1 Multithreaded Programming in Java. 2 Agenda Introduction Thread Applications Defining Threads Java Threads and States Examples.
Etter/Ingber Arrays and Matrices. Etter/Ingber One-Dimensional Arrays 4 An array is an indexed data structure 4 All variables stored in an array are of.
1 Copyright © 2005, Oracle. All rights reserved. Introducing the Java and Oracle Platforms.
Graphics Primitives: line
Memory Management Chapter FourteenModern Programming Languages, 2nd ed.1.
Java Virtual Machine Profiling
1 ECSU-NAM 2OO8 STUDENT RESEARCH INSTITUTE IN COMPUTATIONAL SCIENCE- SCIENTIFIC VISUALIZATION Programming in Java: Problem Solving Moderator: Dr. Jamiiru.
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.
Importing methods in the Java library. Previously discussed Method = a collection of statements that performs a complex (useful) task A method is identified.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
Introduction to Programming G51PRG University of Nottingham Revision 1
Dynamic Memory Allocation in C.  What is Memory What is Memory  Memory Allocation in C Memory Allocation in C  Difference b\w static memory allocation.
Air Force Institute of Technology Electrical and Computer Engineering
50.003: Elements of Software Construction Week 6 Thread Safety and Synchronization.
Core Java Lecture 4-5. What We Will Cover Today What Are Methods Scope and Life Time of Variables Command Line Arguments Use of static keyword in Java.
Method main Point p1 = new Point(5, 6); Point p2 = new Point(10, 11); System.out.println(p1.getX()); System.out.println( Point.num );
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Yoshi
Portability and Safety Mahdi Milani Fard Dec, 2006 Java.
NUMA Tuning for Java Server Applications Mustafa M. Tikir.
CSE 2501 Review Declaring a variable allocates space for the type of datum it is to store int x; // allocates space for an int int *px; // allocates space.
Java for High Performance Computing Jordi Garcia Almiñana 14 de Octubre de 1998 de la era post-internet.
JETT 2003 Java.compareTo(C++). JAVA Java Platform consists of 4 parts: –Java Language –Java API –Java class format –Java Virtual Machine.
Programming Language Semantics Java Threads and Locks Informal Introduction The Java Specification Language Chapter 17.
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
1 Java (vs. C++). 2 Object-oriented Programming Java and C++ are the most popular object-oriented programming languages Java Sun Microsystems in 1990.
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 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.
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.
March 2005Java Programming1. March 2005Java Programming2 Why Java? Platform independence Object Oriented design Run-time checks (fewer bugs) Exception.
CSc 453 Interpreters & Interpretation Saumya Debray The University of Arizona Tucson.
Lecture 1: Overview of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++ Designed.
CMSC 341 Introduction to Java Based on tutorial by Rebecca Hasti at
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.
Programming in Java; Instructor:Moorthy Introduction, Objects, Classes, Libraries1 Programming in Java Introduction.
Java Security. Topics Intro to the Java Sandbox Language Level Security Run Time Security Evolution of Security Sandbox Models The Security Manager.
1 The Java Virtual Machine Yearly Programming Project.
Flex Compiler Compiler Case Study By Mee Ka Chang.
Adapted from Prof. Necula UCB CS 1641 Overview of COOL ICOM 4029 Lecture 2 ICOM 4029 Fall 2008.
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.
Java Virtual Machine Case Study on the Design of JikesRVM.
Introduction and Features of Java. What is java? Developed by Sun Microsystems (James Gosling) A general-purpose object-oriented language Based on C/C++
1162 JDK 5.0 Features Christian Kemper Principal Architect Borland.
1 Object Oriented Programming Lecture IX Some notes on Java Performance with aspects on execution time and memory consumption.
Garbage Collection and Classloading Java Garbage Collectors  Eden Space  Surviver Space  Tenured Gen  Perm Gen  Garbage Collection Notes Classloading.
CSC Multiprocessor Programming, Spring, 2012 Chapter 11 – Performance and Scalability Dr. Dale E. Parson, week 12.
CSE 598c – Virtual Machines Survey Proposal: Improving Performance for the JVM Sandra Rueda.
Threads and Singleton. Threads  The JVM allows multiple “threads of execution”  Essentially separate programs running concurrently in one memory space.
Programming Languages and Paradigms Activation Records in Java.
Duke CPS Java: make it run, make it right, make it fast (see Byte, May 1998, for more details) l “Java isn’t fast enough for ‘real’ applications”
Chapter 9 Introduction to Arrays Fundamentals of Java.
RealTimeSystems Lab Jong-Koo, Lim
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Sung-Dong Kim, Dept. of Computer Engineering, Hansung University Java - Introduction.
Topic: Java Garbage Collection
The Java Virtual Machine (JVM)
JRuby Charles Oliver Nutter
Runtime Analysis of Hotspot Java Virtual Machine
Java Virtual Machine Complete subject details are available at:
Java Virtual Machine : Semantics and Optimization
Presented by: Huston Bokinsky Ying Zhang 25 April, 2013
CSc 453 Interpreters & Interpretation
CSc 453 Interpreters & Interpretation
Presentation transcript:

JVM Internals Douglas Q. Hawkins

JVM Internals Bytecode Garbage Collection Optimizations Compile Time Run Time

Java Bytecode

Stack Based Local Variable Space Local Variables Operand Stack

Operation Types Load and Store Arithmetic and Logic Type Conversion Control Transfer Object Creation and Manipulation Operand Stack Method Invocation

Demo

Garbage Collection

Generational Garbage Collection Segmented into Young, Old, and Permanent Generations Types of Collectors Parallel - across multiple threads Concurrent - while program runs

Demo

Garbage Collection Pattern MinorMajor Major Again - for objects with finalize Soft References Major Major Again - for objects with finalize Throw OutOfMemoryError

Optimizations

Optimizations Just In Time Compilation Purely Interpreted Ahead of Time Compilation Almost No Compile Time Optimization Most Optimizations are Runtime

Compile Time Demo

Is This Optimized? double sumU = 0, sumV = 0; for ( int i = 0; i < 100; ++i ) { Vector2D vector = new Vector2D( i, i ); Vector2D vector = new Vector2D( i, i ); synchronized ( vector ) { synchronized ( vector ) { sumU += vector.getU(); sumU += vector.getU(); sumV += vector.getV(); sumV += vector.getV(); }} How many...? Loop Iterations Heap Allocations Method Invocations Lock Operations

Common Sub-Expression Elimination int x = a + b; int y = a + b; int tmp = a + b; int x = tmp; int y = tmp;

Array Bounds Check Elimination int[] nums =... for ( int i = 0; i < nums.length; ++i ) { System.out.println( nums[ + i + ]= + nums[ i ] ); } int[] nums =... for ( int i = 0; i < nums.length; ++i ) { if ( i = nums.length ) { if ( i = nums.length ) { throw new ArrayIndexOutOfBoundsException(); throw new ArrayIndexOutOfBoundsException(); } System.out.println( nums[ + i + ]= + nums[ i ] ); }

Loop Invariant Hoisting for ( int i = 0; i < nums.length; ++i ) {...} int length = nums.length; for ( int i = 0; i < length; ++i ) {...}

Loop Unrolling int sum = 0; for ( int i = 0; i < 10; ++i ) { sum += i; sum += i;} int sum = 0; sum += 1;... sum += 9;

Method Inlining Vector vector =... double magnitude = vector.magnitude(); Vector vector =... double magnitude = Math.sqrt( vector.u*vector.u + vector.v*vector.v ); vector.u*vector.u + vector.v*vector.v ); Vector vector =... double magnitude; if ( vector instance of Vector2D ) { magnitude = Math.sqrt( magnitude = Math.sqrt( vector.u*vector.u + vector.v*vector.v ); } else { magnitude = vector.magnitude(); magnitude = vector.magnitude();} static final private virtual reflective dynamic always always always often sometimes often

Lock Coarsening StringBuffer buffer =... buffer.append( Hello ); buffer.append( name ); buffer.append( \n ); StringBuffer buffer =... lock( buffer ); buffer.append( Hello ); unlock( buffer ); lock( buffer ); buffer.append( name ); unlock( buffer ); lock( buffer ); buffer.append( \n ); unlock( buffer ); StringBuffer buffer =... lock( buffer ); buffer.append( Hello ); buffer.append( name ); buffer.append( \n ); unlock( buffer );

Other Lock Optimizations Biased Locking Adaptive Locking - Thread sleep vs. Spin lock

Escape Analysis Point p1 = new Point(x1, y1), p2 = new Point(x2, y2); synchronized ( p2 ) { synchronized ( p2 ) { double dx = p1.getX() - p2.getX(); double dx = p1.getX() - p2.getX(); synchronized ( p1 ) { double dy = p1.getY() - p2.getY(); double dy = p1.getY() - p2.getY(); } } double distance = Math.sqrt( dx*dx + dy*dy ); double distance = Math.sqrt( dx*dx + dy*dy ); double dx = x1 - x2; double dx = y1 - y2; double distance = Math.sqrt( dx*dx + dy*dy );

Run Time Demo

Resources Brian Goetz Developer Works Articles Tony Printezis Garbage Collection in the Java HotSpot Virtual Machine - Garbage Collection in the Java HotSpot Virtual Machine Java Specialist Newsletter