7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 #include "adlc.hpp"
26
27 void* Chunk::operator new(size_t requested_size, size_t length) throw() {
28 return CHeapObj::operator new(requested_size + length);
29 }
30
31 void Chunk::operator delete(void* p, size_t length) {
32 CHeapObj::operator delete(p);
33 }
34
35 Chunk::Chunk(size_t length) {
36 _next = NULL; // Chain on the linked list
37 _len = length; // Save actual size
38 }
39
40 //------------------------------chop-------------------------------------------
41 void Chunk::chop() {
42 Chunk *k = this;
43 while( k ) {
44 Chunk *tmp = k->_next;
45 // clear out this chunk (to detect allocation bugs)
46 memset(k, 0xBE, k->_len);
147 _first = _chunk = NULL; // Normal, new-arena initialization
148 _hwm = _max = NULL;
149 return a; // Return Arena with guts
150 }
151
152 //------------------------------contains---------------------------------------
153 // Determine if pointer belongs to this Arena or not.
154 bool Arena::contains( const void *ptr ) const {
155 if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
156 return true; // Check for in this chunk
157 for( Chunk *c = _first; c; c = c->_next )
158 if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
159 return true; // Check for every chunk in Arena
160 return false; // Not in any Chunk, so not in Arena
161 }
162
163 //-----------------------------------------------------------------------------
164 // CHeapObj
165
166 void* CHeapObj::operator new(size_t size) throw() {
167 return (void *) malloc(size);
168 }
169
170 void CHeapObj::operator delete(void* p){
171 free(p);
172 }
|
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
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 #include "adlc.hpp"
26
27 void* AllocateHeap(size_t size) {
28 unsigned char* ptr = (unsigned char*) malloc(size);
29 if (ptr == NULL && size != 0) {
30 fprintf(stderr, "Error: Out of memory in ADLC\n"); // logging can cause crash!
31 fflush(stderr);
32 exit(1);
33 }
34 return ptr;
35 }
36
37 void* Chunk::operator new(size_t requested_size, size_t length) throw() {
38 return CHeapObj::operator new(requested_size + length);
39 }
40
41 void Chunk::operator delete(void* p, size_t length) {
42 CHeapObj::operator delete(p);
43 }
44
45 Chunk::Chunk(size_t length) {
46 _next = NULL; // Chain on the linked list
47 _len = length; // Save actual size
48 }
49
50 //------------------------------chop-------------------------------------------
51 void Chunk::chop() {
52 Chunk *k = this;
53 while( k ) {
54 Chunk *tmp = k->_next;
55 // clear out this chunk (to detect allocation bugs)
56 memset(k, 0xBE, k->_len);
157 _first = _chunk = NULL; // Normal, new-arena initialization
158 _hwm = _max = NULL;
159 return a; // Return Arena with guts
160 }
161
162 //------------------------------contains---------------------------------------
163 // Determine if pointer belongs to this Arena or not.
164 bool Arena::contains( const void *ptr ) const {
165 if( (void*)_chunk->bottom() <= ptr && ptr < (void*)_hwm )
166 return true; // Check for in this chunk
167 for( Chunk *c = _first; c; c = c->_next )
168 if( (void*)c->bottom() <= ptr && ptr < (void*)c->top())
169 return true; // Check for every chunk in Arena
170 return false; // Not in any Chunk, so not in Arena
171 }
172
173 //-----------------------------------------------------------------------------
174 // CHeapObj
175
176 void* CHeapObj::operator new(size_t size) throw() {
177 return (void *) AllocateHeap(size);
178 }
179
180 void CHeapObj::operator delete(void* p){
181 free(p);
182 }
|