Git Product home page Git Product logo

graalvm-truffle-tutorial's Introduction

GraalVM Truffle tutorial

This repository contains the code for a tutorial on the Truffle language implementation framework that I've written for my blog. It focuses on implementing a language I call EasyScript, which is a very simplified subset of JavaScript.

The repository is divided into multiple parts, each corresponding to a part of the blog article. Each part focuses on explaining a small set of Truffle capabilities, and builds on top of the previous parts by adding more features to the EasyScript language implementation.

Each part is a separate Gradle submodule, and so gets built when you build the top-level project.

Setup

To build and execute this project, you need a GraalVM installation on your local machine. The free Community Edition works fine if you don't have the paid Enterprise Edition. You can download it from here: https://github.com/graalvm/graalvm-ce-builds/releases. This repository uses Java 11 features, so make sure to download a version for Java 11.

Once you've downloaded the correct archive for your operating system and extracted it somewhere on your machine, you need to set the JAVA_HOME environment variable to point to the directory containing the uncompressed contents:

$ export JAVA_HOME=/path/to/extracted/archive

You can verify the installation works by executing the java command using JAVA_HOME:

$ $JAVA_HOME/bin/java -version

openjdk version "17.0.5" 2022-10-18
OpenJDK Runtime Environment GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08)
OpenJDK 64-Bit Server VM GraalVM CE 22.3.0 (build 17.0.5+8-jvmci-22.3-b08, mixed mode, sharing)

Building

Once you have GraalVM installed, you can build the project - it uses Gradle as its build system:

$ ./gradlew build

Table of contents

graalvm-truffle-tutorial's People

Contributors

mio-19 avatar skinny85 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

graalvm-truffle-tutorial's Issues

Feedback on part 9 โ€“ performance benchmarking

Hello,

I've read https://www.endoflineblog.com/graal-truffle-tutorial-part-9-performance-benchmarking and wanted to leave some feedback.
It is a nice write up, thank you for these nice blog posts.
I'm sure they help people getting started with Truffle.

I noticed a few things which are rather unexpected, based on my experience with Truffle (I work on TruffleRuby).

The first thing is the benchmark redefines the function every time.
That seems unexpected, especially for micro-benchmarks.
Here it seems much better to declare the function in the setup, and only call fib inside the benchmark itself.
Also calling eval like this is likely to have a non-trivial overhead.
Better would be to Value fib; as a field, fib = context.eval("ezs", "function fib(n) {...}") in setup and then benchmark fib.execute(20).
Another possibility would be to store "fib(20)" as a Source and pass that to eval.

The mutable FunctionObject approach feels quite off for JS-like languages. I guess the inspiration is SLFunction?
IMHO it's kind of a hack and it only works because in SL there are only functions at the top-level, and so a single map of functions conceptually, and the functions objects are used both for caching looking and holding on the CallTarget.
In a JS-like language, typically the function/property lookup would be cached separately (using the Truffle Object Model), and the function itself would have a fixed CallTarget.
Related, the caching in GlobalVarReferenceExprNode seems only correct if it's only functions that can be assigned at the top-level and not other variables. Otherwise, this would cache fib to the given function even after fib = 3 at the top-level (which cannot really be handled by the mutable FunctionObject).

The change in BlockStmtNode should not change peak performance (although it is a good change in general), Graal should compile it the same no matter which version is used, because it can see ret is unused except the last one after it exploded/unrolled the loop. Do you have a way to reproduce that? If the performance actually differs it would likely be a bug.
Possibly the difference you saw could be caused by not enough warmup.
cc @rschatz

Auxiliary slot

They are stored in something called auxiliary slots; basically a map inside the VirtualFrame. The keys of that map historically were instances of a class called FrameSlot. However, that class has been removed in GraalVM version 22, and now the map is indexed by integers, the same way function arguments are. These integer indexes are related to another important class, FrameDescriptor.

Is the term "auxiliary slot" precise here? I understand the flow with descriptors and eg setObject / getObject methods in the Frame. But it also has methods with literal term "auxiliary" in them: setAuxiliarySlot / getAuxiliarySlot, which seem to be something different and unrelated to frame descriptors.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.