SlideShare a Scribd company logo
2
Most read
3
Most read
Inside Java Virtual Machine
Source: -Inside the Java Virtual Machine Bill Venners
Introduction to Java's Architecture
Why Java?
Java was designed for networks.
Its suitability for networked environments is inherent in its architecture, which enables secure, robust, platform-independent programs to be
delivered across networks and run on a great variety of computers and devices.
The Challenges and Opportunities of Networks
One presented to developers is the ichallenge wide range of devices n a networked environment.
Java addresses this challenge by of programs.enabling the creation platform-independent
Java makes it possible to create binary executables that will run unchanged on multiple platforms.
This is important in a networked environment because networks usually interconnect many different kinds of computers and devices (with diverse
, , and ).hardware architectures operating systems purposes
Another to software developers is in a networked environment.challenge security
Networks, because they allow computers to share data and distribute processing, can potentially serve as a way to break into a computer system,
enabling someone to steal information, destroy information, or steal computing resources.
As a consequence, connecting a computer to a network raises many security issues.
To address the security concerns raised by networks, Java's architecture an .comes with extensive built-in security model
One created by an omnipresent network isopportunity online software distribution
Java takes advantage of this opportunity by in across networks.enabling the transmission of binary code small pieces
This capability can make Java programs easier and cheaper to deliver than programs that are not network-mobile.
The Architecture
Java's architecture arises out of 4 , each of which is defined by a separate specification from Sun Microsystems:distinct but interrelated technologies
the Java programming language
the Java class file format
the Java Application Programming Interface
the Java Virtual Machine
When we write and run a Java program, we are tapping the power of these 4 technologies.
We can see the relationship between these 4 parts in the following figure:
Note
Java's architectural support for is focused on it takes to .network-mobility managing the time move software across a network
If we store a program on a server and download it across a network when we need it, it will likely take longer for our program to start
than if we had started the same program from a local disk.
One of the primary issues of network-mobile software is the time it takes to send a program across a network.
Java's architecture addresses this issue by rejecting the in favor of small binary pieces:traditional monolithic binary executable Jav
.a class files
Class files can travel across networks independently, and because Java programs are and ,dynamically linked dynamically extensible
an end-user needn't wait until all of a program's class files are downloaded before the program starts.
For example, Java applets demonstrated the promise of network-mobility
Java applets can run on any platform so long as there is a Java-capable browser for that platform.
As shown in the following figure, Java applets can be maintained on one server, from which they can travel across a network to many
different kinds of computers.
To update an applet, we only need to update the server.
Note
, , and – these three facets of Java's architecture work together to make JavaPlatform independence security network-mobility suitable for
the .emerging networked computing environment
Java programs are platform independent, network-delivery of software is more practical.
The same version of a program can be delivered to all the computers and devices the network interconnects.
Java's built-in security framework also helps make network-delivery of software more practical. By reducing risk, the security
framework helps to build trust in a new paradigm of network-mobile code.
We express the program in source files written in the , compile the source to , and run the classJava programming language Java class files
files on a .Java Virtual Machine
When we write our program, we (such as I/O, for example) that implement the Javaaccess system resources by calling methods in the classes
Application Programming Interface, or .Java API
Together, the and form a " " for .Java Virtual Machine Java API platform which all Java programs are compiled
In addition to being called the , the is called the .Java runtime system combination of the Java Virtual Machine and Java API Java Platform
Java programs because the Java Platform can itself be implemented in software.can run on many different kinds of computers
A Java program can run anywhere the Java Platform is present.
The Java Virtual Machine
At the heart of Java's network-orientation is the Java Virtual Machine, which supports all 3 prongs of Java's network-oriented architecture:
Platform independence
Security
Network-mobility
The Java Virtual Machine is an .abstract computer
A Java Virtual Machine's main job is to and they contain.load class files execute the bytecodes
The Java Virtual Machine contains a class loader, which from .loads class files both the program and the Java API
from the that are into the virtual machine.Only those class files Java API actually needed by a running program are loaded
The bytecodes are executed in an execution engine, which is one part of the virtual machine that can vary in different implementations.
On a Java Virtual Machine implemented in software, the simplest kind of just .execution engine interprets the bytecodes one at a time
In this scheme, the of a method are the .bytecodes compiled to native machine code first time the method is invoked
The native machine code for the method is then cached, so it can be re-used the next time that same method is invoked.
Sometimes the Java Virtual Machine is called the .Java interpreter
When running on a Java Virtual Machine that is implemented in software on top of a host operating system, a with the byJava program interacts host
invoking native methods.
In Java, there are 2 kinds of methods: and .Java method native method
A is written in the Java language, compiled to bytecodes, andJava method stored in class files.
A is written in some other language, such as C, C++, or assembly, and compiled to the native machine code of a particularnative method
processor.
When a running Java program calls a , the virtual machine loads the dynamic library that contains the native method and invokes it.native method
As the following figure, are the connection between a Java program and an underlying host operating system.native methods
Note
Another kind of execution engine, one that is but requires , is afaster more memory just-in-time compiler.
Note
are stored in a whose exact form is platform specific.Native methods dynamically linked library
While Java methods are platform independent, native methods are not.
1.
2.
The Class Loader Architecture
The Java Virtual Machine has a that allows a Java application to load classes in .flexible class loader architecture custom ways
A Java application can use 2 types of class loaders:
A "primordial" class loader
Class loader objects
The (there is only one of them)primordial class loader is a part of the Java Virtual Machine implementation.
- For example, if a Java Virtual Machine is implemented as a C program on top of an existing operating system, then the primordial class
loader will be part of that C program.
- The primordial class loader , including the classes of the , usually from the local disk.loads trusted classes Java API
At run-time, a Java application can install that , such as by downloading class files across aclass loader objects load classes in custom ways
network.
- While the primordial class loader is an intrinsic part of the virtual machine implementation, class loader objects are not.
- Instead, class loader objects are , compiled to class files, loaded into the virtual machine, and instantiated just like any otherwritten in Java
object.
We can see a graphical depiction of this architecture in the following figure.
Note
We can use to give our Java programs to the .native methods direct access resources of the underlying operating system
One native method interface – the Java Native Interface, or JNI – enables native methods to work with any Java Platform
implementation on a particular host computer.
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
The Java Class File
A Java compiler, translates the instructions of the Java source files into , the " " of the Java Virtual Machine.bytecodes machine language
In a class file, is irrespective of what platform generated the file and independent of whatever platforms mayJava byte order big-endian
eventually use it.
Architectural Tradeoffs
Although Java's are desirable, especially in a networked environment, they did not come for free.network-oriented features
As mentioned before, one of the of Java's network-oriented features is the comparedprime costs potential reduction in program execution speed
to other technologies such as C++.
Java programs can run slower than an equivalent C++ program for many reasons:
is 10 to 30 times slower than .Interpreting bytecodes native execution
can be 7 to 10 times faster than interpreting, but still not quite as fast as .Just-in-time compiling bytecodes native execution
Java programs are .dynamically linked
The Java Virtual Machine may have to wait for class files to download across a network.
Array bounds are checked on each array access.
are (no objects are created on the stack).All objects created on the heap
are forAll uses of object references checked at run-time null.
are for .All reference casts checked at run-time type safety
The is likely (though often more effective) at managing the heap than we could be if we managed itgarbage collector less efficient
directly as in C++.
in Java are the , rather than adjusting to the most efficient size on each platform as in C++.Primitive types same on every platform
in Java are . When we really need to manipulate just an ASCII string, aStrings always UNICODE Java program will be slightly less
efficient than an equivalent C++ program.
Note
When we compile and link a C++ program, the we get isexecutable binary file specific to a particular target hardware platform and
because it contains machine language specific to the target processor.operating system
Note
In addition to processor-specific machine language, another platform-dependent attribute of a traditional is thebinary executable file b
.yte order of integers
In for the Intel X86 family of processors, for example, the isexecutable binary files byte order little-endian, or lower order
byte first.
In for the PowerPC chip, however, the isexecutable binary files byte order big-endian, or higher order byte first.
Java Virtual Machine
What is a Java Virtual Machine?
We may be talking about any of 3 different things when we say , as the follows:"Java Virtual Machine"
– tthe abstract specification he abstract specification is a .concept
–a concrete implementation which exist on many platforms and come from many vendors, are either all software or a combination of hardware
and software.
a runtime instance – a runtime instance hosts a single running Java application.
The Lifetime of a Java Virtual Machine
A of the Java Virtual Machine has a clear mission in life: .runtime instance to run one Java application
When a Java application starts, a is born.runtime instance
When the application completes, the instance dies.
If we start 3 Java applications at the same time, on the same computer, using the same , we'll get 3concrete implementation Java Virtual
.Machine instances Each Java application runs inside its own Java Virtual Machine
A its solitary application by theJava Virtual Machine instance starts running invoking ()main method of some initial class.
The () method of an application's initial class the for that application's .main serves as starting point initial thread
The can in turn fire off other threads.initial thread
Inside the Java Virtual Machine, threads come in 2 flavors: and .daemon non-daemon
A is a thread , such as a thread that performs garbage collection.daemon thread ordinarily used by the virtual machine itself
The application, however, can mark any threads it creates as .daemon threads
The of an application – the one that begins at () – is a .initial thread main non-daemon thread
A Java application (the virtual machine instance continues to live) as long as are .continues to execute any non-daemon threads still running
When , the will .all non-daemon threads of a Java application terminate virtual machine instance exit
If permitted by the security manager, the application can also cause its own demise by invoking the ()exit method of class Runtime or System.
The Architecture of the Java Virtual Machine
The following figure shows a block diagram of the Java Virtual Machine that includes the and described in themajor subsystems memory areas
specification.
Each Java Virtual Machine has a class loader subsystem: a mechanism for loading types (classes and interfaces) given fully qualified names.
Each Java Virtual Machine also has an execution engine: a mechanism responsible for executing the instructions contained in the methods of
loaded classes.
Note
The Java Virtual Machine is called because it is an defined by a specification."virtual" abstract computer
Note
Each Java application runs inside of of the of the Java Virtuala runtime instance some concrete implementation abstract specification
Machine.
When a Java Virtual Machine , it needs to store many things, including bytecodes and other information it extracts from loadedruns a program memory
class files, objects the program instantiates,
parameters to methods, return values, local variables, and intermediate results of computations.
The Java Virtual Machine it into severalorganizes the memory needs to execute a program runtime data areas.
Some are shared among all of an application's threads and others are unique to individual threads.runtime data areas
Each of hasinstance the Java Virtual Machine one method area and one heap.
- These areas are running inside the virtual machine.shared by all threads
- When the , it parses information about a type from the binary data contained in the class filevirtual machine loads a class file It places
this type information into the .method area
- As the , the the program instantiates onto the .program runs virtual machine places all objects heap
See the following figure for a graphical depiction of these memory areas.
As each new comes into existence, it gets its ownthread PC register and(program counter) Java stack.
If the thread is executing a (not a native method), the value of the .Java method PC register indicates the next instruction to execute
A thread's the for the thread.Java stack stores state of Java (not native) method invocations
The includes its , the with which it was invoked, its (if any), andstate of a Java method invocation local variables parameters return value interm
.ediate calculations
The state of native method invocations is stored in an implementation-dependent way in native method stacks, as well as possibly in registers or
other implementation-dependent memory areas.
The is composed ofJava stack stack frames (or frames).
A the .stack frame contains state of one Java method invocation
When a a , the Java Virtual Machine onto that thread's .thread invokes method pushes a new frame Java stack
When the the virtual machine for that method.method completes, pops and discards the frame
See the following figure for a graphical depiction of the memory areas the Java Virtual Machine creates for each thread.
These areas are private to the owning thread.
Note
The Java Virtual Machine has .no registers to hold intermediate data values
The .instruction set uses the Java stack for storage of intermediate data values
This approach was taken by Java's designers to keep the Java Virtual Machine's instruction set compact and to facilitate
implementation on architectures with few or irregular general purpose registers.
No thread can access the PC register or Java stack of another thread.
At the instant of the snapshot, thread 1 and thread 2 are . Thread 3 is a .executing Java methods executing native method
For threads that are currently executing a – thread 1 and thread 2 – the .Java method PC register indicates the next instruction to execute
Thread 3 is currently executing a , the contents of its .native method PC register is undefined
Data Types
The Java Virtual Machine computes by performing on certain .operations types of data Both the and are strictly defined by thedata types operations
Java Virtual Machine specification.
The candata types be divided into a set of primitive types and a reference type.
Variables of the primitive types hold primitive values, and variables of the .reference typehold reference values
Reference valuesrefer to objects, but are not objects themselves.
Primitive values, by contrast, . They are the actual data themselves.do not refer to anything
We can see a graphical depiction of the Java Virtual Machine's families of data types in the following figure.
Primitive Types
All the of the Java programming language,primitive types except boolean, .are primitive types of the Java Virtual Machine
When a compiler translates Java source code into bytecodes, it uses int ors byte to represents boolean .s
In the Java Virtual Machine, false is represented by integer zero and true by any non-zero integer.
Operations involving boolean values use int .s
Arrays of boolean are accessed as arrays of byte ugh they may be, tho represented on the heap as arrays of byte .or as bit fields
The of the Java programming language other thanprimitive types boolean form the numeric types of the Java Virtual Machine.
The numeric types are divided between the integral types: byte, short, int, long, and char, and the floating-point types: float and double.
As with the Java programming language, the primitive types of the Java Virtual Machine have the same range everywhere.
The Java Virtual Machine works with one other that is : theprimitive type unavailable to the Java programmer returnValue type.
This primitive type is used to implement finally of Java programs.clauses
Reference Types
The of the Java Virtual Machine is cleverly named .reference type reference
Values of type reference come in 3 flavors: the , the , and the .class type interface type array type
All three types have values that are .references to dynamically created objects
The 's values are .class type references to class instances
The 's values are , which are full-fledged objects in the Java Virtual Machine.array type references to arrays
The 's values are that implement an interface.interface type references to class instances
One other reference value is the value, which indicates the reference variable doesn't refer to any object.null
Note
The Java Virtual Machine specification the for each of the data types, but their .defines range of values does not define sizes
The number of bits used to store each data type value is a decision of the designers of individual implementations.
Ranges of the Java Virtual Machine's data types
The Class Loader Subsystem
The using the .JVM starts up by loading an initial class bootstrap classloader
The class is then linked and initialized before public static void main(String[]) is invoked. The execution of this method will in turn drive the
loading, linking and initialization of additional classes and interfaces as required.
Loading, Linking and Initialization
The class loader subsystem is responsible for more than just locating and importing the binary data for classes.
It must also verify the correctness of imported classes, allocate and initialize memory for class variables, and assist in the resolution of symbolic
references.
These activities are performed in a strict order:
Note
The part of a Java Virtual Machine implementation that is the .takes care of finding and loading types class loader subsystem
1.
2.
3.
Loading
Finding and importing the binary data for a type
Linking
Performing verification, preparation, and (optionally) resolution
Verification: ensuring the correctness of the imported type
Preparation: for and toallocating memory class variables initializing the memory default values
Resolution: transforming from the type into .symbolic references direct references
Initialization
Invoking Java code that initializes class variables to their proper starting values.
Note
Loading is that represents the class or interface type with a particular name andprocess finding the class filethe of reading it into a
.byte array
Note
Verifying is the and obeys the semanticprocess of confirming the class or interface representation is structurally correct
requirements of the Java programming language and JVM, for example the following checks are performed:
- final methods / classes not overridden
- methods respect access control keywords
- methods have correct number and type of parameters
- variables are initialized before being read
- variables are a value of the correct type
Note
Static fields are .created and initialized default valuesto their
However, as that happens as part of initialization.no initializers or code is executed at this stage
ClassLoader Type
In the JVM there are . Each delegates to its parent (that loaded it) except themultiple classloaders with different roles classloader classloader bootstrap
classloader which is the top classloader.
ClassLoader Description
Bootstrap
Classloader Bootstrap Classloader is usually because it is .implemented as native code instantiated very early as the JVM is loaded
The Bootstrap Classloader is , including for example .responsible for loading the basic Java APIs rt.jar
It only which ; as a result it skips much of the validationloads classes found on the boot classpath have a higher level of trust
that gets done for normal classes.
Extension
Classloader Extension Classloader such as .loads classes from standard Java extension APIs security extension functions
System
Classloader System Classloader is the , which .default application classloader loads application classes from the classpath
User Defined
Classloaders User Defined Classloaders can alternatively be used to load application classes.
A User Defined Classloaders is including or separationused for a number of special reasons run time reloading of classes
between different groups of loaded classes typically required by web servers such as Tomcat.
The Method Area
Inside a , information about is called the .Java Virtual Machine instance loaded types stored in a logical area of memory method area
When the Java Virtual Machine loads a type, it uses a to locate the appropriate .class loader class file
The in the – a linear stream of binary data – and the .class loader reads class file passes it to virtual machine
The from the binary data and in the .virtual machine extracts information about the type stores the information method area
for declared in the class the .Memory class (static) variables is also taken from method area
All threads , so access to the method area's data structures must be designed to be .share the same method area thread-safe
If two threads are attempting to find a class named Lava, for example, and Lava has not yet been loaded, only one thread should be allowed to
load it while the other one waits.
Type Information
For each type it loads, a Java Virtual Machine must store the following kinds of information in the method area:
The fully qualified of thename type
The fully qualified of the type's direct (unless the type is an interface or class java.lang.Object, neither of which have aname superclass
superclass)
Whether or not the type is a or anclass interface
The type's ( some subset of , , )modifiers public abstract final
An ordered list of the fully qualified names of any direct super-interfaces
In addition to the basic type information listed above, the each :virtual machine must also store for loaded type
The constant pool for the type
Field information
Method information
All class (static) variables declared in the type, except constants
A reference to class ClassLoader
A reference to class Class
The Constant Pool
For it loads, a Java Virtual Machine aeach type must store constant pool.
A constant pool is an , including (string, integer, and floating point constants) andordered set of constants used by the type literals symbolic
to types, fields, and methods.references
Because it to all types, fields, and methods used by a type, the in theholds symbolic references constant pool plays a central role dynamic
of Java programs.linking
Field Information
For each field declared in the type, the following information must be stored in the method area
The field's name
The field's type
The field's modifiers (some subset of public, private, protected, static, final, volatile, transient)
Method Information
For each method declared in the type, the following information must be stored in the method area.
The method's name
The method's return type (or void)
The number and types (in order) of the method's parameters
The method's modifiers (some subset of public, private, protected, static, final, synchronized, native, abstract)
In addition to the items listed above, the following information must also be stored with each method that is not or :abstract native
The method's bytecodes
The sizes of the operand stack and local variables sections of the method's stack frame
An exception table
Class Variables
are among and can be accessed even in the absence of any instance.Class variables shared all instances of a class
Note
In addition to the information for each field, the order in which the fields are declared by the class or interface must also be recorded.
Note
As with fields, the order in which the methods are declared by the class or interface must be recorded as well as the data.
1.
2.
3.
4.
These variables are associated with the class – not with instances of the class – so they are in the .logically part of the class data method area
Before a Java Virtual Machine uses a class, it from the declared in the class.must allocate memory method area for each non-final class variable
(class variables declared ) are as .Constants final not treated in the same way non-final class variables
that uses a final class variable in its own constant pool.Every type gets a copy of the constant value
As , final class variables method area – just like non-final class variables.part of the constant pool are stored in the
But whereas are stored as part of the data for the type thatnon-final class variables declares them, are stored as part offinal class variables
the data for any type that uses them.
The Heap
Whenever a or is , the a .class instance array created in a running Java application memory for the new object is allocated from single heap
As there is inside a Java Virtual Machine instance, .only one heap all threads share it
Because a Java application runs inside its "own" exclusive Java Virtual Machine instance, there is a separate heap for every individual running
. There is no way two differentapplication
Java applications could trample on each other's heap data.
Two of the same application, however, This is why we must be concerned aboutdifferent threads could trample on each other's heap data prop
of multi-threaded access to objects (heap data) in our Java programs.er synchronization
The Java Virtual Machine has an instruction that allocates memory on the heap for a new object, but has .no instruction for freeing that memory
The virtual machine itself is responsible for deciding whether and when to free memory occupied by objects that are no longer referenced by
the running application.
Usually, a Java Virtual Machine implementation uses a garbage collector .to manage the heap
To support garbage collection the heap is divided into three sections:
Young Generation Often split between andEden Survivor
Old Generation (also called Tenured Generation)
Permanent Generation
Memory Management
Objects and are never explicitly de-allocated instead the garbage collector automatically reclaims them.Arrays
Typically this works as follows:
New and are into the .objects arrays created Young Generation
Minor garbage collection will operate in the . , that are , will be from the to theYoung Generation Objects still alive moved Eden Space Survivor
.Space
Major garbage collection, which typically causes the application threads to pause, will move objects between generations. , that areObjects still
, will be from the to the .alive moved Young Generation Old (Tenured) Generation
The is collected every time the is collected. They are both collected when either becomes full.Permanent Generation Old Generation
The Program Counter
, or program counter, which is when the .Each thread of a running program has its own PC register created thread is started
The PC register is one word in size, so it can hold both a native pointer and a returnValue.
As a thread executes a , the being executed by the thread.Java method PC register contains the address of the current instruction An "address"
can be a native pointer or an offset from the beginning of a method's bytecodes.
If a thread is executing a , the value of the .native method PC register is undefined
The Java Stack
When a , the Java Virtual Machine for the thread.new thread is launched creates a new Java stack
A in discrete .Java stack stores a thread's state frames
The Java Virtual Machine only performs two operations directly on : it and .Java Stacks pushes pops frames
When a thread invokes a , the virtual machine creates and pushes a new frame onto the thread's Java stack.Java method
This new frame then becomes the .current frame
As the method executes, it uses the frame to store parameters, local variables, intermediate computations, and other data.
All the data on a thread's is to that thread.Java stack private
There is no way for a thread to access or alter the Java stack of another thread.
Because of this, we need never worry about synchronizing multithreaded access to local variables in our Java programs.
The Stack Frame
The stack frame has three parts:
local variables
operand stack
frame data
Execution Engine
At the core of any Java Virtual Machine implementation is its .execution engine
In the Java Virtual Machine specification, the behavior of the execution engine is defined in terms of an .instruction set
For each instruction, the specification describes in detail what when it encounters the instruction as it executesan implementation should do
bytecodes, but says very little about how.
Implementation designers are free to decide how their implementations will execute bytecodes.
Their implementations can , , execute natively in silicon, use a combination of these, or dream up some brand newinterpret just-in-time compile
technique.

