9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_CODE_CODEBLOB_HPP
26 #define SHARE_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/compilerDefinitions.hpp"
30 #include "compiler/oopMap.hpp"
31 #include "runtime/javaFrameAnchor.hpp"
32 #include "runtime/frame.hpp"
33 #include "runtime/handles.hpp"
34 #include "utilities/align.hpp"
35 #include "utilities/macros.hpp"
36
37 class ImmutableOopMap;
38 class ImmutableOopMapSet;
39 class JNIHandleBlock;
40 class OopMapSet;
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)
155
156 static const Vptr* vptr(CodeBlobKind kind);
157 const Vptr* vptr() const;
158
159 CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
160 int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
161 int mutable_data_size);
162
163 // Simple CodeBlob used for simple BufferBlob.
164 CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
165
166
167 void operator delete(void* p) { }
168
169 void prepare_for_archiving_impl();
170 void post_restore_impl();
171
172 public:
173
174 ~CodeBlob() {
175 assert(_oop_maps == nullptr, "Not flushed");
176 }
177
178 // Returns the space needed for CodeBlob
179 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
180 static unsigned int align_code_offset(int offset);
181
182 // Deletion
183 void purge();
184
185 // Typing
186 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
187 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
188 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
189 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
190 #ifdef COMPILER2
191 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
192 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
193 #else
194 bool is_uncommon_trap_stub() const { return false; }
195 bool is_exception_stub() const { return false; }
196 #endif
197 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
198 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
199 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
200 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
201 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
202
203 // Casting
204 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
205 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
206 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
207 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
208 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
209 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
210
211 // Boundaries
212 address header_begin() const { return (address) this; }
213 address header_end() const { return ((address) this) + _header_size; }
214 address content_begin() const { return (address) header_begin() + _content_offset; }
215 address content_end() const { return (address) header_begin() + _data_offset; }
216 address code_begin() const { return (address) header_begin() + _code_offset; }
217 address code_end() const { return (address) header_begin() + _data_offset; }
218 address data_begin() const { return (address) header_begin() + _data_offset; }
219 address data_end() const { return (address) header_begin() + _size; }
220 address blob_end() const { return (address) header_begin() + _size; }
221 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
222
223 int mutable_data_size() const { return _mutable_data_size; }
224 address mutable_data_begin() const { return _mutable_data; }
225 address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
226
227 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #ifndef SHARE_CODE_CODEBLOB_HPP
26 #define SHARE_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "code/aotCodeCache.hpp"
30 #include "compiler/compilerDefinitions.hpp"
31 #include "compiler/oopMap.hpp"
32 #include "runtime/javaFrameAnchor.hpp"
33 #include "runtime/frame.hpp"
34 #include "runtime/handles.hpp"
35 #include "utilities/align.hpp"
36 #include "utilities/macros.hpp"
37
38 class ImmutableOopMap;
39 class ImmutableOopMapSet;
40 class JNIHandleBlock;
41 class OopMapSet;
42
43 // CodeBlob Types
44 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
45 enum class CodeBlobType {
46 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
47 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
48 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
49 All = 3, // All types (No code cache segmentation)
156
157 static const Vptr* vptr(CodeBlobKind kind);
158 const Vptr* vptr() const;
159
160 CodeBlob(const char* name, CodeBlobKind kind, CodeBuffer* cb, int size, uint16_t header_size,
161 int16_t frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments,
162 int mutable_data_size);
163
164 // Simple CodeBlob used for simple BufferBlob.
165 CodeBlob(const char* name, CodeBlobKind kind, int size, uint16_t header_size);
166
167
168 void operator delete(void* p) { }
169
170 void prepare_for_archiving_impl();
171 void post_restore_impl();
172
173 public:
174
175 ~CodeBlob() {
176 assert(_oop_maps == nullptr || AOTCodeCache::is_address_in_aot_cache((address)_oop_maps), "Not flushed");
177 }
178
179 // Returns the space needed for CodeBlob
180 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
181 static unsigned int align_code_offset(int offset);
182
183 // Deletion
184 void purge();
185
186 // Typing
187 bool is_nmethod() const { return _kind == CodeBlobKind::Nmethod; }
188 bool is_buffer_blob() const { return _kind == CodeBlobKind::Buffer; }
189 bool is_runtime_stub() const { return _kind == CodeBlobKind::RuntimeStub; }
190 bool is_deoptimization_stub() const { return _kind == CodeBlobKind::Deoptimization; }
191 #ifdef COMPILER2
192 bool is_uncommon_trap_stub() const { return _kind == CodeBlobKind::UncommonTrap; }
193 bool is_exception_stub() const { return _kind == CodeBlobKind::Exception; }
194 #else
195 bool is_uncommon_trap_stub() const { return false; }
196 bool is_exception_stub() const { return false; }
197 #endif
198 bool is_safepoint_stub() const { return _kind == CodeBlobKind::Safepoint; }
199 bool is_adapter_blob() const { return _kind == CodeBlobKind::Adapter; }
200 bool is_vtable_blob() const { return _kind == CodeBlobKind::Vtable; }
201 bool is_method_handles_adapter_blob() const { return _kind == CodeBlobKind::MHAdapter; }
202 bool is_upcall_stub() const { return _kind == CodeBlobKind::Upcall; }
203
204 // Casting
205 nmethod* as_nmethod_or_null() const { return is_nmethod() ? (nmethod*) this : nullptr; }
206 nmethod* as_nmethod() const { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
207 CodeBlob* as_codeblob() const { return (CodeBlob*) this; }
208 AdapterBlob* as_adapter_blob() const { assert(is_adapter_blob(), "must be adapter blob"); return (AdapterBlob*) this; }
209 ExceptionBlob* as_exception_blob() const { assert(is_exception_stub(), "must be exception stub"); return (ExceptionBlob*) this; }
210 UpcallStub* as_upcall_stub() const { assert(is_upcall_stub(), "must be upcall stub"); return (UpcallStub*) this; }
211 RuntimeStub* as_runtime_stub() const { assert(is_runtime_stub(), "must be runtime blob"); return (RuntimeStub*) this; }
212
213 // Boundaries
214 address header_begin() const { return (address) this; }
215 address header_end() const { return ((address) this) + _header_size; }
216 address content_begin() const { return (address) header_begin() + _content_offset; }
217 address content_end() const { return (address) header_begin() + _data_offset; }
218 address code_begin() const { return (address) header_begin() + _code_offset; }
219 address code_end() const { return (address) header_begin() + _data_offset; }
220 address data_begin() const { return (address) header_begin() + _data_offset; }
221 address data_end() const { return (address) header_begin() + _size; }
222 address blob_end() const { return (address) header_begin() + _size; }
223 // code_end == content_end is true for all types of blobs for now, it is also checked in the constructor
224
225 int mutable_data_size() const { return _mutable_data_size; }
226 address mutable_data_begin() const { return _mutable_data; }
227 address mutable_data_end() const { return _mutable_data + _mutable_data_size; }
228
229 relocInfo* relocation_begin() const { return (relocInfo*)_mutable_data; }
|