plasma-umass / doppio

Breaks the browser language barrier (includes a plugin-free JVM).
http://plasma-umass.github.io/doppio-demo
MIT License
2.16k stars 174 forks source link

Can't load java.lang.Thread #447

Closed ianopolous closed 8 years ago

ianopolous commented 8 years ago

I'm trying to get doppio working in a browser. At the moment it throws an exception trying to load the java.lang.Thread class

Cannot read property 'throwNewException' of null - on line 340 of ClassLoader.ts

The webroot I'm using is at https://github.com/ianopolous/DoppioDemo

jvilk commented 8 years ago

This is a reminder to me to have better error messages during JVM bootup...

The JVM loads the thread class first to mock a Thread object to bootstrap the JVM. It is failing to load the file, which means it cannot find java.lang.Thread on the classpath.

And it cannot find java.lang.Thread because the filesystem has an issue; /sys/vendor/java_home/lib/rt.jar exists in the index, but the filesystem cannot fetch it:

BrowserFS.BFSRequire('fs').readFileSync('/sys/vendor/java_home/lib/rt.jar')
xhr.ts:164 GET http://localhost:8080/doppio/vendor/java_home/lib/rt.jar 404 (Not Found)i @ xhr.ts:164b._requestFileSync @ XmlHttpRequest.ts:101b.openSync @ XmlHttpRequest.ts:267b.readFileSync @ XmlHttpRequest.ts:334b @ MountableFileSystem.ts:300a.readFileSync @ FS.ts:474function.e.(anonymous function).f.(anonymous function) @ node_fs.ts:19(anonymous function) @ VM872:1InjectedScript._evaluateOn @ (program):145InjectedScript._evaluateAndWrap @ (program):137InjectedScript.evaluate @ (program):118
MountableFileSystem.ts:303 Uncaught f {syscall: "", errno: 404, code: undefined, path: null, stack: "Error↵    at new f (http://localhost:8080/doppio/b…/browserfs.min.js:7:8011)↵    at <anonymous>:1:28"…}

It's typing to load http://localhost:8080/doppio/vendor/java_home/lib/rt.jar instead of http://localhost:8080/doppio/java_home/lib/rt.jar.

But the JVM isn't even trying to load that file, because the boot classpath is set to /sys/java_home/classes.

To fix these issues:

That should fix the issue.

ianopolous commented 8 years ago

If I run the XHRIndexer in the doppio directory it outputs something with all values null. e.g. {"browserfs.min.js":null,"browserfs.min.js.map":null...

jvilk commented 8 years ago

While weird, that's actually intentional. The XHRFS uses the JSON object directly as its index, with stats stored in each property, so storing it this way on disk prevents XHRFS from having to transform it at runtime. This was a huge performance gain when DoppioJVM did not support JAR files, and had an index with every individual class file in the Java Class Library!

ianopolous commented 8 years ago

Ah, I see. It is still failing to load Thread though with both those changes. The latest is at: https://github.com/ianopolous/DoppioDemo

Have I missed something else?

jvilk commented 8 years ago

Yes; it looks like the default options expect java_home to be in a vendor directory. Move java_home into vendor, regenerate listings, and it should work.

ianopolous commented 8 years ago

That fixed it! Thank you!

jvilk commented 8 years ago

I've updated the getting started guide, and added an example application that can be built in a single command.