42650
|
1 |
/*
|
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation.
|
|
8 |
*
|
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
13 |
* accompanied this code).
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License version
|
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 |
*
|
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
20 |
* or visit www.oracle.com if you need additional information or have any
|
|
21 |
* questions.
|
|
22 |
*/
|
|
23 |
|
|
24 |
#ifndef SHARE_VM_AOT_AOTCODEHEAP_HPP
|
|
25 |
#define SHARE_VM_AOT_AOTCODEHEAP_HPP
|
|
26 |
|
|
27 |
#include "aot/aotCompiledMethod.hpp"
|
|
28 |
#include "classfile/symbolTable.hpp"
|
|
29 |
#include "oops/metadata.hpp"
|
|
30 |
#include "oops/method.hpp"
|
|
31 |
|
|
32 |
enum CodeState {
|
|
33 |
not_set = 0, // _aot fields is not set yet
|
|
34 |
in_use = 1, // _aot field is set to corresponding AOTCompiledMethod
|
|
35 |
invalid = 2 // AOT code is invalidated because dependencies failed
|
|
36 |
};
|
|
37 |
|
|
38 |
typedef struct {
|
|
39 |
AOTCompiledMethod* _aot;
|
|
40 |
CodeState _state; // State change cases: not_set->in_use, not_set->invalid
|
|
41 |
} CodeToAMethod;
|
|
42 |
|
|
43 |
class ClassLoaderData;
|
|
44 |
|
|
45 |
class AOTClass {
|
|
46 |
public:
|
|
47 |
ClassLoaderData* _classloader;
|
|
48 |
};
|
|
49 |
|
|
50 |
typedef struct {
|
|
51 |
int _name_offset;
|
|
52 |
int _code_offset;
|
|
53 |
int _meta_offset;
|
|
54 |
int _metadata_got_offset;
|
|
55 |
int _metadata_got_size;
|
|
56 |
int _code_id;
|
|
57 |
} AOTMethodOffsets;
|
|
58 |
|
|
59 |
typedef struct {
|
|
60 |
const char* _name;
|
|
61 |
address _code;
|
|
62 |
aot_metadata* _meta;
|
|
63 |
jlong* _state_adr;
|
|
64 |
address _metadata_table;
|
|
65 |
int _metadata_size;
|
|
66 |
} AOTMethodData;
|
|
67 |
|
|
68 |
typedef struct {
|
|
69 |
int _got_index;
|
|
70 |
int _class_id;
|
|
71 |
int _compiled_methods_offset;
|
|
72 |
int _dependent_methods_offset;
|
|
73 |
uint64_t _fingerprint;
|
|
74 |
} AOTKlassData;
|
|
75 |
|
|
76 |
typedef struct {
|
|
77 |
int _version;
|
|
78 |
int _class_count;
|
|
79 |
int _method_count;
|
|
80 |
int _metaspace_got_size;
|
|
81 |
int _metadata_got_size;
|
|
82 |
int _oop_got_size;
|
|
83 |
int _jvm_version_offset;
|
|
84 |
|
|
85 |
enum {
|
|
86 |
AOT_SHARED_VERSION = 1
|
|
87 |
};
|
|
88 |
} AOTHeader;
|
|
89 |
|
|
90 |
typedef struct {
|
|
91 |
enum { CONFIG_SIZE = 11 + 7 * 4 };
|
|
92 |
int _config_size;
|
|
93 |
int _narrowOopShift;
|
|
94 |
int _narrowKlassShift;
|
|
95 |
int _contendedPaddingWidth;
|
|
96 |
int _fieldsAllocationStyle;
|
|
97 |
int _objectAlignment;
|
|
98 |
int _codeSegmentSize;
|
|
99 |
// byte[11] array map to boolean values here
|
|
100 |
bool _debug_VM;
|
|
101 |
bool _useCompressedOops;
|
|
102 |
bool _useCompressedClassPointers;
|
|
103 |
bool _compactFields;
|
|
104 |
bool _useG1GC;
|
|
105 |
bool _useCMSGC;
|
|
106 |
bool _useTLAB;
|
|
107 |
bool _useBiasedLocking;
|
|
108 |
bool _tieredAOT;
|
|
109 |
bool _enableContended;
|
|
110 |
bool _restrictContended;
|
|
111 |
} AOTConfiguration;
|
|
112 |
|
|
113 |
class AOTLib : public CHeapObj<mtCode> {
|
|
114 |
static bool _narrow_oop_shift_initialized;
|
|
115 |
static int _narrow_oop_shift;
|
|
116 |
static int _narrow_klass_shift;
|
|
117 |
|
|
118 |
bool _valid;
|
|
119 |
void* _dl_handle;
|
|
120 |
const int _dso_id;
|
|
121 |
const char* _name;
|
|
122 |
// VM configuration during AOT compilation
|
|
123 |
AOTConfiguration* _config;
|
|
124 |
AOTHeader* _header;
|
|
125 |
|
|
126 |
void handle_config_error(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
|
|
127 |
public:
|
|
128 |
AOTLib(void* handle, const char* name, int dso_id);
|
|
129 |
virtual ~AOTLib();
|
|
130 |
static int narrow_oop_shift() { return _narrow_oop_shift; }
|
|
131 |
static int narrow_klass_shift() { return _narrow_klass_shift; }
|
|
132 |
static bool narrow_oop_shift_initialized() { return _narrow_oop_shift_initialized; }
|
|
133 |
|
|
134 |
bool is_valid() const {
|
|
135 |
return _valid;
|
|
136 |
}
|
|
137 |
const char* name() const {
|
|
138 |
return _name;
|
|
139 |
}
|
|
140 |
void* dl_handle() const {
|
|
141 |
return _dl_handle;
|
|
142 |
}
|
|
143 |
int id() const {
|
|
144 |
return _dso_id;
|
|
145 |
}
|
|
146 |
AOTHeader* header() const {
|
|
147 |
return _header;
|
|
148 |
}
|
|
149 |
AOTConfiguration* config() const {
|
|
150 |
return _config;
|
|
151 |
}
|
|
152 |
void verify_config();
|
|
153 |
void verify_flag(bool aot_flag, bool flag, const char* name);
|
|
154 |
void verify_flag(int aot_flag, int flag, const char* name);
|
|
155 |
|
|
156 |
address load_symbol(const char *name);
|
|
157 |
};
|
|
158 |
|
|
159 |
|
|
160 |
class AOTCodeHeap : public CodeHeap {
|
|
161 |
AOTLib* _lib;
|
|
162 |
int _aot_id;
|
|
163 |
|
|
164 |
int _class_count;
|
|
165 |
int _method_count;
|
|
166 |
AOTClass* _classes;
|
|
167 |
CodeToAMethod* _code_to_aot;
|
|
168 |
|
|
169 |
address _code_space;
|
|
170 |
address _code_segments;
|
|
171 |
jlong* _method_state;
|
|
172 |
|
|
173 |
|
|
174 |
// Collect metaspace info: names -> address in .got section
|
|
175 |
const char* _metaspace_names;
|
|
176 |
address _method_metadata;
|
|
177 |
|
|
178 |
address _methods_offsets;
|
|
179 |
address _klasses_offsets;
|
|
180 |
address _dependencies;
|
|
181 |
|
|
182 |
Metadata** _metaspace_got;
|
|
183 |
Metadata** _metadata_got;
|
|
184 |
oop* _oop_got;
|
|
185 |
|
|
186 |
int _metaspace_got_size;
|
|
187 |
int _metadata_got_size;
|
|
188 |
int _oop_got_size;
|
|
189 |
|
|
190 |
// Collect stubs info
|
|
191 |
int* _stubs_offsets;
|
|
192 |
|
|
193 |
address _low_boundary;
|
|
194 |
|
|
195 |
bool _lib_symbols_initialized;
|
|
196 |
|
|
197 |
void adjust_boundaries(AOTCompiledMethod* method) {
|
|
198 |
address low = _low_boundary;
|
|
199 |
if (method->code_begin() < low) {
|
|
200 |
low = method->code_begin();
|
|
201 |
}
|
|
202 |
address high = high_boundary();
|
|
203 |
if (method->code_end() > high) {
|
|
204 |
high = method->code_end();
|
|
205 |
}
|
|
206 |
assert(_method_count > 0, "methods count should be set already");
|
|
207 |
|
|
208 |
_low_boundary = low;
|
|
209 |
_memory.set_high_boundary((char *)high);
|
|
210 |
_memory.set_high((char *)high);
|
|
211 |
}
|
|
212 |
|
|
213 |
void register_stubs();
|
|
214 |
|
|
215 |
void link_shared_runtime_symbols();
|
|
216 |
void link_stub_routines_symbols();
|
|
217 |
void link_os_symbols();
|
|
218 |
void link_graal_runtime_symbols();
|
|
219 |
|
|
220 |
void link_global_lib_symbols();
|
|
221 |
void link_primitive_array_klasses();
|
|
222 |
void publish_aot(const methodHandle& mh, AOTMethodData* method_data, int code_id);
|
|
223 |
|
|
224 |
|
|
225 |
AOTCompiledMethod* next_in_use_at(int index) const;
|
|
226 |
|
|
227 |
// Find klass in SystemDictionary for aot metadata.
|
|
228 |
static Klass* lookup_klass(const char* name, int len, const Method* method, Thread* THREAD);
|
|
229 |
public:
|
|
230 |
AOTCodeHeap(AOTLib* lib);
|
|
231 |
virtual ~AOTCodeHeap();
|
|
232 |
|
|
233 |
address low_boundary() const { return _low_boundary; }
|
|
234 |
address high_boundary() const { return (address)CodeHeap::high(); }
|
|
235 |
|
|
236 |
bool contains(const void* p) const {
|
|
237 |
bool result = (low_boundary() <= p) && (p < high_boundary());
|
|
238 |
assert(!result || (_method_count > 0), "");
|
|
239 |
assert(result == CodeHeap::contains(p), "");
|
|
240 |
return result;
|
|
241 |
}
|
|
242 |
AOTCompiledMethod* find_aot(address p) const;
|
|
243 |
|
|
244 |
virtual void* find_start(void* p) const;
|
|
245 |
virtual CodeBlob* find_blob_unsafe(void* start) const;
|
|
246 |
virtual void* first() const;
|
|
247 |
virtual void* next(void *p) const;
|
|
248 |
|
|
249 |
AOTKlassData* find_klass(InstanceKlass* ik);
|
|
250 |
bool load_klass_data(instanceKlassHandle kh, Thread* thread);
|
|
251 |
Klass* get_klass_from_got(const char* klass_name, int klass_len, const Method* method);
|
|
252 |
void sweep_dependent_methods(AOTKlassData* klass_data);
|
|
253 |
bool is_dependent_method(Klass* dependee, AOTCompiledMethod* aot);
|
|
254 |
|
|
255 |
const char* get_name_at(int offset) {
|
|
256 |
return _metaspace_names + offset;
|
|
257 |
}
|
|
258 |
|
|
259 |
void oops_do(OopClosure* f);
|
|
260 |
void metadata_do(void f(Metadata*));
|
|
261 |
void got_metadata_do(void f(Metadata*));
|
|
262 |
|
|
263 |
#ifdef ASSERT
|
|
264 |
bool got_contains(Metadata **p) {
|
|
265 |
return (p >= &_metadata_got[0] && p < &_metadata_got[_metadata_got_size]) ||
|
|
266 |
(p >= &_metaspace_got[0] && p < &_metaspace_got[_metaspace_got_size]);
|
|
267 |
}
|
|
268 |
#endif
|
|
269 |
|
|
270 |
int dso_id() const { return _lib->id(); }
|
|
271 |
int aot_id() const { return _aot_id; }
|
|
272 |
|
|
273 |
int method_count() { return _method_count; }
|
|
274 |
|
|
275 |
AOTCompiledMethod* get_code_desc_at_index(int index) {
|
|
276 |
if (index < _method_count && _code_to_aot[index]._state == in_use) {
|
|
277 |
AOTCompiledMethod* m = _code_to_aot[index]._aot;
|
|
278 |
assert(m != NULL, "AOT method should be set");
|
|
279 |
if (!m->is_runtime_stub()) {
|
|
280 |
return m;
|
|
281 |
}
|
|
282 |
}
|
|
283 |
return NULL;
|
|
284 |
}
|
|
285 |
|
|
286 |
static Method* find_method(KlassHandle klass, Thread* thread, const char* method_name);
|
|
287 |
|
|
288 |
void cleanup_inline_caches();
|
|
289 |
|
|
290 |
DEBUG_ONLY( int verify_icholder_relocations(); )
|
|
291 |
|
|
292 |
void flush_evol_dependents_on(instanceKlassHandle dependee);
|
|
293 |
|
|
294 |
void alive_methods_do(void f(CompiledMethod* nm));
|
|
295 |
|
|
296 |
#ifndef PRODUCT
|
|
297 |
static int klasses_seen;
|
|
298 |
static int aot_klasses_found;
|
|
299 |
static int aot_klasses_fp_miss;
|
|
300 |
static int aot_klasses_cl_miss;
|
|
301 |
static int aot_methods_found;
|
|
302 |
|
|
303 |
static void print_statistics();
|
|
304 |
#endif
|
|
305 |
};
|
|
306 |
|
|
307 |
#endif // SHARE_VM_AOT_AOTCODEHEAP_HPP
|