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