1 /*
  2  * Copyright (c) 1998, 2018, 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_VM_CODE_CODEBLOB_HPP
 26 #define SHARE_VM_CODE_CODEBLOB_HPP
 27 
 28 #include "asm/codeBuffer.hpp"
 29 #include "compiler/compilerDefinitions.hpp"
 30 #include "compiler/oopMap.hpp"
 31 #include "runtime/frame.hpp"
 32 #include "runtime/handles.hpp"
 33 #include "utilities/align.hpp"
 34 #include "utilities/macros.hpp"
 35 
 36 // CodeBlob Types
 37 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
 38 struct CodeBlobType {
 39   enum {
 40     MethodNonProfiled   = 0,    // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
 41     MethodProfiled      = 1,    // Execution level 2 and 3 (profiled) nmethods
 42     NonNMethod          = 2,    // Non-nmethods like Buffers, Adapters and Runtime Stubs
 43     All                 = 3,    // All types (No code cache segmentation)
 44     AOT                 = 4,    // AOT methods
 45     NumTypes            = 5     // Number of CodeBlobTypes
 46   };
 47 };
 48 
 49 // CodeBlob - superclass for all entries in the CodeCache.
 50 //
 51 // Subtypes are:
 52 //  CompiledMethod       : Compiled Java methods (include method that calls to native code)
 53 //   nmethod             : JIT Compiled Java methods
 54 //   AOTCompiledMethod   : AOT Compiled Java methods - Not in the CodeCache!
 55 //                         AOTCompiledMethod objects are allocated in the C-Heap, the code they
 56 //                         point to is allocated in the AOTCodeHeap which is in the C-Heap as
 57 //                         well (i.e. it's the memory where the shared library was loaded to)
 58 //  RuntimeBlob          : Non-compiled method code; generated glue code
 59 //   BufferBlob          : Used for non-relocatable code such as interpreter, stubroutines, etc.
 60 //    AdapterBlob        : Used to hold C2I/I2C adapters
 61 //    VtableBlob         : Used for holding vtable chunks
 62 //    MethodHandlesAdapterBlob : Used to hold MethodHandles adapters
 63 //   RuntimeStub         : Call to VM runtime methods
 64 //   SingletonBlob       : Super-class for all blobs that exist in only one instance
 65 //    DeoptimizationBlob : Used for deoptimization
 66 //    ExceptionBlob      : Used for stack unrolling
 67 //    SafepointBlob      : Used to handle illegal instruction exceptions
 68 //    UncommonTrapBlob   : Used to handle uncommon traps
 69 //
 70 //
 71 // Layout (all except AOTCompiledMethod) : continuous in the CodeCache
 72 //   - header
 73 //   - relocation
 74 //   - content space
 75 //     - instruction space
 76 //   - data space
 77 //
 78 // Layout (AOTCompiledMethod) : in the C-Heap
 79 //   - header -\
 80 //     ...     |
 81 //   - code  <-/
 82 
 83 
 84 class CodeBlobLayout;
 85 
 86 class CodeBlob {
 87   friend class VMStructs;
 88   friend class JVMCIVMStructs;
 89   friend class CodeCacheDumper;
 90 
 91 protected:
 92 
 93   const CompilerType _type;                      // CompilerType
 94   int        _size;                              // total size of CodeBlob in bytes
 95   int        _header_size;                       // size of header (depends on subclass)
 96   int        _frame_complete_offset;             // instruction offsets in [0.._frame_complete_offset) have
 97                                                  // not finished setting up their frame. Beware of pc's in
 98                                                  // that range. There is a similar range(s) on returns
 99                                                  // which we don't detect.
100   int        _data_offset;                       // offset to where data region begins
101   int        _frame_size;                        // size of stack frame
102 
103   address    _code_begin;
104   address    _code_end;
105   address    _content_begin;                     // address to where content region begins (this includes consts, insts, stubs)
106                                                  // address    _content_end - not required, for all CodeBlobs _code_end == _content_end for now
107   address    _data_end;
108   address    _relocation_begin;
109   address    _relocation_end;
110 
111   ImmutableOopMapSet* _oop_maps;                 // OopMap for this CodeBlob
112   bool                _caller_must_gc_arguments;
113   CodeStrings         _strings;
114   const char*         _name;
115   S390_ONLY(int       _ctable_offset;)
116 
117   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
118   CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
119 public:
120   // Returns the space needed for CodeBlob
121   static unsigned int allocation_size(CodeBuffer* cb, int header_size);
122   static unsigned int align_code_offset(int offset);
123 
124   // Deletion
125   virtual void flush();
126 
127   // Typing
128   virtual bool is_buffer_blob() const                 { return false; }
129   virtual bool is_nmethod() const                     { return false; }
130   virtual bool is_runtime_stub() const                { return false; }
131   virtual bool is_deoptimization_stub() const         { return false; }
132   virtual bool is_uncommon_trap_stub() const          { return false; }
133   virtual bool is_exception_stub() const              { return false; }
134   virtual bool is_safepoint_stub() const              { return false; }
135   virtual bool is_adapter_blob() const                { return false; }
136   virtual bool is_vtable_blob() const                 { return false; }
137   virtual bool is_method_handles_adapter_blob() const { return false; }
138   virtual bool is_aot() const                         { return false; }
139   virtual bool is_compiled() const                    { return false; }
140 
141   inline bool is_compiled_by_c1() const    { return _type == compiler_c1; };
142   inline bool is_compiled_by_c2() const    { return _type == compiler_c2; };
143   inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
144   const char* compiler_name() const;
145 
146   // Casting
147   nmethod* as_nmethod_or_null()                { return is_nmethod() ? (nmethod*) this : NULL; }
148   nmethod* as_nmethod()                        { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
149   CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
150   CompiledMethod* as_compiled_method()         { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
151   CodeBlob* as_codeblob_or_null() const        { return (CodeBlob*) this; }
152 
153   // Boundaries
154   address header_begin() const        { return (address) this; }
155   relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
156   relocInfo* relocation_end() const   { return (relocInfo*) _relocation_end; }
157   address content_begin() const       { return _content_begin; }
158   address content_end() const         { return _code_end; } // _code_end == _content_end is true for all types of blobs for now, it is also checked in the constructor
159   address code_begin() const          { return _code_begin;    }
160   address code_end() const            { return _code_end; }
161   address data_end() const            { return _data_end;      }
162 
163   // This field holds the beginning of the const section in the old code buffer.
164   // It is needed to fix relocations of pc-relative loads when resizing the
165   // the constant pool or moving it.
166   S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
167   void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
168 
169   // Sizes
170   int size() const                               { return _size; }
171   int header_size() const                        { return _header_size; }
172   int relocation_size() const                    { return (address) relocation_end() - (address) relocation_begin(); }
173   int content_size() const                       { return           content_end()    -           content_begin();    }
174   int code_size() const                          { return           code_end()       -           code_begin();       }
175   // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
176   void adjust_size(size_t used) {
177     _size = (int)used;
178     _data_offset = (int)used;
179     _code_end = (address)this + used;
180     _data_end = (address)this + used;
181   }
182 
183   // Containment
184   bool blob_contains(address addr) const         { return header_begin()       <= addr && addr < data_end();       }
185   bool code_contains(address addr) const         { return code_begin()         <= addr && addr < code_end();       }
186   bool contains(address addr) const              { return content_begin()      <= addr && addr < content_end();    }
187   bool is_frame_complete_at(address addr) const  { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
188                                                           code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
189   int frame_complete_offset() const              { return _frame_complete_offset; }
190 
191   // CodeCache support: really only used by the nmethods, but in order to get
192   // asserts and certain bookkeeping to work in the CodeCache they are defined
193   // virtual here.
194   virtual bool is_zombie() const                 { return false; }
195   virtual bool is_locked_by_vm() const           { return false; }
196 
197   virtual bool is_unloaded() const               { return false; }
198   virtual bool is_not_entrant() const            { return false; }
199 
200   // GC support
201   virtual bool is_alive() const                  = 0;
202 
203   // OopMap for frame
204   ImmutableOopMapSet* oop_maps() const           { return _oop_maps; }
205   void set_oop_maps(OopMapSet* p);
206   const ImmutableOopMap* oop_map_for_return_address(address return_address);
207   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) = 0;
208 
209   // Frame support
210   int  frame_size() const                        { return _frame_size; }
211   void set_frame_size(int size)                  { _frame_size = size; }
212 
213   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
214   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
215 
216   // Naming
217   const char* name() const                       { return _name; }
218   void set_name(const char* name)                { _name = name; }
219 
220   // Debugging
221   virtual void verify() = 0;
222   virtual void print() const                     { print_on(tty); };
223   virtual void print_on(outputStream* st) const;
224   virtual void print_value_on(outputStream* st) const;
225   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
226   void print_code();
227 
228   // Print the comment associated with offset on stream, if there is one
229   virtual void print_block_comment(outputStream* stream, address block_begin) const {
230     intptr_t offset = (intptr_t)(block_begin - code_begin());
231     _strings.print_block_comment(stream, offset);
232   }
233 
234   // Transfer ownership of comments to this CodeBlob
235   void set_strings(CodeStrings& strings) {
236     assert(!is_aot(), "invalid on aot");
237     _strings.assign(strings);
238   }
239 
240   static ByteSize name_field_offset() {
241     return byte_offset_of(CodeBlob, _name);
242   }
243 
244   static ByteSize oop_maps_field_offset() {
245     return byte_offset_of(CodeBlob, _oop_maps);
246   }
247 };
248 
249 class CodeBlobLayout : public StackObj {
250 private:
251   int _size;
252   int _header_size;
253   int _relocation_size;
254   int _content_offset;
255   int _code_offset;
256   int _data_offset;
257   address _code_begin;
258   address _code_end;
259   address _content_begin;
260   address _content_end;
261   address _data_end;
262   address _relocation_begin;
263   address _relocation_end;
264 
265 public:
266   CodeBlobLayout(address code_begin, address code_end, address content_begin, address content_end, address data_end, address relocation_begin, address relocation_end) :
267     _size(0),
268     _header_size(0),
269     _relocation_size(0),
270     _content_offset(0),
271     _code_offset(0),
272     _data_offset(0),
273     _code_begin(code_begin),
274     _code_end(code_end),
275     _content_begin(content_begin),
276     _content_end(content_end),
277     _data_end(data_end),
278     _relocation_begin(relocation_begin),
279     _relocation_end(relocation_end)
280   {
281   }
282 
283   CodeBlobLayout(const address start, int size, int header_size, int relocation_size, int data_offset) :
284     _size(size),
285     _header_size(header_size),
286     _relocation_size(relocation_size),
287     _content_offset(CodeBlob::align_code_offset(_header_size + _relocation_size)),
288     _code_offset(_content_offset),
289     _data_offset(data_offset)
290   {
291     assert(is_aligned(_relocation_size, oopSize), "unaligned size");
292 
293     _code_begin = (address) start + _code_offset;
294     _code_end = (address) start + _data_offset;
295 
296     _content_begin = (address) start + _content_offset;
297     _content_end = (address) start + _data_offset;
298 
299     _data_end = (address) start + _size;
300     _relocation_begin = (address) start + _header_size;
301     _relocation_end = _relocation_begin + _relocation_size;
302   }
303 
304   CodeBlobLayout(const address start, int size, int header_size, const CodeBuffer* cb) :
305     _size(size),
306     _header_size(header_size),
307     _relocation_size(align_up(cb->total_relocation_size(), oopSize)),
308     _content_offset(CodeBlob::align_code_offset(_header_size + _relocation_size)),
309     _code_offset(_content_offset + cb->total_offset_of(cb->insts())),
310     _data_offset(_content_offset + align_up(cb->total_content_size(), oopSize))
311   {
312     assert(is_aligned(_relocation_size, oopSize), "unaligned size");
313 
314     _code_begin = (address) start + _code_offset;
315     _code_end = (address) start + _data_offset;
316 
317     _content_begin = (address) start + _content_offset;
318     _content_end = (address) start + _data_offset;
319 
320     _data_end = (address) start + _size;
321     _relocation_begin = (address) start + _header_size;
322     _relocation_end = _relocation_begin + _relocation_size;
323   }
324 
325   int size() const { return _size; }
326   int header_size() const { return _header_size; }
327   int relocation_size() const { return _relocation_size; }
328   int content_offset() const { return _content_offset; }
329   int code_offset() const { return _code_offset; }
330   int data_offset() const { return _data_offset; }
331   address code_begin() const { return _code_begin; }
332   address code_end() const { return _code_end; }
333   address data_end() const { return _data_end; }
334   address relocation_begin() const { return _relocation_begin; }
335   address relocation_end() const { return _relocation_end; }
336   address content_begin() const { return _content_begin; }
337   address content_end() const { return _content_end; }
338 };
339 
340 
341 class RuntimeBlob : public CodeBlob {
342   friend class VMStructs;
343  public:
344 
345   // Creation
346   // a) simple CodeBlob
347   // frame_complete is the offset from the beginning of the instructions
348   // to where the frame setup (from stackwalk viewpoint) is complete.
349   RuntimeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size);
350 
351   // b) full CodeBlob
352   RuntimeBlob(
353     const char* name,
354     CodeBuffer* cb,
355     int         header_size,
356     int         size,
357     int         frame_complete,
358     int         frame_size,
359     OopMapSet*  oop_maps,
360     bool        caller_must_gc_arguments = false
361   );
362 
363   // GC support
364   virtual bool is_alive() const                  = 0;
365 
366   void verify();
367 
368   // OopMap for frame
369   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { ShouldNotReachHere(); }
370 
371   // Debugging
372   void print() const                             { print_on(tty); }
373   virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }
374   virtual void print_value_on(outputStream* st) const { CodeBlob::print_value_on(st); }
375 
376   // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
377   static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
378 };
379 
380 class WhiteBox;
381 //----------------------------------------------------------------------------------------------------
382 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
383 
384 class BufferBlob: public RuntimeBlob {
385   friend class VMStructs;
386   friend class AdapterBlob;
387   friend class VtableBlob;
388   friend class MethodHandlesAdapterBlob;
389   friend class WhiteBox;
390 
391  private:
392   // Creation support
393   BufferBlob(const char* name, int size);
394   BufferBlob(const char* name, int size, CodeBuffer* cb);
395 
396   // This ordinary operator delete is needed even though not used, so the
397   // below two-argument operator delete will be treated as a placement
398   // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
399   void operator delete(void* p);
400   void* operator new(size_t s, unsigned size) throw();
401 
402  public:
403   // Creation
404   static BufferBlob* create(const char* name, int buffer_size);
405   static BufferBlob* create(const char* name, CodeBuffer* cb);
406 
407   static void free(BufferBlob* buf);
408 
409   // Typing
410   virtual bool is_buffer_blob() const            { return true; }
411 
412   // GC/Verification support
413   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
414   bool is_alive() const                          { return true; }
415 
416   void verify();
417   void print_on(outputStream* st) const;
418   void print_value_on(outputStream* st) const;
419 };
420 
421 
422 //----------------------------------------------------------------------------------------------------
423 // AdapterBlob: used to hold C2I/I2C adapters
424 
425 class AdapterBlob: public BufferBlob {
426 private:
427   AdapterBlob(int size, CodeBuffer* cb);
428 
429 public:
430   // Creation
431   static AdapterBlob* create(CodeBuffer* cb);
432 
433   // Typing
434   virtual bool is_adapter_blob() const { return true; }
435 };
436 
437 //---------------------------------------------------------------------------------------------------
438 class VtableBlob: public BufferBlob {
439 private:
440   VtableBlob(const char*, int);
441 
442 public:
443   // Creation
444   static VtableBlob* create(const char* name, int buffer_size);
445 
446   // Typing
447   virtual bool is_vtable_blob() const { return true; }
448 };
449 
450 //----------------------------------------------------------------------------------------------------
451 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
452 
453 class MethodHandlesAdapterBlob: public BufferBlob {
454 private:
455   MethodHandlesAdapterBlob(int size)                 : BufferBlob("MethodHandles adapters", size) {}
456 
457 public:
458   // Creation
459   static MethodHandlesAdapterBlob* create(int buffer_size);
460 
461   // Typing
462   virtual bool is_method_handles_adapter_blob() const { return true; }
463 };
464 
465 
466 //----------------------------------------------------------------------------------------------------
467 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
468 
469 class RuntimeStub: public RuntimeBlob {
470   friend class VMStructs;
471  private:
472   // Creation support
473   RuntimeStub(
474     const char* name,
475     CodeBuffer* cb,
476     int         size,
477     int         frame_complete,
478     int         frame_size,
479     OopMapSet*  oop_maps,
480     bool        caller_must_gc_arguments
481   );
482 
483   // This ordinary operator delete is needed even though not used, so the
484   // below two-argument operator delete will be treated as a placement
485   // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
486   void operator delete(void* p);
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     int         frame_complete,
495     int         frame_size,
496     OopMapSet*  oop_maps,
497     bool        caller_must_gc_arguments
498   );
499 
500   // Typing
501   bool is_runtime_stub() const                   { return true; }
502 
503   address entry_point() const                    { return code_begin(); }
504 
505   // GC/Verification support
506   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
507   bool is_alive() const                          { return true; }
508 
509   void verify();
510   void print_on(outputStream* st) const;
511   void print_value_on(outputStream* st) const;
512 };
513 
514 
515 //----------------------------------------------------------------------------------------------------
516 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
517 
518 class SingletonBlob: public RuntimeBlob {
519   friend class VMStructs;
520 
521  protected:
522   // This ordinary operator delete is needed even though not used, so the
523   // below two-argument operator delete will be treated as a placement
524   // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
525   void operator delete(void* p);
526   void* operator new(size_t s, unsigned size) throw();
527 
528  public:
529    SingletonBlob(
530      const char* name,
531      CodeBuffer* cb,
532      int         header_size,
533      int         size,
534      int         frame_size,
535      OopMapSet*  oop_maps
536    )
537    : RuntimeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
538   {};
539 
540   address entry_point()                          { return code_begin(); }
541 
542   bool is_alive() const                          { return true; }
543 
544   // GC/Verification support
545   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
546   void verify(); // does nothing
547   void print_on(outputStream* st) const;
548   void print_value_on(outputStream* st) const;
549 };
550 
551 
552 //----------------------------------------------------------------------------------------------------
553 // DeoptimizationBlob
554 
555 class DeoptimizationBlob: public SingletonBlob {
556   friend class VMStructs;
557   friend class JVMCIVMStructs;
558  private:
559   int _unpack_offset;
560   int _unpack_with_exception;
561   int _unpack_with_reexecution;
562 
563   int _unpack_with_exception_in_tls;
564 
565 #if INCLUDE_JVMCI
566   // Offsets when JVMCI calls uncommon_trap.
567   int _uncommon_trap_offset;
568   int _implicit_exception_uncommon_trap_offset;
569 #endif
570 
571   // Creation support
572   DeoptimizationBlob(
573     CodeBuffer* cb,
574     int         size,
575     OopMapSet*  oop_maps,
576     int         unpack_offset,
577     int         unpack_with_exception_offset,
578     int         unpack_with_reexecution_offset,
579     int         frame_size
580   );
581 
582  public:
583   // Creation
584   static DeoptimizationBlob* create(
585     CodeBuffer* cb,
586     OopMapSet*  oop_maps,
587     int         unpack_offset,
588     int         unpack_with_exception_offset,
589     int         unpack_with_reexecution_offset,
590     int         frame_size
591   );
592 
593   // Typing
594   bool is_deoptimization_stub() const { return true; }
595   bool exception_address_is_unpack_entry(address pc) const {
596     address unpack_pc = unpack();
597     return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc);
598   }
599 
600   // GC for args
601   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
602 
603   // Printing
604   void print_value_on(outputStream* st) const;
605 
606   address unpack() const                         { return code_begin() + _unpack_offset;           }
607   address unpack_with_exception() const          { return code_begin() + _unpack_with_exception;   }
608   address unpack_with_reexecution() const        { return code_begin() + _unpack_with_reexecution; }
609 
610   // Alternate entry point for C1 where the exception and issuing pc
611   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
612   // instead of being in registers.  This is needed because C1 doesn't
613   // model exception paths in a way that keeps these registers free so
614   // there may be live values in those registers during deopt.
615   void set_unpack_with_exception_in_tls_offset(int offset) {
616     _unpack_with_exception_in_tls = offset;
617     assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
618   }
619   address unpack_with_exception_in_tls() const   { return code_begin() + _unpack_with_exception_in_tls; }
620 
621 #if INCLUDE_JVMCI
622   // Offsets when JVMCI calls uncommon_trap.
623   void set_uncommon_trap_offset(int offset) {
624     _uncommon_trap_offset = offset;
625     assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob");
626   }
627   address uncommon_trap() const                  { return code_begin() + _uncommon_trap_offset; }
628 
629   void set_implicit_exception_uncommon_trap_offset(int offset) {
630     _implicit_exception_uncommon_trap_offset = offset;
631     assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob");
632   }
633   address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; }
634 #endif // INCLUDE_JVMCI
635 };
636 
637 
638 //----------------------------------------------------------------------------------------------------
639 // UncommonTrapBlob (currently only used by Compiler 2)
640 
641 #ifdef COMPILER2
642 
643 class UncommonTrapBlob: public SingletonBlob {
644   friend class VMStructs;
645  private:
646   // Creation support
647   UncommonTrapBlob(
648     CodeBuffer* cb,
649     int         size,
650     OopMapSet*  oop_maps,
651     int         frame_size
652   );
653 
654  public:
655   // Creation
656   static UncommonTrapBlob* create(
657     CodeBuffer* cb,
658     OopMapSet*  oop_maps,
659     int         frame_size
660   );
661 
662   // GC for args
663   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
664 
665   // Typing
666   bool is_uncommon_trap_stub() const             { return true; }
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   // GC for args
693   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
694 
695   // Typing
696   bool is_exception_stub() const                 { return true; }
697 };
698 #endif // COMPILER2
699 
700 
701 //----------------------------------------------------------------------------------------------------
702 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
703 
704 class SafepointBlob: public SingletonBlob {
705   friend class VMStructs;
706  private:
707   // Creation support
708   SafepointBlob(
709     CodeBuffer* cb,
710     int         size,
711     OopMapSet*  oop_maps,
712     int         frame_size
713   );
714 
715  public:
716   // Creation
717   static SafepointBlob* create(
718     CodeBuffer* cb,
719     OopMapSet*  oop_maps,
720     int         frame_size
721   );
722 
723   // GC for args
724   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
725 
726   // Typing
727   bool is_safepoint_stub() const                 { return true; }
728 };
729 
730 #endif // SHARE_VM_CODE_CODEBLOB_HPP