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 in the CodeCache:
71 // - header
72 // - content space
73 // - instruction space
74 // Outside of the CodeCache:
75 // - mutable_data
76 // - relocation info
77 // - additional data for subclasses
78
79 enum class CodeBlobKind : u1 {
80 None,
81 Nmethod,
82 Buffer,
83 Adapter,
84 Vtable,
85 MHAdapter,
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 class AdapterBlob;
101 class ExceptionBlob;
102 class DeoptimizationBlob;
103 class SafepointBlob;
104 class UncommonTrapBlob;
105
184
185 // Deletion
186 void purge();
187
188 // Typing
189 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
190 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
191 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
192 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
193 #ifdef COMPILER2
194 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
195 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
196 #else
197 bool is_uncommon_trap_stub() const { return false; }
198 bool is_exception_stub() const { return false; }
199 #endif
200 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
201 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
202 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
203 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
204 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
205
206 // Casting
207 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
208 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
209 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
210 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
211 ExceptionBlob* as_exception_blob() const { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; }
212 DeoptimizationBlob* as_deoptimization_blob() const { assert(is_deoptimization_stub(), "must be deopt stub"); return (DeoptimizationBlob*) this; }
213 SafepointBlob* as_safepoint_blob() const { assert(is_safepoint_stub(), "must be safepoint stub"); return (SafepointBlob*) this; }
214 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
215 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
216 UncommonTrapBlob* as_uncommon_trap_blob() const { assert(is_uncommon_trap_stub(), "must be uncommon trap stub"); return (UncommonTrapBlob*) this; }
217
218 // Boundaries
219 address header_begin() const { return (address) this; }
220 address header_end() const { return ((address) this) + _header_size; }
221 address content_begin() const { return (address) header_begin() + _content_offset; }
222 address content_end() const { return (address) header_begin() + _data_offset; }
223 address code_begin() const { return (address) header_begin() + _code_offset; }
355 );
356
357 static void free(RuntimeBlob* blob);
358
359 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
360 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
361
362 class Vptr : public CodeBlob::Vptr {
363 };
364 };
365
366 class WhiteBox;
367 //----------------------------------------------------------------------------------------------------
368 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
369
370 class BufferBlob: public RuntimeBlob {
371 friend class VMStructs;
372 friend class AdapterBlob;
373 friend class VtableBlob;
374 friend class MethodHandlesAdapterBlob;
375 friend class UpcallStub;
376 friend class WhiteBox;
377
378 private:
379 // Creation support
380 BufferBlob(const char* name, CodeBlobKind kind, int size);
381 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
382
383 void* operator new(size_t s, unsigned size) throw();
384
385 public:
386 // Creation
387 static BufferBlob* create(const char* name, uint buffer_size);
388 static BufferBlob* create(const char* name, CodeBuffer* cb);
389
390 static void free(BufferBlob* buf);
391
392 void print_on_impl(outputStream* st) const;
393 void print_value_on_impl(outputStream* st) const;
394
395 class Vptr : public RuntimeBlob::Vptr {
396 void print_on(const CodeBlob* instance, outputStream* st) const override {
397 ((const BufferBlob*)instance)->print_on_impl(st);
398 }
399 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
400 ((const BufferBlob*)instance)->print_value_on_impl(st);
401 }
402 };
403
404 static const Vptr _vpntr;
405 };
406
407
408 //----------------------------------------------------------------------------------------------------
409 // AdapterBlob: used to hold C2I/I2C adapters
410
411 class AdapterBlob: public BufferBlob {
412 private:
413 AdapterBlob(int size, CodeBuffer* cb);
414
415 public:
416 // Creation
417 static AdapterBlob* create(CodeBuffer* cb);
418 };
419
420 //---------------------------------------------------------------------------------------------------
421 class VtableBlob: public BufferBlob {
422 private:
423 VtableBlob(const char*, int);
424
425 void* operator new(size_t s, unsigned size) throw();
426
427 public:
428 // Creation
429 static VtableBlob* create(const char* name, int buffer_size);
430 };
431
432 //----------------------------------------------------------------------------------------------------
433 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
434
435 class MethodHandlesAdapterBlob: public BufferBlob {
436 private:
437 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
438
439 public:
440 // Creation
441 static MethodHandlesAdapterBlob* create(int buffer_size);
442 };
443
444
445 //----------------------------------------------------------------------------------------------------
446 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
447
448 class RuntimeStub: public RuntimeBlob {
449 friend class VMStructs;
450 private:
451 // Creation support
452 RuntimeStub(
453 const char* name,
454 CodeBuffer* cb,
455 int size,
456 int16_t frame_complete,
457 int frame_size,
458 OopMapSet* oop_maps,
459 bool caller_must_gc_arguments
460 );
461
462 void* operator new(size_t s, unsigned size) throw();
463
|
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 in the CodeCache:
72 // - header
73 // - content space
74 // - instruction space
75 // Outside of the CodeCache:
76 // - mutable_data
77 // - relocation info
78 // - additional data for subclasses
79
80 enum class CodeBlobKind : u1 {
81 None,
82 Nmethod,
83 Buffer,
84 Adapter,
85 Vtable,
86 MHAdapter,
87 BufferedInlineType,
88 RuntimeStub,
89 Deoptimization,
90 Safepoint,
91 #ifdef COMPILER2
92 Exception,
93 UncommonTrap,
94 #endif
95 Upcall,
96 Number_Of_Kinds
97 };
98
99 class UpcallStub; // for as_upcall_stub()
100 class RuntimeStub; // for as_runtime_stub()
101 class JavaFrameAnchor; // for UpcallStub::jfa_for_frame
102 class AdapterBlob;
103 class ExceptionBlob;
104 class DeoptimizationBlob;
105 class SafepointBlob;
106 class UncommonTrapBlob;
107
186
187 // Deletion
188 void purge();
189
190 // Typing
191 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
192 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
193 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
194 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
195 #ifdef COMPILER2
196 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
197 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
198 #else
199 bool is_uncommon_trap_stub() const { return false; }
200 bool is_exception_stub() const { return false; }
201 #endif
202 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
203 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
204 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
205 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
206 bool is_buffered_inline_type_blob() const { return _kind == CodeBlobKind::BufferedInlineType; }
207 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
208
209 // Casting
210 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
211 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
212 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
213 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
214 ExceptionBlob* as_exception_blob() const { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; }
215 DeoptimizationBlob* as_deoptimization_blob() const { assert(is_deoptimization_stub(), "must be deopt stub"); return (DeoptimizationBlob*) this; }
216 SafepointBlob* as_safepoint_blob() const { assert(is_safepoint_stub(), "must be safepoint stub"); return (SafepointBlob*) this; }
217 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
218 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
219 UncommonTrapBlob* as_uncommon_trap_blob() const { assert(is_uncommon_trap_stub(), "must be uncommon trap stub"); return (UncommonTrapBlob*) this; }
220
221 // Boundaries
222 address header_begin() const { return (address) this; }
223 address header_end() const { return ((address) this) + _header_size; }
224 address content_begin() const { return (address) header_begin() + _content_offset; }
225 address content_end() const { return (address) header_begin() + _data_offset; }
226 address code_begin() const { return (address) header_begin() + _code_offset; }
358 );
359
360 static void free(RuntimeBlob* blob);
361
362 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
363 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
364
365 class Vptr : public CodeBlob::Vptr {
366 };
367 };
368
369 class WhiteBox;
370 //----------------------------------------------------------------------------------------------------
371 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
372
373 class BufferBlob: public RuntimeBlob {
374 friend class VMStructs;
375 friend class AdapterBlob;
376 friend class VtableBlob;
377 friend class MethodHandlesAdapterBlob;
378 friend class BufferedInlineTypeBlob;
379 friend class UpcallStub;
380 friend class WhiteBox;
381
382 private:
383 // Creation support
384 BufferBlob(const char* name, CodeBlobKind kind, int size);
385 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size);
386 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);
387
388 void* operator new(size_t s, unsigned size) throw();
389
390 public:
391 // Creation
392 static BufferBlob* create(const char* name, uint buffer_size);
393 static BufferBlob* create(const char* name, CodeBuffer* cb);
394
395 static void free(BufferBlob* buf);
396
397 void print_on_impl(outputStream* st) const;
398 void print_value_on_impl(outputStream* st) const;
399
400 class Vptr : public RuntimeBlob::Vptr {
401 void print_on(const CodeBlob* instance, outputStream* st) const override {
402 ((const BufferBlob*)instance)->print_on_impl(st);
403 }
404 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
405 ((const BufferBlob*)instance)->print_value_on_impl(st);
406 }
407 };
408
409 static const Vptr _vpntr;
410 };
411
412
413 //----------------------------------------------------------------------------------------------------
414 // AdapterBlob: used to hold C2I/I2C adapters
415
416 class AdapterBlob: public BufferBlob {
417 private:
418 AdapterBlob(int size, CodeBuffer* cb, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
419
420 public:
421 // Creation
422 static AdapterBlob* create(CodeBuffer* cb,
423 int frame_complete,
424 int frame_size,
425 OopMapSet* oop_maps,
426 bool caller_must_gc_arguments = false);
427
428 bool caller_must_gc_arguments(JavaThread* thread) const { return true; }
429 };
430
431 //---------------------------------------------------------------------------------------------------
432 class VtableBlob: public BufferBlob {
433 private:
434 VtableBlob(const char*, int);
435
436 void* operator new(size_t s, unsigned size) throw();
437
438 public:
439 // Creation
440 static VtableBlob* create(const char* name, int buffer_size);
441 };
442
443 //----------------------------------------------------------------------------------------------------
444 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
445
446 class MethodHandlesAdapterBlob: public BufferBlob {
447 private:
448 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
449
450 public:
451 // Creation
452 static MethodHandlesAdapterBlob* create(int buffer_size);
453 };
454
455 //----------------------------------------------------------------------------------------------------
456 // BufferedInlineTypeBlob : used for pack/unpack handlers
457
458 class BufferedInlineTypeBlob: public BufferBlob {
459 private:
460 const int _pack_fields_off;
461 const int _pack_fields_jobject_off;
462 const int _unpack_fields_off;
463
464 BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
465
466 public:
467 // Creation
468 static BufferedInlineTypeBlob* create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
469
470 address pack_fields() const { return code_begin() + _pack_fields_off; }
471 address pack_fields_jobject() const { return code_begin() + _pack_fields_jobject_off; }
472 address unpack_fields() const { return code_begin() + _unpack_fields_off; }
473 };
474
475 //----------------------------------------------------------------------------------------------------
476 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
477
478 class RuntimeStub: public RuntimeBlob {
479 friend class VMStructs;
480 private:
481 // Creation support
482 RuntimeStub(
483 const char* name,
484 CodeBuffer* cb,
485 int size,
486 int16_t frame_complete,
487 int frame_size,
488 OopMapSet* oop_maps,
489 bool caller_must_gc_arguments
490 );
491
492 void* operator new(size_t s, unsigned size) throw();
493
|