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.
CodeBlob()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
is_buffer_blob() const133   virtual bool is_buffer_blob() const                 { return false; }
is_nmethod() const134   virtual bool is_nmethod() const                     { return false; }
is_runtime_stub() const135   virtual bool is_runtime_stub() const                { return false; }
is_deoptimization_stub() const136   virtual bool is_deoptimization_stub() const         { return false; }
is_uncommon_trap_stub() const137   virtual bool is_uncommon_trap_stub() const          { return false; }
is_exception_stub() const138   virtual bool is_exception_stub() const              { return false; }
is_safepoint_stub() const139   virtual bool is_safepoint_stub() const              { return false; }
is_adapter_blob() const140   virtual bool is_adapter_blob() const                { return false; }
is_vtable_blob() const141   virtual bool is_vtable_blob() const                 { return false; }
is_method_handles_adapter_blob() const142   virtual bool is_method_handles_adapter_blob() const { return false; }
is_aot() const143   virtual bool is_aot() const                         { return false; }
is_compiled() const144   virtual bool is_compiled() const                    { return false; }
145 
is_compiled_by_c1() const146   inline bool is_compiled_by_c1() const    { return _type == compiler_c1; };
is_compiled_by_c2() const147   inline bool is_compiled_by_c2() const    { return _type == compiler_c2; };
is_compiled_by_jvmci() const148   inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
149   const char* compiler_name() const;
150 
151   // Casting
as_nmethod_or_null()152   nmethod* as_nmethod_or_null()                { return is_nmethod() ? (nmethod*) this : NULL; }
as_nmethod()153   nmethod* as_nmethod()                        { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
as_compiled_method_or_null()154   CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
as_compiled_method()155   CompiledMethod* as_compiled_method()         { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
as_codeblob_or_null() const156   CodeBlob* as_codeblob_or_null() const        { return (CodeBlob*) this; }
157 
158   // Boundaries
header_begin() const159   address header_begin() const        { return (address) this; }
relocation_begin() const160   relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
relocation_end() const161   relocInfo* relocation_end() const   { return (relocInfo*) _relocation_end; }
content_begin() const162   address content_begin() const       { return _content_begin; }
content_end() const163   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
code_begin() const164   address code_begin() const          { return _code_begin;    }
code_end() const165   address code_end() const            { return _code_end; }
data_end() const166   address data_end() const            { return _data_end;      }
167 
168   // This field holds the beginning of the const section in the old code buffer.
169   // It is needed to fix relocations of pc-relative loads when resizing the
170   // the constant pool or moving it.
S390_ONLY(address ctable_begin ()const{ return header_begin() + _ctable_offset; })171   S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
172   void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
173 
174   // Sizes
size() const175   int size() const                               { return _size; }
header_size() const176   int header_size() const                        { return _header_size; }
relocation_size() const177   int relocation_size() const                    { return (address) relocation_end() - (address) relocation_begin(); }
content_size() const178   int content_size() const                       { return           content_end()    -           content_begin();    }
code_size() const179   int code_size() const                          { return           code_end()       -           code_begin();       }
180   // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
adjust_size(size_t used)181   void adjust_size(size_t used) {
182     _size = (int)used;
183     _data_offset = (int)used;
184     _code_end = (address)this + used;
185     _data_end = (address)this + used;
186   }
187 
188   // Containment
blob_contains(address addr) const189   bool blob_contains(address addr) const         { return header_begin()       <= addr && addr < data_end();       }
code_contains(address addr) const190   bool code_contains(address addr) const         { return code_begin()         <= addr && addr < code_end();       }
contains(address addr) const191   bool contains(address addr) const              { return content_begin()      <= addr && addr < content_end();    }
is_frame_complete_at(address addr) const192   bool is_frame_complete_at(address addr) const  { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
193                                                           code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
frame_complete_offset() const194   int frame_complete_offset() const              { return _frame_complete_offset; }
195 
196   // CodeCache support: really only used by the nmethods, but in order to get
197   // asserts and certain bookkeeping to work in the CodeCache they are defined
198   // virtual here.
is_zombie() const199   virtual bool is_zombie() const                 { return false; }
is_locked_by_vm() const200   virtual bool is_locked_by_vm() const           { return false; }
201 
is_unloaded() const202   virtual bool is_unloaded() const               { return false; }
is_not_entrant() const203   virtual bool is_not_entrant() const            { return false; }
204 
205   // GC support
206   virtual bool is_alive() const                  = 0;
207 
208   // OopMap for frame
oop_maps() const209   ImmutableOopMapSet* oop_maps() const           { return _oop_maps; }
210   void set_oop_maps(OopMapSet* p);
211   const ImmutableOopMap* oop_map_for_return_address(address return_address);
212   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f) = 0;
213 
214   // Frame support. Sizes are in word units.
frame_size() const215   int  frame_size() const                        { return _frame_size; }
set_frame_size(int size)216   void set_frame_size(int size)                  { _frame_size = size; }
217 
218   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
caller_must_gc_arguments(JavaThread * thread) const219   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
220 
221   // Naming
name() const222   const char* name() const                       { return _name; }
set_name(const char * name)223   void set_name(const char* name)                { _name = name; }
224 
225   // Debugging
226   virtual void verify() = 0;
227   virtual void print() const;
228   virtual void print_on(outputStream* st) const;
229   virtual void print_value_on(outputStream* st) const;
230   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
231   void print_code();
232 
has_block_comment(address block_begin) const233   bool has_block_comment(address block_begin) const {
234     intptr_t offset = (intptr_t)(block_begin - code_begin());
235     return _strings.has_block_comment(offset);
236   }
237   // Print the comment associated with offset on stream, if there is one
print_block_comment(outputStream * stream,address block_begin) const238   virtual void print_block_comment(outputStream* stream, address block_begin) const {
239     intptr_t offset = (intptr_t)(block_begin - code_begin());
240     _strings.print_block_comment(stream, offset);
241   }
242 
243   // Transfer ownership of comments to this CodeBlob
set_strings(CodeStrings & strings)244   void set_strings(CodeStrings& strings) {
245     assert(!is_aot(), "invalid on aot");
246     _strings.assign(strings);
247   }
248 
name_field_offset()249   static ByteSize name_field_offset() {
250     return byte_offset_of(CodeBlob, _name);
251   }
252 
oop_maps_field_offset()253   static ByteSize oop_maps_field_offset() {
254     return byte_offset_of(CodeBlob, _oop_maps);
255   }
256 };
257 
258 class CodeBlobLayout : public StackObj {
259 private:
260   int _size;
261   int _header_size;
262   int _relocation_size;
263   int _content_offset;
264   int _code_offset;
265   int _data_offset;
266   address _code_begin;
267   address _code_end;
268   address _content_begin;
269   address _content_end;
270   address _data_end;
271   address _relocation_begin;
272   address _relocation_end;
273 
274 public:
CodeBlobLayout(address code_begin,address code_end,address content_begin,address content_end,address data_end,address relocation_begin,address relocation_end)275   CodeBlobLayout(address code_begin, address code_end, address content_begin, address content_end, address data_end, address relocation_begin, address relocation_end) :
276     _size(0),
277     _header_size(0),
278     _relocation_size(0),
279     _content_offset(0),
280     _code_offset(0),
281     _data_offset(0),
282     _code_begin(code_begin),
283     _code_end(code_end),
284     _content_begin(content_begin),
285     _content_end(content_end),
286     _data_end(data_end),
287     _relocation_begin(relocation_begin),
288     _relocation_end(relocation_end)
289   {
290   }
291 
CodeBlobLayout(const address start,int size,int header_size,int relocation_size,int data_offset)292   CodeBlobLayout(const address start, int size, int header_size, int relocation_size, int data_offset) :
293     _size(size),
294     _header_size(header_size),
295     _relocation_size(relocation_size),
296     _content_offset(CodeBlob::align_code_offset(_header_size + _relocation_size)),
297     _code_offset(_content_offset),
298     _data_offset(data_offset)
299   {
300     assert(is_aligned(_relocation_size, oopSize), "unaligned size");
301 
302     _code_begin = (address) start + _code_offset;
303     _code_end = (address) start + _data_offset;
304 
305     _content_begin = (address) start + _content_offset;
306     _content_end = (address) start + _data_offset;
307 
308     _data_end = (address) start + _size;
309     _relocation_begin = (address) start + _header_size;
310     _relocation_end = _relocation_begin + _relocation_size;
311   }
312 
CodeBlobLayout(const address start,int size,int header_size,const CodeBuffer * cb)313   CodeBlobLayout(const address start, int size, int header_size, const CodeBuffer* cb) :
314     _size(size),
315     _header_size(header_size),
316     _relocation_size(align_up(cb->total_relocation_size(), oopSize)),
317     _content_offset(CodeBlob::align_code_offset(_header_size + _relocation_size)),
318     _code_offset(_content_offset + cb->total_offset_of(cb->insts())),
319     _data_offset(_content_offset + align_up(cb->total_content_size(), oopSize))
320   {
321     assert(is_aligned(_relocation_size, oopSize), "unaligned size");
322 
323     _code_begin = (address) start + _code_offset;
324     _code_end = (address) start + _data_offset;
325 
326     _content_begin = (address) start + _content_offset;
327     _content_end = (address) start + _data_offset;
328 
329     _data_end = (address) start + _size;
330     _relocation_begin = (address) start + _header_size;
331     _relocation_end = _relocation_begin + _relocation_size;
332   }
333 
size() const334   int size() const { return _size; }
header_size() const335   int header_size() const { return _header_size; }
relocation_size() const336   int relocation_size() const { return _relocation_size; }
content_offset() const337   int content_offset() const { return _content_offset; }
code_offset() const338   int code_offset() const { return _code_offset; }
data_offset() const339   int data_offset() const { return _data_offset; }
code_begin() const340   address code_begin() const { return _code_begin; }
code_end() const341   address code_end() const { return _code_end; }
data_end() const342   address data_end() const { return _data_end; }
relocation_begin() const343   address relocation_begin() const { return _relocation_begin; }
relocation_end() const344   address relocation_end() const { return _relocation_end; }
content_begin() const345   address content_begin() const { return _content_begin; }
content_end() const346   address content_end() const { return _content_end; }
347 };
348 
349 
350 class RuntimeBlob : public CodeBlob {
351   friend class VMStructs;
352  public:
353 
354   // Creation
355   // a) simple CodeBlob
356   // frame_complete is the offset from the beginning of the instructions
357   // to where the frame setup (from stackwalk viewpoint) is complete.
358   RuntimeBlob(const char* name, int header_size, int size, int frame_complete, int locs_size);
359 
360   // b) full CodeBlob
361   RuntimeBlob(
362     const char* name,
363     CodeBuffer* cb,
364     int         header_size,
365     int         size,
366     int         frame_complete,
367     int         frame_size,
368     OopMapSet*  oop_maps,
369     bool        caller_must_gc_arguments = false
370   );
371 
372   // GC support
373   virtual bool is_alive() const                  = 0;
374 
375   void verify();
376 
377   // OopMap for frame
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)378   virtual void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { ShouldNotReachHere(); }
379 
380   // Debugging
print_on(outputStream * st) const381   virtual void print_on(outputStream* st) const { CodeBlob::print_on(st); }
print_value_on(outputStream * st) const382   virtual void print_value_on(outputStream* st) const { CodeBlob::print_value_on(st); }
383 
384   // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
385   static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
386 };
387 
388 class WhiteBox;
389 //----------------------------------------------------------------------------------------------------
390 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
391 
392 class BufferBlob: public RuntimeBlob {
393   friend class VMStructs;
394   friend class AdapterBlob;
395   friend class VtableBlob;
396   friend class MethodHandlesAdapterBlob;
397   friend class WhiteBox;
398 
399  private:
400   // Creation support
401   BufferBlob(const char* name, int size);
402   BufferBlob(const char* name, int size, CodeBuffer* cb);
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
is_buffer_blob() const418   virtual bool is_buffer_blob() const            { return true; }
419 
420   // GC/Verification support
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)421   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
is_alive() const422   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);
436 
437 public:
438   // Creation
439   static AdapterBlob* create(CodeBuffer* cb);
440 
441   // Typing
is_adapter_blob() const442   virtual bool is_adapter_blob() const { return true; }
443 };
444 
445 //---------------------------------------------------------------------------------------------------
446 class VtableBlob: public BufferBlob {
447 private:
448   VtableBlob(const char*, int);
449 
450 public:
451   // Creation
452   static VtableBlob* create(const char* name, int buffer_size);
453 
454   // Typing
is_vtable_blob() const455   virtual bool is_vtable_blob() const { return true; }
456 };
457 
458 //----------------------------------------------------------------------------------------------------
459 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
460 
461 class MethodHandlesAdapterBlob: public BufferBlob {
462 private:
MethodHandlesAdapterBlob(int size)463   MethodHandlesAdapterBlob(int size)                 : BufferBlob("MethodHandles adapters", size) {}
464 
465 public:
466   // Creation
467   static MethodHandlesAdapterBlob* create(int buffer_size);
468 
469   // Typing
is_method_handles_adapter_blob() const470   virtual bool is_method_handles_adapter_blob() const { return true; }
471 };
472 
473 
474 //----------------------------------------------------------------------------------------------------
475 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
476 
477 class RuntimeStub: public RuntimeBlob {
478   friend class VMStructs;
479  private:
480   // Creation support
481   RuntimeStub(
482     const char* name,
483     CodeBuffer* cb,
484     int         size,
485     int         frame_complete,
486     int         frame_size,
487     OopMapSet*  oop_maps,
488     bool        caller_must_gc_arguments
489   );
490 
491   // This ordinary operator delete is needed even though not used, so the
492   // below two-argument operator delete will be treated as a placement
493   // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
494   void operator delete(void* p);
495   void* operator new(size_t s, unsigned size) throw();
496 
497  public:
498   // Creation
499   static RuntimeStub* new_runtime_stub(
500     const char* stub_name,
501     CodeBuffer* cb,
502     int         frame_complete,
503     int         frame_size,
504     OopMapSet*  oop_maps,
505     bool        caller_must_gc_arguments
506   );
507 
508   // Typing
is_runtime_stub() const509   bool is_runtime_stub() const                   { return true; }
510 
entry_point() const511   address entry_point() const                    { return code_begin(); }
512 
513   // GC/Verification support
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)514   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
is_alive() const515   bool is_alive() const                          { return true; }
516 
517   void verify();
518   void print_on(outputStream* st) const;
519   void print_value_on(outputStream* st) const;
520 };
521 
522 
523 //----------------------------------------------------------------------------------------------------
524 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
525 
526 class SingletonBlob: public RuntimeBlob {
527   friend class VMStructs;
528 
529  protected:
530   // This ordinary operator delete is needed even though not used, so the
531   // below two-argument operator delete will be treated as a placement
532   // delete rather than an ordinary sized delete; see C++14 3.7.4.2/p2.
533   void operator delete(void* p);
534   void* operator new(size_t s, unsigned size) throw();
535 
536  public:
SingletonBlob(const char * name,CodeBuffer * cb,int header_size,int size,int frame_size,OopMapSet * oop_maps)537    SingletonBlob(
538      const char* name,
539      CodeBuffer* cb,
540      int         header_size,
541      int         size,
542      int         frame_size,
543      OopMapSet*  oop_maps
544    )
545    : RuntimeBlob(name, cb, header_size, size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
546   {};
547 
entry_point()548   address entry_point()                          { return code_begin(); }
549 
is_alive() const550   bool is_alive() const                          { return true; }
551 
552   // GC/Verification support
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)553   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
554   void verify(); // does nothing
555   void print_on(outputStream* st) const;
556   void print_value_on(outputStream* st) const;
557 };
558 
559 
560 //----------------------------------------------------------------------------------------------------
561 // DeoptimizationBlob
562 
563 class DeoptimizationBlob: public SingletonBlob {
564   friend class VMStructs;
565   friend class JVMCIVMStructs;
566  private:
567   int _unpack_offset;
568   int _unpack_with_exception;
569   int _unpack_with_reexecution;
570 
571   int _unpack_with_exception_in_tls;
572 
573 #if INCLUDE_JVMCI
574   // Offsets when JVMCI calls uncommon_trap.
575   int _uncommon_trap_offset;
576   int _implicit_exception_uncommon_trap_offset;
577 #endif
578 
579   // Creation support
580   DeoptimizationBlob(
581     CodeBuffer* cb,
582     int         size,
583     OopMapSet*  oop_maps,
584     int         unpack_offset,
585     int         unpack_with_exception_offset,
586     int         unpack_with_reexecution_offset,
587     int         frame_size
588   );
589 
590  public:
591   // Creation
592   static DeoptimizationBlob* create(
593     CodeBuffer* cb,
594     OopMapSet*  oop_maps,
595     int         unpack_offset,
596     int         unpack_with_exception_offset,
597     int         unpack_with_reexecution_offset,
598     int         frame_size
599   );
600 
601   // Typing
is_deoptimization_stub() const602   bool is_deoptimization_stub() const { return true; }
exception_address_is_unpack_entry(address pc) const603   bool exception_address_is_unpack_entry(address pc) const {
604     address unpack_pc = unpack();
605     return (pc == unpack_pc || (pc + frame::pc_return_offset) == unpack_pc);
606   }
607 
608   // GC for args
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)609   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f) { /* Nothing to do */ }
610 
611   // Printing
612   void print_value_on(outputStream* st) const;
613 
unpack() const614   address unpack() const                         { return code_begin() + _unpack_offset;           }
unpack_with_exception() const615   address unpack_with_exception() const          { return code_begin() + _unpack_with_exception;   }
unpack_with_reexecution() const616   address unpack_with_reexecution() const        { return code_begin() + _unpack_with_reexecution; }
617 
618   // Alternate entry point for C1 where the exception and issuing pc
619   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
620   // instead of being in registers.  This is needed because C1 doesn't
621   // model exception paths in a way that keeps these registers free so
622   // there may be live values in those registers during deopt.
set_unpack_with_exception_in_tls_offset(int offset)623   void set_unpack_with_exception_in_tls_offset(int offset) {
624     _unpack_with_exception_in_tls = offset;
625     assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
626   }
unpack_with_exception_in_tls() const627   address unpack_with_exception_in_tls() const   { return code_begin() + _unpack_with_exception_in_tls; }
628 
629 #if INCLUDE_JVMCI
630   // Offsets when JVMCI calls uncommon_trap.
set_uncommon_trap_offset(int offset)631   void set_uncommon_trap_offset(int offset) {
632     _uncommon_trap_offset = offset;
633     assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob");
634   }
uncommon_trap() const635   address uncommon_trap() const                  { return code_begin() + _uncommon_trap_offset; }
636 
set_implicit_exception_uncommon_trap_offset(int offset)637   void set_implicit_exception_uncommon_trap_offset(int offset) {
638     _implicit_exception_uncommon_trap_offset = offset;
639     assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob");
640   }
implicit_exception_uncommon_trap() const641   address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; }
642 #endif // INCLUDE_JVMCI
643 };
644 
645 
646 //----------------------------------------------------------------------------------------------------
647 // UncommonTrapBlob (currently only used by Compiler 2)
648 
649 #ifdef COMPILER2
650 
651 class UncommonTrapBlob: public SingletonBlob {
652   friend class VMStructs;
653  private:
654   // Creation support
655   UncommonTrapBlob(
656     CodeBuffer* cb,
657     int         size,
658     OopMapSet*  oop_maps,
659     int         frame_size
660   );
661 
662  public:
663   // Creation
664   static UncommonTrapBlob* create(
665     CodeBuffer* cb,
666     OopMapSet*  oop_maps,
667     int         frame_size
668   );
669 
670   // GC for args
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)671   void preserve_callee_argument_oops(frame fr, const RegisterMap *reg_map, OopClosure* f)  { /* nothing to do */ }
672 
673   // Typing
is_uncommon_trap_stub() const674   bool is_uncommon_trap_stub() const             { return true; }
675 };
676 
677 
678 //----------------------------------------------------------------------------------------------------
679 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
680 
681 class ExceptionBlob: public SingletonBlob {
682   friend class VMStructs;
683  private:
684   // Creation support
685   ExceptionBlob(
686     CodeBuffer* cb,
687     int         size,
688     OopMapSet*  oop_maps,
689     int         frame_size
690   );
691 
692  public:
693   // Creation
694   static ExceptionBlob* create(
695     CodeBuffer* cb,
696     OopMapSet*  oop_maps,
697     int         frame_size
698   );
699 
700   // GC for args
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)701   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
702 
703   // Typing
is_exception_stub() const704   bool is_exception_stub() const                 { return true; }
705 };
706 #endif // COMPILER2
707 
708 
709 //----------------------------------------------------------------------------------------------------
710 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
711 
712 class SafepointBlob: public SingletonBlob {
713   friend class VMStructs;
714  private:
715   // Creation support
716   SafepointBlob(
717     CodeBuffer* cb,
718     int         size,
719     OopMapSet*  oop_maps,
720     int         frame_size
721   );
722 
723  public:
724   // Creation
725   static SafepointBlob* create(
726     CodeBuffer* cb,
727     OopMapSet*  oop_maps,
728     int         frame_size
729   );
730 
731   // GC for args
preserve_callee_argument_oops(frame fr,const RegisterMap * reg_map,OopClosure * f)732   void preserve_callee_argument_oops(frame fr, const RegisterMap* reg_map, OopClosure* f)  { /* nothing to do */ }
733 
734   // Typing
is_safepoint_stub() const735   bool is_safepoint_stub() const                 { return true; }
736 };
737 
738 #endif // SHARE_CODE_CODEBLOB_HPP
739