raphw / byte-buddy

Runtime code generation for the Java virtual machine.
https://bytebuddy.net
Apache License 2.0
6.29k stars 807 forks source link

Example that could be used in documentation #1645

Closed jimshowalter closed 6 months ago

jimshowalter commented 6 months ago

Attached is a complete example of how to add modified-fields tracking to classes using ByteBuddy.

It was cobbled together from byte-buddy javadocs, https://bytebuddy.net/#/tutorial, issues reported here, and various StackOverflows, over a couple of weeks.

It might be useful to have a single working example available somewhere that can be used to get a holistic understanding of how the pieces fit together.

You're welcome to use the attached example for that.

byte-buddy-example.zip

raphw commented 6 months ago

Thanks for that. Could you create a QA for this? I'm cleaning out the issue tracker every now and then.

jimshowalter commented 6 months ago

What is a QA?

jimshowalter commented 6 months ago

The example doesn't use a TypeCache. Instead it just uses a ConcurrentHashMap + computeIfAbsent. Is that bad? Should it be changed to use a TypeCache?

raphw commented 6 months ago

I mean discussions: https://github.com/raphw/byte-buddy/discussions

Using a type cache, you allow for garbage collection which is not possible otherwise.

jimshowalter commented 6 months ago

I'll move this to discussions.

We wouldn't ever need to GC a ByteBuddy-generated subclass, because we need them for as long as the pod is running.

jimshowalter commented 6 months ago

Started https://github.com/raphw/byte-buddy/discussions/1646.