Skip to content

Commit

Permalink
pass through the remote ClassLoaders name
Browse files Browse the repository at this point in the history
add getName to the IClassloader and set a name in the RemoteClassLoader

This improves the debugability from RemoteClassloaders to understand any
classloading related issues.
  • Loading branch information
jtnord committed May 14, 2024
1 parent 19e2927 commit e55daa8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/main/java/hudson/remoting/DumbClassLoaderBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ public ResourceFile[] getResources2(String name) throws IOException {
}
return res;
}

@Override
public String getName() throws IOException {
return base.getName();
}

}
35 changes: 32 additions & 3 deletions src/main/java/hudson/remoting/RemoteClassLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,11 +170,18 @@ public static ClassLoader create(@CheckForNull ClassLoader parent, @NonNull ICla
// actually our classloader that we exported to the other side.
return ((ClassLoaderProxy) proxy).cl;
}
return new RemoteClassLoader(parent, proxy);

String name;
try {
name = proxy.getName();
} catch(IOException ignored) {
name = "unknown-due-to-io-error";
}
return new RemoteClassLoader(name, parent, proxy);
}

private RemoteClassLoader(@CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
super(new URL[0], parent);
private RemoteClassLoader(String name, @CheckForNull ClassLoader parent, @NonNull IClassLoader proxy) {
super(name, new URL[0], parent);
final Channel channel = RemoteInvocationHandler.unwrap(proxy);
this.channel = channel == null ? null : channel.ref();
this.underlyingProxy = proxy;
Expand Down Expand Up @@ -887,6 +894,11 @@ public interface IClassLoader {
*/
@NonNull
ResourceFile[] getResources2(String name) throws IOException;

/**
* Name of the classLoader
*/
String getName() throws IOException;
}

/**
Expand Down Expand Up @@ -1178,6 +1190,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
return r;
}

@Override
public String getName() throws IOException {
return cl.getName();
}

@Override
public boolean equals(Object that) {
if (this == that) {
Expand Down Expand Up @@ -1215,6 +1232,7 @@ public String toString() {
return "PSEUDO_BOOTSTRAP";
}
};

}

/**
Expand Down Expand Up @@ -1276,6 +1294,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
return proxy.getResources2(name);
}

@Override
public String getName() throws IOException {
return proxy.getName();
}

private Object readResolve() throws ObjectStreamException {
try {
return getChannelForSerialization().getExportedObject(oid);
Expand All @@ -1285,6 +1308,7 @@ private Object readResolve() throws ObjectStreamException {
}

private static final long serialVersionUID = 1L;

}

private static final class BrokenIClassLoader implements IClassLoader, SerializableOnlyOverRemoting {
Expand Down Expand Up @@ -1336,6 +1360,11 @@ public ResourceFile[] getResources2(String name) throws IOException {
throw new IOException("Cannot get " + name, cause);
}

@Override
public String getName() throws IOException {
throw new IOException("Cannot getName", cause);
}

}

private static Iterable<String> analyze(InputStream bytecode) {
Expand Down

0 comments on commit e55daa8

Please sign in to comment.