Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8266936: Add a finalization JFR event #4101

Closed
wants to merge 13 commits into from

Conversation

bchristi-git
Copy link
Member

@bchristi-git bchristi-git commented May 18, 2021

Please review this enhancement to add a new JFR event, generated whenever a finalizer is run.
(The makeup is similar to the Deserialization event, JDK-8261160.)

The event's only datum (beyond those common to all jfr events) is the class of the object that was finalized.

The Category for the event:
"Java Virtual Machine" / "GC" / "Finalization"
is what made sense to me, even though the event is generated from library code.

Along with the new regtest, I added a run mode to the basic finalizer test to enable jfr.
Automated testing looks good so far.

Thanks,
-Brent


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/4101/head:pull/4101
$ git checkout pull/4101

Update a local copy of the PR:
$ git checkout pull/4101
$ git pull https://git.openjdk.java.net/jdk pull/4101/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 4101

View PR using the GUI difftool:
$ git pr show -t 4101

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/4101.diff

@bridgekeeper
Copy link

bridgekeeper bot commented May 18, 2021

👋 Welcome back bchristi! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented May 18, 2021

@bchristi-git The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot
  • security

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added security security-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels May 18, 2021
@bchristi-git
Copy link
Member Author

/label add hotspot

@openjdk
Copy link

openjdk bot commented May 18, 2021

@bchristi-git The hotspot label was already applied.

@openjdk openjdk bot added the rfr Pull request is ready for review label May 18, 2021
@mlbridge
Copy link

mlbridge bot commented May 18, 2021

Webrevs

@egahlin
Copy link
Member

egahlin commented May 19, 2021

This looks useful, but I am worried about the performance impact:

  • The added allocation for every object that is finalized.
  • The event being enabled in the default configuration.

The default configuration must be safe to use even in pathological cases, i.e. an application with lots of objects being finalized. It's probably too much overhead (or number of events) for the profile configuration as well.

There is also the added startup cost of JFR. One event may not matter that much, but they all add up. We need to put in place a mechanism that doesn't rely on bytecode instrumentation at runtime. There is an enhancement for that, but it requires some engineering first.

@AlanBateman
Copy link
Contributor

This looks useful, but I am worried about the performance impact:

  • The added allocation for every object that is finalized.
  • The event being enabled in the default configuration.

The default configuration must be safe to use even in pathological cases, i.e. an application with lots of objects being finalized. It's probably too much overhead (or number of events) for the profile configuration as well.

There is also the added startup cost of JFR. One event may not matter that much, but they all add up. We need to put in place a mechanism that doesn't rely on bytecode instrumentation at runtime. There is an enhancement for that, but it requires some engineering first.

I'm a bit worried by this too. Does it need to be enabled by default? Can we put a static final instance of FinalizerEvent in that class that can be used to test if the event is enabled so that it doesn't create a FinalizerEvent when disabled?

Is it worth exploring doing have an event in the VM, in register_finalizer, instead?

@egahlin
Copy link
Member

egahlin commented May 19, 2021

I wonder if there needs to be one event per finalized object?

Perhaps a counter per class would be as useful, i.e. jdk.FinalizationStatistics, and if it could be implemented in the VM, without other implications, that would be great.

Such an event could be enabled by default and provide much greater value than an event that users would need to know about and configure themselves, which 99,99% of all user will not do.

@AlanBateman
Copy link
Contributor

/label remove security

@openjdk openjdk bot removed the security security-dev@openjdk.org label May 19, 2021
@openjdk
Copy link

openjdk bot commented May 19, 2021

@AlanBateman
The security label was successfully removed.

@AlanBateman
Copy link
Contributor

AlanBateman commented May 19, 2021

I wonder if there needs to be one event per finalized object?

Perhaps a counter per class would be as useful, i.e. jdk.FinalizationStatistics, and if it could be implemented in the VM, without other implications, that would be great.

Such an event could be enabled by default and provide much greater value than an event that users would need to know about and configure themselves, which 99,99% of all user will not do.

