1 /*
2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
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 *
182 #define DALIGN_M1 7
183 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm;
184 x += delta;
185 #endif
186 if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
187 return NULL;
188 NOT_PRODUCT(inc_bytes_allocated(x);)
189 if (_hwm + x > _max) {
190 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
191 } else {
192 char *old = _hwm;
193 _hwm += x;
194 #if defined(SPARC) && !defined(_LP64)
195 old += delta; // align to 8-bytes
196 #endif
197 return old;
198 }
199 }
200
201 // Fast delete in area. Common case is: NOP (except for storage reclaimed)
202 void Afree(void *ptr, size_t size) {
203 #ifdef ASSERT
204 if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
205 if (UseMallocOnly) return;
206 #endif
207 if (((char*)ptr) + size == _hwm) _hwm = (char*)ptr;
208 }
209
210 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
211 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
212
213 // Move contents of this arena into an empty arena
214 Arena *move_contents(Arena *empty_arena);
215
216 // Determine if pointer belongs to this Arena or not.
217 bool contains( const void *ptr ) const;
218
219 // Total of all chunks in use (not thread-safe)
220 size_t used() const;
221
222 // Total # of bytes used
223 size_t size_in_bytes() const { return _size_in_bytes; };
224 void set_size_in_bytes(size_t size);
225
226 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN;
227 static void free_all(char** start, char** end) PRODUCT_RETURN;
|
1 /*
2 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
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
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 *
182 #define DALIGN_M1 7
183 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm;
184 x += delta;
185 #endif
186 if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
187 return NULL;
188 NOT_PRODUCT(inc_bytes_allocated(x);)
189 if (_hwm + x > _max) {
190 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
191 } else {
192 char *old = _hwm;
193 _hwm += x;
194 #if defined(SPARC) && !defined(_LP64)
195 old += delta; // align to 8-bytes
196 #endif
197 return old;
198 }
199 }
200
201 // Fast delete in area. Common case is: NOP (except for storage reclaimed)
202 bool Afree(void *ptr, size_t size) {
203 #ifdef ASSERT
204 if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
205 if (UseMallocOnly) return true;
206 #endif
207 if (((char*)ptr) + size == _hwm) {
208 _hwm = (char*)ptr;
209 return true;
210 } else {
211 // Unable to fast free, so we just drop it.
212 return false;
213 }
214 }
215
216 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
217 AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM);
218
219 // Move contents of this arena into an empty arena
220 Arena *move_contents(Arena *empty_arena);
221
222 // Determine if pointer belongs to this Arena or not.
223 bool contains( const void *ptr ) const;
224
225 // Total of all chunks in use (not thread-safe)
226 size_t used() const;
227
228 // Total # of bytes used
229 size_t size_in_bytes() const { return _size_in_bytes; };
230 void set_size_in_bytes(size_t size);
231
232 static void free_malloced_objects(Chunk* chunk, char* hwm, char* max, char* hwm2) PRODUCT_RETURN;
233 static void free_all(char** start, char** end) PRODUCT_RETURN;
|