More Related Content

PPTX
Optimization and particle swarm optimization (O & PSO)
PPTX
frames.pptx
PPT
Primitive Recursive Functions
PPTX
go back n protocol
PDF
unit 5 Neural Networks and Deep Learning.pdf
PPTX
Neural Networks
PPTX
AI_Session 25 classical planning.pptx
PPTX
NP completeness
Optimization and particle swarm optimization (O & PSO)
frames.pptx
Primitive Recursive Functions
go back n protocol
unit 5 Neural Networks and Deep Learning.pdf
Neural Networks
AI_Session 25 classical planning.pptx
NP completeness

What's hot (20)

PPTX
AI3391 Artificial intelligence Session 22 Cryptarithmetic problem.pptx
PDF
Lec 5 uncertainty
PPT
prolog ppt
PPTX
PPTX
Knowledge representation in AI
DOCX
Compiler Design
PDF
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
PPT
L03 ai - knowledge representation using logic
PPTX
Introduction to Genetic Algorithms
PPT
Corba introduction and simple example
PPT
Image Sensing & Acquisition
PPT
Extension principle
PDF
Adaptive Resonance Theory (ART)
PDF
Intro to AI STRIPS Planning & Applications in Video-games Lecture6-Part1
PDF
Neural Networks: Self-Organizing Maps (SOM)
PDF
Automata
PPT
Introduction to soft computing
PPTX
hopfield neural network
PPTX
ProLog (Artificial Intelligence) Introduction
ODP
Distributed operating system(os)
AI3391 Artificial intelligence Session 22 Cryptarithmetic problem.pptx
Lec 5 uncertainty
prolog ppt
Knowledge representation in AI
Compiler Design
8.-DAA-LECTURE-8-RECURRENCES-AND-ITERATION-METHOD.pdf
L03 ai - knowledge representation using logic
Introduction to Genetic Algorithms
Corba introduction and simple example
Image Sensing & Acquisition
Extension principle
Adaptive Resonance Theory (ART)
Intro to AI STRIPS Planning & Applications in Video-games Lecture6-Part1
Neural Networks: Self-Organizing Maps (SOM)
Automata
Introduction to soft computing
hopfield neural network
ProLog (Artificial Intelligence) Introduction
Distributed operating system(os)
Ad

