org.jikesrvm.runtime
Class Memory

java.lang.Object
  extended by org.jikesrvm.runtime.Memory

public class Memory
extends Object

Low level memory management functions. Note that this class is "uninterruptible" - calling its methods will never cause the current thread to yield the cpu to another thread (one that might cause a gc, for example).


Field Summary
private static int BYTES_IN_COPY
          Number of bytes used when copying larger chunks of memory.
static int MAP_ANONYMOUS
           
static int MAP_FIXED
           
static int MAP_PRIVATE
           
private static int NATIVE_THRESHOLD
          How many bytes is considered large enough to justify the transition to C code to use memcpy?
private static int pagesize
           
private static int pagesizeLog
           
static int PROT_EXEC
           
static int PROT_NONE
           
static int PROT_READ
           
static int PROT_WRITE
           
private static boolean USE_NATIVE
          Allow the use of C based memcpy
 
Constructor Summary
Memory()
           
 
Method Summary
static Address alignDown(Address address, int alignment)
           
static int alignDown(int address, int alignment)
           
static void aligned32Copy(Address dst, Address src, int numBytes)
           
static void aligned32Copy(Address dst, Address src, Offset numBytes)
          Copy numbytes from src to dst.
static void alignedWordCopy(Address dst, Address src, int numBytes)
          Copy numbytes from src to dst.
static Address alignUp(Address address, int alignment)
           
static int alignUp(int address, int alignment)
           
static void arraycopy16Bit(Address srcPtr, Address dstPtr, int copyBytes)
          Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos].
static void arraycopy16Bit(Object src, int srcPos, Object dst, int dstPos, int len)
          Low level copy of len elements from src[srcPos] to dst[dstPos].
static void arraycopy32Bit(Address srcPtr, Address dstPtr, int copyBytes)
          Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos].
static void arraycopy32Bit(Object src, int srcIdx, Object dst, int dstIdx, int len)
          Low level copy of len elements from src[srcPos] to dst[dstPos].
static void arraycopy64Bit(Address srcPtr, Address dstPtr, int copyBytes)
          Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos].
static void arraycopy64Bit(Object src, int srcIdx, Object dst, int dstIdx, int len)
          Low level copy of len elements from src[srcPos] to dst[dstPos].
static void arraycopy8Bit(Address srcPtr, Address dstPtr, int copyBytes)
          Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos].
static void arraycopy8Bit(Object src, int srcPos, Object dst, int dstPos, int len)
          Low level copy of len elements from src[srcPos] to dst[dstPos].
private static void copy1Bytes(Address dstPtr, Address srcPtr)
           
private static void copy2Bytes(Address dstPtr, Address srcPtr)
           
private static void copy4Bytes(Address dstPtr, Address srcPtr)
           
private static void copy8Bytes(Address dstPtr, Address srcPtr)
           
static void dumpMemory(Address start, int beforeBytes, int afterBytes)
           
static Address dzmmap(Address address, Extent size)
          Do mmap demand zero fixed address memory mapping call
static int getPagesize()
          Do getpagesize call
private static void internalAlignedWordCopy(Address dst, Address src, int numBytes)
          Copy numbytes from src to dst.
static boolean isPageAligned(Address addr)
           
static boolean isPageMultiple(Extent val)
           
static boolean isPageMultiple(int val)
           
static boolean isPageMultiple(Offset val)
           
static void memcopy(Address dst, Address src, Extent cnt)
          Copy a region of memory.
static void memcopy(Address dst, Address src, int cnt)
           
static Address mmap(Address address, Extent size, int prot, int flags)
          Do generic mmap non-file memory mapping call
static boolean mprotect(Address address, Extent size, int prot)
          Do mprotect system call
static void sync(Address address, int size)
          Synchronize a region of memory: force data in dcache to be written out to main memory so that it will be seen by icache when instructions are fetched back.
static void zero(Address start, Extent len)
          Zero a region of memory.
static void zeroPages(Address start, int len)
          Zero a range of pages of memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NATIVE_THRESHOLD

private static final int NATIVE_THRESHOLD
How many bytes is considered large enough to justify the transition to C code to use memcpy?

See Also:
Constant Field Values

USE_NATIVE

private static final boolean USE_NATIVE
Allow the use of C based memcpy

See Also:
Constant Field Values

BYTES_IN_COPY

private static final int BYTES_IN_COPY
Number of bytes used when copying larger chunks of memory. Normally 8 bytes except on x87 Intel

See Also:
Constant Field Values

PROT_NONE

public static final int PROT_NONE
See Also:
Constant Field Values

PROT_READ

public static final int PROT_READ
See Also:
Constant Field Values

PROT_WRITE

public static final int PROT_WRITE
See Also:
Constant Field Values

PROT_EXEC

public static final int PROT_EXEC
See Also:
Constant Field Values

MAP_PRIVATE

public static final int MAP_PRIVATE
See Also:
Constant Field Values

MAP_FIXED

public static final int MAP_FIXED
See Also:
Constant Field Values

MAP_ANONYMOUS

public static final int MAP_ANONYMOUS
See Also:
Constant Field Values

pagesize

private static int pagesize

pagesizeLog

private static int pagesizeLog
Constructor Detail

Memory

public Memory()
Method Detail

copy8Bytes

private static void copy8Bytes(Address dstPtr,
                               Address srcPtr)

copy4Bytes

private static void copy4Bytes(Address dstPtr,
                               Address srcPtr)

copy2Bytes

private static void copy2Bytes(Address dstPtr,
                               Address srcPtr)

copy1Bytes

private static void copy1Bytes(Address dstPtr,
                               Address srcPtr)

arraycopy8Bit

public static void arraycopy8Bit(Object src,
                                 int srcPos,
                                 Object dst,
                                 int dstPos,
                                 int len)
Low level copy of len elements from src[srcPos] to dst[dstPos]. Assumptions: src != dst || (scrPos >= dstPos + 4) and src and dst are 8Bit arrays.

Parameters:
src - the source array
srcPos - index in the source array to begin copy
dst - the destination array
dstPos - index in the destination array to being copy
len - number of array elements to copy

arraycopy8Bit

public static void arraycopy8Bit(Address srcPtr,
                                 Address dstPtr,
                                 int copyBytes)
Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos) and element size is 4 bytes.

Parameters:
srcPtr - The source start address
dstPtr - The destination start address
copyBytes - The number of bytes to be copied

arraycopy16Bit

public static void arraycopy16Bit(Object src,
                                  int srcPos,
                                  Object dst,
                                  int dstPos,
                                  int len)
Low level copy of len elements from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos + 2).

Parameters:
src - the source array
srcPos - index in the source array to begin copy
dst - the destination array
dstPos - index in the destination array to being copy
len - number of array elements to copy

arraycopy16Bit

public static void arraycopy16Bit(Address srcPtr,
                                  Address dstPtr,
                                  int copyBytes)
Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos) and element size is 2 bytes.

Parameters:
srcPtr - The source start address
dstPtr - The destination start address
copyBytes - The number of bytes to be copied

arraycopy32Bit

public static void arraycopy32Bit(Object src,
                                  int srcIdx,
                                  Object dst,
                                  int dstIdx,
                                  int len)
Low level copy of len elements from src[srcPos] to dst[dstPos]. Assumption: src != dst || (srcPos >= dstPos) and element size is 4 bytes.

Parameters:
src - the source array
srcIdx - index in the source array to begin copy
dst - the destination array
dstIdx - index in the destination array to being copy
len - number of array elements to copy

arraycopy32Bit

public static void arraycopy32Bit(Address srcPtr,
                                  Address dstPtr,
                                  int copyBytes)
Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos) and element size is 4 bytes.

Parameters:
srcPtr - The source start address
dstPtr - The destination start address
copyBytes - The number of bytes to be copied

arraycopy64Bit

public static void arraycopy64Bit(Object src,
                                  int srcIdx,
                                  Object dst,
                                  int dstIdx,
                                  int len)
Low level copy of len elements from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos) and element size is 8 bytes.

Parameters:
src - the source array
srcIdx - index in the source array to begin copy
dst - the destination array
dstIdx - index in the destination array to being copy
len - number of array elements to copy

