2010 FRC Java API


com.sun.squawk
Class GC

java.lang.Object
  extended by com.sun.squawk.GC

public class GC
extends Object

Pure static class that handles object creation and GC control and monitoring. The particular GC implementation used is a subclass of GarbageCollector. Many of the "public" methods of this class are actually "suite-private". See the file "squawk.library.properties" for the list of exported methods.


Nested Class Summary
static class GC.ClassStat
           
 
Method Summary
static void arraycopy(Object src, int srcPos, Object dst, int dstPos, int lth)
          Copy data from one array to another.
static int calculateOopMapSizeInBytes(int size)
          Calculates the size (in bytes) of an oop map that will have a bit for every word in a memory of a given size.
static long freeMemory()
          Returns the amount of free memory in the system.
static int getArrayLength(Object array)
          Get the length of an array.
static int getBytesAllocatedSinceLastGC()
          Get the number of bytes allocated since the last GC.
static GarbageCollector getCollector()
          Gets a reference to the installed collector.
static int getFullCount()
          Returns the number of full-heap collections.
static int getHashCode(Object object)
          Get the hashcode for an object.
static Class getKlass(Object object)
          Get the class of an object.
static int getPartialCount()
          Returns the number of partial-heap collections.
static int getTotalCount()
          Returns the total number of garbage collections that have been performed by the VM.
static void initHeapStats()
          Pre-create all data structures used in heap stats, so heap walking won't allocate more memory.
static boolean inRam(Address start, Address end)
          Determines if any part of the range is in RAM.
static boolean inRam(Object object)
          Determines if a given object is in RAM.
static boolean isGCEnabled()
          Is Garnage collection enabled?
static boolean isSafeToSwitchThreads()
          Test to see if this is a safe time to switch threads.
static String makeEightBitString(Object oop)
          Change the type of the given object to com.sun.squawk.StringOfBytes.
static String makeSixteenBitString(Object oop)
          Change the type of the given object to java.lang.String.
static void printEstimatedHashtableSize(SquawkHashtable tbl)
          print an estimate the number of bytes used by this hastable, not including keys and values.
static void printHeapStats(Object startObj, boolean printInstances)
          Do actual heap walk, from start object, or whole heap is startObj is null.
static int roundUpToWord(int value)
          Rounds up a 32 bit value to the next word boundry.
static boolean setGCEnabled(boolean newState)
          Enable or disable the garbage collector.
static void stringcopy(Object src, int srcPos, Object dst, int dstPos, int lth)
          Copy data from one string to another.
static long totalMemory()
          Returns the total amount of RAM memory in the Squawk Virtual Machine.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

arraycopy

public static void arraycopy(Object src,
                             int srcPos,
                             Object dst,
                             int dstPos,
                             int lth)
Copy data from one array to another.

Parameters:
src - the source array
srcPos - the start position in the source array
dst - the destination array
dstPos - the start position in the destination array
lth - number of elements to copy

calculateOopMapSizeInBytes

public static int calculateOopMapSizeInBytes(int size)
Calculates the size (in bytes) of an oop map that will have a bit for every word in a memory of a given size.

Parameters:
size - the size (in bytes) of the memory that the oop map will describe
Returns:
the size (in bytes) of an oop map that will have a bit for every word in a memory region of size size bytes

freeMemory

public static long freeMemory()
Returns the amount of free memory in the system. Calling the gc method may result in increasing the value returned by freeMemory.

Returns:
an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.

getArrayLength

public static int getArrayLength(Object array)
Get the length of an array.

Parameters:
array - the array
Returns:
the length in elements of the array

getBytesAllocatedSinceLastGC

public static int getBytesAllocatedSinceLastGC()
Get the number of bytes allocated since the last GC. May be inaccurate during a copyObjectGraph operation.

Returns:
bytes

getCollector

public static GarbageCollector getCollector()
Gets a reference to the installed collector.

Returns:
a reference to the installed collector

getFullCount

public static int getFullCount()
Returns the number of full-heap collections.

Returns:
the count of full-heap collections.

getHashCode

public static int getHashCode(Object object)
Get the hashcode for an object.

Parameters:
object - the object the hashcode is needed for.
Returns:
the hashcode

getKlass

public static Class getKlass(Object object)
Get the class of an object.

Parameters:
object - the object
Returns:
its class

getPartialCount

public static int getPartialCount()
Returns the number of partial-heap collections.

Returns:
the count of partial-heap collections.

getTotalCount

public static int getTotalCount()
Returns the total number of garbage collections that have been performed by the VM.

Returns:
the total count of collections.

inRam

public static boolean inRam(Address start,
                            Address end)
Determines if any part of the range is in RAM.

Parameters:
start -
end -
Returns:
true if any part of the range start..end overlaps with the heap

inRam

public static boolean inRam(Object object)
Determines if a given object is in RAM.

Parameters:
object - the object to test
Returns:
true if object is an instance in RAM

initHeapStats

public static void initHeapStats()
Pre-create all data structures used in heap stats, so heap walking won't allocate more memory.


isGCEnabled

public static boolean isGCEnabled()
Is Garnage collection enabled?

Returns:
true if GC enabled.

isSafeToSwitchThreads

public static boolean isSafeToSwitchThreads()
Test to see if this is a safe time to switch threads.

Returns:
true if it is

makeEightBitString

public static String makeEightBitString(Object oop)
Change the type of the given object to com.sun.squawk.StringOfBytes.

Parameters:
oop - the object
Returns:
the converted object

makeSixteenBitString

public static String makeSixteenBitString(Object oop)
Change the type of the given object to java.lang.String.

Parameters:
oop - the object
Returns:
the converted object

printEstimatedHashtableSize

public static void printEstimatedHashtableSize(SquawkHashtable tbl)
print an estimate the number of bytes used by this hastable, not including keys and values.

Parameters:
tbl -

printHeapStats

public static void printHeapStats(Object startObj,
                                  boolean printInstances)
Do actual heap walk, from start object, or whole heap is startObj is null. Count how many instances, and how many bytes are used, by all objects that are the same aage or youngre than startObj. Print out statistics of each class that has at least one instance in the set found in the heap walk. Statistics are NOT sorted.

Parameters:
startObj - the object to start walking from , or null
printInstances - if true, print information about each object before printing statistics

roundUpToWord

public static int roundUpToWord(int value)
Rounds up a 32 bit value to the next word boundry.

Parameters:
value - the value to round up
Returns:
the result

setGCEnabled

public static boolean setGCEnabled(boolean newState)
Enable or disable the garbage collector.

Parameters:
newState - the new abled/disabled state of the garbage collector
Returns:
the garbage collector's state before this call

stringcopy

public static void stringcopy(Object src,
                              int srcPos,
                              Object dst,
                              int dstPos,
                              int lth)
Copy data from one string to another.

Parameters:
src - the source string
srcPos - the start position in the source string
dst - the destination string
dstPos - the start position in the destination string
lth - number of characters to copy

totalMemory

public static long totalMemory()
Returns the total amount of RAM memory in the Squawk Virtual Machine. The value returned by this method may vary over time, depending on the host environment.

Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.

2010 FRC Java API


Copyright © 2006-2009 Sun Microsystems, Inc. All Rights Reserved.