jvm - JAVA常量池的作用
PHP中文网
PHP中文网 2017-04-17 11:26:53
[Java讨论组]

对常量池有一定的了解,但是感觉没有直观的明白常量池的作用,如果方法区中没有常量池这块内存空间,程序不也可以照常跑么?这个区域的作用到底是什么呢?

PHP中文网
PHP中文网

认证0级讲师

全部回复(1)
高洛峰

仅说一下我认为比较重要的地方, 如果你去看java 字节码, 会看到这种东西:

 279: invokevirtual #127     // Method java/lang/Throwable.addSuppressed:Ljava/lang/Throwable;)V

127 即代表 此class中的一个常量池元素, 如果你去看jvm spec7:

invokevirtual ... Description The unsigned indexbyte1 and indexbyte2 are used to construct an index into the run-time constant pool of the current class (§2.6), where the value of the index is (indexbyte1 << 8) | indexbyte2. The run-time constant pool item at that index must be a symbolic reference to a method (§5.1), which gives the name and descriptor (§4.3.3) of the method as well as a symbolic reference to the class in which the method is to be found.

简单说, jvm正是使用 常量池元素 "Method java/lang/Throwable.addSuppressed:Ljava/lang/Throwable;)V" 找到需要调用的 class和方法.

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号