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