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_VM_ASM_CODEBUFFER_HPP
26 #define SHARE_VM_ASM_CODEBUFFER_HPP
27
28 #include "code/oopRecorder.hpp"
29 #include "code/relocInfo.hpp"
30
31 class CodeStrings;
32 class PhaseCFG;
33 class Compile;
34 class BufferBlob;
35 class CodeBuffer;
36 class Label;
37
38 class CodeOffsets: public StackObj {
39 public:
40 enum Entries { Entry,
41 Verified_Entry,
42 Frame_Complete, // Offset in the code where the frame setup is (for forte stackwalks) is complete
43 OSR_Entry,
44 Dtrace_trap = OSR_Entry, // dtrace probes can never have an OSR entry so reuse it
45 Exceptions, // Offset where exception handler lives
46 Deopt, // Offset where deopt handler lives
47 DeoptMH, // Offset where MethodHandle deopt handler lives
48 UnwindHandler, // Offset to default unwind handler
49 max_Entries };
228 // Mark a section frozen. Assign its remaining space to
229 // the following section. It will never expand after this point.
230 inline void freeze(); // { _outer->freeze_section(this); }
231
232 // Ensure there's enough space left in the current section.
233 // Return true if there was an expansion.
234 bool maybe_expand_to_ensure_remaining(csize_t amount);
235
236 #ifndef PRODUCT
237 void decode();
238 void dump();
239 void print(const char* name);
240 #endif //PRODUCT
241 };
242
243 class CodeString;
244 class CodeStrings VALUE_OBJ_CLASS_SPEC {
245 private:
246 #ifndef PRODUCT
247 CodeString* _strings;
248 #endif
249
250 CodeString* find(intptr_t offset) const;
251 CodeString* find_last(intptr_t offset) const;
252
253 public:
254 CodeStrings() {
255 #ifndef PRODUCT
256 _strings = NULL;
257 #endif
258 }
259
260 const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
261
262 void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
263 void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
264 void assign(CodeStrings& other) PRODUCT_RETURN;
265 void free() PRODUCT_RETURN;
266 };
267
268 // A CodeBuffer describes a memory space into which assembly
269 // code is generated. This memory space usually occupies the
270 // interior of a single BufferBlob, but in some cases it may be
271 // an arbitrary span of memory, even outside the code cache.
272 //
273 // A code buffer comes in two variants:
274 //
275 // (1) A CodeBuffer referring to an already allocated piece of memory:
276 // This is used to direct 'static' code generation (e.g. for interpreter
277 // or stubroutine generation, etc.). This code comes with NO relocation
278 // information.
279 //
280 // (2) A CodeBuffer referring to a piece of memory allocated when the
281 // CodeBuffer is allocated. This is used for nmethod generation.
282 //
283 // The memory can be divided up into several parts called sections.
284 // Each section independently accumulates code (or data) an relocations.
285 // Sections can grow (at the expense of a reallocation of the BufferBlob
515 OopRecorder* recorder = oop_recorder();
516 return (recorder == NULL)? 0: recorder->oop_size();
517 }
518
519 // allocated size of any and all recorded metadata
520 csize_t total_metadata_size() const {
521 OopRecorder* recorder = oop_recorder();
522 return (recorder == NULL)? 0: recorder->metadata_size();
523 }
524
525 // Configuration functions, called immediately after the CB is constructed.
526 // The section sizes are subtracted from the original insts section.
527 // Note: Call them in reverse section order, because each steals from insts.
528 void initialize_consts_size(csize_t size) { initialize_section_size(&_consts, size); }
529 void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); }
530 // Override default oop recorder.
531 void initialize_oop_recorder(OopRecorder* r);
532
533 OopRecorder* oop_recorder() const { return _oop_recorder; }
534 CodeStrings& strings() { return _strings; }
535
536 // Code generation
537 void relocate(address at, RelocationHolder const& rspec, int format = 0) {
538 _insts.relocate(at, rspec, format);
539 }
540 void relocate(address at, relocInfo::relocType rtype, int format = 0) {
541 _insts.relocate(at, rtype, format);
542 }
543
544 // Management of overflow storage for binding of Labels.
545 GrowableArray<int>* create_patch_overflow();
546
547 // NMethod generation
548 void copy_code_and_locs_to(CodeBlob* blob) {
549 assert(blob != NULL, "sane");
550 copy_relocations_to(blob);
551 copy_code_to(blob);
552 }
553 void copy_values_to(nmethod* nm) {
554 if (!oop_recorder()->is_unused()) {
|
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_VM_ASM_CODEBUFFER_HPP
26 #define SHARE_VM_ASM_CODEBUFFER_HPP
27
28 #include "code/oopRecorder.hpp"
29 #include "code/relocInfo.hpp"
30 #include "utilities/debug.hpp"
31
32 class CodeStrings;
33 class PhaseCFG;
34 class Compile;
35 class BufferBlob;
36 class CodeBuffer;
37 class Label;
38
39 class CodeOffsets: public StackObj {
40 public:
41 enum Entries { Entry,
42 Verified_Entry,
43 Frame_Complete, // Offset in the code where the frame setup is (for forte stackwalks) is complete
44 OSR_Entry,
45 Dtrace_trap = OSR_Entry, // dtrace probes can never have an OSR entry so reuse it
46 Exceptions, // Offset where exception handler lives
47 Deopt, // Offset where deopt handler lives
48 DeoptMH, // Offset where MethodHandle deopt handler lives
49 UnwindHandler, // Offset to default unwind handler
50 max_Entries };
229 // Mark a section frozen. Assign its remaining space to
230 // the following section. It will never expand after this point.
231 inline void freeze(); // { _outer->freeze_section(this); }
232
233 // Ensure there's enough space left in the current section.
234 // Return true if there was an expansion.
235 bool maybe_expand_to_ensure_remaining(csize_t amount);
236
237 #ifndef PRODUCT
238 void decode();
239 void dump();
240 void print(const char* name);
241 #endif //PRODUCT
242 };
243
244 class CodeString;
245 class CodeStrings VALUE_OBJ_CLASS_SPEC {
246 private:
247 #ifndef PRODUCT
248 CodeString* _strings;
249 // Becomes true after copy-out, forbids further use.
250 bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
251 #endif
252
253 CodeString* find(intptr_t offset) const;
254 CodeString* find_last(intptr_t offset) const;
255
256 void set_null_and_invalidate() {
257 #ifdef ASSERT
258 _strings = NULL;
259 _defunct = true;
260 #endif
261 }
262
263 public:
264 CodeStrings() {
265 #ifndef PRODUCT
266 _strings = NULL;
267 _defunct = false;
268 #endif
269 }
270
271 bool isNull() {
272 #ifdef ASSERT
273 return _strings == NULL;
274 #else
275 return true;
276 #endif
277 }
278
279 const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
280
281 void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
282 void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
283 // MOVE strings from other to this; invalidate other.
284 void assign(CodeStrings& other) PRODUCT_RETURN;
285 // COPY strings from other to this; leave other valid.
286 void copy(CodeStrings& other) PRODUCT_RETURN;
287 void free() PRODUCT_RETURN;
288 // Guarantee that _strings are used at most once; assign invalidates a buffer.
289 inline void check_valid() const {
290 #ifdef ASSERT
291 assert(!_defunct, "Use of invalid CodeStrings");
292 #endif
293 }
294 };
295
296 // A CodeBuffer describes a memory space into which assembly
297 // code is generated. This memory space usually occupies the
298 // interior of a single BufferBlob, but in some cases it may be
299 // an arbitrary span of memory, even outside the code cache.
300 //
301 // A code buffer comes in two variants:
302 //
303 // (1) A CodeBuffer referring to an already allocated piece of memory:
304 // This is used to direct 'static' code generation (e.g. for interpreter
305 // or stubroutine generation, etc.). This code comes with NO relocation
306 // information.
307 //
308 // (2) A CodeBuffer referring to a piece of memory allocated when the
309 // CodeBuffer is allocated. This is used for nmethod generation.
310 //
311 // The memory can be divided up into several parts called sections.
312 // Each section independently accumulates code (or data) an relocations.
313 // Sections can grow (at the expense of a reallocation of the BufferBlob
543 OopRecorder* recorder = oop_recorder();
544 return (recorder == NULL)? 0: recorder->oop_size();
545 }
546
547 // allocated size of any and all recorded metadata
548 csize_t total_metadata_size() const {
549 OopRecorder* recorder = oop_recorder();
550 return (recorder == NULL)? 0: recorder->metadata_size();
551 }
552
553 // Configuration functions, called immediately after the CB is constructed.
554 // The section sizes are subtracted from the original insts section.
555 // Note: Call them in reverse section order, because each steals from insts.
556 void initialize_consts_size(csize_t size) { initialize_section_size(&_consts, size); }
557 void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); }
558 // Override default oop recorder.
559 void initialize_oop_recorder(OopRecorder* r);
560
561 OopRecorder* oop_recorder() const { return _oop_recorder; }
562 CodeStrings& strings() { return _strings; }
563
564 void free_strings() {
565 if (!_strings.isNull()) {
566 _strings.free(); // sets _strings Null as a side-effect.
567 }
568 }
569
570 // Code generation
571 void relocate(address at, RelocationHolder const& rspec, int format = 0) {
572 _insts.relocate(at, rspec, format);
573 }
574 void relocate(address at, relocInfo::relocType rtype, int format = 0) {
575 _insts.relocate(at, rtype, format);
576 }
577
578 // Management of overflow storage for binding of Labels.
579 GrowableArray<int>* create_patch_overflow();
580
581 // NMethod generation
582 void copy_code_and_locs_to(CodeBlob* blob) {
583 assert(blob != NULL, "sane");
584 copy_relocations_to(blob);
585 copy_code_to(blob);
586 }
587 void copy_values_to(nmethod* nm) {
588 if (!oop_recorder()->is_unused()) {
|