Hi there this is they don't want to know. 2
And welcome back. 3
It's not time to learn about the under the hood the days or the way the movie industry folks call it 4
behind the scenes didas. 5
So we're going to learn about what goes on within JVM. 6
And to be a complete engineer that's very important to a lot of programmers even though they have been 7
programming for years. 8
Do not have enough understanding of how JVM works. 9
It is relatively rare for Djala courses or even giallo books to cover this topic. 10
So it's a special chapter and I hope you like it. 11
Let's just briefly review the control in this program. 12
It would serve as a motivation for investing over time in learning about JVM internals. 13
So here we have three courses class initialization D-Mont. subclass and superclass subclasses extending 14
extending the superclass and class initialization is just an independent class which is run from the 15
command line. 16
And so it has a main method here. 17
But we will not do that. 18
The more I know the more will be done later but we'll just look at the concurrent floor right here within 19
this slide. 20
And it has a static initializer block and an instance initializer Rob or here on both of them Halprin 21
statements saying where we are within the program. 22
Here we are saying that we are inside the static initializers block within the class initialization 23
Demel and within the subclass There is also the static initial as a Glock undercharge or defining. 24
You'll start to underscore final Antarctic underscore final two. 25
So both of them are static final views on one of them as a compile time constant whereas the other one 26
is initialized via a random function within the math class. 27
And here we have the main function. 28
Also the boot subgraphs on superclass have constructors here with respect to print statements and within 29
the main statement we have these two print statements both of them are printing these statements that 30
not to underscore final so they are just accessing the static underscore final. 31
Unstarted underscored final two undervalues are getting rendered here. 32
And finally we are creating an instance of the subclass. 33
Now when we run this class class initialization DeMaio. 34
So there are these put in statements that get printed because most of them aren't. 35
The interesting thing would be to observe the order in which these print statements get printed. 36
So that would be the interesting thing. 37
And from that we can look at couple of questions and that word so as motivation for why we are going 38
to spend some time on this chapter learning the GBM internals. 39
So let's assume that we have run this program using the Java command and the first statement that gets 40
executed. 41
So the print statement within the static initializer block is getting executed. 42
Next is the print statement. 43
The statement in the main method is getting a good or so the instance initializer is not getting executed 44
. 45
OK so that's one question that we can have raised or not getting printer. 46
And the third statement is actually the static initializer group within subclass is getting initialiser 47
is getting executed. 48
So this print statement is getting executed rather than the second statement in the main method. 49
So that's another question why is this thing getting is why is this thing getting printed. 50
And then the second statement is getting executed. 51
So so that's the question. 52
Another question is what exactly is happening with the subclass itself when it is being accessed here 53
when we are accessing the static final fields in the subclass. 54
What is going to happen to subclass behind the scenes. 55
So that's another question and the next treatment would be the superclass constructor would get executed 56
and then the sapless constructor would get executed. 57
So these are the kind of questions that this chapter will help us answer. 58
And next we will do will cover something called as lifetime offer type and once we do that we will clearly 59
understand what is happening here. 60
So we will revisit this program later after completing that topic. 61
The lifetime offer on a duck pond or family will be a real I'm offered. 62
So next let's look at the agenda. 63
We will first understand the lifetime of type within Gibeon. 64
That is a lifetime book classes and interfaces within GBM. 65
Next we will look at runtime data areas which will help us understand the different memory areas within 66
GBM and how pipes and objects are handled within these memory areas. 67
Finally we will look at the anatomy of a Djala classified which would help us understand a Java program 68
at bytecode level. 69
That is how Reems instructions work. 70
So that's the agenda that we have for this chapter. 71
Before we get started with GBM internals let's just do a very brief recap of what we discussed about 72
GBM in the first chapter GBM is a cornerstone of Jalopnik foam. 73
It hurts Djala it use some of its goals like platform independence security and very fast execution 74
. 75
It's an incredibly bright Thisted and very optimized runtime environment with excellent concurrency 76
support. 77
But just critical and overlapping large scale systems. 78
Sometimes people say that even if joggles Abi GBM would still remain as JVM can't support many other 79
popular languages like Scarlet groovey and closure that is source code in these other languages can 80
be compiled into Java bytecode which can be run on JVM java what your mission is Calder's virtual because 81
it's an abstract computing machine that is like a real computing machine. 82
It has an instruction set that it executes which we know is a job by code. 83
So for a Sebille machine code so says the instruction set well for a JVM Java bytecode so says the instruction 84
set. 85
Like a real computing machine GBM also Manipal its memory at runtime. 86
That is it uses memory to run its programs and to manipulate their data. 87
JVM has few core responsibilities and they include loading and interpreting of Java bytecode security 88
an automatic memory management. 89
Now this slide demonstrates the platform independence capability of Jawa platform independence is possible 90
because JVM is platform dependent which can execute the platform independent job bytecode. 91
This whole process is pretty similar to interpretation. 92
It is just a JVM interprets bytecode and sort of source code. 93
When we discuss JVM there are three things but Ingrid Hostetter a GBM specification. 94
It is simply a specification that describes JVM features on how it should work. 95
It also specifies the instruction set. 96
Anyone can use a specification to implement their own Gibeon nesting related or JVM is a concrete implementation 97
of the JVM specification popular JVM implementations include Oracle's hotspot and IBM GBM. 98
Finally the third notion pertaining any good JVM is a runtime instance which is simply an instance of 99
a concrete JVM implementation. 100
When we're on a Java program from command line at runtime instance of JVM is created and then loaded 101
into memory before that program can be run. 102
Finally with regards to performance JVM plays a critical role in ensuring that Djala programs run very 103
fast. 104
One reason is to do with job bytecode as interpreting Java bytecode is much faster than interpreting 105
source code. 106
This is because bytecode has a compact format and is already compiled and optimized. 107
Additionally most JVM implementations also perform just in time or GRB compilation to further speed 108
up execution Geddie compiler basically caches frequently use bytecode in the form of machine code on 109
when needed. 110
Good stuff. 111
Gosh the machine code to speed up performance. 112
So that's a quick recap I and it's time to get started now on learning about JVM maintenance