org.jikesrvm
Class Services

java.lang.Object
  extended by org.jikesrvm.Services
All Implemented Interfaces:
SizeConstants

public class Services
extends Object
implements SizeConstants

Various service utilities. This is a common place for some shared utility routines


Field Summary
private static char[] dumpBuffer
          Pre-allocate the dump buffer, since dump() might get called inside GC.
private static int dumpBufferLock
           
private static Offset dumpBufferLockOffset
          Reset at boot time.
private static char[] hexDigitCharacter
          A map of hexadecimal digit values to their character representations.
private static int INT_BUFFER_SIZE
          How many characters we need to have in a buffer for building string representations of longs, such as intBuffer.
private static char[] intBuffer
          A buffer for building string representations of longs
private static int intBufferLock
          A lock for intBuffer
private static Offset intBufferLockOffset
          The offset of intBufferLock in this class's TIB.
static int MAX_DUMP_LEN
          Biggest buffer you would possibly need for RVMThread.dump(char[], int) Modify this if you modify that method.
 
Fields inherited from interface org.jikesrvm.SizeConstants
BITS_IN_ADDRESS, BITS_IN_BOOLEAN, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_DOUBLE, BITS_IN_EXTENT, BITS_IN_FLOAT, BITS_IN_INT, BITS_IN_LONG, BITS_IN_OFFSET, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BOOLEAN, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_DOUBLE, BYTES_IN_EXTENT, BYTES_IN_FLOAT, BYTES_IN_INT, BYTES_IN_LONG, BYTES_IN_OFFSET, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BOOLEAN, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_DOUBLE, LOG_BITS_IN_EXTENT, LOG_BITS_IN_FLOAT, LOG_BITS_IN_INT, LOG_BITS_IN_LONG, LOG_BITS_IN_OFFSET, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_BOOLEAN, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_DOUBLE, LOG_BYTES_IN_EXTENT, LOG_BYTES_IN_FLOAT, LOG_BYTES_IN_INT, LOG_BYTES_IN_LONG, LOG_BYTES_IN_OFFSET, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD
 
Constructor Summary
Services()
           
 
Method Summary
static void boot()
          Called during the boot sequence, any time before we go multi-threaded.
static void breakStub()
           
static byte[] getArrayNoBarrier(byte[][] src, int index)
          Gets an element of an array of byte arrays without causing the potential thread switch point that array accesses normally cause.
static byte getArrayNoBarrier(byte[] src, int index)
          Gets an element of a byte array without invoking any read barrier or bounds check.
static char getArrayNoBarrier(char[] src, int index)
          Gets an element of a char array without invoking any read barrier or performing bounds check.
static int getArrayNoBarrier(int[] src, int index)
          Gets an element of an int array without invoking any read barrier or performing bounds checks.
static Object getArrayNoBarrier(Object[] src, int index)
          Gets an element of an Object array without invoking any read barrier or performing bounds checks.
static String getHexString(int i, boolean blank)
          Utility printing function.
static char[] grabDumpBuffer()
           
private static char[] grabIntBuffer()
          Get exclusive access to intBuffer, the buffer for building string representations of integers.
static void percentage(int numerator, int denominator, String quantity)
           
(package private) static void percentage(long numerator, long denominator, String quantity)
           
(package private) static void print(int i)
           
(package private) static void print(String s)
           
(package private) static void print(String s, int i)
           
(package private) static void println()
           
(package private) static void println(int i)
           
(package private) static void println(String s)
           
(package private) static void println(String s, int i)
           
static void releaseDumpBuffer()
           
private static void releaseIntBuffer()
          Release intBuffer, the buffer for building string representations of integers.
static void setArrayNoBarrier(char[] dst, int index, char value)
          Sets an element of a char array without invoking any write barrier.
static void setArrayUninterruptible(Object[] dst, int index, Object value)
          Sets an element of a object array without possibly losing control.
static int sprintf(char[] dest, int destOffset, char c)
           
static int sprintf(char[] dest, int destOffset, char[] src)
           
static int sprintf(char[] dest, int destOffset, char[] src, int srcStart, int srcEnd)
          Copies characters from src into the destination character array dest.
static int sprintf(char[] dest, int offset, long l)
          Copy the printed decimal representation of a long into a character array.
static int sprintf(char[] dest, int destOffset, String s)
          Copy a String into a character array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_DUMP_LEN

public static final int MAX_DUMP_LEN
Biggest buffer you would possibly need for RVMThread.dump(char[], int) Modify this if you modify that method.

See Also:
Constant Field Values

dumpBuffer

private static final char[] dumpBuffer
Pre-allocate the dump buffer, since dump() might get called inside GC.


dumpBufferLock

private static int dumpBufferLock

dumpBufferLockOffset

private static Offset dumpBufferLockOffset
Reset at boot time.


hexDigitCharacter

private static final char[] hexDigitCharacter
A map of hexadecimal digit values to their character representations.

XXX We currently only use '0' through '9'. The rest are here pending possibly merging this code with the similar code in Log.java, or breaking this code out into a separate utility class.


INT_BUFFER_SIZE

private static final int INT_BUFFER_SIZE
How many characters we need to have in a buffer for building string representations of longs, such as intBuffer. A long is a signed 64-bit integer in the range -2^63 to 2^63+1. The number of digits in the decimal representation of 2^63 is ceiling(log10(2^63)) == ceiling(63 * log10(2)) == 19. An extra character may be required for a minus sign (-). So the maximum number of characters is 20.

See Also:
Constant Field Values

intBuffer

private static final char[] intBuffer
A buffer for building string representations of longs


intBufferLock

