Created
June 10, 2018 23:47
-
-
Save shelajev/b9d6cbd9814151662d539dfeebb48ded to your computer and use it in GitHub Desktop.
PolyglotTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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