SlideShare a Scribd company logo
1 of 107
Download to read offline
JAVA 19
PROJECT PANAMA


4


NEWBIES
A friendly intro to JEP 419’s Foreign
Function & Memory API
1
About Me
• A Sr. Developer Advocate at Azul Systems


• Developing software for 20+ years


• Authored & Tech Reviewed Java books


• A JavaFX (fanboy) enthusiast


• Loves sharing and advocating Java based technologies




Other interests:


Graphics, UI, Game programming, GEO spatial data & map
visualizations, Custom UI controls, IoT, Smart phones, AI, and
Robotics and Boating.




 Twitter: @carldea


LinkedIn: https://github.com/carldea


   Email: cdea@azul.com
Carl Dea
2
Panama4Newbies
https://github.com/carldea/java-panama-workshop
https://foojay.io/today/author/carldea
3
OpenGL & SDL RFID Card Reader
JNI
Java interop?
4
JNI Pain Points
Java Native Interface
5
Year 2003
6
7
The JACOB Project: A JAva-COM Bridge
Now you can call COM Automation from any Win32 Java VM using JNI
Copyright 1999-2004 Dan Adler
Latest Version: October 17, 2004 (V1.8)
https://danadler.com/tech-articles/jacob-2/
8
jacob.jar
jacob.dll
Win32 DLL
myApplication.jar
Java 

Application
9
jacob.jar
jacob.dll
Win32 DLL
myApplication.jar
Java Library
10
jacob.jar
jacob.dll
Win32 DLL
myApplication.jar
Native 

Wrapper lib
11
jacob.jar
jacob.dll
Win32 DLL
myApplication.jar
OS Native 

Library
12
jacob.jar
jacob.dll
Win32 DLL
myApplication.jar
OS Native 

Library
13
Wormholes are hypothetical bridges through space-time (Image credit: Getty)
Future
https://github.com/carldea/panama4newbies
14
15
What is


Project Panama?
16
JEP 389: 1st Incubator
JEP 370: 1st Incubator
Foreign-Memory Access API
Vector API
JEP 338: 1st Incubator JEP 383: 2nd Incubator
JEP 393: 3rd Incubator
Foreign Linker API
Foreign Function


&


Memory Access API
JEP 412: 1st Incubator
Project Panama
JEP 419: 2nd Incubator
JEP 424: Preview
JEP 414: 2nd Incubator
17
18
JEP 419: 2nd Incubator
jdk.incubator.foreign
JEP 424 Preview
java.lang.foreign
+

Bug-fixes
19
Why


Project Panama?
20
Bene
fi
ts
Ease of use — Alternative to Java Native Interface (JNI) with a superior,
pure-Java
Performance — Provide performance that is comparable to, if not better than,
existing APIs such as JNI and sun.misc.Unsafe.
General Purpose — Provide ways to operate on different kinds of foreign memory
(e.g., native memory, persistent memory, and managed heap memory) and, over time, to
accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages
other than C (e.g., C++, Fortran).
Safety — Disable unsafe operations by default, allowing them only after
explicit opt-in from application developers or end users.
21
Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java
development model.
Performance — Provide performance that is comparable to, if not better than,
existing APIs such as JNI and sun.misc.Unsafe.
General Purpose — Provide ways to operate on different kinds of foreign memory
(e.g., native memory, persistent memory, and managed heap memory) and, over time, to
accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages
other than C (e.g., C++, Fortran).
Safety — Disable unsafe operations by default, allowing them only after
explicit opt-in from application developers or end users.
Bene
fi
ts
22
Performance — Provide performance that is comparable to, if not better than,
existing APIs such as JNI and sun.misc.Unsafe.
General Purpose — Provide ways to operate on different kinds of foreign memory
(e.g., native memory, persistent memory, and managed heap memory) and, over time, to
accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages
other than C (e.g., C++, Fortran).
Safety — Disable unsafe operations by default, allowing them only after
explicit opt-in from application developers or end users.
Bene
fi
ts
Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java
development model.
23
Performance — Provide performance that is comparable to, if not better than,
existing APIs such as JNI and sun.misc.Unsafe.
General Purpose — Provide ways to operate on different kinds of foreign memory
(e.g., native memory, persistent memory, and managed heap memory) and, over time, to
accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages
other than C (e.g., C++, Fortran).
Safety — Disable unsafe operations by default, allowing them only after
explicit opt-in from application developers or end users.
Bene
fi
ts
Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java
development model.
24
ABI
Application


Binary


InterFace
25
Demos
26
OpenGL & SDL
Displaying 3D surfaces
27
Where to get Panama?
--add-modules jdk.incubator.foreign
28
Early Access Builds
https://jdk.java.net/panama
Feedback
panama-dev@openjdk.java.net 
Contribute or Build OpenJDK
yourself
https://github.com/openjdk/panama-foreign
29
Getting Started
30
JAVA_HOME
c:> set JAVA_HOME=<unzipped_dir>jdk-19.jdkContentsHome


