我正在尝试为在 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];
}
}
人.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;
}
}
我需要知道我做错了什么。我在互联网上找到的每一个例子都让我想到了这一点。