1 /*
2 * Copyright (c) 2017, 2019, 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 *
157 // Further assume size is padded out to words
158 void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
159 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
160 debug_only(if (UseMallocOnly) return malloc(x);)
161 if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode))
162 return NULL;
163 if (_hwm + x > _max) {
164 return grow(x, alloc_failmode);
165 } else {
166 char *old = _hwm;
167 _hwm += x;
168 return old;
169 }
170 }
171
172 // Allocate with 'double' alignment. It is 8 bytes on sparc.
173 // In other cases Amalloc_D() should be the same as Amalloc_4().
174 void* Amalloc_D(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
175 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
176 debug_only(if (UseMallocOnly) return malloc(x);)
177 #if defined(SPARC) && !defined(_LP64)
178 #define DALIGN_M1 7
179 size_t delta = (((size_t)_hwm + DALIGN_M1) & ~DALIGN_M1) - (size_t)_hwm;
180 x += delta;
181 #endif
182 if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
183 return NULL;
184 if (_hwm + x > _max) {
185 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
186 } else {
187 char *old = _hwm;
188 _hwm += x;
189 #if defined(SPARC) && !defined(_LP64)
190 old += delta; // align to 8-bytes
191 #endif
192 return old;
193 }
194 }
195
196 // Fast delete in area. Common case is: NOP (except for storage reclaimed)
197 bool Afree(void *ptr, size_t size) {
198 #ifdef ASSERT
199 if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
200 if (UseMallocOnly) return true;
201 #endif
202 if (((char*)ptr) + size == _hwm) {
203 _hwm = (char*)ptr;
204 return true;
205 } else {
206 // Unable to fast free, so we just drop it.
207 return false;
208 }
209 }
210
211 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
|
1 /*
2 * Copyright (c) 2017, 2020, 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 *
157 // Further assume size is padded out to words
158 void *Amalloc_4(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
159 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
160 debug_only(if (UseMallocOnly) return malloc(x);)
161 if (!check_for_overflow(x, "Arena::Amalloc_4", alloc_failmode))
162 return NULL;
163 if (_hwm + x > _max) {
164 return grow(x, alloc_failmode);
165 } else {
166 char *old = _hwm;
167 _hwm += x;
168 return old;
169 }
170 }
171
172 // Allocate with 'double' alignment. It is 8 bytes on sparc.
173 // In other cases Amalloc_D() should be the same as Amalloc_4().
174 void* Amalloc_D(size_t x, AllocFailType alloc_failmode = AllocFailStrategy::EXIT_OOM) {
175 assert( (x&(sizeof(char*)-1)) == 0, "misaligned size" );
176 debug_only(if (UseMallocOnly) return malloc(x);)
177 if (!check_for_overflow(x, "Arena::Amalloc_D", alloc_failmode))
178 return NULL;
179 if (_hwm + x > _max) {
180 return grow(x, alloc_failmode); // grow() returns a result aligned >= 8 bytes.
181 } else {
182 char *old = _hwm;
183 _hwm += x;
184 return old;
185 }
186 }
187
188 // Fast delete in area. Common case is: NOP (except for storage reclaimed)
189 bool Afree(void *ptr, size_t size) {
190 #ifdef ASSERT
191 if (ZapResourceArea) memset(ptr, badResourceValue, size); // zap freed memory
192 if (UseMallocOnly) return true;
193 #endif
194 if (((char*)ptr) + size == _hwm) {
195 _hwm = (char*)ptr;
196 return true;
197 } else {
198 // Unable to fast free, so we just drop it.
199 return false;
200 }
201 }
202
203 void *Arealloc( void *old_ptr, size_t old_size, size_t new_size,
|