Public Member Functions | Static Public Member Functions

nanojit::CodeAlloc Class Reference

Code memory allocator is a long lived manager for many code blocks that manages interaction with an underlying code memory allocator, sets page permissions. More...

#include <CodeAlloc.h>

Collaboration diagram for nanojit::CodeAlloc:

List of all members.

Public Member Functions

 CodeAlloc ()
 ~CodeAlloc ()
void reset ()
 return all the memory allocated through this allocator to the gcheap.
void alloc (NIns *&start, NIns *&end, size_t byteLimit)
 allocate some memory (up to 'byteLimit' bytes) for code returning pointers to the region.
void free (NIns *start, NIns *end)
 free a block of memory previously returned by alloc()
void freeAll (CodeList *&code)
 free several blocks
void addRemainder (CodeList *&code, NIns *start, NIns *end, NIns *holeStart, NIns *holeEnd)
 add the ranges [start, holeStart) and [holeEnd, end) to code, and free [holeStart, holeEnd) if the hole is >= minsize
size_t size ()
 return the number of bytes in all the code blocks in "code", including block overhead
void logStats ()
 print out stats about heap usage
void markAllExec ()
 protect all code managed by this CodeAlloc
void markExec (CodeList *&blocks)
 protect all mem in the block list
void markChunkExec (CodeList *term)
 protect an entire chunk
void markBlockWrite (CodeList *b)
 unprotect the code chunk containing just this one block

Static Public Member Functions

static void flushICache (CodeList *&blocks)
 flush the icache for all code in the list, before executing
static void flushICache (void *start, size_t len)
 flush the icache for a specific extent
static void add (CodeList *&code, NIns *start, NIns *end)
 add a block previously returned by alloc(), to code

Detailed Description

Code memory allocator is a long lived manager for many code blocks that manages interaction with an underlying code memory allocator, sets page permissions.

CodeAlloc provides APIs for allocating and freeing individual blocks of code memory (for methods, stubs, or compiled traces), static functions for managing lists of allocated code, and has a few pure virtual methods that embedders must implement to provide memory to the allocator.

A "chunk" is a region of memory obtained from allocCodeChunk; it must be page aligned and be a multiple of the system page size.

A "block" is a region of memory within a chunk. It can be arbitrarily sized and aligned, but is always contained within a single chunk. class CodeList represents one block; the members of CodeList track the extent of the block and support creating lists of blocks.

The allocator coalesces free blocks when it can, in free(), but never coalesces chunks.


Constructor & Destructor Documentation

nanojit::CodeAlloc::CodeAlloc (  ) 
nanojit::CodeAlloc::~CodeAlloc (  ) 

Member Function Documentation

static void nanojit::CodeAlloc::add ( CodeList *&  code,
NIns start,
NIns end 
) [static]

add a block previously returned by alloc(), to code

void nanojit::CodeAlloc::addRemainder ( CodeList *&  code,
NIns start,
NIns end,
NIns holeStart,
NIns holeEnd 
)

add the ranges [start, holeStart) and [holeEnd, end) to code, and free [holeStart, holeEnd) if the hole is >= minsize

void nanojit::CodeAlloc::alloc ( NIns *&  start,
NIns *&  end,
size_t  byteLimit 
)

allocate some memory (up to 'byteLimit' bytes) for code returning pointers to the region.

A zero 'byteLimit' means no limit

static void nanojit::CodeAlloc::flushICache ( CodeList *&  blocks  )  [static]

flush the icache for all code in the list, before executing

static void nanojit::CodeAlloc::flushICache ( void *  start,
size_t  len 
) [static]

flush the icache for a specific extent

void nanojit::CodeAlloc::free ( NIns start,
NIns end 
)

free a block of memory previously returned by alloc()

void nanojit::CodeAlloc::freeAll ( CodeList *&  code  ) 

free several blocks

void nanojit::CodeAlloc::logStats (  ) 

print out stats about heap usage

void nanojit::CodeAlloc::markAllExec (  ) 

protect all code managed by this CodeAlloc

void nanojit::CodeAlloc::markBlockWrite ( CodeList b  ) 

unprotect the code chunk containing just this one block

void nanojit::CodeAlloc::markChunkExec ( CodeList term  ) 

protect an entire chunk

void nanojit::CodeAlloc::markExec ( CodeList *&  blocks  ) 

protect all mem in the block list

void nanojit::CodeAlloc::reset (  ) 

return all the memory allocated through this allocator to the gcheap.

size_t nanojit::CodeAlloc::size (  ) 

return the number of bytes in all the code blocks in "code", including block overhead

return the total number of bytes held by this CodeAlloc.


The documentation for this class was generated from the following file: