RFR: 7903608: Cyclic initialization leads to NPE in header class with global variable

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Dec 14 12:37:17 UTC 2023


This PR fixes some new static initialization cycles that have been made possible by (a) the removal of constant classes and (b) the fact that we refer to struct layouts by name.

The fix consists in two parts:

* First, we make sure that whenever the header class needs to reference another layout, we do so behind a holder class idiom (this patch only touches globals, as all other cases are already using the holder idiom)

* Secondly, we invert the inheritance order of header classes (this is only relevant when using header file splitting). In the current order, symbols that are found "later" in the header files, are added in classes that are "higher up" in the inheritance chain. This leads to issues, as you can have e.g. a primitive typedef depending on a previous primitive typedef, which is in reality defined in a subclass (which leads to a cycle).

Since I was there, I decided to simplify the logic for global variables, and make it more uniform with the rest: now we only emit an accessor for the global segment and a layout. We no longer emit a var handle accessor - developers have all they need to get one. Global vars setters/getters have also been simplified to just use memory segment accessors.

-------------

Commit messages:
 - Fix whitespaces
 - Add tests
 - Merge branch 'panama' into clinit_cycles
 - Adjust indentation
 - Cleanup some code
 - Invert inheritance in header classes
 - Initial push

Changes: https://git.openjdk.org/jextract/pull/160/files
 Webrev: https://webrevs.openjdk.org/?repo=jextract&pr=160&range=00
  Issue: https://bugs.openjdk.org/browse/CODETOOLS-7903608
  Stats: 337 lines in 13 files changed: 260 ins; 24 del; 53 mod
  Patch: https://git.openjdk.org/jextract/pull/160.diff
  Fetch: git fetch https://git.openjdk.org/jextract.git pull/160/head:pull/160

PR: https://git.openjdk.org/jextract/pull/160


More information about the jextract-dev mailing list