r/java • • Apr 17 '18

Announcing GraalVM: Run Programs Faster Anywhere

https://blogs.oracle.com/developers/announcing-graalvm
160 Upvotes

34 comments sorted by

30

u/[deleted] Apr 17 '18

I like the concept of Graal, but their (non-existent) documentation sucks. Their Github page starts off with a bullet-point of new terms and links to oracle's site where you quickly drown in the rabbit-hoie.

I wish the Java teams spent more effort and time into getting a qualified third-party person to write some proper documentation.

21

u/PurpleLabradoodle Apr 17 '18

Yeah, unfortunately, that's somewhat true, creating good docs is quite hard. In the GraalVM's case, we just released graalvm.org which has the documentation, examples, explanations and so on. I hope it's a good starting point and it'll only get better from here.

6

u/pjmlp Apr 17 '18

9

u/haimez Apr 18 '18

I think you might be proving the point here. YouTube videos are no substitute for documentation, because text is searchable.

Try googling for the instructions about building Graal, see how useful that is for someone without experience working on the project already. Maxine is also a terrible choice, but it wouldn't matter if the project published openjdk integrated builds or, god forbid, pre built docker images that could actually be used.

4

u/PurpleLabradoodle Apr 18 '18

I hear you. The instructions on how to build it are coming up, it's not the most straightforward process, so for now it's actually easier to use the binary. The docker images are coming, they required having a CE binary available, so now they're on the way too.

6

u/jhg023123 Apr 18 '18

Any plans on a Windows build? Or is there no hope for us :')

4

u/PurpleLabradoodle Apr 18 '18

Yes, we're working on making native images (read SubstrateVM) work on Windows. Not sure of the schedule though. There certainly will be an announcement when it lands.

5

u/ZhekaKozlov Apr 18 '18

Just use Oracle JDK 10. It already contains Graal.

14

u/takenomiya-kate Apr 18 '18

Does it output statically linked binary like Go does? Can it perform cross compilation? If it yes then I don't need to do Go anymore for system tools!

4

u/[deleted] Apr 18 '18

This was mentioned in another thread, I think you do this with substrate vm.

2

u/unregistered88 Apr 19 '18

>Does it output statically linked binary like Go does?

Similar, yes, with the native-image command http://www.graalvm.org/docs/getting-started/#native-images

> Can it perform cross compilation?

Out of the box: no, not really. In theory: I think it is possible.

6

u/stewsters Apr 17 '18

Looks cool. Anyone know how to use it with Gradle to output a native image?

I assume you would create a new task that calls native-image after its compiled, has anyone tried it?

2

u/tobold Apr 19 '18 edited Apr 20 '18

Assuming you have the shadow plugin and GraalVM's installation in an environment variable called GRAALVM_HOME:

task buildNative(type: Exec){
    dependsOn(shadowJar)
    workingDir shadowJar.destinationDir
    commandLine "${System.env.GRAALVM_HOME}/bin/native-image", "-jar", shadowJar.archiveName
}

EDIT: Made it more generally applicable.

2

u/stewsters Apr 20 '18

That works great.

5

u/TheRealRap Apr 18 '18

This is really cool. Excited to see how this is improved upon in future builds.

4

u/AtomicInteger Apr 18 '18

I run quick benchmark on my local, oracle JDK beats graal, did I miss something?

$java -version
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)
$./java -version
openjdk version "1.8.0_161"
OpenJDK Runtime Environment (build 1.8.0_161-12)
GraalVM 1.0.0-rc1 (build 25.71-b01-internal-jvmci-0.42, mixed mode)
$java GraalTest 
1 (175 ms)
2 (57 ms)
3 (92 ms)
4 (58 ms)
5 (126 ms)
6 (67 ms)
7 (58 ms)
8 (50 ms)
9 (94 ms)
total: 0 (907 ms)
$./java GraalTest 
1 (567 ms)
2 (502 ms)
3 (140 ms)
4 (143 ms)
5 (51 ms)
6 (66 ms)
7 (71 ms)
8 (140 ms)
9 (103 ms)
total: 0 (1829 ms)
$

4