private static int intBufferLock
A lock for intBuffer


intBufferLockOffset

private static Offset intBufferLockOffset
The offset of intBufferLock in this class's TIB. This is set properly at boot time, even though it's a private variable. .

Constructor Detail

Services

public Services()
Method Detail

boot

public static void boot()
Called during the boot sequence, any time before we go multi-threaded. We do this so that we can leave the lockOffsets set to -1 until the VM actually needs the locking (and is running multi-threaded).


grabDumpBuffer

public static char[] grabDumpBuffer()

releaseDumpBuffer

public static void releaseDumpBuffer()

sprintf

public static int sprintf(char[] dest,
                          int destOffset,
                          String s)
Copy a String into a character array.

This function may be called during GC and may be used in conjunction with the MMTk Log class. It avoids write barriers and allocation.

XXX This function should probably be moved to a sensible location where we can use it as a utility. Suggestions welcome.

Parameters:
dest - char array to copy into.
destOffset - Offset into dest where we start copying
Returns:
1 plus the index of the last character written. If we were to write zero characters (which we won't) then we would return offset. This is intended to represent the first unused position in the array dest. However, it also serves as a pseudo-overflow check: It may have the value dest.length, if the array dest was completely filled by the call, or it may have a value greater than dest.length, if the info needs more than dest.length - offset characters of space.

sprintf

public static int sprintf(char[] dest,
                          int destOffset,
                          char[] src)

sprintf

public static int sprintf(char[] dest,
                          int destOffset,
                          char[] src,
                          int srcStart,
                          int srcEnd)
Copies characters from src into the destination character array dest.

The first character to be copied is at index srcBegin; the last character to be copied is at index srcEnd-1. (This is the same convention as followed by java.lang.String#getChars).

Parameters:
dest - char array to copy into.
destOffset - Offset into dest where we start copying
src - Char array to copy from
srcStart - index of the first character of src to copy.
srcEnd - index after the last character of src to copy.

sprintf

public static int sprintf(char[] dest,
                          int destOffset,
                          char c)

sprintf

public static int sprintf(char[] dest,
                          int offset,
                          long l)
Copy the printed decimal representation of a long into a character array. The value is not padded and no thousands separator is copied. If the value is negative a leading minus sign (-) is copied.

This function may be called during GC and may be used in conjunction with the Log class. It avoids write barriers and allocation.

XXX This function should probably be moved to a sensible location where we can use it as a utility. Suggestions welcome.

XXX This method's implementation is stolen from the Log class.

Parameters:
dest - char array to copy into.
offset - Offset into dest where we start copying
Returns:
1 plus the index of the last character written. If we were to write zero characters (which we won't) then we would return offset. This is intended to represent the first unused position in the array dest. However, it also serves as a pseudo-overflow check: It may have the value dest.length, if the array dest was completely filled by the call, or it may have a value greater than dest.length, if the info needs more than dest.length - offset characters of space.

grabIntBuffer

private static char[] grabIntBuffer()
Get exclusive access to intBuffer, the buffer for building string representations of integers.


releaseIntBuffer

private static void releaseIntBuffer()
Release intBuffer, the buffer for building string representations of integers.


getHexString

public static String getHexString(int i,
                                  boolean blank)
Utility printing function.

Parameters:
i -
blank -

breakStub

public static void breakStub()

println

static void println()

print

static void print(String s)

println

static void println(String s)

print

static void print(int i)

println

static void println(int i)

print

static void print(String s,
                  int i)

println

static void println(String s,
                    int i)

percentage

public static void percentage(int numerator,
                              int denominator,
                              String quantity)

percentage

static void percentage(long numerator,
                       long denominator,
                       String quantity)

setArrayUninterruptible

public static void setArrayUninterruptible(Object[] dst,
                                           int index,
                                           Object value)
Sets an element of a object array without possibly losing control. NB doesn't perform checkstore or array index checking.

Parameters:
dst - the destination array
index - the index of the element to set
value - the new value for the element

setArrayNoBarrier

public static void setArrayNoBarrier(char[] dst,
                                     int index,
                                     char value)
Sets an element of a char array without invoking any write barrier. This method is called by the Log method, as it will be used during garbage collection and needs to manipulate character arrays without causing a write barrier operation.

Parameters:
dst - the destination array
index - the index of the element to set
value - the new value for the element

getArrayNoBarrier

public static Object getArrayNoBarrier(Object[] src,
                                       int index)
Gets an element of an Object array without invoking any read barrier or performing bounds checks.

Parameters:
src - the source array
index - the natural array index of the element to get
Returns:
the new value of element

getArrayNoBarrier

public static int getArrayNoBarrier(int[] src,
                                    int index)
Gets an element of an int array without invoking any read barrier or performing bounds checks.

Parameters:
src - the source array
index - the natural array index of the element to get
Returns:
the new value of element

getArrayNoBarrier

public static char getArrayNoBarrier(char[] src,
                                     int index)
Gets an element of a char array without invoking any read barrier or performing bounds check.

Parameters:
src - the source array
index - the natural array index of the element to get
Returns:
the new value of element

getArrayNoBarrier

public static byte getArrayNoBarrier(byte[] src,
                                     int index)
Gets an element of a byte array without invoking any read barrier or bounds check.

Parameters:
src - the source array
index - the natural array index of the element to get
Returns:
the new value of element

getArrayNoBarrier

public static byte[] getArrayNoBarrier(byte[][] src,
                                       int index)
Gets an element of an array of byte arrays without causing the potential thread switch point that array accesses normally cause.

Parameters:
src - the source array
index - the index of the element to get
Returns:
the new value of element