c:> set PATH=%JAVA_HOME%bin;%PATH%


MacOS/Linux


$ export JAVA_HOME=<untarred_dir>/jdk-19.jdk/Contents/Home


$ export PATH=$JAVA_HOME/bin:$PATH


PATH
Setting Environment Variables
Windows


31
java -version
Quick Check
openjdk version “19-internal" 2022-09-20


OpenJDK Runtime Environment (build 19-internal+0-
adhoc.jdoe.panama-foreign)


OpenJDK 64-Bit Server VM (build 19-internal+0-
adhoc.jdoe.panama-foreign, mixed mode, sharing)
JDK 19 Panama


32
MethodHandle(s)
Understanding Low level Panama code such as MethodHandles
since JDK 7
33
What’s a MethodHandle?
A method handle is a Java object that references a
native C function or C variable in memory and
the ability to accessed or invoked from Java code.




In the C/C++ world symbols are a unique lookup of C
functions and variables from the C linker
(java.library.path).
In layman’s (newbie) terms:
34
What’s a MethodHandle?
A method handle is a typed, directly executable
reference to an underlying method, constructor,
fi
eld, or
similar low-level operation, with optional
transformations of arguments or return values.These
transformations are quite general, and include such
patterns as conversion, insertion, deletion, and
substitution.
According to the Javadoc Documentation since JDK 7
35
Unix/Linux functions
Getting the process ID using the getpid() function
Really a C int
36
Creating a MethodHandle - JDK 18+
MethodHandle class
FunctionDescriptor


describes return type from C
NativeSymbol


C symbols from library path
Note: For better performance make method handles public
fi
nal static
37
Is there a better way?
FILE *freopen(const char *filename, const char *mode, FILE *stream)
38
jextract
Output: Calling getpid() (1234)
https://github.com/openjdk/jextract
39
in C
40
C Standard Input/Output


Header
41
int printf(const char *format, ...)


42
Zero means OK.


Anything else is an
error or status code
43
in Java
Panama
Using


Jextract
44
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


45
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


C headers path


ie: /usr/local/include
46
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


Generated Code


ie: ./classes


      ./generated/src
47
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


Library


ie: tensorflow
48
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


Generated Java Source


ie: org/unix/foo_h.java
49
jextract -h
Quick Check
Option                         Description                              


------                         -----------                              


-?, -h, --help                 print help                               


-C <String>                    pass through argument for clang          


-I <String>                    specify include files path               


-d <String>                    specify where to place generated files   


--dump-includes <String>       dump included symbols into specified file


--header-class-name <String>   name of the header class                 


--include-function <String>    name of function to include              


--include-macro <String>       name of constant macro to include        


--include-struct <String>      name of struct definition to include     


--include-typedef <String>     name of type definition to include       


--include-union <String>       name of union definition to include      


--include-var <String>         name of global variable to include       


-l <String>                    specify a library                        


--source                       generate java sources                    


-t, --target-package <String>  target package for specified header files


Panama’s JExtract


Package namespace prefix


ie: org.unix
50
$ export C_INCLUDE_PATH=/usr/local/include


# or depending where the defaults are installed


$ export C_INCLUDE_PATH=/usr/include
MacOS


$ export C_INCLUDE_PATH=Applications/Xcode.app/Contents/
Developer/Platforms/MacOSX.platform/Developer/SDKs/
MacOSX.sdk/usr/include
Let’s jextract stdio.h
Windows


Linux
Create a convenient
environment variable
C_INCLUDE
51
C:MinGWinclude (If MinGW is used)


C:mysys2include (If mysys2 is used)
$ jextract -d classes 


-t org.unix 


-I $C_INCLUDE_PATH 


$C_INCLUDE_PATH/stdio.h


Generate Java Classes
52
$ jextract -d classes 


-t org.unix 


-I $C_INCLUDE_PATH 


$C_INCLUDE_PATH/stdio.h


Generate Java Classes
Destination Directory ./classes
53
$ jextract -d classes 


-t org.unix 


-I $C_INCLUDE_PATH 


$C_INCLUDE_PATH/stdio.h


Generate Java Classes
Package Namespace: org.unix
54
$ jextract -d classes 


-t org.unix 


-I $C_INCLUDE_PATH 


$C_INCLUDE_PATH/stdio.h


Generate Java Classes Header include directory
55
$ jextract -d classes 


-t org.unix 


-I $C_INCLUDE_PATH 


$C_INCLUDE_PATH/stdio.h


Generate Java Classes
Target Header
fi
le
56
Generate Java Classes
Generated Java Classes
57
$ jextract --source 


-d generated/src 


