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_CODEBLOB_HPP
26 #define SHARE_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "compiler/oopMap.hpp"
31 #include "runtime/javaFrameAnchor.hpp"
32 #include "runtime/frame.hpp"
33 #include "runtime/handles.hpp"
34 #include "utilities/align.hpp"
35 #include "utilities/macros.hpp"
36
37 class ImmutableOopMap;
38 class ImmutableOopMapSet;
39 class JNIHandleBlock;
40 class OopMapSet;
41
42 // CodeBlob Types
43 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
44 enum class CodeBlobType {
45 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
46 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
47 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
48 All = 3, // All types (No code cache segmentation)
158
159 static const Vptr* vptr(CodeBlobKind kind);
160 const Vptr* vptr() const;
161
162 CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
163 int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
164 int mutable_data_size);
165
166 // Simple CodeBlob used for simple BufferBlob.
167 CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
168
169
170 void operator delete(void* p) { }
171
172 void prepare_for_archiving_impl();
173 void post_restore_impl();
174
175 public:
176
177 ~CodeBlob() {
178 assert(_oop_maps == nullptr, "Not flushed");
179 }
180
181 // Returns the space needed for CodeBlob
182 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
183 static unsigned int align_code_offset(int offset);
184
185 // Deletion
186 void purge();
187
188 // Typing
189 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
190 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
191 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
192 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
193 #ifdef COMPILER2
194 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
195 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
196 #else
197 bool is_uncommon_trap_stub() const { return false; }
198 bool is_exception_stub() const { return false; }
230 int mutable_data_size() const { return _mutable_data_size; }
231 address mutable_data_begin() const { return _mutable_data; }
232 address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
233
234 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
235 relocInfo* relocation_end() const { return (relocInfo*)((address)relocation_begin() + _relocation_size); }
236
237 // Offsets
238 int content_offset() const { return _content_offset; }
239 int code_offset() const { return _code_offset; }
240
241 // This field holds the beginning of the const section in the old code buffer.
242 // It is needed to fix relocations of pc-relative loads when resizing the
243 // the constant pool or moving it.
244 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
245 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
246
247 // Sizes
248 int size() const { return _size; }
249 int header_size() const { return _header_size; }
250 int relocation_size() const { return pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); }
251 int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); }
252 int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); }
253
254 // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
255 void adjust_size(size_t used) {
256 _size = (int)used;
257 _data_offset = _size;
258 }
259
260 // Containment
261 bool blob_contains(address addr) const { return header_begin() <= addr && addr < blob_end(); }
262 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
263 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
264 bool is_frame_complete_at(address addr) const { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
265 code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
266 int frame_complete_offset() const { return _frame_complete_offset; }
267
268 // OopMap for frame
269 ImmutableOopMapSet* oop_maps() const { return _oop_maps; }
270 void set_oop_maps(OopMapSet* p);
301 DbgStrings &dbg_strings() { return _dbg_strings; }
302
303 void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); }
304 void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); }
305 #endif
306
307 void copy_to(address buffer) {
308 memcpy(buffer, this, this->size());
309 }
310
311 // methods to archive a blob into AOT code cache
312 void prepare_for_archiving();
313 static void archive_blob(CodeBlob* blob, address archive_buffer);
314
315 // methods to restore a blob from AOT code cache into the CodeCache
316 void post_restore();
317 CodeBlob* restore(address code_cache_buffer, const char* name, address archived_reloc_data, ImmutableOopMapSet* archived_oop_maps);
318 static CodeBlob* create(CodeBlob* archived_blob,
319 const char* name,
320 address archived_reloc_data,
321 ImmutableOopMapSet* archived_oop_maps
322 #ifndef PRODUCT
323 , AsmRemarks& archived_asm_remarks
324 , DbgStrings& archived_dbg_strings
325 #endif // PRODUCT
326 );
327 };
328
329 //----------------------------------------------------------------------------------------------------
330 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs)
331
332 class RuntimeBlob : public CodeBlob {
333 friend class VMStructs;
334 public:
335
336 // Creation
337 // a) simple CodeBlob
338 RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
339 : CodeBlob(name, kind, size, header_size)
340 {}
341
342 // b) full CodeBlob
343 // frame_complete is the offset from the beginning of the instructions
344 // to where the frame setup (from stackwalk viewpoint) is complete.
345 RuntimeBlob(
346 const char* name,
|
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_CODEBLOB_HPP
26 #define SHARE_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "code/aotCodeCache.hpp"
30 #include "compiler/compilerDefinitions.hpp"
31 #include "compiler/oopMap.hpp"
32 #include "runtime/javaFrameAnchor.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/handles.hpp"
35 #include "utilities/align.hpp"
36 #include "utilities/macros.hpp"
37
38 class ImmutableOopMap;
39 class ImmutableOopMapSet;
40 class JNIHandleBlock;
41 class OopMapSet;
42
43 // CodeBlob Types
44 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
45 enum class CodeBlobType {
46 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
47 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
48 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
49 All = 3, // All types (No code cache segmentation)
159
160 static const Vptr* vptr(CodeBlobKind kind);
161 const Vptr* vptr() const;
162
163 CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
164 int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
165 int mutable_data_size);
166
167 // Simple CodeBlob used for simple BufferBlob.
168 CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
169
170
171 void operator delete(void* p) { }
172
173 void prepare_for_archiving_impl();
174 void post_restore_impl();
175
176 public:
177
178 ~CodeBlob() {
179 assert(_oop_maps == nullptr || AOTCodeCache::is_address_in_aot_cache((address)_oop_maps), "Not flushed");
180 }
181
182 // Returns the space needed for CodeBlob
183 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
184 static unsigned int align_code_offset(int offset);
185
186 // Deletion
187 void purge();
188
189 // Typing
190 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
191 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
192 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
193 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
194 #ifdef COMPILER2
195 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
196 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
197 #else
198 bool is_uncommon_trap_stub() const { return false; }
199 bool is_exception_stub() const { return false; }
231 int mutable_data_size() const { return _mutable_data_size; }
232 address mutable_data_begin() const { return _mutable_data; }
233 address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
234
235 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
236 relocInfo* relocation_end() const { return (relocInfo*)((address)relocation_begin() + _relocation_size); }
237
238 // Offsets
239 int content_offset() const { return _content_offset; }
240 int code_offset() const { return _code_offset; }
241
242 // This field holds the beginning of the const section in the old code buffer.
243 // It is needed to fix relocations of pc-relative loads when resizing the
244 // the constant pool or moving it.
245 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
246 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
247
248 // Sizes
249 int size() const { return _size; }
250 int header_size() const { return _header_size; }
251 int relocation_size() const { return _relocation_size; }
252 int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); }
253 int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); }
254
255 // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
256 void adjust_size(size_t used) {
257 _size = (int)used;
258 _data_offset = _size;
259 }
260
261 // Containment
262 bool blob_contains(address addr) const { return header_begin() <= addr && addr < blob_end(); }
263 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
264 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
265 bool is_frame_complete_at(address addr) const { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
266 code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
267 int frame_complete_offset() const { return _frame_complete_offset; }
268
269 // OopMap for frame
270 ImmutableOopMapSet* oop_maps() const { return _oop_maps; }
271 void set_oop_maps(OopMapSet* p);
302 DbgStrings &dbg_strings() { return _dbg_strings; }
303
304 void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); }
305 void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); }
306 #endif
307
308 void copy_to(address buffer) {
309 memcpy(buffer, this, this->size());
310 }
311
312 // methods to archive a blob into AOT code cache
313 void prepare_for_archiving();
314 static void archive_blob(CodeBlob* blob, address archive_buffer);
315
316 // methods to restore a blob from AOT code cache into the CodeCache
317 void post_restore();
318 CodeBlob* restore(address code_cache_buffer, const char* name, address archived_reloc_data, ImmutableOopMapSet* archived_oop_maps);
319 static CodeBlob* create(CodeBlob* archived_blob,
320 const char* name,
321 address archived_reloc_data,
322 ImmutableOopMapSet* archived_oop_maps);
323 };
324
325 //----------------------------------------------------------------------------------------------------
326 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs)
327
328 class RuntimeBlob : public CodeBlob {
329 friend class VMStructs;
330 public:
331
332 // Creation
333 // a) simple CodeBlob
334 RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
335 : CodeBlob(name, kind, size, header_size)
336 {}
337
338 // b) full CodeBlob
339 // frame_complete is the offset from the beginning of the instructions
340 // to where the frame setup (from stackwalk viewpoint) is complete.
341 RuntimeBlob(
342 const char* name,
|