JVM源码实战 - OOP-Klass模型
【摘要】 1 OOP-Klass(Ordinary Object Pointer)模型
OOP-Klass模型用来描述class的属性和行为 设计为OOP和Klass两部分是因为不希望每个对象都有一个C ++ vtbl指针, 因此,普通的oops没有任何虚拟功能。 相反,他们将所有“虚拟”函数转发到它们的klass,它具有vtbl并根据对象的实际类型执行C ++调度。
1.1...
1 OOP-Klass(Ordinary Object Pointer)模型
OOP-Klass模型用来描述class的属性和行为
设计为OOP和Klass两部分是因为不希望每个对象都有一个C ++ vtbl指针, 因此,普通的oops没有任何虚拟功能。 相反,他们将所有“虚拟”函数转发到它们的klass,它具有vtbl并根据对象的实际类型执行C ++调度。
1.1 OOP
oopDesc是对象类的最高父类。 {name}Desc类描述了Java对象的格式,可从C++访问这些字段
- 路径:
/hotspot/share/oops/oop.hpp
完整的类层次结构,请阅读src/hotspot/share/oops/oopsHierarchy.hpp
- OOP体系
1.2 Klass
- Klass体系
Klass对象提供 - 语言级别的类对象(方法字典等)
- 为对象提供虚拟机调度行为
class Klass : public Metadata {
friend class VMStructs;
friend class JVMCIVMStructs;
protected:
// 如果添加指向任何元数据对象的新字段,则必须将此字段添加到Klass :: metaspace_pointers_do()
// 注意:在klass结构的起始处将常用字段放在一起,以获得更好的缓存行为(虽然可能不会有太大的区别,但可以肯定不会造成伤害)
enum { _primary_super_limit = 8 }; // The "layout helper" is a combined descriptor of object layout.
// For klasses which are neither instance nor array, the value is zero.
//
// For instances, layout helper is a positive number, the instance size.
// This size is already passed through align_object_size and scaled to bytes.
// The low order bit is set if instances of this class cannot be
// allocated using the fastpath.
//
// For arrays, layout helper is a negative number, containing four
// distinct bytes, as follows:
// MSB:[tag, hsz, ebt, log2(esz)]:LSB
// where:
// tag is 0x80 if the elements are oops, 0xC0 if non-oops
// hsz is array header size in bytes (i.e., offset of first element)
// ebt is the BasicType of the elements
// esz is the element size in bytes
// This packed word is arranged so as to be quickly unpacked by the
// various fast paths that use the various subfields.
//
// The esz bits can be used directly by a SLL instruction, without masking.
//
// Note that the array-kind tag looks like 0x00 for instance klasses,
// since their length in bytes is always less than 24Mb.
//
// Final note: This comes first, immediately after C++ vtable,
// because it is frequently queried.
jint _layout_helper; // Klass identifier used to implement devirtualized oop closure dispatching.
const KlassID _id; // The fields _super_check_offset, _secondary_super_cache, _secondary_supers
// and _primary_supers all help make fast subtype checks. See big discussion
// in doc/server_compiler/checktype.txt
//
// Where to look to observe a supertype (it is &_secondary_super_cache for
// secondary supers, else is &_primary_supers[depth()].
juint _super_check_offset; // 类名. Instance classes: java/lang/String, etc. Array classes: [I,
// [Ljava/lang/String;, etc. Set to zero for all other kinds of classes.
Symbol* _name; // Cache of last observed secondary supertype
Klass* _secondary_super_cache;
// Array of all secondary supertypes
Array<Klass*>* _secondary_supers;
// Ordered list of all primary supertypes
Klass* _primary_supers[_primary_super_limit];
// java/lang/Class instance mirroring this class
OopHandle _java_mirror;
// Superclass
Klass* _super;
// First subclass (NULL if none); _subklass->next_sibling() is next one
Klass* volatile _subklass;
// Sibling link (or NULL); links all subklasses of a klass
Klass* volatile _next_sibling; // All klasses loaded by a class loader are chained through these links
Klass* _next_link; // 用于加载此类的VM对类加载器的表示。
//提供访问相应的java.lang.ClassLoader实例
ClassLoaderData* _class_loader_data; jint _modifier_flags; // 处理的访问标志,由Class.getModifiers使用
AccessFlags _access_flags; // 访问标志。 类/接口的区别就存储在这里 JFR_ONLY(DEFINE_TRACE_ID_FIELD;) // 偏向锁定实现和统计
// 64位块优先,以避免碎片
jlong _last_biased_lock_bulk_revocation_time;
markOop _prototype_header; // Used when biased locking is both enabled and disabled for this type
jint _biased_lock_revocation_count; // 虚表长度
int _vtable_len;
...
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
文章来源: javaedge.blog.csdn.net,作者:JavaEdge.,版权归原作者所有,如需转载,请联系作者。
原文链接:javaedge.blog.csdn.net/article/details/103286134
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)