JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.

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

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.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Java security (in a nutshell)
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.
© Vinny Cahill 1 Classes in Java. © Vinny Cahill 2 Writing a Java class Recall the program to calculate the area and perimeter of a rectangle of given.
JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections.
Unit 021 Abstract Classes What is an Abstract Class? Properties of an Abstract Class Discovering Abstract Classes.
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.
JVM-1 Introduction to Java Virtual Machine. JVM-2 Outline Java Language, Java Virtual Machine and Java Platform Organization of Java Virtual Machine Garbage.
Scott Grissom, copyright 2004Ch 3: Java Features Slide 1 Why Java? It is object-oriented provides many ready to use classes platform independent modern.
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.
Initialization George Blank Subba Reddy Daka. Importance of Initialization Java classes are initialized and have predictable default values. These values.
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.
1 Memory Model of A Program, Methods Overview l Memory Model of JVM »Method Area »Heap »Stack.
1 Chapter 8 Objects and Classes. 2 Motivations After learning the preceding chapters, you are capable of solving many programming problems using selections,
UML Basics & Access Modifier
Appendix A.2: Review of Java and Object-Oriented Programming: Part 2 “For the object-oriented project, remember that the primary unit of decomposition.
1 Inheritance and Polymorphism Chapter 9. 2 Polymorphism, Dynamic Binding and Generic Programming public class Test { public static void main(String[]
Chapter 6 Class Inheritance F Superclasses and Subclasses F Keywords: super F Overriding methods F The Object Class F Modifiers: protected, final and abstract.
CSM-Java Programming-I Spring,2005 Objects and Classes Overview Lesson - 1.
1 The Java Virtual Machine Yearly Programming Project.
 Java Programming Environment  Creating Simple Java Application  Lexical Issues  Java Class Library.
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
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
1 Comp 104: Operating Systems Concepts Java Development and Run-Time Store Organisation.
1 Introduction to JVM Based on material produced by Bill Venners.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
Java 2 security model Valentina Casola. Components of Java the development environment –development lifecycle –Java language features –class files and.
Programming With Java ICS201 University Of Hail1 Chapter 13 Interfaces.
Centre for Computer Technology ICT214 Object Oriented Design and Programming Week 02 – Classes, Objects, Instances Richard Salomon and Umesh Patel Centre.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
1 The finalize, clone, and getClass Methods  The finalize method is invoked by the garbage collector on an object when the object becomes garbage.  The.
CSE 143 Lecture 20 Abstract classes. 2 Circle public class Circle { private double radius; public Circle(double radius) { this.radius = radius; } public.
Inheritance CSI 1101 Nour El Kadri. OOP  We have seen that object-oriented programming (OOP) helps organizing and maintaining large software systems.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
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++;
1 Static Variable and Method Lecture 9 by Dr. Norazah Yusof.
1 Interfaces and Abstract Classes The ability to define the behavior of an object without specifying that behavior is to be implemented Interface class.
1 Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
OOP Basics Classes & Methods (c) IDMS/SQL News
Reference Types CSE301 University of Sunderland Harry R Erwin, PhD.
Creating Java Applications (Software Development Life Cycle) 1. specify the problem requirements - clarify 2. analyze the problem - Input? Processes? Output.
RealTimeSystems Lab Jong-Koo, Lim
Objects and Classes. F OO Programming Concepts F Creating Objects and Object Reference Variables –Differences between primitive data type and object type.
Design issues for Object-Oriented Languages
CS 432: Compiler Construction Lecture 15
Java Memory Management
Inheritance ITI1121 Nour El Kadri.
Java Memory Management
Inheritance and Polymorphism
Java Programming Language
CSE 413, Autumn 2002 Programming Languages
Java security (in a nutshell)
Topic: JAVA .Class File Structure
Java Virtual Machine Complete subject details are available at:
Multithreading in Java
EE 422C Java Reflection re·flec·tion rəˈflekSH(ə)n/ noun
Java Programming Language
Chapter 14 Abstract Classes and Interfaces
Object Oriented Programming in java
Chapter 11 Inheritance and Polymorphism
Presentation transcript:

JVM-1 Java Virtual Machine Reading Assignment: Chapter 1: All Chapter 3: Sections 5, 6 Chapter 5: Sections 1 - 5

JVM-2 Java Virtual Machine (JVM) What is Java Virtual Machine? The Class Loader Subsystem Linking oVerification oPreparation oResolution Class Initialization Class Instantiation

JVM-3 What is JVM JVM is a component of the Java system that interprets and executes the instructions in our class files. The following figure shows a block diagram of the JVM that includes its major subsystems and memory areas.

JVM-4 What is JVM Cont’d Each instance of the JVM has one method area, one heap, and one or more stacks - one for each thread. –Each JVM Thread has its own program counter (pc) When JVM loads a class file, it puts its information in the method area. As the program runs, all objects instantiated are stored in the heap. The stack area is used to store activation records as a program runs.

JVM-5 The Class Loader Subsystem The class loader performs three main functions of JVM, namely: loading, linking & initialization. The linking process consists of three sub-tasks, namely, verification, preparation, and resolution, as shown in the following figure. These activities are performed in a strict order as shown in the figure.

JVM-6 Class Loading Loading means reading the class file for a type, parsing it to get its information, and storing the information in the method area. For each type it loads, the JVM must store the following kinds of information in the method area: –The fully qualified name of the type –The fully qualified name of the type's direct superclass or if the type is an interface, a list of its direct super interfaces. –Whether the type is a class or an interface –The type's modifiers ( public, abstract, final, etc) –Constant pool for the type: constants and symbolic references. –Field info : name, type and modifiers of variables (not constants) –Method info : name, return type, number & types of parameters, modifiers, bytecodes, size of stack frame and exception table.

JVM-7 Class Loading – Cont’d The end of the loading process is the creation of an instance of java.lang.Class for the loaded type. The purpose is to give access to some of the information captured in the method area for the type, to the programmer. Some of the methods of the class java.lang.Class are: 1.public String getName() 2.public Class getSupClass() 3.public boolean isInterface() 4.public Class[] getInterfaces() 5.public Method[] getMethods() 6.public Fields[] getFields() 7.public Constructor[] getConstructors() Note that for any loaded type T, only one instance of java.lang.Class is created even if T is used several times in an application. To use the above methods, we need to first call the getClass method on any instance of T to get the reference to the Class instance for T.

JVM-8 Class Loading –Cont’d 1.public abstract class Shape{ 2.public String name(){ 3.return getClass().getName(); 4.} 5.public abstract double area(); 6.public abstract double perimeter(); 7.} 1.public class Circle extends Shape{ 2.public double radius; 3.public Circle(double r){ 4.radius = r; 5.} 6.public double area(){ 7.return Math.PI * (radius * radius); 8.} 9.public double perimeter(){ 10.return (2.0 * Math.PI )*radius; 11.} 12.}

JVM-9 Class Loading –Cont’d 1.public class Rectangle extends Shape{ 2.private double length; 3.private double width; 4. 5.public Rectangle(double length, double width){ 6.this.length = length; 7.this.width = width; 8.} 9.public double area(){ 10.return length * width; 11.} 12.public double perimeter(){ 13.return 2 * (length + width ); 14.} 15.} 1.public class Square extends Rectangle{ 2.public Square(double length){ 3.super(length, length); 4.} 5.}

JVM-10 Class Loading –Cont’d 1.import java.lang.reflect.Method; 2.public class TestClassClass{ 3.public static void main(String[] args){ 4.Circle circle = new Circle(10); 5.Class circleClassInfo = circle.getClass(); 6.System.out.println("Class name is :"+circleClassInfo.getName()); 7.System.out.println("Parent is :"+circleClassInfo.getSuperclass()); 8. Method[] methods = circleClassInfo.getMethods(); 9.System.out.println("\nMethods are: "); 10.for(int i = 0; i<methods.length; i++) 11.System.out.println(methods[i]); 12.} 13.}

JVM-11 Class Loading – Cont’d What if we do not have an object of a class T? Use the following. Public static Class forName(String className) throws ClassNotFoundException 1.import java.lang.reflect.Method; 2.public class TestClassClass2{ 3.public static void main(String[] args) throws ClassNotFoundException{ 4.Class test = Class.forName("TestClassClass2"); 5.System.out.println("\nClass name is:" +test.getName()); 6.System.out.println("Superclass is: d " + test.getSuperclass()); 7.System.out.println("\nMethods are: "); 8.Method[] methods = test.getMethods(); 9.for(int i = 0; i<methods.length; i++) 10.System.out.println(methods[i]); 11.} 12.}

JVM-12 Linking : Verification The next process handled by the class loader is Linking. This involves three sub-processes: Verification, Preparation and Resolution. Verification is the process of ensuring that binary representation of a class is structurally correct. The JVM has to make sure that a file it is asked to load was generated by a valid compiler and it is well formed. Class B may be a valid sub-class of A at the time A and B were compiled, but class A may have been changed and re-compiled. Example of some of the things that are checked at verification are: –Every method is provided with a structurally correct signature. –Every instruction obeys the type discipline of the Java language –Every branch instruction branches to the start not middle of another instruction.

JVM-13 Preparation In this phase, the Java virtual machine allocates memory for the class (i.e static) variables and sets them to default initial values. Note that class variables are not initialized to their proper initial values until the initialization phase - no java code is executed until initialization. The default values for the various types are shown below:

JVM-14 Resolution is the process of replacing symbolic names for types, fields and methods used by a loaded type with their actual references. Symbolic references are resolved into direct references by searching through the method area to locate the referenced entity. For the class below, at the loading phase, the class loader would have loaded the classes: TestClassClass3, Circle, Shape, System, & Object. 1.public class TestClassClass3{ 2.public static void main(String[] args){ 3.Circle circle = new Circle(10); 4.Class circleClassInfo = circle.getClass(); 5.System.out.println("Parent is: "+circleClassInfo.getSuperclass()); 6.} 7.} The names of these classes would have been stored in the constant pool for TestClassClass3. In this phase, the names are replaced with their actual references. Resolution