301AA - Advanced Programming [AP-2017]

Similar documents
301AA - Advanced Programming

301AA - Advanced Programming [AP-2017]

Compiling Techniques

Agenda. CSE P 501 Compilers. Java Implementation Overview. JVM Architecture. JVM Runtime Data Areas (1) JVM Data Types. CSE P 501 Su04 T-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

301AA - Advanced Programming [AP-2017]

Programming Languages and Techniques (CIS120)

301AA - Advanced Programming [AP-2017]

Architecture of so-ware systems

Na.ve POSIX Threading Library (NPTL)

CONTROL FLOW ANALYSES!

High-Level Language VMs

Java: framework overview and in-the-small features

Course Overview. PART I: overview material. PART II: inside a compiler. PART III: conclusion

Principles of Programming Languages

Run-time Program Management. Hwansoo Han

JVM. What This Topic is About. Course Overview. Recap: Interpretive Compilers. Abstract Machines. Abstract Machines. Class Files and Class File Format

Chapter 1 GETTING STARTED. SYS-ED/ Computer Education Techniques, Inc.

Quiz on Tuesday April 13. CS 361 Concurrent programming Drexel University Fall 2004 Lecture 4. Java facts and questions. Things to try in Java

5 Distributed Objects: The Java Approach

Another difference is that the kernel includes only the suspend to memory mechanism, and not the suspend to hard disk, which is used on PCs.

Java Internals. Frank Yellin Tim Lindholm JavaSoft

Assumptions. History

Signals and Inter-Process Communica.on

Programming Languages and Techniques (CIS120)

Virtual Machine Design

Short Notes of CS201

CS321 Languages and Compiler Design I. Winter 2012 Lecture 2

EDAN65: Compilers, Lecture 13 Run;me systems for object- oriented languages. Görel Hedin Revised:

Processes. Johan Montelius KTH

CS201 - Introduction to Programming Glossary By

MethodHandlesArrayElementGetterBench.testCreate Analysis. Copyright 2016, Oracle and/or its affiliates. All rights reserved.

code://rubinius/technical

A process. the stack

Dongseok Jang Zachary Tatlock. UC San Diego Washington

Under the Hood: The Java Virtual Machine. Lecture 23 CS2110 Fall 2008

Special Topics: Programming Languages

Tizen/Artik IoT Lecture Chapter 3. JerryScript Parser & VM

Computer Systems A Programmer s Perspective 1 (Beta Draft)

Programming Languages FILS Andrei Vasilateanu

CPSC 3740 Programming Languages University of Lethbridge. Data Types

Effec%ve So*ware. Lecture 9: JVM - Memory Analysis, Data Structures, Object Alloca=on. David Šišlák

DAD Lab. 1 Introduc7on to C#

Types II. Hwansoo Han

Delft-Java Link Translation Buffer

CSc 453 Interpreters & Interpretation

Managed runtimes & garbage collection. CSE 6341 Some slides by Kathryn McKinley

MEMORY MANAGEMENT IN C++ AND JAVA

Introduction to Java. Lecture 1 COP 3252 Summer May 16, 2017

Managed runtimes & garbage collection

JAVA An overview for C++ programmers

Outline. Java Models for variables Types and type checking, type safety Interpretation vs. compilation. Reasoning about code. CSCI 2600 Spring

Pointers, Dynamic Data, and Reference Types

Java and C II. CSE 351 Spring Instructor: Ruth Anderson

Notes of the course - Advanced Programming. Barbara Russo

JAVA PERFORMANCE. PR SW2 S18 Dr. Prähofer DI Leopoldseder

Announcements. My office hours are today in Gates 160 from 1PM-3PM. Programming Project 3 checkpoint due tomorrow night at 11:59PM.

Process Address Spaces and Binary Formats

Project. there are a couple of 3 person teams. a new drop with new type checking is coming. regroup or see me or forever hold your peace

The issues. Programming in C++ Common storage modes. Static storage in C++ Session 8 Memory Management

B.V. Patel Institute of BMC & IT, UTU 2014

StackVsHeap SPL/2010 SPL/20

Threads Questions Important Questions

Concepts Lite. Constraining Template Arguments with Predicates. Andrew Su9on, Bjarne Stroustrup, Gabriel Dos Reis Texas A&M University

15CS45 : OBJECT ORIENTED CONCEPTS

Java Performance: The Definitive Guide

Today. Instance Method Dispatch. Instance Method Dispatch. Instance Method Dispatch 11/29/11. today. last time

Java On Steroids: Sun s High-Performance Java Implementation. History

