Project Panama - Beyond the (JVM) Wall
-
Upload
christoph-engelbert -
Category
Software
-
view
1.127 -
download
0
Transcript of Project Panama - Beyond the (JVM) Wall
![Page 1: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/1.jpg)
https://middleofnowheregaming.files.wordpress.com/2015/04/game-of-thrones_20150327091828.jpg
Project PanamaBeyond the (JVM) Wall
![Page 2: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/2.jpg)
www.hazelcast.com@noctarius2k
DisclaimerThis is not a rant - promised!
Just a little bit about JNI ;-)
![Page 3: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/3.jpg)
www.hazelcast.com@noctarius2k
Disclaimer #2If you haven’t seen Game of Thrones yet
keep your eyes closed!
![Page 4: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/4.jpg)
www.hazelcast.com@noctarius2k
Disclaimer #3Everything is provisional
Don’t take anything as final!
![Page 5: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/5.jpg)
www.hazelcast.com@noctarius2k
Who’s that dude?• Chris Engelbert • Manager of Developer Relations @Hazelcast
• Java-Passionate (10+ years)
• Performance • Garbage Collection • JVM / Benchmark Fairytales
![Page 6: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/6.jpg)
www.hazelcast.com@noctarius2k
I drink and I know things (sometimes)
![Page 7: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/7.jpg)
www.hazelcast.com@noctarius2k
Project Panama
The True Native Love
![Page 8: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/8.jpg)
www.hazelcast.com@noctarius2k
Unite Enemies
C/C++Java
![Page 9: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/9.jpg)
www.hazelcast.com@noctarius2k
JNI! That's a good name for you!
![Page 10: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/10.jpg)
www.hazelcast.com@noctarius2k
JNI brings interaction between native code and Java
#include <unistd.h>int pid = getpid();
simple kernel call
![Page 11: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/11.jpg)
www.hazelcast.com@noctarius2k
JNI brings interaction between native code and Java
#include <unistd.h>int pid = getpid();
simple kernel call header import
![Page 12: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/12.jpg)
www.hazelcast.com@noctarius2k
JNI brings interaction between native code and Java
#include <unistd.h>int pid = getpid();
simple kernel call header import
request PID
![Page 13: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/13.jpg)
www.hazelcast.com@noctarius2k
#include <unistd.h>int pid = getpid();
Isn’t that easy in C?
![Page 14: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/14.jpg)
www.hazelcast.com@noctarius2k
You know nothing, of JNI!
![Page 15: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/15.jpg)
www.hazelcast.com@noctarius2k
Starting with the C part :-)
![Page 16: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/16.jpg)
www.hazelcast.com@noctarius2k
Starting with the C part :-)
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
![Page 17: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/17.jpg)
www.hazelcast.com@noctarius2k
Starting with the C part :-)
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
export it as a JNI method
![Page 18: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/18.jpg)
www.hazelcast.com@noctarius2k
Starting with the C part :-)
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
export it as a JNI method
Java Classname
![Page 19: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/19.jpg)
www.hazelcast.com@noctarius2k
Starting with the C part :-)
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
export it as a JNI method
Java Classname Java Methodname
![Page 20: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/20.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
Starting with the C part :-)
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
![Page 21: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/21.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
Starting with the C part :-)
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
kernel call
![Page 22: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/22.jpg)
www.hazelcast.com@noctarius2k
When you think you just won…
![Page 23: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/23.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
Starting with the C part :-)JNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
![Page 24: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/24.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
Starting with the C part :-)JNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
JNI version definition
![Page 25: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/25.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
done, easy right?JNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
![Page 26: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/26.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
oh, missing the Java side, stillJNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
public class ProcessIdentifier { static { System.loadLibrary("processidentifier"); }
public native void getProcessId();}
![Page 27: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/27.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
oh, missing the Java side, stillJNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
public class ProcessIdentifier { static { System.loadLibrary("processidentifier"); }
public native void getProcessId();}
Java Classname
![Page 28: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/28.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
oh, missing the Java side, stillJNIEXPORT jint JNICALLJNI_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
![Page 29: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/29.jpg)
www.hazelcast.com@noctarius2k
extern C { JNIEXPORT int JNICALL Java_ProcessIdentifier_getProcessId(JNIEnv *, jobject);}
JNIEXPORT int JNICALLJava_ProcessIdentifier_getProcessId(JNIEnv *env, jobject thisObject) { return getpid();}
ok, ok, now we’re done!JNIEXPORT jint JNICALLJNI_OnLoad(JavaVM *vm, void *reserved) { return JNI_VERSION_1_2;}
public class ProcessIdentifier { static { System.loadLibrary("processidentifier"); }
public native void getProcessId();}
![Page 30: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/30.jpg)
www.hazelcast.com@noctarius2k
Wasn’t that easy?
![Page 31: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/31.jpg)
www.hazelcast.com@noctarius2k
Wasn’t that easy?
but remember…
![Page 32: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/32.jpg)
www.hazelcast.com@noctarius2k
Everybody struggles with JNI!
![Page 33: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/33.jpg)
www.hazelcast.com@noctarius2k
meanwhile behind the wall…
![Page 34: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/34.jpg)
www.hazelcast.com@noctarius2k
Java 9 to the rescue
![Page 35: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/35.jpg)
www.hazelcast.com@noctarius2k
Java 9 to the rescue
long pid = ProcessHandle.current().getPid();
![Page 36: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/36.jpg)
www.hazelcast.com@noctarius2k
Java 9 to the rescue
long pid = ProcessHandle.current().getPid();
convenient, eh?
![Page 37: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/37.jpg)
www.hazelcast.com@noctarius2k
but how many can just update?
![Page 38: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/38.jpg)
www.hazelcast.com@noctarius2k
So? JNI?
![Page 39: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/39.jpg)
www.hazelcast.com@noctarius2k
So? JNI? - NO!
![Page 40: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/40.jpg)
www.hazelcast.com@noctarius2k
A Song From Methods And Handles
![Page 41: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/41.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
![Page 42: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/42.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
type definition
![Page 43: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/43.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
returntypetype definition
![Page 44: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/44.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
returntypetype definition
Java Classname
![Page 45: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/45.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
returntypetype definition
Java Classname Java Methodname
![Page 46: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/46.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
returntypetype definition
Java Classname Java Methodnamecall the new callsite
![Page 47: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/47.jpg)
www.hazelcast.com@noctarius2k
MethodHandles
So? What’s the deal? Java 7, right?
![Page 48: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/48.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
![Page 49: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/49.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findVirtual(ProcessIdentifier.class, "getProcessId", type);
int pid = mh.invokeExact();
virtual call
![Page 50: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/50.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findNative(null, "getpid", type);
int pid = mh.invokeExact();
native
![Page 51: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/51.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findNative(null, "getpid", type);
int pid = mh.invokeExact();
native
native call
![Page 52: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/52.jpg)
www.hazelcast.com@noctarius2k
MethodHandlesMethodType type = MethodType.methodType(int.class);MethodHandle mh = MethodHandles.lookup() .findNative(null, "getpid", type);
int pid = mh.invokeExact();
native
native call null = kernel callotherwise lib name
![Page 53: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/53.jpg)
www.hazelcast.com@noctarius2k
Easier than takingthe Iron Throne!
![Page 54: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/54.jpg)
www.hazelcast.com@noctarius2k
The Mad King
![Page 55: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/55.jpg)
www.hazelcast.com@noctarius2k
Pointer with sun.misc.Unsafe
Unsafe unsafe = getUnsafeWithMagic();long ptr = unsafe.allocateMemory(20);byte val = unsafe.getByte(ptr + 5);
![Page 56: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/56.jpg)
www.hazelcast.com@noctarius2k
Pointer with sun.misc.Unsafe
Unsafe unsafe = getUnsafeWithMagic();long ptr = unsafe.allocateMemory(20);byte val = unsafe.getByte(ptr + 5);
retrieve sun.misc.Unsafe instance
![Page 57: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/57.jpg)
www.hazelcast.com@noctarius2k
Pointer with sun.misc.Unsafe
Unsafe unsafe = getUnsafeWithMagic();long ptr = unsafe.allocateMemory(20);byte val = unsafe.getByte(ptr + 5);
retrieve sun.misc.Unsafe instance
allocate 20 bytes
![Page 58: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/58.jpg)
www.hazelcast.com@noctarius2k
Pointer with sun.misc.Unsafe
Unsafe unsafe = getUnsafeWithMagic();long ptr = unsafe.allocateMemory(20);byte val = unsafe.getByte(ptr + 5);
retrieve sun.misc.Unsafe instance
allocate 20 bytesget byte at ptr+5
![Page 59: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/59.jpg)
www.hazelcast.com@noctarius2k
So I die, for using Unsafe?
![Page 60: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/60.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anywaysLayoutType<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();}
![Page 61: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/61.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anywaysLayoutType<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-arraylayout
![Page 62: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/62.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anywaysLayoutType<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-arraylayout
create ascope
![Page 63: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/63.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anywaysLayoutType<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-arraylayout
create ascope
allocate 20 bytes
![Page 64: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/64.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anywaysLayoutType<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-arraylayout
create ascope
allocate 20 bytesget byte at ptr+5
![Page 65: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/65.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
![Page 66: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/66.jpg)
www.hazelcast.com@noctarius2k
Who needs Unsafe anyways
![Page 67: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/67.jpg)
www.hazelcast.com@noctarius2k
A REAL NULL POINTER! THANK YOU JAVA!
Who needs Unsafe anyways
![Page 68: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/68.jpg)
www.hazelcast.com@noctarius2k
About Structs and other Creatures
![Page 69: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/69.jpg)
www.hazelcast.com@noctarius2k
Struct in Java? No, Layout!
typedef struct { int32_t val; Node next;} Node;
![Page 70: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/70.jpg)
www.hazelcast.com@noctarius2k
Same LinkedList Node in Java
@LayoutDesc({"x:jint:4", "y:Node:8"})public interface Node extends Layout { // …}
![Page 71: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/71.jpg)
www.hazelcast.com@noctarius2k
@LayoutDesc({"x:jint:4", "y:Node:8"})public interface Node extends Layout { interface EffectiveAddress { IntPointer val(); Pointer<Node> next(); } // …}
Same LinkedList Node in Java
![Page 72: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/72.jpg)
www.hazelcast.com@noctarius2k
@LayoutDesc({"x:jint:4", "y:Node:8"})public interface Node extends Layout { Node.EffectiveAddress EA(); long sizeof(); int val(); // …}
Same LinkedList Node in Java
![Page 73: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/73.jpg)
www.hazelcast.com@noctarius2k
@LayoutDesc({"x:jint:4", "y:Node:8"})public interface Node extends Layout { Node next(); void val(int val); void next(Node next); String toString();}
Same LinkedList Node in Java
![Page 74: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/74.jpg)
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
![Page 75: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/75.jpg)
www.hazelcast.com@noctarius2k
I slayed the Mad King
![Page 76: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/76.jpg)
www.hazelcast.com@noctarius2k
Value Isn’t A Pit. Value Is A Ladder.
![Page 77: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/77.jpg)
www.hazelcast.com@noctarius2k
Value Types
value class Point { int x; int y;}
![Page 78: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/78.jpg)
www.hazelcast.com@noctarius2k
Value Types
Point point = __make Point(1, 2);int x = point.x;int y = point.y;
![Page 79: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/79.jpg)
www.hazelcast.com@noctarius2k
Yet another layout?
![Page 80: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/80.jpg)
www.hazelcast.com@noctarius2k
class Point {}Point[] points = …
Arrays of Points
![Page 81: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/81.jpg)
www.hazelcast.com@noctarius2k
value class Point {}Point[] points = …
Arrays of Points
![Page 82: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/82.jpg)
www.hazelcast.com@noctarius2k
I’m feeling so Assembler today
![Page 83: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/83.jpg)
www.hazelcast.com@noctarius2k
Coding a Vector-Function in JavaMethodType type = MethodType.methodType( Float.class, Float.class, Float.class);
MethodHandle m256_vadds = CodeSnippets .make(..., type, …);
m256_vadds.invokeExact(out, in1, in2);
low-level
![Page 84: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/84.jpg)
www.hazelcast.com@noctarius2k
Coding a Vector-Function in Javahigh-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}
![Page 85: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/85.jpg)
www.hazelcast.com@noctarius2k
Coding a Vector-Function in Javahigh-level
void addVector(float[] left, float[] right, float[] res, int length) { // …}
![Page 86: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/86.jpg)
www.hazelcast.com@noctarius2k
Coding a Vector-Function in Javahigh-level
void addVector(float[] left, float[] right, float[] res, int length) { FloatVector<S256Bit> l = float256FromArray(left, length); FloatVector<S256Bit> r = float256FromArray(right, length); // …}
![Page 87: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/87.jpg)
www.hazelcast.com@noctarius2k
Coding a Vector-Function in Javahigh-level
void addVector(float[] left, float[] right, float[] res, int length) { // … FloatVector<S256Bit> lr = l.add(r); lr.intoArray(res, length);}
![Page 88: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/88.jpg)
www.hazelcast.com@noctarius2k
Razersharp tooling
![Page 89: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/89.jpg)
www.hazelcast.com@noctarius2k
So what do we expect?
![Page 90: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/90.jpg)
www.hazelcast.com@noctarius2k
Peace with the Dragons
![Page 91: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/91.jpg)
www.hazelcast.com@noctarius2k
Peace with the DragonsC / C++
![Page 92: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/92.jpg)
www.hazelcast.com@noctarius2k
Painless communication…
![Page 93: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/93.jpg)
www.hazelcast.com@noctarius2k
Painless communication…
…between native and Java code
![Page 94: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/94.jpg)
www.hazelcast.com@noctarius2k
More fun…
![Page 95: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/95.jpg)
www.hazelcast.com@noctarius2k
More fun…
… and faster code …
![Page 96: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/96.jpg)
www.hazelcast.com@noctarius2k
More fun…
…without JNI
… and faster code …
![Page 97: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/97.jpg)
www.hazelcast.com@noctarius2k
Thank You &George R.R. Martin
![Page 98: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/98.jpg)
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!
![Page 99: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/99.jpg)
www.hazelcast.com@noctarius2k
Thank You!Any Questions?
@noctarius2k http://www.sourceprojects.org
http://github.com/noctarius
@hazelcast http://www.hazelcast.com http://www.hazelcast.org
http://github.com/hazelcast
![Page 100: Project Panama - Beyond the (JVM) Wall](https://reader031.fdocuments.in/reader031/viewer/2022012923/58e4aabe1a28abbb038b547f/html5/thumbnails/100.jpg)
www.hazelcast.com@noctarius2k
Germanspeaking?
JVM related talk on Slack
Get your own invite at:https://slackin-jvm-german.herokuapp.com