Similar to Inside JVM (20)

PPTX
Java ms harsha
PDF
Java Programming
PDF
Introduction to Java Programming.pdf
PPTX
Java Programming Tutorials Basic to Advanced 1
PPTX
java basics.pptx
PPTX
Java part1
PPT
Java features
PPTX
JAVA ALL 5 MODULE NOTES.pptx
PDF
Java unit 1
PPT
Java2020 programming basics and fundamentals
PPTX
Unit1 JAVA.pptx
PPTX
MODULE_1_The History and Evolution of Java.pptx
PPTX
Features of java unit 1
PPT
Introduction to Java Programming, Basic Structure, variables Data type, input...
PPT
J2ee strutswithhibernate-140121221332-phpapp01
PPTX
Presentación rs232 java
PDF
JAVA for Every one
PDF
Ijaprr vol1-2-13-60-64tejinder
Java ms harsha
Java Programming
Introduction to Java Programming.pdf
Java Programming Tutorials Basic to Advanced 1
java basics.pptx
Java part1
Java features
JAVA ALL 5 MODULE NOTES.pptx
Java unit 1
Java2020 programming basics and fundamentals
Unit1 JAVA.pptx
MODULE_1_The History and Evolution of Java.pptx
Features of java unit 1
Introduction to Java Programming, Basic Structure, variables Data type, input...
J2ee strutswithhibernate-140121221332-phpapp01
Presentación rs232 java
JAVA for Every one
Ijaprr vol1-2-13-60-64tejinder
Ad

