rt_benchs/jikes_write_barrier/src/lip6/jikesrvm/bench/Main.java

99 lines
2.3 KiB
Java

package lip6.jikesrvm.bench;
import java.util.Random;
import lip6.jikesrvm.bench.Cell;
import lip6.microbenchs.PapiHighLevel;
public class Main
{
private static final long NB_ELEM = 10000;
private static Random randomInt; // random int to put into the cells
private static Cell head;
static
{
System.loadLibrary("papihighlevel");
}
public static void main(String args[])
{
randomInt = new Random(424242424242L);
{
Cell oldCell, newCell;
newCell = null;
head = new Cell(randomInt.nextInt());
oldCell = head;
for (int i = 0; i < NB_ELEM - 1; i++)
{
if (i == NB_ELEM / 2)
Runtime.getRuntime().gc();
newCell = new Cell(randomInt.nextInt());
newCell.setPrev(oldCell);
oldCell.setNext(newCell);
oldCell = newCell;
}
newCell.setNext(head);
head.setPrev(newCell);
}
if (PapiHighLevel.initialize_papi() != 0)
{
System.err.println("Error while inizializing PAPI");
java.lang.System.exit(1);
return;
}
bubbleSort();
if (PapiHighLevel.print_results() != 0)
{
System.err.println("Error while getting results");
java.lang.System.exit(2);
return;
}
}
private static void bubbleSort()
{
Cell cell, nextCell;
/* We suppose the list disordered */
boolean ordered = false;
/* We stop after NB_ELEM loop or if a loop has been done without inversion */
for(int i = 0 ; (i < NB_ELEM) && !ordered; i++)
{
/* We suppose the list ordered */
ordered = true;
/* New tracing of the list: we start to examine the first 2 cells */
cell = head;
nextCell = cell.getNext();
for(int j = 1 ;j < NB_ELEM - i; j++)
{
/* If the 2 cells aren't ordered */
if (nextCell.getValue() < cell.getValue())
{
/* We invert the 2 cells */
cell.getPrev().setNext(nextCell);
nextCell.getNext().setPrev(cell);
cell.setNext(nextCell.getNext());
nextCell.setPrev(cell.getPrev());
cell.setPrev(nextCell);
nextCell.setNext(cell);
Cell.incCounter(6);
/* We made an inversion: the list isn't ordered */
ordered = false;
}
else
cell = nextCell; /* Get ready for the next loop: we make a one cell shift (1) */
/* Get ready for the next loop: we make a one cell shift (2) */
nextCell = cell.getNext();
}
}
System.out.println("ctr: " + Cell.getCounter());
}
};