JVM Notes - 1

Being the Java programmer for a long time, I feel that it is more and more important
to know what is running under the java. That is why I start to read the JVM which is
the tough part of Java. I wish after the learning I can benifit on:
1. Know how do java do the method invocation.
2. Know how do java do the overload, override.
3. Know how do java throw the exception.
4. Know how do java know the scope of the variable.
5. Know how do java handle the String as the constant.

I will record everything I got from reading the book. Inside the Java virtual machine.

JVM Note 1.


The life time of JVM :
The life of a JVM depends on the application runs inside it. When the application completes the JVM will die.

Data type :
All the primitive type of java programming(byte, short, int, long, float, double, boolean), except the boolean
are all the primitive type of the JVM. For the boolean type, it will be translated into the int or byte in
the JVM represnetation.

There is a data type that only worked inside JVM but java programming, the returnValue type which indicates the
finally clauses of the java program.

The reference type, the value of which comes in three flavor: the class type, the interface type, the array type.

Word size :
The JVM run time data area are desgined base on the word which is 32 bit long.(as int) and when the java program
runs the JVM will measure the necessary area base on the word.

Class loader :
JVM contains two kinds of the class loader: primodial class loader and the class loader object. the first one is
part of the JVM, another one is the java object which is part of the running application. The implementation
of JVM must be able to recognize class file. An implementation is free to recognize other binary format. Eg, the
Microsoft VM can load the CAB file as well. The class loader maintains its own name space populated by the types it
has loaded, a single Java application can load multiple types with the same fully qualified name.(?????Why,)

The method area :
Inside the JVM, information about loaded types is stored in a logical area of memory called the method area. memory
for class variable declared in the class is also taken from the method area. All the thread share the same method
area which implieds that the static variable must be designed as thread safe. Also the size of the method area is
not fixed.

there is a lot of infomation included in the method area like: The fully qualified name of the type, the superclass,
whether it is a class or interface, type modifier, the method table and so forth. the variable which modified by final
is not only included in the class that defined them, the class which refer to them will get a local copy.

A JVM can alway determine the amount of memory requried to represent an object by looking into the class data stored
in the method area
[Question]
But how. it is easy to under stand that a class only contains some variable as primitive type, but how about the
String, it is unlimited. how java know how many memory should be allocated to the string object.?
[/Question]

[Answer]
It is easy for JVM to know how many memory should be allocated to the string object, since it is controlled by a Array which contains a collection of the characters, then read the length of the array is ok.
[/Answer]

The heap:
There is only one heap inside one JVM, all the object is in it. Two different can not trample each other's heap data
but the thread could. This is why the programmer should be care about the multi-thread accessing on the same object.
Usually, a Java Virtual Machine implementaion uses a garbage collector to manage the heap. Note, the garbage collector
is not a required part of the JVM. The object usually inculdes some kind of pointer into the method area. because:
1. It may something perform the cast type
2. It may incude the instanceof checking
3. It may invoke on some class variale.


The program counter:

It hold by the thread, measures in word size and contains the current instruction being executed.

The stack :
It lives in the heap. in my understanding, there is no data survives in the heap but stack. The stack is created when
thread starts. The Java stack stores a thread's state in its frame. As thread is alreay in some method. then all the
data include in the stack is private to the current thread (It is the local variable which defined in the method).

The stack frame :
In my understanding, It takes charge of the temporary data storage, manipulate the data, execute the instruction. In
other words, It is concrete execution part of the application.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值