From: Waldemar Kozaczuk <jwkozac...@gmail.com>
Committer: Waldemar Kozaczuk <jwkozac...@gmail.com>
Branch: master

Update graalvm-example to use latest version 19.1.0

This patch also converts the app to build as a regular
self-contained Linux executable that runs as-is on OSv.
The previous version of this example built it as a shared
library.

This also fixes cloudius-systems/osv#1031

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>

---
diff --git a/graalvm-example/Hello.java b/graalvm-example/Hello.java
--- a/graalvm-example/Hello.java
+++ b/graalvm-example/Hello.java
@@ -1,15 +1,21 @@
-//
-// Copyright (C) 2018 Waldek Kozaczuk
-//
-// This work is open source software, licensed under the terms of the
-// BSD license as described in the LICENSE file in the top-level directory.
-//
-import org.graalvm.nativeimage.IsolateThread;
-import org.graalvm.nativeimage.c.function.CEntryPoint;
+import java.lang.management.ManagementFactory;
+
+import org.graalvm.nativeimage.*;
+import org.graalvm.nativeimage.Isolates.CreateIsolateParameters;

 public class Hello {
-    @CEntryPoint(name = "graal_main")
-    public static void main(IsolateThread thread) {
+    public static void main(String[] args) {
         System.out.println("Hello, World from GraalVM on OSv!");
+
+        /* Create a new isolate for the next function evaluation. */
+ IsolateThread newContext = Isolates.createIsolate(CreateIsolateParameters.getDefault());
+
+ System.out.println("Hello, World from GraalVM on OSv from an isolate!");
+
+        /* Tear down the isolate, freeing all the temporary objects. */
+        Isolates.tearDownIsolate(newContext);
+
+ long currentMemory = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed(); + System.out.println("Memory usage: " + currentMemory / 1024 + " KByte" );
     }
 }
diff --git a/graalvm-example/Makefile b/graalvm-example/Makefile
--- a/graalvm-example/Makefile
+++ b/graalvm-example/Makefile
@@ -1,20 +1,20 @@
-module: main.so
+module: hello

-CFLAGS = -std=gnu99 -fPIC -rdynamic
+GRAAL_VERSION=19.1.0

-main.so: libhello.so main.c
-       $(CC) -pie -o $@ $(CFLAGS) -I. main.c -L. -lhello -ldl
+Hello.class: Hello.java upstream/graalvm-ce-$(GRAAL_VERSION)
+       upstream/graalvm-ce-$(GRAAL_VERSION)/bin/javac -d . Hello.java

-Hello.class: Hello.java upstream/graalvm-ce-1.0.0-rc12
-       upstream/graalvm-ce-1.0.0-rc12/bin/javac -d . Hello.java
+hello: Hello.class upstream/graalvm-ce-$(GRAAL_VERSION)/bin/native-image
+       upstream/graalvm-ce-$(GRAAL_VERSION)/bin/native-image --no-server Hello

-libhello.so: Hello.class upstream/graalvm-ce-1.0.0-rc12
- upstream/graalvm-ce-1.0.0-rc12/bin/native-image --no-server --shared -H:Name=libhello
-
-upstream/graalvm-ce-1.0.0-rc12:
+upstream/graalvm-ce-$(GRAAL_VERSION):
        mkdir -p upstream
- wget -c -O upstream/graalvm.tar.gz https://github.com/oracle/graal/releases/download/vm-1.0.0-rc12/graalvm-ce-1.0.0-rc12-linux-amd64.tar.gz
-       cd upstream && tar xf graalvm.tar.gz
+ wget -c -O upstream/graalvm-ce-linux-amd64-$(GRAAL_VERSION).tar.gz https://github.com/oracle/graal/releases/download/vm-$(GRAAL_VERSION)/graalvm-ce-linux-amd64-$(GRAAL_VERSION).tar.gz
+       cd upstream && tar xf graalvm-ce-linux-amd64-$(GRAAL_VERSION).tar.gz
+
+upstream/graalvm-ce-$(GRAAL_VERSION)/bin/native-image: upstream/graalvm-ce-$(GRAAL_VERSION) + cd upstream/graalvm-ce-$(GRAAL_VERSION) && ./bin/gu install native-image && touch ./bin/native-image

 clean:
-       rm -rf *.class libhello* main*.so graal*.h upstream
+       rm -rf *.class hello upstream
diff --git a/graalvm-example/main.c b/graalvm-example/main.c
--- a/graalvm-example/main.c
+++ b/graalvm-example/main.c
@@ -1,23 +0,0 @@
-//
-// Copyright (C) 2018 Waldek Kozaczuk
-//
-// This work is open source software, licensed under the terms of the
-// BSD license as described in the LICENSE file in the top-level directory.
-//
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <libhello.h>
-
-int main(int argc, char **argv) {
-  graal_isolate_t *isolate = NULL;
-  graal_isolatethread_t *thread = NULL;
-
-  if (graal_create_isolate(NULL, &isolate, &thread) != 0) {
-    fprintf(stderr, "initialization error\n");
-    return 1;
-  }
-
-  graal_main(thread);
-  return 0;
-}
diff --git a/graalvm-example/module.py b/graalvm-example/module.py
--- a/graalvm-example/module.py
+++ b/graalvm-example/module.py
@@ -1,3 +1,3 @@
 from osv.modules import api

-default = api.run("/main.so")
+default = api.run("/hello")
diff --git a/graalvm-example/usr.manifest b/graalvm-example/usr.manifest
--- a/graalvm-example/usr.manifest
+++ b/graalvm-example/usr.manifest
@@ -1,2 +1 @@
-/main.so: ${MODULE_DIR}/main.so
-/libhello.so: ${MODULE_DIR}/libhello.so
+/hello: ${MODULE_DIR}/hello

--
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/000000000000d78fc9058d36adc3%40google.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to