Skip to content

Instantly share code, notes, and snippets.

@shelajev
Created June 10, 2018 23:47
Show Gist options
  • Select an option

  • Save shelajev/b9d6cbd9814151662d539dfeebb48ded to your computer and use it in GitHub Desktop.

Select an option

Save shelajev/b9d6cbd9814151662d539dfeebb48ded to your computer and use it in GitHub Desktop.
PolyglotTest.java
public class PolyglotTest {
public static void main(String[] args) {
System.out.println("Hello World from Java!");
org.graalvm.polyglot.Context context = org.graalvm.polyglot.Context.newBuilder().allowAllAccess(true).build();
context.eval("js", "print('Hello World from JavaScript!');");
// context.eval("python", "print('Hello World from Python!')");
// context.eval("R", "print('Hello World from R!')");
// context.eval("ruby", "puts 'Hello World from Ruby!'");
context.close();
try { createHeapDump(); }
catch (java.io.IOException ex) {}
}
private static void createHeapDump() throws java.io.IOException {
java.io.File file = java.io.File.createTempFile("svm-heapdump-", ".hprof");
java.io.FileOutputStream fileOutputStream = new java.io.FileOutputStream(file);
String command = "HeapDump.dumpHeap(FileOutputStream, Boolean)Boolean";
Compiler.command(new Object[] { command, fileOutputStream, Boolean.TRUE });
fileOutputStream.close();
System.out.println("Heap dump saved to " + file.getAbsolutePath());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment