1 /*
  2  * Copyright (c) 1998, 2025, 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/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 enum class CodeBlobType {
 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 // CodeBlob - superclass for all entries in the CodeCache.
 53 //
 54 // Subtypes are:
 55 //  nmethod              : JIT Compiled Java methods
 56 //  RuntimeBlob          : Non-compiled method code; generated glue code
 57 //   BufferBlob          : Used for non-relocatable code such as interpreter, stubroutines, etc.
 58 //    AdapterBlob        : Used to hold C2I/I2C adapters
 59 //    VtableBlob         : Used for holding vtable chunks
 60 //    MethodHandlesAdapterBlob : Used to hold MethodHandles adapters
 61 //    BufferedInlineTypeBlob   : used for pack/unpack handlers
 62 //   RuntimeStub         : Call to VM runtime methods
 63 //   SingletonBlob       : Super-class for all blobs that exist in only one instance
 64 //    DeoptimizationBlob : Used for deoptimization
 65 //    SafepointBlob      : Used to handle illegal instruction exceptions
 66 //    ExceptionBlob      : Used for stack unrolling
 67 //    UncommonTrapBlob   : Used to handle uncommon traps
 68 //   UpcallStub  : Used for upcalls from native code
 69 //
 70 //
 71 // Layout : continuous in the CodeCache
 72 //   - header
 73 //   - relocation
 74 //   - content space
 75 //     - instruction space
 76 //   - data space
 77 
 78 enum class CodeBlobKind : u1 {
 79   None,
 80   Nmethod,
 81   Buffer,
 82   Adapter,
 83   Vtable,
 84   MHAdapter,
 85   BufferedInlineType,
 86   RuntimeStub,
 87   Deoptimization,
 88   Safepoint,
 89 #ifdef COMPILER2
 90   Exception,
 91   UncommonTrap,
 92 #endif
 93   Upcall,
 94   Number_Of_Kinds
 95 };
 96 
 97 class UpcallStub;      // for as_upcall_stub()
 98 class RuntimeStub;     // for as_runtime_stub()
 99 class JavaFrameAnchor; // for UpcallStub::jfa_for_frame
100 
101 class CodeBlob {
102   friend class VMStructs;
103   friend class JVMCIVMStructs;
104 
105 protected:
106   // order fields from large to small to minimize padding between fields
107   ImmutableOopMapSet* _oop_maps;   // OopMap for this CodeBlob
108   const char*         _name;
109 
110   int      _size;                  // total size of CodeBlob in bytes
111   int      _relocation_size;       // size of relocation (could be bigger than 64Kb)
112   int      _content_offset;        // offset to where content region begins (this includes consts, insts, stubs)
113   int      _code_offset;           // offset to where instructions region begins (this includes insts, stubs)
114 
115   int      _data_offset;           // offset to where data region begins
116   int      _frame_size;            // size of stack frame in words (NOT slots. On x64 these are 64bit words)
117 
118   S390_ONLY(int _ctable_offset;)
119 
120   uint16_t _header_size;           // size of header (depends on subclass)
121   int16_t  _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
122                                    // not finished setting up their frame. Beware of pc's in
123                                    // that range. There is a similar range(s) on returns
124                                    // which we don't detect.
125 
126   CodeBlobKind _kind;              // Kind of this code blob
127 
128   bool _caller_must_gc_arguments;
129 
130 #ifndef PRODUCT
131   AsmRemarks _asm_remarks;
132   DbgStrings _dbg_strings;
133 #endif
134 
135   void print_on_impl(outputStream* st) const;
136   void print_value_on_impl(outputStream* st) const;
137 
138   class Vptr {
139    public:
140     virtual void print_on(const CodeBlob* instance, outputStream* st) const = 0;
141     virtual void print_value_on(const CodeBlob* instance, outputStream* st) const = 0;
142   };
143 
144   const Vptr* vptr() const;
145 
146   CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
147            int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
148 
149   // Simple CodeBlob used for simple BufferBlob.
150   CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
151 
152   void operator delete(void* p) { }
153 
154 public:
155 
156   ~CodeBlob() {
157     assert(_oop_maps == nullptr, "Not flushed");
158   }
159 
160   // Returns the space needed for CodeBlob
161   static unsigned int allocation_size(CodeBuffer* cb, int header_size);
162   static unsigned int align_code_offset(int offset);
163 
164   // Deletion
165   void purge();
166 
167   // Typing
168   bool is_nmethod() const                     { return _kind == CodeBlobKind::Nmethod; }
169   bool is_buffer_blob() const                 { return _kind == CodeBlobKind::Buffer; }
170   bool is_runtime_stub() const                { return _kind == CodeBlobKind::RuntimeStub; }
171   bool is_deoptimization_stub() const         { return _kind == CodeBlobKind::Deoptimization; }
172 #ifdef COMPILER2
173   bool is_uncommon_trap_stub() const          { return _kind == CodeBlobKind::UncommonTrap; }
174   bool is_exception_stub() const              { return _kind == CodeBlobKind::Exception; }
175 #else
176   bool is_uncommon_trap_stub() const          { return false; }
177   bool is_exception_stub() const              { return false; }
178 #endif
179   bool is_safepoint_stub() const              { return _kind == CodeBlobKind::Safepoint; }
180   bool is_adapter_blob() const                { return _kind == CodeBlobKind::Adapter; }
181   bool is_vtable_blob() const                 { return _kind == CodeBlobKind::Vtable; }
182   bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
183   bool is_buffered_inline_type_blob() const   { return _kind == CodeBlobKind::BufferedInlineType; }
184   bool is_upcall_stub() const                 { return _kind == CodeBlobKind::Upcall; }
185 
186   // Casting
187   nmethod* as_nmethod_or_null() const         { return is_nmethod() ? (nmethod*) this : nullptr; }
188   nmethod* as_nmethod() const                 { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
189   CodeBlob* as_codeblob() const               { return (CodeBlob*) this; }
190   UpcallStub* as_upcall_stub() const          { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
191   RuntimeStub* as_runtime_stub() const        { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
192 
193   // Boundaries
194   address    header_begin() const             { return (address)    this; }
195   address    header_end() const               { return ((address)   this) + _header_size; }
196   relocInfo* relocation_begin() const         { return (relocInfo*) header_end(); }
197   relocInfo* relocation_end() const           { return (relocInfo*)(header_end()   + _relocation_size); }
198   address    content_begin() const            { return (address)    header_begin() + _content_offset; }
199   address    content_end() const              { return (address)    header_begin() + _data_offset; }
200   address    code_begin() const               { return (address)    header_begin() + _code_offset; }
201   // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
202   address    code_end() const                 { return (address)    header_begin() + _data_offset; }
203   address    data_begin() const               { return (address)    header_begin() + _data_offset; }
204   address    data_end() const                 { return (address)    header_begin() + _size; }
205 
206   // Offsets
207   int content_offset() const                  { return _content_offset; }
208   int code_offset() const                     { return _code_offset; }
209   int data_offset() const                     { return _data_offset; }
210 
211   // This field holds the beginning of the const section in the old code buffer.
212   // It is needed to fix relocations of pc-relative loads when resizing the
213   // the constant pool or moving it.
214   S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
215   void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
216 
217   // Sizes
218   int size() const               { return _size; }
219   int header_size() const        { return _header_size; }
220   int relocation_size() const    { return pointer_delta_as_int((address) relocation_end(), (address) relocation_begin()); }
221   int content_size() const       { return pointer_delta_as_int(content_end(), content_begin()); }
222   int code_size() const          { return pointer_delta_as_int(code_end(), code_begin()); }
223 
224   // Only used from CodeCache::free_unused_tail() after the Interpreter blob was trimmed
225   void adjust_size(size_t used) {
226     _size = (int)used;
227     _data_offset = (int)used;
228   }
229 
230   // Containment
231   bool blob_contains(address addr) const         { return header_begin()       <= addr && addr < data_end();       }
232   bool code_contains(address addr) const         { return code_begin()         <= addr && addr < code_end();       }
233   bool contains(address addr) const              { return content_begin()      <= addr && addr < content_end();    }
234   bool is_frame_complete_at(address addr) const  { return _frame_complete_offset != CodeOffsets::frame_never_safe &&
235                                                           code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
236   int frame_complete_offset() const              { return _frame_complete_offset; }
237 
238   // OopMap for frame
239   ImmutableOopMapSet* oop_maps() const           { return _oop_maps; }
240   void set_oop_maps(OopMapSet* p);
241 
242   const ImmutableOopMap* oop_map_for_slot(int slot, address return_address) const;
243   const ImmutableOopMap* oop_map_for_return_address(address return_address) const;
244 
245   // Frame support. Sizes are in word units.
246   int  frame_size() const                        { return _frame_size; }
247   void set_frame_size(int size)                  { _frame_size = size; }
248 
249   // Returns true, if the next frame is responsible for GC'ing oops passed as arguments
250   bool caller_must_gc_arguments(JavaThread* thread) const { return _caller_must_gc_arguments; }
251 
252   // Naming
253   const char* name() const                       { return _name; }
254   void set_name(const char* name)                { _name = name; }
255 
256   // Debugging
257   void verify();
258   void print() const;
259   void print_on(outputStream* st) const;
260   void print_value_on(outputStream* st) const;
261 
262   void dump_for_addr(address addr, outputStream* st, bool verbose) const;
263   void print_code_on(outputStream* st);
264 
265   // Print to stream, any comments associated with offset.
266   void print_block_comment(outputStream* stream, address block_begin) const;
267 
268 #ifndef PRODUCT
269   AsmRemarks &asm_remarks() { return _asm_remarks; }
270   DbgStrings &dbg_strings() { return _dbg_strings; }
271 
272   void use_remarks(AsmRemarks &remarks) { _asm_remarks.share(remarks); }
273   void use_strings(DbgStrings &strings) { _dbg_strings.share(strings); }
274 #endif
275 };
276 
277 //----------------------------------------------------------------------------------------------------
278 // RuntimeBlob: used for non-compiled method code (adapters, stubs, blobs)
279 
280 class RuntimeBlob : public CodeBlob {
281   friend class VMStructs;
282  public:
283 
284   // Creation
285   // a) simple CodeBlob
286   RuntimeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size)
287     : CodeBlob(name, kind, size, header_size)
288   {}
289 
290   // b) full CodeBlob
291   // frame_complete is the offset from the beginning of the instructions
292   // to where the frame setup (from stackwalk viewpoint) is complete.
293   RuntimeBlob(
294     const char* name,
295     CodeBlobKind kind,
296     CodeBuffer* cb,
297     int         size,
298     uint16_t    header_size,
299     int16_t     frame_complete,
300     int         frame_size,
301     OopMapSet*  oop_maps,
302     bool        caller_must_gc_arguments = false
303   );
304 
305   static void free(RuntimeBlob* blob);
306 
307   // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
308   static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
309 
310   class Vptr : public CodeBlob::Vptr {
311   };
312 };
313 
314 class WhiteBox;
315 //----------------------------------------------------------------------------------------------------
316 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
317 
318 class BufferBlob: public RuntimeBlob {
319   friend class VMStructs;
320   friend class AdapterBlob;
321   friend class VtableBlob;
322   friend class MethodHandlesAdapterBlob;
323   friend class BufferedInlineTypeBlob;
324   friend class UpcallStub;
325   friend class WhiteBox;
326 
327  private:
328   // Creation support
329   BufferBlob(const char* name, CodeBlobKind kind, int size);
330   BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size);
331   BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
332 
333   void* operator new(size_t s, unsigned size) throw();
334 
335  public:
336   // Creation
337   static BufferBlob* create(const char* name, uint buffer_size);
338   static BufferBlob* create(const char* name, CodeBuffer* cb);
339 
340   static void free(BufferBlob* buf);
341 
342   void print_on_impl(outputStream* st) const;
343   void print_value_on_impl(outputStream* st) const;
344 
345   class Vptr : public RuntimeBlob::Vptr {
346     void print_on(const CodeBlob* instance, outputStream* st) const override {
347       ((const BufferBlob*)instance)->print_on_impl(st);
348     }
349     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
350       ((const BufferBlob*)instance)->print_value_on_impl(st);
351     }
352   };
353 
354   static const Vptr _vpntr;
355 };
356 
357 
358 //----------------------------------------------------------------------------------------------------
359 // AdapterBlob: used to hold C2I/I2C adapters
360 
361 class AdapterBlob: public BufferBlob {
362 private:
363   AdapterBlob(int size, CodeBuffer* cb, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
364 
365 public:
366   // Creation
367   static AdapterBlob* create(CodeBuffer* cb,
368                              int frame_complete,
369                              int frame_size,
370                              OopMapSet* oop_maps,
371                              bool caller_must_gc_arguments = false);
372 
373   bool caller_must_gc_arguments(JavaThread* thread) const { return true; }
374 };
375 
376 //---------------------------------------------------------------------------------------------------
377 class VtableBlob: public BufferBlob {
378 private:
379   VtableBlob(const char*, int);
380 
381   void* operator new(size_t s, unsigned size) throw();
382 
383 public:
384   // Creation
385   static VtableBlob* create(const char* name, int buffer_size);
386 };
387 
388 //----------------------------------------------------------------------------------------------------
389 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
390 
391 class MethodHandlesAdapterBlob: public BufferBlob {
392 private:
393   MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
394 
395 public:
396   // Creation
397   static MethodHandlesAdapterBlob* create(int buffer_size);
398 };
399 
400 //----------------------------------------------------------------------------------------------------
401 // BufferedInlineTypeBlob : used for pack/unpack handlers
402 
403 class BufferedInlineTypeBlob: public BufferBlob {
404 private:
405   const int _pack_fields_off;
406   const int _pack_fields_jobject_off;
407   const int _unpack_fields_off;
408 
409   BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
410 
411 public:
412   // Creation
413   static BufferedInlineTypeBlob* create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
414 
415   address pack_fields() const { return code_begin() + _pack_fields_off; }
416   address pack_fields_jobject() const { return code_begin() + _pack_fields_jobject_off; }
417   address unpack_fields() const { return code_begin() + _unpack_fields_off; }
418 };
419 
420 //----------------------------------------------------------------------------------------------------
421 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
422 
423 class RuntimeStub: public RuntimeBlob {
424   friend class VMStructs;
425  private:
426   // Creation support
427   RuntimeStub(
428     const char* name,
429     CodeBuffer* cb,
430     int         size,
431     int16_t     frame_complete,
432     int         frame_size,
433     OopMapSet*  oop_maps,
434     bool        caller_must_gc_arguments
435   );
436 
437   void* operator new(size_t s, unsigned size) throw();
438 
439  public:
440   // Creation
441   static RuntimeStub* new_runtime_stub(
442     const char* stub_name,
443     CodeBuffer* cb,
444     int16_t     frame_complete,
445     int         frame_size,
446     OopMapSet*  oop_maps,
447     bool        caller_must_gc_arguments,
448     bool        alloc_fail_is_fatal=true
449   );
450 
451   static void free(RuntimeStub* stub) { RuntimeBlob::free(stub); }
452 
453   address entry_point() const         { return code_begin(); }
454 
455   void print_on_impl(outputStream* st) const;
456   void print_value_on_impl(outputStream* st) const;
457 
458   class Vptr : public RuntimeBlob::Vptr {
459     void print_on(const CodeBlob* instance, outputStream* st) const override {
460       instance->as_runtime_stub()->print_on_impl(st);
461     }
462     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
463       instance->as_runtime_stub()->print_value_on_impl(st);
464     }
465   };
466 
467   static const Vptr _vpntr;
468 };
469 
470 
471 //----------------------------------------------------------------------------------------------------
472 // Super-class for all blobs that exist in only one instance. Implements default behaviour.
473 
474 class SingletonBlob: public RuntimeBlob {
475   friend class VMStructs;
476 
477  protected:
478   void* operator new(size_t s, unsigned size) throw();
479 
480  public:
481    SingletonBlob(
482      const char*  name,
483      CodeBlobKind kind,
484      CodeBuffer*  cb,
485      int          size,
486      uint16_t     header_size,
487      int          frame_size,
488      OopMapSet*   oop_maps
489    )
490    : RuntimeBlob(name, kind, cb, size, header_size, CodeOffsets::frame_never_safe, frame_size, oop_maps)
491   {};
492 
493   address entry_point()                          { return code_begin(); }
494 
495   void print_on_impl(outputStream* st) const;
496   void print_value_on_impl(outputStream* st) const;
497 
498   class Vptr : public RuntimeBlob::Vptr {
499     void print_on(const CodeBlob* instance, outputStream* st) const override {
500       ((const SingletonBlob*)instance)->print_on_impl(st);
501     }
502     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
503       ((const SingletonBlob*)instance)->print_value_on_impl(st);
504     }
505   };
506 
507   static const Vptr _vpntr;
508 };
509 
510 
511 //----------------------------------------------------------------------------------------------------
512 // DeoptimizationBlob
513 
514 class DeoptimizationBlob: public SingletonBlob {
515   friend class VMStructs;
516   friend class JVMCIVMStructs;
517  private:
518   int _unpack_offset;
519   int _unpack_with_exception;
520   int _unpack_with_reexecution;
521 
522   int _unpack_with_exception_in_tls;
523 
524 #if INCLUDE_JVMCI
525   // Offsets when JVMCI calls uncommon_trap.
526   int _uncommon_trap_offset;
527   int _implicit_exception_uncommon_trap_offset;
528 #endif
529 
530   // Creation support
531   DeoptimizationBlob(
532     CodeBuffer* cb,
533     int         size,
534     OopMapSet*  oop_maps,
535     int         unpack_offset,
536     int         unpack_with_exception_offset,
537     int         unpack_with_reexecution_offset,
538     int         frame_size
539   );
540 
541  public:
542   // Creation
543   static DeoptimizationBlob* create(
544     CodeBuffer* cb,
545     OopMapSet*  oop_maps,
546     int         unpack_offset,
547     int         unpack_with_exception_offset,
548     int         unpack_with_reexecution_offset,
549     int         frame_size
550   );
551 
552   address unpack() const                         { return code_begin() + _unpack_offset;           }
553   address unpack_with_exception() const          { return code_begin() + _unpack_with_exception;   }
554   address unpack_with_reexecution() const        { return code_begin() + _unpack_with_reexecution; }
555 
556   // Alternate entry point for C1 where the exception and issuing pc
557   // are in JavaThread::_exception_oop and JavaThread::_exception_pc
558   // instead of being in registers.  This is needed because C1 doesn't
559   // model exception paths in a way that keeps these registers free so
560   // there may be live values in those registers during deopt.
561   void set_unpack_with_exception_in_tls_offset(int offset) {
562     _unpack_with_exception_in_tls = offset;
563     assert(code_contains(code_begin() + _unpack_with_exception_in_tls), "must be PC inside codeblob");
564   }
565   address unpack_with_exception_in_tls() const   { return code_begin() + _unpack_with_exception_in_tls; }
566 
567 #if INCLUDE_JVMCI
568   // Offsets when JVMCI calls uncommon_trap.
569   void set_uncommon_trap_offset(int offset) {
570     _uncommon_trap_offset = offset;
571     assert(contains(code_begin() + _uncommon_trap_offset), "must be PC inside codeblob");
572   }
573   address uncommon_trap() const                  { return code_begin() + _uncommon_trap_offset; }
574 
575   void set_implicit_exception_uncommon_trap_offset(int offset) {
576     _implicit_exception_uncommon_trap_offset = offset;
577     assert(contains(code_begin() + _implicit_exception_uncommon_trap_offset), "must be PC inside codeblob");
578   }
579   address implicit_exception_uncommon_trap() const { return code_begin() + _implicit_exception_uncommon_trap_offset; }
580 #endif // INCLUDE_JVMCI
581 
582   void print_value_on_impl(outputStream* st) const;
583 
584   class Vptr : public SingletonBlob::Vptr {
585     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
586       ((const DeoptimizationBlob*)instance)->print_value_on_impl(st);
587     }
588   };
589 
590   static const Vptr _vpntr;
591 };
592 
593 
594 //----------------------------------------------------------------------------------------------------
595 // UncommonTrapBlob (currently only used by Compiler 2)
596 
597 #ifdef COMPILER2
598 
599 class UncommonTrapBlob: public SingletonBlob {
600   friend class VMStructs;
601  private:
602   // Creation support
603   UncommonTrapBlob(
604     CodeBuffer* cb,
605     int         size,
606     OopMapSet*  oop_maps,
607     int         frame_size
608   );
609 
610  public:
611   // Creation
612   static UncommonTrapBlob* create(
613     CodeBuffer* cb,
614     OopMapSet*  oop_maps,
615     int         frame_size
616   );
617 };
618 
619 
620 //----------------------------------------------------------------------------------------------------
621 // ExceptionBlob: used for exception unwinding in compiled code (currently only used by Compiler 2)
622 
623 class ExceptionBlob: public SingletonBlob {
624   friend class VMStructs;
625  private:
626   // Creation support
627   ExceptionBlob(
628     CodeBuffer* cb,
629     int         size,
630     OopMapSet*  oop_maps,
631     int         frame_size
632   );
633 
634  public:
635   // Creation
636   static ExceptionBlob* create(
637     CodeBuffer* cb,
638     OopMapSet*  oop_maps,
639     int         frame_size
640   );
641 };
642 #endif // COMPILER2
643 
644 
645 //----------------------------------------------------------------------------------------------------
646 // SafepointBlob: handles illegal_instruction exceptions during a safepoint
647 
648 class SafepointBlob: public SingletonBlob {
649   friend class VMStructs;
650  private:
651   // Creation support
652   SafepointBlob(
653     CodeBuffer* cb,
654     int         size,
655     OopMapSet*  oop_maps,
656     int         frame_size
657   );
658 
659  public:
660   // Creation
661   static SafepointBlob* create(
662     CodeBuffer* cb,
663     OopMapSet*  oop_maps,
664     int         frame_size
665   );
666 };
667 
668 //----------------------------------------------------------------------------------------------------
669 
670 class UpcallLinker;
671 
672 // A (Panama) upcall stub. Not used by JNI.
673 class UpcallStub: public RuntimeBlob {
674   friend class VMStructs;
675   friend class UpcallLinker;
676  private:
677   jobject _receiver;
678   ByteSize _frame_data_offset;
679 
680   UpcallStub(const char* name, CodeBuffer* cb, int size, jobject receiver, ByteSize frame_data_offset);
681 
682   void* operator new(size_t s, unsigned size) throw();
683 
684   struct FrameData {
685     JavaFrameAnchor jfa;
686     JavaThread* thread;
687     JNIHandleBlock* old_handles;
688     JNIHandleBlock* new_handles;
689   };
690 
691   // defined in frame_ARCH.cpp
692   FrameData* frame_data_for_frame(const frame& frame) const;
693  public:
694   // Creation
695   static UpcallStub* create(const char* name, CodeBuffer* cb, jobject receiver, ByteSize frame_data_offset);
696 
697   static void free(UpcallStub* blob);
698 
699   jobject receiver() { return _receiver; }
700 
701   JavaFrameAnchor* jfa_for_frame(const frame& frame) const;
702 
703   // GC support
704   void oops_do(OopClosure* f, const frame& frame);
705 
706   void print_on_impl(outputStream* st) const;
707   void print_value_on_impl(outputStream* st) const;
708 
709   class Vptr : public RuntimeBlob::Vptr {
710     void print_on(const CodeBlob* instance, outputStream* st) const override {
711       instance->as_upcall_stub()->print_on_impl(st);
712     }
713     void print_value_on(const CodeBlob* instance, outputStream* st) const override {
714       instance->as_upcall_stub()->print_value_on_impl(st);
715     }
716   };
717 
718   static const Vptr _vpntr;
719 };
720 
721 #endif // SHARE_CODE_CODEBLOB_HPP