Programming Languages and Paradigms Activation Records in Java.

Slides:



Advertisements
Similar presentations
13 X 11 Java Lecture 3 CS 1311 Structure 13 X 11.
Advertisements

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.
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.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
Names and Bindings.
BA1 JVM arkitektur BA2 Specifikation I The Java Virtual Machine Specification specificeres bl.a.: –De grundlæggende datatyper.
Memory Management Case study (JVM & CLR) KIRAN KUMAR V KIRAN KUMAR V LENIN THUMMALAPALLI LENIN THUMMALAPALLI.
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.
IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
Memory Management & Method Calls in Java Program Execution © Allan C. Milne v
JAVA Processors and JIT Scheduling. Overview & Literature n Formulation of the problem n JAVA introduction n Description of Caffeine * Literature: “Java.
Introduction to Object-Oriented Programming CS 21a: Introduction to Computing I First Semester,
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 18.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Implications of Substitution Fall 2005 OOPD John Anthony.
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.
Run-Time Storage Organization
1 COMP 144 Programming Language Concepts Felix Hernandez-Campos Lecture 32: The Java Virtual Machine COMP 144 Programming Language Concepts Spring 2002.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
1 Memory Model of A Program, Methods Overview l Closer Look at Methods l Memory Model of JVM »Method Area »Heap »Stack l Preview: Parameter Passing.
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.
Unit 061 Java Virtual Machine (JVM) What is Java Virtual Machine? The Class Loader Subsystem Linking oVerification oPreparation oResolution Class Initialization.
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.
Processes CS 416: Operating Systems Design, Spring 2001 Department of Computer Science Rutgers University
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
1 Software Testing and Quality Assurance Lecture 31 – SWE 205 Course Objective: Basics of Programming Languages & Software Construction Techniques.
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++
Programming Languages and Paradigms Object-Oriented Programming.
1 The Java Virtual Machine Yearly Programming Project.
CS-2710 Dr. Mark L. Hornick 1 Defining and calling procedures (subroutines) in assembly And using the Stack.
Java Bytecode What is a.class file anyway? Dan Fleck George Mason University Fall 2007.
Introduction to Object-Oriented Programming
Programming in Java Unit 2. Class and variable declaration A class is best thought of as a template from which objects are created. You can create many.
Lecture 10 : Introduction to Java Virtual Machine
CSC Programming I Lecture 8 September 9, 2002.
Runtime Environments Compiler Construction Chapter 7.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1 Introduction to JVM Based on material produced by Bill Venners.
CPSC 388 – Compiler Design and Construction Runtime Environments.
Constructors CMSC 202. Object Creation Objects are created by using the operator new in statements such as… The following expression invokes a special.
Run-Time Storage Organization Compiler Design Lecture (03/23/98) Computer Science Rensselaer Polytechnic.
RUN-Time Organization Compiler phase— Before writing a code generator, we must decide how to marshal the resources of the target machine (instructions,
Processes CS 6560: Operating Systems Design. 2 Von Neuman Model Both text (program) and data reside in memory Execution cycle Fetch instruction Decode.
CSCE 314 Programming Languages JVM Dr. Hyunyoung Lee 1.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
ITEC 352 Lecture 19 Functions in Assembly. Functions + Assembly Review Questions? Project due on Friday Stacks Function activation / deactivation.
CMSC 202 Advanced Section Classes and Objects: Object Creation and Constructors.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Winter 2006CISC121 - Prof. McLeod1 Stuff No stuff today!
Chapter 9 Life & Death of an Object Stacks & Heaps; Constructors Garbage Collector (gc)
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
RealTimeSystems Lab Jong-Koo, Lim
Memory Management in Java Mr. Gerb Computer Science 4.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Design issues for Object-Oriented Languages
Storage Classes There are three places in memory where data may be placed: In Data section declared with .data in assembly language in C - Static) On the.
Java Memory Management
Functions.
The Java Virtual Machine (JVM)
Java Memory Management
Java Virtual Machine Complete subject details are available at:
Memory Allocation CS 217.
JAVA CLASSES.
Introduction to Object-Oriented Programming
RUN-TIME STORAGE Chuen-Liang Chen Department of Computer Science
Corresponds with Chapter 5
Presentation transcript:

Programming Languages and Paradigms Activation Records in Java

Activation record: A chunk of computer memory which contains the data needed for the activation of a routine Java Virtual Machine ’ s Role Loads class files needed and executes bytecodes they contain in a running program Organizes memory into structured areas

Java Virtual Machine

Runtime data areas in JVM Method area – contains class information Heap – memory for class instances and arrays PC registers – program counters for each thread Java stack – stores stack frames Native method stacks – Native methods: written in other languages

Runtime Data Areas Method Area Contains class information One for each JVM instance Shared by all threads in JVM One thread access at a time Heap Contains class instance or array (objects) One for each JVM instance Facilitates garbage collection Expands and contracts as program progresses

Objects Representation in Heap

Java Stack Each thread creates separate Java stack Contains frames: current thread ’ s state Pushing and popping of frames Runtime Data Areas: Java Stack