So some statistics or periodic event that N instances of class C were registered or queued? I think you are right that this would be a lot more valuable. It might be possible to prototype this quickly with a ClassValue.

@ChrisHegarty
Copy link
Member

My 0.02$ ;-) I really like the idea of a jdk.FinalizationStatistics event. The devil is (as always) in the details.

Multiple concerns have been raised above, which benefit from being separated out:

  1. Raising an event per invocation of each individual finalizer may be costly when JFR is enabled (since there could be an extremely large number of these), as well as a little unwieldy for a human observer. Aggregating invocations of finalizers and reporting periodically seems like a nice solution to this.

  2. A jdk.FinalizationStatistics event that provides an aggregate count of all finalizer invocations seems most straightforward, but less useful. A jdk.FinalizationStatistics event that provides per-class invocation metrics seems more useful, but at the expense of a more complex event structure. Maybe model jdk.FinalizationStatistics as a tuple of Class and long (count) - periodically committing multiple jdk.FinalizationStatistics events, one event per class? ( or was the thought to somehow aggregate all these per-class metrics into a single jdk.FinalizationStatistics event? )

  3. If we keep the currently proposed semantic - capturing actual invocation/queueing counts (rather than registrations), then I see no reason why the implementation of a jdk.FinalizationStatistics needs to be in the JVM. The metrics can be captured in Java code and reported in a similar way to the container metrics (being proposed in PR 3126). Surely, this would be more straightforward to implement and maintain, no?

  4. The startup cost of JFR. I dunno enough about this, but what I do know is that a handler needs to be spun per Java-event, so maybe this has some bearing on the decision of no.3 above?

@mlchung
Copy link
Member

mlchung commented May 19, 2021

I wonder if there needs to be one event per finalized object?

I also concern with the performance overhead of one event per finalized object.

The primary goal of this JFR event is to help identifying the use of finalizers in existing libraries/applications and prepare them to migrate away from using finalization. As well-known, the finalization mechanism is inherently problematic.

Perhaps a counter per class would be as useful, i.e. jdk.FinalizationStatistics, and if it could be implemented in the VM, without other implications, that would be great.

Therefore, a counter per class would be useful as it identifies the usage of finalizers while providing the number of objects per class pending for finalization (see ReferenceQueue::enqueue and ReferenceQueue::reallyPoll where it keeps track of the pending for finalization counter).

Another option is to go with a simple approach - just report the aggregated number of Finalizer objects per class which still meets the primary goal to identify what existing code uses finalizers and the counter gives the users an additional information how many finalizers are created.

BTW the number of finalizer invocation is not more useful than the number of Finalizer instances unless we provide both counters so that the users can determine the number of objects pending for finalization.

Such an event could be enabled by default and provide much greater value than an event that users would need to know about and configure themselves, which 99,99% of all user will not do.

I agree an event enabled by default is more useful provided that the performance overhead is insignificant.

I was also thinking if this event should be implemented in the VM in order to avoid some performance overhead such as object allocation. Erin, what is the benefit of implementing in in the VM?

@egahlin
Copy link
Member

egahlin commented May 19, 2021

I was also thinking if this event should be implemented in the VM in order to avoid some performance overhead such as object allocation. Erik, what is the benefit of implementing in in the VM?

No startup cost, no allocation and there are callbacks when a class gets unloaded, so it's probably easier to clear any table where the statistics is held.

@mlchung
Copy link
Member

mlchung commented May 19, 2021

I was also thinking if this event should be implemented in the VM in order to avoid some performance overhead such as object allocation. Erik, what is the benefit of implementing in in the VM?

No startup cost, no allocation and there are callbacks when a class gets unloaded, so it's probably easier to clear any table where the statistics is held.

Thanks for the confirmation. This is performance sensitive area and so it's worth considering doing it in the VM. In either case, performance measurement of the overhead will tell.

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 16, 2021

@bchristi-git This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Jul 14, 2021

@bchristi-git This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the /open pull request command.

@bridgekeeper bridgekeeper bot closed this Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core-libs core-libs-dev@openjdk.org hotspot hotspot-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

6 participants