More Related Content Similar to Project Panama - Beyond the (JVM) Wall (20) More from Christoph Engelbert (20) Project Panama - Beyond the (JVM) Wall20. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
Starting with the C part :-)
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
21. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
Starting with the C part :-)
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
kernel call
23. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
Starting with the C part :-)
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
24. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
Starting with the C part :-)
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
JNI version definition
25. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
done, easy right?
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
26. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
oh, missing the Java side, still
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
public class ProcessIdentifier {
static {
System.loadLibrary("processidentifier");
}
public native void getProcessId();
}
27. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
oh, missing the Java side, still
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
public class ProcessIdentifier {
static {
System.loadLibrary("processidentifier");
}
public native void getProcessId();
}
Java Classname
28. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
oh, missing the Java side, still
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
public class ProcessIdentifier {
static {
System.loadLibrary("processidentifier");
}
public native void getProcessId();
}
Java Classname Java Methodname
29. www.hazelcast.com@noctarius2k
extern C {
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);
}
JNIEXPORT int JNICALL
Java_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) {
return getpid();
}
ok, ok, now we’re done!
JNIEXPORT jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved) {
return JNI_VERSION_1_2;
}
public class ProcessIdentifier {
static {
System.loadLibrary("processidentifier");
}
public native void getProcessId();
}
60. www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
LayoutType<Byte> layout =
NativeLibrary.createLayout(byte.class);
try (Scope scope = new NativeScope()) {
Pointer<Byte> p = scope.allocate(layout, 20);
Reference<Byte> ref = p.offset(5).deref();
byte val = ref.get();
}
61. www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
LayoutType<Byte> layout =
NativeLibrary.createLayout(byte.class);
try (Scope scope = new NativeScope()) {
Pointer<Byte> p = scope.allocate(layout, 20);
Reference<Byte> ref = p.offset(5).deref();
byte val = ref.get();
}
byte-array
layout
62. www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
LayoutType<Byte> layout =
NativeLibrary.createLayout(byte.class);
try (Scope scope = new NativeScope()) {
Pointer<Byte> p = scope.allocate(layout, 20);
Reference<Byte> ref = p.offset(5).deref();
byte val = ref.get();
}
byte-array
layout
create a
scope
63. www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
LayoutType<Byte> layout =
NativeLibrary.createLayout(byte.class);
try (Scope scope = new NativeScope()) {
Pointer<Byte> p = scope.allocate(layout, 20);
Reference<Byte> ref = p.offset(5).deref();
byte val = ref.get();
}
byte-array
layout
create a
scope
allocate
20 bytes
64. www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
LayoutType<Byte> layout =
NativeLibrary.createLayout(byte.class);
try (Scope scope = new NativeScope()) {
Pointer<Byte> p = scope.allocate(layout, 20);
Reference<Byte> ref = p.offset(5).deref();
byte val = ref.get();
}
byte-array
layout
create a
scope
allocate
20 bytes
get byte
at ptr+5
74. www.hazelcast.com@noctarius2k
Scope scope = new NativeScope();
Pointer<Node> ptr = scope.allocate(Node.class);
Node node = ptr.getLayout();
int val = node.val();
Node next = node.next();
Creating layouted Objects
84. www.hazelcast.com@noctarius2k
Coding a Vector-Function in Java
high-level
interface Vector<E, S extends Shape<Vector?, S>> {
Vector<E, S> add (Vector<E, S> other);
Vector<E, S> mul (Vector<E, S> other);
Vector<E, S> and (Vector<E, S> other);
// ... more operations
}
98. www.hazelcast.com@noctarius2k
More information:
• http://openjdk.java.net/projects/valhalla/
• http://openjdk.java.net/projects/panama/
• http://cr.openjdk.java.net/~jrose/values/values-0.html
• http://blog.codefx.org/java/dev/the-road-to-valhalla/
• http://openjdk.java.net/jeps/191
• https://www.youtube.com/watch?v=JR1zI5gLhRM
• https://github.com/J9Java/panama-layout-prototype
• https://developer.ibm.com/open/openprojects/project-panama-layout-prototype/
• https://www.youtube.com/watch?v=Tc9vs_HFHVo
• https://www.youtube.com/watch?v=Z2XgO1H6xPM
Thank You!