org.jikesrvm.mm.mmtk.gcspy
Class Util

java.lang.Object
  extended by org.mmtk.vm.gcspy.Util
      extended by org.jikesrvm.mm.mmtk.gcspy.Util
All Implemented Interfaces:
Constants

public class Util
extends Util
implements Constants

This class provides generally useful methods.


Field Summary
private static boolean DEBUG_
           
static int KILOBYTE
           
static int MEGABYTE
           
 
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
Util()
           
 
Method Summary
 Object createDataArray(Object templ, int numElements)
          Create an array of a particular type.
 void formatSize(Address buffer, int size)
          Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate
 Address formatSize(String format, int bufsize, int size)
          Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate
 void free(Address addr)
          Free an array of bytes previously allocated with malloc
 Address getBytes(String str)
          Convert a String to a 0-terminated array of bytes WARNING: we call out to String.length and String.charAt, both of which are interruptible.
 Address malloc(int size)
          Allocate an array of bytes with malloc
 int sprintf(Address str, Address format, Address value)
          sprintf(char *str, char *format, char* value)
 
Methods inherited from class org.mmtk.vm.gcspy.Util
dumpRange, numToBytes, numToBytes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEBUG_

private static final boolean DEBUG_
See Also:
Constant Field Values

KILOBYTE

public static final int KILOBYTE
See Also:
Constant Field Values

MEGABYTE

public static final int MEGABYTE
See Also:
Constant Field Values
Constructor Detail

Util

public Util()
Method Detail

malloc

public final Address malloc(int size)
Description copied from class: Util
Allocate an array of bytes with malloc

Specified by:
malloc in class Util
Parameters:
size - The size to allocate
Returns:
The start address of the memory allocated in C space
See Also:
Util.free(org.vmmagic.unboxed.Address)

free

public final void free(Address addr)
Description copied from class: Util
Free an array of bytes previously allocated with malloc

Specified by:
free in class Util
Parameters:
addr - The address of some memory previously allocated with malloc
See Also:
Util.malloc(int)

getBytes

public final Address getBytes(String str)
Convert a String to a 0-terminated array of bytes

WARNING: we call out to String.length and String.charAt, both of which are interruptible. We protect these calls with a swLock/swUnlock mechanism, as per VM.sysWrite on String.

Specified by:
getBytes in class Util
Parameters:
str - The string to convert
Returns:
The address of a null-terminated array in C-space

formatSize

public final void formatSize(Address buffer,
                             int size)
Description copied from class: Util
Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate

Specified by:
formatSize in class Util
Parameters:
buffer - The buffer (in C space) in which to place the formatted size
size - The size in bytes

formatSize

public final Address formatSize(String format,
                                int bufsize,
                                int size)
Description copied from class: Util
Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate

Specified by:
formatSize in class Util
Parameters:
format - A format string
bufsize - The size of a buffer large enough to hold the formatted result
size - The size in bytes

createDataArray

public Object createDataArray(Object templ,
                              int numElements)
Description copied from class: Util
Create an array of a particular type. The easiest way to use this is: Foo[] x = (Foo [])Stream.createDataArray(new Foo[0], numElements);

Specified by:
createDataArray in class Util
Parameters:
templ - a data array to use as a template
numElements - number of elements in new array
Returns:
the new array

sprintf

public final int sprintf(Address str,
                         Address format,
                         Address value)
Description copied from class: Util
sprintf(char *str, char *format, char* value)

Specified by:
sprintf in class Util
Parameters:
str - The destination 'string' (memory in C space)
format - The format 'string' (memory in C space)
value - The value 'string' (memory in C space)
Returns:
The number of characters printed (as returned by C's sprintf