Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

heap_simple.c File Reference


Detailed Description

simple heap management functions

This is the first of probably several implementations of heap management for this JVM implementation. It uses the simple OS/stdlib resources of malloc(3)/free(3) as the foundation for its management scheme. The memory allocation pointer is generated by malloc(3). Calling free(3) with this same pointer marks the block of memory as available for other allocation.

The common header file gc.h defines the prototypes for all heap allocation implementations by way of the CONFIG_HEAP_TYPE_xxx symbol definitions.

Control

$URL: https://svn.apache.org/path/name/heap_simple.c $ $Id: heap_simple.c 0 09/28/2005 dlydick $

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.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file heap_simple.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.

Functions

static rvoid heap_free_common_simple (rvoid *pheap_block)
 Release a previously allocated block back into the heap for future reallocation.
rvoid heap_free_data_simple (rvoid *pheap_block)
 Release a previously allocated data block back into the heap for future reallocation.
rvoid heap_free_method_simple (rvoid *pheap_block)
 Release a previously allocated method block back into the heap for future reallocation.
rvoid heap_free_stack_simple (rvoid *pheap_block)
 Release a previously allocated stack block back into the heap for future reallocation.
static rvoidheap_get_common_simple (int size, rboolean clrmem_flag)
 Simple heap allocation method that uses only malloc(3) and free(3).
rvoidheap_get_data_simple (int size, rboolean clrmem_flag)
 Allocate memory for a data area from heap to caller.
int heap_get_error_simple (rvoid *badptr)
 Allocation failure diagnostic.
rvoidheap_get_method_simple (int size, rboolean clrmem_flag)
 Allocate memory for a method from heap to caller.
rvoidheap_get_stack_simple (int size, rboolean clrmem_flag)
 Allocate memory for a stack area from heap to caller.
rvoid heap_init_simple ()
 Start up heap management methodology.
rvoid heap_shutdown_simple ()
 Shut down up heap management after JVM execution is finished.
static void heap_simple_c_dummy (void)

Variables

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_simple(). Typically found in <errno.h> or <sys/errno.h>.
static rlong heap_malloc_count = 0
 Number of calls to malloc(3).
static char * heap_simple_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/heap_simple.c $ $Id: heap_simple.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable."


Function Documentation

static void heap_simple_c_dummy void   )  [static]
 

Definition at line 53 of file heap_simple.c.

rvoid heap_init_simple  ) 
 

Start up heap management methodology.

In a malloc/free scheme, there is nothing to do, but in other methods there might be.

Parameters: rvoid

Returns:
rvoid

Definition at line 81 of file heap_simple.c.

References jvm_heap_initialized, and rtrue.

static rvoid* heap_get_common_simple int  size,
rboolean  clrmem_flag
[static]
 

Simple heap allocation method that uses only malloc(3) and free(3).

Parameters:
size Number of bytes to allocate
clrmem_flag Set memory to all zeroes (rtrue) or not (rfalse). If rtrue, clear the allocated block, otherwise return it with its existing contents.
Returns:
(rvoid *) to allocated area. This pointer may be cast to any desired data type. If size of zero bytes is requested, return rnull and let caller croak on SIGSEGV. If no memory is available or some OS system call error happened, throw error, but do not return.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no memory is available..
JVMCLASS_JAVA_LANG_INTERNALERROR if other allocation error.

Definition at line 155 of file heap_simple.c.

rvoid* heap_get_method_simple int  size,
rboolean  clrmem_flag
 

Allocate memory for a method from heap to caller.

When finished, this pointer should be sent back to heap_free_method_simple() for reallocation.

Note:
This implementation makes no distinction betwen method area heap and any other usage. Other implementations may choose to implement the JVM Spec section 3.5.4 more rigorously.
Parameters:
size Number of bytes to allocate
clrmem_flag Set memory to all zeroes (rtrue) or not (rfalse)
Returns:
(rvoid *) to allocated area. This pointer may be cast to any desired data type. If size of zero bytes is requested, return rnull and let caller croak on SIGSEGV. If no memory is available or some OS system call error happened, throw error, but do not return.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no memory is available.
JVMCLASS_JAVA_LANG_INTERNALERROR if other allocation error.

Definition at line 272 of file heap_simple.c.

rvoid* heap_get_stack_simple int  size,
rboolean  clrmem_flag
 

Allocate memory for a stack area from heap to caller.

When finished, this pointer should be sent back to heap_free_stack_simple() for reallocation.

