package de.am.gc.benchmarks; import java.util.ArrayList; import java.util.List; /** * GC benchmark producing a mix of lifetime=0 and lifetime>0 objects which are kept in randomly updated lists. * * @author jsound */ public class MixedRandomList { private static final int DEFAULT_NUMBEROFTHREADS=1; // object size in bytes private static final int DEFAULT_OBJECTSIZE=100; private static int numberOfThreads=DEFAULT_NUMBEROFTHREADS; private static int objectSize=DEFAULT_OBJECTSIZE; // Number of objects to fill about half of the available memory with live objects // The result of this calculation is not a constant with different garbage collectors. // Therefore, it is preferable to set this value as an explicit parameter to the benchmark. // Explicit setting is required if objectsize is different from default private static long numLive = (Runtime.getRuntime().maxMemory()/objectSize/5); /** * @param args the command line arguments */ public static void main(String[] args) { if( args.length>0 ) { // first, optional argument is the size of the objects objectSize = Integer.parseInt(args[0]); // second, optional argument is the number of threads if( args.length>1 ) { numberOfThreads = Integer.parseInt(args[1]); // third, optional argument is the number of live objects if( args.length>2 ) { numLive = Long.parseLong(args[2]); } } } for( int i=0; i0 which is distributed about an average lifetime. * This average lifetime is a function of fractionLive and numLive * * @param fractionLive * @param numLive */ public GarbageProducer(int fractionLive, long numLive) { this.fractionLive = fractionLive; this.myNumLive = numLive; } @Override public void run() { int osize = objectSize; char[] chars = getCharArray(objectSize); List liveList = new ArrayList((int)myNumLive); // initially, the lifeList is filled for(int i=0; i