More from Chinh Ngo Nguyen (6)

PDF
Node js internal
PDF
Design principles
PDF
Software architecture for developers
PDF
Effective java
PPTX
Case Study of Sound Cloud Architecture
PPTX
Patterns of enterprise application architecture
Node js internal
Design principles
Software architecture for developers
Effective java
Case Study of Sound Cloud Architecture
Patterns of enterprise application architecture

Recently uploaded (20)

PDF
medical staffing services at VALiNTRY
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
top salesforce developer skills in 2025.pdf
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ai tools demonstartion for schools and inter college
PPTX
Essential Infomation Tech presentation.pptx
PPTX
L1 - Introduction to python Backend.pptx
PDF
Softaken Excel to vCard Converter Software.pdf
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
System and Network Administraation Chapter 3
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Odoo Companies in India – Driving Business Transformation.pdf
medical staffing services at VALiNTRY
VVF-Customer-Presentation2025-Ver1.9.pptx
Transform Your Business with a Software ERP System
Design an Analysis of Algorithms I-SECS-1021-03
top salesforce developer skills in 2025.pdf
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ai tools demonstartion for schools and inter college
Essential Infomation Tech presentation.pptx
L1 - Introduction to python Backend.pptx
Softaken Excel to vCard Converter Software.pdf
wealthsignaloriginal-com-DS-text-... (1).pdf
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
CHAPTER 2 - PM Management and IT Context
System and Network Administraation Chapter 3
Reimagine Home Health with the Power of Agentic AI​
PTS Company Brochure 2025 (1).pdf.......
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
How Creative Agencies Leverage Project Management Software.pdf
Odoo Companies in India – Driving Business Transformation.pdf