arraycopy64Bit

public static void arraycopy64Bit(Address srcPtr,
                                  Address dstPtr,
                                  int copyBytes)
Low level copy of copyBytes bytes from src[srcPos] to dst[dstPos]. Assumption src != dst || (srcPos >= dstPos) and element size is 8 bytes.

Parameters:
srcPtr - The source start address
dstPtr - The destination start address
copyBytes - The number of bytes to be copied

aligned32Copy

public static void aligned32Copy(Address dst,
                                 Address src,
                                 Offset numBytes)
Copy numbytes from src to dst. Assumption either the ranges are non overlapping, or src >= dst + 4. Also, src and dst are 4 byte aligned and numBytes is a multiple of 4.

Parameters:
dst - the destination addr
src - the source addr
numBytes - the number of bytes top copy

aligned32Copy

public static void aligned32Copy(Address dst,
                                 Address src,
                                 int numBytes)

alignedWordCopy

public static void alignedWordCopy(Address dst,
                                   Address src,
                                   int numBytes)
Copy numbytes from src to dst. Assumption either the ranges are non overlapping, or src >= dst + BYTES_IN_ADDRESS. Also, src and dst are word aligned and numBytes is a multiple of BYTES_IN_ADDRESS.

Parameters:
dst - the destination addr
src - the source addr
numBytes - the number of bytes top copy

internalAlignedWordCopy

private static void internalAlignedWordCopy(Address dst,
                                            Address src,
                                            int numBytes)
Copy numbytes from src to dst. Assumption either the ranges are non overlapping, or src >= dst + BYTES_IN_ADDRESS.

Parameters:
dst - The destination addr
src - The source addr
numBytes - The number of bytes to copy

memcopy

public static void memcopy(Address dst,
                           Address src,
                           Extent cnt)
Copy a region of memory.

Parameters:
dst - Destination address
src - Source address
cnt - Number of bytes to copy Assumption: source and destination regions do not overlap

memcopy

public static void memcopy(Address dst,
                           Address src,
                           int cnt)

zero

public static void zero(Address start,
                        Extent len)
Zero a region of memory.

Parameters:
start - of address range (inclusive)
len - extent to zero.

zeroPages

public static void zeroPages(Address start,
                             int len)
Zero a range of pages of memory.

Parameters:
start - Starting address (must be a page address)
len - Number of bytes (must be multiple of page size)

sync

public static void sync(Address address,
                        int size)
Synchronize a region of memory: force data in dcache to be written out to main memory so that it will be seen by icache when instructions are fetched back.

Parameters:
address - Start of address range
size - Size of address range (bytes)

isPageMultiple

public static boolean isPageMultiple(int val)

isPageMultiple

public static boolean isPageMultiple(Extent val)

isPageMultiple

public static boolean isPageMultiple(Offset val)

isPageAligned

public static boolean isPageAligned(Address addr)

mmap

public static Address mmap(Address address,
                           Extent size,
                           int prot,
                           int flags)
Do generic mmap non-file memory mapping call

Parameters:
address - Start of address range (Address)
size - Size of address range
prot - Protection (int)
flags - (int)
Returns:
Address (of region) if successful; errno (1 to 127) otherwise

dzmmap

public static Address dzmmap(Address address,
                             Extent size)
Do mmap demand zero fixed address memory mapping call

Parameters:
address - Start of address range
size - Size of address range
Returns:
Address (of region) if successful; errno (1 to 127) otherwise

mprotect

public static boolean mprotect(Address address,
                               Extent size,
                               int prot)
Do mprotect system call

Parameters:
address - Start of address range (Address)
size - Size of address range
prot - Protection (int)
Returns:
true iff success

getPagesize

public static int getPagesize()
Do getpagesize call

Returns:
page size

dumpMemory

public static void dumpMemory(Address start,
                              int beforeBytes,
                              int afterBytes)

alignUp

public static Address alignUp(Address address,
                              int alignment)

alignDown

public static Address alignDown(Address address,
                                int alignment)

alignUp

public static int alignUp(int address,
                          int alignment)

alignDown

public static int alignDown(int address,
                            int alignment)