org.mmtk.utility
Class Log

java.lang.Object
  extended by org.mmtk.utility.Log
All Implemented Interfaces:
Constants

public class Log
extends Object
implements Constants

Error and trace logging.


Field Summary
private  char[] buffer
          buffer to store written message until flushing
private  int bufferIndex
          location of next character to be written
private static String HEX_PREFIX
          string that prefixes numbers logged in hexadecimal
private static char[] hexDigitCharacter
          map of hexadecimal digit values to their character representations
private static Log log
          log instance used at build time.
private static int LOG_BITS_IN_HEX_DIGIT
          log2 of number of bits represented by a single hexidemimal digit
private static int LOG_HEX_DIGITS_IN_BYTE
          log2 of number of digits in the unsigned hexadecimal representation of a byte
private static int MESSAGE_BUFFER_SIZE
          characters in the write buffer for the caller's message.
private static char NEW_LINE_CHAR
          new line character.
private  boolean overflow
          true if the buffer has overflown
private static String OVERFLOW_MESSAGE
          message added when the write buffer has overflown
private static char OVERFLOW_MESSAGE_FIRST_CHAR
           
private static int OVERFLOW_SIZE
          characters in the overflow message, including the (optional) final newline
private  char overflowLastChar
          The last character that was written by #addToBuffer(char).
private static int TEMP_BUFFER_SIZE
          characters in buffer for building string representations of longs.
private  char[] tempBuffer
          buffer for building string representations of longs
private  boolean threadIdFlag
          true if a thread id will be prepended
 
Fields inherited from interface org.mmtk.utility.Constants
ALIGNMENT_VALUE, ARRAY_ELEMENT, BITS_IN_ADDRESS, BITS_IN_BYTE, BITS_IN_CHAR, BITS_IN_INT, BITS_IN_PAGE, BITS_IN_SHORT, BITS_IN_WORD, BYTES_IN_ADDRESS, BYTES_IN_BYTE, BYTES_IN_CHAR, BYTES_IN_INT, BYTES_IN_KBYTE, BYTES_IN_MBYTE, BYTES_IN_PAGE, BYTES_IN_SHORT, BYTES_IN_WORD, CARD_MASK, CARD_META_PAGES_PER_REGION, INSTANCE_FIELD, LOG_BITS_IN_ADDRESS, LOG_BITS_IN_BYTE, LOG_BITS_IN_CHAR, LOG_BITS_IN_INT, LOG_BITS_IN_PAGE, LOG_BITS_IN_SHORT, LOG_BITS_IN_WORD, LOG_BYTES_IN_ADDRESS, LOG_BYTES_IN_ADDRESS_SPACE, LOG_BYTES_IN_BYTE, LOG_BYTES_IN_CHAR, LOG_BYTES_IN_INT, LOG_BYTES_IN_KBYTE, LOG_BYTES_IN_MBYTE, LOG_BYTES_IN_PAGE, LOG_BYTES_IN_SHORT, LOG_BYTES_IN_WORD, LOG_CARD_BYTES, LOG_CARD_GRAIN, LOG_CARD_META_BYTES, LOG_CARD_META_PAGES, LOG_CARD_META_SIZE, LOG_CARD_UNITS, LOG_MIN_ALIGNMENT, MAX_ALIGNMENT, MAX_BYTES_PADDING, MAX_INT, MIN_ALIGNMENT, MIN_INT, SUPPORT_CARD_SCANNING
 
Constructor Summary
Log()
          constructor
 
Method Summary
private static void add(char c)
          adds a character to the buffer
private static void add(String s)
          adds a string to the buffer
private  void addToBuffer(char c)
          adds a character to the buffer
private  void addToBuffer(String s)
          adds a string to the buffer
static void flush()
          flushes the buffer.
private  void flushBuffer()
          flushes the buffer
private static char[] getIntBuffer()
          gets the buffer for building string representations of integers.
private static Log getLog()
           
private  char[] getTempBuffer()
          gets the buffer for building string representations of integers.
static void prependThreadId()
          Log a thread identifier at the start of the next message flushed.
private  void setThreadIdFlag()
          sets the flag so that a thread identifier will be included before the logged message
static void write(Address a)
          writes an address, in hexadecimal.
static void write(boolean b)
          writes a boolean.
