scale.common
Class WorkArea

java.lang.Object
  extended by scale.common.WorkArea

public class WorkArea
extends java.lang.Object

This class helps to eliminate JVM Heap allocations.

$Id: WorkArea.java,v 1.7 2007-08-27 18:37:51 burrill Exp $

Copyright 2008 by the Scale Compiler Group,
Department of Computer Science
University of Massachusetts,
Amherst MA. 01003, USA
All Rights Reserved.

This class provides Stack and HashSet instances for re-use. Stacks & HashSets are often used for spanning algorithms. By re-using exisiting instances many allocations of large structures can be avoided.


Constructor Summary
WorkArea()
           
 
Method Summary
static void cleanup()
          Clean up for profiling statistics.
static
<T> HashSet<T>
getSet(java.lang.String name)
          Obtain a HashSet instance for temporary use.
static
<T> Stack<T>
getStack(java.lang.String name)
          Obtain a Stack for temporary use.
static int inUseSets()
          Return the number of in use sets.
static int inUseStacks()
          Return the number of in use stacks.
static int maxSets()
          Return the maximum number of sets allocated.
static int maxStacks()
          Return the maximum number of stacks allocated.
static
<T> void
returnSet(HashSet<T> set)
          Release the HashSet instance so that it can be used again.
static
<T> void
returnStack(Stack<T> stk)
          Release the Stack so that it can be used again.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WorkArea

public WorkArea()
Method Detail

maxStacks

public static int maxStacks()
Return the maximum number of stacks allocated.


inUseStacks

public static int inUseStacks()
Return the number of in use stacks.


maxSets

public static int maxSets()
Return the maximum number of sets allocated.


inUseSets

public static int inUseSets()
Return the number of in use sets.


getStack

public static <T> Stack<T> getStack(java.lang.String name)
Obtain a Stack for temporary use. The Stack obtained must not be attached to anything whose lifetime is longer than the invocation time of the method calling the getStack method. It must be returned for further use by using returnStack.

Parameters:
name - is used to detect who didn't return a Stack for re-use

returnStack

public static <T> void returnStack(Stack<T> stk)
Release the Stack so that it can be used again.


getSet

public static <T> HashSet<T> getSet(java.lang.String name)
Obtain a HashSet instance for temporary use. The HashSet instance obtained must not be attached to anything whose lifetime is longer than the invocation time of the method calling the getSet method. It must be returned for further use by using returnSet.

Parameters:
name - is used to detect who didn't return a HashSet instance for re-use

returnSet

public static <T> void returnSet(HashSet<T> set)
Release the HashSet instance so that it can be used again.


cleanup

public static void cleanup()
Clean up for profiling statistics.