-t org.unix 


-I $C_INCLUDE_PATH 


  $C_INCLUDE_PATH/stdio.h


Generate Java Sources
58
$ jextract --source 


-d generated/src 


-t org.unix 


-I $C_INCLUDE_PATH 


  $C_INCLUDE_PATH/stdio.h


Generate Java Sources
Generate Java Source Code
Generate Source Directory
59
Generate Java Sources
Generated Java Sources
60
Lab 01
61
https://github.com/carldea/java-panama-workshop/tree/main/lab1
--add-modules jdk.incubator.foreign


IntelliJ - Preferences
IDE Setup
62
imports
HelloWorld.java
63
HelloWorld.java
JDK 18+ ResourceScope
Implements Closable.
Cleans up after try block.
64
allocateUtf8String()
HelloWorld.java


JDK 19+
C Functions
65
MemorySegment


to


Java String
C String converts to Java String object
66
Let’s Run HelloWorld.java
Enabling Native Access
67
Let’s Run HelloWorld.java
Adding foreign function & memory module
68
Let’s Run HelloWorld.java
Java Application
69
Output of HelloWorld.java
70
Memory Allocation
RAM
71
ValueLayout
To create a C primitive use CLinker’s C ValueLayouts such as


C_INT


C_DOUBLE


C_POINTER, etc.
MemorySegment
72
ValueLayout
To create a C primitive use CLinker’s C ValueLayouts such as


C_INT


C_DOUBLE


C_POINTER, etc. Native Allocator
73
ValueLayout
To create a C primitive use CLinker’s C ValueLayouts such as


C_INT


C_DOUBLE


C_POINTER, etc.
74
ValueLayout
To create a C primitive use CLinker’s C ValueLayouts such as


C_INT


C_DOUBLE


C_POINTER, etc.
JDK 18+ uses the


MemorySegment class’


get()/set() methods
75
C Primitive Arrays
SegmentAllocator.allocateArray()
76
Primitive Array - JDK 18+
To create a C primitive Arrays use:
SegmentAllocator.implicitAllocator().allocateArray()
00 00 00 00 00 00 00 01
0
00 00 00 00 00 00 00 02
1
77
Primitive Array
Output:
78
Lab 02
79
https://github.com/carldea/java-panama-workshop/tree/main/lab2
Summary
•The 3Ws of Project Panama
•MethodHandle class
•jextract
•MethodSegment class
•ValueLayout class
•allocateArray() method
80
But there’s more…
81
But there’s more…
C Structs
C Pointers
C Callbacks
Other Languages


(Polyglot)
82
https://github.com/carldea/panama4newbies
83
Q/A
Thank you for coming!
Twitter: @carldea


    Blog: carlfx.com  & foojay.io


  Github: https://github.com/carldea


   Email: cdea@azul.com


LinkedIn: https://www.linkedin.com/in/carldea
84
References
Links, Mailing Lists, videos, blogs
• Panama 4 Newbies – https://foojay.io/today/project-panama-for-newbies-part-1


• Panama EA builds - https://jdk.java.net/panama


• Feedback - panama-dev@openjdk.java.net


• Mailing List     - https://mail.openjdk.java.net/mailman/listinfo/panama-dev


• JEP 412 1st incubator - https://openjdk.java.net/jeps/412


• JEP 419 2nd incubator - https://openjdk.java.net/jeps/419


• JEP 424 Preview - https://openjdk.java.net/jeps/424


• Foojay.io – https://foojay.io


• Panama Samples - https://github.com/sundararajana/panama-jextract-samples


• Panama at GitHub – https://github.com/openjdk/panama-foreign


• Panama Update by Maurizio Cimadamore - https://www.youtube.com/watch?v=r4dNRVWYaZI


• Upcalls by M.C.  - https://cr.openjdk.java.net/~mcimadamore/panama/f
fi
.html


• Going Meta to Valhalla & Panama w/ John Rose - https://www.youtube.com/watch?v=49GUljUmGHg


• Rust & Panama - https://jornvernee.github.io/rust/panama-f
fi
/2021/09/03/rust-panama-helloworld.html


• Method Handles - https://download.java.net/java/early_access/panama/docs/api/java.base/java/lang/
invoke/MethodHandle.html


• Jextract on GitHub - https://github.com/openjdk/jextract
85
Supplemental
Slides & Demos


86
What’s a C Pointer?
C supports the use of pointers, a type of reference that records the
address or location of an object or function in memory. Pointers can
be dereferenced to access data stored at the address pointed to, or
to invoke a pointed-to function. Pointers can be manipulated using
assignment or pointer arithmetic.
The C Programming Language book


by


