1 /*
2 * Copyright (c) 2025, 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
25 #ifndef SHARE_CODE_AOTCODECACHE_HPP
26 #define SHARE_CODE_AOTCODECACHE_HPP
27
28 /*
29 * AOT Code Cache collects code from Code Cache and corresponding metadata
30 * during application training run.
31 * In following "production" runs this code and data can be loaded into
32 * Code Cache skipping its generation.
33 */
34
35 class CodeBuffer;
36 class RelocIterator;
37 class AOTCodeCache;
38 class AdapterBlob;
39 class ExceptionBlob;
40 class ImmutableOopMapSet;
41 class AsmRemarks;
42 class DbgStrings;
43
44 enum class vmIntrinsicID : int;
45 enum CompLevel : signed char;
46
47 #define DO_AOTCODEENTRY_KIND(Fn) \
48 Fn(None) \
49 Fn(Adapter) \
50 Fn(SharedBlob) \
51 Fn(C1Blob) \
52 Fn(C2Blob) \
53
54 // Descriptor of AOT Code Cache's entry
55 class AOTCodeEntry {
56 public:
57 enum Kind : s1 {
58 #define DECL_KIND_ENUM(kind) kind,
59 DO_AOTCODEENTRY_KIND(DECL_KIND_ENUM)
60 #undef DECL_KIND_ENUM
61 Kind_count
62 };
63
64 private:
65 AOTCodeEntry* _next;
66 Kind _kind;
67 uint _id; // Adapter's id, vmIntrinsic::ID for stub or name's hash for nmethod
68 uint _offset; // Offset to entry
69 uint _size; // Entry size
70 uint _name_offset; // Code blob name
71 uint _name_size;
72 uint _blob_offset; // Start of code in cache
73 bool _has_oop_maps;
74 address _dumptime_content_start_addr; // CodeBlob::content_begin() at dump time; used for applying relocations
75
76 public:
77 AOTCodeEntry(Kind kind, uint id,
78 uint offset, uint size,
79 uint name_offset, uint name_size,
80 uint blob_offset, bool has_oop_maps,
81 address dumptime_content_start_addr) {
82 _next = nullptr;
83 _kind = kind;
84 _id = id;
85 _offset = offset;
86 _size = size;
87 _name_offset = name_offset;
88 _name_size = name_size;
89 _blob_offset = blob_offset;
90 _has_oop_maps = has_oop_maps;
91 _dumptime_content_start_addr = dumptime_content_start_addr;
92 }
93 void* operator new(size_t x, AOTCodeCache* cache);
94 // Delete is a NOP
95 void operator delete( void *ptr ) {}
96
97 AOTCodeEntry* next() const { return _next; }
98 void set_next(AOTCodeEntry* next) { _next = next; }
99
100 Kind kind() const { return _kind; }
101 uint id() const { return _id; }
102
103 uint offset() const { return _offset; }
104 void set_offset(uint off) { _offset = off; }
105
106 uint size() const { return _size; }
107 uint name_offset() const { return _name_offset; }
108 uint name_size() const { return _name_size; }
109 uint blob_offset() const { return _blob_offset; }
110 bool has_oop_maps() const { return _has_oop_maps; }
111 address dumptime_content_start_addr() const { return _dumptime_content_start_addr; }
112
113 static bool is_valid_entry_kind(Kind kind) { return kind > None && kind < Kind_count; }
114 static bool is_blob(Kind kind) { return kind == SharedBlob || kind == C1Blob || kind == C2Blob; }
115 static bool is_adapter(Kind kind) { return kind == Adapter; }
116 };
117
118 // Addresses of stubs, blobs and runtime finctions called from compiled code.
119 class AOTCodeAddressTable : public CHeapObj<mtCode> {
120 private:
121 address* _extrs_addr;
122 address* _stubs_addr;
123 address* _shared_blobs_addr;
124 address* _C1_blobs_addr;
125 uint _extrs_length;
126 uint _stubs_length;
127 uint _shared_blobs_length;
128 uint _C1_blobs_length;
129
130 bool _extrs_complete;
131 bool _early_stubs_complete;
132 bool _shared_blobs_complete;
133 bool _early_c1_complete;
134 bool _complete;
135
136 public:
137 AOTCodeAddressTable() :
138 _extrs_addr(nullptr),
139 _shared_blobs_addr(nullptr),
140 _C1_blobs_addr(nullptr),
141 _extrs_length(0),
142 _stubs_length(0),
143 _shared_blobs_length(0),
144 _C1_blobs_length(0),
145 _extrs_complete(false),
146 _early_stubs_complete(false),
147 _shared_blobs_complete(false),
148 _early_c1_complete(false),
149 _complete(false)
150 { }
151 ~AOTCodeAddressTable();
152 void init_extrs();
153 void init_early_stubs();
154 void init_shared_blobs();
155 void init_early_c1();
156 const char* add_C_string(const char* str);
157 int id_for_C_string(address str);
158 address address_for_C_string(int idx);
159 int id_for_address(address addr, RelocIterator iter, CodeBlob* code_blob);
160 address address_for_id(int id);
161 };
162
163 class AOTCodeCache : public CHeapObj<mtCode> {
164
165 // Classes used to describe AOT code cache.
166 protected:
167 class Config {
168 address _compressedOopBase;
169 uint _compressedOopShift;
170 uint _compressedKlassShift;
171 uint _contendedPaddingWidth;
172 uint _objectAlignment;
173 uint _gc;
174 enum Flags {
175 none = 0,
176 debugVM = 1,
177 compressedOops = 2,
178 compressedClassPointers = 4,
179 useTLAB = 8,
180 systemClassAssertions = 16,
181 userClassAssertions = 32,
182 enableContendedPadding = 64,
183 restrictContendedPadding = 128
184 };
185 uint _flags;
186
187 public:
188 void record();
189 bool verify() const;
190 };
191
192 class Header : public CHeapObj<mtCode> {
193 private:
194 enum {
195 AOT_CODE_VERSION = 1
196 };
197 uint _version; // AOT code version (should match when reading code cache)
198 uint _cache_size; // cache size in bytes
199 uint _strings_count; // number of recorded C strings
200 uint _strings_offset; // offset to recorded C strings
201 uint _entries_count; // number of recorded entries
202 uint _entries_offset; // offset of AOTCodeEntry array describing entries
203 uint _adapters_count;
204 uint _shared_blobs_count;
205 uint _C1_blobs_count;
206 uint _C2_blobs_count;
207 Config _config;
208
209 public:
210 void init(uint cache_size,
211 uint strings_count, uint strings_offset,
212 uint entries_count, uint entries_offset,
213 uint adapters_count, uint shared_blobs_count,
214 uint C1_blobs_count, uint C2_blobs_count) {
215 _version = AOT_CODE_VERSION;
216 _cache_size = cache_size;
217 _strings_count = strings_count;
218 _strings_offset = strings_offset;
219 _entries_count = entries_count;
220 _entries_offset = entries_offset;
221 _adapters_count = adapters_count;
222 _shared_blobs_count = shared_blobs_count;
223 _C1_blobs_count = C1_blobs_count;
224 _C2_blobs_count = C2_blobs_count;
225 _config.record();
226 }
227
228
229 uint cache_size() const { return _cache_size; }
230 uint strings_count() const { return _strings_count; }
231 uint strings_offset() const { return _strings_offset; }
232 uint entries_count() const { return _entries_count; }
233 uint entries_offset() const { return _entries_offset; }
234 uint adapters_count() const { return _adapters_count; }
235 uint shared_blobs_count() const { return _shared_blobs_count; }
236 uint C1_blobs_count() const { return _C1_blobs_count; }
237 uint C2_blobs_count() const { return _C2_blobs_count; }
238
239 bool verify_config(uint load_size) const;
240 bool verify_vm_config() const { // Called after Universe initialized
241 return _config.verify();
242 }
243 };
244
245 // Continue with AOTCodeCache class definition.
246 private:
247 Header* _load_header;
248 char* _load_buffer; // Aligned buffer for loading cached code
249 char* _store_buffer; // Aligned buffer for storing cached code
250 char* _C_store_buffer; // Original unaligned buffer
251
252 uint _write_position; // Position in _store_buffer
253 uint _load_size; // Used when reading cache
254 uint _store_size; // Used when writing cache
255 bool _for_use; // AOT cache is open for using AOT code
256 bool _for_dump; // AOT cache is open for dumping AOT code
257 bool _closing; // Closing cache file
258 bool _failed; // Failed read/write to/from cache (cache is broken?)
259 bool _lookup_failed; // Failed to lookup for info (skip only this code load)
260
261 AOTCodeAddressTable* _table;
262
263 AOTCodeEntry* _load_entries; // Used when reading cache
264 uint* _search_entries; // sorted by ID table [id, index]
265 AOTCodeEntry* _store_entries; // Used when writing cache
266 const char* _C_strings_buf; // Loaded buffer for _C_strings[] table
267 uint _store_entries_cnt;
268
269 static AOTCodeCache* open_for_use();
270 static AOTCodeCache* open_for_dump();
271
272 bool set_write_position(uint pos);
273 bool align_write();
274 address reserve_bytes(uint nbytes);
275 uint write_bytes(const void* buffer, uint nbytes);
276 const char* addr(uint offset) const { return _load_buffer + offset; }
277 static AOTCodeAddressTable* addr_table() {
278 return is_on() && (cache()->_table != nullptr) ? cache()->_table : nullptr;
279 }
280
281 void set_lookup_failed() { _lookup_failed = true; }
282 void clear_lookup_failed() { _lookup_failed = false; }
283 bool lookup_failed() const { return _lookup_failed; }
284
285 public:
286 AOTCodeCache(bool is_dumping, bool is_using);
287 ~AOTCodeCache();
288
289 const char* cache_buffer() const { return _load_buffer; }
290 bool failed() const { return _failed; }
291 void set_failed() { _failed = true; }
292
293 static uint max_aot_code_size();
294
295 uint load_size() const { return _load_size; }
296 uint write_position() const { return _write_position; }
297
298 void load_strings();
299 int store_strings();
300
301 static void init_extrs_table() NOT_CDS_RETURN;
302 static void init_early_stubs_table() NOT_CDS_RETURN;
303 static void init_shared_blobs_table() NOT_CDS_RETURN;
304 static void init_early_c1_table() NOT_CDS_RETURN;
305
306 address address_for_C_string(int idx) const { return _table->address_for_C_string(idx); }
307 address address_for_id(int id) const { return _table->address_for_id(id); }
308
309 bool for_use() const { return _for_use && !_failed; }
310 bool for_dump() const { return _for_dump && !_failed; }
311
312 bool closing() const { return _closing; }
313
314 AOTCodeEntry* add_entry() {
315 _store_entries_cnt++;
316 _store_entries -= 1;
317 return _store_entries;
318 }
319
320 AOTCodeEntry* find_entry(AOTCodeEntry::Kind kind, uint id);
321
322 bool finish_write();
323
324 bool write_relocations(CodeBlob& code_blob);
325 bool write_oop_map_set(CodeBlob& cb);
326 #ifndef PRODUCT
327 bool write_asm_remarks(CodeBlob& cb);
328 bool write_dbg_strings(CodeBlob& cb);
329 #endif // PRODUCT
330
331 static bool store_code_blob(CodeBlob& blob,
332 AOTCodeEntry::Kind entry_kind,
333 uint id, const char* name,
334 int entry_offset_count = 0,
335 int* entry_offsets = nullptr) NOT_CDS_RETURN_(false);
336
337 static CodeBlob* load_code_blob(AOTCodeEntry::Kind kind,
338 uint id, const char* name,
339 int entry_offset_count = 0,
340 int* entry_offsets = nullptr) NOT_CDS_RETURN_(nullptr);
341
342 static uint store_entries_cnt() {
343 if (is_on_for_dump()) {
344 return cache()->_store_entries_cnt;
345 }
346 return -1;
347 }
348
349 // Static access
350
351 private:
352 static AOTCodeCache* _cache;
353
354 static bool open_cache(bool is_dumping, bool is_using);
355 static bool verify_vm_config() {
356 if (is_on_for_use()) {
357 return _cache->_load_header->verify_vm_config();
358 }
359 return true;
360 }
361 public:
362 static AOTCodeCache* cache() { return _cache; }
363 static void initialize() NOT_CDS_RETURN;
364 static void init2() NOT_CDS_RETURN;
365 static void close() NOT_CDS_RETURN;
366 static bool is_on() CDS_ONLY({ return _cache != nullptr && !_cache->closing(); }) NOT_CDS_RETURN_(false);
367 static bool is_on_for_use() { return is_on() && _cache->for_use(); }
368 static bool is_on_for_dump() { return is_on() && _cache->for_dump(); }
369
370 static bool is_dumping_adapter() NOT_CDS_RETURN_(false);
371 static bool is_using_adapter() NOT_CDS_RETURN_(false);
372
373 static bool is_dumping_stub() NOT_CDS_RETURN_(false);
374 static bool is_using_stub() NOT_CDS_RETURN_(false);
375
376 static const char* add_C_string(const char* str) NOT_CDS_RETURN_(str);
377
378 static void print_on(outputStream* st) NOT_CDS_RETURN;
379 };
380
381 // Concurent AOT code reader
382 class AOTCodeReader {
383 private:
384 const AOTCodeCache* _cache;
385 const AOTCodeEntry* _entry;
386 const char* _load_buffer; // Loaded cached code buffer
387 uint _read_position; // Position in _load_buffer
388 uint read_position() const { return _read_position; }
389 void set_read_position(uint pos);
390 const char* addr(uint offset) const { return _load_buffer + offset; }
391
392 bool _lookup_failed; // Failed to lookup for info (skip only this code load)
393 void set_lookup_failed() { _lookup_failed = true; }
394 void clear_lookup_failed() { _lookup_failed = false; }
395 bool lookup_failed() const { return _lookup_failed; }
396
397 AOTCodeEntry* aot_code_entry() { return (AOTCodeEntry*)_entry; }
398 public:
399 AOTCodeReader(AOTCodeCache* cache, AOTCodeEntry* entry);
400
401 CodeBlob* compile_code_blob(const char* name, int entry_offset_count, int* entry_offsets);
402
403 ImmutableOopMapSet* read_oop_map_set();
404
405 void fix_relocations(CodeBlob* code_blob);
406 #ifndef PRODUCT
407 void read_asm_remarks(AsmRemarks& asm_remarks);
408 void read_dbg_strings(DbgStrings& dbg_strings);
409 #endif // PRODUCT
410 };
411
412 #endif // SHARE_CODE_AOTCODECACHE_HPP
|
1 /*
2 * Copyright (c) 2023, 2025, 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
25 #ifndef SHARE_CODE_AOTCODECACHE_HPP
26 #define SHARE_CODE_AOTCODECACHE_HPP
27
28 #include "compiler/compilerDefinitions.hpp"
29 #include "memory/allocation.hpp"
30 #include "nmt/memTag.hpp"
31 #include "oops/oopsHierarchy.hpp"
32 #include "runtime/vm_version.hpp"
33 #include "utilities/sizes.hpp"
34 #include "utilities/exceptions.hpp"
35 /*
36 * AOT Code Cache collects code from Code Cache and corresponding metadata
37 * during application training run.
38 * In following "production" runs this code and data can be loaded into
39 * Code Cache skipping its generation.
40 * Additionaly special compiled code "preload" is generated with class initialization
41 * barriers which can be called on first Java method invocation.
42 */
43
44 class AbstractCompiler;
45 class AOTCodeCache;
46 class AsmRemarks;
47 class ciConstant;
48 class ciEnv;
49 class ciMethod;
50 class CodeBlob;
51 class CodeOffsets;
52 class CompileTask;
53 class DbgStrings;
54 class DebugInformationRecorder;
55 class Dependencies;
56 class ExceptionTable;
57 class ExceptionHandlerTable;
58 template<typename E>
59 class GrowableArray;
60 class ImmutableOopMapSet;
61 class ImplicitExceptionTable;
62 class JavaThread;
63 class Klass;
64 class methodHandle;
65 class Metadata;
66 class Method;
67 class nmethod;
68 class OopMapSet;
69 class OopRecorder;
70 class outputStream;
71 class RelocIterator;
72 class StubCodeGenerator;
73
74 enum class vmIntrinsicID : int;
75
76 #define DO_AOTCODEENTRY_KIND(Fn) \
77 Fn(None) \
78 Fn(Adapter) \
79 Fn(Stub) \
80 Fn(SharedBlob) \
81 Fn(C1Blob) \
82 Fn(C2Blob) \
83 Fn(Code) \
84
85 // Descriptor of AOT Code Cache's entry
86 class AOTCodeEntry {
87 public:
88 enum Kind : s1 {
89 #define DECL_KIND_ENUM(kind) kind,
90 DO_AOTCODEENTRY_KIND(DECL_KIND_ENUM)
91 #undef DECL_KIND_ENUM
92 Kind_count
93 };
94
95 private:
96 Method* _method;
97 Kind _kind;
98 uint _id; // Adapter's id, vmIntrinsic::ID for stub or name's hash for nmethod
99 uint _offset; // Offset to entry
100 uint _size; // Entry size
101 uint _name_offset; // Method's or intrinsic name
102 uint _name_size;
103 uint _num_inlined_bytecodes;
104
105 uint _code_offset; // Start of code in cache
106 uint _code_size; // Total size of all code sections
107
108 uint _comp_level; // compilation level
109 uint _comp_id; // compilation id
110 bool _has_oop_maps;
111 bool _has_clinit_barriers; // Generated code has class init checks
112 bool _for_preload; // Code can be used for preload
113 bool _loaded; // Code was loaded
114 bool _not_entrant; // Deoptimized
115 bool _load_fail; // Failed to load due to some klass state
116 address _dumptime_content_start_addr; // CodeBlob::content_begin() at dump time; used for applying relocations
117
118 public:
119 // this constructor is used only by AOTCodeEntry::Stub
120 AOTCodeEntry(uint offset, uint size, uint name_offset, uint name_size,
121 uint code_offset, uint code_size,
122 Kind kind, uint id) {
123 assert(kind == AOTCodeEntry::Stub, "sanity check");
124 _method = nullptr;
125 _kind = kind;
126 _id = id;
127 _offset = offset;
128 _size = size;
129 _name_offset = name_offset;
130 _name_size = name_size;
131 _code_offset = code_offset;
132 _code_size = code_size;
133
134 _dumptime_content_start_addr = nullptr;
135 _num_inlined_bytecodes = 0;
136 _comp_level = 0;
137 _comp_id = 0;
138 _has_oop_maps = false; // unused here
139 _has_clinit_barriers = false;
140 _for_preload = false;
141 _loaded = false;
142 _not_entrant = false;
143 _load_fail = false;
144 }
145
146 AOTCodeEntry(Kind kind, uint id,
147 uint offset, uint size,
148 uint name_offset, uint name_size,
149 uint blob_offset, bool has_oop_maps,
150 address dumptime_content_start_addr,
151 uint comp_level = 0,
152 uint comp_id = 0,
153 bool has_clinit_barriers = false,
154 bool for_preload = false) {
155 _method = nullptr;
156 _kind = kind;
157 _id = id;
158 _offset = offset;
159 _size = size;
160 _name_offset = name_offset;
161 _name_size = name_size;
162 _code_offset = blob_offset;
163 _code_size = 0; // unused
164
165 _dumptime_content_start_addr = dumptime_content_start_addr;
166 _num_inlined_bytecodes = 0;
167
168 _comp_level = comp_level;
169 _comp_id = comp_id;
170 _has_oop_maps = has_oop_maps;
171 _has_clinit_barriers = has_clinit_barriers;
172 _for_preload = for_preload;
173 _loaded = false;
174 _not_entrant = false;
175 _load_fail = false;
176
177 _loaded = false;
178 _not_entrant = false;
179 _load_fail = false;
180 }
181
182 void* operator new(size_t x, AOTCodeCache* cache);
183 // Delete is a NOP
184 void operator delete( void *ptr ) {}
185
186 Method* method() const { return _method; }
187 Method** method_addr() { return &_method; }
188 void set_method(Method* method) { _method = method; }
189
190 Kind kind() const { return _kind; }
191 uint id() const { return _id; }
192
193 uint offset() const { return _offset; }
194 void set_offset(uint off) { _offset = off; }
195
196 uint size() const { return _size; }
197 uint name_offset() const { return _name_offset; }
198 uint name_size() const { return _name_size; }
199 uint code_offset() const { return _code_offset; }
200 uint code_size() const { return _code_size; }
201
202 bool has_oop_maps() const { return _has_oop_maps; }
203 address dumptime_content_start_addr() const { return _dumptime_content_start_addr; }
204 uint num_inlined_bytecodes() const { return _num_inlined_bytecodes; }
205 void set_inlined_bytecodes(int bytes) { _num_inlined_bytecodes = bytes; }
206
207 uint comp_level() const { return _comp_level; }
208 uint comp_id() const { return _comp_id; }
209
210 bool has_clinit_barriers() const { return _has_clinit_barriers; }
211 bool for_preload() const { return _for_preload; }
212 bool is_loaded() const { return _loaded; }
213 void set_loaded() { _loaded = true; }
214
215 bool not_entrant() const { return _not_entrant; }
216 void set_not_entrant() { _not_entrant = true; }
217 void set_entrant() { _not_entrant = false; }
218
219 bool load_fail() const { return _load_fail; }
220 void set_load_fail() { _load_fail = true; }
221
222 void print(outputStream* st) const;
223
224 static bool is_valid_entry_kind(Kind kind) { return kind > None && kind < Kind_count; }
225 static bool is_blob(Kind kind) { return kind == SharedBlob || kind == C1Blob || kind == C2Blob; }
226 static bool is_adapter(Kind kind) { return kind == Adapter; }
227 bool is_code() { return _kind == Code; }
228 };
229
230 // Addresses of stubs, blobs and runtime finctions called from compiled code.
231 class AOTCodeAddressTable : public CHeapObj<mtCode> {
232 private:
233 address* _extrs_addr;
234 address* _stubs_addr;
235 address* _shared_blobs_addr;
236 address* _C1_blobs_addr;
237 address* _C2_blobs_addr;
238 uint _extrs_length;
239 uint _stubs_length;
240 uint _shared_blobs_length;
241 uint _C1_blobs_length;
242 uint _C2_blobs_length;
243
244 bool _extrs_complete;
245 bool _early_stubs_complete;
246 bool _shared_blobs_complete;
247 bool _early_c1_complete;
248 bool _c1_complete;
249 bool _c2_complete;
250 bool _complete;
251
252 public:
253 AOTCodeAddressTable() :
254 _extrs_addr(nullptr),
255 _stubs_addr(nullptr),
256 _shared_blobs_addr(nullptr),
257 _C1_blobs_addr(nullptr),
258 _C2_blobs_addr(nullptr),
259 _extrs_length(0),
260 _stubs_length(0),
261 _shared_blobs_length(0),
262 _C1_blobs_length(0),
263 _C2_blobs_length(0),
264 _extrs_complete(false),
265 _early_stubs_complete(false),
266 _shared_blobs_complete(false),
267 _early_c1_complete(false),
268 _c1_complete(false),
269 _c2_complete(false),
270 _complete(false)
271 { }
272 ~AOTCodeAddressTable();
273 void init_extrs();
274 void init_early_stubs();
275 void init_shared_blobs();
276 void init_stubs();
277 void init_early_c1();
278 void init_c1();
279 void init_c2();
280 const char* add_C_string(const char* str);
281 int id_for_C_string(address str);
282 address address_for_C_string(int idx);
283 int id_for_address(address addr, RelocIterator iter, CodeBlob* blob);
284 address address_for_id(int id);
285 bool c2_complete() const { return _c2_complete; }
286 bool c1_complete() const { return _c1_complete; }
287 };
288
289 struct AOTCodeSection {
290 public:
291 address _origin_address;
292 uint _size;
293 uint _offset;
294 };
295
296 enum class DataKind: int {
297 No_Data = -1,
298 Null = 0,
299 Klass = 1,
300 Method = 2,
301 String = 3,
302 MH_Oop = 4,
303 Primitive = 5, // primitive Class object
304 SysLoader = 6, // java_system_loader
305 PlaLoader = 7, // java_platform_loader
306 MethodCnts= 8
307 };
308
309 class AOTCodeCache : public CHeapObj<mtCode> {
310
311 // Classes used to describe AOT code cache.
312 protected:
313 class Config {
314 size_t _codeCacheSize;
315 address _compressedOopBase;
316 address _compressedKlassBase;
317 uint _compressedOopShift;
318 uint _compressedKlassShift;
319 uint _contendedPaddingWidth;
320 uint _objectAlignment;
321 uint _gc;
322 enum Flags {
323 none = 0,
324 debugVM = 2,
325 compressedOops = 4,
326 compressedClassPointers = 8,
327 useTLAB = 16,
328 systemClassAssertions = 32,
329 userClassAssertions = 64,
330 enableContendedPadding = 128,
331 restrictContendedPadding = 256,
332 preserveFramePointer = 512
333 };
334 uint _flags;
335 uint _cpu_features_offset; // offset in the cache where cpu features are stored
336
337 public:
338 void record(uint cpu_features_offset);
339 bool verify(AOTCodeCache* cache) const;
340 };
341
342 class Header : public CHeapObj<mtCode> {
343 private:
344 // Here should be version and other verification fields
345 enum {
346 AOT_CODE_VERSION = 1
347 };
348 uint _version; // AOT code version (should match when reading code cache)
349 uint _cache_size; // cache size in bytes
350 uint _strings_count; // number of recorded C strings
351 uint _strings_offset; // offset to recorded C strings
352 uint _entries_count; // number of recorded entries
353 uint _search_table_offset; // offset of table for looking up an AOTCodeEntry
354 uint _entries_offset; // offset of AOTCodeEntry array describing entries
355 uint _preload_entries_count; // entries for pre-loading code
356 uint _preload_entries_offset;
357 uint _adapters_count;
358 uint _shared_blobs_count;
359 uint _C1_blobs_count;
360 uint _C2_blobs_count;
361 uint _stubs_count;
362 Config _config; // must be the last element as there is trailing data stored immediately after Config
363
364 public:
365 void init(uint cache_size,
366 uint strings_count, uint strings_offset,
367 uint entries_count, uint search_table_offset, uint entries_offset,
368 uint preload_entries_count, uint preload_entries_offset,
369 uint adapters_count, uint shared_blobs_count,
370 uint C1_blobs_count, uint C2_blobs_count,
371 uint stubs_count, uint cpu_features_offset) {
372 _version = AOT_CODE_VERSION;
373 _cache_size = cache_size;
374 _strings_count = strings_count;
375 _strings_offset = strings_offset;
376 _entries_count = entries_count;
377 _search_table_offset = search_table_offset;
378 _entries_offset = entries_offset;
379 _preload_entries_count = preload_entries_count;
380 _preload_entries_offset = preload_entries_offset;
381 _adapters_count = adapters_count;
382 _shared_blobs_count = shared_blobs_count;
383 _C1_blobs_count = C1_blobs_count;
384 _C2_blobs_count = C2_blobs_count;
385 _stubs_count = stubs_count;
386
387 _config.record(cpu_features_offset);
388 }
389
390 uint cache_size() const { return _cache_size; }
391 uint strings_count() const { return _strings_count; }
392 uint strings_offset() const { return _strings_offset; }
393 uint entries_count() const { return _entries_count; }
394 uint search_table_offset() const { return _search_table_offset; }
395 uint entries_offset() const { return _entries_offset; }
396 uint preload_entries_count() const { return _preload_entries_count; }
397 uint preload_entries_offset() const { return _preload_entries_offset; }
398 uint adapters_count() const { return _adapters_count; }
399 uint shared_blobs_count() const { return _shared_blobs_count; }
400 uint C1_blobs_count() const { return _C1_blobs_count; }
401 uint C2_blobs_count() const { return _C2_blobs_count; }
402 uint stubs_count() const { return _stubs_count; }
403 uint nmethods_count() const { return _entries_count
404 - _stubs_count
405 - _shared_blobs_count
406 - _C1_blobs_count
407 - _C2_blobs_count
408 - _adapters_count; }
409
410 bool verify(uint load_size) const;
411 bool verify_config(AOTCodeCache* cache) const { // Called after Universe initialized
412 return _config.verify(cache);
413 }
414 };
415
416 // Continue with AOTCodeCache class definition.
417 private:
418 Header* _load_header;
419 char* _load_buffer; // Aligned buffer for loading AOT code
420 char* _store_buffer; // Aligned buffer for storing AOT code
421 char* _C_store_buffer; // Original unaligned buffer
422
423 uint _write_position; // Position in _store_buffer
424 uint _load_size; // Used when reading cache
425 uint _store_size; // Used when writing cache
426 bool _for_use; // AOT cache is open for using AOT code
427 bool _for_dump; // AOT cache is open for dumping AOT code
428 bool _closing; // Closing cache file
429 bool _failed; // Failed read/write to/from cache (cache is broken?)
430 bool _lookup_failed; // Failed to lookup for info (skip only this code load)
431
432 bool _for_preload; // Code for preload
433 bool _has_clinit_barriers; // Code with clinit barriers
434
435 AOTCodeAddressTable* _table;
436
437 AOTCodeEntry* _load_entries; // Used when reading cache
438 uint* _search_entries; // sorted by ID table [id, index]
439 AOTCodeEntry* _store_entries; // Used when writing cache
440 const char* _C_strings_buf; // Loaded buffer for _C_strings[] table
441 uint _store_entries_cnt;
442
443 uint _compile_id;
444 uint _comp_level;
445 uint compile_id() const { return _compile_id; }
446 uint comp_level() const { return _comp_level; }
447
448 static AOTCodeCache* open_for_use();
449 static AOTCodeCache* open_for_dump();
450
451 bool set_write_position(uint pos);
452 bool align_write();
453
454 address reserve_bytes(uint nbytes);
455 uint write_bytes(const void* buffer, uint nbytes);
456 const char* addr(uint offset) const { return _load_buffer + offset; }
457 static AOTCodeAddressTable* addr_table() {
458 return is_on() && (cache()->_table != nullptr) ? cache()->_table : nullptr;
459 }
460
461 void set_lookup_failed() { _lookup_failed = true; }
462 void clear_lookup_failed() { _lookup_failed = false; }
463 bool lookup_failed() const { return _lookup_failed; }
464
465 AOTCodeEntry* write_nmethod(nmethod* nm, bool for_preload);
466
467 // States:
468 // S >= 0: allow new readers, S readers are currently active
469 // S < 0: no new readers are allowed; (-S-1) readers are currently active
470 // (special case: S = -1 means no readers are active, and would never be active again)
471 static volatile int _nmethod_readers;
472
473 static void wait_for_no_nmethod_readers();
474
475 class ReadingMark {
476 private:
477 bool _failed;
478 public:
479 ReadingMark();
480 ~ReadingMark();
481 bool failed() {
482 return _failed;
483 }
484 };
485
486 public:
487 AOTCodeCache(bool is_dumping, bool is_using);
488 ~AOTCodeCache();
489
490 const char* cache_buffer() const { return _load_buffer; }
491 bool failed() const { return _failed; }
492 void set_failed() { _failed = true; }
493
494 static bool is_address_in_aot_cache(address p) NOT_CDS_RETURN_(false);
495 static uint max_aot_code_size();
496
497 uint load_size() const { return _load_size; }
498 uint write_position() const { return _write_position; }
499
500 void load_strings();
501 int store_strings();
502
503 static void init_early_stubs_table() NOT_CDS_RETURN;
504 static void init_shared_blobs_table() NOT_CDS_RETURN;
505 static void init_stubs_table() NOT_CDS_RETURN;
506 static void init_early_c1_table() NOT_CDS_RETURN;
507 static void init_c1_table() NOT_CDS_RETURN;
508 static void init_c2_table() NOT_CDS_RETURN;
509
510 address address_for_C_string(int idx) const { return _table->address_for_C_string(idx); }
511 address address_for_id(int id) const { return _table->address_for_id(id); }
512
513 bool for_use() const { return _for_use && !_failed; }
514 bool for_dump() const { return _for_dump && !_failed; }
515
516 bool closing() const { return _closing; }
517
518 AOTCodeEntry* add_entry() {
519 _store_entries_cnt++;
520 _store_entries -= 1;
521 return _store_entries;
522 }
523 void preload_aot_code(TRAPS);
524
525 AOTCodeEntry* find_entry(AOTCodeEntry::Kind kind, uint id, uint comp_level = 0);
526 void invalidate_entry(AOTCodeEntry* entry);
527
528 void mark_method_pointer(AOTCodeEntry* entries, int count);
529 void store_cpu_features(char*& buffer, uint buffer_size);
530
531 bool finish_write();
532
533 void log_stats_on_exit();
534
535 static bool load_stub(StubCodeGenerator* cgen, vmIntrinsicID id, const char* name, address start) NOT_CDS_RETURN_(false);
536 static bool store_stub(StubCodeGenerator* cgen, vmIntrinsicID id, const char* name, address start) NOT_CDS_RETURN_(false);
537
538 bool write_klass(Klass* klass);
539 bool write_method(Method* method);
540
541 bool write_relocations(CodeBlob& code_blob, GrowableArray<Handle>* oop_list = nullptr, GrowableArray<Metadata*>* metadata_list = nullptr);
542
543 bool write_oop_map_set(CodeBlob& cb);
544 bool write_nmethod_reloc_immediates(GrowableArray<Handle>& oop_list, GrowableArray<Metadata*>& metadata_list);
545
546 jobject read_oop(JavaThread* thread, const methodHandle& comp_method);
547 Metadata* read_metadata(const methodHandle& comp_method);
548
549 bool write_oop(jobject& jo);
550 bool write_oop(oop obj);
551 bool write_metadata(Metadata* m);
552 bool write_oops(nmethod* nm);
553 bool write_metadata(nmethod* nm);
554
555 #ifndef PRODUCT
556 bool write_asm_remarks(AsmRemarks& asm_remarks, bool use_string_table);
557 bool write_dbg_strings(DbgStrings& dbg_strings, bool use_string_table);
558 #endif // PRODUCT
559
560 static bool store_code_blob(CodeBlob& blob,
561 AOTCodeEntry::Kind entry_kind,
562 uint id, const char* name,
563 int entry_offset_count = 0,
564 int* entry_offsets = nullptr) NOT_CDS_RETURN_(false);
565
566 static CodeBlob* load_code_blob(AOTCodeEntry::Kind kind,
567 uint id, const char* name,
568 int entry_offset_count = 0,
569 int* entry_offsets = nullptr) NOT_CDS_RETURN_(nullptr);
570
571 static bool load_nmethod(ciEnv* env, ciMethod* target, int entry_bci, AbstractCompiler* compiler, CompLevel comp_level) NOT_CDS_RETURN_(false);
572 static AOTCodeEntry* store_nmethod(nmethod* nm, AbstractCompiler* compiler, bool for_preload) NOT_CDS_RETURN_(nullptr);
573
574 static uint store_entries_cnt() {
575 if (is_on_for_dump()) {
576 return cache()->_store_entries_cnt;
577 }
578 return -1;
579 }
580
581 // Static access
582
583 private:
584 static AOTCodeCache* _cache;
585 DEBUG_ONLY( static bool _passed_init2; )
586
587 static bool open_cache(bool is_dumping, bool is_using);
588
589 bool verify_config_on_use() {
590 if (for_use()) {
591 return _load_header->verify_config(this);
592 }
593 return true;
594 }
595 public:
596 static AOTCodeCache* cache() { assert(_passed_init2, "Too early to ask"); return _cache; }
597 static void initialize() NOT_CDS_RETURN;
598 static void init2() NOT_CDS_RETURN;
599 static void close() NOT_CDS_RETURN;
600 static bool is_on() CDS_ONLY({ return cache() != nullptr && !_cache->closing(); }) NOT_CDS_RETURN_(false);
601 static bool is_code_load_thread_on() NOT_CDS_RETURN_(false);
602 static bool is_on_for_use() CDS_ONLY({ return is_on() && _cache->for_use(); }) NOT_CDS_RETURN_(false);
603 static bool is_on_for_dump() CDS_ONLY({ return is_on() && _cache->for_dump(); }) NOT_CDS_RETURN_(false);
604 static bool is_dumping_code() NOT_CDS_RETURN_(false);
605 static bool is_dumping_stub() NOT_CDS_RETURN_(false);
606 static bool is_dumping_adapter() NOT_CDS_RETURN_(false);
607 static bool is_using_code() NOT_CDS_RETURN_(false);
608 static bool is_using_stub() NOT_CDS_RETURN_(false);
609 static bool is_using_adapter() NOT_CDS_RETURN_(false);
610 static void enable_caching() NOT_CDS_RETURN;
611 static void disable_caching() NOT_CDS_RETURN;
612 static bool is_caching_enabled() NOT_CDS_RETURN_(false);
613
614 // It is used before AOTCodeCache is initialized.
615 static bool maybe_dumping_code() NOT_CDS_RETURN_(false);
616
617 static bool allow_const_field(ciConstant& value) NOT_CDS_RETURN_(false);
618 static void invalidate(AOTCodeEntry* entry) NOT_CDS_RETURN;
619 static AOTCodeEntry* find_code_entry(const methodHandle& method, uint comp_level);
620 static void preload_code(JavaThread* thread) NOT_CDS_RETURN;
621
622 template<typename Function>
623 static void iterate(Function function) { // lambda enabled API
624 AOTCodeCache* cache = open_for_use();
625 if (cache != nullptr) {
626 ReadingMark rdmk;
627 if (rdmk.failed()) {
628 // Cache is closed, cannot touch anything.
629 return;
630 }
631
632 uint count = cache->_load_header->entries_count();
633 uint* search_entries = (uint*)cache->addr(cache->_load_header->entries_offset()); // [id, index]
634 AOTCodeEntry* load_entries = (AOTCodeEntry*)(search_entries + 2 * count);
635
636 for (uint i = 0; i < count; i++) {
637 int index = search_entries[2*i + 1];
638 AOTCodeEntry* entry = &(load_entries[index]);
639 function(entry);
640 }
641 }
642 }
643
644 static const char* add_C_string(const char* str) NOT_CDS_RETURN_(str);
645
646 static void print_on(outputStream* st) NOT_CDS_RETURN;
647 static void print_statistics_on(outputStream* st) NOT_CDS_RETURN;
648 static void print_timers_on(outputStream* st) NOT_CDS_RETURN;
649 static void print_unused_entries_on(outputStream* st) NOT_CDS_RETURN;
650 };
651
652 // Concurent AOT code reader
653 class AOTCodeReader {
654 private:
655 const AOTCodeCache* _cache;
656 const AOTCodeEntry* _entry;
657 const char* _load_buffer; // Loaded AOT code buffer
658 uint _read_position; // Position in _load_buffer
659 uint read_position() const { return _read_position; }
660 void set_read_position(uint pos);
661 const char* addr(uint offset) const { return _load_buffer + offset; }
662
663 uint _compile_id;
664 uint _comp_level;
665 uint compile_id() const { return _compile_id; }
666 uint comp_level() const { return _comp_level; }
667
668 bool _preload; // Preloading code before method execution
669 bool _lookup_failed; // Failed to lookup for info (skip only this code load)
670 void set_lookup_failed() { _lookup_failed = true; }
671 void clear_lookup_failed() { _lookup_failed = false; }
672 bool lookup_failed() const { return _lookup_failed; }
673
674 public:
675 AOTCodeReader(AOTCodeCache* cache, AOTCodeEntry* entry, CompileTask* task);
676
677 AOTCodeEntry* aot_code_entry() { return (AOTCodeEntry*)_entry; }
678
679 // convenience method to convert offset in AOTCodeEntry data to its address
680 bool compile_nmethod(ciEnv* env, ciMethod* target, AbstractCompiler* compiler);
681
682 CodeBlob* compile_code_blob(const char* name, int entry_offset_count, int* entry_offsets);
683
684 Klass* read_klass(const methodHandle& comp_method);
685 Method* read_method(const methodHandle& comp_method);
686
687 oop read_oop(JavaThread* thread, const methodHandle& comp_method);
688 Metadata* read_metadata(const methodHandle& comp_method);
689 bool read_oops(OopRecorder* oop_recorder, ciMethod* target);
690 bool read_metadata(OopRecorder* oop_recorder, ciMethod* target);
691
692 bool read_oop_metadata_list(JavaThread* thread, ciMethod* target, GrowableArray<Handle> &oop_list, GrowableArray<Metadata*> &metadata_list, OopRecorder* oop_recorder);
693 void apply_relocations(nmethod* nm, GrowableArray<Handle> &oop_list, GrowableArray<Metadata*> &metadata_list) NOT_CDS_RETURN;
694
695 ImmutableOopMapSet* read_oop_map_set();
696
697 void fix_relocations(CodeBlob* code_blob, GrowableArray<Handle>* oop_list = nullptr, GrowableArray<Metadata*>* metadata_list = nullptr) NOT_CDS_RETURN;
698 #ifndef PRODUCT
699 void read_asm_remarks(AsmRemarks& asm_remarks, bool use_string_table) NOT_CDS_RETURN;
700 void read_dbg_strings(DbgStrings& dbg_strings, bool use_string_table) NOT_CDS_RETURN;
701 #endif // PRODUCT
702
703 void print_on(outputStream* st);
704 };
705
706 // +1 for preload code
707 const int AOTCompLevel_count = CompLevel_count + 1; // 6 levels indexed from 0 to 5
708
709 struct AOTCodeStats {
710 private:
711 struct {
712 uint _kind_cnt[AOTCodeEntry::Kind_count];
713 uint _nmethod_cnt[AOTCompLevel_count];
714 uint _clinit_barriers_cnt;
715 } ccstats; // AOT code stats
716
717 void check_kind(uint kind) { assert(kind >= AOTCodeEntry::None && kind < AOTCodeEntry::Kind_count, "Invalid AOTCodeEntry kind %d", kind); }
718 void check_complevel(uint lvl) { assert(lvl >= CompLevel_none && lvl < AOTCompLevel_count, "Invalid compilation level %d", lvl); }
719
720 public:
721 void inc_entry_cnt(uint kind) { check_kind(kind); ccstats._kind_cnt[kind] += 1; }
722 void inc_nmethod_cnt(uint lvl) { check_complevel(lvl); ccstats._nmethod_cnt[lvl] += 1; }
723 void inc_preload_cnt() { ccstats._nmethod_cnt[AOTCompLevel_count-1] += 1; }
724 void inc_clinit_barriers_cnt() { ccstats._clinit_barriers_cnt += 1; }
725
726 void collect_entry_stats(AOTCodeEntry* entry) {
727 inc_entry_cnt(entry->kind());
728 if (entry->is_code()) {
729 entry->for_preload() ? inc_nmethod_cnt(AOTCompLevel_count-1)
730 : inc_nmethod_cnt(entry->comp_level());
731 if (entry->has_clinit_barriers()) {
732 inc_clinit_barriers_cnt();
733 }
734 }
735 }
736
737 uint entry_count(uint kind) { check_kind(kind); return ccstats._kind_cnt[kind]; }
738 uint nmethod_count(uint lvl) { check_complevel(lvl); return ccstats._nmethod_cnt[lvl]; }
739 uint preload_count() { return ccstats._nmethod_cnt[AOTCompLevel_count-1]; }
740 uint clinit_barriers_count() { return ccstats._clinit_barriers_cnt; }
741
742 uint total_count() {
743 uint total = 0;
744 for (int kind = AOTCodeEntry::None; kind < AOTCodeEntry::Kind_count; kind++) {
745 total += ccstats._kind_cnt[kind];
746 }
747 return total;
748 }
749
750 static AOTCodeStats add_aot_code_stats(AOTCodeStats stats1, AOTCodeStats stats2);
751
752 // Runtime stats of the AOT code
753 private:
754 struct {
755 struct {
756 uint _loaded_cnt;
757 uint _invalidated_cnt;
758 uint _load_failed_cnt;
759 } _entry_kinds[AOTCodeEntry::Kind_count],
760 _nmethods[AOTCompLevel_count];
761 } rs; // rs = runtime stats
762
763 public:
764 void inc_entry_loaded_cnt(uint kind) { check_kind(kind); rs._entry_kinds[kind]._loaded_cnt += 1; }
765 void inc_entry_invalidated_cnt(uint kind) { check_kind(kind); rs._entry_kinds[kind]._invalidated_cnt += 1; }
766 void inc_entry_load_failed_cnt(uint kind) { check_kind(kind); rs._entry_kinds[kind]._load_failed_cnt += 1; }
767
768 void inc_nmethod_loaded_cnt(uint lvl) { check_complevel(lvl); rs._nmethods[lvl]._loaded_cnt += 1; }
769 void inc_nmethod_invalidated_cnt(uint lvl) { check_complevel(lvl); rs._nmethods[lvl]._invalidated_cnt += 1; }
770 void inc_nmethod_load_failed_cnt(uint lvl) { check_complevel(lvl); rs._nmethods[lvl]._load_failed_cnt += 1; }
771
772 uint entry_loaded_count(uint kind) { check_kind(kind); return rs._entry_kinds[kind]._loaded_cnt; }
773 uint entry_invalidated_count(uint kind) { check_kind(kind); return rs._entry_kinds[kind]._invalidated_cnt; }
774 uint entry_load_failed_count(uint kind) { check_kind(kind); return rs._entry_kinds[kind]._load_failed_cnt; }
775
776 uint nmethod_loaded_count(uint lvl) { check_complevel(lvl); return rs._nmethods[lvl]._loaded_cnt; }
777 uint nmethod_invalidated_count(uint lvl) { check_complevel(lvl); return rs._nmethods[lvl]._invalidated_cnt; }
778 uint nmethod_load_failed_count(uint lvl) { check_complevel(lvl); return rs._nmethods[lvl]._load_failed_cnt; }
779
780 void inc_loaded_cnt(AOTCodeEntry* entry) {
781 inc_entry_loaded_cnt(entry->kind());
782 if (entry->is_code()) {
783 entry->for_preload() ? inc_nmethod_loaded_cnt(AOTCompLevel_count-1)
784 : inc_nmethod_loaded_cnt(entry->comp_level());
785 }
786 }
787
788 void inc_invalidated_cnt(AOTCodeEntry* entry) {
789 inc_entry_invalidated_cnt(entry->kind());
790 if (entry->is_code()) {
791 entry->for_preload() ? inc_nmethod_invalidated_cnt(AOTCompLevel_count-1)
792 : inc_nmethod_invalidated_cnt(entry->comp_level());
793 }
794 }
795
796 void inc_load_failed_cnt(AOTCodeEntry* entry) {
797 inc_entry_load_failed_cnt(entry->kind());
798 if (entry->is_code()) {
799 entry->for_preload() ? inc_nmethod_load_failed_cnt(AOTCompLevel_count-1)
800 : inc_nmethod_load_failed_cnt(entry->comp_level());
801 }
802 }
803
804 void collect_entry_runtime_stats(AOTCodeEntry* entry) {
805 if (entry->is_loaded()) {
806 inc_loaded_cnt(entry);
807 }
808 if (entry->not_entrant()) {
809 inc_invalidated_cnt(entry);
810 }
811 if (entry->load_fail()) {
812 inc_load_failed_cnt(entry);
813 }
814 }
815
816 void collect_all_stats(AOTCodeEntry* entry) {
817 collect_entry_stats(entry);
818 collect_entry_runtime_stats(entry);
819 }
820
821 AOTCodeStats() {
822 memset(this, 0, sizeof(AOTCodeStats));
823 }
824 };
825
826 // code cache internal runtime constants area used by AOT code
827 class AOTRuntimeConstants {
828 friend class AOTCodeCache;
829 private:
830 uint _grain_shift;
831 uint _card_shift;
832 static address _field_addresses_list[];
833 static AOTRuntimeConstants _aot_runtime_constants;
834 // private constructor for unique singleton
835 AOTRuntimeConstants() { }
836 // private for use by friend class AOTCodeCache
837 static void initialize_from_runtime();
838 public:
839 #if INCLUDE_CDS
840 static bool contains(address adr) {
841 address base = (address)&_aot_runtime_constants;
842 address hi = base + sizeof(AOTRuntimeConstants);
843 return (base <= adr && adr < hi);
844 }
845 static address grain_shift_address() { return (address)&_aot_runtime_constants._grain_shift; }
846 static address card_shift_address() { return (address)&_aot_runtime_constants._card_shift; }
847 static address* field_addresses_list() {
848 return _field_addresses_list;
849 }
850 #else
851 static bool contains(address adr) { return false; }
852 static address grain_shift_address() { return nullptr; }
853 static address card_shift_address() { return nullptr; }
854 static address* field_addresses_list() { return nullptr; }
855 #endif
856 };
857
858 #endif // SHARE_CODE_AOTCODECACHE_HPP
|