3131#include " utilities/debug.hpp"
3232#include " utilities/macros.hpp"
3333
34- class CodeStrings ;
3534class PhaseCFG ;
3635class Compile ;
3736class BufferBlob ;
@@ -273,70 +272,75 @@ class CodeSection {
273272#endif // PRODUCT
274273};
275274
276- class CodeString ;
277- class CodeStrings {
278- private:
275+
279276#ifndef PRODUCT
280- CodeString* _strings;
281- CodeString* _strings_last;
282- #ifdef ASSERT
283- // Becomes true after copy-out, forbids further use.
284- bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
285- #endif
286- static const char * _prefix; // defaults to " ;; "
287277
288- CodeString* find ( intptr_t offset) const ;
289- CodeString* find_last ( intptr_t offset) const ;
278+ class AsmRemarkCollection ;
279+ class DbgStringCollection ;
290280
291- void set_null_and_invalidate () {
292- _strings = NULL ;
293- _strings_last = NULL ;
294- #ifdef ASSERT
295- _defunct = true ;
296- #endif
297- }
298- #endif
281+ // The assumption made here is that most code remarks (or comments) added to
282+ // the generated assembly code are unique, i.e. there is very little gain in
283+ // trying to share the strings between the different offsets tracked in a
284+ // buffer (or blob).
299285
300- public:
301- CodeStrings () {
302- #ifndef PRODUCT
303- _strings = NULL ;
304- _strings_last = NULL ;
305- #ifdef ASSERT
306- _defunct = false ;
307- #endif
308- #endif
309- }
286+ class AsmRemarks {
287+ public:
288+ AsmRemarks ();
289+ ~AsmRemarks ();
310290
311- #ifndef PRODUCT
312- bool is_null () {
313- #ifdef ASSERT
314- return _strings == NULL ;
315- #else
316- return true ;
317- #endif
318- }
291+ const char * insert (uint offset, const char * remstr);
319292
320- const char * add_string ( const char * string) ;
293+ bool is_empty () const ;
321294
322- void add_comment (intptr_t offset, const char * comment);
323- void print_block_comment (outputStream* stream, intptr_t offset) const ;
324- int count () const ;
325- // COPY strings from other to this; leave other valid.
326- void copy (CodeStrings& other);
327- // FREE strings; invalidate this.
328- void free ();
295+ void share (const AsmRemarks &src);
296+ void clear ();
297+ uint print (uint offset, outputStream* strm = tty) const ;
329298
330- // Guarantee that _strings are used at most once; assign and free invalidate a buffer.
331- inline void check_valid () const {
332- assert (!_defunct, " Use of invalid CodeStrings" );
333- }
299+ // For testing purposes only.
300+ const AsmRemarkCollection* ref () const { return _remarks; }
334301
335- static void set_prefix (const char *prefix) {
336- _prefix = prefix;
302+ private:
303+ AsmRemarkCollection* _remarks;
304+ };
305+
306+ // The assumption made here is that the number of debug strings (with a fixed
307+ // address requirement) is a rather small set per compilation unit.
308+
309+ class DbgStrings {
310+ public:
311+ DbgStrings ();
312+ ~DbgStrings ();
313+
314+ const char * insert (const char * dbgstr);
315+
316+ bool is_empty () const ;
317+
318+ void share (const DbgStrings &src);
319+ void clear ();
320+
321+ // For testing purposes only.
322+ const DbgStringCollection* ref () const { return _strings; }
323+
324+ private:
325+ DbgStringCollection* _strings;
326+ };
327+ #endif // not PRODUCT
328+
329+
330+ #ifdef ASSERT
331+ #include " utilities/copy.hpp"
332+
333+ class Scrubber {
334+ public:
335+ Scrubber (void * addr, size_t size) : _addr(addr), _size(size) {}
336+ ~Scrubber () {
337+ Copy::fill_to_bytes (_addr, _size, badResourceValue);
337338 }
338- #endif // !PRODUCT
339+ private:
340+ void * _addr;
341+ size_t _size;
339342};
343+ #endif // ASSERT
340344
341345// A CodeBuffer describes a memory space into which assembly
342346// code is generated. This memory space usually occupies the
@@ -362,7 +366,7 @@ class CodeStrings {
362366// Instructions and data in one section can contain relocatable references to
363367// addresses in a sibling section.
364368
365- class CodeBuffer : public StackObj {
369+ class CodeBuffer : public StackObj DEBUG_ONLY (COMMA private Scrubber) {
366370 friend class CodeSection ;
367371 friend class StubCodeGenerator ;
368372
@@ -411,7 +415,8 @@ class CodeBuffer: public StackObj {
411415 address _last_insn; // used to merge consecutive memory barriers, loads or stores.
412416
413417#ifndef PRODUCT
414- CodeStrings _code_strings;
418+ AsmRemarks _asm_remarks;
419+ DbgStrings _dbg_strings;
415420 bool _collect_comments; // Indicate if we need to collect block comments at all.
416421 address _decode_begin; // start address for decode
417422 address decode_begin ();
@@ -429,7 +434,6 @@ class CodeBuffer: public StackObj {
429434
430435#ifndef PRODUCT
431436 _decode_begin = NULL ;
432- _code_strings = CodeStrings ();
433437 // Collect block comments, but restrict collection to cases where a disassembly is output.
434438 _collect_comments = ( PrintAssembly
435439 || PrintStubCode
@@ -484,7 +488,9 @@ class CodeBuffer: public StackObj {
484488
485489 public:
486490 // (1) code buffer referring to pre-allocated instruction memory
487- CodeBuffer (address code_start, csize_t code_size) {
491+ CodeBuffer (address code_start, csize_t code_size)
492+ DEBUG_ONLY (: Scrubber (this , sizeof (*this )))
493+ {
488494 assert (code_start != NULL , " sanity" );
489495 initialize_misc (" static buffer" );
490496 initialize (code_start, code_size);
@@ -497,14 +503,18 @@ class CodeBuffer: public StackObj {
497503 // (3) code buffer allocating codeBlob memory for code & relocation
498504 // info but with lazy initialization. The name must be something
499505 // informative.
500- CodeBuffer (const char * name) {
506+ CodeBuffer (const char * name)
507+ DEBUG_ONLY (: Scrubber (this , sizeof (*this )))
508+ {
501509 initialize_misc (name);
502510 }
503511
504512 // (4) code buffer allocating codeBlob memory for code & relocation
505513 // info. The name must be something informative and code_size must
506514 // include both code and stubs sizes.
507- CodeBuffer (const char * name, csize_t code_size, csize_t locs_size) {
515+ CodeBuffer (const char * name, csize_t code_size, csize_t locs_size)
516+ DEBUG_ONLY (: Scrubber (this , sizeof (*this )))
517+ {
508518 initialize_misc (name);
509519 initialize (code_size, locs_size);
510520 }
@@ -634,12 +644,12 @@ class CodeBuffer: public StackObj {
634644 void clear_last_insn () { set_last_insn (NULL ); }
635645
636646#ifndef PRODUCT
637- CodeStrings& strings () { return _code_strings; }
647+ AsmRemarks &asm_remarks () { return _asm_remarks; }
648+ DbgStrings &dbg_strings () { return _dbg_strings; }
638649
639- void free_strings () {
640- if (!_code_strings.is_null ()) {
641- _code_strings.free (); // sets _strings Null as a side-effect.
642- }
650+ void clear_strings () {
651+ _asm_remarks.clear ();
652+ _dbg_strings.clear ();
643653 }
644654#endif
645655
@@ -666,7 +676,7 @@ class CodeBuffer: public StackObj {
666676 }
667677 }
668678
669- void block_comment (intptr_t offset, const char * comment) PRODUCT_RETURN;
679+ void block_comment (ptrdiff_t offset, const char * comment) PRODUCT_RETURN;
670680 const char * code_string (const char * str) PRODUCT_RETURN_ (return NULL ;);
671681
672682 // Log a little info about section usage in the CodeBuffer
0 commit comments