On Mon, 26 Oct 2026 12:27:49 GMT, Koichi Sakata <[email protected]> wrote:
> This change prevents NullPointerException in the clhsdb dumpcodecache command. > > `CodeCache.createCodeBlobWrapper()` causes NullPointerException. > `CodeHeap.findStart()` may return null and `CodeHeap.iterate()` passes it to > `CodeCache.createCodeBlobWrapper()` as the `cbStart` argument. > > https://github.com/openjdk/jdk/blob/bbd629b0ef4d0ac7fbc2b33bb76170fd15060cd3/src/jdk.hotspot.agent/share/classes/sun/jvm/hotspot/memory/CodeHeap.java#L111 > > So this change makes `createCodeBlobWrapper()` return null when `cbStart` is > null. > > ### Testing > * jtreg:hotspot/jtreg/serviceability/sa/ > > $ make test TEST="jtreg:hotspot/jtreg/serviceability/sa/" > ============================== > TEST TOTAL PASS FAIL ERROR > SKIP > jtreg:test/hotspot/jtreg/serviceability/sa 81 76 0 0 > 5 > ============================== > > * Manual verification: dumpcodecache does not output NullPointerException. > > $ jhsdb clhsdb --pid 654607 > Attaching to process 654607, please wait... > hsdb> dumpcodecache > <snip> > hsdb> > > Note: `hotspot/jtreg/serviceability/sa/TestDebugInfoDecode.java` passed, but > printed NullPointerException before this change. There is no > NullPointerException in the test output after the change. > > --------- > - [x] I confirm that I make this contribution in accordance with the [OpenJDK > Interim AI Policy](https://openjdk.org/legal/ai). I saw following exception call stacks in TestDebugInfoDecode.jtr: java.lang.NullPointerException: Cannot invoke "sun.jvm.hotspot.debugger.Address.getCIntegerAt(long, long, boolean)" because "addr" is null at jdk.hotspot.agent/sun.jvm.hotspot.types.basic.BasicField.getCInteger(BasicField.java:162) at jdk.hotspot.agent/sun.jvm.hotspot.types.basic.BasicCIntegerField.getValue(BasicCIntegerField.java:54) at jdk.hotspot.agent/sun.jvm.hotspot.code.CodeBlob.getKind(CodeBlob.java:163) at jdk.hotspot.agent/sun.jvm.hotspot.code.CodeBlob.getClassFor(CodeBlob.java:103) at jdk.hotspot.agent/sun.jvm.hotspot.code.CodeCache.createCodeBlobWrapper(CodeCache.java:98) at jdk.hotspot.agent/sun.jvm.hotspot.memory.CodeHeap.iterate(CodeHeap.java:111) at jdk.hotspot.agent/sun.jvm.hotspot.code.CodeCache.iterate(CodeCache.java:132) at TestDebugInfoDecode.checkDecode(TestDebugInfoDecode.java:84) at TestDebugInfoDecode.main(TestDebugInfoDecode.java:118) AFAICS `CodeHeap::iterate` in SA is not a mirror of HotSpot. However we can refer `NMethodIterator` in HotSpot used by `CodeCache::print_codelist()` for `Compiler.codelist` dcmd. Function calls would reach `CodeHeap::next()`, and `CodeHeap::next_used()` is called from it. I think we can implement `CodeHeap::next_used()` in SA, and it should be used rather than `createCodeBlobWrapper()` for code heap iteration because it ensures the result is not a free block: https://github.com/openjdk/jdk/blob/bfffe172f185c4e97ee717580deffcd999a09983/src/hotspot/share/memory/heap.cpp#L480-L490 I agree with you to check there are no exceptions in stderr. ------------- PR Comment: https://git.openjdk.org/jdk/pull/33568#issuecomment-6434907793
