24
25 #ifndef SHARE_VM_CODE_CODEBLOB_HPP
26 #define SHARE_VM_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "compiler/oopMap.hpp"
31 #include "runtime/frame.hpp"
32 #include "runtime/handles.hpp"
33 #include "utilities/macros.hpp"
34
35 // CodeBlob Types
36 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
37 struct CodeBlobType {
38 enum {
39 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
40 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
41 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
42 All = 3, // All types (No code cache segmentation)
43 Pregenerated = 4, // Special blobs, managed by CodeCacheExtensions
44 NumTypes = 5 // Number of CodeBlobTypes
45 };
46 };
47
48 // CodeBlob - superclass for all entries in the CodeCache.
49 //
50 // Subtypes are:
51 // CompiledMethod : Compiled Java methods (include method that calls to native code)
52 // nmethod : JIT Compiled Java methods
53 // RuntimeBlob : Non-compiled method code; generated glue code
54 // RuntimeStub : Call to VM runtime methods
55 // DeoptimizationBlob : Used for deoptimization
56 // ExceptionBlob : Used for stack unrolling
57 // SafepointBlob : Used to handle illegal instruction exceptions
58 //
59 //
60 // Layout:
61 // - header
62 // - relocation
63 // - content space
64 // - instruction space
101 CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
102 CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
103 public:
104 // Returns the space needed for CodeBlob
105 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
106 static unsigned int align_code_offset(int offset);
107
108 // Deletion
109 virtual void flush();
110
111 // Typing
112 virtual bool is_buffer_blob() const { return false; }
113 virtual bool is_nmethod() const { return false; }
114 virtual bool is_runtime_stub() const { return false; }
115 virtual bool is_deoptimization_stub() const { return false; }
116 virtual bool is_uncommon_trap_stub() const { return false; }
117 virtual bool is_exception_stub() const { return false; }
118 virtual bool is_safepoint_stub() const { return false; }
119 virtual bool is_adapter_blob() const { return false; }
120 virtual bool is_method_handles_adapter_blob() const { return false; }
121 virtual bool is_compiled() const { return false; }
122
123 inline bool is_compiled_by_c1() const { return _type == compiler_c1; };
124 inline bool is_compiled_by_c2() const { return _type == compiler_c2; };
125 inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
126 inline bool is_compiled_by_shark() const { return _type == compiler_shark; };
127 const char* compiler_name() const;
128
129 // Casting
130 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
131 nmethod* as_nmethod() { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
132 CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
133 CompiledMethod* as_compiled_method() { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
134
135 // Boundaries
136 address header_begin() const { return (address) this; }
137 relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
138 relocInfo* relocation_end() const { return (relocInfo*) _relocation_end; }
139 address content_begin() const { return _content_begin; }
140 address content_end() const { return _code_end; } // _code_end == _content_end is true for all types of blobs for now, it is also checked in the constructor
141 address code_begin() const { return _code_begin; }
142 address code_end() const { return _code_end; }
143 address data_end() const { return _data_end; }
144
145 // This field holds the beginning of the const section in the old code buffer.
146 // It is needed to fix relocations of pc-relative loads when resizing the
147 // the constant pool or moving it.
148 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
149 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
150
151 // Sizes
152 int size() const { return _size; }
153 int header_size() const { return _header_size; }
188
189 // Naming
190 const char* name() const { return _name; }
191 void set_name(const char* name) { _name = name; }
192
193 // Debugging
194 virtual void verify() = 0;
195 virtual void print() const { print_on(tty); };
196 virtual void print_on(outputStream* st) const;
197 virtual void print_value_on(outputStream* st) const;
198 void print_code();
199
200 // Print the comment associated with offset on stream, if there is one
201 virtual void print_block_comment(outputStream* stream, address block_begin) const {
202 intptr_t offset = (intptr_t)(block_begin - code_begin());
203 _strings.print_block_comment(stream, offset);
204 }
205
206 // Transfer ownership of comments to this CodeBlob
207 void set_strings(CodeStrings& strings) {
208 _strings.assign(strings);
209 }
210
211 static ByteSize name_field_offset() {
212 return byte_offset_of(CodeBlob, _name);
213 }
214
215 static ByteSize oop_maps_field_offset() {
216 return byte_offset_of(CodeBlob, _oop_maps);
217 }
218 };
219
220 class CodeBlobLayout : public StackObj {
221 private:
222 int _size;
223 int _header_size;
224 int _relocation_size;
225 int _content_offset;
226 int _code_offset;
227 int _data_offset;
|
24
25 #ifndef SHARE_VM_CODE_CODEBLOB_HPP
26 #define SHARE_VM_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "compiler/oopMap.hpp"
31 #include "runtime/frame.hpp"
32 #include "runtime/handles.hpp"
33 #include "utilities/macros.hpp"
34
35 // CodeBlob Types
36 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
37 struct CodeBlobType {
38 enum {
39 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
40 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
41 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
42 All = 3, // All types (No code cache segmentation)
43 Pregenerated = 4, // Special blobs, managed by CodeCacheExtensions
44 AOT = 5, // AOT methods
45 NumTypes = 6 // Number of CodeBlobTypes
46 };
47 };
48
49 // CodeBlob - superclass for all entries in the CodeCache.
50 //
51 // Subtypes are:
52 // CompiledMethod : Compiled Java methods (include method that calls to native code)
53 // nmethod : JIT Compiled Java methods
54 // RuntimeBlob : Non-compiled method code; generated glue code
55 // RuntimeStub : Call to VM runtime methods
56 // DeoptimizationBlob : Used for deoptimization
57 // ExceptionBlob : Used for stack unrolling
58 // SafepointBlob : Used to handle illegal instruction exceptions
59 //
60 //
61 // Layout:
62 // - header
63 // - relocation
64 // - content space
65 // - instruction space
102 CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
103 CodeBlob(const char* name, CompilerType type, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
104 public:
105 // Returns the space needed for CodeBlob
106 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
107 static unsigned int align_code_offset(int offset);
108
109 // Deletion
110 virtual void flush();
111
112 // Typing
113 virtual bool is_buffer_blob() const { return false; }
114 virtual bool is_nmethod() const { return false; }
115 virtual bool is_runtime_stub() const { return false; }
116 virtual bool is_deoptimization_stub() const { return false; }
117 virtual bool is_uncommon_trap_stub() const { return false; }
118 virtual bool is_exception_stub() const { return false; }
119 virtual bool is_safepoint_stub() const { return false; }
120 virtual bool is_adapter_blob() const { return false; }
121 virtual bool is_method_handles_adapter_blob() const { return false; }
122 virtual bool is_aot() const { return false; }
123 virtual bool is_compiled() const { return false; }
124
125 inline bool is_compiled_by_c1() const { return _type == compiler_c1; };
126 inline bool is_compiled_by_c2() const { return _type == compiler_c2; };
127 inline bool is_compiled_by_jvmci() const { return _type == compiler_jvmci; };
128 inline bool is_compiled_by_shark() const { return _type == compiler_shark; };
129 const char* compiler_name() const;
130
131 // Casting
132 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
133 nmethod* as_nmethod() { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
134 CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
135 CompiledMethod* as_compiled_method() { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
136 CodeBlob* as_codeblob_or_null() const { return (CodeBlob*) this; }
137
138 // Boundaries
139 address header_begin() const { return (address) this; }
140 relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
141 relocInfo* relocation_end() const { return (relocInfo*) _relocation_end; }
142 address content_begin() const { return _content_begin; }
143 address content_end() const { return _code_end; } // _code_end == _content_end is true for all types of blobs for now, it is also checked in the constructor
144 address code_begin() const { return _code_begin; }
145 address code_end() const { return _code_end; }
146 address data_end() const { return _data_end; }
147
148 // This field holds the beginning of the const section in the old code buffer.
149 // It is needed to fix relocations of pc-relative loads when resizing the
150 // the constant pool or moving it.
151 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
152 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
153
154 // Sizes
155 int size() const { return _size; }
156 int header_size() const { return _header_size; }
191
192 // Naming
193 const char* name() const { return _name; }
194 void set_name(const char* name) { _name = name; }
195
196 // Debugging
197 virtual void verify() = 0;
198 virtual void print() const { print_on(tty); };
199 virtual void print_on(outputStream* st) const;
200 virtual void print_value_on(outputStream* st) const;
201 void print_code();
202
203 // Print the comment associated with offset on stream, if there is one
204 virtual void print_block_comment(outputStream* stream, address block_begin) const {
205 intptr_t offset = (intptr_t)(block_begin - code_begin());
206 _strings.print_block_comment(stream, offset);
207 }
208
209 // Transfer ownership of comments to this CodeBlob
210 void set_strings(CodeStrings& strings) {
211 assert(!is_aot(), "invalid on aot");
212 _strings.assign(strings);
213 }
214
215 static ByteSize name_field_offset() {
216 return byte_offset_of(CodeBlob, _name);
217 }
218
219 static ByteSize oop_maps_field_offset() {
220 return byte_offset_of(CodeBlob, _oop_maps);
221 }
222 };
223
224 class CodeBlobLayout : public StackObj {
225 private:
226 int _size;
227 int _header_size;
228 int _relocation_size;
229 int _content_offset;
230 int _code_offset;
231 int _data_offset;
|