org.mmtk.vm.gcspy
Class Util

java.lang.Object
  extended by org.mmtk.vm.gcspy.Util
Direct Known Subclasses:
Util

public abstract class Util
extends Object

Abstract class that provides generally useful methods.


Constructor Summary
Util()
           
 
Method Summary
abstract  Object createDataArray(Object templ, int numElements)
          Create an array of a particular type.
static void dumpRange(Address start, Address end)
          Dump a range in format [start,end)
abstract  void formatSize(Address buffer, int size)
          Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate
abstract  Address formatSize(String format, int bufsize, int size)
          Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate
abstract  void free(Address addr)
          Free an array of bytes previously allocated with malloc
abstract  Address getBytes(String str)
          Convert a String to a 0-terminated array of bytes
abstract  Address malloc(int size)
          Allocate an array of bytes with malloc
static int numToBytes(byte[] buffer, long value)
          Place a string representation of a long in an array of bytes without incurring allocation
static int numToBytes(byte[] buffer, long value, int radix)
          Place a string representation of a long in an array of bytes without incurring allocation
abstract  int sprintf(Address str, Address format, Address value)
          sprintf(char *str, char *format, char* value)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

public Util()
Method Detail

malloc

public abstract Address malloc(int size)
Allocate an array of bytes with malloc

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

free

public abstract void free(Address addr)
Free an array of bytes previously allocated with malloc

Parameters:
addr - The address of some memory previously allocated with malloc
See Also:
malloc(int)

dumpRange

public static void dumpRange(Address start,
                             Address end)
Dump a range in format [start,end)

Parameters:
start - The start of the range
end - The end of the range

getBytes

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

Parameters:
str - The string to convert
Returns:
The address of a null-terminated array in C-space

formatSize

public abstract void formatSize(Address buffer,
                                int size)
Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate

Parameters:
buffer - The buffer (in C space) in which to place the formatted size
size - The size in bytes

formatSize

public abstract Address formatSize(String format,
                                   int bufsize,
                                   int size)
Pretty print a size, converting from bytes to kilo- or mega-bytes as appropriate

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

numToBytes

public static int numToBytes(byte[] buffer,
                             long value)
Place a string representation of a long in an array of bytes without incurring allocation

Parameters:
buffer - The byte array
value - The long to convert
Returns:
The length of the string representation of the integer -1 indicates some problem (e.g the char buffer was too small)

numToBytes

public static int numToBytes(byte[] buffer,
                             long value,
                             int radix)
Place a string representation of a long in an array of bytes without incurring allocation

Parameters:
buffer - The byte array
value - The long to convert
radix - the base to use for conversion
Returns:
The length of the string representation of the integer -1 indicates some problem (e.g the char buffer was too small)

sprintf

public abstract int sprintf(Address str,
                            Address format,
                            Address value)
sprintf(char *str, char *format, char* value)

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

createDataArray

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

Parameters:
templ - a data array to use as a template
numElements - number of elements in new array
Returns:
the new array