In the last lesson we discussed glassblowing which is a first page in the lifetime offered by a class 2
or an interface on gender's the corresponding class object which is the input to the next page which 3
is linking not it's get an in-depth understanding of the linking process linking is the most complicated 4
of the three stages of the LifeGem effect. 5
And as we discussed earlier it includes three steps verification preparation and the optional resolution 6
step. 7
And let's begin with the verification step the verification step verifies that the Nordic class is not 8
malformed. 9
That is it conforms to the Java language to us and this is needed as the class file might have been 10
lorded from across the network or it could be a user defined class from the local file system itself 11
. 12
In either case JVM does not trust those classes as they come from less trustworthy resources. 13
As we discussed earlier there is there could have been generated by a hostile compiler whose intention 14
is to perform some malicious actions to Gibeon subjects them through some stringent security checks 15
through the verification process under the same verification is already done during compilation. 16
Generally speaking user defined classes are mostly well-formed process but GBM has to stick to its process 17
. 18
We know that the classes from Java library are not very fight as they're considered trustworthy and 19
recall that they are looked at by the bootstrap classloader bytecode verification is done by the component 20
bytecode. 21
Once the code is successfully verified by the bytecode welfare only then the code is considered safe 22
to be run by JVM on it with a log it's execution engine. 23
The poor form at optimum level as it doesn't have to perform any further security checks. 24
But if it finds a problem it rejects the malformed class and throws an exception on hit. 25
For example verification checks that bytecode that performs final process must not be subclassed right 26
. 27
Final methods must not be overridden under must not be any illegal method overloading and the final 28
one ensures that statements like. 29
If condition does not send the control beyond the methods Bhandari So that's verification nextstep is 30
preparation and Ixtoc is pretty straightforward. 31
I look at space post Arctic fields and initialize them with default values. 32
If there isn't enough memory then an out of memory error will be generated. 33
Not that if the class is loaded because an instance of it is created then space will be a look at it 34
. 35
For instance fields also and they would also be initialized the default values. 36
However this would be done only after all stocktake fields are initialized properly with the actual 37
user defined values. 38
And this happens across the class hierarchy. 39
We know that super classes will be loaded before the subclasses so all the stocktake fields across the 40
class hierarchy will be initialized before the instance fields are initialized. 41
Next is the last step which is resolution and we know that it is an optional step that is it need not 42
strictly happen after Operation step on it can be performed later after initialization stage. 43
Now in the current class we typically reference fields on methods from other classes and also interfaces 44
. 45
So this step is about resolving those references. 46
That is to load them so that the current class can use them. 47
No such references are referred to as symbolic references and symbolic references are nothing but logical 48
references or symbolic references are stored in one area of the doc class file called Constant bullet 49
. 50
If you recall. 51
We looked at constant pool in a demo we did in the method binding lesson did we used the jalopy disassembler 52
tool to examine the bytecode and we actually looked at the contents of constant Gwinn. 53
So you can go back and review that video if needed. 54
Note that apart from symbolic references constant as its name suggests can also include constants such 55
as compile time constants and stringless in the resolution step. 56
The referenced classes are loaded into memory and once they are loaded into memory their corresponding 57
symbolic references to the current class will be replaced with direct references to their actual locations 58
in the memory so that support resolution is about this look at an example here. 59
Here the box at the top has the source code. 60
Well the one at bottom shows the corresponding byte order in the source code. 61
We have a single statement creating the whole object and in the bytecode we can see the corresponding 62
bytecode instruction and it is referencing an entry in the constant pull and constant pull. 63
It's like an army and has entries that can be accessed by some in mixed numbers. 64
So what is the object creation instruction is referencing the entry at the index number two within the 65
constant pull on this entry is interned affronting the create index number 19 which basically is a symbolic 66
reference not at runtime. 67
GBM creates an internal notion of this constant which is referred to as a runtime constant. 68
And then the resolution step the component doing resolution would look at the symbolic reference within 69
Tintern time constant ball and would then load the class handle that is class. 70
Hello would be taken through all three stages of the lifetime off it would be stored on the heap. 71
The symbolic reference will now be replaced with a direct reference to that hello instance on the heap 72
. 73
And this form of the solution is known as dynamic linking as linking is being done at runtime in certain 74
languages such linking is done at compile time itself. 75
And does it refer to start acting uninstructed linking the contents of the reference file or copied 76
into the final executable. 77
No advantage of dynamic linking is that you can make easy objects that is replace a class file with 78
a more newer updated class. 79
However the software would also cease to work if updates are incompatible. 80
For instance in the new class file it previously available method might be missing on the class might 81
be referencing that method and that JVM would generate an error. 82
Note that this resolution of symbolic references in the current class happens only once. 83
There is a symbolic reference maybe a reference from multiple locations within the same class but that 84
reference would be resolved only once. 85
So if Hello instance is created at multiple locations in the same class then it is resolved only once 86
and thereafter the direct reference is used not dynamic linking. 87
Can happen in two ways depending on the JVM implementation. 88
It can be either to be either loading or we are lazy loading. 89
If it is either loading then it means that resolution happens right after the operation step. 90
That is all classes are referenced by the current class will also be loaded which means that they get 91
loaded on initialized before the current class is itself initialized. 92
So they are loaded upfront. 93
That is they are eagerly loaded. 94
If it is lazy loading then it means resolution is postponed to a later time after the next stage which 95
is initialization to be more precise when missing a later time. 96
It implies to the time when the statement that includes the reference is actually executed so at that 97
point the reference is loaded on demand and the symbolic reference is replaced with the direct reference 98
. 99
Typically DBMS implement lazy loading and that's because you don't have to load a class until you're 100
really needed. 101
Sometimes certain statements may never get executed and so there is no point loading the references 102
appearing in those statements. 103
Finally just note that when resolving differences resolution also ensures that the current class has 104
permission to access the reference to class a what with regards to freezing other classes. 105
Resolution ensures that the fields exist in those classes under how to the a type also under current 106
class. 107
Once again has the permission to access them as you can see these paths are pretty fiction related and 108
so resolution does form some form of verification. 109
So that's about linking. 110
So once the classes form would be safe. 111
Next stage would be initialization after which JVM can freely executed. 112
As discussed earlier initialization step simply initialize a static field. 113
But the actual user defined initial values. 114
Earlier they were initialized with different values. 115
If you recall one thing note about initialization was with regards to interfaces. 116
Interfaces will be initialized only if one of its documents is accessed or one off its fields. 117
That is a non compile time constant is accessed. 118
That is a field is initialized via a method or a constructor under is initialization and so we will 119
not be discussing it any more. 120
So that's about it. 121
Next we will be a demo of the lifetime effect. 122
Thank you