Parameters:
size Number of bytes to allocate
clrmem_flag Set memory to all zeroes (rtrue) or not (rfalse)
Returns:
(rvoid *) to allocated area. This pointer may be cast to any desired data type. If size of zero bytes is requested, return rnull and let caller croak on SIGSEGV. If no memory is available or some OS system call error happened, throw error, but do not return.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no memory is available.
JVMCLASS_JAVA_LANG_INTERNALERROR if other allocation error.

Definition at line 314 of file heap_simple.c.

rvoid* heap_get_data_simple int  size,
rboolean  clrmem_flag
 

Allocate memory for a data area from heap to caller.

When finished, this pointer should be sent back to heap_free_data_simple() for reallocation.

Parameters:
size Number of bytes to allocate
clrmem_flag Set memory to all zeroes (rtrue) or not (rfalse)
Returns:
(rvoid *) to allocated area. This pointer may be cast to any desired data type. If size of zero bytes is requested, return rnull and let caller croak on SIGSEGV. If no memory is available or some OS system call error happened, throw error, but do not return.
Exceptions:
JVMCLASS_JAVA_LANG_OUTOFMEMORYERROR if no memory is available.
JVMCLASS_JAVA_LANG_INTERNALERROR if other allocation error.

Definition at line 356 of file heap_simple.c.

static rvoid heap_free_common_simple rvoid pheap_block  )  [static]
 

Release a previously allocated block back into the heap for future reallocation.

If a rnull pointer is passed in, ignore the request.

Parameters:
pheap_block An (rvoid *) previously returned by one of the heap_get_XXX_simple() functions.
Returns:
rvoid

Definition at line 383 of file heap_simple.c.

References heap_free_count.

rvoid heap_free_method_simple rvoid pheap_block  ) 
 

Release a previously allocated method block back into the heap for future reallocation.

Note:
This implementation makes no distinction betwen method area heap and any other usage. Other implementations may choose to implement the JVM Spec section 3.5.4 more rigorously.
Parameters:
pheap_block An (rvoid *) previously returned by heap_get_method_simple()
Returns:
rvoid

Definition at line 418 of file heap_simple.c.

rvoid heap_free_stack_simple rvoid pheap_block  ) 
 

Release a previously allocated stack block back into the heap for future reallocation.

Parameters:
pheap_block An (rvoid *) previously returned by heap_get_stack_simple()
Returns:
rvoid

Definition at line 439 of file heap_simple.c.

rvoid heap_free_data_simple rvoid pheap_block  ) 
 

Release a previously allocated data block back into the heap for future reallocation.

Parameters:
pheap_block An (rvoid *) previously returned by heap_get_data_simple()
Returns:
rvoid

Definition at line 460 of file heap_simple.c.

int heap_get_error_simple rvoid badptr  ) 
 

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.

Parameters:
badptr Return value from heap allocation function.
Returns:
ERROR0 when no error was found or non-null badptr given. heap_last_errno value otherwise.
< Typically found in <errno.h> or <sys/errno.h>

< Typically found in <errno.h> or <sys/errno.h>

< Typically found in <errno.h> or <sys/errno.h>

Definition at line 488 of file heap_simple.c.

References ERROR0, and heap_last_errno.

rvoid heap_shutdown_simple  ) 
 

Shut down up heap management after JVM execution is finished.

Parameters: rvoid

Returns:
rvoid
< Typically found in <errno.h> or <sys/errno.h>

Definition at line 524 of file heap_simple.c.


Variable Documentation

char* heap_simple_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/heap_simple.c $ $Id: heap_simple.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." [static]
 

Definition at line 53 of file heap_simple.c.

int heap_last_errno = 0 [static]
 

Most recent error code from malloc(3), for use by heap_get_error_simple(). Typically found in <errno.h> or <sys/errno.h>.

Definition at line 97 of file heap_simple.c.

rlong heap_malloc_count = 0 [static]
 

Number of calls to malloc(3).

One of two global variables providing rudimentary statistics for heap allocation history.

See also:
heap_free_count

Definition at line 110 of file heap_simple.c.

rlong heap_free_count = 0 [static]
 

Number of calls to free(3).

One of two global variables providing rudimentary statistics for heap allocation history.

See also:
heap_malloc_count

Definition at line 120 of file heap_simple.c.


Generated on Fri Sep 30 19:00:13 2005 by  doxygen 1.4.4