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

[#10828] Backport: Resolve issue for rewritten launcher on spring-boot 3.2 #10834

Merged
merged 1 commit into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
import com.navercorp.pinpoint.common.trace.ServiceType;
import com.navercorp.pinpoint.common.util.VarArgs;
import com.navercorp.pinpoint.plugin.spring.boot.interceptor.LauncherLaunchInterceptor;

import java.security.ProtectionDomain;
Expand Down Expand Up @@ -71,6 +72,7 @@ public void setTransformTemplate(TransformTemplate transformTemplate) {

private void addLauncherEditor() {
transformTemplate.transform("org.springframework.boot.loader.Launcher", LauncherTransform.class);
transformTemplate.transform("org.springframework.boot.loader.launch.Launcher", LauncherTransform.class);
}

public static class LauncherTransform implements TransformCallback {
Expand All @@ -83,9 +85,14 @@ public byte[] doInTransform(Instrumentor instrumentor, ClassLoader classLoader,
InstrumentClass target = instrumentor.getInstrumentClass(classLoader, className, classfileBuffer);
InstrumentMethod method = target.getDeclaredMethod("launch", "java.lang.String[]", "java.lang.String", "java.lang.ClassLoader");
if (method != null) {
method.addInterceptor(LauncherLaunchInterceptor.class);
method.addInterceptor(LauncherLaunchInterceptor.class, VarArgs.va(2));
} else {
// >= '3.2.0'
method = target.getDeclaredMethod("launch", "java.lang.ClassLoader", "java.lang.String", "java.lang.String[]");
if (method != null) {
method.addInterceptor(LauncherLaunchInterceptor.class, VarArgs.va(0));
}
}

return target.toBytecode();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.navercorp.pinpoint.bootstrap.interceptor.AroundInterceptor;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
import com.navercorp.pinpoint.common.util.ArrayArgumentUtils;
import com.navercorp.pinpoint.plugin.spring.boot.SpringBootConstants;

import java.net.URL;
Expand All @@ -44,8 +45,15 @@ public class LauncherLaunchInterceptor implements AroundInterceptor {

private final TraceContext traceContext;

private final int classLoaderIndex;

public LauncherLaunchInterceptor(TraceContext traceContext) {
this(traceContext, 2);
}

public LauncherLaunchInterceptor(TraceContext traceContext, int classLoaderIndex) {
this.traceContext = traceContext;
this.classLoaderIndex = classLoaderIndex;
}

@Override
Expand All @@ -57,7 +65,7 @@ public void before(Object target, Object[] args) {
return;
}
String serviceName = createServiceName(target);
URLClassLoader classLoader = (URLClassLoader) args[2];
URLClassLoader classLoader = ArrayArgumentUtils.getArgument(args, classLoaderIndex, URLClassLoader.class);
URL[] urls = classLoader.getURLs();
List<String> loadedJarNames = new ArrayList<String>(extractLibJarNamesFromURLs(urls));
ServerMetaDataHolder holder = this.traceContext.getServerMetaDataHolder();
Expand All @@ -83,7 +91,8 @@ private boolean validate(Object target, Object[] args) {
if (args.length < 3) {
return false;
}
if (!(args[2] instanceof URLClassLoader)) {
URLClassLoader classLoader = ArrayArgumentUtils.getArgument(args, classLoaderIndex, URLClassLoader.class);
if (classLoader == null) {
return false;
}
return true;
Expand Down
Loading