static void write(byte[] b)
          writes an array of bytes.
static void write(char c)
          writes a character
static void write(char[] c)
          writes an array of characters
static void write(char[] c, int len)
          writes the start of an array of characters
static void write(double d)
          writes a double.
static void write(double d, int postDecimalDigits)
          writes a double.
static void write(Extent e)
          writes an extent, in hexadecimal.
static void write(long l)
          writes a long, in decimal.
static void write(ObjectReference o)
          writes an object reference, in hexadecimal.
static void write(Offset o)
          writes an offset, in hexadecimal.
static void write(String s)
          writes a string
static void write(String s, Address a)
          writes a string followed by an address, in hexadecimal.
static void write(String s, long l)
          Write a string followed by a long
static void write(Word w)
          writes a word, in hexadecimal.
static void writeDec(Word w)
          writes a word, in decimal.
private static void writeHex(Word w, int bytes)
          writes a long in hexadecimal
static void writeln()
          write a new-line and flushes the buffer
static void writeln(Address a)
          writes an address, in hexadecimal, and a new-line, then flushes the buffer.
static void writeln(Address a, boolean flush)
          writes an address, in hexadecimal, and a new-line, then optionally flushes the buffer.
static void writeln(boolean b)
          writes a boolean and a new-line, then flushes the buffer.
static void writeln(boolean b, boolean flush)
          writes a boolean and a new-line, then optionally flushes the buffer.
static void writeln(byte[] b)
          writes an array of bytes and a new-line, then flushes the buffer.
static void writeln(byte[] b, boolean flush)
          writes an array of bytes and a new-line, then optionally flushes the buffer.
static void writeln(char c)
          writes a character and a new-line, then flushes the buffer.
static void writeln(char[] ca)
          writes an array of characters and a new-line, then flushes the buffer.
static void writeln(char[] ca, boolean flush)
          writes an array of characters and a new-line, then optionally flushes the buffer.
static void writeln(char[] ca, int len)
          writes the start of an array of characters and a new-line, then flushes the buffer.
static void writeln(char[] ca, int len, boolean flush)
          writes the start of an array of characters and a new-line, then optionally flushes the buffer.
static void writeln(char c, boolean flush)
          writes a character and a new-line, then optionally flushes the buffer.
static void writeln(double d)
          writes a double and a new-line, then flushes the buffer.
static void writeln(double d, boolean flush)
          writes a double and a new-line, then optionally flushes the buffer.
static void writeln(double d, int postDecimalDigits)
          writes a double and a new-line, then flushes the buffer.
static void writeln(double d, int postDecimalDigits, boolean flush)
          writes a double and a new-line, then optionally flushes the buffer.
static void writeln(Extent e)
          writes an extent, in hexadecimal, and a new-line, then flushes the buffer.
static void writeln(Extent e, boolean flush)
          writes an extent, in hexadecimal, and a new-line, then optionally flushes the buffer.
static void writeln(long l)
          writes a long, in decimal, and a new-line, then flushes the buffer.
static void writeln(long l, boolean flush)
          writes a long, in decimal, and a new-line, then optionally flushes the buffer.
static void writeln(ObjectReference o)
          writes an object reference, in hexadecimal, and a new-line, then flushes the buffer.
static void writeln(ObjectReference o, boolean flush)
          writes an object reference, in hexadecimal, and a new-line, then optionally flushes the buffer.
static void writeln(Offset o)
          writes an offset, in hexadecimal, and a new-line, then flushes the buffer.
static void writeln(Offset o, boolean flush)
          writes an offset, in hexadecimal, and a new-line, then optionally flushes the buffer.
static void writeln(String s)
          writes a string and a new-line, then flushes the buffer.
static void writeln(String s, Address a)
          writes a string followed by a Address
static void writeln(String s, boolean flush)
          writes a string and a new-line, then optionally flushes the buffer.
static void writeln(String s, long l)
           
static void writeln(Word w)
          writes a word, in hexadecimal, and a new-line, then flushes the buffer.
static void writeln(Word w, boolean flush)
          writes a word, in hexadecimal, and a new-line, then optionally flushes the buffer.
static void writelnNoFlush()
          writes a new-line without flushing the buffer
private static void writelnWithFlush(boolean flush)
          writes a new-line and optionally flushes the buffer
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_BUFFER_SIZE

