Skip to content

Commit beaa5c0

Browse files
authored
Issue/85 (#86)
* Reenable test * Cleanup usage of raw types * Fix flaky test. Fix #85
1 parent e091bae commit beaa5c0

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/main/java/net/openhft/compiler/CachedCompiler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class CachedCompiler implements Closeable {
4242
private static final Logger LOG = LoggerFactory.getLogger(CachedCompiler.class);
4343
private static final PrintWriter DEFAULT_WRITER = new PrintWriter(System.err);
4444

45-
private final Map<ClassLoader, Map<String, Class>> loadedClassesMap = Collections.synchronizedMap(new WeakHashMap<>());
45+
private final Map<ClassLoader, Map<String, Class<?>>> loadedClassesMap = Collections.synchronizedMap(new WeakHashMap<>());
4646
private final Map<ClassLoader, MyJavaFileManager> fileManagerMap = Collections.synchronizedMap(new WeakHashMap<>());
4747

4848
@Nullable
@@ -130,12 +130,12 @@ public Class loadFromJava(@NotNull ClassLoader classLoader,
130130
@NotNull String className,
131131
@NotNull String javaCode,
132132
@Nullable PrintWriter writer) throws ClassNotFoundException {
133-
Class clazz = null;
134-
Map<String, Class> loadedClasses;
133+
Class<?> clazz = null;
134+
Map<String, Class<?>> loadedClasses;
135135
synchronized (loadedClassesMap) {
136136
loadedClasses = loadedClassesMap.get(classLoader);
137137
if (loadedClasses == null)
138-
loadedClassesMap.put(classLoader, loadedClasses = new LinkedHashMap<String, Class>());
138+
loadedClassesMap.put(classLoader, loadedClasses = new LinkedHashMap<>());
139139
else
140140
clazz = loadedClasses.get(className);
141141
}

src/main/java/net/openhft/compiler/MyJavaFileManager.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ class MyJavaFileManager implements JavaFileManager {
7171
this.fileManager = fileManager;
7272
}
7373

74-
public Iterable<Set<Location>> listLocationsForModules(final Location location) {
74+
// Apparently, this method might not be thread-safe.
75+
// See https://github.com/OpenHFT/Java-Runtime-Compiler/issues/85
76+
public synchronized Iterable<Set<Location>> listLocationsForModules(final Location location) {
7577
return invokeNamedMethodIfAvailable(location, "listLocationsForModules");
7678
}
7779

78-
public String inferModuleName(final Location location) {
80+
// Apparently, this method might not be thread-safe.
81+
// See https://github.com/OpenHFT/Java-Runtime-Compiler/issues/85
82+
public synchronized String inferModuleName(final Location location) {
7983
return invokeNamedMethodIfAvailable(location, "inferModuleName");
8084
}
8185

src/test/java/mytest/RuntimeCompileTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void outOfBounds() throws Exception {
4242
}
4343
}
4444

45-
@Ignore("see https://teamcity.chronicle.software/viewLog.html?buildId=639347&tab=buildResultsDiv&buildTypeId=OpenHFT_BuildAll_BuildJava11compileJava11")
45+
//@Ignore("see https://teamcity.chronicle.software/viewLog.html?buildId=639347&tab=buildResultsDiv&buildTypeId=OpenHFT_BuildAll_BuildJava11compileJava11")
4646
@Test
4747
public void testMultiThread() throws Exception {
4848
StringBuilder largeClass = new StringBuilder("package mytest;\n" +
@@ -64,6 +64,7 @@ public void testMultiThread() throws Exception {
6464
final ClassLoader cl = new URLClassLoader(new URL[0]);
6565
final CachedCompiler cc = new CachedCompiler(null, null);
6666
final int nThreads = Runtime.getRuntime().availableProcessors();
67+
System.out.println("nThreads = " + nThreads);
6768
final AtomicInteger started = new AtomicInteger(0);
6869
final ExecutorService executor = Executors.newFixedThreadPool(nThreads);
6970
final List<Future<?>> futures = new ArrayList<>();

0 commit comments

Comments
 (0)