On Thu, 16 Feb 2023 14:58:21 GMT, Maurizio Cimadamore <mcimadam...@openjdk.org> wrote:
>> Adam Sotona has updated the pull request incrementally with one additional >> commit since the last revision: >> >> added 4-byte Unicode text to Utf8EntryTest > > src/java.base/share/classes/jdk/internal/classfile/impl/TransformImpl.java > line 51: > >> 49: * TransformImpl >> 50: */ >> 51: public class TransformImpl { > > Understanding check: a transform implementation is made up of two runnable > (start/end handlers) and a consumer. The consumer can be used e.g. to iterate > and transform all the contents of a compound element (e.g. all the > instruction in a code attribute). > > User-defined transforms can be "resolved" that is, we can "bind" them to a > specific builder, which effectively turns them into consumers (and into a > concrete transform implementation that can be used). > > When two transforms T1 and T2 are composed (so that T1 runs before T2), we > need to implement the `resolve` method of the resulting transform so that: > * We resolve T2 against the provided builder - this gives us a "downstream" > consumer; > * We create a new "chained" builder which wraps the provided builder, and > whose `with` method calls the downstream consumer; > * We then resolve T1 against the chained builder, and return the resulting > consumer > > This means that when we call `accept` on the resulting consumer, we will > transform (using T1) and call `with` (passing the transformed element) on > the chained builder, which will end up calling `accept` on the downstream > consumer, which will apply T2 and finally add the resulting element to the > provided builder. > > Correct? (Phew) Yes, this is how it is designed and implemented. Actually we have only a few real use cases testing this concept, one is a prototype of jdk.jfr class instrumentation at: https://github.com/openjdk/jdk/blob/212bb04e9491badb17c110787727ea19842d1528/test/jdk/jdk/classfile/AdvancedTransformationsTest.java#L293 ------------- PR: https://git.openjdk.org/jdk/pull/10982