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