首页 > 代码库 > Understanding the JVM

Understanding the JVM

The aim to write this blog is that I want to summerize and NOTE what I have learned with the booked called as

Understanding the JVM Advandced features and Best prac

 

  
Now it‘s the first chapter reviews : 

  ? This chapter didn‘t talk much ,just the history and future of technology in java system, also kinds of virtual macine(VM) 

  > what i deeply remembered is the version of my java VM ,because i teste it specially.

  技术分享

  u can see my version of VM is hotspot VM with mixed mode and it is usually common of java developer 

 

It‘s the time to revise the second chapter:

  ?  In this chapter , i pick up lots of knowledge about VM 

    > the VM memories to be allocated particular data. ↓

    技术分享

    > next i will tell the detail function of these memories

      No1. program count register (pcr)

        function : to control the next bit code which will be launched , such as the loop and jump, branch, some exceptions...

        private : because java VM‘s multithreading ,so every threading will has it‘s own pcr to make sure every single pcr work 

       No2. VM Stack and Native Stack -- In HotSpot, these two stacks are the one stack.

        function : purpose of stack is to describe the model launched in java or native methods --  every method begin to

               launch that means one thread starts with VM stack being set up, where there are the specific part vairables, such

              as (the basic type od variable) long, double and reference...

        private : every method has it‘s own form of specific part variables

        potential error : if the part variables are confirmed before launched, and u want apply more memories in stack, and then u will get 

                  stackOverflowError... but if VM stack can be extend dynamicly(now most VM stack can make it) things are different

                  but if u can‘t apply more memories when u extend dynamicly , and u will get outOfMemoryError...

      No3. Heap -- the biggest area of memory 

         function : heap is the homeland of kinds of class instance,  basically all instance lived in heap, but with the JIT developing, not all the 

               instance in heap, also the stack can do it.

         public : all the instance in the heap,  so threads can get the all instance. By the way, there are also called GC heap, because garbage collected

              in this area divided into young_generation and old_generation

         potential error : java heap can be allocated in discontinuous physical area...so if there are not enough zone to allocate class instance,and this 

                  heap can‘t be extended , u will get outOfMemoryError

      No4. Method Area -- like the heap

         function : store up the information of class which has already been loaded by VM, the static variable, the constant,and code by JIT...

         public : this area can be extended or not, and what amazed me is that u can achieve non-GC, so it‘s also called premanent generation...

         potential error : OutOfMemoryError

     No5. Runtime Constant pool -- part of Method Area

          function : during the runtime, u also can put the constanrt into the constant pool...    

          example : see this blog . String : intern() which is used most in actually develop

             http://www.cnblogs.com/AmoryWang-JavaSunny/p/6407996.html

 

    > then i will tell u how to visit the Object , and there are two ways to make it ...

    技术分享

    一般来说的虚拟机都是采用下面的直接访问的方法,因为这样节省时间一些,对于并发来说这就是一种客观的节约资源的方式,而上面的句柄池也有在用

   ? situations of OOM 

    (1) java heap : where the class instance lived 

     (2) VM stack and native stack :

        - OOM

        - SOF     

      对于单线程来说,总是会出现sof情况,因为这两种在单线程方面来说就是一种情况,线程请求的栈空间大于虚拟机最大提供的空间,

      因为虚拟机无法再扩展更大的空间了,但是对于多线程来说,就不太一样,一般线程的栈空间越大,那么线程的数就会越少,剩下的

      空间很容易被线程整垮。。。如果出现了线程很多,但又不可避免的时候就要考虑减少最大堆或者栈空间,来确保多线程的运行,这种

      牺牲内存来成全线程的情况也是很牛的想法。。。

   

Understanding the JVM