Certified Core Java Developer VS-1036

SABLEJIT: A Retargetable Just-In-Time Compiler for a Portable Virtual Machine p. 1

CS 61C: Great Ideas in Computer Architecture Introduc)on to C, Part III

Administration CS 412/413. Why build a compiler? Compilers. Architectural independence. Source-to-source translator

Chapter 8 :: Composite Types

Operating Systems CMPSCI 377, Lec 2 Intro to C/C++ Prashant Shenoy University of Massachusetts Amherst

Introduction to Java Programming

Introduction to Java

CS577 Modern Language Processors. Spring 2018 Lecture Interpreters

Chapter 5. Names, Bindings, and Scopes

Inheritance, Polymorphism and the Object Memory Model

Memory Management In C++ And Java

Structure of Programming Languages Lecture 10

CS 231 Data Structures and Algorithms, Fall 2016

Compiler construction 2009

CA341 - Comparative Programming Languages

JVM ByteCode Interpreter

Practical Malware Analysis

Research opportuni/es with me

CSE 504: Compiler Design. Runtime Environments

OS and Computer Architecture. Chapter 3: Operating-System Structures. Common System Components. Process Management

Program Dynamic Analysis. Overview

3/15/18. Overview. Program Dynamic Analysis. What is dynamic analysis? [3] Why dynamic analysis? Why dynamic analysis? [3]

Chapter 3: Operating-System Structures

Lecture 8 Dynamic Memory Allocation

Programming Languages and Techniques (CIS120)

Index. object lifetimes, and ownership, use after change by an alias errors, use after drop errors, BTreeMap, 309

Run-time Environments - 3

CS555: Distributed Systems [Fall 2017] Dept. Of Computer Science, Colorado State University

Compiler construction 2009

Crash Course in Java. Why Java? Java notes for C++ programmers. Network Programming in Java is very different than in C/C++

TinyVM: User's Guide

Transcription:

301AA - Advanced Programming [AP-2017] Lecturer: Andrea Corradini andrea@di.unipi.it Tutor: Lillo GalleBa galleba@di.unipi.it Department of Computer Science, Pisa Academic Year 2017/18 AP-2017-04: Run&me Systems and intro to JVM

Overview RunNme Systems The Java RunNme Environment The JVM as an abstract machine JVM Data Types JVM RunNme Data Areas MulNthreading Per-thread Data Areas Dynamic Linking JIT compilanon Method Area 2

RunNme system Every programming language defines an execu%on model A run%me system implements (part of) such execunon model, providing support during the execunon of corresponding programs Run%me support is needed both by interpreted and by compiled programs, even if typically less by the laber 3

RunNme system (2) The runnme system can be made of Code in the execunng program generated by the compiler Code running in other threads/processes during program execunon Language libraries OperaNng systems funcnonalines The interpreter / virtual machine itself 4

RunNme Support needed for Memory management Stack management: Push/pop of acnvanon records Heap management: allocanon, garbage collecnon Input/Output Interface to file system / network sockets / I/O devices InteracNon with the run%me environment, state values accessible during execunon (eg. environment variables) acnve ennnes like disk drives and people via keyboards. 5

RunNme Support needed for (2) Parallel execunon via threads/tasks/processes Dynamic type checking and dynamic binding Dynamic loading and linking of modules Debugging Code generanon (for JIT compilanon) and OpNmizaNon VerificaNon and monitoring 6

Java RunNme Enviroment - JRE Includes all what is needed to run compiled Java programs JVM Java Virtual Machine JCL Java Class Library (Java API) We shall focus on the JVM as a real runnme system covering most of the funcnonalines just listed Reference documentanon: The Java TM Virtual Machine SpecificaNon, Java SE 8 EdiNon https://docs.oracle.com/javase/specs/jvms/se8/jvms8.pdf! The Java Language SpecificaNon, Java SE 8 EdiNon https://docs.oracle.com/javase/specs/jls/se8/jls8.pdf! è Java 9 officially released on September 21, 2017 7

What is the JVM? The JVM is an abstract machine in the true sense of the word. The JVM specificanon does not give implementanon details like memory layout of run-nme data area, garbage-collecnon algorithm, internal opnmizanon (can be dependent on target OS/plagorm, performance requirements, etc.) The JVM specificanon defines a machine independent class file format that all JVM implementanons must support The JVM imposes strong syntac%c and structural constraints on the code in a class file. Any language with funcnonality that can be expressed in terms of a valid class file can be hosted by the JVM 8

