1 /*
  2  * Copyright (c) 1998, 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_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)
 50   NumTypes            = 4     // Number of CodeBlobTypes
 51 };
 52 
 53 // CodeBlob - superclass for all entries in the CodeCache.
 54 //
 55 // Subtypes are:
 56 //  nmethod              : JIT Compiled Java methods
 57 //  RuntimeBlob          : Non-compiled method code; generated glue code
 58 //   BufferBlob          : Used for non-relocatable code such as interpreter, stubroutines, etc.
 59 //    AdapterBlob        : Used to hold C2I/I2C adapters
 60 //    VtableBlob         : Used for holding vtable chunks
 61 //    MethodHandlesAdapterBlob : Used to hold MethodHandles adapters
 62 //   RuntimeStub         : Call to VM runtime methods
 63 //   SingletonBlob       : Super-class for all blobs that exist in only one instance
 64 //    DeoptimizationBlob : Used for deoptimization
 65 //    SafepointBlob      : Used to handle illegal instruction exceptions
 66 //    ExceptionBlob      : Used for stack unrolling
 67 //    UncommonTrapBlob   : Used to handle uncommon traps
 68 //   UpcallStub  : Used for upcalls from native code
 69 //
 70 //
 71 // Layout in the CodeCache:
 72 //   - header
 73 //   - content space
 74 //     - instruction space
 75 // Outside of the CodeCache:
 76 //   - mutable_data
 77 //     - relocation info
 78 //     - additional data for subclasses
 79 
 80 enum class CodeBlobKind : u1 {
 81   None,
 82   Nmethod,
 83   Buffer,
 84   Adapter,
 85   Vtable,
 86   MHAdapter,
 87   RuntimeStub,
 88   Deoptimization,
 89   Safepoint,
 90 #ifdef COMPILER2
 91   Exception,
 92   UncommonTrap,
 93 #endif
 94   Upcall,
 95   Number_Of_Kinds
 96 };
 97 
 98 class UpcallStub;      // for as_upcall_stub()
 99 class RuntimeStub;     // for as_runtime_stub()
100 class JavaFrameAnchor; // for UpcallStub::jfa_for_frame
101 class AdapterBlob;
102 class ExceptionBlob;
103 class DeoptimizationBlob;
104 class SafepointBlob;
105 class UncommonTrapBlob;
106 
107 class CodeBlob {
108   friend class VMStructs;
109   friend class JVMCIVMStructs;
110 
111 private:
112   void restore_mutable_data(address reloc_data);
113 
114 protected:
115   // order fields from large to small to minimize padding between fields
116   ImmutableOopMapSet* _oop_maps;   // OopMap for this CodeBlob
117   const char*         _name;
118   address             _mutable_data;
119 
120   int      _size;                  // total size of CodeBlob in bytes
121   int      _relocation_size;       // size of relocation (could be bigger than 64Kb)
122   int      _content_offset;        // offset to where content region begins (this includes consts, insts, stubs)
123   int      _code_offset;           // offset to where instructions region begins (this includes insts, stubs)
124   int      _data_offset;           // offset to where data region begins
125   int      _frame_size;            // size of stack frame in words (NOT slots. On x64 these are 64bit words)
126   int      _mutable_data_size;
127 
128   S390_ONLY(int _ctable_offset;)
129 
130   uint16_t _header_size;           // size of header (depends on subclass)
131   int16_t  _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
132                                    // not finished setting up their frame. Beware of pc's in
133                                    // that range. There is a similar range(s) on returns
134                                    // which we don't detect.
135 
136   CodeBlobKind _kind;              // Kind of this code blob
137 
138   bool _caller_must_gc_arguments;
139 
140 #ifndef PRODUCT
141   AsmRemarks _asm_remarks;
142   DbgStrings _dbg_strings;
143 #endif
144 
145   void print_on_impl(outputStream* st) const;
146   void print_value_on_impl(outputStream* st) const;
147 
148   class Vptr {
149    public:
150     virtual void print_on(const CodeBlob* instance, outputStream* st) const = 0;
151     virtual void print_value_on(const CodeBlob* instance, outputStream* st) const = 0;
152     virtual void prepare_for_archiving(CodeBlob* instance) const {
153       instance->prepare_for_archiving_impl();
154     };
155     virtual void post_restore(CodeBlob* instance) const {
156       instance->post_restore_impl();
157     };
158   };
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; }
200 #endif
201   bool is_safepoint_stub() const              { return _kind == CodeBlobKind::Safepoint; }
202   bool is_adapter_blob() const                { return _kind == CodeBlobKind::Adapter; }
203   bool is_vtable_blob() const                 { return _kind == CodeBlobKind::Vtable; }
204   bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
205   bool is_upcall_stub() const                 { return _kind == CodeBlobKind::Upcall; }
206 
207   // Casting
208   nmethod* as_nmethod_or_null() const         { return is_nmethod() ? (nmethod*) this : nullptr; }
209   nmethod* as_nmethod() const                 { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
210   CodeBlob* as_codeblob() const               { return (CodeBlob*) this; }
211   AdapterBlob* as_adapter_blob() const        { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
212   ExceptionBlob* as_exception_blob() const    { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; }
213   DeoptimizationBlob* as_deoptimization_blob() const { assert(is_deoptimization_stub(), "must be deopt stub"); return (DeoptimizationBlob*) this; }
214   SafepointBlob* as_safepoint_blob() const    { assert(is_safepoint_stub(), "must be safepoint stub"); return (SafepointBlob*) this; }
215   UpcallStub* as_upcall_stub() const          { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
216   RuntimeStub* as_runtime_stub() const        { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
217   UncommonTrapBlob* as_uncommon_trap_blob() const { assert(is_uncommon_trap_stub(), "must be uncommon trap stub"); return (UncommonTrapBlob*) this; }
218 
219   // Boundaries
220   address    header_begin() const             { return (address)    this; }
221   address    header_end() const               { return ((address)   this) + _header_size; }
222   address    content_begin() const            { return (address)    header_begin() + _content_offset; }
223   address    content_end() const              { return (address)    header_begin() + _data_offset; }
224   address    code_begin() const               { return (address)    header_begin() + _code_offset; }
225   address    code_end() const                 { return (address)    header_begin() + _data_offset; }
226   address    data_begin() const               { return (address)    header_begin() + _data_offset; }
227   address    data_end() const                 { return (address)    header_begin() + _size; }
228   address    blob_end() const                 { return (address)    header_begin() + _size; }
229   // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
230 
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 pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); }
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);
272   void set_oop_maps(ImmutableOopMapSet* p)       { _oop_maps = p; }
273 
274   const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const;
275   const ImmutableOopMap* oop_map_for_return_address(address return_address) const;
276 
277   // Frame support. Sizes are in word units.
278   int  frame_size() const                        { return _frame_size; }
279   void set_frame_size(int size)                  { _frame_size = size; }
280 
281   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
282   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
283 
284   // Naming
285   const char* name() const                       { return _name; }
286   void set_name(const char* name)                { _name = name; }
287 
288   // Debugging
289   void verify();
290   void print() const;
291   void print_on(outputStream* st) const;
292   void print_value_on(outputStream* st) const;
293 
294   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
295   void print_code_on(outputStream* st);
296 
297   // Print to stream, any comments associated with offset.
298   void print_block_comment(outputStream* stream, address block_begin) const;
299 
300 #ifndef PRODUCT
301   AsmRemarks &asm_remarks() { return _asm_remarks; }
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,
343     CodeBlobKind kind,
344     CodeBuffer* cb,
345     int         size,
346     uint16_t    header_size,
347     int16_t     frame_complete,
348     int         frame_size,
349     OopMapSet*  oop_maps,
350     bool        caller_must_gc_arguments = false
351   );
352 
353   static void free(RuntimeBlob* blob);
354 
355   // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
356   static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
357 
358   class Vptr : public CodeBlob::Vptr {
359   };
360 };
361 
362 class WhiteBox;
363 //----------------------------------------------------------------------------------------------------
364 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
365 
366 class BufferBlob: public RuntimeBlob {
367   friend class VMStructs;
368   friend class AdapterBlob;
369   friend class VtableBlob;
370   friend class MethodHandlesAdapterBlob;
371   friend class UpcallStub;
372   friend class WhiteBox;
373 
374  private:
375   // Creation support
376   BufferBlob(const char* name, CodeBlobKind kind, int size);
377   BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
378 
379   void* operator new(size_t s, unsigned size) throw();
380 
381  public:
382   // Creation
383   static BufferBlob* create(const char* name, uint buffer_size);
384   static BufferBlob* create(const char* name, CodeBuffer* cb);
385 
386   static void free(BufferBlob* buf);
387 
388   void print_on_impl(outputStream* st) const;
389   void print_value_on_impl(outputStream* st) const;
390 
391   class Vptr : public RuntimeBlob::Vptr {
392     void print_on(const CodeBlob* instance, outputStream* st) const override {
393       ((const BufferBlob*)instance)->print_on_impl(st);
394     }
395     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
396       ((const BufferBlob*)instance)->print_value_on_impl(st);
397     }
398   };
399 
400   static const Vptr _vpntr;
401 };
402 
403 
404 //----------------------------------------------------------------------------------------------------
405 // AdapterBlob: used to hold C2I/I2C adapters
406 
407 class AdapterBlob: public BufferBlob {
408 private:
409   AdapterBlob(int size, CodeBuffer* cb);
410 
411 public:
412   // Creation
413   static AdapterBlob* create(CodeBuffer* cb);
414 };
415 
416 //---------------------------------------------------------------------------------------------------
417 class VtableBlob: public BufferBlob {
418 private:
419   VtableBlob(const char*, int);
420 
421   void* operator new(size_t s, unsigned size) throw();
422 
423 public:
424   // Creation
425   static VtableBlob* create(const char* name, int buffer_size);
426 };
427 
428 //----------------------------------------------------------------------------------------------------
429 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
430 
431 class MethodHandlesAdapterBlob: public BufferBlob {
432 private:
433   MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
434 
435 public:
436   // Creation
437   static MethodHandlesAdapterBlob* create(int buffer_size);
438 };
439 
440 
441 //----------------------------------------------------------------------------------------------------
442 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
443 
444 class RuntimeStub: public RuntimeBlob {
445   friend class VMStructs;
446  private:
447   // Creation support
448   RuntimeStub(
449     const char* name,
450     CodeBuffer* cb,
451     int         size,
452     int16_t     frame_complete,
453     int         frame_size,
454     OopMapSet*  oop_maps,
455     bool        caller_must_gc_arguments
456   );
457 
458   void* operator new(size_t s, unsigned size) throw();
459 
460  public:
461   // Creation
462   static RuntimeStub* new_runtime_stub(
463     const char* stub_name,
464     CodeBuffer* cb,
465     int16_t     frame_complete,
466     int         frame_size,
467     OopMapSet*  oop_maps,
468     bool        caller_must_gc_arguments,
469     bool        alloc_fail_is_fatal=true
470   );
471 
472   static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); }
473 
474   address entry_point() const         { return code_begin(); }
475 
476   void print_on_impl(outputStream* st) const;
477   void print_value_on_impl(outputStream* st) const;
478 
479   class Vptr : public RuntimeBlob::Vptr {
480     void print_on(const CodeBlob* instance, outputStream* st) const override {
481       instance->as_runtime_stub()->print_on_impl(st);
482     }
483     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
484       instance->as_runtime_stub()->print_value_on_impl(st);
485     }
486   };
487 
488   static const Vptr _vpntr;
489 };
490 
491 
492 //----------------------------------------------------------------------------------------------------
493 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
494 
495 class SingletonBlob: public RuntimeBlob {
496   friend class VMStructs;
497 
498  protected:
499   void* operator new(size_t s, unsigned size, bool alloc_fail_is_fatal=true) throw();
500 
501  public:
502    SingletonBlob(
503      const char*  name,
504      CodeBlobKind kind,
505      CodeBuffer*  cb,
506      int          size,
507      uint16_t     header_size,
508      int          frame_size,
509      OopMapSet*   oop_maps
510    )
511    : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
512   {};
513 
514   address entry_point()                          { return code_begin(); }
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 print_on(const CodeBlob* instance, outputStream* st) const override {
521       ((const SingletonBlob*)instance)->print_on_impl(st);
522     }
523     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
524       ((const SingletonBlob*)instance)->print_value_on_impl(st);
525     }
526   };
527 
528   static const Vptr _vpntr;
529 };
530 
531 
532 //----------------------------------------------------------------------------------------------------
533 // DeoptimizationBlob
534 
535 class DeoptimizationBlob: public SingletonBlob {
536   friend class VMStructs;
537   friend class JVMCIVMStructs;
538  private:
539   int _unpack_offset;
540   int _unpack_with_exception;
541   int _unpack_with_reexecution;
542 
543   int _unpack_with_exception_in_tls;
544 
545 #if INCLUDE_JVMCI
546   // Offsets when JVMCI calls uncommon_trap.
547   int _uncommon_trap_offset;
548   int _implicit_exception_uncommon_trap_offset;
549 #endif
550 
551   // Creation support
552   DeoptimizationBlob(
553     CodeBuffer* cb,
554     int         size,
555     OopMapSet*  oop_maps,
556     int         unpack_offset,
557     int         unpack_with_exception_offset,
558     int         unpack_with_reexecution_offset,
559     int         frame_size
560   );
561 
562  public:
563   // Creation
564   static DeoptimizationBlob* create(
565     CodeBuffer* cb,
566     OopMapSet*  oop_maps,
567     int         unpack_offset,
568     int         unpack_with_exception_offset,
569     int         unpack_with_reexecution_offset,
570     int         frame_size
571   );
572 
573   address unpack() const                         { return code_begin() + _unpack_offset;           }
574   address unpack_with_exception() const          { return code_begin() + _unpack_with_exception;   }
575   address unpack_with_reexecution() const        { return code_begin() + _unpack_with_reexecution; }
576 
577   // Alternate entry point for C1 where the exception and issuing pc
578   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
579   // instead of being in registers.  This is needed because C1 doesn't
580   // model exception paths in a way that keeps these registers free so
581   // there may be live values in those registers during deopt.
582   void set_unpack_with_exception_in_tls_offset(int offset) {
583     _unpack_with_exception_in_tls = offset;
584     assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
585   }
586   address unpack_with_exception_in_tls() const   { return code_begin() + _unpack_with_exception_in_tls; }
587 
588 #if INCLUDE_JVMCI
589   // Offsets when JVMCI calls uncommon_trap.
590   void set_uncommon_trap_offset(int offset) {
591     _uncommon_trap_offset = offset;
592     assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob");
593   }
594   address uncommon_trap() const                  { return code_begin() + _uncommon_trap_offset; }
595 
596   void set_implicit_exception_uncommon_trap_offset(int offset) {
597     _implicit_exception_uncommon_trap_offset = offset;
598     assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob");
599   }
600   address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; }
601 #endif // INCLUDE_JVMCI
602 
603   void print_value_on_impl(outputStream* st) const;
604 
605   class Vptr : public SingletonBlob::Vptr {
606     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
607       ((const DeoptimizationBlob*)instance)->print_value_on_impl(st);
608     }
609   };
610 
611   static const Vptr _vpntr;
612 };
613 
614 
615 //----------------------------------------------------------------------------------------------------
616 // UncommonTrapBlob (currently only used by Compiler 2)
617 
618 #ifdef COMPILER2
619 
620 class UncommonTrapBlob: public SingletonBlob {
621   friend class VMStructs;
622  private:
623   // Creation support
624   UncommonTrapBlob(
625     CodeBuffer* cb,
626     int         size,
627     OopMapSet*  oop_maps,
628     int         frame_size
629   );
630 
631  public:
632   // Creation
633   static UncommonTrapBlob* create(
634     CodeBuffer* cb,
635     OopMapSet*  oop_maps,
636     int         frame_size
637   );
638 };
639 
640 
641 //----------------------------------------------------------------------------------------------------
642 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
643 
644 class ExceptionBlob: public SingletonBlob {
645   friend class VMStructs;
646  private:
647   // Creation support
648   ExceptionBlob(
649     CodeBuffer* cb,
650     int         size,
651     OopMapSet*  oop_maps,
652     int         frame_size
653   );
654 
655  public:
656   // Creation
657   static ExceptionBlob* create(
658     CodeBuffer* cb,
659     OopMapSet*  oop_maps,
660     int         frame_size
661   );
662 
663   void post_restore_impl() {
664     trace_new_stub(this, "ExceptionBlob");
665   }
666 
667   class Vptr : public SingletonBlob::Vptr {
668     void post_restore(CodeBlob* instance) const override {
669       ((ExceptionBlob*)instance)->post_restore_impl();
670     }
671   };
672 
673   static const Vptr _vpntr;
674 };
675 #endif // COMPILER2
676 
677 
678 //----------------------------------------------------------------------------------------------------
679 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
680 
681 class SafepointBlob: public SingletonBlob {
682   friend class VMStructs;
683  private:
684   // Creation support
685   SafepointBlob(
686     CodeBuffer* cb,
687     int         size,
688     OopMapSet*  oop_maps,
689     int         frame_size
690   );
691 
692  public:
693   // Creation
694   static SafepointBlob* create(
695     CodeBuffer* cb,
696     OopMapSet*  oop_maps,
697     int         frame_size
698   );
699 };
700 
701 //----------------------------------------------------------------------------------------------------
702 
703 class UpcallLinker;
704 
705 // A (Panama) upcall stub. Not used by JNI.
706 class UpcallStub: public RuntimeBlob {
707   friend class VMStructs;
708   friend class UpcallLinker;
709  private:
710   jobject _receiver;
711   ByteSize _frame_data_offset;
712 
713   UpcallStub(const char* name, CodeBuffer* cb, int size, jobject receiver, ByteSize frame_data_offset);
714 
715   void* operator new(size_t s, unsigned size) throw();
716 
717   struct FrameData {
718     JavaFrameAnchor jfa;
719     JavaThread* thread;
720     JNIHandleBlock* old_handles;
721     JNIHandleBlock* new_handles;
722   };
723 
724   // defined in frame_ARCH.cpp
725   FrameData* frame_data_for_frame(const frame& frame) const;
726  public:
727   // Creation
728   static UpcallStub* create(const char* name, CodeBuffer* cb, jobject receiver, ByteSize frame_data_offset);
729 
730   static void free(UpcallStub* blob);
731 
732   jobject receiver() { return _receiver; }
733 
734   JavaFrameAnchor* jfa_for_frame(const frame& frame) const;
735 
736   // GC support
737   void oops_do(OopClosure* f, const frame& frame);
738 
739   void print_on_impl(outputStream* st) const;
740   void print_value_on_impl(outputStream* st) const;
741 
742   class Vptr : public RuntimeBlob::Vptr {
743     void print_on(const CodeBlob* instance, outputStream* st) const override {
744       instance->as_upcall_stub()->print_on_impl(st);
745     }
746     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
747       instance->as_upcall_stub()->print_value_on_impl(st);
748     }
749   };
750 
751   static const Vptr _vpntr;
752 };
753 
754 #endif // SHARE_CODE_CODEBLOB_HPP