禅意coder 禅意coder
首页
  • 跟我一起学NodeJs
  • JavaScript 异步编程
  • kafka 相关知识
  • 分类
  • 标签
  • 归档
关于
GitHub
首页
  • 跟我一起学NodeJs
  • JavaScript 异步编程
  • kafka 相关知识
  • 分类
  • 标签
  • 归档
关于
GitHub
  • 一起学nodejs

  • javascript 异步编程

  • kafka知识

  • linux的奥义

  • java语言

    • java 常量池
      • 关于java常量池的理解
        • jdk6
        • jdk7
        • 回顾一个jvm 类加载过程
      • 参考资料
    • java 并发01-synchoronized与volatile
  • 系列文章
  • java语言
liushaoqing
2019-01-15

java 常量池

# 关于java常量池的理解

最近刚学习了jvm的知识,关于java常量池书中只说到了jdk1.6的常量池模型,而且关于jdk1.7,1.8 网上也众说纷纭,之前面试也屡屡被问起,屡屡不懂,我们就来研究一下,闲话少说:

# jdk6

引用自jdk6 jvm 说明书

A runtime constant pool is a per-class or per-interface runtime representation of the constant_pool table in a class file (§4.4). It contains several kinds of constants, ranging from numeric literals known at compile time to method and field references that must be resolved at run time. The runtime constant pool serves a function similar to that of a symbol table for a conventional programming language, although it contains a wider range of data than a typical symbol table. Each runtime constant pool is allocated from the Java virtual machine's method area (§3.5.4). The runtime constant pool for a class or interface is constructed when the class or interface is created (§5.3) by the Java virtual machine.

运行时常量池是java每一个类(或接口)的类文件的一个常量表,包含多种类型,编译时的基本数据类型, 运行时的引用类型.运行时常量池提供的功能类似于传统编程语言的符号表,虽然它的数据范围比符号表更广。 每一个运行时常量池都是从jvm的方法区分配的,当类(或接口)创建的时候,那么这个类(或接口)的常量池就会被创建.

# jdk7

A run-time constant pool is a per-class or per-interface run-time representation of the constant_pool table in a class file (§4.4). It contains several kinds of constants, ranging from numeric literals known at compile-time to method and field references that must be resolved at run-time. The run-time constant pool serves a function similar to that of a symbol table for a conventional programming language, although it contains a wider range of data than a typical symbol table. Each run-time constant pool is allocated from the Java Virtual Machine's method area (§2.5.4). The run-time constant pool for a class or interface is constructed when the class or interface is created (§5.3) by the Java Virtual Machine.

# 回顾一个jvm 类加载过程

# load

找到具有特定名称的类或接口类型的二进制表示并从该二进制表示中创建类或接口

# link

获取类或接口并将其组合到Java虚拟机的运行时的状态.

# initializesk

执行类或接口初始化方法组成

# 参考资料

  • Java Language and Virtual Machine Specifications
  • se6 jvm
  • se7 jvm
  • 美团技术团队
  • ScjpTipLine-StringsLiterally.
  • java-string-literal-and-string-constant-pool-concept
  • JVMInternals
  • string-constant-pool-adn-intern
  • stackoverflow purpose of constant pool
  • java-string-pool
编辑
上次更新: 2021/01/23, 09:10:58
命令行日常使用配置
java 并发01-synchoronized与volatile

← 命令行日常使用配置 java 并发01-synchoronized与volatile→

最近更新
01
轮子哥编程的感悟(转载)
01-23
02
tmux 配置和使用
01-23
03
命令行日常使用配置
01-15
更多文章>
Theme by Vdoing | Copyright © 2020-2021 刘少卿 | MIT License
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×