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_VM_CODE_CODEBLOB_HPP
26 #define SHARE_VM_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/oopMap.hpp"
30 #include "runtime/frame.hpp"
31 #include "runtime/handles.hpp"
32
33 // CodeBlob Types
34 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
35 struct CodeBlobType {
36 enum {
37 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
38 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
39 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
40 All = 3, // All types (No code cache segmentation)
41 Pregenerated = 4, // Special blobs, managed by CodeCacheExtensions
42 NumTypes = 5 // Number of CodeBlobTypes
43 };
44 };
45
46 // CodeBlob - superclass for all entries in the CodeCache.
47 //
48 // Subtypes are:
49 // CompiledMethod : Compiled Java methods (include method that calls to native code)
50 // nmethod : JIT Compiled Java methods
51 // RuntimeBlob : Non-compiled method code; generated glue code
75 int _size; // total size of CodeBlob in bytes
76 int _header_size; // size of header (depends on subclass)
77 int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
78 // not finished setting up their frame. Beware of pc's in
79 // that range. There is a similar range(s) on returns
80 // which we don't detect.
81 int _data_offset; // offset to where data region begins
82 int _frame_size; // size of stack frame
83
84 address _code_begin;
85 address _code_end;
86 address _content_begin; // address to where content region begins (this includes consts, insts, stubs)
87 // address _content_end - not required, for all CodeBlobs _code_end == _content_end for now
88 address _data_end;
89 address _relocation_begin;
90 address _relocation_end;
91
92 ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
93 bool _caller_must_gc_arguments;
94 CodeStrings _strings;
95
96 CodeBlob(const char* name, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
97 CodeBlob(const char* name, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
98 public:
99 // Returns the space needed for CodeBlob
100 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
101 static unsigned int align_code_offset(int offset);
102
103 // Deletion
104 virtual void flush();
105
106 // Typing
107 virtual bool is_buffer_blob() const { return false; }
108 virtual bool is_nmethod() const { return false; }
109 virtual bool is_runtime_stub() const { return false; }
110 virtual bool is_deoptimization_stub() const { return false; }
111 virtual bool is_uncommon_trap_stub() const { return false; }
112 virtual bool is_exception_stub() const { return false; }
113 virtual bool is_safepoint_stub() const { return false; }
114 virtual bool is_adapter_blob() const { return false; }
117
118 virtual bool is_compiled_by_c2() const { return false; }
119 virtual bool is_compiled_by_c1() const { return false; }
120 virtual bool is_compiled_by_jvmci() const { return false; }
121
122 // Casting
123 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
124 nmethod* as_nmethod() { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
125 CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
126 CompiledMethod* as_compiled_method() { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
127
128 // Boundaries
129 address header_begin() const { return (address) this; }
130 relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
131 relocInfo* relocation_end() const { return (relocInfo*) _relocation_end; }
132 address content_begin() const { return _content_begin; }
133 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
134 address code_begin() const { return _code_begin; }
135 address code_end() const { return _code_end; }
136 address data_end() const { return _data_end; }
137
138 // Sizes
139 int size() const { return _size; }
140 int header_size() const { return _header_size; }
141 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); }
142 int content_size() const { return content_end() - content_begin(); }
143 int code_size() const { return code_end() - code_begin(); }
144
145 // Containment
146 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); }
147 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
148 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
149 bool is_frame_complete_at(address addr) const { return code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
150
151 // CodeCache support: really only used by the nmethods, but in order to get
152 // asserts and certain bookkeeping to work in the CodeCache they are defined
153 // virtual here.
154 virtual bool is_zombie() const { return false; }
155 virtual bool is_locked_by_vm() const { return false; }
156
|
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_VM_CODE_CODEBLOB_HPP
26 #define SHARE_VM_CODE_CODEBLOB_HPP
27
28 #include "asm/codeBuffer.hpp"
29 #include "compiler/oopMap.hpp"
30 #include "runtime/frame.hpp"
31 #include "runtime/handles.hpp"
32 #include "utilities/macros.hpp"
33
34 // CodeBlob Types
35 // Used in the CodeCache to assign CodeBlobs to different CodeHeaps
36 struct CodeBlobType {
37 enum {
38 MethodNonProfiled = 0, // Execution level 1 and 4 (non-profiled) nmethods (including native nmethods)
39 MethodProfiled = 1, // Execution level 2 and 3 (profiled) nmethods
40 NonNMethod = 2, // Non-nmethods like Buffers, Adapters and Runtime Stubs
41 All = 3, // All types (No code cache segmentation)
42 Pregenerated = 4, // Special blobs, managed by CodeCacheExtensions
43 NumTypes = 5 // Number of CodeBlobTypes
44 };
45 };
46
47 // CodeBlob - superclass for all entries in the CodeCache.
48 //
49 // Subtypes are:
50 // CompiledMethod : Compiled Java methods (include method that calls to native code)
51 // nmethod : JIT Compiled Java methods
52 // RuntimeBlob : Non-compiled method code; generated glue code
76 int _size; // total size of CodeBlob in bytes
77 int _header_size; // size of header (depends on subclass)
78 int _frame_complete_offset; // instruction offsets in [0.._frame_complete_offset) have
79 // not finished setting up their frame. Beware of pc's in
80 // that range. There is a similar range(s) on returns
81 // which we don't detect.
82 int _data_offset; // offset to where data region begins
83 int _frame_size; // size of stack frame
84
85 address _code_begin;
86 address _code_end;
87 address _content_begin; // address to where content region begins (this includes consts, insts, stubs)
88 // address _content_end - not required, for all CodeBlobs _code_end == _content_end for now
89 address _data_end;
90 address _relocation_begin;
91 address _relocation_end;
92
93 ImmutableOopMapSet* _oop_maps; // OopMap for this CodeBlob
94 bool _caller_must_gc_arguments;
95 CodeStrings _strings;
96 S390_ONLY(int _ctable_offset;)
97
98 CodeBlob(const char* name, const CodeBlobLayout& layout, int frame_complete_offset, int frame_size, ImmutableOopMapSet* oop_maps, bool caller_must_gc_arguments);
99 CodeBlob(const char* name, const CodeBlobLayout& layout, CodeBuffer* cb, int frame_complete_offset, int frame_size, OopMapSet* oop_maps, bool caller_must_gc_arguments);
100 public:
101 // Returns the space needed for CodeBlob
102 static unsigned int allocation_size(CodeBuffer* cb, int header_size);
103 static unsigned int align_code_offset(int offset);
104
105 // Deletion
106 virtual void flush();
107
108 // Typing
109 virtual bool is_buffer_blob() const { return false; }
110 virtual bool is_nmethod() const { return false; }
111 virtual bool is_runtime_stub() const { return false; }
112 virtual bool is_deoptimization_stub() const { return false; }
113 virtual bool is_uncommon_trap_stub() const { return false; }
114 virtual bool is_exception_stub() const { return false; }
115 virtual bool is_safepoint_stub() const { return false; }
116 virtual bool is_adapter_blob() const { return false; }
119
120 virtual bool is_compiled_by_c2() const { return false; }
121 virtual bool is_compiled_by_c1() const { return false; }
122 virtual bool is_compiled_by_jvmci() const { return false; }
123
124 // Casting
125 nmethod* as_nmethod_or_null() { return is_nmethod() ? (nmethod*) this : NULL; }
126 nmethod* as_nmethod() { assert(is_nmethod(), "must be nmethod"); return (nmethod*) this; }
127 CompiledMethod* as_compiled_method_or_null() { return is_compiled() ? (CompiledMethod*) this : NULL; }
128 CompiledMethod* as_compiled_method() { assert(is_compiled(), "must be compiled"); return (CompiledMethod*) this; }
129
130 // Boundaries
131 address header_begin() const { return (address) this; }
132 relocInfo* relocation_begin() const { return (relocInfo*) _relocation_begin; };
133 relocInfo* relocation_end() const { return (relocInfo*) _relocation_end; }
134 address content_begin() const { return _content_begin; }
135 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
136 address code_begin() const { return _code_begin; }
137 address code_end() const { return _code_end; }
138 address data_end() const { return _data_end; }
139
140 // This field holds the beginning of the const section in the old code buffer.
141 // It is needed to fix relocations of pc-relative loads when resizing the
142 // the constant pool or moving it.
143 S390_ONLY(address ctable_begin() const { return header_begin() + _ctable_offset; })
144 void set_ctable_begin(address ctable) { S390_ONLY(_ctable_offset = ctable - header_begin();) }
145
146 // Sizes
147 int size() const { return _size; }
148 int header_size() const { return _header_size; }
149 int relocation_size() const { return (address) relocation_end() - (address) relocation_begin(); }
150 int content_size() const { return content_end() - content_begin(); }
151 int code_size() const { return code_end() - code_begin(); }
152
153 // Containment
154 bool blob_contains(address addr) const { return header_begin() <= addr && addr < data_end(); }
155 bool code_contains(address addr) const { return code_begin() <= addr && addr < code_end(); }
156 bool contains(address addr) const { return content_begin() <= addr && addr < content_end(); }
157 bool is_frame_complete_at(address addr) const { return code_contains(addr) && addr >= code_begin() + _frame_complete_offset; }
158
159 // CodeCache support: really only used by the nmethods, but in order to get
160 // asserts and certain bookkeeping to work in the CodeCache they are defined
161 // virtual here.
162 virtual bool is_zombie() const { return false; }
163 virtual bool is_locked_by_vm() const { return false; }
164
|