Graal VM
Homepage | Documentation | Github
Native Image¶
Scala 2.13.x support¶
See scala/bug#11634, you will need a substitution for scala.runtime.Statics
:
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
@TargetClass(className = "scala.runtime.Statics")
final class Target_scala_runtime_Statics {
@Substitute
public static void releaseFence() {
UnsafeUtils.UNSAFE.storeFence();
}
}
import java.lang.reflect.Field;
class UnsafeUtils {
static final sun.misc.Unsafe UNSAFE;
static {
try {
Field field = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
UNSAFE = (sun.misc.Unsafe) field.get(null);
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
}
Size of generated image¶
Currently not quite optimized it seems. See oracle/graal#287 for ongoing discussion about that.
Generating heap dumps for substrate VM at runtime¶
Warning
Currently not possible for CE!
Print heap histogram from inside binary¶
Similar to what jmap -histo
would do on openjdk but from inside the process. Would probably make sense to trigger GC right before that if you are only interested in live objects.
(as of CE 20.1.0)
import com.oracle.svm.core.heap.ClassHistogramVisitor;
import com.oracle.svm.core.heap.Heap;
import com.oracle.svm.core.log.Log;
import com.oracle.svm.core.thread.JavaVMOperation;
JavaVMOperation.enqueueBlockingSafepoint("histo", () -> {
ClassHistogramVisitor vis = ClassHistogramVisitor.factory();
Heap.getHeap().walkImageHeapObjects(vis);
vis.toLogByCount(Log.log(), 0, false);
});
0.1.0*