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; }
350 );
351
352 static void free(RuntimeBlob* blob);
353
354 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
355 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
356
357 class Vptr : public CodeBlob::Vptr {
358 };
359 };
360
361 class WhiteBox;
362 //----------------------------------------------------------------------------------------------------
363 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
364
365 class BufferBlob: public RuntimeBlob {
366 friend class VMStructs;
367 friend class AdapterBlob;
368 friend class VtableBlob;
369 friend class MethodHandlesAdapterBlob;
370 friend class UpcallStub;
371 friend class WhiteBox;
372
373 private:
374 // Creation support
375 BufferBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size = sizeof(BufferBlob));
376 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size = sizeof(BufferBlob));
377
378 void* operator new(size_t s, unsigned size) throw();
379
380 public:
381 // Creation
382 static BufferBlob* create(const char* name, uint buffer_size);
383 static BufferBlob* create(const char* name, CodeBuffer* cb);
384
385 static void free(BufferBlob* buf);
386
387 void print_on_impl(outputStream* st) const;
388 void print_value_on_impl(outputStream* st) const;
389
390 class Vptr : public RuntimeBlob::Vptr {
391 void print_on(const CodeBlob* instance, outputStream* st) const override {
392 ((const BufferBlob*)instance)->print_on_impl(st);
393 }
394 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
395 ((const BufferBlob*)instance)->print_value_on_impl(st);
396 }
397 };
398
399 static const Vptr _vpntr;
400 };
401
402
403 //----------------------------------------------------------------------------------------------------
404 // AdapterBlob: used to hold C2I/I2C adapters
405
406 class AdapterBlob: public BufferBlob {
407 public:
408 static const int ENTRY_COUNT = 4;
409 private:
410 AdapterBlob(int size, CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
411 // _i2c_offset is always 0 so no need to store it
412 int _c2i_offset;
413 int _c2i_unverified_offset;
414 int _c2i_no_clinit_check_offset;
415 public:
416 // Creation
417 static AdapterBlob* create(CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
418 void get_offsets(int entry_offset[ENTRY_COUNT]);
419 };
420
421 //---------------------------------------------------------------------------------------------------
422 class VtableBlob: public BufferBlob {
423 private:
424 VtableBlob(const char*, int);
425
426 void* operator new(size_t s, unsigned size) throw();
427
428 public:
429 // Creation
430 static VtableBlob* create(const char* name, int buffer_size);
431 };
432
433 //----------------------------------------------------------------------------------------------------
434 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
435
436 class MethodHandlesAdapterBlob: public BufferBlob {
437 private:
438 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
439
440 public:
441 // Creation
442 static MethodHandlesAdapterBlob* create(int buffer_size);
443 };
444
445
446 //----------------------------------------------------------------------------------------------------
447 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
448
449 class RuntimeStub: public RuntimeBlob {
450 friend class VMStructs;
451 private:
452 // Creation support
453 RuntimeStub(
454 const char* name,
455 CodeBuffer* cb,
456 int size,
457 int16_t frame_complete,
458 int frame_size,
459 OopMapSet* oop_maps,
460 bool caller_must_gc_arguments
461 );
462
463 void* operator new(size_t s, unsigned size) throw();
464
|
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; }
353 );
354
355 static void free(RuntimeBlob* blob);
356
357 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
358 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
359
360 class Vptr : public CodeBlob::Vptr {
361 };
362 };
363
364 class WhiteBox;
365 //----------------------------------------------------------------------------------------------------
366 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
367
368 class BufferBlob: public RuntimeBlob {
369 friend class VMStructs;
370 friend class AdapterBlob;
371 friend class VtableBlob;
372 friend class MethodHandlesAdapterBlob;
373 friend class BufferedInlineTypeBlob;
374 friend class UpcallStub;
375 friend class WhiteBox;
376
377 private:
378 // Creation support
379 BufferBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size = sizeof(BufferBlob));
380 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size = sizeof(BufferBlob));
381 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
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 public:
413 static const int ENTRY_COUNT = 7;
414 private:
415 AdapterBlob(int size, CodeBuffer* cb, int entry_offset[ENTRY_COUNT], int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
416
417 // _i2c_offset is always 0 so no need to store it
418 int _c2i_offset;
419 int _c2i_inline_offset;
420 int _c2i_inline_ro_offset;
421 int _c2i_unverified_offset;
422 int _c2i_unverified_inline_offset;
423 int _c2i_no_clinit_check_offset;
424 public:
425 // Creation
426 static AdapterBlob* create(CodeBuffer* cb,
427 int entry_offset[ENTRY_COUNT],
428 int frame_complete,
429 int frame_size,
430 OopMapSet* oop_maps,
431 bool caller_must_gc_arguments = false);
432
433 bool caller_must_gc_arguments(JavaThread* thread) const { return true; }
434 static AdapterBlob* create(CodeBuffer* cb, int entry_offset[ENTRY_COUNT]);
435 void get_offsets(int entry_offset[ENTRY_COUNT]);
436 };
437
438 //---------------------------------------------------------------------------------------------------
439 class VtableBlob: public BufferBlob {
440 private:
441 VtableBlob(const char*, int);
442
443 void* operator new(size_t s, unsigned size) throw();
444
445 public:
446 // Creation
447 static VtableBlob* create(const char* name, int buffer_size);
448 };
449
450 //----------------------------------------------------------------------------------------------------
451 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
452
453 class MethodHandlesAdapterBlob: public BufferBlob {
454 private:
455 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
456
457 public:
458 // Creation
459 static MethodHandlesAdapterBlob* create(int buffer_size);
460 };
461
462 //----------------------------------------------------------------------------------------------------
463 // BufferedInlineTypeBlob : used for pack/unpack handlers
464
465 class BufferedInlineTypeBlob: public BufferBlob {
466 private:
467 const int _pack_fields_off;
468 const int _pack_fields_jobject_off;
469 const int _unpack_fields_off;
470
471 BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
472
473 public:
474 // Creation
475 static BufferedInlineTypeBlob* create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
476
477 address pack_fields() const { return code_begin() + _pack_fields_off; }
478 address pack_fields_jobject() const { return code_begin() + _pack_fields_jobject_off; }
479 address unpack_fields() const { return code_begin() + _unpack_fields_off; }
480 };
481
482 //----------------------------------------------------------------------------------------------------
483 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
484
485 class RuntimeStub: public RuntimeBlob {
486 friend class VMStructs;
487 private:
488 // Creation support
489 RuntimeStub(
490 const char* name,
491 CodeBuffer* cb,
492 int size,
493 int16_t frame_complete,
494 int frame_size,
495 OopMapSet* oop_maps,
496 bool caller_must_gc_arguments
497 );
498
499 void* operator new(size_t s, unsigned size) throw();
500
|