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

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Dec 14 15:26:38 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.

Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:

  Drop spurious changes

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

Changes:
  - all: https://git.openjdk.org/jextract/pull/160/files
  - new: https://git.openjdk.org/jextract/pull/160/files/a9e186de..2b97678b

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jextract&pr=160&range=02
 - incr: https://webrevs.openjdk.org/?repo=jextract&pr=160&range=01-02

  Stats: 6 lines in 1 file changed: 0 ins; 4 del; 2 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