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