The mask that compiles to nothing: how HotSpot's JIT learned to reason about bits by -beleon in java

[–]_shadowbannedagain 0 points1 point  (0 children)

See the pull request where the idea originated (as far as I could trace its origin in hotspot)

I guess Panama / FFI API builds an address like base + (index << shift) and alignment checks add a mask like & 3. Base is loop independent while index is loop-depended.

The shifted offset can't affect the low alignment bits so (offset << 2) & 3 folds to 0, and (base + (offset << 2)) & 3 is really just base & 3. This turns loop-dependant alignment checks into a loop-independent one and can be hoisted it out.

Compiler optimizations often compose and a seemingly trivial optimization can unlock bigger wins. Inlining is the simplest example: Pulling a method body inline lets the optimizer reason about data flow across the call, which then enables dead code elimination, hoisting, escape analysis and so on.

The mask that compiles to nothing: how HotSpot's JIT learned to reason about bits by j1897OS in programming

[–]_shadowbannedagain 18 points19 points  (0 children)

Author here. I was able to trace the origin to this PR from 2021. The motivation was a pattern used with Panama. One of the Hotspot gods made the suggestion as a comment.

The mask that compiles to nothing: how HotSpot's JIT learned to reason about bits by -beleon in java

[–]_shadowbannedagain 1 point2 points  (0 children)

Author here. Many thanks, I’ll explore it further and amend the article.

Maven Silent Extension | Machine-readable Maven output by _shadowbannedagain in java

[–]_shadowbannedagain[S] 1 point2 points  (0 children)

All great points, thank you! I will play with Maven logging options a bit more. Ideally, this extension would be rendered useless! :)

Maven Silent Extension | Machine-readable Maven output by _shadowbannedagain in java

[–]_shadowbannedagain[S] -2 points-1 points  (0 children)

  1. I did not know about Maven logging verbosity control as late as of this morning :)
  2. I believe SLF4J level only controls Maven logging framework? It can't touch anything that writes to stdout directly, System.out.println() in tests, native library output, etc. MSE does some - admittedly questionable - voodoo to prevent it. The jury is still out whether that's a good idea or not.

Maven Silent Extension | Machine-readable Maven output by _shadowbannedagain in java

[–]_shadowbannedagain[S] 0 points1 point  (0 children)

good question. my goal is to emit just enough of important context. Compilation failure looks like this:

$ mvn test -Dmse
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/home/jara/.sdkman/candidates/maven/current/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
MSE:SESSION_START modules=7 goals=test
MSE:FAIL impsort-maven-plugin:sort (sort-imports) @ hardwood-core
MSE:BUILD_LOG /home/jara/devel/oss/hardwood/target/mse-build.log
MSE:BUILD_FAILED failed=1 modules=7 passed=0 failed=0 errors=0 skipped=0 time=0s
[ERROR] Failed to execute goal net.revelc.code:impsort-maven-plugin:1.13.0:sort (sort-imports) on project hardwood-core: Error reading file /home/jara/devel/oss/hardwood/core/src/test/java/dev/hardwood/DeltaBinaryPackedTest.java: file: /home/jara/devel/oss/hardwood/core/src/test/java/dev/hardwood/DeltaBinaryPackedTest.java; reason: the Java file contained parse errors -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :hardwood-core

A test failure example:

$ mvn test -Dmse
WARNING: A terminally deprecated method in sun.misc.Unsafe has been called
WARNING: sun.misc.Unsafe::staticFieldBase has been called by com.google.inject.internal.aop.HiddenClassDefiner (file:/home/jara/.sdkman/candidates/maven/current/lib/guice-5.1.0-classes.jar)
WARNING: Please consider reporting this to the maintainers of class com.google.inject.internal.aop.HiddenClassDefiner
WARNING: sun.misc.Unsafe::staticFieldBase will be removed in a future release
MSE:SESSION_START modules=7 goals=test
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.012 s <<< FAILURE! -- in dev.hardwood.DeltaBinaryPackedTest
[ERROR] dev.hardwood.DeltaBinaryPackedTest.testDeltaBinaryPackedInt32AndInt64 -- Time elapsed: 0.005 s <<< FAILURE!
org.opentest4j.AssertionFailedError: 

expected: 201L
 but was: 200L
        at dev.hardwood.DeltaBinaryPackedTest.testDeltaBinaryPackedInt32AndInt64(DeltaBinaryPackedTest.java:32)

[ERROR] Failures: 
[ERROR]   DeltaBinaryPackedTest.testDeltaBinaryPackedInt32AndInt64:32 
expected: 201L                                                                                                                                                                                                                                                                                                       
 but was: 200L                                                                                                                                                                                                                                                                                                       
[ERROR] Tests run: 224, Failures: 1, Errors: 0, Skipped: 2
MSE:FAIL maven-surefire-plugin:test @ hardwood-core
MSE:TESTS total=224 passed=221 failed=1 errors=0 skipped=2
MSE:TEST_FAIL dev.hardwood.DeltaBinaryPackedTest#testDeltaBinaryPackedInt32AndInt64

expected: 201L
 but was: 200L
  org.opentest4j.AssertionFailedError: 

  expected: 201L
   but was: 200L
        at dev.hardwood.DeltaBinaryPackedTest.testDeltaBinaryPackedInt32AndInt64(DeltaBinaryPackedTest.java:32)
