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 September 2024
JProfiler
|
Get rid of your performance problems and memory leaks!
|
JProfiler
|
Get rid of your performance problems and memory leaks!
|
|
|
Back to newsletter 286 contents
https://www.youtube.com/watch?v=rMBV0iWgIfk
Handling concurrent access to shared resources in Java (Page last updated September 2024, Added 2024-09-29, Author Sebastian Konieczek, Publisher JAVAPRO). Tips:
- Concurrency is hard when you have shared resources. Access and updates of a shared resource by multiple threads is a race condition. Without concurrency coordination, the outcome of access and updates are non-deterministic.
- Java
synchronized
and Locks (eg ReentrantReadWriteLock) provide mutual exclusive access to shared resources which makes using them concurrently deterministic.
volatile
variables provides exclusive access and update to a shared resource, but only for one action, not a group of actions. For compound actions to execute concurrently deterministically, you need to use synchronized
or Locks.
- A deadlock can occur when more than one thread tries to lock more than one
synchronized
monitor but in different orders. One thread acquires the first monitor and tries to acquires the second monitor, while a second thread has acquired that second monitor and is trying to acquire the first monitor - deadlock.
- A virtual thread will pin the underlying platform thread if you use
synchronized
, so be careful to avoid using synchronized
for any non-short actions.
- Optimistic locking is a different concurrency technique where the action is attempted and it succeeds if nothing else changed the shared resource in the meantime, but fails if the shared resource has been changed.
https://www.infoq.com/presentations/jvm-exotic-hardware/
Harnessing Exotic Hardware: Charting the Future of JVM Performance (Page last updated July 2024, Added 2024-09-29, Author Monica Beckwith, Publisher InfoQ). Tips:
- Using JNI has multiple inefficiencies: memory management mismatch, performance overheads, double language complexity, impedance mismatch between Java and 3rd party non-Java libraries.
- The GPU expects data, it's not managed memory, so there is a mismatch between how Java works and the GPU memory is managed. Aparapi is a Java framework for executing native Java code directly on the GPU.
- TornadoVM is an open source plugin that accelerates Java programs on GPUs and FPGAs. This reduces the impedance mismatch for using GPUs from JVMs, compared to directly using JNI and GPU management libraries.
- The foreign function and memory interface (currently in preview, originally called project Panama) attempts to provide a Java-centric way to efficiently interface with hardware like GPUs including memory management.
https://www.youtube.com/watch?v=H4WPgHVp6gQ
JEP 466 Explained: Class-File API (Page last updated August 2024, Added 2024-09-29, Author Mala Gupta, Rafael Winterhalter, Publisher IntelliJ IDEA). Tips:
- Every Java app is already creating dynamic classes (lambda expressions, proxies, generated classes, etc), even if the app doesn't explicitly do this. Application developers typically don't need to explicitly generate or transform classes, unless they are creating frameworks. Frameworks often need to interact with classes that are unknown at framework creation time, and one very efficient way to interact is with runtime class generation and transformation.
- The most common class generation is to generate subclasses of existing classes, to modify or specify some behaviour differently from the superclass. The second most common is with Java agents, these try to minimize the overhead, and this is most efficiently done with specialized class generation and transforming existing classes.
- The JVM can parse a classfile with the new API from Java 22, and Byte Buddy exposes ASM visitors that provides efficient mature classfile parsing APIs for any version of Java since 5.
- The classfile API creates a lot of objects, so can be less than optimal in terms of allocation. But the API does provide forward compatibility compared to current classfile parsers like ASM which cannot be forwardly compatible.
- The most efficient way to generate and transform classes is via ASM (and ASM based libraries like Byte Buddy) and fall back to the classfile API if the ASM approach fails because of forward compatibility issues.
Jack Shirazi
Back to newsletter 286 contents
Last Updated: 2024-12-27
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/newtips286.shtml
RSS Feed: http://www.JavaPerformanceTuning.com/newsletters.rss
Trouble with this page? Please contact us