I'm try to compile a mini-benchmark to native code for Ubuntu 18.04 running on WSL. I'm comparing it to functionally identical code written in C# which is being compiled to Dotnet Native, which runs about 10x faster than MSIL code. I want this to be an apples-to-apples test. I'm using OpenJDK 12 to do this. Below is the commands and code being used.
jaotc -J-XX:+UseParallelGC -J-XX:-UseCompressedOops --output Java/Chain.so --class-name Java.Chain:Java.Person
followed by
java -XX:AOTLibrary=Java/Chain.so Java.Chain
results in
Error: Could not find or load main class Java.Chain
Caused by: java.lang.ClassNotFoundException: Java.Chain
Code: Chain.java
package Java;
public class Chain
{
private static int ITER = 10000;
private Person first = null;
private static Chain[] chains = new Chain[ITER];
private static Chain[] target = new Chain[ITER];
public Chain(int size)
{
Person last = null;
Person current = null;
for (int i = 0 ; i < size ; i++)
{
current = new Person(i);
if (first == null) first = current;
if (last != null)
{
last.setNext(current);
current.setPrev(last);
}
last = current;
}
first.setPrev(last);
last.setNext(first);
}
public Person kill(int nth)
{
Person current = first;
int shout = 1;
while(current.getNext() != current)
{
shout = current.shout(shout, nth);
current = current.getNext();
}
first = current;
return current;
}
public Person getFirst()
{
return first;
}
public static void main(String[] args)
{
long start = System.nanoTime();
for (int i = 0 ; i < ITER ; i++)
{
Chain chain = new Chain(40);
chain.kill(3);
chains[i] = chain;
}
// Ensure JIT doesn't optimize out the first loop
for (int i = 0; i < ITER; ++i)
{
target[i] = chains[i];
}
long end = System.nanoTime();
System.out.println(GetLastChain());
double elapsedTime = (end - start);
System.out.println("Elapsed time: " + elapsedTime + " nanoseconds");
System.out.println("Time per iteration = " + elapsedTime / ITER + " nanoseconds.");
}
private static Chain GetLastChain()
{
return target[ITER - 1];
}
}
Person.java
package Java;
public class Person
{
int count;
private Person prev = null;
private Person next = null;
public Person(int count)
{
this.count = count;
}
public int shout(int shout, int deadif)
{
if (shout < deadif) return (shout + 1);
this.getPrev().setNext(this.getNext());
this.getNext().setPrev(this.getPrev());
return 1;
}
public int getCount()
{
return this.count;
}
public Person getPrev()
{
return prev;
}
public void setPrev(Person prev)
{
this.prev = prev;
}
public Person getNext()
{
return next;
}
public void setNext(Person next)
{
this.next = next;
}
}
I need to know what I'm doing wrong. Every example I find on the interwebs leads me to this.
I have no experience with
jaotc
but googling tells me you first have to compile Chain.java to Chain.class and then Chain.class to Chain.soso full script is