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

indy instrumentation - leftovers migration #13074

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

SylvainJuge
Copy link
Contributor

@SylvainJuge SylvainJuge commented Jan 20, 2025

Should be the final step of #11457, hopefully completing it.

There are currently 5 overrides of isIndyModule() and the goal here is to remove all most of them, hence allowing to move forward with the next steps described in #13031

This PR should be considered a "work in progress" until all the checks are passing before being ready for review.

@SylvainJuge SylvainJuge mentioned this pull request Jan 21, 2025
36 tasks
@SylvainJuge SylvainJuge marked this pull request as ready for review January 21, 2025 15:10
@SylvainJuge SylvainJuge requested a review from a team as a code owner January 21, 2025 15:10
@@ -28,8 +32,17 @@ public boolean defaultEnabled(ConfigProperties config) {
}

@Override
public boolean isIndyModule() {
return false;
public void injectClasses(ClassInjector injector) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think having any invokedynamic-based instrumentation/proxies is a good idea for the lambda instrumentation: The reason is that we unecessarily risk recursions for the invokedynamic bootstrapping if lambdas are used in there in some unfortunate places, even if this is not the case right now.

I feel we should rather simply move those two classes to the agent bootstrap package, lambda instrumentation imo is special enough to justify this. Alternatively, we could directly inject the classes via injectedClassNames().

Copy link
Contributor Author

@SylvainJuge SylvainJuge Jan 21, 2025

Choose a reason for hiding this comment

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

Good point, until moving those to the bootstrap package is further discussed I've switched to using injectedClassNames() in 45ead47

try {
byte[] result =
transformer.transform(
targetClass.getClassLoader(), slashClassName, targetClass, null, classBytes);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] here we used to call .transform(...) with null target class.
However, the implementation of JavaModuleClassFileTransformer needs targetClass to be set in order to get the jpms module, in practice it does not seem to make any difference as the transformation should be idempotent and identical when defining or redefining the class. Also here the targetClass is never null thanks to the call to isHelperClass above.

}

@Override
public byte[] transform(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] here we override the pre-java9 API and then resolve the class module from the class, this allows to transparently call it from code compiled with Java 8 API level.

In practice, there is only a single usage for this in the internal lambda instrumentation, which makes it equivalent to the (now removed) Java9LambdaTransformer.

instrumentationInstalled = true;
ClassFileTransformerHolder.setClassFileTransformer(resettableClassFileTransformer);
if (JavaModule.isSupported()) {
// wrapping in a JPMS compliant implementation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] wrapping at registration time helps to make the consumer transparently use it with java 8 API.

public class InlineIbmResourceLevelInstrumentationModule extends InstrumentationModule {
public InlineIbmResourceLevelInstrumentationModule() {
super("inline-ibm-resource-level");
public class IbmResourceLevelInstrumentationModule extends InstrumentationModule {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

[for reviewer] there is no need to maintain an inline and indy variants of this instrumentation, so we only need one that is compatible with both.

@SylvainJuge SylvainJuge marked this pull request as draft January 22, 2025 15:08
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