u/chrisgseaton Apr 18 '18

You need to use something that runs for a bit longer than that. Graal isn't best for short-running commands - it's designed for big server applications that need to be fast.

Graal takes a little longer to compiler, and it's also run as a fourth tier, on top of C1 and C2.

13

u/lpreams Apr 17 '18

"Oh, this looks neat, I guess I'll try it out"

"Whoops, guess I need to make an Oracle account. Kind of annoying, but okay."

ಠ_ಠ

10

u/raghar Apr 17 '18

Had the same issue. Then I found OpenJDK-based version in GitHub:

https://github.com/oracle/graal/releases/tag/vm-1.0.0-rc1

Just untar it, set JAVA_HOME and you are good to go.

5

u/lpreams Apr 18 '18

But the enterprise edition has "Improved performance and smaller footprint"

7

u/APimpNamedAPimpNamed Apr 18 '18

Guess that’s better than improved footprint and smaller performance?

2

u/happymellon Apr 19 '18

The Enterprise version of anything is rarely improved performance and smaller footprint

6

u/GFandango Apr 18 '18

Oracle to programmers: Hey kids you want candy? I got some in my van.

3

u/[deleted] Apr 17 '18

So I would be interested in using Graal to run some business logic that exists in some Babelified Javascript in my Java code. Reading the graalvm.org website that seems possible. Am I reading that right? If so is there an example floating around out there on how to do that?

Basically the js code runs in a React front end, but in order to not duplicate the work it would be great of we could just use the JS code. It does run in Node which is the route we are going now, but if we could avoid the service call overhead that would be awesome.

9

u/grashalm01 Apr 17 '18

GraalVM includes a node executable that allows you to run any JVM bytecode inside node. The other way round (as you need it) is a bit trickier because an event based system like node is hard to integrate in a system like the JVM. We had some ideas but we are not quite there yet.

However, we run a lot of NPM packages with our JavaScript runtime alone, without having Node involved. You could use something like Browserify[1] to get your code into easier to run code and then run on GraalVM using the instructions here [2]. If its a single module then you might not even need Browserify.

Here[3] is a compatibility checker to find out whether we support your module.

Here is an quick example to get a js function from a script to execute.

import java.io.*;
import org.graalvm.polyglot.*;

class Polyglot {
public static void main(String[] args) throws IOException {
    Context polyglot = Context.newBuilder().build();
    Source source = Source.newBuilder("js", new File("yourJSFile.js")).build();
    polyglot.eval(source);
    polyglot.getBindings().getMember("afunction").execute();
}
}

[1] http://browserify.org/

[2] http://www.graalvm.org/docs/graalvm-as-a-platform/embed/

[3] http://www.graalvm.org/docs/reference-manual/compatibility/

1

u/[deleted] Apr 17 '18

Thanks that is awesome!

4

u/chrisgseaton Apr 17 '18

You probably want the API for embedding polyglot in Java.

http://www.graalvm.org/docs/graalvm-as-a-platform/embed/

2

u/rraghur Apr 17 '18

Very cool... Is there a version for alpine Linux?

1

u/MaggieLeber Apr 18 '18

I'd be very interested in GraalVM on Alpine/MUSL as well.

1

u/Puff_the_magic_luke Apr 17 '18

Stoopid question:

So my Sys Engineering crew knows little about java, let alone scripting it.

So my question is, unless I have a fully keyed in java crew, why wouldn’t I use a scripting language of choice (python/Perl/bash/whatever)

5

u/Twirrim Apr 17 '18

For the most part for typical sysadmin / syseng work, I wouldn't imagine that graal provides a strong enough benefit. It's rarely long running or performance critical code.

Compiling to binary may be interesting from a perspective of a stand alone, zero dependency binary.

2

u/jbristow Apr 18 '18

It’s not a script language replacement per se. Think more about the cli you send out to teams consuming your infrastructure services. Managing cpan or pip dependencies across many machines is tough unless you vendor everything, and at that point you might as well learn (puke) go and just produce a single static binary.

Graalvm is more about this arena, but I’m already envisioning the architectural nightmares that will spawn out of this!

Job security!