2-JVM-内存模型

私有
  • 线程
    • 程序计数器PC(native时为undefined)
    • 虚拟机栈
    • 本地方法栈(结构取决于语言)
  • 虚拟机栈
    • 栈帧(分配后无法改变大小)
    • 本地变量数组(slot)
      • 类方法参数从0开始,实例方法0放this
      • this引用
      • 方法参数
      • 局部变量
      • 返回值地址(returnAddress)
      • 常量池引用 -> 当前类运行时常量池(reference)
    • 操作数栈
      • 类似cpu通用寄存器
  • 本地方法栈
    • JNI调C,本地方法栈即是C栈
    • 本地方法回调java时,线程会回到虚拟机栈
  • HotSpot线程模型
    • Java线程 - 操作系统线程:一一对应
    • Create Java thread, prepare below
    • thread-local storage
    • allocation buffers
    • synchronization objects, stacks and the program counter
    • The native thread is created
    • Once the native thread has initialized it invokes the run() method in the Java thread
    • The native thread confirms if the JVM needs to be terminated as a result of the thread terminating
    • The native thread is reclaimed once the Java thread terminates
  • 动态链接
    • C/C++
    • C/C++ code is typically compiled to an object file then multiple object files are linked together to product a usable artifact such as an executable or dll.
    • During the linking phase symbolic references in each object file are replaced with an actual memory address relative to the final executable.
    • Java
    • 源码编译成字节码时,对变量、方法、类的引用都放在字节码常量池中,作为符号引用存在
    • 将符号引用解析为直接引用的过程,可以发生在验证之后(主动/静态解析),也可以发生在第一次使用时(懒/晚解析)
    • 直接引用以调用者运行时位置的地址偏移形式存在
  • JVM system thread
    • VM thread
    • 执行需要safe point的操作,safe point意味着堆不会发生变化
    • gc,thread stack dumps(线程栈转储),thread suspension(线程挂起),biased locking revocation(偏向锁撤销)
    • Periodic task thread
    • 执行周期性任务,如中断
    • GC threads
    • Compiler threads
      运行时编译(解释还是JIT???)
    • Signal dispatcher thread
      接收发给JVM的信号,并调用相关的JVM方法
共享

    • 新生代(Young Generation)
    • Eden
    • From Survivor
    • To Survivor
    • 老年代(Old/Tenured Generation)
  • 非堆
    • 代码缓存(JIT)
    • 永久代(Java 8被本地内存Meta Space取代)
    • 字符串内部池(字符串表 + Interned Strings:JDK 1.7去普通堆)
    • 符号表(所有运行时常量池符号,引用计数为0时卸载)
    • 方法区
      • 类加载器引用
      • 静态常量(应该是Java 8时去普通堆)
      • 运行时常量池
      • 字面量(string,numeric,含final变量)
      • class reference
      • field reference
      • method reference
      • attribute reference
      • name and type
      • invoke dynamic
      • 属性数据
      • 修饰符,类型,名称,属性(注解)
      • 方法数据
      • 修饰符,返回值,参数类型,名称,属性(注解)
      • 方法代码
      • 字节码
      • 操作数栈大小
      • 局部变量数组大小
      • 局部变量数组
      • 异常表
        • If a method has defined a try-catch or a try-finally exception handler then an Exception Table will be created.
        • 异常处理句柄,起始点,结束点,异常处理代码的PC偏移,被捕捉异常类的常量池索引
  • 关于Interned-Strings的官方说明
    • http://www.oracle.com/technetwork/java/javase/jdk7-relnotes-418459.html
    • HotSpot Synopsis
    • In JDK 7, interned strings are no longer allocated in the permanent generation of the Java heap, but are instead allocated in the main part of the Java heap (known as the young and old generations), along with the other objects created by the application.
    • This change will result in more data residing in the main Java heap, and less data in the permanent generation, and thus may require heap sizes to be adjusted.
    • Most applications will see only relatively small differences in heap usage due to this change, but larger applications that load many classes or make heavy use of the String.intern() method will see more significant differences.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值