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}}
标签:lang,java,--,fields,0x0000,源码,oop,offset,Class 来源: https://www.cnblogs.com/zytcomeon/p/14638408.html