This is the second of two implementations of heap management. It extends the simple malloc/free scheme by adding a single large allocation for requests smaller tha a certain size. This was added due to an apparent internal limit in malloc(3) or
perhaps a kernel limit that after a certain number of calls and/or bytes of allocation and freeing, returns NULL for no apparent reason.
The common header file gc.h defines the prototypes for all heap allocation implementations by way of the CONFIG_HEAP_TYPE_xxx symbol definitions.
Here is a note taken from the original project README file:
(16) When nearing the end of the initial development, I ran across what is probably a memory configuration limit on my Solaris platform, which I did not bother to track down, but rather work around. It seems that when calling malloc(3C) or malloc(3MALLOC), after 2,280 malloc() allocations and 612 free() invocations, there is something under the covers that does a SIGSEGV, and it can happen in either routine. I therefore extended the heap mechanism to allocate 1M slots of 'n' bytes for small allocations up to this size. Everything else still uses malloc(). In this way, I was able to finish development on the JVM and release it to the ASF in a more timely manner. In other words, I will let the team fix it! I am not sure that the real project wants a static 'n + 1' MB data area just hanging around the runtime just because I did not take time to tune the system configuration!
This modified algorithm makes exactly two malloc() calls, one for an array of fixed size slots of (rbyte) and the other for an array of (rboolean) for rtrue/rfalse on whether a fixed-size memory slot is in use or not.
Copyright 2005 The Apache Software Foundation or its licensors, as applicable.
Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
Definition in file heap_bimodal.c.
#include "arch.h"
#include <errno.h>
#include <stdlib.h>
#include "jvmcfg.h"
#include "exit.h"
#include "gc.h"
#include "heap.h"
#include "jvmclass.h"
#include "util.h"
Go to the source code of this file.
Defines | |
#define | HEAP_NUMBER_OF_SLOTS 1048576 |
Number of slots of this size. | |
#define | HEAP_SLOT_SIZE 160 |
Small heap allocation area. | |
#define | LOCATE_SLOT |
Functions | |
static void | heap_bimodal_c_dummy (void) |
static rvoid | heap_free_common_bimodal (rvoid *pheap_block) |
Release a previously allocated block back into the heap for future reallocation. | |
rvoid | heap_free_data_bimodal (rvoid *pheap_block) |
Release a previously allocated data block back into the heap for future reallocation. | |
rvoid | heap_free_method_bimodal (rvoid *pheap_block) |
Release a previously allocated method block back into the heap for future reallocation. | |
rvoid | heap_free_stack_bimodal (rvoid *pheap_block) |
Release a previously allocated stack block back into the heap for future reallocation. | |
static rvoid * | heap_get_common_bimodal (int size, rboolean clrmem_flag) |
Allocate memory from heap to caller, judging which mode to use for allocation. | |
static rvoid * | heap_get_common_simple_bimodal (int size, rboolean clrmem_flag) |
Original heap allocation method that uses only malloc(3) and free(3). | |
rvoid * | heap_get_data_bimodal (int size, rboolean clrmem_flag) |
Allocate memory for a data area from heap to caller. | |
int | heap_get_error_bimodal (rvoid *badptr) |
Allocation failure diagnostic. | |
rvoid * | heap_get_method_bimodal (int size, rboolean clrmem_flag) |
Allocate memory for a method from heap to caller. | |
rvoid * | heap_get_stack_bimodal (int size, rboolean clrmem_flag) |
Allocate memory for a stack area from heap to caller. | |
rvoid | heap_init_bimodal () |
Start up heap management methodology. | |
rvoid | heap_shutdown_bimodal () |
Shut down up heap management after JVM execution is finished. | |
Variables | |
static char * | heap_bimodal_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/heap_bimodal.c $ $Id: heap_bimodal.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." |
static rlong | heap_free_count = 0 |
Number of calls to free(3). | |
static int | heap_last_errno = 0 |
Most recent error code from malloc(3), for use by heap_get_error_bimodal(). Typically found in <errno.h> or <sys/errno.h>. | |
static rlong | heap_malloc_count = 0 |
Number of calls to malloc(3). | |
static rbyte * | pheap_slot |
Pointer for physical allocation of heap block to manage. | |
static rboolean * | pheap_slot_in_use |
Pointer for physical allocation for slots in use. | |
static rlong | slot_alloc_count = 0 |
Number of allocations made from pheap_slot. | |
static rlong | slot_free_count = 0 |
Number of allocations freed from pheap_slot. |
|
Small heap allocation area. For allocations up to n bytes, use this instead of system allocation and thus minimize number of calls to malloc() and free(). After 2,280 calls to malloc(3C) and 612 to free(3C), the library would kick out a SIGSEGV for no apparent reason. Use of malloc(3MALLOC) and free(3MALLOC) did the same thing, with -lmalloc. Use of -lbsdmalloc was at an even lower number. Therefore, it seems best to delay the issue (See quotation above from README file.)
The value of the HEAP_SLOT_SIZE definition ABSOLUTELY MUST BE A MULTIPLE of 4!!! (prefer 8 for future 64-bit implementation). This is Definition at line 113 of file heap_bimodal.c. Referenced by heap_free_common_bimodal(), and heap_init_bimodal(). |
|
Number of slots of this size. Any number of slots is possible, up to the reasonable resource limits of the machine. Definition at line 121 of file heap_bimodal.c. Referenced by heap_init_bimodal(). |
|
|
|
Definition at line 79 of file heap_bimodal.c. |
|
Start up heap management methodology. In a malloc/free scheme, there is nothing to do, but here, the two blocks and pheap_slot must be allocated and initialized. Parameters: rvoid
Definition at line 149 of file heap_bimodal.c. References EXIT_HEAP_ALLOC, exit_jvm(), HEAP_NUMBER_OF_SLOTS, HEAP_SLOT_SIZE, jvm_heap_initialized, pheap_slot, pheap_slot_in_use, rfalse, rnull, rtrue, and sysErrMsg(). |
|
Original heap allocation method that uses only
Definition at line 287 of file heap_bimodal.c. References EXIT_HEAP_ALLOC, exit_throw_exception(), GC_RUN, heap_last_errno, heap_malloc_count, JVMCLASS_JAVA_LANG_INTERNALERROR, JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR, rnull, and rtrue. |
|
Allocate memory from heap to caller, judging which mode to use for allocation. When finished, this pointer should be sent back to heap_free_xxxx_bimodal() for reallocation.
< Typically found in <errno.h> or <sys/errno.h> Definition at line 420 of file heap_bimodal.c. References rnull. Referenced by heap_get_method_bimodal(), and heap_get_stack_bimodal(). |
|
Allocate memory for a method from heap to caller. When finished, this pointer should be sent back to heap_free_method_bimodal() for reallocation.
Definition at line 568 of file heap_bimodal.c. References heap_get_common_bimodal(). |
|
Allocate memory for a stack area from heap to caller. When finished, this pointer should be sent back to heap_free_stack_bimodal() for reallocation.
Definition at line 610 of file heap_bimodal.c. References heap_get_common_bimodal(). |
|
Allocate memory for a data area from heap to caller. When finished, this pointer should be sent back to heap_free_data_bimodal() for reallocation.
Definition at line 652 of file heap_bimodal.c. References rnull. |
|
Release a previously allocated block back into the heap for future reallocation. If a rnull pointer is passed in, ignore the request.
Definition at line 678 of file heap_bimodal.c. References HEAP_SLOT_SIZE, pheap_slot_in_use, rfalse, and slot_free_count. Referenced by heap_free_method_bimodal(), and heap_free_stack_bimodal(). |
|
Release a previously allocated method block back into the heap for future reallocation.
Definition at line 741 of file heap_bimodal.c. References heap_free_common_bimodal(). |
|
Release a previously allocated stack block back into the heap for future reallocation.
Definition at line 761 of file heap_bimodal.c. References heap_free_common_bimodal(). |
|
Release a previously allocated data block back into the heap for future reallocation.
Definition at line 781 of file heap_bimodal.c. References rnull. |
|
Allocation failure diagnostic. Returns an errno value per "errno.h" if a rnull pointer is passed in, namely from the most recent call to a heap allocation function. It may only be called once before the value is cleared. If a non-null pointer is passed in, ERROR0 is returned and the error status is again cleared.
< Typically found in <errno.h> or <sys/errno.h> < Typically found in <errno.h> or <sys/errno.h> Definition at line 809 of file heap_bimodal.c. |
|
Shut down up heap management after JVM execution is finished. Parameters: rvoid
Definition at line 845 of file heap_bimodal.c. |
|
Definition at line 79 of file heap_bimodal.c. |
|
Pointer for physical allocation for slots in use.
Definition at line 127 of file heap_bimodal.c. Referenced by heap_free_common_bimodal(), and heap_init_bimodal(). |
|
Pointer for physical allocation of heap block to manage.
Definition at line 132 of file heap_bimodal.c. Referenced by heap_init_bimodal(). |
|
Most recent error code from
Definition at line 200 of file heap_bimodal.c. Referenced by heap_get_common_simple_bimodal(), and heap_get_error_simple(). |
|
Number of calls to One of four global variables providing rudimentary statistics for heap allocation history.
Definition at line 215 of file heap_bimodal.c. Referenced by heap_get_common_simple_bimodal(). |
|
Number of calls to One of four global variables providing rudimentary statistics for heap allocation history.
Definition at line 227 of file heap_bimodal.c. Referenced by heap_free_common_simple(). |
|
Number of allocations made from pheap_slot. One of four global variables providing rudimentary statistics for heap allocation history.
Definition at line 239 of file heap_bimodal.c. |
|
Number of allocations freed from pheap_slot. One of four global variables providing rudimentary statistics for heap allocation history.
Definition at line 251 of file heap_bimodal.c. Referenced by heap_free_common_bimodal(). |