Skip to content

Commit ccf937a

Browse files
committed
update hello world
1 parent 11fd75a commit ccf937a

File tree

1 file changed

+58
-47
lines changed

1 file changed

+58
-47
lines changed

doc/clojure-graalvm-native-binary.md

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ your Clojure projects using GraalVM.
55

66

77
### Step1 - Download and install GraalVM
8-
Go to https://github.com/oracle/graal/releases and download the
8+
Go to https://github.com/graalvm/graalvm-ce-builds/releases and download the
99
binaries for your platform.
1010

1111
Unpack the package in a folder and add it to the path:
@@ -14,24 +14,33 @@ Unpack the package in a folder and add it to the path:
1414
$ export GRAALVM_HOME=/full/path/to/graalvm
1515
$ export PATH=$GRAALVM_HOME/bin:$PATH
1616
$ java -version
17-
openjdk version "1.8.0_212"
18-
OpenJDK Runtime Environment (build 1.8.0_212-20190420112649.buildslave.jdk8u-src-tar--b03)
19-
OpenJDK GraalVM CE 19.0.0 (build 25.212-b03-jvmci-19-b01, mixed mode)
17+
openjdk version "11.0.7" 2020-04-14
18+
OpenJDK Runtime Environment GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02)
19+
OpenJDK 64-Bit Server VM GraalVM CE 20.1.0 (build 11.0.7+10-jvmci-20.1-b02, mixed mode, sharing)
2020
```
2121

2222
Now install the `native-image` component:
2323

2424
``` bash
2525
$ gu install native-image
2626
Downloading: Component catalog from www.graalvm.org
27-
Processing component archive: Native Image
28-
Component Native Image (org.graalvm.native-image) installed.
27+
Processing Component: Native Image
28+
Downloading: Component native-image: Native Image from github.com
29+
Installing new component: Native Image (org.graalvm.native-image, version 20.1.0)
2930

3031
$ gu list
3132
ComponentId Version Component name Origin
3233
--------------------------------------------------------------------------------
33-
graalvm 19.0.0 GraalVM Core
34-
native-image 19.0.0 Native Image licencegithub.com
34+
graalvm 20.1.0 GraalVM Core
35+
native-image 20.1.0 Native Image github.com
36+
```
37+
38+
**NOTE**: *if you are on Mac OSX you might need to de-quarantine the binaries.*
39+
Here a script to do so:
40+
41+
``` bash
42+
# for Mac OSX
43+
sudo xattr -r -d com.apple.quarantine ${GRAALVM_HOME}
3544
```
3645

3746
### Step2 - Your project
@@ -55,7 +64,7 @@ Update the `project.clj` and add the `:main`
5564
:url "http://example.com/FIXME"
5665
:license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
5766
:url "https://www.eclipse.org/legal/epl-2.0/"}
58-
:dependencies [[org.clojure/clojure "1.9.0"]]
67+
:dependencies [[org.clojure/clojure "1.10.1"]]
5968
;; add the main namespace
6069
:main hello-world.core
6170

@@ -89,8 +98,8 @@ Now build a uberjar.
8998
``` bash
9099
$ lein do clean, uberjar
91100
Compiling hello-world.core
92-
Created /private/tmp/5/hello-world/target/hello-world-0.1.0-SNAPSHOT.jar
93-
Created /private/tmp/5/hello-world/target/hello-world-0.1.0-SNAPSHOT-standalone.jar
101+
Created /private/tmp/hello-world/target/hello-world-0.1.0-SNAPSHOT.jar
102+
Created /private/tmp/hello-world/target/hello-world-0.1.0-SNAPSHOT-standalone.jar
94103
```
95104

96105
Now that you have a `-standalone.jar` file which contains all the
@@ -103,26 +112,26 @@ can proceed to build the native binary.
103112
``` bash
104113
native-image --report-unsupported-elements-at-runtime \
105114
--initialize-at-build-time \
115+
--no-server \
106116
-jar ./target/hello-world-0.1.0-SNAPSHOT-standalone.jar \
107117
-H:Name=./target/hello-world
108118

