我正在尝试为在WSL上运行的Ubuntu 18.04的本机代码编译一个迷你基准。我将其与用C#编写的功能相同的代码进行比较,该代码正在编译为Dotnet Native,其运行速度比MSIL代码快10倍。我希望这是一次苹果对苹果的测试。我正在使用OpenJDK 12来做到这一点。下面是正在使用的命令和代码。
jaotc -J-XX:+UseParallelGC -J-XX:-UseCompressedOops --output Java/Chain.so --class-name Java.Chain:Java.Person
之后
java -XX:AOTLibrary=Java/Chain.so Java.Chain
产生
Error: Could not find or load main class Java.Chain
Caused by: java.lang.ClassNotFoundException: Java.Chain
代码: 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;
}
}
我需要知道我在做什么错。我在互连网上发现的每个示例都将我引向这一点。
答案 0 :(得分:0)
我没有使用jaotc
的经验,但是谷歌搜索告诉我,您首先必须将Chain.java编译为Chain.class,然后将Chain.class编译为Chain.so
javac Java/Chain.java Java/Person.java
因此完整的脚本是
javac Java/Chain.java Java/Person.java
jaotc -J-XX:+UseParallelGC -J-XX:-UseCompressedOops --output Java/Chain.so --class-name Java.Chain:Java.Person
java -XX:AOTLibrary=Java/Chain.so Java.Chain