Skip to content

Commit

Permalink
Make code listings more consistent.
Browse files Browse the repository at this point in the history
  • Loading branch information
fniephaus committed Sep 8, 2021
1 parent 03b7276 commit 9790f52
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 117 deletions.
76 changes: 38 additions & 38 deletions compiler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ For brevity, the GraalVM compiler is often referred to as "the compiler" below.
Working with the GraalVM compiler will mean cloning more than one repository and so it's
recommended to create and use a separate directory:

```
mkdir graal
cd graal
```bash
$ mkdir graal
$ cd graal
```

## Building the GraalVM compiler

To simplify development, a separate Python tool called [mx](https://github.com/graalvm/mx) has been co-developed.
This tool must be downloaded and put onto your PATH:

```
git clone https://github.com/graalvm/mx.git
export PATH=$PWD/mx:$PATH
```bash
$ git clone https://github.com/graalvm/mx.git
$ export PATH=$PWD/mx:$PATH
```

The compiler depends on a JDK that supports a compatible version of JVMCI ([JVM Compiler Interface](https://bugs.openjdk.java.net/browse/JDK-8062493)).
Expand All @@ -34,42 +34,42 @@ These sources are in [versioned projects](https://github.com/graalvm/mx#versioni
If you don't have a JDK that satisfies the requirement of a versioned project, the project is ignored by mx.

If you want to develop on a single JDK version, you only need to define `JAVA_HOME`. For example:
```
export JAVA_HOME=/usr/lib/jvm/oraclejdk1.8.0_212-jvmci-20-b01
```bash
$ export JAVA_HOME=/usr/lib/jvm/oraclejdk1.8.0_212-jvmci-20-b01
```
or:
```
export JAVA_HOME=/usr/lib/jvm/jdk-11
```bash
$ export JAVA_HOME=/usr/lib/jvm/jdk-11
```

If you want to ensure your changes will pass both JDK 8 and JDK 11 gates, you can specify the secondary JDK(s) in `EXTRA_JAVA_HOMES`.
For example, to develop for JDK 8 while ensuring `mx build` still works with the JDK 11 specific sources:

```
export JAVA_HOME=/usr/lib/jvm/oraclejdk1.8.0_212-jvmci-20-b01
export EXTRA_JAVA_HOMES=/usr/lib/jvm/jdk-11
```bash
$ export JAVA_HOME=/usr/lib/jvm/oraclejdk1.8.0_212-jvmci-20-b01
$ export EXTRA_JAVA_HOMES=/usr/lib/jvm/jdk-11
```
And on macOS:
```
export JAVA_HOME=/Library/Java/JavaVirtualMachines/oraclejdk1.8.0_212-jvmci-20-b01/Contents/Home
export EXTRA_JAVA_HOMES=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
```bash
$ export JAVA_HOME=/Library/Java/JavaVirtualMachines/oraclejdk1.8.0_212-jvmci-20-b01/Contents/Home
$ export EXTRA_JAVA_HOMES=/Library/Java/JavaVirtualMachines/jdk-11.jdk/Contents/Home
```
If you omit `EXTRA_JAVA_HOMES` in the above examples, versioned projects depending on the specified JDK(s) will be ignored.
Note that `JAVA_HOME` defines the *primary* JDK for development. For instance, when running `mx vm`, this is the JDK that will be used so if you want to run on JDK 11, swap JDK 8 and JDK 11 in `JAVA_HOME` and `EXTRA_JAVA_HOMES`.

Now change to the `graal/compiler` directory:
```
cd graal/compiler
```bash
$ cd graal/compiler
```

Changing to the `graal/compiler` directory informs mx that the focus of development (called the _primary suite_) is the GraalVM compiler.
All subsequent mx commands should be executed from this directory.

Here's the recipe for building and running the GraalVM compiler:

```
mx build
mx vm
```bash
$ mx build
$ mx vm
```

When running `mx vm`, the GraalVM compiler is used as the top tier JIT compiler by default. To revert to using C2 instead,
Expand All @@ -84,8 +84,8 @@ When applying above steps on Windows, replace `export` with `set`.

You can generate IDE project configurations by running:

```
mx ideinit
```bash
$ mx ideinit
```

This will generate Eclipse, IntelliJ, and NetBeans project configurations.
Expand All @@ -97,8 +97,8 @@ You can get a quick insight into this tool by running the commands below.
The first command launches the tool and the second runs one of the unit tests included in the code base with extra options to dump the compiler IR for all methods compiled.
You should wait for the GUI to appear before running the second command.

```
$GRAALVM_EE_HOME/bin/idealgraphvisualizer &
```bash
$ $GRAALVM_EE_HOME/bin/idealgraphvisualizer &
mx unittest -Dgraal.Dump BC_athrow0
```

Expand Down Expand Up @@ -131,36 +131,36 @@ compilers such as C1 and C2.

To build libgraal:

```
cd graal/vm
mx --env libgraal build
```bash
$ cd graal/vm
$ mx --env libgraal build
```
The newly built GraalVM image containing libgraal is available at:
```
mx --env libgraal graalvm-home
```bash
$ mx --env libgraal graalvm-home
```
or following this symlink:
```
./latest_graalvm_home
```bash
$ ./latest_graalvm_home
```
For more information about building GraalVM images, see the [README file of the vm suite](../vm/README.md).

Without leaving the `graal/vm` directory, you can now run libgraal as follows:

1. Use the GraalVM image that you just built:

```
./latest_graalvm_home/bin/java -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```bash
$ ./latest_graalvm_home/bin/java -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```

2. Use `mx`:
- On linux:
```
mx -p ../compiler vm -XX:JVMCILibPath=latest_graalvm_home/jre/lib/amd64 -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```bash
$ mx -p ../compiler vm -XX:JVMCILibPath=latest_graalvm_home/jre/lib/amd64 -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```
- On macOS:
```
mx -p ../compiler vm -XX:JVMCILibPath=latest_graalvm_home/jre/lib -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```bash
$ mx -p ../compiler vm -XX:JVMCILibPath=latest_graalvm_home/jre/lib -XX:+UseJVMCICompiler -XX:+UseJVMCINativeLibrary ...
```

## Publications and Presentations
Expand Down
50 changes: 25 additions & 25 deletions espresso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,17 @@ Set your (JVMCI-enabled) JDK via `mx` argument e.g. `mx --java-home /path/to/ja

To build the default configuration (interpreter-only), on the `espresso` repository:
```bash
mx build
$ mx build
```

Other configurations are provided:
```bash
mx --env jvm build # GraalVM CE + Espresso jars (interpreter only)
mx --env jvm-ce build # GraalVM CE + Espresso jars (JIT)
mx --env native-ce build # GraalVM CE + Espresso native (JIT)
$ mx --env jvm build # GraalVM CE + Espresso jars (interpreter only)
$ mx --env jvm-ce build # GraalVM CE + Espresso jars (JIT)
$ mx --env native-ce build # GraalVM CE + Espresso native (JIT)

# Use the same --env argument used to build.
export ESPRESSO=`mx --env native-ce graalvm-home`/bin/espresso
$ export ESPRESSO=`mx --env native-ce graalvm-home`/bin/espresso
```

Configuration files: `mx.espresso/{jvm,jvm-ce,native-ce}` and `mx.espresso/native-image.properties`
Expand All @@ -42,64 +42,64 @@ Configuration files: `mx.espresso/{jvm,jvm-ce,native-ce}` and `mx.espresso/nativ
`mx espresso` runs Espresso (from jars or native) from within a GraalVM. It mimics the `java` (8|11) command. Bare `mx espresso` runs Espresso on interpreter-only mode.

```bash
mx --env jvm-ce build # Always build first
mx --env jvm-ce espresso -cp my.jar HelloWorld
$ mx --env jvm-ce build # Always build first
$ mx --env jvm-ce espresso -cp my.jar HelloWorld
```

To build and run Espresso native image:
```bash
mx --env native-ce build # Always build first
mx --env native-ce espresso -cp my.jar HelloWorld
$ mx --env native-ce build # Always build first
$ mx --env native-ce espresso -cp my.jar HelloWorld
```

The `mx espresso` launcher adds some overhead, to execute Espresso native image directly use:
```bash
mx --env native-ce build # Always build first
export ESPRESSO=`mx --env native-ce graalvm-home`/bin/espresso
time $ESPRESSO -cp my.jar HelloWorld
$ mx --env native-ce build # Always build first
$ export ESPRESSO=`mx --env native-ce graalvm-home`/bin/espresso
$ time $ESPRESSO -cp my.jar HelloWorld
```

### `mx espresso-standalone ...`
To run Espresso on a vanilla JDK (8|11) and/or not within a GraalVM use `mx espresso-standalone ...`, it mimics the `java` (8|11) command. The launcher adds all jars and properties required to run Espresso on any vanilla JDK (8|11).

To debug Espresso:
```
mx build
mx -d espresso-standalone -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.HelloWorld
```bash
$ mx build
$ mx -d espresso-standalone -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.HelloWorld
```

It can also run on a GraalVM with JIT compilation:
```bash
mx build
mx --dy /compiler espresso-standalone -cp my.jar HelloWorld
$ mx build
$ mx --dy /compiler espresso-standalone -cp my.jar HelloWorld
```

### Dumping IGV graphs
```bash
mx -v --dy /compiler -J"-Dgraal.Dump=:4 -Dgraal.TraceTruffleCompilation=true -Dgraal.TruffleBackgroundCompilation=false" espresso-standalone -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.TestMain
$ mx -v --dy /compiler -J"-Dgraal.Dump=:4 -Dgraal.TraceTruffleCompilation=true -Dgraal.TruffleBackgroundCompilation=false" espresso-standalone -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.TestMain
```

### Running Espresso cross-versions
By default, Espresso runs within a GraalVM and it reuses the jars and native libraries shipped with GraalVM. But it's possible to specify a different Java home, even with a different version; Espresso will automatically switch versions regardless of the host JVM.
```bash
mx build
mx espresso -version
mx espresso --java.JavaHome=/path/to/java/8/home -version
mx espresso --java.JavaHome=/path/to/java/11/home -version
$ mx build
$ mx espresso -version
$ mx espresso --java.JavaHome=/path/to/java/8/home -version
$ mx espresso --java.JavaHome=/path/to/java/11/home -version
```

### Limitations
Espresso relies on glibc's [dlmopen](https://man7.org/linux/man-pages/man3/dlopen.3.html) to run on HotSpot, but this approach has limitations that lead to crashes e.g. `libnio.so: undefined symbol: fstatat64` . Some of these limitations can be by avoided by defining `LD_DEBUG=unused` e.g.
```bash
LD_DEBUG=unused mx espresso -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.Tetris
$ LD_DEBUG=unused mx espresso -cp mxbuild/dists/jdk1.8/espresso-playground.jar com.oracle.truffle.espresso.playground.Tetris
```

## _Espressoⁿ_ Java-ception
**Self-hosting requires a Linux distribution with an up-to-date glibc.**
Use `mx espresso-meta` to run programs on Espresso². Ensure to prepend `LD_DEBUG=unused` to overcome a known **glibc** bug.
To run HelloWorld on Espresso² execute the following:
```bash
mx build
LD_DEBUG=unused mx --dy /compiler espresso-meta -cp my.jar HelloWorld
$ mx build
$ LD_DEBUG=unused mx --dy /compiler espresso-meta -cp my.jar HelloWorld
```
It takes some time for both (nested) VMs to boot, only the base layer is blessed with JIT compilation. Enjoy!
4 changes: 2 additions & 2 deletions regex/docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ following results:

An example of how to parse a regular expression:

```
```java
Source source = Source.newBuilder("regex", "Flavor=ECMAScript/(a|(b))c/i", "myRegex").mimeType("application/tregex").internal(true).build();
Object regex;
try {
Expand Down Expand Up @@ -70,7 +70,7 @@ the result of a `RegexObject`'s

Compiled regex usage example in pseudocode:

```
```java
regex = <matcher from previous example>
assert(regex.pattern == "(a|(b))c")
assert(regex.flags.ignoreCase == true)
Expand Down
16 changes: 8 additions & 8 deletions tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ and put onto your PATH. Also, point `JAVA_HOME` to a
[JVMCI-enabled JDK 8](https://github.com/graalvm/openjdk8-jvmci-builder/releases).

```bash
git clone https://github.com/graalvm/mx.git
export PATH=$PWD/mx:$PATH
git clone https://github.com/graalvm/graal.git
cd graal/tools
mx build
mx unittest
$ git clone https://github.com/graalvm/mx.git
$ export PATH=$PWD/mx:$PATH
$ git clone https://github.com/graalvm/graal.git
$ cd graal/tools
$ mx build
$ mx unittest
```

## IDE Configuration

You can generate IDE project configurations by running:

```
mx ideinit
```bash
$ mx ideinit
```

This will generate Eclipse, IntelliJ, and NetBeans project configurations.
Expand Down
8 changes: 4 additions & 4 deletions vm/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ This can be done either by:

After the compilation:
- the `latest_graalvm` symbolic link points to the latest built GraalVM
- `$ mx [build-time arguments] graalvm-home` prints the path to the GraalVM home directory
- `mx [build-time arguments] graalvm-home` prints the path to the GraalVM home directory

Note that the build dependencies of each component are specified in the README file of the corresponding repository.
A common requirement is that the `JAVA_HOME` environment variable must point to the latest JVMCI-enabled JDK8 ([pre-built archives](https://github.com/graalvm/openjdk8-jvmci-builder/releases); [build instructions](https://github.com/graalvm/openjdk8-jvmci-builder)).
Expand All @@ -19,7 +19,7 @@ A common requirement is that the `JAVA_HOME` environment variable must point to

In any of the build commands, replace `build` with `graalvm-show`:
```bash
mx ... graalvm-show
$ mx ... graalvm-show
```

This will show a list of components, launchers and libraries to be built.
Expand Down Expand Up @@ -127,12 +127,12 @@ builds the native SubstrateVM launcher for native-image, and creates bash launch

### Example: build only TruffleRuby with bash launchers
```bash
mx --dy truffleruby --components='TruffleRuby' build
$ mx --dy truffleruby --components='TruffleRuby' build
```

### Example: build only the TruffleRuby launcher
```bash
mx --dy truffleruby,/substratevm,/tools --components='TruffleRuby,Native Image,suite:tools' --native-images=truffleruby build
$ mx --dy truffleruby,/substratevm,/tools --components='TruffleRuby,Native Image,suite:tools' --native-images=truffleruby build
```
or as env file (e.g., in `mx.vm/ruby`):
```
Expand Down
Loading

0 comments on commit 9790f52

Please sign in to comment.