1
1
/*
2
- * Copyright (c) 1998, 2018 , Oracle and/or its affiliates. All rights reserved.
2
+ * Copyright (c) 1998, 2022 , Oracle and/or its affiliates. All rights reserved.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
24
24
25
25
#include " adlc.hpp"
26
26
27
- void * AllocateHeap (size_t size) {
27
+ void * AdlAllocateHeap (size_t size) {
28
28
unsigned char * ptr = (unsigned char *) malloc (size);
29
29
if (ptr == NULL && size != 0 ) {
30
30
fprintf (stderr, " Error: Out of memory in ADLC\n " ); // logging can cause crash!
@@ -34,7 +34,7 @@ void* AllocateHeap(size_t size) {
34
34
return ptr;
35
35
}
36
36
37
- void * ReAllocateHeap (void * old_ptr, size_t size) {
37
+ void * AdlReAllocateHeap (void * old_ptr, size_t size) {
38
38
unsigned char * ptr = (unsigned char *) realloc (old_ptr, size);
39
39
if (ptr == NULL && size != 0 ) {
40
40
fprintf (stderr, " Error: Out of memory in ADLC\n " ); // logging can cause crash!
@@ -44,77 +44,77 @@ void* ReAllocateHeap(void* old_ptr, size_t size) {
44
44
return ptr;
45
45
}
46
46
47
- void * Chunk ::operator new (size_t requested_size, size_t length) throw () {
48
- return CHeapObj ::operator new (requested_size + length);
47
+ void * AdlChunk ::operator new (size_t requested_size, size_t length) throw () {
48
+ return AdlCHeapObj ::operator new (requested_size + length);
49
49
}
50
50
51
- void Chunk ::operator delete (void * p, size_t length) {
52
- CHeapObj ::operator delete (p);
51
+ void AdlChunk ::operator delete (void * p, size_t length) {
52
+ AdlCHeapObj ::operator delete (p);
53
53
}
54
54
55
- Chunk::Chunk (size_t length) {
55
+ AdlChunk::AdlChunk (size_t length) {
56
56
_next = NULL ; // Chain on the linked list
57
57
_len = length; // Save actual size
58
58
}
59
59
60
60
// ------------------------------chop-------------------------------------------
61
- void Chunk ::chop () {
62
- Chunk *k = this ;
61
+ void AdlChunk ::chop () {
62
+ AdlChunk *k = this ;
63
63
while ( k ) {
64
- Chunk *tmp = k->_next ;
64
+ AdlChunk *tmp = k->_next ;
65
65
// clear out this chunk (to detect allocation bugs)
66
66
memset (k, 0xBE , k->_len );
67
67
free (k); // Free chunk (was malloc'd)
68
68
k = tmp;
69
69
}
70
70
}
71
71
72
- void Chunk ::next_chop () {
72
+ void AdlChunk ::next_chop () {
73
73
_next->chop ();
74
74
_next = NULL ;
75
75
}
76
76
77
- // ------------------------------Arena ------------------------------------------
78
- Arena::Arena ( size_t init_size ) {
77
+ // ------------------------------AdlArena ------------------------------------------
78
+ AdlArena::AdlArena ( size_t init_size ) {
79
79
init_size = (init_size+3 ) & ~3 ;
80
- _first = _chunk = new (init_size) Chunk (init_size);
80
+ _first = _chunk = new (init_size) AdlChunk (init_size);
81
81
_hwm = _chunk->bottom (); // Save the cached hwm, max
82
82
_max = _chunk->top ();
83
83
set_size_in_bytes (init_size);
84
84
}
85
85
86
- Arena::Arena () {
87
- _first = _chunk = new (Chunk ::init_size) Chunk (Chunk ::init_size);
86
+ AdlArena::AdlArena () {
87
+ _first = _chunk = new (AdlChunk ::init_size) AdlChunk (AdlChunk ::init_size);
88
88
_hwm = _chunk->bottom (); // Save the cached hwm, max
89
89
_max = _chunk->top ();
90
- set_size_in_bytes (Chunk ::init_size);
90
+ set_size_in_bytes (AdlChunk ::init_size);
91
91
}
92
92
93
- Arena::Arena ( Arena *a )
93
+ AdlArena::AdlArena ( AdlArena *a )
94
94
: _chunk(a->_chunk), _hwm(a->_hwm), _max(a->_max), _first(a->_first) {
95
95
set_size_in_bytes (a->size_in_bytes ());
96
96
}
97
97
98
98
// ------------------------------used-------------------------------------------
99
- // Total of all Chunks in arena
100
- size_t Arena ::used () const {
101
- size_t sum = _chunk->_len - (_max-_hwm); // Size leftover in this Chunk
102
- Chunk *k = _first;
103
- while ( k != _chunk) { // Whilst have Chunks in a row
104
- sum += k->_len ; // Total size of this Chunk
105
- k = k->_next ; // Bump along to next Chunk
99
+ // Total of all AdlChunks in arena
100
+ size_t AdlArena ::used () const {
101
+ size_t sum = _chunk->_len - (_max-_hwm); // Size leftover in this AdlChunk
102
+ AdlChunk *k = _first;
103
+ while ( k != _chunk) { // Whilst have AdlChunks in a row
104
+ sum += k->_len ; // Total size of this AdlChunk
105
+ k = k->_next ; // Bump along to next AdlChunk
106
106
}
107
107
return sum; // Return total consumed space.
108
108
}
109
109
110
110
// ------------------------------grow-------------------------------------------
111
- // Grow a new Chunk
112
- void * Arena ::grow ( size_t x ) {
111
+ // Grow a new AdlChunk
112
+ void * AdlArena ::grow ( size_t x ) {
113
113
// Get minimal required size. Either real big, or even bigger for giant objs
114
- size_t len = max (x, Chunk ::size);
114
+ size_t len = max (x, AdlChunk ::size);
115
115
116
- Chunk *k = _chunk; // Get filled-up chunk address
117
- _chunk = new (len) Chunk (len);
116
+ AdlChunk *k = _chunk; // Get filled-up chunk address
117
+ _chunk = new (len) AdlChunk (len);
118
118
119
119
if ( k ) k->_next = _chunk; // Append new chunk to end of linked list
120
120
else _first = _chunk;
@@ -127,17 +127,17 @@ void* Arena::grow( size_t x ) {
127
127
}
128
128
129
129
// ------------------------------calloc-----------------------------------------
130
- // Allocate zeroed storage in Arena
131
- void *Arena ::Acalloc ( size_t items, size_t x ) {
130
+ // Allocate zeroed storage in AdlArena
131
+ void *AdlArena ::Acalloc ( size_t items, size_t x ) {
132
132
size_t z = items*x; // Total size needed
133
133
void *ptr = Amalloc (z); // Get space
134
134
memset ( ptr, 0 , z ); // Zap space
135
135
return ptr; // Return space
136
136
}
137
137
138
138
// ------------------------------realloc----------------------------------------
139
- // Reallocate storage in Arena .
140
- void *Arena ::Arealloc ( void *old_ptr, size_t old_size, size_t new_size ) {
139
+ // Reallocate storage in AdlArena .
140
+ void *AdlArena ::Arealloc ( void *old_ptr, size_t old_size, size_t new_size ) {
141
141
char *c_old = (char *)old_ptr; // Handy name
142
142
// Stupid fast special case
143
143
if ( new_size <= old_size ) { // Shrink in-place
@@ -161,32 +161,32 @@ void *Arena::Arealloc( void *old_ptr, size_t old_size, size_t new_size ) {
161
161
}
162
162
163
163
// ------------------------------reset------------------------------------------
164
- // Reset this Arena to empty, and return this Arenas guts in a new Arena .
165
- Arena * Arena ::reset (void ) {
166
- Arena *a = new Arena (this ); // New empty arena
164
+ // Reset this AdlArena to empty, and return this AdlArenas guts in a new AdlArena .
165
+ AdlArena * AdlArena ::reset (void ) {
166
+ AdlArena *a = new AdlArena (this ); // New empty arena
167
167
_first = _chunk = NULL ; // Normal, new-arena initialization
168
168
_hwm = _max = NULL ;
169
- return a; // Return Arena with guts
169
+ return a; // Return AdlArena with guts
170
170
}
171
171
172
172
// ------------------------------contains---------------------------------------
173
- // Determine if pointer belongs to this Arena or not.
174
- bool Arena ::contains ( const void *ptr ) const {
173
+ // Determine if pointer belongs to this AdlArena or not.
174
+ bool AdlArena ::contains ( const void *ptr ) const {
175
175
if ( (void *)_chunk->bottom () <= ptr && ptr < (void *)_hwm )
176
176
return true ; // Check for in this chunk
177
- for ( Chunk *c = _first; c; c = c->_next )
177
+ for ( AdlChunk *c = _first; c; c = c->_next )
178
178
if ( (void *)c->bottom () <= ptr && ptr < (void *)c->top ())
179
- return true ; // Check for every chunk in Arena
180
- return false ; // Not in any Chunk , so not in Arena
179
+ return true ; // Check for every chunk in AdlArena
180
+ return false ; // Not in any AdlChunk , so not in AdlArena
181
181
}
182
182
183
183
// -----------------------------------------------------------------------------
184
184
// CHeapObj
185
185
186
- void * CHeapObj ::operator new (size_t size) throw () {
187
- return (void *) AllocateHeap (size);
186
+ void * AdlCHeapObj ::operator new (size_t size) throw () {
187
+ return (void *) AdlAllocateHeap (size);
188
188
}
189
189
190
- void CHeapObj ::operator delete (void * p){
190
+ void AdlCHeapObj ::operator delete (void * p){
191
191
free (p);
192
192
}
0 commit comments