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

Refinements to AssociatedConverterImpl.cache #7976

Merged
merged 3 commits into from May 16, 2023

Conversation

jglick
Copy link
Member

@jglick jglick commented May 10, 2023

I saw some thread dumps from a heavily loaded server that were all inside loadClass from AssociatedConverterImpl and noticed several things in sources that could be improved:

  • ClassValue can be used as of Java 7 for this sort of cache based on Class. (Basically anything using Map<Class, T> with compute-on-first-load caching semantics.) This is simpler, and also allows garbage collection of classes (though for XStream types we would not expect the class loaders to be removed during a Jenkins session).
  • The common case on a cache miss is that there is not any such converter. But then constructing the ClassNotFoundException is relatively expensive, especially fillInStackTrace. Suffices to short-circuit this by checking whether the corresponding *.class file even exists.
  • Every XStream2 instance maintains its own cache, and thus has to do its own class loading (including negative cache misses) for every type that comes up in XML. There are normally several instances in the system, and while many types are only ever used in one, some (like PersistedList) may be used generically. I suspect this may have actually been the issue in the observed thread dumps, in conjunction with a bug in a proprietary plugin that leads to numerous XStream2 instances being constructed.

Testing done

Started Jenkins and did basic stuff (created a project, ran builds, saved global config) with some printlns verifying when cache misses were resolved and how.

Proposed changelog entries

  • Refinements to class loading behavior looking up special formatters for XML configuration files.

Maintainer checklist

Before the changes are marked as ready-for-merge:

  • There are at least two (2) approvals for the pull request and no outstanding requests for change.
  • Conversations in the pull request are over, or it is explicit that a reviewer is not blocking the change.
  • Changelog entries in the pull request title and/or Proposed changelog entries are accurate, human-readable, and in the imperative mood.
  • Proper changelog labels are set so that the changelog can be generated automatically.
  • If the change needs additional upgrade steps from users, the upgrade-guide-needed label is set and there is a Proposed upgrade guidelines section in the pull request title (see example).
  • If it would make sense to backport the change to LTS, a Jira issue must exist, be a Bug or Improvement, and be labeled as lts-candidate to be considered (see query).

@basil basil self-assigned this May 10, 2023
basil
basil previously approved these changes May 10, 2023
Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice optimization. Thanks for the PR!

@jglick jglick dismissed basil’s stale review May 10, 2023 18:30

substantive modification since then

@NotMyFault NotMyFault requested a review from basil May 10, 2023 22:53
@NotMyFault NotMyFault added the rfe For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted label May 10, 2023
Copy link
Member

@NotMyFault NotMyFault left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

o, nice!

Copy link
Member

@basil basil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR is now ready for merge. We will merge it after approximately 24 hours if there is no negative feedback. Please see the merge process documentation for more information about the merge process. Thanks!

@basil basil added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label May 12, 2023
@NotMyFault NotMyFault merged commit 1ce978a into jenkinsci:master May 16, 2023
15 checks passed
@jglick jglick deleted the AssociatedConverterImpl branch May 16, 2023 14:03
@basil
Copy link
Member

basil commented Sep 26, 2023

Causes JENKINS-72067.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback rfe For changelog: Minor enhancement. use `major-rfe` for changes to be highlighted
Projects
None yet
3 participants