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

106 lines
3.2 KiB
Java

/*
* Copyright (C) 2009, 2011 Thomas Preud'homme <thomas.preud-homme@lip6.fr>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
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());
}
};