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