Mercurial > hg > graal-compiler
comparison src/share/vm/memory/resourceArea.hpp @ 11136:dbc0b5dc08f5
7143807: ResourceMark nesting problem in stringStream
Reviewed-by: kvn, dcubed
author | fparain |
---|---|
date | Wed, 10 Jul 2013 15:49:15 +0000 |
parents | f34d701e952e |
children | 63a4eb8bcd23 833b0f92429a |
comparison
equal
deleted
inserted
replaced
11105:22baec423e2f | 11136:dbc0b5dc08f5 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
81 protected: | 81 protected: |
82 ResourceArea *_area; // Resource area to stack allocate | 82 ResourceArea *_area; // Resource area to stack allocate |
83 Chunk *_chunk; // saved arena chunk | 83 Chunk *_chunk; // saved arena chunk |
84 char *_hwm, *_max; | 84 char *_hwm, *_max; |
85 size_t _size_in_bytes; | 85 size_t _size_in_bytes; |
86 #ifdef ASSERT | |
87 Thread* _thread; | |
88 ResourceMark* _previous_resource_mark; | |
89 #endif //ASSERT | |
86 | 90 |
87 void initialize(Thread *thread) { | 91 void initialize(Thread *thread) { |
88 _area = thread->resource_area(); | 92 _area = thread->resource_area(); |
89 _chunk = _area->_chunk; | 93 _chunk = _area->_chunk; |
90 _hwm = _area->_hwm; | 94 _hwm = _area->_hwm; |
91 _max= _area->_max; | 95 _max= _area->_max; |
92 _size_in_bytes = _area->size_in_bytes(); | 96 _size_in_bytes = _area->size_in_bytes(); |
93 debug_only(_area->_nesting++;) | 97 debug_only(_area->_nesting++;) |
94 assert( _area->_nesting > 0, "must stack allocate RMs" ); | 98 assert( _area->_nesting > 0, "must stack allocate RMs" ); |
99 #ifdef ASSERT | |
100 _thread = thread; | |
101 _previous_resource_mark = thread->current_resource_mark(); | |
102 thread->set_current_resource_mark(this); | |
103 #endif // ASSERT | |
95 } | 104 } |
96 public: | 105 public: |
97 | 106 |
98 #ifndef ASSERT | 107 #ifndef ASSERT |
99 ResourceMark(Thread *thread) { | 108 ResourceMark(Thread *thread) { |
109 ResourceMark( ResourceArea *r ) : | 118 ResourceMark( ResourceArea *r ) : |
110 _area(r), _chunk(r->_chunk), _hwm(r->_hwm), _max(r->_max) { | 119 _area(r), _chunk(r->_chunk), _hwm(r->_hwm), _max(r->_max) { |
111 _size_in_bytes = r->_size_in_bytes; | 120 _size_in_bytes = r->_size_in_bytes; |
112 debug_only(_area->_nesting++;) | 121 debug_only(_area->_nesting++;) |
113 assert( _area->_nesting > 0, "must stack allocate RMs" ); | 122 assert( _area->_nesting > 0, "must stack allocate RMs" ); |
123 #ifdef ASSERT | |
124 Thread* thread = ThreadLocalStorage::thread(); | |
125 if (thread != NULL) { | |
126 _thread = thread; | |
127 _previous_resource_mark = thread->current_resource_mark(); | |
128 thread->set_current_resource_mark(this); | |
129 } else { | |
130 _thread = NULL; | |
131 _previous_resource_mark = NULL; | |
132 } | |
133 #endif // ASSERT | |
114 } | 134 } |
115 | 135 |
116 void reset_to_mark() { | 136 void reset_to_mark() { |
117 if (UseMallocOnly) free_malloced_objects(); | 137 if (UseMallocOnly) free_malloced_objects(); |
118 | 138 |
135 | 155 |
136 ~ResourceMark() { | 156 ~ResourceMark() { |
137 assert( _area->_nesting > 0, "must stack allocate RMs" ); | 157 assert( _area->_nesting > 0, "must stack allocate RMs" ); |
138 debug_only(_area->_nesting--;) | 158 debug_only(_area->_nesting--;) |
139 reset_to_mark(); | 159 reset_to_mark(); |
160 #ifdef ASSERT | |
161 if (_thread != NULL) { | |
162 _thread->set_current_resource_mark(_previous_resource_mark); | |
163 } | |
164 #endif // ASSERT | |
140 } | 165 } |
141 | 166 |
142 | 167 |
143 private: | 168 private: |
144 void free_malloced_objects() PRODUCT_RETURN; | 169 void free_malloced_objects() PRODUCT_RETURN; |