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