private static final int MESSAGE_BUFFER_SIZE
characters in the write buffer for the caller's message. This does not include characters reserved for the overflow message.

This needs to be large because Jikes RVM's implementation of Lock.java logs a lot of information when there is potential GC deadlock.

See Also:
Constant Field Values

OVERFLOW_MESSAGE

private static final String OVERFLOW_MESSAGE
message added when the write buffer has overflown

See Also:
Constant Field Values

OVERFLOW_MESSAGE_FIRST_CHAR

private static final char OVERFLOW_MESSAGE_FIRST_CHAR

OVERFLOW_SIZE

private static final int OVERFLOW_SIZE
characters in the overflow message, including the (optional) final newline


TEMP_BUFFER_SIZE

private static final int TEMP_BUFFER_SIZE
characters in buffer for building string representations of longs. 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

HEX_PREFIX

private static final String HEX_PREFIX
string that prefixes numbers logged in hexadecimal

See Also:
Constant Field Values

LOG_BITS_IN_HEX_DIGIT

private static final int LOG_BITS_IN_HEX_DIGIT
log2 of number of bits represented by a single hexidemimal digit

See Also:
Constant Field Values

LOG_HEX_DIGITS_IN_BYTE

private static final int LOG_HEX_DIGITS_IN_BYTE
log2 of number of digits in the unsigned hexadecimal representation of a byte

See Also:
Constant Field Values

hexDigitCharacter

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


NEW_LINE_CHAR

private static final char NEW_LINE_CHAR
new line character. Emitted by writeln methods.

See Also:
Constant Field Values

log

private static Log log
log instance used at build time.


buffer

private char[] buffer
buffer to store written message until flushing


bufferIndex

private int bufferIndex
location of next character to be written


overflow

private boolean overflow
true if the buffer has overflown


overflowLastChar

private char overflowLastChar
The last character that was written by #addToBuffer(char). This is used to check whether we want to newline-terminate the text.


threadIdFlag

private boolean threadIdFlag
true if a thread id will be prepended


tempBuffer

private char[] tempBuffer
buffer for building string representations of longs

Constructor Detail

Log

public Log()
constructor

Method Detail

write

public static void write(boolean b)
writes a boolean. Either "true" or "false" is logged.

Parameters:
b - boolean value to be logged.

write

public static void write(char c)
writes a character

Parameters:
c - character to be logged

write

public static void write(long l)
writes a long, in decimal. The value is not padded and no thousands separator is logged. If the value is negative a leading minus sign (-) is logged.

Parameters:
l - long value to be logged

write

public static void write(double d)
writes a double. Two digits after the decimal point are always logged. The value is not padded and no thousands separator is used. If the value is negative a leading hyphen-minus (-) is logged. The decimal point is a full stop (.).

Parameters:
d - the double to be logged

write

public static void write(double d,
                         int postDecimalDigits)
writes a double. The number of digits after the decimal point is determined by postDecimalDigits. The value is not padded and not thousands separator is used. If the value is negative a leading hyphen-minus (-) is logged. The decimal point is a full stop (.) and is logged even if is zero. If d is greater than the largest representable value of type int, it is logged as "TooBig". Similarly, if it is less than the negative of the largest representable value, it is logged as "TooSmall". If d is NaN is is logged as "NaN".

Parameters:
d - the double to be logged
postDecimalDigits - the number of digits to be logged after the decimal point. If less than or equal to zero no digits are logged, but the decimal point is.

write

public static void write(char[] c)
writes an array of characters

Parameters:
c - the array of characters to be logged

write

public static void write(char[] c,
                         int len)
writes the start of an array of characters

Parameters:
c - the array of characters
len - the number of characters to be logged, starting with the first character

write

public static void write(byte[] b)
writes an array of bytes. The bytes are interpretted as characters.

Parameters:
b - the array of bytes to be logged

write

public static void write(String s)
writes a string

Parameters:
s - the string to be logged

write

public static void write(Word w)
writes a word, in hexadecimal. It is zero-padded to the size of an address.

Parameters:
w - the word to be logged

writeDec

public static void writeDec(Word w)
writes a word, in decimal.

Parameters:
w - the word to be logged

write

public static void write(Address a)
writes an address, in hexadecimal. It is zero-padded.

Parameters:
a - the address to be logged

