On Tue, 7 Oct 2025 01:42:15 GMT, Erik Gahlin <[email protected]> wrote:
> I believe the filter can be simplified to this
>
> ```
> @StackFilter({"java.lang.reflect.Field", "java.lang.reflect.ReflectAccess",
> "java.lang.invoke.MethodHandles$Lookup"})
> ```
>
> and then set the offset to 4 or 5 in
> PlatformEventType::determineStackTraceOffset() to skip the offer method. This
> is cheaper and probably more robust. It will also make the place where the
> mutation happens the top frame, similar to other events, which works well for
> tooling.
The APIs are in Field and Lookup so having the API method as the top frame is
useful. It would be possible to reduce the filter to `{
"java.lang.reflect.ReflectAccess",
"java.lang.invoke.MethodHandles$Lookup::unreflectField" }` with
determineStackTraceOffset returning 6 but it's too fiddly and requires knowing
about two "faraway places" when doing any refactoring. Mutating final fields is
the slow path so performance is not a concern. So I think the trade-off to keep
it as maintainable as possible is okay. The test checks the top frame and also
scans the StackFilter to ensure the class is visible and that any filter value
with a method name at least names a method that is declared in the class.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/25115#issuecomment-3375647041