Brian W. Kernighan & Dennis M. Ritchie
87
What’s a C Pointer?
ptr = &x x = 5
0x0DDBA11 0xCAFEBABE 0xCAFEBABE 5
Address or Location
88
What’s a C Pointer?
ptr = &x x = 5
0x0DDBA11 0xCAFEBABE 0xCAFEBABE 5
Storage
89
Obtaining a C Pointer in Panama
The reference or address of a C int variable:
90
How to Dereference A Pointer?
Obtain value at the address referenced by the pointer.
91
Dereferencing a C Pointer in Panama - JDK 18+
MemoryAddress class
92
What’s a C Struct?
To put it simply, this is the ancestor to C++ & Java's
concept of classes or records. 
Declaring pt of type Point struct
93
How to Create a Struct in
Panama?
Use GroupLayout and MemoryLayout to describe a C struct.
94
Creating C Structs in Panama
Using MemoryLayout’s structLayout() method.
95
Accessing C Structs in Panama - JDK 18+
To access a MemoryLayout (C Struct) use VarHandles.
96
Lab 03
97
https://github.com/carldea/java-panama-workshop/tree/main/lab3
Present Day
JNI
JNI Requires Native Wrapper Code
98
Rock, Paper Scissors
Playing against the computer you lose every time
99
Call Backs
100
Lab 04
101
https://github.com/carldea/java-panama-workshop/tree/main/lab4
102
Lab 05
103
https://github.com/carldea/java-panama-workshop/tree/main/lab5
Native Access to


Mic & Sound Audio
Realtime audio input and output
104
Apple’s Touch ID
Access Denied with your
fi
ngerprint :-)
105
Apple’s Touch ID
Access Denied with your
fi
ngerprint :-)
106
Panama4Newbies
https://github.com/carldea/panama4newbies
https://foojay.io/today/author/carldea/
107
https://github.com/carldea/java-panama-workshop

More Related Content

What's hot

RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetchRedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
Redis Labs
 
Apache Hadoop YARN: best practices
Apache Hadoop YARN: best practicesApache Hadoop YARN: best practices
Apache Hadoop YARN: best practices
DataWorks Summit
 

What's hot (20)

InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOx
InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOxInfluxDB IOx Tech Talks: Query Processing in InfluxDB IOx
InfluxDB IOx Tech Talks: Query Processing in InfluxDB IOx
 
DASK and Apache Spark
DASK and Apache SparkDASK and Apache Spark
DASK and Apache Spark
 
Distributed load testing with k6
Distributed load testing with k6Distributed load testing with k6
Distributed load testing with k6
 
Using Dagger in a Clean Architecture project
Using Dagger in a Clean Architecture projectUsing Dagger in a Clean Architecture project
Using Dagger in a Clean Architecture project
 
Cloud-Native Apache Spark Scheduling with YuniKorn Scheduler
Cloud-Native Apache Spark Scheduling with YuniKorn SchedulerCloud-Native Apache Spark Scheduling with YuniKorn Scheduler
Cloud-Native Apache Spark Scheduling with YuniKorn Scheduler
 
Graph Computing with JanusGraph
Graph Computing with JanusGraphGraph Computing with JanusGraph
Graph Computing with JanusGraph
 
JupyterHub: Learning at Scale
JupyterHub: Learning at ScaleJupyterHub: Learning at Scale
JupyterHub: Learning at Scale
 
Locality Sensitive Hashing By Spark
Locality Sensitive Hashing By SparkLocality Sensitive Hashing By Spark
Locality Sensitive Hashing By Spark
 
Time-Series Apache HBase
Time-Series Apache HBaseTime-Series Apache HBase
Time-Series Apache HBase
 
Query relaxation - A rewriting technique between search and recommendations
Query relaxation - A rewriting technique between search and recommendationsQuery relaxation - A rewriting technique between search and recommendations
Query relaxation - A rewriting technique between search and recommendations
 
Web 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style SheetsWeb 2 | CSS - Cascading Style Sheets
Web 2 | CSS - Cascading Style Sheets
 
CSS
CSSCSS
CSS
 
Getting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQLGetting started with Apollo Client and GraphQL
Getting started with Apollo Client and GraphQL
 
Streaming architecture patterns
Streaming architecture patternsStreaming architecture patterns
Streaming architecture patterns
 
C# quick ref (bruce 2016)
C# quick ref (bruce 2016)C# quick ref (bruce 2016)
C# quick ref (bruce 2016)
 
How the Postgres Query Optimizer Works
How the Postgres Query Optimizer WorksHow the Postgres Query Optimizer Works
How the Postgres Query Optimizer Works
 
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetchRedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
RedisConf17 - Internet Archive - Preventing Cache Stampede with Redis and XFetch
 
Towards Functional Programming through Hexagonal Architecture
Towards Functional Programming through Hexagonal ArchitectureTowards Functional Programming through Hexagonal Architecture
Towards Functional Programming through Hexagonal Architecture
 
