[foreign-jextract] [Rev 02] RFR: 8239493: Add classfile generation to jextract
Jorn Vernee
jvernee at openjdk.java.net
Tue Apr 7 13:01:10 UTC 2020
> Hi,
>
> This patch adds class file generation to jextract using ASM, which in some places replaces the generation done by the
> current source code generator. In particularly, it replaces the generation of all constant fields with static getters,
> that use dynamic constants as backing storage rather than fields. This allows for more sharing between constants, and
> also reduces the pressure on clinit code size a lot, enabling extraction of much bigger native header files. The new
> scheme generates an extra constant helper class which holds all these constants, and the source generator generates the
> high-level wrapper functions. The scheme can also be extended to generate multiple constant helper classes, should we
> run out of constant pool indices (in rare cases). This patch reworks the interface of JavaSourceBuilder, since extra
> parameters are needed in order to do the new constant generation. For generating methods that need constants, it calls
> into a new ConstantHelper class, which returns a DirectMethodHandleDesc describing the generated constant getter. A
> call to this getter is then emitted. This patch also merges the HandleSourceFactory and StaticWrapperSourceFactory
> into OutputFactory, since only the latter was ever being used, but the split in code made it a lot harder to reason
> about the correctness of for instance changing C identifiers into java-safe ones. Because of this, the diff for
> OuputFactory looks a bit messy, so maybe it's easier to look at the resulting file as a whole. The tests are changed
> to look for the now generated static getters, instead of fields (`static final` fields don't work well with dynamic
> constants, since they are eagerly initialized). As a small bonus, this patch adds the missing ABI-agnostic
> C_LONGDOUBLE constant (this was causing some test failures). Thanks, Jorn
Jorn Vernee has updated the pull request incrementally with three additional commits since the last revision:
- Addressed review comments:
- Made Utils final, and added private constructor
- renamed some addXXX methods in JavaSourceBuilder to addXXXGetter for clarity
- renamed some getXXX method in JavaSourceBuilder to XXXGetCallString for clarity
- renamed some visitedXXX methods in OutputFactory to XXXSeen for clarity
- Factored out several calls to emitGetter in constantHelper into helper methods with more readable names
- Remove makeCString bootstrap and depend on Cstring::toCString instead
- Add class gen test
-------------
Changes:
- all: https://git.openjdk.java.net/panama-foreign/pull/102/files
- new: https://git.openjdk.java.net/panama-foreign/pull/102/files/517a9c72..aa60472b
Webrevs:
- full: https://webrevs.openjdk.java.net/panama-foreign/102/webrev.02
- incr: https://webrevs.openjdk.java.net/panama-foreign/102/webrev.01-02
Stats: 586 lines in 8 files changed: 468 ins; 81 del; 37 mod
Patch: https://git.openjdk.java.net/panama-foreign/pull/102.diff
Fetch: git fetch https://git.openjdk.java.net/panama-foreign pull/102/head:pull/102
PR: https://git.openjdk.java.net/panama-foreign/pull/102
More information about the panama-dev
mailing list