jvm源码解读--09 创建oop对象,将static静态变量放置在oop的96 offset处 第二篇
2021/4/9 20:26:02
本文主要是介绍jvm源码解读--09 创建oop对象,将static静态变量放置在oop的96 offset处 第二篇,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
先打断点systemDictionary.cpp 1915行
Universe::fixup_mirrors(CHECK);
进入
void Universe::fixup_mirrors(TRAPS) { // Bootstrap problem: all classes gets a mirror (java.lang.Class instance) assigned eagerly, // but we cannot do that for classes created before java.lang.Class is loaded. Here we simply // walk over permanent objects created so far (mostly classes) and fixup their mirrors. Note // that the number of objects allocated at this point is very small. assert(SystemDictionary::Class_klass_loaded(), "java.lang.Class should be loaded"); HandleMark hm(THREAD); // Cache the start of the static fields InstanceMirrorKlass::init_offset_of_static_fields(); GrowableArray <Klass*>* list = java_lang_Class::fixup_mirror_list(); int list_length = list->length(); for (int i = 0; i < list_length; i++) { Klass* k = list->at(i); assert(k->is_klass(), "List should only hold classes"); EXCEPTION_MARK; KlassHandle kh(THREAD, k); java_lang_Class::fixup_mirror(kh, CATCH); } delete java_lang_Class::fixup_mirror_list(); java_lang_Class::set_fixup_mirror_list(NULL); }
给红色打断点,当i=12的时候进入java.lang.String类的解析
void java_lang_Class::fixup_mirror(KlassHandle k, TRAPS) { assert(InstanceMirrorKlass::offset_of_static_fields() != 0, "must have been computed already"); // If the offset was read from the shared archive, it was fixed up already if (!k->is_shared()) { if (k->oop_is_instance()) { // During bootstrap, java.lang.Class wasn't loaded so static field // offsets were computed without the size added it. Go back and // update all the static field offsets to included the size. for (JavaFieldStream fs(InstanceKlass::cast(k())); !fs.done(); fs.next()) { if (fs.access_flags().is_static()) { int real_offset = fs.offset() + InstanceMirrorKlass::offset_of_static_fields(); fs.set_offset(real_offset); } } } } create_mirror(k, Handle(NULL), CHECK); }
给紫色的构造器
JavaFieldStream(instanceKlassHandle k): FieldStreamBase(k->fields(), k->constants(), 0, k->java_fields_count()) {} FieldStreamBase(Array<u2>* fields, constantPoolHandle constants, int start, int limit) { _fields = fields; _constants = constants; _index = start; int num_fields = init_generic_signature_start_slot(); if (limit < start) { _limit = num_fields; } else { _limit = limit; } }
打印对象
(gdb) p fields
$25 = (Array<unsigned short> *) 0x7f28e0a03280
(gdb) x/36h fields
0x7f28e0a03280: 0x001f 0x0000 0x0012 0x0098 0x0099 0x0000 {{ 0x0031 0x0000
0x7f28e0a03290: 0x0002 0x009a 0x009b 0x0000 }}{{ 0x0041 0x0000 0x001a 0x009c
0x7f28e0a032a0: 0x009d 0x009f}}{{ 0x0021 0x0000 0x001a 0x00a1 0x00a2 0x0000
0x7f28e0a032b0: 0x0001 0x0000 0x0819 0x00a3 0x00a4 0x0000 }}{{0x0011 0x0000
0x7f28e0a032c0: 0x00a6 0x0000 0x0000 0x0000}}
这篇关于jvm源码解读--09 创建oop对象,将static静态变量放置在oop的96 offset处 第二篇的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign学习入门:轻松掌握微服务通信
- 2024-12-27OpenFeign学习入门:轻松掌握微服务间的HTTP请求
- 2024-12-27JDK17新特性学习入门:简洁教程带你轻松上手
- 2024-12-27JMeter传递token学习入门教程
- 2024-12-27JMeter压测学习入门指南
- 2024-12-27JWT单点登录学习入门指南
- 2024-12-27JWT单点登录原理学习入门
- 2024-12-27JWT单点登录原理学习入门