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