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);
376 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
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 private:
408 AdapterBlob(int size, CodeBuffer* cb);
409
410 public:
411 // Creation
412 static AdapterBlob* create(CodeBuffer* cb);
413 };
414
415 //---------------------------------------------------------------------------------------------------
416 class VtableBlob: public BufferBlob {
417 private:
418 VtableBlob(const char*, int);
419
420 void* operator new(size_t s, unsigned size) throw();
421
422 public:
423 // Creation
424 static VtableBlob* create(const char* name, int buffer_size);
425 };
426
427 //----------------------------------------------------------------------------------------------------
428 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
429
430 class MethodHandlesAdapterBlob: public BufferBlob {
431 private:
432 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
433
434 public:
435 // Creation
436 static MethodHandlesAdapterBlob* create(int buffer_size);
437 };
438
439
440 //----------------------------------------------------------------------------------------------------
441 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
442
443 class RuntimeStub: public RuntimeBlob {
444 friend class VMStructs;
445 private:
446 // Creation support
447 RuntimeStub(
448 const char* name,
449 CodeBuffer* cb,
450 int size,
451 int16_t frame_complete,
452 int frame_size,
453 OopMapSet* oop_maps,
454 bool caller_must_gc_arguments
455 );
456
457 void* operator new(size_t s, unsigned size) throw();
458
|
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);
380 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size);
381 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);
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, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
414
415 public:
416 // Creation
417 static AdapterBlob* create(CodeBuffer* cb,
418 int frame_complete,
419 int frame_size,
420 OopMapSet* oop_maps,
421 bool caller_must_gc_arguments = false);
422
423 bool caller_must_gc_arguments(JavaThread* thread) const { return true; }
424 };
425
426 //---------------------------------------------------------------------------------------------------
427 class VtableBlob: public BufferBlob {
428 private:
429 VtableBlob(const char*, int);
430
431 void* operator new(size_t s, unsigned size) throw();
432
433 public:
434 // Creation
435 static VtableBlob* create(const char* name, int buffer_size);
436 };
437
438 //----------------------------------------------------------------------------------------------------
439 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
440
441 class MethodHandlesAdapterBlob: public BufferBlob {
442 private:
443 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
444
445 public:
446 // Creation
447 static MethodHandlesAdapterBlob* create(int buffer_size);
448 };
449
450 //----------------------------------------------------------------------------------------------------
451 // BufferedInlineTypeBlob : used for pack/unpack handlers
452
453 class BufferedInlineTypeBlob: public BufferBlob {
454 private:
455 const int _pack_fields_off;
456 const int _pack_fields_jobject_off;
457 const int _unpack_fields_off;
458
459 BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
460
461 public:
462 // Creation
463 static BufferedInlineTypeBlob* create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
464
465 address pack_fields() const { return code_begin() + _pack_fields_off; }
466 address pack_fields_jobject() const { return code_begin() + _pack_fields_jobject_off; }
467 address unpack_fields() const { return code_begin() + _unpack_fields_off; }
468 };
469
470 //----------------------------------------------------------------------------------------------------
471 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
472
473 class RuntimeStub: public RuntimeBlob {
474 friend class VMStructs;
475 private:
476 // Creation support
477 RuntimeStub(
478 const char* name,
479 CodeBuffer* cb,
480 int size,
481 int16_t frame_complete,
482 int frame_size,
483 OopMapSet* oop_maps,
484 bool caller_must_gc_arguments
485 );
486
487 void* operator new(size_t s, unsigned size) throw();
488
|