Seriously slow?
I tried to execute this code using jvmgo
import java.util.*;
class prime {
public static void main(String[] args) {
ArrayList<Integer> res = new ArrayList<Integer>();
int last = 3;
res.add(last);
while(true) {
last = last + 2;
boolean prime = true;
for(int v : res) {
if(v*v>last) break;
if(last%v == 0) {
prime = false;
break;
}
}
if(prime) {
res.add(last);
if(res.size()%100000 == 0) System.out.println(last);
if(last>9999999) break;
}
}
}
}
but it took too much time, more than 578.62s (I terminate execution because it took too long), for comparison openjdk 8u40 gives complete output within 1.23s
OS: 64-bit ArchLinux
Kernel version: 3.18.7-1
Processor: i3-4150
RAM: 16GB
Hi, thanks for your issue. This project is coded for fun and learning. Besides that, it is in the baby stage(two months old, mostly programmed by one guy). So, do not expect too much : ) I will try my best to finish this project and make it run faster.
Btw this project is cool :cool: i'll look forward for the completion :+1:
@zxh0 could there be a bug or something related to this? I have a feeling that no matter how slow, it shouldn't take that long. I don't know anything but yeah, my 2 cents.
Yes, it's too slow :( I did some cpu profile and code optimization yesterday, but I feel it's not the time to do this kind of stuff. For now, this jvm is still a toy. Thread, ClassLoader, Java Memory Model, File, Socket... a lot of things are still not working(correctly). I will try to implement all of that and then go back to this issue.
While peeking at the code I think it's already using a threaded interpreter, right? Then to achieve good performance you must implement JITs, which I suspect will take years to be competitive... (look at LuaJIT) I agree it's better making things working than making them performant for now.
Actually, writing a JIT is beyond my ability :(
Go can't easily support a JIT currently because Go's memory model clashes with most ways of doing jit. Creating a JIT itself is not particularly hard.
What if we instead transpiled Java to Golang, and then could get native execution speed?
Kind of like GWT transpiles Java bytecode to JavaScript.
@bpilot why use go then? GCC has gcj which compiles Java to native x64 elf binaries.