jvm.go icon indicating copy to clipboard operation
jvm.go copied to clipboard

Seriously slow?

Open kokizzu opened this issue 10 years ago • 10 comments

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

kokizzu avatar Mar 19 '15 08:03 kokizzu

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.

zxh0 avatar Mar 19 '15 12:03 zxh0

Btw this project is cool :cool: i'll look forward for the completion :+1:

kokizzu avatar Mar 19 '15 13:03 kokizzu

@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.

hami9x avatar Mar 20 '15 17:03 hami9x

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.

zxh0 avatar Mar 21 '15 00:03 zxh0

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.

wishstudio avatar Apr 02 '15 08:04 wishstudio

Actually, writing a JIT is beyond my ability :(

zxh0 avatar Apr 02 '15 13:04 zxh0

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.

andrewchambers avatar Apr 22 '15 22:04 andrewchambers

What if we instead transpiled Java to Golang, and then could get native execution speed?

Kind of like GWT transpiles Java bytecode to JavaScript.

ailabs-software avatar Nov 03 '16 04:11 ailabs-software

@bpilot why use go then? GCC has gcj which compiles Java to native x64 elf binaries.

bmarwell avatar Nov 21 '16 22:11 bmarwell

Actually, writing a JIT is beyond my ability :(

How about migrate VMKit to latest LLVM?

xiangzhai avatar Nov 26 '18 01:11 xiangzhai