Chinaunix首页 | 论坛 | 博客
  • 博客访问: 258919
  • 博文数量: 70
  • 博客积分: 2500
  • 博客等级: 少校
  • 技术积分: 930
  • 用 户 组: 普通用户
  • 注册时间: 2008-04-22 12:32
文章存档

2009年(42)

2008年(28)

我的朋友

分类:

2009-04-08 09:46:16

:转载时请以超链接形式标明文章原始出处和作者信息及本声明
http://itsxhu.blogbus.com/logs/21972309.html

由于去年11月系统经常出现OutOfMemory的问题,弄得我焦头烂额,问题最终得于解决。通过这个问题让我开始深入的接触JVM,并对JVM产生兴趣。前前后后花了几个月的时间看了不少JVM的文档,Leader于是让我给小组其它成员做一个相关的JVM培训,于是就有了这份文档。基本上总结了JVM的主要模块,里面的指令集并没有涉及。通过这段时间的学习对于JVM内存管理和内存问题的解决有了一定的经验。这些东西下次专门整理一个文章来讲一讲。

Java 虚拟机
JVM的基本概念
 类装载器的机制
    ➢   命名空间
    ➢   双亲委派装载机制
 JVM内部的体系结构
    ➢    JVM中各个数据区及其作用
 类型生命周期
    ➢   类的初始化
    ➢   实例初始化
 垃圾收集机制
JVM的体系结构
体系结构图
运行时共享数据区
运行时所有线程共享的数据区
各线程独立的数据区
Java stack
Object Lifetime
Object Lifetime
类型生命周期的简单描述
装载     查找并装载类型的二进制数据
连接      执行验证,准备,解析(可选)
    验证     确保被导入的类型的正确型
    准备  为类变量分配内存,并初始化为默认值
     解析  将类型中的符号引用转换为直接引用
初始化 把类变量初始化为正确初始值

The Method Area
Inside a Java Virtual Machine instance, information about loaded types is stored in a logical area of memory called the method area.
Information
Type Information
The Constant Pool
Field Information
Method Information
Class Variables
A Reference to Class ClassLoader
A Reference to Class Class
Method Tables


Heap
Contains the class instance,Class,Arrays.

Every Class Type would associated to a Class Object in the Heap.
Java Stack
A thread’s Java stack stores the state of Java (not native) method invocations for the thread. Push stack frame And Pop stack frame to execute.
the register count indicated which stack frame should be push in the Java stack.
The Java stack is composed of stack frames
stack frame
A stack frame contains the state of one Java method invocation.

The stack frame has three parts: local variables, operand stack, and frame data.

The size of the Jvm data areas
Heap default size
   client:
    • Initial heap size of 4MB
    • Maximum heap size of 64MB
   
  server:
    • Initial heap size of 1/64th of the physical memory, up to 1GB. (Note that the minimum initial heap size is 32MB, since a server-class machine is defined to have at least 2GB of memory and 1/64th of 2GB is 32MB.)
     • Maximum heap size of 1/4th of the physical memory, up to 1GB.
Set heap size
    •–Xmsn    java -Xms4m test
    •–Xmxn    java –Xmx8m test

Method area
Sun's implementation of the Java virtual machine in JDK release 1.0.2 dynamically expands the method area as required by the computation, but never contracts the method area. The Java virtual machine implementations in Sun's JDK release 1.1 and the Java 2 SDK, Standard Edition, v1.2 garbage collect the method area. In neither case is user control over the initial, minimum, or maximum size of the method area provided.
Thread stack
Default size
    512kb on Sparc and 256kb on Intel for 1.3 and 1.4 32-bit VMs, 1mb with the 64-bit Sparc 1.4 VM; and 128k for 1.2 VMs.
Set thread frame size
    -oss     
        eg: java –oss test

Garbage Collection
The Object Lifecycle
    1.Created
    2.In Use  (Strongly reachable)
    3.Invisible
    4.Unreachable
    5.Collected
    6.Finalized
    7.Deallocated

Before Deallocated The Object the GC would invoke the Finalized ().

GC  Tuning  doc:memorymanagement_whitepaper.pdf
Class loader
Class Loader overview
Boot strap Class Loader

System Class Loader

Delegate loading

Namespace
initial classes
Let C be the result of L.loadClass(), L is the initiating loader of C.
Loaded class cache maps class names and initiating loaders to class types.

define classes
Let C be the result of  L.defineClass(), L is the defining loader of C.
ClassLoader  Class
Motheds
The method defineClass converts an array of bytes into an instance of class Class.
Java virtual machine invokes the loadClass method of the class loader that originally created the class.
resolveClass(Class c) Links the specified class.
findSystemClass(String name)  This method loads the class through the system class loader
findLoadedClass(String name) 
findClass(String name)   
Dynamic Class Loading
Customize  Class Loader
Eg:
class MyClassLoader()  extends ClassLoader{
        @ override ClassLoader.loadClass
         public synchronized Class loadClass(String name){
             …   
        return defineClass(name,newData,0,newData.length);
          }
    }
Instrumenting Class Files
Instrumenting
    class MyClassLoader extends ClassLoader{
    public synchronized Class loadClass(String name){
        …
        byte[] data = getClassData(name);
        byte[] newdata = instrumentClassFile(data);
        return defineClass(name,newdata,
                    0,newdata.length());
    }
    }
Tools
CGLIB 
Multi Thread
Thread
Java Thread Model
Thread on the Solaris platform
       
ThreadPool
In the thread pool pattern in programming, a number of threads are created to perform a number of tasks, which are usually organized in a queue. Typically, there are many more tasks than threads. As soon as a thread completes its task, it will request the next task from the queue until all tasks have been completed. The thread can then terminate, or sleep until there are new tasks available.

Summarize
Java Class Loader
Memory area
Thread
GC introduce and tuning
           
 References
ThreadPool:
http://today.java.net/pub/a/today/2008/01/31/query-by-slice-parallel-execute-join-thread-pool-pattern.html
http://www-128.ibm.com/developerworks/java/library/j-jtp0730.html
CGLib:

GC Tuning:

阅读(616) | 评论(2) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-10-11 21:01:55

太肤浅了

chinaunix网友2010-10-11 21:01:51

太肤浅了