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