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 #ifndef PRODUCT
324                           , AsmRemarks& archived_asm_remarks
325                           , DbgStrings& archived_dbg_strings
326 #endif // PRODUCT
327                          );
328 };
329 
330 //----------------------------------------------------------------------------------------------------
331 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs)
332 
333 class RuntimeBlob : public CodeBlob {
334   friend class VMStructs;
335  public:
336 
337   // Creation
338   // a) simple CodeBlob
339   RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
340     : CodeBlob(name, kind, size, header_size)
341   {}
342 
343   // b) full CodeBlob
344   // frame_complete is the offset from the beginning of the instructions
345   // to where the frame setup (from stackwalk viewpoint) is complete.
346   RuntimeBlob(
347     const char* name,
348     CodeBlobKind kind,
349     CodeBuffer* cb,
350     int         size,
351     uint16_t    header_size,
352     int16_t     frame_complete,
353     int         frame_size,
354     OopMapSet*  oop_maps,
355     bool        caller_must_gc_arguments = false
356   );
357 
358   static void free(RuntimeBlob* blob);
359 
360   // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
361   static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
362 
363   class Vptr : public CodeBlob::Vptr {
364   };
365 };
366 
367 class WhiteBox;
368 //----------------------------------------------------------------------------------------------------
369 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
370 
371 class BufferBlob: public RuntimeBlob {
372   friend class VMStructs;
373   friend class AdapterBlob;
374   friend class VtableBlob;
375   friend class MethodHandlesAdapterBlob;
376   friend class UpcallStub;
377   friend class WhiteBox;
378 
379  private:
380   // Creation support
381   BufferBlob(const char* name, CodeBlobKind kind, int size);
382   BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
383 
384   void* operator new(size_t s, unsigned size) throw();
385 
386  public:
387   // Creation
388   static BufferBlob* create(const char* name, uint buffer_size);
389   static BufferBlob* create(const char* name, CodeBuffer* cb);
390 
391   static void free(BufferBlob* buf);
392 
393   void print_on_impl(outputStream* st) const;
394   void print_value_on_impl(outputStream* st) const;
395 
396   class Vptr : public RuntimeBlob::Vptr {
397     void print_on(const CodeBlob* instance, outputStream* st) const override {
398       ((const BufferBlob*)instance)->print_on_impl(st);
399     }
400     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
401       ((const BufferBlob*)instance)->print_value_on_impl(st);
402     }
403   };
404 
405   static const Vptr _vpntr;
406 };
407 
408 
409 //----------------------------------------------------------------------------------------------------
410 // AdapterBlob: used to hold C2I/I2C adapters
411 
412 class AdapterBlob: public BufferBlob {
413 private:
414   AdapterBlob(int size, CodeBuffer* cb);
415 
416 public:
417   // Creation
418   static AdapterBlob* create(CodeBuffer* cb);
419 };
420 
421 //---------------------------------------------------------------------------------------------------
422 class VtableBlob: public BufferBlob {
423 private:
424   VtableBlob(const char*, int);
425 
426   void* operator new(size_t s, unsigned size) throw();
427 
428 public:
429   // Creation
430   static VtableBlob* create(const char* name, int buffer_size);
431 };
432 
433 //----------------------------------------------------------------------------------------------------
434 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
435 
436 class MethodHandlesAdapterBlob: public BufferBlob {
437 private:
438   MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
439 
440 public:
441   // Creation
442   static MethodHandlesAdapterBlob* create(int buffer_size);
443 };
444 
445 
446 //----------------------------------------------------------------------------------------------------
447 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
448 
449 class RuntimeStub: public RuntimeBlob {
450   friend class VMStructs;
451  private:
452   // Creation support
453   RuntimeStub(
454     const char* name,
455     CodeBuffer* cb,
456     int         size,
457     int16_t     frame_complete,
458     int         frame_size,
459     OopMapSet*  oop_maps,
460     bool        caller_must_gc_arguments
461   );
462 
463   void* operator new(size_t s, unsigned size) throw();
464 
465  public:
466   // Creation
467   static RuntimeStub* new_runtime_stub(
468     const char* stub_name,
469     CodeBuffer* cb,
470     int16_t     frame_complete,
471     int         frame_size,
472     OopMapSet*  oop_maps,
473     bool        caller_must_gc_arguments,
474     bool        alloc_fail_is_fatal=true
475   );
476 
477   static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); }
478 
479   address entry_point() const         { return code_begin(); }
480 
481   void print_on_impl(outputStream* st) const;
482   void print_value_on_impl(outputStream* st) const;
483 
484   class Vptr : public RuntimeBlob::Vptr {
485     void print_on(const CodeBlob* instance, outputStream* st) const override {
486       instance->as_runtime_stub()->print_on_impl(st);
487     }
488     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
489       instance->as_runtime_stub()->print_value_on_impl(st);
490     }
491   };
492 
493   static const Vptr _vpntr;
494 };
495 
496 
497 //----------------------------------------------------------------------------------------------------
498 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
499 
500 class SingletonBlob: public RuntimeBlob {
501   friend class VMStructs;
502 
503  protected:
504   void* operator new(size_t s, unsigned size, bool alloc_fail_is_fatal=true) throw();
505 
506  public:
507    SingletonBlob(
508      const char*  name,
509      CodeBlobKind kind,
510      CodeBuffer*  cb,
511      int          size,
512      uint16_t     header_size,
513      int          frame_size,
514      OopMapSet*   oop_maps
515    )
516    : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
517   {};
518 
519   address entry_point()                          { return code_begin(); }
520 
521   void print_on_impl(outputStream* st) const;
522   void print_value_on_impl(outputStream* st) const;
523 
524   class Vptr : public RuntimeBlob::Vptr {
525     void print_on(const CodeBlob* instance, outputStream* st) const override {
526       ((const SingletonBlob*)instance)->print_on_impl(st);
527     }
528     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
529       ((const SingletonBlob*)instance)->print_value_on_impl(st);
530     }
531   };
532 
533   static const Vptr _vpntr;
534 };
535 
536 
537 //----------------------------------------------------------------------------------------------------
538 // DeoptimizationBlob
539 
540 class DeoptimizationBlob: public SingletonBlob {
541   friend class VMStructs;
542   friend class JVMCIVMStructs;
543  private:
544   int _unpack_offset;
545   int _unpack_with_exception;
546   int _unpack_with_reexecution;
547 
548   int _unpack_with_exception_in_tls;
549 
550 #if INCLUDE_JVMCI
551   // Offsets when JVMCI calls uncommon_trap.
552   int _uncommon_trap_offset;
553   int _implicit_exception_uncommon_trap_offset;
554 #endif
555 
556   // Creation support
557   DeoptimizationBlob(
558     CodeBuffer* cb,
559     int         size,
560     OopMapSet*  oop_maps,
561     int         unpack_offset,
562     int         unpack_with_exception_offset,
563     int         unpack_with_reexecution_offset,
564     int         frame_size
565   );
566 
567  public:
568   // Creation
569   static DeoptimizationBlob* create(
570     CodeBuffer* cb,
571     OopMapSet*  oop_maps,
572     int         unpack_offset,
573     int         unpack_with_exception_offset,
574     int         unpack_with_reexecution_offset,
575     int         frame_size
576   );
577 
578   address unpack() const                         { return code_begin() + _unpack_offset;           }
579   address unpack_with_exception() const          { return code_begin() + _unpack_with_exception;   }
580   address unpack_with_reexecution() const        { return code_begin() + _unpack_with_reexecution; }
581 
582   // Alternate entry point for C1 where the exception and issuing pc
583   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
584   // instead of being in registers.  This is needed because C1 doesn't
585   // model exception paths in a way that keeps these registers free so
586   // there may be live values in those registers during deopt.
587   void set_unpack_with_exception_in_tls_offset(int offset) {
588     _unpack_with_exception_in_tls = offset;
589     assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
590   }
591   address unpack_with_exception_in_tls() const   { return code_begin() + _unpack_with_exception_in_tls; }
592 
593 #if INCLUDE_JVMCI
594   // Offsets when JVMCI calls uncommon_trap.
595   void set_uncommon_trap_offset(int offset) {
596     _uncommon_trap_offset = offset;
597     assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob");
598   }
599   address uncommon_trap() const                  { return code_begin() + _uncommon_trap_offset; }
600 
601   void set_implicit_exception_uncommon_trap_offset(int offset) {
602     _implicit_exception_uncommon_trap_offset = offset;
603     assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob");
604   }
605   address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; }
606 #endif // INCLUDE_JVMCI
607 
608   void print_value_on_impl(outputStream* st) const;
609 
610   class Vptr : public SingletonBlob::Vptr {
611     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
612       ((const DeoptimizationBlob*)instance)->print_value_on_impl(st);
613     }
614   };
615 
616   static const Vptr _vpntr;
617 };
618 
619 
620 //----------------------------------------------------------------------------------------------------
621 // UncommonTrapBlob (currently only used by Compiler 2)
622 
623 #ifdef COMPILER2
624 
625 class UncommonTrapBlob: public SingletonBlob {
626   friend class VMStructs;
627  private:
628   // Creation support
629   UncommonTrapBlob(
630     CodeBuffer* cb,
631     int         size,
632     OopMapSet*  oop_maps,
633     int         frame_size
634   );
635 
636  public:
637   // Creation
638   static UncommonTrapBlob* create(
639     CodeBuffer* cb,
640     OopMapSet*  oop_maps,
641     int         frame_size
642   );
643 };
644 
645 
646 //----------------------------------------------------------------------------------------------------
647 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
648 
649 class ExceptionBlob: public SingletonBlob {
650   friend class VMStructs;
651  private:
652   // Creation support
653   ExceptionBlob(
654     CodeBuffer* cb,
655     int         size,
656     OopMapSet*  oop_maps,
657     int         frame_size
658   );
659 
660  public:
661   // Creation
662   static ExceptionBlob* create(
663     CodeBuffer* cb,
664     OopMapSet*  oop_maps,
665     int         frame_size
666   );
667 
668   void post_restore_impl() {
669     trace_new_stub(this, "ExceptionBlob");
670   }
671 
672   class Vptr : public SingletonBlob::Vptr {
673     void post_restore(CodeBlob* instance) const override {
674       ((ExceptionBlob*)instance)->post_restore_impl();
675     }
676   };
677 
678   static const Vptr _vpntr;
679 };
680 #endif // COMPILER2
681 
682 
683 //----------------------------------------------------------------------------------------------------
684 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
685 
686 class SafepointBlob: public SingletonBlob {
687   friend class VMStructs;
688  private:
689   // Creation support
690   SafepointBlob(
691     CodeBuffer* cb,
692     int         size,
693     OopMapSet*  oop_maps,
694     int         frame_size
695   );
696 
697  public:
698   // Creation
699   static SafepointBlob* create(
700     CodeBuffer* cb,
701     OopMapSet*  oop_maps,
702     int         frame_size
703   );
704 };
705 
706 //----------------------------------------------------------------------------------------------------
707 
708 class UpcallLinker;
709 
710 // A (Panama) upcall stub. Not used by JNI.
711 class UpcallStub: public RuntimeBlob {
712   friend class VMStructs;
713   friend class UpcallLinker;
714  private:
715   jobject _receiver;
716   ByteSize _frame_data_offset;
717 
718   UpcallStub(const char* name, CodeBuffer* cb, int size, jobject receiver, ByteSize frame_data_offset);
719 
720   void* operator new(size_t s, unsigned size) throw();
721 
722   struct FrameData {
723     JavaFrameAnchor jfa;
724     JavaThread* thread;
725     JNIHandleBlock* old_handles;
726     JNIHandleBlock* new_handles;
727   };
728 
729   // defined in frame_ARCH.cpp
730   FrameData* frame_data_for_frame(const frame& frame) const;
731  public:
732   // Creation
733   static UpcallStub* create(const char* name, CodeBuffer* cb, jobject receiver, ByteSize frame_data_offset);
734 
735   static void free(UpcallStub* blob);
736 
737   jobject receiver() { return _receiver; }
738 
739   JavaFrameAnchor* jfa_for_frame(const frame& frame) const;
740 
741   // GC support
742   void oops_do(OopClosure* f, const frame& frame);
743 
744   void print_on_impl(outputStream* st) const;
745   void print_value_on_impl(outputStream* st) const;
746 
747   class Vptr : public RuntimeBlob::Vptr {
748     void print_on(const CodeBlob* instance, outputStream* st) const override {
749       instance->as_upcall_stub()->print_on_impl(st);
750     }
751     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
752       instance->as_upcall_stub()->print_value_on_impl(st);
753     }
754   };
755 
756   static const Vptr _vpntr;
757 };
758 
759 #endif // SHARE_CODE_CODEBLOB_HPP