Apache Hadoop YARN: best practices
Apache Hadoop YARN: best practicesApache Hadoop YARN: best practices
Apache Hadoop YARN: best practices
 
FLiP Into Trino
FLiP Into TrinoFLiP Into Trino
FLiP Into Trino
 

Similar to Panama4Newbies_Jfokus2_slides.pdf

Topic2JavaBasics.ppt
Topic2JavaBasics.pptTopic2JavaBasics.ppt
Topic2JavaBasics.ppt
MENACE4
 

Similar to Panama4Newbies_Jfokus2_slides.pdf (20)

Panama4Newbies_Atlanta.pdf
Panama4Newbies_Atlanta.pdfPanama4Newbies_Atlanta.pdf
Panama4Newbies_Atlanta.pdf
 
Panama4Newbies_Atlanta.pdf
Panama4Newbies_Atlanta.pdfPanama4Newbies_Atlanta.pdf
Panama4Newbies_Atlanta.pdf
 
Presentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStackPresentation of Python, Django, DockerStack
Presentation of Python, Django, DockerStack
 
Eric Lafortune - Fighting application size with ProGuard and beyond
Eric Lafortune - Fighting application size with ProGuard and beyondEric Lafortune - Fighting application size with ProGuard and beyond
Eric Lafortune - Fighting application size with ProGuard and beyond
 
Eric Lafortune - Fighting application size with ProGuard and beyond
Eric Lafortune - Fighting application size with ProGuard and beyondEric Lafortune - Fighting application size with ProGuard and beyond
Eric Lafortune - Fighting application size with ProGuard and beyond
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Java Notes
Java Notes Java Notes
Java Notes
 
JAVA BASICS
JAVA BASICSJAVA BASICS
JAVA BASICS
 
Topic2JavaBasics.ppt
Topic2JavaBasics.pptTopic2JavaBasics.ppt
Topic2JavaBasics.ppt
 
hallleuah_java.ppt
hallleuah_java.ppthallleuah_java.ppt
hallleuah_java.ppt
 
2.ppt
2.ppt2.ppt
2.ppt
 
CMake Tutorial
CMake TutorialCMake Tutorial
CMake Tutorial
 
Custom deployments with sbt-native-packager
Custom deployments with sbt-native-packagerCustom deployments with sbt-native-packager
Custom deployments with sbt-native-packager
 
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
PyParis 2017 / Camisole : A secure online sandbox to grade student - Antoine ...
 
Querying 1.8 billion reddit comments with python
Querying 1.8 billion reddit comments with pythonQuerying 1.8 billion reddit comments with python
Querying 1.8 billion reddit comments with python
 
DBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse EngineeringDBI-Assisted Android Application Reverse Engineering
DBI-Assisted Android Application Reverse Engineering
 
Embedded Android
Embedded AndroidEmbedded Android
Embedded Android
 
containerD
containerDcontainerD
containerD
 
Docker.io
Docker.ioDocker.io
Docker.io
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
 

Recently uploaded

Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Marc Lester
 

Recently uploaded (20)

GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with GraphGraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
GraphSummit Milan & Stockholm - Neo4j: The Art of the Possible with Graph
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-CloudAlluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
Alluxio Monthly Webinar | Simplify Data Access for AI in Multi-Cloud
 
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
Entropy, Software Quality, and Innovation (presented at Princeton Plasma Phys...
 
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
Wired_2.0_CREATE YOUR ULTIMATE LEARNING ENVIRONMENT_JCON_16052024
 
Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024Food Delivery Business App Development Guide 2024
Food Delivery Business App Development Guide 2024
 
Weeding your micro service landscape.pdf
Weeding your micro service landscape.pdfWeeding your micro service landscape.pdf
Weeding your micro service landscape.pdf
 
BusinessGPT - Security and Governance for Generative AI
BusinessGPT  - Security and Governance for Generative AIBusinessGPT  - Security and Governance for Generative AI
BusinessGPT - Security and Governance for Generative AI
 
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
Auto Affiliate  AI Earns First Commission in 3 Hours..pdfAuto Affiliate  AI Earns First Commission in 3 Hours..pdf
Auto Affiliate AI Earns First Commission in 3 Hours..pdf
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
Lessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdfLessons Learned from Building a Serverless Notifications System.pdf
Lessons Learned from Building a Serverless Notifications System.pdf
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Jax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined DeckJax, FL Admin Community Group 05.14.2024 Combined Deck
Jax, FL Admin Community Group 05.14.2024 Combined Deck
 
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
Optimizing Operations by Aligning Resources with Strategic Objectives Using O...
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
Abortion Pill Prices Mthatha (@](+27832195400*)[ 🏥 Women's Abortion Clinic In...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 

Panama4Newbies_Jfokus2_slides.pdf

  • 1. JAVA 19 PROJECT PANAMA 
 4 
 NEWBIES A friendly intro to JEP 419’s Foreign Function & Memory API 1
  • 2. About Me • A Sr. Developer Advocate at Azul Systems • Developing software for 20+ years • Authored & Tech Reviewed Java books • A JavaFX (fanboy) enthusiast • Loves sharing and advocating Java based technologies 
 
 Other interests: 
 Graphics, UI, Game programming, GEO spatial data & map visualizations, Custom UI controls, IoT, Smart phones, AI, and Robotics and Boating. 
  Twitter: @carldea 
 LinkedIn: https://github.com/carldea 
    Email: cdea@azul.com Carl Dea 2
  • 4. OpenGL & SDL RFID Card Reader JNI Java interop? 4
  • 5. JNI Pain Points Java Native Interface 5
  • 7. 7
  • 8. The JACOB Project: A JAva-COM Bridge Now you can call COM Automation from any Win32 Java VM using JNI Copyright 1999-2004 Dan Adler Latest Version: October 17, 2004 (V1.8) https://danadler.com/tech-articles/jacob-2/ 8
  • 14. Wormholes are hypothetical bridges through space-time (Image credit: Getty) Future https://github.com/carldea/panama4newbies 14
  • 15. 15
  • 17. JEP 389: 1st Incubator JEP 370: 1st Incubator Foreign-Memory Access API Vector API JEP 338: 1st Incubator JEP 383: 2nd Incubator JEP 393: 3rd Incubator Foreign Linker API Foreign Function 
 & 
 Memory Access API JEP 412: 1st Incubator Project Panama JEP 419: 2nd Incubator JEP 424: Preview JEP 414: 2nd Incubator 17
  • 18. 18
  • 19. JEP 419: 2nd Incubator jdk.incubator.foreign JEP 424 Preview java.lang.foreign +
 Bug-fixes 19
  • 21. Bene fi ts Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java Performance — Provide performance that is comparable to, if not better than, existing APIs such as JNI and sun.misc.Unsafe. General Purpose — Provide ways to operate on different kinds of foreign memory (e.g., native memory, persistent memory, and managed heap memory) and, over time, to accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages other than C (e.g., C++, Fortran). Safety — Disable unsafe operations by default, allowing them only after explicit opt-in from application developers or end users. 21
  • 22. Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java development model. Performance — Provide performance that is comparable to, if not better than, existing APIs such as JNI and sun.misc.Unsafe. General Purpose — Provide ways to operate on different kinds of foreign memory (e.g., native memory, persistent memory, and managed heap memory) and, over time, to accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages other than C (e.g., C++, Fortran). Safety — Disable unsafe operations by default, allowing them only after explicit opt-in from application developers or end users. Bene fi ts 22
  • 23. Performance — Provide performance that is comparable to, if not better than, existing APIs such as JNI and sun.misc.Unsafe. General Purpose — Provide ways to operate on different kinds of foreign memory (e.g., native memory, persistent memory, and managed heap memory) and, over time, to accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages other than C (e.g., C++, Fortran). Safety — Disable unsafe operations by default, allowing them only after explicit opt-in from application developers or end users. Bene fi ts Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java development model. 23
  • 24. Performance — Provide performance that is comparable to, if not better than, existing APIs such as JNI and sun.misc.Unsafe. General Purpose — Provide ways to operate on different kinds of foreign memory (e.g., native memory, persistent memory, and managed heap memory) and, over time, to accommodate other platforms (e.g., 32-bit x86) and foreign functions written in languages other than C (e.g., C++, Fortran). Safety — Disable unsafe operations by default, allowing them only after explicit opt-in from application developers or end users. Bene fi ts Ease of use — Alternative to Java Native Interface (JNI) with a superior, pure-Java development model. 24
  • 27. OpenGL & SDL Displaying 3D surfaces 27
  • 28. Where to get Panama? --add-modules jdk.incubator.foreign 28
  • 29. Early Access Builds https://jdk.java.net/panama Feedback panama-dev@openjdk.java.net  Contribute or Build OpenJDK yourself https://github.com/openjdk/panama-foreign 29
  • 31. JAVA_HOME c:> set JAVA_HOME=<unzipped_dir>jdk-19.jdkContentsHome c:> set PATH=%JAVA_HOME%bin;%PATH% MacOS/Linux $ export JAVA_HOME=<untarred_dir>/jdk-19.jdk/Contents/Home $ export PATH=$JAVA_HOME/bin:$PATH PATH Setting Environment Variables Windows 31
  • 32. java -version Quick Check openjdk version “19-internal" 2022-09-20 OpenJDK Runtime Environment (build 19-internal+0- adhoc.jdoe.panama-foreign) OpenJDK 64-Bit Server VM (build 19-internal+0- adhoc.jdoe.panama-foreign, mixed mode, sharing) JDK 19 Panama 32
  • 33. MethodHandle(s) Understanding Low level Panama code such as MethodHandles since JDK 7 33
  • 34. What’s a MethodHandle? A method handle is a Java object that references a native C function or C variable in memory and the ability to accessed or invoked from Java code. 
 
 In the C/C++ world symbols are a unique lookup of C functions and variables from the C linker (java.library.path). In layman’s (newbie) terms: 34
  • 35. What’s a MethodHandle? A method handle is a typed, directly executable reference to an underlying method, constructor, fi eld, or similar low-level operation, with optional transformations of arguments or return values.These transformations are quite general, and include such patterns as conversion, insertion, deletion, and substitution. According to the Javadoc Documentation since JDK 7 35
  • 36. Unix/Linux functions Getting the process ID using the getpid() function Really a C int 36
  • 37. Creating a MethodHandle - JDK 18+ MethodHandle class FunctionDescriptor 
 describes return type from C NativeSymbol 
 C symbols from library path Note: For better performance make method handles public fi nal static 37
  • 38. Is there a better way? FILE *freopen(const char *filename, const char *mode, FILE *stream) 38
  • 39. jextract Output: Calling getpid() (1234) https://github.com/openjdk/jextract 39
  • 42. int printf(const char *format, ...) 42
  • 43. Zero means OK. 
 Anything else is an error or status code 43
  • 45. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract 45
  • 46. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract C headers path 
 ie: /usr/local/include 46
  • 47. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract Generated Code 
 ie: ./classes 
       ./generated/src 47
  • 48. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract Library 
 ie: tensorflow 48
  • 49. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract Generated Java Source 
 ie: org/unix/foo_h.java 49
  • 50. jextract -h Quick Check Option                         Description                               ------                         -----------                               -?, -h, --help                 print help                                -C <String>                    pass through argument for clang           -I <String>                    specify include files path                -d <String>                    specify where to place generated files    --dump-includes <String>       dump included symbols into specified file --header-class-name <String>   name of the header class                  --include-function <String>    name of function to include               --include-macro <String>       name of constant macro to include         --include-struct <String>      name of struct definition to include      --include-typedef <String>     name of type definition to include        --include-union <String>       name of union definition to include       --include-var <String>         name of global variable to include        -l <String>                    specify a library                         --source                       generate java sources                     -t, --target-package <String>  target package for specified header files Panama’s JExtract Package namespace prefix 
 ie: org.unix 50
  • 51. $ export C_INCLUDE_PATH=/usr/local/include 
 # or depending where the defaults are installed $ export C_INCLUDE_PATH=/usr/include MacOS $ export C_INCLUDE_PATH=Applications/Xcode.app/Contents/ Developer/Platforms/MacOSX.platform/Developer/SDKs/ MacOSX.sdk/usr/include Let’s jextract stdio.h Windows Linux Create a convenient environment variable C_INCLUDE 51 C:MinGWinclude (If MinGW is used) C:mysys2include (If mysys2 is used)
  • 52. $ jextract -d classes 
 -t org.unix 
 -I $C_INCLUDE_PATH 
 $C_INCLUDE_PATH/stdio.h Generate Java Classes 52
  • 53. $ jextract -d classes 
 -t org.unix 
 -I $C_INCLUDE_PATH 
 $C_INCLUDE_PATH/stdio.h Generate Java Classes Destination Directory ./classes 53
  • 54. $ jextract -d classes 
 -t org.unix 
 -I $C_INCLUDE_PATH 
 $C_INCLUDE_PATH/stdio.h Generate Java Classes Package Namespace: org.unix 54
  • 55. $ jextract -d classes 
 -t org.unix 
 -I $C_INCLUDE_PATH 
 $C_INCLUDE_PATH/stdio.h Generate Java Classes Header include directory 55
  • 56. $ jextract -d classes 
 -t org.unix 
 -I $C_INCLUDE_PATH 
 $C_INCLUDE_PATH/stdio.h Generate Java Classes Target Header fi le 56
  • 58. $ jextract --source 
 -d generated/src 
 -t org.unix 
 -I $C_INCLUDE_PATH   $C_INCLUDE_PATH/stdio.h Generate Java Sources 58
  • 59. $ jextract --source 
 -d generated/src 
 -t org.unix 
 -I $C_INCLUDE_PATH   $C_INCLUDE_PATH/stdio.h Generate Java Sources Generate Java Source Code Generate Source Directory 59
  • 64. HelloWorld.java JDK 18+ ResourceScope Implements Closable. Cleans up after try block. 64
  • 66. MemorySegment 
 to 
 Java String C String converts to Java String object 66
  • 68. Let’s Run HelloWorld.java Adding foreign function & memory module 68
  • 72. ValueLayout To create a C primitive use CLinker’s C ValueLayouts such as 
 C_INT 
 C_DOUBLE 
 C_POINTER, etc. MemorySegment 72
  • 73. ValueLayout To create a C primitive use CLinker’s C ValueLayouts such as 
 C_INT 
 C_DOUBLE 
 C_POINTER, etc. Native Allocator 73
  • 74. ValueLayout To create a C primitive use CLinker’s C ValueLayouts such as 
 C_INT 
 C_DOUBLE 
 C_POINTER, etc. 74
  • 75. ValueLayout To create a C primitive use CLinker’s C ValueLayouts such as 
 C_INT 
 C_DOUBLE 
 C_POINTER, etc. JDK 18+ uses the 
 MemorySegment class’ 
 get()/set() methods 75
  • 77. Primitive Array - JDK 18+ To create a C primitive Arrays use: SegmentAllocator.implicitAllocator().allocateArray() 00 00 00 00 00 00 00 01 0 00 00 00 00 00 00 00 02 1 77
  • 80. Summary •The 3Ws of Project Panama •MethodHandle class •jextract •MethodSegment class •ValueLayout class •allocateArray() method 80
  • 82. But there’s more… C Structs C Pointers C Callbacks Other Languages 
 (Polyglot) 82
  • 84. Q/A Thank you for coming! Twitter: @carldea 
     Blog: carlfx.com  & foojay.io 
   Github: https://github.com/carldea    Email: cdea@azul.com 
 LinkedIn: https://www.linkedin.com/in/carldea 84
  • 85. References Links, Mailing Lists, videos, blogs • Panama 4 Newbies – https://foojay.io/today/project-panama-for-newbies-part-1 • Panama EA builds - https://jdk.java.net/panama • Feedback - panama-dev@openjdk.java.net • Mailing List     - https://mail.openjdk.java.net/mailman/listinfo/panama-dev • JEP 412 1st incubator - https://openjdk.java.net/jeps/412 • JEP 419 2nd incubator - https://openjdk.java.net/jeps/419 • JEP 424 Preview - https://openjdk.java.net/jeps/424 • Foojay.io – https://foojay.io • Panama Samples - https://github.com/sundararajana/panama-jextract-samples • Panama at GitHub – https://github.com/openjdk/panama-foreign • Panama Update by Maurizio Cimadamore - https://www.youtube.com/watch?v=r4dNRVWYaZI • Upcalls by M.C.  - https://cr.openjdk.java.net/~mcimadamore/panama/f fi .html • Going Meta to Valhalla & Panama w/ John Rose - https://www.youtube.com/watch?v=49GUljUmGHg • Rust & Panama - https://jornvernee.github.io/rust/panama-f fi /2021/09/03/rust-panama-helloworld.html • Method Handles - https://download.java.net/java/early_access/panama/docs/api/java.base/java/lang/ invoke/MethodHandle.html • Jextract on GitHub - https://github.com/openjdk/jextract 85
  • 87. What’s a C Pointer? C supports the use of pointers, a type of reference that records the address or location of an object or function in memory. Pointers can be dereferenced to access data stored at the address pointed to, or to invoke a pointed-to function. Pointers can be manipulated using assignment or pointer arithmetic. The C Programming Language book 
 by 
 Brian W. Kernighan & Dennis M. Ritchie 87
  • 88. What’s a C Pointer? ptr = &x x = 5 0x0DDBA11 0xCAFEBABE 0xCAFEBABE 5 Address or Location 88
  • 89. What’s a C Pointer? ptr = &x x = 5 0x0DDBA11 0xCAFEBABE 0xCAFEBABE 5 Storage 89
  • 90. Obtaining a C Pointer in Panama The reference or address of a C int variable: 90
  • 91. How to Dereference A Pointer? Obtain value at the address referenced by the pointer. 91
  • 92. Dereferencing a C Pointer in Panama - JDK 18+ MemoryAddress class 92
  • 93. What’s a C Struct? To put it simply, this is the ancestor to C++ & Java's concept of classes or records.  Declaring pt of type Point struct 93
  • 94. How to Create a Struct in Panama? Use GroupLayout and MemoryLayout to describe a C struct. 94
  • 95. Creating C Structs in Panama Using MemoryLayout’s structLayout() method. 95
  • 96. Accessing C Structs in Panama - JDK 18+ To access a MemoryLayout (C Struct) use VarHandles. 96
  • 98. Present Day JNI JNI Requires Native Wrapper Code 98
  • 99. Rock, Paper Scissors Playing against the computer you lose every time 99
  • 102. 102
  • 104. Native Access to 
 Mic & Sound Audio Realtime audio input and output 104
  • 105. Apple’s Touch ID Access Denied with your fi ngerprint :-) 105
  • 106. Apple’s Touch ID Access Denied with your fi ngerprint :-) 106