109-
Build on Server(pid: 76573, port: 63429)*
110-
[./target/hello-world:76573] classlist: 2,931.41 ms
111-
[./target/hello-world:76573] (cap): 2,494.11 ms
112-
[./target/hello-world:76573] setup: 4,030.12 ms
113-
[./target/hello-world:76573] (typeflow): 5,544.43 ms
114-
[./target/hello-world:76573] (objects): 2,177.19 ms
115-
[./target/hello-world:76573] (features): 225.10 ms
116-
[./target/hello-world:76573] analysis: 8,098.25 ms
117-
[./target/hello-world:76573] (clinit): 136.48 ms
118-
[./target/hello-world:76573] universe: 399.00 ms
119-
[./target/hello-world:76573] (parse): 1,106.76 ms
120-
[./target/hello-world:76573] (inline): 1,968.59 ms
121-
[./target/hello-world:76573] (compile): 9,156.00 ms
122-
[./target/hello-world:76573] compile: 12,728.30 ms
123-
[./target/hello-world:76573] image: 975.56 ms
124-
[./target/hello-world:76573] write: 252.32 ms
125-
[./target/hello-world:76573] [total]: 29,587.34 ms
119+
[./target/hello-world:33840] classlist: 3,119.60 ms, 0.96 GB
120+
[./target/hello-world:33840] (cap): 2,250.97 ms, 0.96 GB
121+
[./target/hello-world:33840] setup: 3,980.23 ms, 0.96 GB
122+
[./target/hello-world:33840] (clinit): 163.43 ms, 1.72 GB
123+
[./target/hello-world:33840] (typeflow): 6,249.38 ms, 1.72 GB
124+
[./target/hello-world:33840] (objects): 4,975.02 ms, 1.72 GB
125+
[./target/hello-world:33840] (features): 202.49 ms, 1.72 GB
126+
[./target/hello-world:33840] analysis: 11,819.61 ms, 1.72 GB
127+
[./target/hello-world:33840] universe: 341.69 ms, 1.72 GB
128+
[./target/hello-world:33840] (parse): 1,850.44 ms, 1.72 GB
129+
[./target/hello-world:33840] (inline): 2,497.03 ms, 1.72 GB
130+
[./target/hello-world:33840] (compile): 12,415.94 ms, 2.35 GB
131+
[./target/hello-world:33840] compile: 17,341.60 ms, 2.35 GB
132+
[./target/hello-world:33840] image: 1,197.96 ms, 2.35 GB
133+
[./target/hello-world:33840] write: 643.75 ms, 2.35 GB
134+
[./target/hello-world:33840] [total]: 38,716.97 ms, 2.35 GB
126135
```
127136

128137
That's it! now you can test your native binary!
@@ -170,7 +179,7 @@ Now you can add an alias for it the `project.clj itself:
170179
{"native"
171180
["shell"
172181
"native-image" "--report-unsupported-elements-at-runtime"
173-
"--initialize-at-build-time"
182+
"--initialize-at-build-time" "--no-server"
174183
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
175184
"-H:Name=./target/${:name}"]}
176185
```
@@ -192,7 +201,7 @@ Overall your `project.clj` should look like as follow:
192201
{"native"
193202
["shell"
194203
"native-image" "--report-unsupported-elements-at-runtime"
195-
"--initialize-at-build-time"
204+
"--initialize-at-build-time" "--no-server"
196205
"-jar" "./target/${:uberjar-name:-${:name}-${:version}-standalone.jar}"
197206
"-H:Name=./target/${:name}"]}
198207
)
@@ -202,24 +211,26 @@ With this in place you can just run `lein native` to build the native binary:
202211

203212
``` bash
204213
$ lein native
205-
Build on Server(pid: 76573, port: 63429)
206-
[./target/hello-world:76573] classlist: 925.69 ms
207-
[./target/hello-world:76573] (cap): 1,052.47 ms
208-
[./target/hello-world:76573] setup: 1,416.62 ms
209-
[./target/hello-world:76573] (typeflow): 3,499.51 ms
210-
[./target/hello-world:76573] (objects): 1,224.39 ms
211-
[./target/hello-world:76573] (features): 129.42 ms
212-
[./target/hello-world:76573] analysis: 4,946.87 ms
213-
[./target/hello-world:76573] (clinit): 95.94 ms
214-
[./target/hello-world:76573] universe: 298.63 ms
215-
[./target/hello-world:76573] (parse): 622.46 ms
216-
[./target/hello-world:76573] (inline): 1,119.10 ms
217-
[./target/hello-world:76573] (compile): 4,646.36 ms
218-
[./target/hello-world:76573] compile: 6,730.73 ms
219-
[./target/hello-world:76573] image: 672.79 ms
220-
[./target/hello-world:76573] write: 199.98 ms
221-
[./target/hello-world:76573] [total]: 15,268.99 ms
214+
OpenJDK 64-Bit Server VM warning: forcing TieredStopAtLevel to full optimization because JVMCI is enabled
215+
[./target/hello-world:33980] classlist: 2,970.75 ms, 0.96 GB
216+
[./target/hello-world:33980] (cap): 2,824.32 ms, 0.96 GB
217+
[./target/hello-world:33980] setup: 4,532.29 ms, 0.96 GB
218+
[./target/hello-world:33980] (clinit): 180.49 ms, 1.72 GB
219+
[./target/hello-world:33980] (typeflow): 6,960.70 ms, 1.72 GB
220+
[./target/hello-world:33980] (objects): 4,050.59 ms, 1.72 GB
221+
[./target/hello-world:33980] (features): 267.73 ms, 1.72 GB
222+
[./target/hello-world:33980] analysis: 11,822.33 ms, 1.72 GB
223+
[./target/hello-world:33980] universe: 322.57 ms, 1.72 GB
224+
[./target/hello-world:33980] (parse): 1,758.44 ms, 1.72 GB
225+
[./target/hello-world:33980] (inline): 2,497.64 ms, 1.72 GB
226+
[./target/hello-world:33980] (compile): 12,186.63 ms, 2.35 GB
227+
[./target/hello-world:33980] compile: 17,039.18 ms, 2.35 GB
228+
[./target/hello-world:33980] image: 1,252.06 ms, 2.35 GB
229+
[./target/hello-world:33980] write: 430.08 ms, 2.35 GB
230+
[./target/hello-world:33980] [total]: 38,668.99 ms, 2.35 GB
222231

223232
$ ./target/hello-world
224233
Hello, World!
225234
```
235+
236+
Happy hacking!

0 commit comments

Comments
 (0)