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