-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJvmStructures.hpp
More file actions
205 lines (164 loc) · 4.66 KB
/
JvmStructures.hpp
File metadata and controls
205 lines (164 loc) · 4.66 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "Offsets.hpp"
#include <jni.h>
#define FIELDINFO_TAG_OFFSET 1
#define FIELDINFO_TAG_SIZE 2
#define FIELDINFO_TAG_MASK 3
#pragma warning(disable:4312)
class InstanceKlass;
class oopDesc;
typedef unsigned short u2;
typedef unsigned int u4;
typedef oopDesc* oop;
class Symbol {
public:
unsigned short _length;
unsigned short _pad_0;
int _identity_hash;
char _body[1];
std::string as_string() {
return std::string(_body, _length);
}
};
template<typename T>
class Array {
public:
int _length;
T _data[1];
T at(int index) { return _data[index]; }
T* adr_at(int index) { return &_data[index]; }
};
class ClassLoaderData {
public:
InstanceKlass* klasses() {
return *reinterpret_cast<InstanceKlass**>((BYTE*)this + cld_klasses_offset);
}
};
class ConstantPool {
public:
Symbol* symbol_at(int index) {
return *reinterpret_cast<Symbol**>((BYTE*)this + cp_sizeof + (index * 8));
}
};
class ConstMethod {
public:
ConstantPool* constants() {
return *reinterpret_cast<ConstantPool**>((BYTE*)this + cm_constants_offset);
}
u2 name_index() {
return *reinterpret_cast<u2*>((BYTE*)this + cm_name_index_offset);
}
u2 signature_index() {
return *reinterpret_cast<u2*>((BYTE*)this + cm_signature_index_offset);
}
};
class nmethod {
public:
void* verified_entry_point() {
return *reinterpret_cast<void**>((BYTE*)this + nm_verified_entry_point_offset);
}
};
class Method {
public:
ConstMethod* constmethod() {
return *reinterpret_cast<ConstMethod**>((BYTE*)this + m_constmethod_offset);
}
void* i2i_entry() {
return *reinterpret_cast<void**>((BYTE*)this + m_i2i_entry_offset);
}
nmethod* code() {
return *reinterpret_cast<nmethod**>((BYTE*)this + m_code_offset);
}
inline static Method* resolve_jmethod_id(jmethodID mid) {
return *reinterpret_cast<Method**>(mid);
}
BYTE* flags() {
return (BYTE*)this + m_flags_offset;
}
};
class oopDesc {
public:
inline void* field_base(int offset) const {
return reinterpret_cast<void*>(&((BYTE*)this)[offset]);
}
inline oop obj_field(int offset) {
return reinterpret_cast<oop>(*reinterpret_cast<uint32_t*>(field_base(offset)));
}
template<typename T>
T get_field(int offset) {
return *reinterpret_cast<T*>(field_base(offset));
}
template<typename T>
void set_field(int offset, T value) {
*reinterpret_cast<T*>(field_base(offset)) = value;
}
inline InstanceKlass* instanceof() {
return reinterpret_cast<InstanceKlass*>((uintptr_t) * reinterpret_cast<DWORD*>((BYTE*)this + 8) << 3);
}
};
class InstanceKlass {
public:
Symbol* name() {
return *reinterpret_cast<Symbol**>((BYTE*)this + k_name_offset);
}
ClassLoaderData* class_loader_data() {
return *reinterpret_cast<ClassLoaderData**>((BYTE*)this + k_class_loader_data_offset);
}
oop java_mirror() {
return *reinterpret_cast<oop*>((BYTE*)this + k_java_mirror_offset);
}
InstanceKlass* next_link() {
return *reinterpret_cast<InstanceKlass**>((BYTE*)this + k_next_link_offset);
}
Array<Method*>* methods() {
return *reinterpret_cast<Array<Method*>**>((BYTE*)this + ik_methods_offset);
}
Array<u2>* fields() {
return *reinterpret_cast<Array<u2>**>((BYTE*)this + ik_fields_offset);
}
ConstantPool* constants() {
return *reinterpret_cast<ConstantPool**>((BYTE*)this + ik_constants_offset);
}
};
class FieldInfo {
private:
inline int build_int_from_shorts(u2 low, u2 high) {
return ((int)((unsigned int)high << 16) | (unsigned int)low);
}
public:
enum FieldOffset {
access_flags_offset = 0,
name_index_offset = 1,
signature_index_offset = 2,
initval_index_offset = 3,
low_packed_offset = 4,
high_packed_offset = 5,
field_slots = 6
};
u2 _shorts[field_slots];
u2 name_index() const { return _shorts[name_index_offset]; }
u2 signature_index() const { return _shorts[signature_index_offset]; }
static FieldInfo* from_field_array(Array<u2>* fields, int index) {
return reinterpret_cast<FieldInfo*>(fields->adr_at(index * field_slots));
}
u4 offset() {
u2 lo = _shorts[low_packed_offset];
if ((lo & FIELDINFO_TAG_MASK) == FIELDINFO_TAG_OFFSET)
return build_int_from_shorts(_shorts[low_packed_offset], _shorts[high_packed_offset]) >> FIELDINFO_TAG_SIZE;
return 0;
}
};
class CollectedHeap {
private:
typedef size_t(*capacity_t)(CollectedHeap* instance);
public:
BYTE* vftable;
size_t capacity() {
return (*reinterpret_cast<capacity_t*>(vftable + collected_heap_capacity_offset))(this);
}
};
class Universe {
public:
static CollectedHeap* heap() {
return *reinterpret_cast<CollectedHeap**>(collected_heap);
}
};