Local Variables Organized in an array Accessed via array indices Operand Stack Organized in an array Accessed via pushing and popping Always on top of the stack frame Work space for operations Frame Data Constant Pool Resolution: Dynamic Binding Normal Method Return No exception thrown Returns a value to the previous frame Exception Dispatch … Incoming parameter 2 Incoming parameter 1 Frame data Local variables Operand stack Outgoing parameters Current frame Next frame Stack Frame

class StackFrameExample { public static void addAndPrint() { double result = addTwoTypes(1, 88.88); System.out.println(result); } public static double addTwoTypes(int i, double d) { return i + d; } Example: Separate Stack Frames

Example: Contiguous Stack

Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++; } public void deposit( double amount ) { balance += amount; } public class Driver { public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); }

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() // In command prompt java Driver // In Java Virtual Machine Driver.main( args ) A stack frame for main() is pushed into the Java stack main() Parameters Local variables Frame data Operand stack * 100 args[0]… ab ClassLoader loads Driver to the method area

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() Parameters Local variables Frame data Operand stack * 100 args[0]… // Driver.java public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); } A stack frame for the BankAccount constructor is pushed into the Java stack Parameters BankAccount() Parameters Frame data Parameters Operand stack Local variables BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) pointer * A pointer to the BankAccount class data is created A pointer to the BankAccount pointer in the heap is created (Constant Pool Resolution) ab ClassLoader loads BankAccount to the method area

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() pointer balance 0.0 BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) Static Variables totalAccounts 0 main() BankAccount() Parameters Local variables Frame data Operand stack Parameters Frame data Parameters * * Operand stack args[0]… Local variables // BankAccount.java private double balance; private static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++; } public void deposit( double amount ) { balance += amount; } The balance variable of this instance is initialized with a default value The totalAccounts static variable of BankAccount is initialized with a default value and then assigned with 0 The balance variable of this instance is assigned with 0 totalAccounts is incremented by ab

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() Parameters Local variables Frame data Operand stack * args[0]… // Driver.java public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); } Parameters BankAccount() Parameters Frame data Parameters Operand stack Local variables BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) pointer * Static Variables totalAccounts 1 * The stack frame for the BankAccount constructor is popped from the Java stack ab balance The pointer is returned to the calling frame The pointer is popped from the operand stack and assigned to a

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() Parameters Local variables Frame data Operand stack * args[0]… // Driver.java public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); } A stack frame for the BankAccount Constructor is pushed into the Java stack Parameters BankAccount() Parameters Frame data Parameters Operand stack Local variables BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) A pointer to the BankAccount class data is created pointer balance 0.0 pointer * Static Variables totalAccounts A pointer to the BankAccount pointer in the heap is created (Constant Pool Resolution) Since the BankAccount class was already loaded in the method area, no other loading happens ab

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() balance 0.0 BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) Static Variables totalAccounts 1 main() BankAccount() Parameters Local variables Frame data Operand stack Parameters Frame data Parameters * Operand stack args[0]… Local variables // BankAccount.java private double balance; private static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++; } public void deposit( double amount ) { balance += amount; } pointer balance 0.0 pointer * Nothing happens since the totalAccounts was already initialized when the BankAccount class was first loaded totalAccounts is incremented by ab The balance variable of this instance is initialized with a default value The balance variable of this instance is assigned with 0

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 Methods main() Parameters Local variables Frame data Operand stack * args[0]… // Driver.java public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); } Parameters BankAccount() Parameters Frame data Parameters Operand stack Local variables BankAccount class Constant Pool 0 Methods BankAccount() deposit( double ) * Static Variables totalAccounts 2 * pointer balance 0.0 balance 0.0 pointer 100 ab The stack frame for the BankAccount Constructor is popped from the Java stack The pointer is popped from the operand stack and assigned to b The pointer is returned to the calling frame

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 BankAccount class Constant Pool 0 Methods main() Methods BankAccount() deposit( double ) pointer balance 0.0 balance 0.0 Static Variables totalAccounts 2 main() Parameters Local variables Frame data Operand stack * args[0]… // Driver.java public static void main( String[] args ) { BankAccount a = new BankAccount(); BankAccount b = new BankAccount(); b.deposit( 100 ); } Parameters deposit( double ) Parameters Frame data Parameters Operand stack Local variables b The object reference to the instance is always put as the first local variable of a stack frame 100 ab b amount=100 A stack frame for the deposit method of instance ‘b’ is pushed into the Java stack 100 is popped from the operand stack and put into the next frame’s parameters

Method Area Heap Driver class Constant Pool “BankAccount” a “BankAccount” b 100 BankAccount class Constant Pool 0 Methods main() Methods BankAccount() deposit( double ) pointer balance balance 0.0 Static Variables totalAccounts 2 main() BankAccount() Parameters Local variables Frame data Operand stack Parameters Frame data Parameters * Operand stack args[0]… // BankAccount.java private double balance; private static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++; } public void deposit( double amount ) { balance += amount; } Local variables The frame knows which balance to modify because of the object reference ab b amount=