Skip to content

Commit cae44b7

Browse files
committed
singleton ClassFileCache.getDefault() removed
1 parent d8e2be4 commit cae44b7

27 files changed

+233
-196
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Manifest-Version: 1.0
22
OpenIDE-Module: org.graalvm.visualvm.lib.jfluid/2
33
OpenIDE-Module-Localizing-Bundle: org/graalvm/visualvm/lib/jfluid/Bundle.properties
4-
OpenIDE-Module-Specification-Version: 2.13
4+
OpenIDE-Module-Specification-Version: 2.14
55

visualvm/libs.profiler/lib.profiler/src/org/graalvm/visualvm/lib/jfluid/ProfilerClient.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,7 @@ public void run() {
410410
private int currentAgentId = -1;
411411
private long instrProcessingTime;
412412
private long resultsStart;
413+
private ClassRepository classRepo;
413414

414415
//~ Constructors -------------------------------------------------------------------------------------------------------------
415416

@@ -420,7 +421,8 @@ public ProfilerClient(ProfilerEngineSettings settings, ProfilingSessionStatus st
420421
this.status = status;
421422
appStatusHandler = ash;
422423
serverCommandHandler = sch;
423-
instrumentor = new Instrumentor(status, settings);
424+
classRepo = new ClassRepository();
425+
instrumentor = new Instrumentor(classRepo, status, settings);
424426
histogramManager = new HeapHistogramManager(settings);
425427
EventBufferProcessor.initialize(this);
426428
EventBufferResultsProvider.getDefault().addDispatcher(ProfilingResultsDispatcher.getDefault());
@@ -531,6 +533,10 @@ public int getCurrentInstrType() {
531533
return status.currentInstrType;
532534
}
533535

536+
public ClassRepository getClassRepository() {
537+
return classRepo;
538+
}
539+
534540
public JMethodIdTable getJMethodIdTable() {
535541
synchronized (methodIdsTableLock) {
536542
if (methodIdsTable == null) {
@@ -1557,7 +1563,7 @@ private boolean setVMProperties(VMPropertiesResponse resp, boolean terminateOnEr
15571563
settings.setWorkingDir("");
15581564
settings.setVMClassPaths("", null, null);
15591565
}
1560-
ClassRepository.initClassPaths(settings.getWorkingDir(), settings.getVMClassPaths());
1566+
classRepo.initClassPaths(settings.getWorkingDir(), settings.getVMClassPaths());
15611567

15621568
return true;
15631569
}

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

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@
4949
*
5050
* @author Misha Dmitirev
5151
*/
52-
public class ClassFileCache {
53-
//~ Static fields/initializers -----------------------------------------------------------------------------------------------
54-
55-
private static ClassFileCache defaultClassFileCache;
56-
52+
class ClassFileCache {
5753
//~ Instance fields ----------------------------------------------------------------------------------------------------------
5854

5955
private ClassPath classPath; // Used to quickly obtain an open JAR file for a given name
@@ -71,7 +67,7 @@ public class ClassFileCache {
7167
//~ Constructors -------------------------------------------------------------------------------------------------------------
7268

7369
//------------ We don't expect the below API to be used outside of this package, hence it's package-private ------------
74-
ClassFileCache() {
70+
ClassFileCache(ClassPath cp) {
7571
capacity = 877; // FIXME: may be worth setting size flexibly, or adjusting inside cache if too many evictions happen
7672
size = 0;
7773
sizeLimit = (capacity * 3) / 4;
@@ -82,22 +78,11 @@ public class ClassFileCache {
8278
vmSuppliedClassCache = new HashMap();
8379
preloadNames = new ArrayList();
8480
preloadLoaderIds = new ArrayList();
81+
classPath = cp;
8582
}
8683

8784
//~ Methods ------------------------------------------------------------------------------------------------------------------
8885

89-
static ClassFileCache getDefault() {
90-
if (defaultClassFileCache == null) {
91-
defaultClassFileCache = new ClassFileCache();
92-
}
93-
94-
return defaultClassFileCache;
95-
}
96-
97-
static void resetDefaultCache() {
98-
defaultClassFileCache = null;
99-
}
100-
10186
byte[] getClassFile(String name, String location) throws IOException {
10287
String nameAndLocation = (name + "#" + location).intern(); // NOI18N
10388
byte[] res;
@@ -246,10 +231,6 @@ private byte[] readClassFile(String name, String classFileLocation)
246231

247232
ZipFile zip = null;
248233

249-
if (classPath == null) {
250-
classPath = ClassRepository.getClassPath();
251-
}
252-
253234
if (classPath != null) {
254235
try {
255236
zip = classPath.getZipFileForName(classFileLocation);

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ protected boolean removeEldestEntry(Map.Entry eldest) {
169169

170170
//~ Instance fields ----------------------------------------------------------------------------------------------------------
171171

172+
private ClassFileCache classCache;
172173
private JarLRUCache zipFileNameToFile;
173174
private PathEntry[] paths;
174175
private boolean isCP; // True for a class path, false for a source path
@@ -197,6 +198,7 @@ public ClassPath(String classPath, boolean isCP) {
197198
}
198199

199200
paths = (PathEntry[])vec.toArray(new PathEntry[0]);
201+
classCache = new ClassFileCache(this);
200202
}
201203

202204
//~ Methods ------------------------------------------------------------------------------------------------------------------
@@ -217,7 +219,7 @@ public DynamicClassInfo getClassInfoForClass(String className, int classLoaderId
217219
return null;
218220
}
219221

220-
return new DynamicClassInfo(slashedClassName, classLoaderId, dirOrJar);
222+
return new DynamicClassInfo(this, slashedClassName, classLoaderId, dirOrJar);
221223
}
222224

223225
/** Requires "slashed" class name. Returns the directory or .jar name where this class is located, or null if not found. */
@@ -243,6 +245,22 @@ public ZipFile getZipFileForName(String zipFileName) throws IOException {
243245
return zip;
244246
}
245247

248+
void addVMSuppliedClassFile(String className, int classLoaderId, byte[] buf) {
249+
classCache.addVMSuppliedClassFile(className, classLoaderId, buf);
250+
}
251+
252+
int hasVMSuppliedClassFile(String className, int classLoaderId) {
253+
return classCache.hasVMSuppliedClassFile(className, classLoaderId);
254+
}
255+
256+
byte[] getClassFile(String name, String classFileLocation) throws IOException {
257+
return classCache.getClassFile(name, classFileLocation);
258+
}
259+
260+
void preloadBytecode(String name, String classFileLocation) {
261+
classCache.preloadBytecode(name, classFileLocation);
262+
}
263+
246264
public void close() {
247265
// close all ZipFiles in ClassPath, the files on disk would otherwise be locked
248266
// this is a bugfix for http://profiler.netbeans.org/issues/show_bug.cgi?id=61849

0 commit comments

Comments
 (0)