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