Java Performance Tuning
Java(TM) - see bottom of page
Our valued sponsors who help make this site possible
JProfiler: Get rid of your performance problems and memory leaks!
Training online: Concurrency, Threading, GC, Advanced Java and more ...
Tips February 2024
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 279 contents
https://www.youtube.com/watch?v=HDLEmXH2AwM
Bare metal Java (Page last updated November 2023, Added 2024-02-26, Author Jaroslaw Palka, Publisher GeeCON). Tips:
- malloc is available in Java via DirectByteBuffer, Unsafe, JNI and the foreign function & memory API (with MemorySegment).
- MemorySegment can create memory that is manually managed or automatically GC managed by scope or even manually managed by try-with-resources scope.
- Arena can restrict memory access to specific arenas, eg a specific thread.
- MemoryLayout let's you specify alignment and padding.
https://www.youtube.com/watch?v=t8c1Q2wJOoM
The Panama Dojo: Black Belt Programming with Java 21 and the FFM API By Per Minborg (Page last updated October 2023, Added 2024-02-26, Author Per Minborg, Publisher Devoxx). Tips:
- MemorySegment provides access in to the java heap (Heap Segment) and outside the heap (Native Segment). Both types are size, lifetime and thread bounded (thread bounding is optional).
- Arena models the lifecycle of MemorySegments. They can be Global (lasts for the JVM lifetime), Automatic (managed by GC), Confined (bounded to a single thread and deallocated when closed or scope exits) or Shared (not bounded by threads but also deallocated when closed or scope exits).
- By using VarHandles to MemorySegments, you can use atomic operations (eg compareAndSet()) and so ensure that memory manipulation for shared memory is thread-safe.
https://www.youtube.com/watch?v=M57l4DMcADg
Project Panama: Interconnecting the Java Virtual Machine and Native Code (Page last updated April 2023, Added 2024-02-26, Author Paul Sandoz, Publisher Oracle). Tips:
- Direct ByteBuffers has expensive allocation and no way to explicitly deallocate - you have to wait for the GC to do it and that can effectively lead to resource leaks because resources stay around too long - the GC is triggered from Java-side memory pressure not native-side memory pressure.
- memory segments allow access to native memory, with the access bounded in space and inaccessible after deallocation; Additionally the memory can be structured with named offsets for the structure elements, eg a struct of two doubles called x and y is
Mem = MemoryLayout.structLayout(ValueLayout.JAVA_DOUBLE.withName("x"),ValueLayout.JAVA_DOUBLE.withName("y"))
. This can then be accessed efficiently using a handle, eg MemX = Mem.varHandle(PathElement.groupLayout("x")
- all static so far, and finally for dynamic manipulation try(Arena offHeap = Arena.ofConfined){obj = offHeap.allocate(Mem); MemX.set(obj, 42D);}
.
- The foreign function and memory API (panama) is faster than JNI and provides deterministic memory deallocation.
Jack Shirazi
Back to newsletter 279 contents
Last Updated: 2024-11-29
Copyright © 2000-2024 Fasterj.com. All Rights Reserved.
All trademarks and registered trademarks appearing on JavaPerformanceTuning.com are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries. JavaPerformanceTuning.com is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
URL: http://www.JavaPerformanceTuning.com/news/newtips279.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us