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

Avoids reinstalling the agent after retransformation of loaded classes. #28

Merged
merged 1 commit into from
Dec 15, 2021

Conversation

raphw
Copy link
Contributor

@raphw raphw commented Dec 15, 2021

This closes a short hole where classes might get loaded after retransformation and transformer removal but before the new transformer is added. Also, it keeps the patch intact if a Jndi lookup class is retransformed by another agent.

…s. This closes a short hole where classes might get loaded after retransformation and transformer removal but before the new transformer is added. Also, it keeps the patch intact if a Jndi lookup class is retransformed by another agent.
Copy link
Contributor

@simonis simonis left a comment

Choose a reason for hiding this comment

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

Hi @raphw and thanks for your PR,

I think you change looks good. I just want to clarify a few things for my understanding:

This closes a short hole where classes might get loaded after retransformation and transformer removal but before the new transformer is added.

Completely agree here.

Also, it keeps the patch intact if a Jndi lookup class is retransformed by another agent.

This is where I can't fully follow. In the context of the old version and according to my reading of the API documentation of retransformClasses(...) the following happens when another agent will retransform the class:

  1. starting from the initial class file bytes
  2. for each transformer that was added with canRetransform=false, the bytes returned by transform during the last class load or redefine are reused as the output of the transformation; note that this is equivalent to reapplying the previous transformation, unaltered; except that transform method is not called.
  3. for each transformer that was added with canRetransform=true, the transform method is called in these transformers

Doesn't step 2. means that the new agent will use the previous transformation results of our initial agent? If yes, everything would be fine, right? If not, I agree with you because in that case the original bytecodes will be used.

If the removal of the first agent which was added with canRetransform=true means that its transformation won't be considered any more in a new retransformation and there's no transformation available from our second transformer which was added with canRetransform=false afterwards, I understand your argument.

@raphw
Copy link
Contributor Author

raphw commented Dec 15, 2021

In my understanding, your last segment applies. Removing and adding clears this "memory". You can even add the same transformer instance multiple times and it will be invoked multiple times, the registrations are treated as fully independent.

Therefore, I would suggest to simply keep the transformer in place, the costs of retransforming for a rare event are negligible.

@simonis simonis merged commit ab25000 into corretto:main Dec 15, 2021
@simonis
Copy link
Contributor

simonis commented Dec 15, 2021

Thanks for the confirmation.

@alvdavi alvdavi mentioned this pull request Dec 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants