Skip to content

Commit 7c347d0

Browse files
committed
make ClassLoaderTable.parentLoaderIds[] instance variable
1 parent cae44b7 commit 7c347d0

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassFileCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ int hasVMSuppliedClassFile(String name, int classLoaderId) {
171171
if (res) {
172172
return classLoaderId;
173173
} else if (classLoaderId != 0) {
174-
classLoaderId = ClassLoaderTable.getParentLoader(classLoaderId);
174+
classLoaderId = classPath.getClassLoaderTable().getParentLoader(classLoaderId);
175175
}
176176

177177
if (classLoaderId == -1) {

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassLoaderTable.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public class ClassLoaderTable {
3737

3838
// TODO [release]: change value to TRUE to remove the print code below entirely by compiler
3939
private static final boolean DEBUG = System.getProperty("org.graalvm.visualvm.lib.jfluid.classfile.ClassLoaderTable") != null; // NOI18N
40-
private static int[] parentLoaderIds;
40+
private int[] parentLoaderIds;
4141

4242
//~ Methods ------------------------------------------------------------------------------------------------------------------
4343

@@ -48,7 +48,7 @@ public class ClassLoaderTable {
4848
* @param loader id of ClassLoader whose parent we are looking for
4949
* @return The id of the parent classloader of the specified classloader
5050
*/
51-
public static int getParentLoader(int loader) {
51+
public int getParentLoader(int loader) {
5252
if (DEBUG) {
5353
System.err.println("ClassLoaderTable.DEBUG: getParent loader: " + loader); // NOI18N
5454
}
@@ -66,7 +66,7 @@ public static int getParentLoader(int loader) {
6666
/**
6767
* @param thisAndParentLoaderData An array
6868
*/
69-
public static void addChildAndParent(int[] thisAndParentLoaderData) {
69+
public void addChildAndParent(int[] thisAndParentLoaderData) {
7070
int ofs = thisAndParentLoaderData[2];
7171

7272
if (ofs == 0) {
@@ -88,7 +88,7 @@ public static void addChildAndParent(int[] thisAndParentLoaderData) {
8888
*
8989
* @param inParentLoaderIds table mapping id (idx) -> parent id ([idx])
9090
*/
91-
public static void initTable(int[] inParentLoaderIds) {
91+
public void initTable(int[] inParentLoaderIds) {
9292
if (DEBUG) {
9393
System.err.println("ClassLoaderTable.DEBUG: init patent loader ids: " + inParentLoaderIds.length); // NOI18N
9494

@@ -114,7 +114,7 @@ public static void initTable(int[] inParentLoaderIds) {
114114
* @param childLoader Id of classloader
115115
* @param parentLoader Id of its parent classloader
116116
*/
117-
private static void addChildAndParent(int childLoader, int parentLoader) {
117+
private void addChildAndParent(int childLoader, int parentLoader) {
118118
if (DEBUG) {
119119
System.err.println("ClassLoaderTable.DEBUG: add child and parent: child: " // NOI18N
120120
+ childLoader + ", parent: " // NOI18N

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassPath.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
170170
//~ Instance fields ----------------------------------------------------------------------------------------------------------
171171

172172
private ClassFileCache classCache;
173+
private ClassLoaderTable loaderTable;
173174
private JarLRUCache zipFileNameToFile;
174175
private PathEntry[] paths;
175176
private boolean isCP; // True for a class path, false for a source path
@@ -199,6 +200,7 @@ public ClassPath(String classPath, boolean isCP) {
199200

200201
paths = (PathEntry[])vec.toArray(new PathEntry[0]);
201202
classCache = new ClassFileCache(this);
203+
loaderTable = new ClassLoaderTable();
202204
}
203205

204206
//~ Methods ------------------------------------------------------------------------------------------------------------------
@@ -261,6 +263,10 @@ void preloadBytecode(String name, String classFileLocation) {
261263
classCache.preloadBytecode(name, classFileLocation);
262264
}
263265

266+
public ClassLoaderTable getClassLoaderTable() {
267+
return loaderTable;
268+
}
269+
264270
public void close() {
265271
// close all ZipFiles in ClassPath, the files on disk would otherwise be locked
266272
// this is a bugfix for http://profiler.netbeans.org/issues/show_bug.cgi?id=61849

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/ClassRepository.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ private DynamicClassInfo tryLoadRealClass(String className, int classLoaderId, b
731731
}
732732

733733
// Try parent loader - in some cases a class can be initially requested with the loader of its subclass
734-
loader = ClassLoaderTable.getParentLoader(loader);
734+
loader = classPath.getClassLoaderTable().getParentLoader(loader);
735735
} while (loader >= 0);
736736

737737
if (clazz == null) {

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/classfile/SameNameClassGroup.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,15 @@ public void add(BaseClassInfo clazz) {
6262
* loader classLoaderId will return this class if asked for the class with this name.
6363
*/
6464
public static BaseClassInfo checkForCompatibility(ClassRepository repo, BaseClassInfo clazz, int classLoaderId) {
65+
ClassLoaderTable table = repo.getClassPath().getClassLoaderTable();
6566
int entryLoader = clazz.getLoaderId();
6667

6768
if (entryLoader == classLoaderId) {
6869
return clazz;
6970
} else {
70-
if (isParentLoaderTo(entryLoader, classLoaderId)) {
71+
if (isParentLoaderTo(table, entryLoader, classLoaderId)) {
7172
return clazz;
72-
} else if (clazz instanceof PlaceholderClassInfo && isParentLoaderTo(classLoaderId, entryLoader)) { // This can happen at least with placeholders
73+
} else if (clazz instanceof PlaceholderClassInfo && isParentLoaderTo(table, classLoaderId, entryLoader)) { // This can happen at least with placeholders
7374
clazz.setLoaderId(classLoaderId);
7475

7576
return clazz;
@@ -118,14 +119,14 @@ public void replace(BaseClassInfo clazz1, BaseClassInfo clazz2) {
118119
classes.add(clazz2);
119120
}
120121

121-
private static boolean isParentLoaderTo(int testParentLoader, int testChildLoader) {
122-
int parent = ClassLoaderTable.getParentLoader(testChildLoader);
122+
private static boolean isParentLoaderTo(ClassLoaderTable table, int testParentLoader, int testChildLoader) {
123+
int parent = table.getParentLoader(testChildLoader);
123124

124125
while (parent != testParentLoader) {
125126
if (parent == 0) {
126127
return false;
127128
} else {
128-
parent = ClassLoaderTable.getParentLoader(parent);
129+
parent = table.getParentLoader(parent);
129130
}
130131
}
131132

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/instrumentation/Instrumentor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import java.util.List;
3131
import org.graalvm.visualvm.lib.jfluid.ProfilerEngineSettings;
3232
import org.graalvm.visualvm.lib.jfluid.classfile.BaseClassInfo;
33-
import org.graalvm.visualvm.lib.jfluid.classfile.ClassLoaderTable;
3433
import org.graalvm.visualvm.lib.jfluid.classfile.ClassRepository;
3534
import org.graalvm.visualvm.lib.jfluid.client.ClientUtils.SourceCodeSelection;
3635
import org.graalvm.visualvm.lib.jfluid.client.RuntimeProfilingPoint;
@@ -233,7 +232,7 @@ public synchronized InstrumentMethodGroupResponse createFollowUpInstrumentMethod
233232
classRepo.addVMSuppliedClassFile(clcmd.getClassName().replace('.','/'), thisAndParentLoaderData[0], classFileBytes);
234233
}
235234

236-
ClassLoaderTable.addChildAndParent(thisAndParentLoaderData);
235+
classRepo.getClassPath().getClassLoaderTable().addChildAndParent(thisAndParentLoaderData);
237236
} else if (cmd instanceof MethodLoadedCommand) {
238237
MethodLoadedCommand mcmd = (MethodLoadedCommand) cmd;
239238

@@ -282,7 +281,7 @@ public synchronized InstrumentMethodGroupResponse createFollowUpInstrumentMethod
282281

283282
public synchronized InstrumentMethodGroupResponse createInitialInstrumentMethodGroupResponse(RootClassLoadedCommand cmd)
284283
throws ClassNotFoundException, BadLocationException {
285-
ClassLoaderTable.initTable(cmd.getParentLoaderIds());
284+
classRepo.getClassPath().getClassLoaderTable().initTable(cmd.getParentLoaderIds());
286285

287286
InstrumentMethodGroupResponse imgr = null;
288287

0 commit comments

Comments
 (0)