2-JVM-内存模型

作者: 宠辱不惊的咸鱼 | 来源:发表于2018-01-27 23:49 被阅读6次

私有

  • 线程
    • 程序计数器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.

相关文章

  • 2-JVM-内存模型

    私有 线程程序计数器PC(native时为undefined)虚拟机栈本地方法栈(结构取决于语言) 虚拟机栈栈帧(...

  • Flink JobManager | TaskManager内存

    Flink内存模型分析 JobManager内存模型 TaskManager内存模型 内存模型分析 Flink使用...

  • 图解jvm--(四)内存模型

    内存模型 java 内存模型 很多人将【java 内存结构】与【java 内存模型】傻傻分不清,【java 内存模...

  • JVM内存模型(jvm 入门篇)

    概述 jvm 入门篇,想要学习jvm,必须先得了解JVM内存模型,JVM内存模型,JVM内存模型,JVM内存模型,...

  • java内存模型

    1.内存模型(JMM) 1.1什么是Java内存模型? Java内存模型将内存分为主内存和工作内存两大部分;主内存...

  • [Java多线程编程之八] Java内存模型

    一、Java内存模型 == JVM内存模型?   很多人都会认为Java内存模型就是JVM内存模型,但实际上是错的...

  • 深度解析Java多线程的内存模型

    内部java内存模型 硬件层面的内存模型 Java内存模型和硬件内存模型的联系 共享对象的可见性 资源竞速 Jav...

  • java虚拟机-内存模型与线程

    一、java内存模型 java定义的内存模型是类似物理计算机的三级缓存模型 1.主内存与工作内存 java内存模型...

  • CPU内存模型 和 JAVA内存模型 讲解

    CPU 内存模型 在讲解 JAVA 内存模型之前,先了解 CPU 内存模型,因为JAVA内存模型跟它是十分相似的。...

  • Java基础之内存模型

    Java基础之内存模型 目录 Java内存模型简单介绍 JVM介绍 存储方式 并发原因 Java内存模型与系统内存...

网友评论

    本文标题:2-JVM-内存模型

    本文链接:https://www.haomeiwen.com/subject/gxooaxtx.html