write

public static void write(String s,
                         Address a)
writes a string followed by an address, in hexadecimal.

Parameters:
s - the string to be logged
a - the address to be logged
See Also:
write(String), write(Address)

write

public static void write(String s,
                         long l)
Write a string followed by a long

Parameters:
s - the string to be logged
l - the long to be logged
See Also:
write(String), write(long)

write

public static void write(ObjectReference o)
writes an object reference, in hexadecimal. It is zero-padded.

Parameters:
o - the object reference to be logged

write

public static void write(Offset o)
writes an offset, in hexadecimal. It is zero-padded.

Parameters:
o - the offset to be logged

write

public static void write(Extent e)
writes an extent, in hexadecimal. It is zero-padded.

Parameters:
e - the extent to be logged

writeln

public static void writeln()
write a new-line and flushes the buffer


writeln

public static void writeln(boolean b)
writes a boolean and a new-line, then flushes the buffer.

Parameters:
b - boolean value to be logged.
See Also:
write(boolean)

writeln

public static void writeln(char c)
writes a character and a new-line, then flushes the buffer.

Parameters:
c - character to be logged
See Also:
write(char)

writeln

public static void writeln(long l)
writes a long, in decimal, and a new-line, then flushes the buffer.

Parameters:
l - long value to be logged
See Also:
write(long)

writeln

public static void writeln(double d)
writes a double and a new-line, then flushes the buffer.

Parameters:
d - the double to be logged
See Also:
write(double)

writeln

public static void writeln(double d,
                           int postDecimalDigits)
writes a double and a new-line, then flushes the buffer.

Parameters:
d - the double to be logged
See Also:
write(double, int)

writeln

public static void writeln(char[] ca)
writes an array of characters and a new-line, then flushes the buffer.

Parameters:
ca - the array of characters to be logged
See Also:
write(char [])

writeln

public static void writeln(char[] ca,
                           int len)
writes the start of an array of characters and a new-line, then flushes the buffer.

Parameters:
ca - the array of characters
len - the number of characters to be logged, starting with the first character
See Also:
write(char[], int)

writeln

public static void writeln(byte[] b)
writes an array of bytes and a new-line, then flushes the buffer.

Parameters:
b - the array of bytes to be logged
See Also:
write(byte[])

writeln

public static void writeln(String s)
writes a string and a new-line, then flushes the buffer.

Parameters:
s - the string to be logged

writeln

public static void writeln(Word w)
writes a word, in hexadecimal, and a new-line, then flushes the buffer.

Parameters:
w - the word to be logged
See Also:
write(Word)

writeln

public static void writeln(Address a)
writes an address, in hexadecimal, and a new-line, then flushes the buffer.

Parameters:
a - the address to be logged
See Also:
write(Address)

writeln

public static void writeln(ObjectReference o)
writes an object reference, in hexadecimal, and a new-line, then flushes the buffer.

Parameters:
o - the object reference to be logged
See Also:
write(ObjectReference)

writeln

public static void writeln(Offset o)
writes an offset, in hexadecimal, and a new-line, then flushes the buffer.

Parameters:
o - the offset to be logged
See Also:
write(Offset)

writeln

public static void writeln(Extent e)
writes an extent, in hexadecimal, and a new-line, then flushes the buffer.

Parameters:
e - the extent to be logged
See Also:
write(Extent)

writelnNoFlush

public static void writelnNoFlush()
writes a new-line without flushing the buffer


writeln

public static void writeln(boolean b,
                           boolean flush)
writes a boolean and a new-line, then optionally flushes the buffer.

Parameters:
b - boolean value to be logged.
flush - if true then flushes the buffer
See Also:
write(boolean)

writeln

public static void writeln(char c,
                           boolean flush)
writes a character and a new-line, then optionally flushes the buffer.

Parameters:
c - character to be logged
flush - if true then flushes the buffer
See Also:
write(char)

writeln

public static void writeln(long l,
                           boolean flush)
writes a long, in decimal, and a new-line, then optionally flushes the buffer.

Parameters:
l - long value to be logged
flush - if true then flushes the buffer
See Also:
write(long)

writeln

public static void writeln(double d,
                           boolean flush)
writes a double and a new-line, then optionally flushes the buffer.

