joeq.Allocator
Class CodeAllocator

java.lang.Object
  extended by joeq.Allocator.CodeAllocator
Direct Known Subclasses:
BootstrapCodeAllocator, RuntimeCodeAllocator

public abstract class CodeAllocator
extends Object

This class provides the abstract interface for code allocators. A code allocator handles the allocation and management of code buffers. It also provides static methods for keeping track of the compiled methods and their address ranges. It also includes an inner class that provides the interface for code buffers.

Version:
$Id: CodeAllocator.java,v 1.26 2004/09/30 03:35:30 joewhaley Exp $
Author:
John Whaley

Nested Class Summary
static class CodeAllocator.InstructionPointer
          An object of this class represents a code address.
static class CodeAllocator.x86CodeBuffer
          This class provides the interface for x86 code buffers.
 
Field Summary
static jq_Class _class
           
static jq_StaticField _compiledMethods
           
static jq_StaticField _highAddress
           
static jq_StaticField _lowAddress
           
static SortedMap compiledMethods
          Map of compiled methods, sorted by address.
static boolean TRACE
          Trace flag.
 
Constructor Summary
CodeAllocator()
           
 
Method Summary
abstract  CodeAllocator.x86CodeBuffer getCodeBuffer(int estimatedSize, int offset, int alignment)
          Allocate a code buffer of the given estimated size, such that the given offset will have the given alignment.
static jq_CompiledCode getCodeContaining(CodeAddress ip)
          Return the compiled code which contains the given code address.
static Iterator getCompiledMethods()
          Returns an iterator of the registered jq_CompiledCode objects, in address order.
static CodeAddress getHighAddress()
          Returns the highest address of any registered code.
static CodeAddress getLowAddress()
          Returns the lowest address of any registered code.
static int getNumberOfCompiledMethods()
          Returns the number of registered jq_CompiledCode objects.
abstract  void init()
          Initialize this code allocator.
static void initializeCompiledMethodMap()
           
abstract  void patchAbsolute(Address addr1, Address addr2)
          Patch the given address to refer to the other given address, in absolute terms.
abstract  void patchRelativeOffset(CodeAddress code, CodeAddress target)
          Patch the given code address to refer to the given code address, in relative terms.
static void registerCode(jq_CompiledCode cc)
          Register the given compiled code, so lookups by address will return this code.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TRACE

public static boolean TRACE
Trace flag.


compiledMethods

public static final SortedMap compiledMethods
Map of compiled methods, sorted by address.


_class

public static final jq_Class _class

_lowAddress

public static final jq_StaticField _lowAddress

_highAddress

public static final jq_StaticField _highAddress

_compiledMethods

public static final jq_StaticField _compiledMethods
Constructor Detail

CodeAllocator

public CodeAllocator()
Method Detail

init

public abstract void init()
Initialize this code allocator. This method is always called before the code allocator is actually used.


getCodeBuffer

public abstract CodeAllocator.x86CodeBuffer getCodeBuffer(int estimatedSize,
                                                          int offset,
                                                          int alignment)
Allocate a code buffer of the given estimated size, such that the given offset will have the given alignment. It is legal for code to exceed the estimated size, but the cost may be high (i.e. it may require recopying of the buffer.)

Parameters:
estimatedSize - estimated size, in bytes, of desired code buffer
offset - desired offset to align to
alignment - desired alignment, or 0 if don't care
Returns:
the new code buffer

patchAbsolute

public abstract void patchAbsolute(Address addr1,
                                   Address addr2)
Patch the given address to refer to the other given address, in absolute terms. This is used to patch heap address references in the code, and code references in the heap.

Parameters:
addr1 - address to patch
addr2 - address to patch to

patchRelativeOffset

public abstract void patchRelativeOffset(CodeAddress code,
                                         CodeAddress target)
Patch the given code address to refer to the given code address, in relative terms. This is used to patch branch targets in the code.

Parameters:
code - code address to patch
target - code address to patch to

initializeCompiledMethodMap

public static void initializeCompiledMethodMap()

registerCode

public static void registerCode(jq_CompiledCode cc)
Register the given compiled code, so lookups by address will return this code.

Parameters:
cc - compiled code to register

getCodeContaining

public static jq_CompiledCode getCodeContaining(CodeAddress ip)
Return the compiled code which contains the given code address. Returns null if there is no registered code that contains the given address.

Parameters:
ip - code address to check
Returns:
compiled code containing given address, or null

getLowAddress

public static CodeAddress getLowAddress()
Returns the lowest address of any registered code.

Returns:
lowest address of any registered code.

getHighAddress

public static CodeAddress getHighAddress()
Returns the highest address of any registered code.

Returns:
highest address of any registered code.

getCompiledMethods

public static Iterator getCompiledMethods()
Returns an iterator of the registered jq_CompiledCode objects, in address order.

Returns:
iterator of jq_CompiledCode objects

getNumberOfCompiledMethods

public static int getNumberOfCompiledMethods()
Returns the number of registered jq_CompiledCode objects.

Returns:
number of registered jq_CompiledCode objects


Copyright © 2001-2005 John Whaley. All Rights Reserved.