Inside JVM

  • 1. Inside Java Virtual Machine Source: -Inside the Java Virtual Machine Bill Venners Introduction to Java's Architecture Why Java? Java was designed for networks. Its suitability for networked environments is inherent in its architecture, which enables secure, robust, platform-independent programs to be delivered across networks and run on a great variety of computers and devices. The Challenges and Opportunities of Networks One presented to developers is the ichallenge wide range of devices n a networked environment. Java addresses this challenge by of programs.enabling the creation platform-independent Java makes it possible to create binary executables that will run unchanged on multiple platforms. This is important in a networked environment because networks usually interconnect many different kinds of computers and devices (with diverse , , and ).hardware architectures operating systems purposes Another to software developers is in a networked environment.challenge security Networks, because they allow computers to share data and distribute processing, can potentially serve as a way to break into a computer system, enabling someone to steal information, destroy information, or steal computing resources. As a consequence, connecting a computer to a network raises many security issues. To address the security concerns raised by networks, Java's architecture an .comes with extensive built-in security model One created by an omnipresent network isopportunity online software distribution Java takes advantage of this opportunity by in across networks.enabling the transmission of binary code small pieces This capability can make Java programs easier and cheaper to deliver than programs that are not network-mobile.
  • 2. The Architecture Java's architecture arises out of 4 , each of which is defined by a separate specification from Sun Microsystems:distinct but interrelated technologies the Java programming language the Java class file format the Java Application Programming Interface the Java Virtual Machine When we write and run a Java program, we are tapping the power of these 4 technologies. We can see the relationship between these 4 parts in the following figure: Note Java's architectural support for is focused on it takes to .network-mobility managing the time move software across a network If we store a program on a server and download it across a network when we need it, it will likely take longer for our program to start than if we had started the same program from a local disk. One of the primary issues of network-mobile software is the time it takes to send a program across a network. Java's architecture addresses this issue by rejecting the in favor of small binary pieces:traditional monolithic binary executable Jav .a class files Class files can travel across networks independently, and because Java programs are and ,dynamically linked dynamically extensible an end-user needn't wait until all of a program's class files are downloaded before the program starts. For example, Java applets demonstrated the promise of network-mobility Java applets can run on any platform so long as there is a Java-capable browser for that platform. As shown in the following figure, Java applets can be maintained on one server, from which they can travel across a network to many different kinds of computers. To update an applet, we only need to update the server. Note , , and – these three facets of Java's architecture work together to make JavaPlatform independence security network-mobility suitable for the .emerging networked computing environment Java programs are platform independent, network-delivery of software is more practical. The same version of a program can be delivered to all the computers and devices the network interconnects. Java's built-in security framework also helps make network-delivery of software more practical. By reducing risk, the security framework helps to build trust in a new paradigm of network-mobile code.
  • 3. We express the program in source files written in the , compile the source to , and run the classJava programming language Java class files files on a .Java Virtual Machine When we write our program, we (such as I/O, for example) that implement the Javaaccess system resources by calling methods in the classes Application Programming Interface, or .Java API Together, the and form a " " for .Java Virtual Machine Java API platform which all Java programs are compiled In addition to being called the , the is called the .Java runtime system combination of the Java Virtual Machine and Java API Java Platform Java programs because the Java Platform can itself be implemented in software.can run on many different kinds of computers A Java program can run anywhere the Java Platform is present. The Java Virtual Machine At the heart of Java's network-orientation is the Java Virtual Machine, which supports all 3 prongs of Java's network-oriented architecture: Platform independence Security Network-mobility The Java Virtual Machine is an .abstract computer A Java Virtual Machine's main job is to and they contain.load class files execute the bytecodes
  • 4. The Java Virtual Machine contains a class loader, which from .loads class files both the program and the Java API from the that are into the virtual machine.Only those class files Java API actually needed by a running program are loaded The bytecodes are executed in an execution engine, which is one part of the virtual machine that can vary in different implementations. On a Java Virtual Machine implemented in software, the simplest kind of just .execution engine interprets the bytecodes one at a time In this scheme, the of a method are the .bytecodes compiled to native machine code first time the method is invoked The native machine code for the method is then cached, so it can be re-used the next time that same method is invoked. Sometimes the Java Virtual Machine is called the .Java interpreter When running on a Java Virtual Machine that is implemented in software on top of a host operating system, a with the byJava program interacts host invoking native methods. In Java, there are 2 kinds of methods: and .Java method native method A is written in the Java language, compiled to bytecodes, andJava method stored in class files. A is written in some other language, such as C, C++, or assembly, and compiled to the native machine code of a particularnative method processor. When a running Java program calls a , the virtual machine loads the dynamic library that contains the native method and invokes it.native method As the following figure, are the connection between a Java program and an underlying host operating system.native methods Note Another kind of execution engine, one that is but requires , is afaster more memory just-in-time compiler. Note are stored in a whose exact form is platform specific.Native methods dynamically linked library While Java methods are platform independent, native methods are not.
  • 5. 1. 2. The Class Loader Architecture The Java Virtual Machine has a that allows a Java application to load classes in .flexible class loader architecture custom ways A Java application can use 2 types of class loaders: A "primordial" class loader Class loader objects The (there is only one of them)primordial class loader is a part of the Java Virtual Machine implementation. - For example, if a Java Virtual Machine is implemented as a C program on top of an existing operating system, then the primordial class loader will be part of that C program. - The primordial class loader , including the classes of the , usually from the local disk.loads trusted classes Java API At run-time, a Java application can install that , such as by downloading class files across aclass loader objects load classes in custom ways network. - While the primordial class loader is an intrinsic part of the virtual machine implementation, class loader objects are not. - Instead, class loader objects are , compiled to class files, loaded into the virtual machine, and instantiated just like any otherwritten in Java object. We can see a graphical depiction of this architecture in the following figure. Note We can use to give our Java programs to the .native methods direct access resources of the underlying operating system One native method interface – the Java Native Interface, or JNI – enables native methods to work with any Java Platform implementation on a particular host computer.
  • 6. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. The Java Class File A Java compiler, translates the instructions of the Java source files into , the " " of the Java Virtual Machine.bytecodes machine language In a class file, is irrespective of what platform generated the file and independent of whatever platforms mayJava byte order big-endian eventually use it. Architectural Tradeoffs Although Java's are desirable, especially in a networked environment, they did not come for free.network-oriented features As mentioned before, one of the of Java's network-oriented features is the comparedprime costs potential reduction in program execution speed to other technologies such as C++. Java programs can run slower than an equivalent C++ program for many reasons: is 10 to 30 times slower than .Interpreting bytecodes native execution can be 7 to 10 times faster than interpreting, but still not quite as fast as .Just-in-time compiling bytecodes native execution Java programs are .dynamically linked The Java Virtual Machine may have to wait for class files to download across a network. Array bounds are checked on each array access. are (no objects are created on the stack).All objects created on the heap are forAll uses of object references checked at run-time null. are for .All reference casts checked at run-time type safety The is likely (though often more effective) at managing the heap than we could be if we managed itgarbage collector less efficient directly as in C++. in Java are the , rather than adjusting to the most efficient size on each platform as in C++.Primitive types same on every platform in Java are . When we really need to manipulate just an ASCII string, aStrings always UNICODE Java program will be slightly less efficient than an equivalent C++ program. Note When we compile and link a C++ program, the we get isexecutable binary file specific to a particular target hardware platform and because it contains machine language specific to the target processor.operating system Note In addition to processor-specific machine language, another platform-dependent attribute of a traditional is thebinary executable file b .yte order of integers In for the Intel X86 family of processors, for example, the isexecutable binary files byte order little-endian, or lower order byte first. In for the PowerPC chip, however, the isexecutable binary files byte order big-endian, or higher order byte first.
  • 7. Java Virtual Machine What is a Java Virtual Machine? We may be talking about any of 3 different things when we say , as the follows:"Java Virtual Machine" – tthe abstract specification he abstract specification is a .concept –a concrete implementation which exist on many platforms and come from many vendors, are either all software or a combination of hardware and software. a runtime instance – a runtime instance hosts a single running Java application. The Lifetime of a Java Virtual Machine A of the Java Virtual Machine has a clear mission in life: .runtime instance to run one Java application When a Java application starts, a is born.runtime instance When the application completes, the instance dies. If we start 3 Java applications at the same time, on the same computer, using the same , we'll get 3concrete implementation Java Virtual .Machine instances Each Java application runs inside its own Java Virtual Machine A its solitary application by theJava Virtual Machine instance starts running invoking ()main method of some initial class. The () method of an application's initial class the for that application's .main serves as starting point initial thread The can in turn fire off other threads.initial thread Inside the Java Virtual Machine, threads come in 2 flavors: and .daemon non-daemon A is a thread , such as a thread that performs garbage collection.daemon thread ordinarily used by the virtual machine itself The application, however, can mark any threads it creates as .daemon threads The of an application – the one that begins at () – is a .initial thread main non-daemon thread A Java application (the virtual machine instance continues to live) as long as are .continues to execute any non-daemon threads still running When , the will .all non-daemon threads of a Java application terminate virtual machine instance exit If permitted by the security manager, the application can also cause its own demise by invoking the ()exit method of class Runtime or System. The Architecture of the Java Virtual Machine The following figure shows a block diagram of the Java Virtual Machine that includes the and described in themajor subsystems memory areas specification. Each Java Virtual Machine has a class loader subsystem: a mechanism for loading types (classes and interfaces) given fully qualified names. Each Java Virtual Machine also has an execution engine: a mechanism responsible for executing the instructions contained in the methods of loaded classes. Note The Java Virtual Machine is called because it is an defined by a specification."virtual" abstract computer Note Each Java application runs inside of of the of the Java Virtuala runtime instance some concrete implementation abstract specification Machine.
  • 8. When a Java Virtual Machine , it needs to store many things, including bytecodes and other information it extracts from loadedruns a program memory class files, objects the program instantiates, parameters to methods, return values, local variables, and intermediate results of computations. The Java Virtual Machine it into severalorganizes the memory needs to execute a program runtime data areas. Some are shared among all of an application's threads and others are unique to individual threads.runtime data areas Each of hasinstance the Java Virtual Machine one method area and one heap. - These areas are running inside the virtual machine.shared by all threads - When the , it parses information about a type from the binary data contained in the class filevirtual machine loads a class file It places this type information into the .method area - As the , the the program instantiates onto the .program runs virtual machine places all objects heap
  • 9. See the following figure for a graphical depiction of these memory areas. As each new comes into existence, it gets its ownthread PC register and(program counter) Java stack. If the thread is executing a (not a native method), the value of the .Java method PC register indicates the next instruction to execute A thread's the for the thread.Java stack stores state of Java (not native) method invocations The includes its , the with which it was invoked, its (if any), andstate of a Java method invocation local variables parameters return value interm .ediate calculations The state of native method invocations is stored in an implementation-dependent way in native method stacks, as well as possibly in registers or other implementation-dependent memory areas. The is composed ofJava stack stack frames (or frames). A the .stack frame contains state of one Java method invocation When a a , the Java Virtual Machine onto that thread's .thread invokes method pushes a new frame Java stack When the the virtual machine for that method.method completes, pops and discards the frame See the following figure for a graphical depiction of the memory areas the Java Virtual Machine creates for each thread. These areas are private to the owning thread. Note The Java Virtual Machine has .no registers to hold intermediate data values The .instruction set uses the Java stack for storage of intermediate data values This approach was taken by Java's designers to keep the Java Virtual Machine's instruction set compact and to facilitate implementation on architectures with few or irregular general purpose registers.
  • 10. No thread can access the PC register or Java stack of another thread. At the instant of the snapshot, thread 1 and thread 2 are . Thread 3 is a .executing Java methods executing native method For threads that are currently executing a – thread 1 and thread 2 – the .Java method PC register indicates the next instruction to execute Thread 3 is currently executing a , the contents of its .native method PC register is undefined Data Types The Java Virtual Machine computes by performing on certain .operations types of data Both the and are strictly defined by thedata types operations Java Virtual Machine specification. The candata types be divided into a set of primitive types and a reference type. Variables of the primitive types hold primitive values, and variables of the .reference typehold reference values Reference valuesrefer to objects, but are not objects themselves. Primitive values, by contrast, . They are the actual data themselves.do not refer to anything We can see a graphical depiction of the Java Virtual Machine's families of data types in the following figure.
  • 11. Primitive Types All the of the Java programming language,primitive types except boolean, .are primitive types of the Java Virtual Machine When a compiler translates Java source code into bytecodes, it uses int ors byte to represents boolean .s In the Java Virtual Machine, false is represented by integer zero and true by any non-zero integer. Operations involving boolean values use int .s Arrays of boolean are accessed as arrays of byte ugh they may be, tho represented on the heap as arrays of byte .or as bit fields The of the Java programming language other thanprimitive types boolean form the numeric types of the Java Virtual Machine. The numeric types are divided between the integral types: byte, short, int, long, and char, and the floating-point types: float and double. As with the Java programming language, the primitive types of the Java Virtual Machine have the same range everywhere. The Java Virtual Machine works with one other that is : theprimitive type unavailable to the Java programmer returnValue type. This primitive type is used to implement finally of Java programs.clauses Reference Types The of the Java Virtual Machine is cleverly named .reference type reference Values of type reference come in 3 flavors: the , the , and the .class type interface type array type All three types have values that are .references to dynamically created objects The 's values are .class type references to class instances The 's values are , which are full-fledged objects in the Java Virtual Machine.array type references to arrays The 's values are that implement an interface.interface type references to class instances One other reference value is the value, which indicates the reference variable doesn't refer to any object.null Note The Java Virtual Machine specification the for each of the data types, but their .defines range of values does not define sizes The number of bits used to store each data type value is a decision of the designers of individual implementations.
  • 12. Ranges of the Java Virtual Machine's data types The Class Loader Subsystem The using the .JVM starts up by loading an initial class bootstrap classloader The class is then linked and initialized before public static void main(String[]) is invoked. The execution of this method will in turn drive the loading, linking and initialization of additional classes and interfaces as required. Loading, Linking and Initialization The class loader subsystem is responsible for more than just locating and importing the binary data for classes. It must also verify the correctness of imported classes, allocate and initialize memory for class variables, and assist in the resolution of symbolic references. These activities are performed in a strict order: Note The part of a Java Virtual Machine implementation that is the .takes care of finding and loading types class loader subsystem
  • 13. 1. 2. 3. Loading Finding and importing the binary data for a type Linking Performing verification, preparation, and (optionally) resolution Verification: ensuring the correctness of the imported type Preparation: for and toallocating memory class variables initializing the memory default values Resolution: transforming from the type into .symbolic references direct references Initialization Invoking Java code that initializes class variables to their proper starting values. Note Loading is that represents the class or interface type with a particular name andprocess finding the class filethe of reading it into a .byte array Note Verifying is the and obeys the semanticprocess of confirming the class or interface representation is structurally correct requirements of the Java programming language and JVM, for example the following checks are performed: - final methods / classes not overridden - methods respect access control keywords - methods have correct number and type of parameters - variables are initialized before being read - variables are a value of the correct type Note Static fields are .created and initialized default valuesto their However, as that happens as part of initialization.no initializers or code is executed at this stage
  • 14. ClassLoader Type In the JVM there are . Each delegates to its parent (that loaded it) except themultiple classloaders with different roles classloader classloader bootstrap classloader which is the top classloader. ClassLoader Description Bootstrap Classloader Bootstrap Classloader is usually because it is .implemented as native code instantiated very early as the JVM is loaded The Bootstrap Classloader is , including for example .responsible for loading the basic Java APIs rt.jar It only which ; as a result it skips much of the validationloads classes found on the boot classpath have a higher level of trust that gets done for normal classes. Extension Classloader Extension Classloader such as .loads classes from standard Java extension APIs security extension functions System Classloader System Classloader is the , which .default application classloader loads application classes from the classpath User Defined Classloaders User Defined Classloaders can alternatively be used to load application classes. A User Defined Classloaders is including or separationused for a number of special reasons run time reloading of classes between different groups of loaded classes typically required by web servers such as Tomcat. The Method Area Inside a , information about is called the .Java Virtual Machine instance loaded types stored in a logical area of memory method area When the Java Virtual Machine loads a type, it uses a to locate the appropriate .class loader class file The in the – a linear stream of binary data – and the .class loader reads class file passes it to virtual machine The from the binary data and in the .virtual machine extracts information about the type stores the information method area for declared in the class the .Memory class (static) variables is also taken from method area All threads , so access to the method area's data structures must be designed to be .share the same method area thread-safe
  • 15. If two threads are attempting to find a class named Lava, for example, and Lava has not yet been loaded, only one thread should be allowed to load it while the other one waits. Type Information For each type it loads, a Java Virtual Machine must store the following kinds of information in the method area: The fully qualified of thename type The fully qualified of the type's direct (unless the type is an interface or class java.lang.Object, neither of which have aname superclass superclass) Whether or not the type is a or anclass interface The type's ( some subset of , , )modifiers public abstract final An ordered list of the fully qualified names of any direct super-interfaces In addition to the basic type information listed above, the each :virtual machine must also store for loaded type The constant pool for the type Field information Method information All class (static) variables declared in the type, except constants A reference to class ClassLoader A reference to class Class The Constant Pool For it loads, a Java Virtual Machine aeach type must store constant pool. A constant pool is an , including (string, integer, and floating point constants) andordered set of constants used by the type literals symbolic to types, fields, and methods.references Because it to all types, fields, and methods used by a type, the in theholds symbolic references constant pool plays a central role dynamic of Java programs.linking Field Information For each field declared in the type, the following information must be stored in the method area The field's name The field's type The field's modifiers (some subset of public, private, protected, static, final, volatile, transient) Method Information For each method declared in the type, the following information must be stored in the method area. The method's name The method's return type (or void) The number and types (in order) of the method's parameters The method's modifiers (some subset of public, private, protected, static, final, synchronized, native, abstract) In addition to the items listed above, the following information must also be stored with each method that is not or :abstract native The method's bytecodes The sizes of the operand stack and local variables sections of the method's stack frame An exception table Class Variables are among and can be accessed even in the absence of any instance.Class variables shared all instances of a class Note In addition to the information for each field, the order in which the fields are declared by the class or interface must also be recorded. Note As with fields, the order in which the methods are declared by the class or interface must be recorded as well as the data.
  • 16. 1. 2. 3. 4. These variables are associated with the class – not with instances of the class – so they are in the .logically part of the class data method area Before a Java Virtual Machine uses a class, it from the declared in the class.must allocate memory method area for each non-final class variable (class variables declared ) are as .Constants final not treated in the same way non-final class variables that uses a final class variable in its own constant pool.Every type gets a copy of the constant value As , final class variables method area – just like non-final class variables.part of the constant pool are stored in the But whereas are stored as part of the data for the type thatnon-final class variables declares them, are stored as part offinal class variables the data for any type that uses them. The Heap Whenever a or is , the a .class instance array created in a running Java application memory for the new object is allocated from single heap As there is inside a Java Virtual Machine instance, .only one heap all threads share it Because a Java application runs inside its "own" exclusive Java Virtual Machine instance, there is a separate heap for every individual running . There is no way two differentapplication Java applications could trample on each other's heap data. Two of the same application, however, This is why we must be concerned aboutdifferent threads could trample on each other's heap data prop of multi-threaded access to objects (heap data) in our Java programs.er synchronization The Java Virtual Machine has an instruction that allocates memory on the heap for a new object, but has .no instruction for freeing that memory The virtual machine itself is responsible for deciding whether and when to free memory occupied by objects that are no longer referenced by the running application. Usually, a Java Virtual Machine implementation uses a garbage collector .to manage the heap To support garbage collection the heap is divided into three sections: Young Generation Often split between andEden Survivor Old Generation (also called Tenured Generation) Permanent Generation Memory Management Objects and are never explicitly de-allocated instead the garbage collector automatically reclaims them.Arrays Typically this works as follows: New and are into the .objects arrays created Young Generation Minor garbage collection will operate in the . , that are , will be from the to theYoung Generation Objects still alive moved Eden Space Survivor .Space Major garbage collection, which typically causes the application threads to pause, will move objects between generations. , that areObjects still , will be from the to the .alive moved Young Generation Old (Tenured) Generation The is collected every time the is collected. They are both collected when either becomes full.Permanent Generation Old Generation The Program Counter , or program counter, which is when the .Each thread of a running program has its own PC register created thread is started The PC register is one word in size, so it can hold both a native pointer and a returnValue. As a thread executes a , the being executed by the thread.Java method PC register contains the address of the current instruction An "address" can be a native pointer or an offset from the beginning of a method's bytecodes. If a thread is executing a , the value of the .native method PC register is undefined The Java Stack When a , the Java Virtual Machine for the thread.new thread is launched creates a new Java stack A in discrete .Java stack stores a thread's state frames The Java Virtual Machine only performs two operations directly on : it and .Java Stacks pushes pops frames When a thread invokes a , the virtual machine creates and pushes a new frame onto the thread's Java stack.Java method This new frame then becomes the .current frame As the method executes, it uses the frame to store parameters, local variables, intermediate computations, and other data. All the data on a thread's is to that thread.Java stack private There is no way for a thread to access or alter the Java stack of another thread. Because of this, we need never worry about synchronizing multithreaded access to local variables in our Java programs.
  • 17. The Stack Frame The stack frame has three parts: local variables operand stack frame data Execution Engine At the core of any Java Virtual Machine implementation is its .execution engine In the Java Virtual Machine specification, the behavior of the execution engine is defined in terms of an .instruction set For each instruction, the specification describes in detail what when it encounters the instruction as it executesan implementation should do bytecodes, but says very little about how. Implementation designers are free to decide how their implementations will execute bytecodes. Their implementations can , , execute natively in silicon, use a combination of these, or dream up some brand newinterpret just-in-time compile technique.