comparison src/share/vm/asm/codeBuffer.hpp @ 20435:094cbdffa87d

8054292: code comments leak in fastdebug builds Summary: Added deallocation to destructor; hardened interface against misuse Reviewed-by: kvn
author drchase
date Fri, 29 Aug 2014 19:45:49 -0400
parents 78bbf4d43a14
children
comparison
equal deleted inserted replaced
20428:4d8781a35525 20435:094cbdffa87d
25 #ifndef SHARE_VM_ASM_CODEBUFFER_HPP 25 #ifndef SHARE_VM_ASM_CODEBUFFER_HPP
26 #define SHARE_VM_ASM_CODEBUFFER_HPP 26 #define SHARE_VM_ASM_CODEBUFFER_HPP
27 27
28 #include "code/oopRecorder.hpp" 28 #include "code/oopRecorder.hpp"
29 #include "code/relocInfo.hpp" 29 #include "code/relocInfo.hpp"
30 #include "utilities/debug.hpp"
30 31
31 class CodeStrings; 32 class CodeStrings;
32 class PhaseCFG; 33 class PhaseCFG;
33 class Compile; 34 class Compile;
34 class BufferBlob; 35 class BufferBlob;
243 class CodeString; 244 class CodeString;
244 class CodeStrings VALUE_OBJ_CLASS_SPEC { 245 class CodeStrings VALUE_OBJ_CLASS_SPEC {
245 private: 246 private:
246 #ifndef PRODUCT 247 #ifndef PRODUCT
247 CodeString* _strings; 248 CodeString* _strings;
249 #ifdef ASSERT
250 // Becomes true after copy-out, forbids further use.
251 bool _defunct; // Zero bit pattern is "valid", see memset call in decode_env::decode_env
252 #endif
248 #endif 253 #endif
249 254
250 CodeString* find(intptr_t offset) const; 255 CodeString* find(intptr_t offset) const;
251 CodeString* find_last(intptr_t offset) const; 256 CodeString* find_last(intptr_t offset) const;
257
258 void set_null_and_invalidate() {
259 #ifndef PRODUCT
260 _strings = NULL;
261 #ifdef ASSERT
262 _defunct = true;
263 #endif
264 #endif
265 }
252 266
253 public: 267 public:
254 CodeStrings() { 268 CodeStrings() {
255 #ifndef PRODUCT 269 #ifndef PRODUCT
256 _strings = NULL; 270 _strings = NULL;
271 #ifdef ASSERT
272 _defunct = false;
273 #endif
274 #endif
275 }
276
277 bool is_null() {
278 #ifdef ASSERT
279 return _strings == NULL;
280 #else
281 return true;
257 #endif 282 #endif
258 } 283 }
259 284
260 const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;); 285 const char* add_string(const char * string) PRODUCT_RETURN_(return NULL;);
261 286
262 void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN; 287 void add_comment(intptr_t offset, const char * comment) PRODUCT_RETURN;
263 void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN; 288 void print_block_comment(outputStream* stream, intptr_t offset) const PRODUCT_RETURN;
289 // MOVE strings from other to this; invalidate other.
264 void assign(CodeStrings& other) PRODUCT_RETURN; 290 void assign(CodeStrings& other) PRODUCT_RETURN;
291 // COPY strings from other to this; leave other valid.
292 void copy(CodeStrings& other) PRODUCT_RETURN;
265 void free() PRODUCT_RETURN; 293 void free() PRODUCT_RETURN;
294 // Guarantee that _strings are used at most once; assign invalidates a buffer.
295 inline void check_valid() const {
296 #ifdef ASSERT
297 assert(!_defunct, "Use of invalid CodeStrings");
298 #endif
299 }
266 }; 300 };
267 301
268 // A CodeBuffer describes a memory space into which assembly 302 // A CodeBuffer describes a memory space into which assembly
269 // code is generated. This memory space usually occupies the 303 // code is generated. This memory space usually occupies the
270 // interior of a single BufferBlob, but in some cases it may be 304 // interior of a single BufferBlob, but in some cases it may be
328 BufferBlob* _blob; // optional buffer in CodeCache for generated code 362 BufferBlob* _blob; // optional buffer in CodeCache for generated code
329 address _total_start; // first address of combined memory buffer 363 address _total_start; // first address of combined memory buffer
330 csize_t _total_size; // size in bytes of combined memory buffer 364 csize_t _total_size; // size in bytes of combined memory buffer
331 365
332 OopRecorder* _oop_recorder; 366 OopRecorder* _oop_recorder;
333 CodeStrings _strings; 367 CodeStrings _code_strings;
334 OopRecorder _default_oop_recorder; // override with initialize_oop_recorder 368 OopRecorder _default_oop_recorder; // override with initialize_oop_recorder
335 Arena* _overflow_arena; 369 Arena* _overflow_arena;
336 370
337 address _decode_begin; // start address for decode 371 address _decode_begin; // start address for decode
338 address decode_begin(); 372 address decode_begin();
529 void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); } 563 void initialize_stubs_size(csize_t size) { initialize_section_size(&_stubs, size); }
530 // Override default oop recorder. 564 // Override default oop recorder.
531 void initialize_oop_recorder(OopRecorder* r); 565 void initialize_oop_recorder(OopRecorder* r);
532 566
533 OopRecorder* oop_recorder() const { return _oop_recorder; } 567 OopRecorder* oop_recorder() const { return _oop_recorder; }
534 CodeStrings& strings() { return _strings; } 568 CodeStrings& strings() { return _code_strings; }
569
570 void free_strings() {
571 if (!_code_strings.is_null()) {
572 _code_strings.free(); // sets _strings Null as a side-effect.
573 }
574 }
535 575
536 // Code generation 576 // Code generation
537 void relocate(address at, RelocationHolder const& rspec, int format = 0) { 577 void relocate(address at, RelocationHolder const& rspec, int format = 0) {
538 _insts.relocate(at, rspec, format); 578 _insts.relocate(at, rspec, format);
539 } 579 }