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
101 class CodeBlob {
102 friend class VMStructs;
103 friend class JVMCIVMStructs;
104
105 protected:
165
166 // Deletion
167 void purge();
168
169 // Typing
170 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
171 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
172 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
173 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
174 #ifdef COMPILER2
175 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
176 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
177 #else
178 bool is_uncommon_trap_stub() const { return false; }
179 bool is_exception_stub() const { return false; }
180 #endif
181 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
182 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
183 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
184 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
185 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
186
187 // Casting
188 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
189 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
190 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
191 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
192 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
193
194 // Boundaries
195 address header_begin() const { return (address) this; }
196 address header_end() const { return ((address) this) + _header_size; }
197 address content_begin() const { return (address) header_begin() + _content_offset; }
198 address content_end() const { return (address) header_begin() + _data_offset; }
199 address code_begin() const { return (address) header_begin() + _code_offset; }
200 address code_end() const { return (address) header_begin() + _data_offset; }
201 address data_begin() const { return (address) header_begin() + _data_offset; }
202 address data_end() const { return (address) header_begin() + _size; }
203 address blob_end() const { return (address) header_begin() + _size; }
204 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
309 );
310
311 static void free(RuntimeBlob* blob);
312
313 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
314 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
315
316 class Vptr : public CodeBlob::Vptr {
317 };
318 };
319
320 class WhiteBox;
321 //----------------------------------------------------------------------------------------------------
322 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
323
324 class BufferBlob: public RuntimeBlob {
325 friend class VMStructs;
326 friend class AdapterBlob;
327 friend class VtableBlob;
328 friend class MethodHandlesAdapterBlob;
329 friend class UpcallStub;
330 friend class WhiteBox;
331
332 private:
333 // Creation support
334 BufferBlob(const char* name, CodeBlobKind kind, int size);
335 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size);
336
337 void* operator new(size_t s, unsigned size) throw();
338
339 public:
340 // Creation
341 static BufferBlob* create(const char* name, uint buffer_size);
342 static BufferBlob* create(const char* name, CodeBuffer* cb);
343
344 static void free(BufferBlob* buf);
345
346 void print_on_impl(outputStream* st) const;
347 void print_value_on_impl(outputStream* st) const;
348
349 class Vptr : public RuntimeBlob::Vptr {
350 void print_on(const CodeBlob* instance, outputStream* st) const override {
351 ((const BufferBlob*)instance)->print_on_impl(st);
352 }
353 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
354 ((const BufferBlob*)instance)->print_value_on_impl(st);
355 }
356 };
357
358 static const Vptr _vpntr;
359 };
360
361
362 //----------------------------------------------------------------------------------------------------
363 // AdapterBlob: used to hold C2I/I2C adapters
364
365 class AdapterBlob: public BufferBlob {
366 private:
367 AdapterBlob(int size, CodeBuffer* cb);
368
369 public:
370 // Creation
371 static AdapterBlob* create(CodeBuffer* cb);
372 };
373
374 //---------------------------------------------------------------------------------------------------
375 class VtableBlob: public BufferBlob {
376 private:
377 VtableBlob(const char*, int);
378
379 void* operator new(size_t s, unsigned size) throw();
380
381 public:
382 // Creation
383 static VtableBlob* create(const char* name, int buffer_size);
384 };
385
386 //----------------------------------------------------------------------------------------------------
387 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
388
389 class MethodHandlesAdapterBlob: public BufferBlob {
390 private:
391 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
392
393 public:
394 // Creation
395 static MethodHandlesAdapterBlob* create(int buffer_size);
396 };
397
398
399 //----------------------------------------------------------------------------------------------------
400 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
401
402 class RuntimeStub: public RuntimeBlob {
403 friend class VMStructs;
404 private:
405 // Creation support
406 RuntimeStub(
407 const char* name,
408 CodeBuffer* cb,
409 int size,
410 int16_t frame_complete,
411 int frame_size,
412 OopMapSet* oop_maps,
413 bool caller_must_gc_arguments
414 );
415
416 void* operator new(size_t s, unsigned size) throw();
417
|
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
103 class CodeBlob {
104 friend class VMStructs;
105 friend class JVMCIVMStructs;
106
107 protected:
167
168 // Deletion
169 void purge();
170
171 // Typing
172 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
173 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
174 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
175 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
176 #ifdef COMPILER2
177 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
178 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
179 #else
180 bool is_uncommon_trap_stub() const { return false; }
181 bool is_exception_stub() const { return false; }
182 #endif
183 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
184 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
185 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
186 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
187 bool is_buffered_inline_type_blob() const { return _kind == CodeBlobKind::BufferedInlineType; }
188 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
189
190 // Casting
191 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
192 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
193 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
194 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
195 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
196
197 // Boundaries
198 address header_begin() const { return (address) this; }
199 address header_end() const { return ((address) this) + _header_size; }
200 address content_begin() const { return (address) header_begin() + _content_offset; }
201 address content_end() const { return (address) header_begin() + _data_offset; }
202 address code_begin() const { return (address) header_begin() + _code_offset; }
203 address code_end() const { return (address) header_begin() + _data_offset; }
204 address data_begin() const { return (address) header_begin() + _data_offset; }
205 address data_end() const { return (address) header_begin() + _size; }
206 address blob_end() const { return (address) header_begin() + _size; }
207 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
312 );
313
314 static void free(RuntimeBlob* blob);
315
316 // Deal with Disassembler, VTune, Forte, JvmtiExport, MemoryService.
317 static void trace_new_stub(RuntimeBlob* blob, const char* name1, const char* name2 = "");
318
319 class Vptr : public CodeBlob::Vptr {
320 };
321 };
322
323 class WhiteBox;
324 //----------------------------------------------------------------------------------------------------
325 // BufferBlob: used to hold non-relocatable machine code such as the interpreter, stubroutines, etc.
326
327 class BufferBlob: public RuntimeBlob {
328 friend class VMStructs;
329 friend class AdapterBlob;
330 friend class VtableBlob;
331 friend class MethodHandlesAdapterBlob;
332 friend class BufferedInlineTypeBlob;
333 friend class UpcallStub;
334 friend class WhiteBox;
335
336 private:
337 // Creation support
338 BufferBlob(const char* name, CodeBlobKind kind, int size);
339 BufferBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, int header_size);
340 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);
341
342 void* operator new(size_t s, unsigned size) throw();
343
344 public:
345 // Creation
346 static BufferBlob* create(const char* name, uint buffer_size);
347 static BufferBlob* create(const char* name, CodeBuffer* cb);
348
349 static void free(BufferBlob* buf);
350
351 void print_on_impl(outputStream* st) const;
352 void print_value_on_impl(outputStream* st) const;
353
354 class Vptr : public RuntimeBlob::Vptr {
355 void print_on(const CodeBlob* instance, outputStream* st) const override {
356 ((const BufferBlob*)instance)->print_on_impl(st);
357 }
358 void print_value_on(const CodeBlob* instance, outputStream* st) const override {
359 ((const BufferBlob*)instance)->print_value_on_impl(st);
360 }
361 };
362
363 static const Vptr _vpntr;
364 };
365
366
367 //----------------------------------------------------------------------------------------------------
368 // AdapterBlob: used to hold C2I/I2C adapters
369
370 class AdapterBlob: public BufferBlob {
371 private:
372 AdapterBlob(int size, CodeBuffer* cb, int frame_complete, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments = false);
373
374 public:
375 // Creation
376 static AdapterBlob* create(CodeBuffer* cb,
377 int frame_complete,
378 int frame_size,
379 OopMapSet* oop_maps,
380 bool caller_must_gc_arguments = false);
381
382 bool caller_must_gc_arguments(JavaThread* thread) const { return true; }
383 };
384
385 //---------------------------------------------------------------------------------------------------
386 class VtableBlob: public BufferBlob {
387 private:
388 VtableBlob(const char*, int);
389
390 void* operator new(size_t s, unsigned size) throw();
391
392 public:
393 // Creation
394 static VtableBlob* create(const char* name, int buffer_size);
395 };
396
397 //----------------------------------------------------------------------------------------------------
398 // MethodHandlesAdapterBlob: used to hold MethodHandles adapters
399
400 class MethodHandlesAdapterBlob: public BufferBlob {
401 private:
402 MethodHandlesAdapterBlob(int size): BufferBlob("MethodHandles adapters", CodeBlobKind::MHAdapter, size) {}
403
404 public:
405 // Creation
406 static MethodHandlesAdapterBlob* create(int buffer_size);
407 };
408
409 //----------------------------------------------------------------------------------------------------
410 // BufferedInlineTypeBlob : used for pack/unpack handlers
411
412 class BufferedInlineTypeBlob: public BufferBlob {
413 private:
414 const int _pack_fields_off;
415 const int _pack_fields_jobject_off;
416 const int _unpack_fields_off;
417
418 BufferedInlineTypeBlob(int size, CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
419
420 public:
421 // Creation
422 static BufferedInlineTypeBlob* create(CodeBuffer* cb, int pack_fields_off, int pack_fields_jobject_off, int unpack_fields_off);
423
424 address pack_fields() const { return code_begin() + _pack_fields_off; }
425 address pack_fields_jobject() const { return code_begin() + _pack_fields_jobject_off; }
426 address unpack_fields() const { return code_begin() + _unpack_fields_off; }
427 };
428
429 //----------------------------------------------------------------------------------------------------
430 // RuntimeStub: describes stubs used by compiled code to call a (static) C++ runtime routine
431
432 class RuntimeStub: public RuntimeBlob {
433 friend class VMStructs;
434 private:
435 // Creation support
436 RuntimeStub(
437 const char* name,
438 CodeBuffer* cb,
439 int size,
440 int16_t frame_complete,
441 int frame_size,
442 OopMapSet* oop_maps,
443 bool caller_must_gc_arguments
444 );
445
446 void* operator new(size_t s, unsigned size) throw();
447
|