1 /*
2 * Copyright (c) 1998, 2026, 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_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/frame.hpp"
32 #include "runtime/handles.hpp"
33 #include "runtime/javaFrameAnchor.hpp"
34 #include "utilities/align.hpp"
35 #include "utilities/macros.hpp"
36
37 class AOTCodeReader;
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 MethodHot = 2, // Nmethods predicted to be always hot
49 NonNMethod = 3, // Non-nmethods like Buffers, Adapters and Runtime Stubs
50 All = 4, // All types (No code cache segmentation)
51 NumTypes = 5 // Number of CodeBlobTypes
52 };
53
54 // CodeBlob - superclass for all entries in the CodeCache.
55 //
56 // Subtypes are:
57 // nmethod : JIT Compiled Java methods
58 // RuntimeBlob : Non-compiled method code; generated glue code
59 // BufferBlob : Used for non-relocatable code such as interpreter, stubroutines, etc.
60 // AdapterBlob : Used to hold C2I/I2C adapters
61 // VtableBlob : Used for holding vtable chunks
62 // MethodHandlesAdapterBlob : Used to hold MethodHandles adapters
63 // RuntimeStub : Call to VM runtime methods
64 // SingletonBlob : Super-class for all blobs that exist in only one instance
65 // DeoptimizationBlob : Used for deoptimization
66 // SafepointBlob : Used to handle illegal instruction exceptions
67 // ExceptionBlob : Used for stack unrolling
68 // UncommonTrapBlob : Used to handle uncommon traps
69 // UpcallStub : Used for upcalls from native code
70 //
71 //
72 // Layout in the CodeCache:
73 // - header
74 // - content space
75 // - instruction space
76 // Outside of the CodeCache:
77 // - mutable_data
78 // - relocation info
79 // - additional data for subclasses
80
81 enum class CodeBlobKind : u1 {
82 None,
83 Nmethod,
84 Buffer,
85 Adapter,
86 Vtable,
87 MHAdapter,
88 RuntimeStub,
89 Deoptimization,
90 Safepoint,
91 #ifdef COMPILER2
92 Exception,
93 UncommonTrap,
94 #endif
95 Upcall,
96 Number_Of_Kinds
97 };
98
99 class UpcallStub; // for as_upcall_stub()
100 class RuntimeStub; // for as_runtime_stub()
101 class JavaFrameAnchor; // for UpcallStub::jfa_for_frame
102 class BufferBlob;
103 class AdapterBlob;
104 class SingletonBlob;
105 class ExceptionBlob;
106 class DeoptimizationBlob;
107 class SafepointBlob;
108 class UncommonTrapBlob;
109
110 class CodeBlob {
111 friend class VMStructs;
112
113 protected:
114 // order fields from large to small to minimize padding between fields
115 ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
116 const char* _name;
117 address _mutable_data;
118
119 int _size; // total size of CodeBlob in bytes
120 int _relocation_size; // size of relocation (could be bigger than 64Kb)
121 int _content_offset; // offset to where content region begins (this includes consts, insts, stubs)
122 int _code_offset; // offset to where instructions region begins (this includes insts, stubs)
123 int _data_offset; // offset to where data region begins
124 int _frame_size; // size of stack frame in words (NOT slots. On x64 these are 64bit words)
125 int _mutable_data_size;
126
127 S390_ONLY(int _ctable_offset;)
128
129 uint16_t _header_size; // size of header (depends on subclass)
130 int16_t _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
131 // not finished setting up their frame. Beware of pc's in
132 // that range. There is a similar range(s) on returns
133 // which we don't detect.
134
135 CodeBlobKind _kind; // Kind of this code blob
136
137 bool _caller_must_gc_arguments;
138
139 #ifndef PRODUCT
140 AsmRemarks _asm_remarks;
141 DbgStrings _dbg_strings;
142 #endif
143
144 void print_on_impl(outputStream* st) const;
145 void print_value_on_impl(outputStream* st) const;
146
147 class Vptr {
148 public:
149 virtual void print_on(const CodeBlob* instance, outputStream* st) const = 0;
150 virtual void print_value_on(const CodeBlob* instance, outputStream* st) const = 0;
151 virtual void prepare_for_archiving(CodeBlob* instance) const {
152 instance->prepare_for_archiving_impl();
153 };
154 virtual void post_restore(CodeBlob* instance) const {
155 instance->post_restore_impl();
156 };
157 };
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() NOT_CDS_RETURN;
173 void post_restore_impl() NOT_CDS_RETURN;
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 // we may want to check for an actual buffer blob or subtype instance
191 bool is_buffer_blob(bool strict=true) const {
192 if (strict) {
193 return _kind == CodeBlobKind::Buffer;
194 } else {
195 return (_kind == CodeBlobKind::Buffer ||
196 _kind == CodeBlobKind::Adapter ||
197 _kind == CodeBlobKind::Vtable ||
198 _kind == CodeBlobKind::MHAdapter);
199 }
200 }
201 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
202 // singleton blobs are never directly implemented
203 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
204 #ifdef COMPILER2
205 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
206 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
207 #else
208 bool is_uncommon_trap_stub() const { return false; }
209 bool is_exception_stub() const { return false; }
210 #endif
211 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
212 bool is_singleton_blob() const {
213 return (is_deoptimization_stub() ||
214 is_uncommon_trap_stub() ||
215 is_exception_stub() ||
216 is_safepoint_stub());
217 }
218 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
219 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
220 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
221 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
222
223 // Casting
224 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
225 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
226 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
227 // we may want to force an actual buffer blob or subtype instance
228 BufferBlob* as_buffer_blob(bool strict = true) const { assert(is_buffer_blob(strict), "must be %sbuffer blob", (strict ? "strict " : "")); return (BufferBlob*) this; }
229 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
230 ExceptionBlob* as_exception_blob() const { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; }
231 // this will always return a subtype instance
232 SingletonBlob* as_singleton_blob() const { assert(is_singleton_blob(), "must be singleton blob"); return (SingletonBlob*) this; }
233 DeoptimizationBlob* as_deoptimization_blob() const { assert(is_deoptimization_stub(), "must be deopt stub"); return (DeoptimizationBlob*) this; }
234 SafepointBlob* as_safepoint_blob() const { assert(is_safepoint_stub(), "must be safepoint stub"); return (SafepointBlob*) this; }
235 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
236 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
237 UncommonTrapBlob* as_uncommon_trap_blob() const { assert(is_uncommon_trap_stub(), "must be uncommon trap stub"); return (UncommonTrapBlob*) this; }
238
239 // Boundaries
240 address header_begin() const { return (address) this; }
241 address header_end() const { return ((address) this) + _header_size; }
242 address content_begin() const { return (address) header_begin() + _content_offset; }
243 address content_end() const { return (address) header_begin() + _data_offset; }
244 address code_begin() const { return (address) header_begin() + _code_offset; }
245 address code_end() const { return (address) header_begin() + _data_offset; }
246 address data_begin() const { return (address) header_begin() + _data_offset; }
247 address data_end() const { return (address) header_begin() + _size; }
248 address blob_end() const { return (address) header_begin() + _size; }
249 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
250
251 int mutable_data_size() const { return _mutable_data_size; }
252 address mutable_data_begin() const { return _mutable_data; }
253 address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
254
255 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
256 relocInfo* relocation_end() const { return (relocInfo*)((address)relocation_begin() + _relocation_size); }
257
258 // Offsets
259 int content_offset() const { return _content_offset; }
260 int code_offset() const { return _code_offset; }
261
262 // This field holds the beginning of the const section in the old code buffer.
263 // It is needed to fix relocations of pc-relative loads when resizing the
264 // the constant pool or moving it.
265 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
266 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
267
268 // Sizes
269 int size() const { return _size; }
270 int header_size() const { return _header_size; }
271 int relocation_size() const { return _relocation_size; }
272 int content_size() const { return pointer_delta_as_int(content_end(), content_begin()); }
273 int code_size() const { return pointer_delta_as_int(code_end(), code_begin()); }
274
275 // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
276 void adjust_size(size_t used) {
277 _size = (int)used;
278 _data_offset = _size;
279 }
280
281 // Containment
282 bool blob_contains(address addr) const { return header_begin() <= addr && addr < blob_end(); }
283 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
284 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
285 bool is_frame_complete_at(address addr) const { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
286 code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
287 int frame_complete_offset() const { return _frame_complete_offset; }
288
289 // OopMap for frame
290 ImmutableOopMapSet* oop_maps() const { return _oop_maps; }
291 void set_oop_maps(OopMapSet* p);
292 void set_oop_maps(ImmutableOopMapSet* p) { _oop_maps = p; }
293
294 const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const;
295 const ImmutableOopMap* oop_map_for_return_address(address return_address) const;
296
297 // Frame support. Sizes are in word units.
298 int frame_size() const { return _frame_size; }
299 void set_frame_size(int size) { _frame_size = size; }
300
301 // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
302 bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
303
304 // Naming
305 const char* name() const { return _name; }
306 void set_name(const char* name) { _name = name; }
307
308 // Debugging
309 void verify();
310 void print() const;
311 void print_on(outputStream* st) const;
312 void print_value_on(outputStream* st) const;
313
314 void dump_for_addr(address addr, outputStream* st, bool verbose) const;
315 void print_code_on(outputStream* st);
316
317 // Print to stream, any comments associated with offset.
318 void print_block_comment(outputStream* stream, address block_begin) const;
319
320 #ifndef PRODUCT
321 AsmRemarks &asm_remarks() { return _asm_remarks; }
322 DbgStrings &dbg_strings() { return _dbg_strings; }
323
324 void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); }
325 void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); }
326 #endif
327
328 #if INCLUDE_CDS
329 void restore_mutable_data(address reloc_data);
330
331 void copy_to(address buffer) {
332 memcpy(buffer, this, this->size());
333 }
334
335 // methods to archive a blob into AOT code cache
336 void prepare_for_archiving();
337 static void archive_blob(CodeBlob* blob, address archive_buffer);
338
339 // methods to restore a blob from AOT code cache into the CodeCache
340 void post_restore();
341 CodeBlob* restore(address code_cache_buffer, AOTCodeReader* reader);
342 static CodeBlob* create(CodeBlob* archived_blob, AOTCodeReader* reader);
343 #endif
344 };
345
346 //----------------------------------------------------------------------------------------------------
347 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs)
348
349 class RuntimeBlob : public CodeBlob {
350 public:
351
352 // Creation
353 // a) simple CodeBlob
354 RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
355 : CodeBlob(name, kind, size, header_size)
356 {}
357
358 // b) full CodeBlob
359 // frame_complete is the offset from the beginning of the instructions
360 // to where the frame setup (from stackwalk viewpoint) is complete.
361 RuntimeBlob(
362 const char* name,
363 CodeBlobKind kind,
364 CodeBuffer* cb,
365 int size,
366 uint16_t header_size,
367 int16_t frame_complete,
368 int frame_size,
369 OopMapSet* oop_maps,
370 bool caller_must_gc_arguments = false
371 );
372
373 static void free(RuntimeBlob* blob);
374
375 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
376 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
377
378 class Vptr : public CodeBlob::Vptr {
379 };
380 };
381
382 class WhiteBox;
383 //----------------------------------------------------------------------------------------------------
384 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
385
386 class BufferBlob: public RuntimeBlob {
387 friend class VMStructs;
388 friend class AdapterBlob;
389 friend class VtableBlob;
390 friend class MethodHandlesAdapterBlob;
391 friend class UpcallStub;
392 friend class WhiteBox;
393
394 private:
395 // Creation support
396 BufferBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size = sizeof(BufferBlob));
397 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size = sizeof(BufferBlob));
398
399 void* operator new(size_t s, unsigned size) throw();
400
401 public:
402 // Creation
403 static BufferBlob* create(const char* name, uint buffer_size);
404 static BufferBlob* create(const char* name, CodeBuffer* cb);
405
406 static void free(BufferBlob* buf);
407
408 void print_on_impl(outputStream* st) const;
409 void print_value_on_impl(outputStream* st) const;
410
411 class Vptr : public RuntimeBlob::Vptr {
412 void print_on(const CodeBlob* instance, outputStream* st) const override {
413 instance->as_buffer_blob(false)->print_on_impl(st);
414 }
415 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
416 instance->as_buffer_blob(false)->print_value_on_impl(st);
417 }
418 };
419
420 static const Vptr _vpntr;
421 };
422
423
424 //----------------------------------------------------------------------------------------------------
425 // AdapterBlob: used to hold C2I/I2C adapters
426
427 class AdapterBlob: public BufferBlob {
428 public:
429 enum Entry {
430 I2C,
431 C2I,
432 C2I_Unverified,
433 C2I_No_Clinit_Check,
434 ENTRY_COUNT
435 };
436 private:
437 AdapterBlob(int size, CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
438 // _i2c_offset is always 0 so no need to store it
439 int _c2i_offset;
440 int _c2i_unverified_offset;
441 int _c2i_no_clinit_check_offset;
442 public:
443 // Creation
444 static AdapterBlob* create(CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
445 address i2c_entry() { return code_begin(); }
446 address c2i_entry() { return i2c_entry() + _c2i_offset; }
447 address c2i_unverified_entry() { return i2c_entry() + _c2i_unverified_offset; }
448 address c2i_no_clinit_check_entry() { return _c2i_no_clinit_check_offset == -1 ? nullptr : i2c_entry() + _c2i_no_clinit_check_offset; }
449 };
450
451 //---------------------------------------------------------------------------------------------------
452 class VtableBlob: public BufferBlob {
453 private:
454 VtableBlob(const char*, int);
455
456 void* operator new(size_t s, unsigned size) throw();
457
458 public:
459 // Creation
460 static VtableBlob* create(const char* name, int buffer_size);
461 };
462
463 //----------------------------------------------------------------------------------------------------
464 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
465
466 class MethodHandlesAdapterBlob: public BufferBlob {
467 private:
468 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
469
470 public:
471 // Creation
472 static MethodHandlesAdapterBlob* create(int buffer_size);
473 };
474
475
476 //----------------------------------------------------------------------------------------------------
477 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
478
479 class RuntimeStub: public RuntimeBlob {
480 friend class VMStructs;
481 private:
482 // Creation support
483 RuntimeStub(
484 const char* name,
485 CodeBuffer* cb,
486 int size,
487 int16_t frame_complete,
488 int frame_size,
489 OopMapSet* oop_maps,
490 bool caller_must_gc_arguments
491 );
492
493 void* operator new(size_t s, unsigned size) throw();
494
495 public:
496 static const int ENTRY_COUNT = 1;
497 // Creation
498 static RuntimeStub* new_runtime_stub(
499 const char* stub_name,
500 CodeBuffer* cb,
501 int16_t frame_complete,
502 int frame_size,
503 OopMapSet* oop_maps,
504 bool caller_must_gc_arguments,
505 bool alloc_fail_is_fatal=true
506 );
507
508 static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); }
509
510 address entry_point() const { return code_begin(); }
511
512 void post_restore_impl() {
513 trace_new_stub(this, "RuntimeStub - ", name());
514 }
515
516 void print_on_impl(outputStream* st) const;
517 void print_value_on_impl(outputStream* st) const;
518
519 class Vptr : public RuntimeBlob::Vptr {
520 void post_restore(CodeBlob* instance) const override {
521 instance->as_runtime_stub()->post_restore_impl();
522 }
523 void print_on(const CodeBlob* instance, outputStream* st) const override {
524 instance->as_runtime_stub()->print_on_impl(st);
525 }
526 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
527 instance->as_runtime_stub()->print_value_on_impl(st);
528 }
529 };
530
531 static const Vptr _vpntr;
532 };
533
534
535 //----------------------------------------------------------------------------------------------------
536 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
537
538 class SingletonBlob: public RuntimeBlob {
539 friend class VMStructs;
540
541 protected:
542 void* operator new(size_t s, unsigned size, bool alloc_fail_is_fatal=true) throw();
543
544 public:
545 SingletonBlob(
546 const char* name,
547 CodeBlobKind kind,
548 CodeBuffer* cb,
549 int size,
550 uint16_t header_size,
551 int frame_size,
552 OopMapSet* oop_maps
553 )
554 : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
555 {};
556
557 address entry_point() { return code_begin(); }
558
559 void print_on_impl(outputStream* st) const;
560 void print_value_on_impl(outputStream* st) const;
561
562 class Vptr : public RuntimeBlob::Vptr {
563 void print_on(const CodeBlob* instance, outputStream* st) const override {
564 instance->as_singleton_blob()->print_on_impl(st);
565 }
566 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
567 instance->as_singleton_blob()->print_value_on_impl(st);
568 }
569 };
570
571 static const Vptr _vpntr;
572 };
573
574
575 //----------------------------------------------------------------------------------------------------
576 // DeoptimizationBlob
577
578 class DeoptimizationBlob: public SingletonBlob {
579 friend class VMStructs;
580
581 private:
582 int _unpack_offset;
583 int _unpack_with_exception;
584 int _unpack_with_reexecution;
585
586 int _unpack_with_exception_in_tls;
587
588 // Creation support
589 DeoptimizationBlob(
590 CodeBuffer* cb,
591 int size,
592 OopMapSet* oop_maps,
593 int unpack_offset,
594 int unpack_with_exception_offset,
595 int unpack_with_reexecution_offset,
596 int frame_size
597 );
598
599 public:
600 static const int ENTRY_COUNT = 4;
601 // Creation
602 static DeoptimizationBlob* create(
603 CodeBuffer* cb,
604 OopMapSet* oop_maps,
605 int unpack_offset,
606 int unpack_with_exception_offset,
607 int unpack_with_reexecution_offset,
608 int frame_size
609 );
610
611 address unpack() const { return code_begin() + _unpack_offset; }
612 address unpack_with_exception() const { return code_begin() + _unpack_with_exception; }
613 address unpack_with_reexecution() const { return code_begin() + _unpack_with_reexecution; }
614
615 // Alternate entry point for C1 where the exception and issuing pc
616 // are in JavaThread::_exception_oop and JavaThread::_exception_pc
617 // instead of being in registers. This is needed because C1 doesn't
618 // model exception paths in a way that keeps these registers free so
619 // there may be live values in those registers during deopt.
620 void set_unpack_with_exception_in_tls_offset(int offset) {
621 _unpack_with_exception_in_tls = offset;
622 assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
623 }
624 address unpack_with_exception_in_tls() const { return code_begin() + _unpack_with_exception_in_tls; }
625
626 void post_restore_impl() {
627 trace_new_stub(this, "DeoptimizationBlob");
628 }
629
630 void print_value_on_impl(outputStream* st) const;
631
632 class Vptr : public SingletonBlob::Vptr {
633 void post_restore(CodeBlob* instance) const override {
634 instance->as_deoptimization_blob()->post_restore_impl();
635 }
636
637 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
638 instance->as_deoptimization_blob()->print_value_on_impl(st);
639 }
640 };
641
642 static const Vptr _vpntr;
643 };
644
645
646 //----------------------------------------------------------------------------------------------------
647 // UncommonTrapBlob (currently only used by Compiler 2)
648
649 #ifdef COMPILER2
650
651 class UncommonTrapBlob: public SingletonBlob {
652 private:
653 // Creation support
654 UncommonTrapBlob(
655 CodeBuffer* cb,
656 int size,
657 OopMapSet* oop_maps,
658 int frame_size
659 );
660
661 public:
662 // Creation
663 static UncommonTrapBlob* create(
664 CodeBuffer* cb,
665 OopMapSet* oop_maps,
666 int frame_size
667 );
668 void post_restore_impl() {
669 trace_new_stub(this, "UncommonTrapBlob");
670 }
671 class Vptr : public SingletonBlob::Vptr {
672 void post_restore(CodeBlob* instance) const override {
673 instance->as_uncommon_trap_blob()->post_restore_impl();
674 }
675 };
676
677 static const Vptr _vpntr;
678 };
679
680
681 //----------------------------------------------------------------------------------------------------
682 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
683
684 class ExceptionBlob: public SingletonBlob {
685 private:
686 // Creation support
687 ExceptionBlob(
688 CodeBuffer* cb,
689 int size,
690 OopMapSet* oop_maps,
691 int frame_size
692 );
693
694 public:
695 // Creation
696 static ExceptionBlob* create(
697 CodeBuffer* cb,
698 OopMapSet* oop_maps,
699 int frame_size
700 );
701
702 void post_restore_impl() {
703 trace_new_stub(this, "ExceptionBlob");
704 }
705
706 class Vptr : public SingletonBlob::Vptr {
707 void post_restore(CodeBlob* instance) const override {
708 instance->as_exception_blob()->post_restore_impl();
709 }
710 };
711
712 static const Vptr _vpntr;
713 };
714 #endif // COMPILER2
715
716
717 //----------------------------------------------------------------------------------------------------
718 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
719
720 class SafepointBlob: public SingletonBlob {
721 private:
722 // Creation support
723 SafepointBlob(
724 CodeBuffer* cb,
725 int size,
726 OopMapSet* oop_maps,
727 int frame_size
728 );
729
730 public:
731 static const int ENTRY_COUNT = 1;
732 // Creation
733 static SafepointBlob* create(
734 CodeBuffer* cb,
735 OopMapSet* oop_maps,
736 int frame_size
737 );
738
739 void post_restore_impl() {
740 trace_new_stub(this, "SafepointBlob - ", name());
741 }
742 class Vptr : public SingletonBlob::Vptr {
743 void post_restore(CodeBlob* instance) const override {
744 instance->as_safepoint_blob()->post_restore_impl();
745 }
746 };
747
748 static const Vptr _vpntr;
749 };
750
751 //----------------------------------------------------------------------------------------------------
752
753 class UpcallLinker;
754
755 // A (Panama) upcall stub. Not used by JNI.
756 class UpcallStub: public RuntimeBlob {
757 friend class VMStructs;
758 friend class UpcallLinker;
759 private:
760 jobject _receiver;
761 ByteSize _frame_data_offset;
762
763 UpcallStub(const char* name, CodeBuffer* cb, int size, jobject receiver, ByteSize frame_data_offset);
764
765 void* operator new(size_t s, unsigned size) throw();
766
767 struct FrameData {
768 JavaFrameAnchor jfa;
769 JavaThread* thread;
770 JNIHandleBlock* old_handles;
771 JNIHandleBlock* new_handles;
772 };
773
774 // defined in frame_ARCH.cpp
775 FrameData* frame_data_for_frame(const frame& frame) const;
776 public:
777 // Creation
778 static UpcallStub* create(const char* name, CodeBuffer* cb, jobject receiver, ByteSize frame_data_offset);
779
780 static void free(UpcallStub* blob);
781
782 jobject receiver() { return _receiver; }
783
784 JavaFrameAnchor* jfa_for_frame(const frame& frame) const;
785
786 // GC support
787 void oops_do(OopClosure* f, const frame& frame);
788
789 void print_on_impl(outputStream* st) const;
790 void print_value_on_impl(outputStream* st) const;
791
792 class Vptr : public RuntimeBlob::Vptr {
793 void print_on(const CodeBlob* instance, outputStream* st) const override {
794 instance->as_upcall_stub()->print_on_impl(st);
795 }
796 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
797 instance->as_upcall_stub()->print_value_on_impl(st);
798 }
799 };
800
801 static const Vptr _vpntr;
802 };
803
804 #endif // SHARE_CODE_CODEBLOB_HPP