Repository navigation
Conversation
Motivation: Java 24 has started to print warnings when `sub.misc.Unsafe` is used to access memory. See JEP 498: https://openjdk.org/jeps/498 People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling `Unsafe` by default on Java 24 onwards. Modification: Effectively change the default value of the `io.netty.noUnsafe` system property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default. Any sort of explicit settings, be it `-Dio.netty.noUnsafe=false` or `--sun-misc-unsafe-memory-access=allow`, will continue to work as before. Manually verified that the changes work as intended on Java 24. Result: No more warnings printed to the console on Java 24+. Fixes #14942
|
Hey @normanmaurer, This commit doesn't work as expected in 4.2, because Not a bug, but you may also want to flip |
|
@Spasi want to do a PR to fix it ? |
Motivation: After netty#14975, EXPLICIT_NO_UNSAFE_CAUSE has a dependency to JAVA_VERSION, which is initialized after it. When explicitNoUnsafeCause0() tries to set io.netty.noUnsafe to true by default on Java 24, it fails, because javaVersion() always returns 0 at that point. Also, isAndroid0() is called twice, once in javaVersion0() and once to initialize IS_ANDROID. This is not a bug or a performance issue, but it does have a visible side-effect when debug logging is enabled. Modification: The declaration of EXPLICIT_NO_UNSAFE_CAUSE is moved after JAVA_VERSION, ensuring javaVersion() returns the correct version when explicitNoUnsafeCause0() calls it. IS_ANDROID is also moved before JAVA_VERSION, such that the isAndroid0() method is called only once. Result: Fixes netty#14942 correctly
Motivation: After #14975, `EXPLICIT_NO_UNSAFE_CAUSE` has a dependency to `JAVA_VERSION`, which is initialized after it. When `explicitNoUnsafeCause0()` tries to set `io.netty.noUnsafe` to true by default on Java 24, it fails, because `javaVersion()` always returns 0 at that point. Also, `isAndroid0()` is called twice, once in `javaVersion0()` and once to initialize `IS_ANDROID`. This is not a bug or a performance issue, but it does have a visible side-effect when debug logging is enabled. Modification: The declaration of `EXPLICIT_NO_UNSAFE_CAUSE` is moved after `JAVA_VERSION`, ensuring `javaVersion()` returns the correct version when `explicitNoUnsafeCause0()` calls it. `IS_ANDROID` is also moved before `JAVA_VERSION`, such that the `isAndroid0()` method is called only once. Result: Fixes #14942 correctly
Motivation: After netty#14975, `EXPLICIT_NO_UNSAFE_CAUSE` has a dependency to `JAVA_VERSION`, which is initialized after it. When `explicitNoUnsafeCause0()` tries to set `io.netty.noUnsafe` to true by default on Java 24, it fails, because `javaVersion()` always returns 0 at that point. Also, `isAndroid0()` is called twice, once in `javaVersion0()` and once to initialize `IS_ANDROID`. This is not a bug or a performance issue, but it does have a visible side-effect when debug logging is enabled. Modification: The declaration of `EXPLICIT_NO_UNSAFE_CAUSE` is moved after `JAVA_VERSION`, ensuring `javaVersion()` returns the correct version when `explicitNoUnsafeCause0()` calls it. `IS_ANDROID` is also moved before `JAVA_VERSION`, such that the `isAndroid0()` method is called only once. Result: Fixes netty#14942 correctly
|
Is it possible that there are still warnings with Java 25 and Netty 4.2.7? WARNING: A restricted method in java.lang.System has been called JVM: OpenJDK Runtime Environment Temurin-25.0.1+8 |
|
@WhiteTrashLord This is completely unrelated to Unsafe. This warning is about the use of JNI that Oracle is replacing with the new Foreign Function & Memory API. For now, you should add this JVM option. |
…rect buffers (#298) ## Summary Netty 4.1.120 and 4.1.121 disabled their internal `sun.misc.Unsafe` usage by default ([netty/netty#14975](netty/netty#14975)) to silence JEP 498 warnings on JDK 24+. With Unsafe disabled, `PlatformDependent.useDirectBufferNoCleaner()` returns `false`: every Netty direct buffer (pooled **and** unpooled) falls back to `ByteBuffer.allocateDirect` → `java.nio.Bits.reserveMemory`, which is bounded by `-XX:MaxDirectMemorySize`. The result is `OutOfMemoryError` under heavy ingestion even though `-Dio.netty.maxDirectMemory` was set generously. Netty 4.1.122 ([netty/netty#15296](netty/netty#15296)) reverts the default. Until HerdDB upgrades (commit c0cf458 downgraded us 4.1.130 → 4.1.121 for issue #274), add `--sun-misc-unsafe-memory-access=allow` to: - `herddb-services/src/main/resources/bin/setenv.sh` — applies to every JVM launched via `bin/service` (server, indexing-service, file-server, bookkeeper) and to the CLI tools that inherit `JDK_JAVA_OPTIONS` (`herddb-cli.sh`, `vector-bench.sh`, `indexing-admin.sh`). - `pom.xml` — both Surefire `argLine`s (default and `ci` profile) so unit tests on JDK 25 don't take the slow `Bits.reserveMemory` path either. ## Verification Reproduced locally on Eclipse Temurin **JDK 25.0.2** with the in-tree Netty **4.1.121**. **Before** (no flag): server saturates `-XX:MaxDirectMemorySize=1g`, OOMs at 160k/1M rows even with `-Dio.netty.maxDirectMemory=4g`. `netty_used_direct_memory_bytes` Prometheus gauge stuck at `-1` (counter inactive). **After** (with flag): server peak direct memory ~300 MiB, **0 OutOfMemoryErrors** through the full gist1m bench (1M vectors × 960-dim, 8 ingest threads, 5000 batch, post-ingest checkpoint, recall queries). `netty_used_direct_memory_bytes` reports actual usage (counter active). | Metric | Before | After | |---|---|---| | `netty_used_direct_memory_bytes` | `-1` | active (~134 MiB at end) | | Server direct mem peak | hits 1024/1024 MiB cap | ~300 MiB / 4 GiB | | OOMs in 1M-row ingest | 30–66 | **0** | | Ingest throughput | bench fails | 20,332 rows/s | | Recall@10 | bench fails | 0.91 | ## Also included `herddb-services/examples/local-bench/install.sh` got a small batch of bench-tuning changes that emerged from this investigation: - `-Dherddb.file.requirefsync=false` for both server and indexing-service (benchmark-only — never use this in production). - Explicit `-XX:MaxDirectMemorySize` and `-Dio.netty.maxDirectMemory` for both services (was leaving Netty at `=0`/JVM-bound; now explicit and consistent). - Indexing-service heap reduced from 40g → 30g so the `(server) + (IS)` budget fits in a 61 GiB host with headroom for the OS. - Documentation comments explaining the layout. These are isolated to the `examples/local-bench` directory and don't affect production defaults. ## Test plan - [ ] CI runs all unit tests with the new Surefire `argLine` on JDK 25 - [ ] Smoke-test the `local-bench` example: `./teardown.sh && ./install.sh && ./scripts/run-bench.sh --dataset gist1m -n 1000000 --ingest-threads 8 --batch-size 5000 --checkpoint --wait-for-indexes` ## Long-term follow-up When HerdDB is upgraded back to **Netty 4.1.122+** (or **4.2.x**, which is FFM-based and Unsafe-free), the `--sun-misc-unsafe-memory-access=allow` flag in `setenv.sh` becomes redundant and the comment block can be removed. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Sonnet 4.6 <[email protected]>
Motivation:
Java 24 has started to print warnings when
sub.misc.Unsafeis used to access memory. See JEP 498: https://openjdk.org/jeps/498People tend to be sensitive to new warnings and errors printed by the JVM, so we should avoid enabling
Unsafeby default on Java 24 onwards.Modification:
Effectively change the default value of the
io.netty.noUnsafesystem property for Java 24 onwards, but in a way where we can tell if it was explicitly set to a given value or if it follows the default.Any sort of explicit settings, be it
-Dio.netty.noUnsafe=falseor--sun-misc-unsafe-memory-access=allow, will continue to work as before.Manually verified that the changes work as intended on Java 24.
Result:
No more warnings printed to the console on Java 24+.
Fixes #14942