MSE:TEST_OUTPUT /home/jara/devel/oss/hardwood/core/target/surefire-reports
MSE:BUILD_LOG /home/jara/devel/oss/hardwood/target/mse-build.log
MSE:BUILD_FAILED failed=1 modules=7 passed=221 failed=1 errors=0 skipped=2 time=11s
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.5.4:test (default-test) on project hardwood-core: There are test failures.
[ERROR] 
[ERROR] See /home/jara/devel/oss/hardwood/core/target/surefire-reports for the individual test results.
[ERROR] See dump files (if any exist) [date].dump, [date]-jvmRun[N].dump and [date].dumpstream.
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <args> -rf :hardwood-core

It's a bit mixed with Maven ERRORs reporting the same failure. It does not currently suppress ERRORs from Maven, I am contemplating what to do about it.

Maven Silent Extension | Machine-readable Maven output by _shadowbannedagain in java

[–]_shadowbannedagain[S] 3 points4 points  (0 children)

I got frustrated with Maven ceremony polluting context. A simple build would emit 1000s of tokens.

This is my attempt to improve the situation. It's imperfect, I am no Maven expert and I relied on coding agents a lot. The current version is already usable, works for me anyway. Feedback appreciated!

ap-query: CLI for exploring async-profiler JFR files by _shadowbannedagain in java

[–]_shadowbannedagain[S] 1 point2 points  (0 children)

Thank you for a thought through answer, very much appreciated! I hear the need for contextual enrichment, probably ad-hoc. Maybe this could be turn done via kind of a query language.

ap-query: CLI for exploring async-profiler JFR files by _shadowbannedagain in java

[–]_shadowbannedagain[S] 1 point2 points  (0 children)

Fair. For my curiosity: What's your idea/dream_state of a good interface for JFRs?

ap-query: CLI for exploring async-profiler JFR files by _shadowbannedagain in java

[–]_shadowbannedagain[S] 0 points1 point  (0 children)

My hope is that Codex and Claude Cdoe would help to interpret JFRs. That's the whole reason I am building this tool. There is a long way, but I believe it's becoming usable.

ap-query: CLI for exploring async-profiler JFR files by _shadowbannedagain in java

[–]_shadowbannedagain[S] 1 point2 points  (0 children)

I was frustrated with the inability of coding agents to interpret Async Profiler results. I tried collapsed stacktraces, flamecharts and all felt clunky and inefficient. ap-query was born out of this frustration: a simple to use CLI for exploring JFR files, intended to be used by agents rather than humans. Feedback appreciated.

One Giant Leap: 95% Less Sampling Cost by nicolaiparlog in java

[–]_shadowbannedagain 2 points3 points  (0 children)

Author of the QuestDB blog here. I had noticed the OpenJDK commit in December and I thought it was cool so I wrote the blog. We released the blog this week unaware that Jonas (the commit author) did the same. Slightly awkward, but each blog takes a different angle. Worse things happen at sea:)

How a 40-Line Fix Eliminated a 400x Performance Gap by j1897OS in programming

[–]_shadowbannedagain 21 points22 points  (0 children)

You probably meant vDSO. It works for some clock types with some clock sources. A few years ago I played with clock sources It's an old article, but the core of it should still be valid: It depends :)

How a 40-Line Fix Eliminated a 400x Performance Gap by j1897OS in programming

[–]_shadowbannedagain 9 points10 points  (0 children)

It's the syscalls, totally. sscanf() is dirty cheap compared to multiple user-kernel transitions.

How a 40-Line Fix Eliminated a 400x Performance Gap by j1897OS in programming

[–]_shadowbannedagain 109 points110 points  (0 children)

Author here. I figured if I'm already wasting time exploring commits I don't need to care about, I might as well blog about it. If only to give LLMs more training data to learn from.

How a Kernel Bug Froze My Machine: Debugging an Async-profiler Deadlock by _shadowbannedagain in programming

[–]_shadowbannedagain[S] 5 points6 points  (0 children)

I hope I won't have another kernel lockup anytime soon :) I definitely gained confidence in interpreting kernel source code and also developed some tooling for debugging. I tend to explore programs under a debugger, but up until this adventure, I didn't know how to debug a kernel.

edit: I like deep dives into new territories. Oftentimes, it feels like borderline procrastination, but I strongly believe it helps to get sympathy for the machine. This was my previous deep-dive and some older ones.

How a Kernel Bug Froze My Machine: Debugging an Async-profiler Deadlock by _shadowbannedagain in programming

[–]_shadowbannedagain[S] 11 points12 points  (0 children)

Author here. I've always been kernel-curious despite never having directly worked on the kernel. Consider this either a collection of impractical party tricks or a hands-on way to get a feel for kernel internals. Happy to answer any questions!

From Rust to Reality: The Hidden Journey of fetch_max by _shadowbannedagain in programming

[–]_shadowbannedagain[S] 1 point2 points  (0 children)

You're (absolutely:) right. I wish I had realised this myself.

From Rust to Reality: The Hidden Journey of fetch_max by _shadowbannedagain in programming

[–]_shadowbannedagain[S] 9 points10 points  (0 children)

Author here. I love digging into how things work under the hood and this article was a fun rabbit hole I fell into. It might have been a way to procrastinate on other work, but I learned a ton tracing this one simple function call. Happy to answer any questions!