Parameters:
d - the double to be logged
flush - if true then flush the buffer
See Also:
write(double)

writeln

public static void writeln(double d,
                           int postDecimalDigits,
                           boolean flush)
writes a double and a new-line, then optionally flushes the buffer.

Parameters:
d - the double to be logged
flush - if true then flushes the buffer
See Also:
write(double, int)

writeln

public static void writeln(char[] ca,
                           boolean flush)
writes an array of characters and a new-line, then optionally flushes the buffer.

Parameters:
ca - the array of characters to be logged
flush - if true then flushes the buffer
See Also:
write(char [])

writeln

public static void writeln(char[] ca,
                           int len,
                           boolean flush)
writes the start of an array of characters and a new-line, then optionally flushes the buffer.

Parameters:
ca - the array of characters
len - the number of characters to be logged, starting with the first character
flush - if true then flushes the buffer
See Also:
write(char[], int)

writeln

public static void writeln(byte[] b,
                           boolean flush)
writes an array of bytes and a new-line, then optionally flushes the buffer.

Parameters:
b - the array of bytes to be logged
flush - if true then flushes the buffer
See Also:
write(byte[])

writeln

public static void writeln(String s,
                           boolean flush)
writes a string and a new-line, then optionally flushes the buffer.

Parameters:
s - the string to be logged
flush - if true then flushes the buffer

writeln

public static void writeln(String s,
                           long l)

writeln

public static void writeln(Word w,
                           boolean flush)
writes a word, in hexadecimal, and a new-line, then optionally flushes the buffer.

Parameters:
w - the word to be logged
flush - if true then flushes the buffer
See Also:
write(Word)

writeln

public static void writeln(Address a,
                           boolean flush)
writes an address, in hexadecimal, and a new-line, then optionally flushes the buffer.

Parameters:
a - the address to be logged
flush - if true then flushes the buffer
See Also:
write(Address)

writeln

public static void writeln(ObjectReference o,
                           boolean flush)
writes an object reference, in hexadecimal, and a new-line, then optionally flushes the buffer.

Parameters:
o - the object reference to be logged
flush - if true then flushes the buffer
See Also:
write(ObjectReference)

writeln

public static void writeln(Offset o,
                           boolean flush)
writes an offset, in hexadecimal, and a new-line, then optionally flushes the buffer.

Parameters:
o - the offset to be logged
flush - if true then flushes the buffer
See Also:
write(Offset)

writeln

public static void writeln(Extent e,
                           boolean flush)
writes an extent, in hexadecimal, and a new-line, then optionally flushes the buffer.

Parameters:
e - the extent to be logged
flush - if true then flushes the buffer
See Also:
write(Extent)

writeln

public static void writeln(String s,
                           Address a)
writes a string followed by a Address

Parameters:
s - the string to be logged
a - the Address to be logged
See Also:
write(String), write(Address)

prependThreadId

public static void prependThreadId()
Log a thread identifier at the start of the next message flushed.


flush

public static void flush()
flushes the buffer. The buffered effected of writes since the last flush will be logged in one block without output from other thread's logging interleaving.


writelnWithFlush

private static void writelnWithFlush(boolean flush)
writes a new-line and optionally flushes the buffer

Parameters:
flush - if true the buffer is flushed

writeHex

private static void writeHex(Word w,
                             int bytes)
writes a long in hexadecimal

Parameters:
w - the Word to be logged
bytes - the number of bytes from the long to be logged. If less than 8 then the least significant bytes are logged and some of the most significant bytes are ignored.

add

private static void add(char c)
adds a character to the buffer

Parameters:
c - the character to add

add

private static void add(String s)
adds a string to the buffer

Parameters:
s - the string to add

getLog

private static Log getLog()

addToBuffer

private void addToBuffer(char c)
adds a character to the buffer

Parameters:
c - the character to add

addToBuffer

private void addToBuffer(String s)
adds a string to the buffer

Parameters:
s - the string to add

flushBuffer

private void flushBuffer()
flushes the buffer


setThreadIdFlag

private void setThreadIdFlag()
sets the flag so that a thread identifier will be included before the logged message


getIntBuffer

private static char[] getIntBuffer()
gets the buffer for building string representations of integers. There is one of these buffers for each Log instance.


getTempBuffer

private char[] getTempBuffer()
gets the buffer for building string representations of integers.