back

by fniephaus·6y ago·view on hn ↗
> Can someone please give a sober explanation of what GraalVM, is and how Truffle works?

GraalVM is basically a JVM with a new compiler, the Graal compiler. Truffle is the language implementation framework for GraalVM and designed to build AST interpreter. The Graal compiler can optimize Truffle ASTs through partial evaluation (see "One VM to rule them all" paper [1]), and produces machine code directly without using Java bytecode as IR.

> how do JS semantics get expressed in a Java VM?

Graal.js comes with a parser for JavaScript code that generates a Truffle ASTs for a given JavaScript program. JS semantics are defined within the AST nodes (see [2]).

> What does a getProperty instruction look like?

I think getProperty is implemented in `CachedGetPropertyNode` [3], but I am not sure as there are multiple other property-related nodes.

> How does it know when to invalidate inline caches?

Unfortunately, Graal.js lacks documentation for `CachedGetPropertyNode`. But I encourage you to have a look at SimpleLanguage [4], a JS-like toy language and the reference language implementation for Truffle with proper documentation. [5] explains how reading properties and invalidating inline caches works and it's all done using the Truffle DSL. The `@Specialization` annotation [6] might be a good starting point if you want to learn how it works. You may also want to check out the docs on the GraalVM website (e.g. [7]).

[1] https://doi.org/10.1145/2509578.2509581

[2] https://github.com/graalvm/graaljs/tree/a36b978aa328a8da3a7f...

[3] https://github.com/graalvm/graaljs/blob/a36b978aa328a8da3a7f...

[4] https://github.com/graalvm/simplelanguage

[5] https://github.com/graalvm/simplelanguage/blob/a25e385dd8626...

[6] https://www.graalvm.org/truffle/javadoc/com/oracle/truffle/a...

[7] https://www.graalvm.org/docs/Truffle-Framework/user/README