ExecuNon model JVM is a mul&-threaded stack based machine JVM instrucnons implicitly take arguments from the top of the operand stack of the current frame put their result on the top of the operand stack The operand stack is used to pass arguments to methods return a result from a method store intermediate results while evaluanng expressions store local variables 9

Java Abstact Machine Hierarchy 10

Class Files and Class File Format External representa%on (plagorm independent).class files load JVM Internal representa%on (implementanon dependent) classes priminve types objects arrays methods strings 11

JVM Data Types Primi%ve types: boolean: boolean (support only for arrays) numeric integral: byte, short, int, long, char! numeric floanng point: float, double! internal, for excepnon handling: returnaddress! Reference types: class types array types interface types Note: No type informanon on local variables at runnme Types of operands specified by opcodes (eg: iadd, fadd,.) 12

Object RepresentaNon Lep to the implementanon Including concrete value of null This add extra level of indirecnon need pointers to instance data and class data make garbage collecnon easier Object representanon must include mutex lock GC state (flags) 13

JVM RunNme Data Areas Per Thread Area Shared among Threads 14 14

Threads JVM allows mulnple threads per applicanon, starnng with main Created as instances of Thread invoking start() (which invokes run() )! Several background (daemon) system threads for Garbage collecnon, finalizanon Signal dispatching CompilaNon, etc. Threads can be supported by Nme-slicing and/or mulnple processors 15

Threads (2) Threads have shared access to heap and persistent memory Complex specificanon of consistency model volanles working memory vs. general store non-atomic longs and doubles The Java programming language memory model prescribes the behaviour of mulnthreaded programs (JLS-8 Ch. 17) 16

{ y o O [ Java Thread Life Cycle Object.notify() Thread.interrupt() timeout waiting sleep finished Thread.interrupt() Thread.sleep() suspended Object.wait() Thread.start() / ready f expired time slot or Thread.yield() selected / in execution terminated return from run() o Thread.stop() I/O data ready or monitor free blocked I/O or monitor request 17

Per Thread Data Areas pc: pointer to next instrucnon in method area undefined if current method is na&ve The java stack: a stack of frames (or ac&va&on records). A new frame is created each Nme a method is invoked and it is destroyed when the method completes. The JVMS does not require that frames are allocated connguously The na%ve stack: is used for invocanon of nanve funcnons, through the JNI (Java NaNve Interface) When a nanve funcnon is invoked, eg. a C funcnon, execunon connnues using the nanve stack NaNve funcnons can call back Java methods, which use the Java stack 18

Structure of frames Local Variable Array (32 bits) containing Reference to this (if instance method) Method parameters Local variables Operand Stack to support evaluanon of expressions and evalutanon of the method Most JVM bytecodes manipulate the stack Reference to Constant Pool of current class 19

Dynamic Linking (1) The reference to the constant pool for the current class helps to support dynamic linking. In C/C++ typically mulnple object files are linked together to produce an executable or dll. During the linking phase symbolic references are replaced with an actual memory address relanve to the final executable. In Java this linking phase is done dynamically at runnme. When a Java class is compiled, all references to variables and methods are stored in the class's constant pool as a symbolic reference. 20

Dynamic Linking (2) The JVM implementanon can choose when to resolve symbolic references. Eager or sta%c resolu%on: when the class file is verified aper being loaded Lazy or late resolu%on: when the symbolic reference is used for the first Nme The JVM has to behave as if the resolunon occurred when each reference is first used and throw any resolunon errors at this point. Binding is the process of the ennty (field, method or class) idennfied by the symbolic reference being replaced by a direct reference This only happens once because the symbolic reference is completely replaced in the constant pool If the symbolic reference refers to a class that has not yet been resolved then this class will be loaded. 21

Data Areas Shared by Threads: Heap Memory for objects and arrays; unlike C/C++ they are never allocated to stack Explicit deallocanon not supported. Only by garbage collecnon. The HotSpot JVM includes four Genera%onal Garbage Collec%on Algorithms 22

Data Areas Shared by Threads: Non-Heap Memory for objects which are never deallocated, needed for the JVM execunon Method area Interned strings Code cache for JIT 23

JIT compilanon The Hotspot JVM (and other JVMs) profiles the code during interpretanon, looking for hot areas of byte code that are executed regularly These parts are compiled to nanve code. Such code is then stored in the code cache in non-heap memory. 24

Method area The memory where class files are loaded. For each class: Classloader Reference From the class file: Run Time Constant Pool Field data Method data Method code Note: Method area is shared among thread. Access to it has to be thread safe. Changes of method area when: A new class is loaded A symbolic link is resolved by dynamic linking 25