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

84 lines
2.1 KiB
Java

package lip6.jikesrvm.bench;
import java.util.Random;
import lip6.jikesrvm.bench.Cell;
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;
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);
}
bubbleSort();
/* Only the 6 store in the if of the bubbleSort call the write barrier */
System.out.println("Number of loop: "+ NB_ELEM);
System.out.println("Number of writes per loop: 6");
}
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());
}
};