Skip to content

Commit fd9f9a1

Browse files
committed
compiler test: invalidate cache on other options, contributed by [email protected]
1 parent 1a5e49e commit fd9f9a1

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/src/jdk.graal.compiler.test/src/jdk/graal/compiler/core/test/GraalCompilerTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import java.util.concurrent.ConcurrentHashMap;
6060
import java.util.function.Supplier;
6161

62+
import org.graalvm.collections.Pair;
6263
import org.junit.After;
6364
import org.junit.Assert;
6465
import org.junit.Before;
@@ -395,7 +396,7 @@ protected LIRSuites createLIRSuites(OptionValues opts) {
395396
return ret;
396397
}
397398

398-
private static final ThreadLocal<HashMap<ResolvedJavaMethod, InstalledCode>> cache = ThreadLocal.withInitial(HashMap::new);
399+
private static final ThreadLocal<HashMap<ResolvedJavaMethod, Pair<OptionValues, InstalledCode>>> cache = ThreadLocal.withInitial(HashMap::new);
399400

400401
/**
401402
* Reset the entire {@linkplain #cache} of {@linkplain InstalledCode}. Additionally, invalidate
@@ -404,8 +405,8 @@ protected LIRSuites createLIRSuites(OptionValues opts) {
404405
*/
405406
@BeforeClass
406407
public static void resetCodeCache() {
407-
for (InstalledCode code : cache.get().values()) {
408-
code.invalidate();
408+
for (Pair<OptionValues, InstalledCode> code : cache.get().values()) {
409+
code.getRight().invalidate();
409410
}
410411
cache.get().clear();
411412
}
@@ -1133,11 +1134,14 @@ protected final InstalledCode getCode(final ResolvedJavaMethod installedCodeOwne
11331134
protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, StructuredGraph graph, boolean forceCompile, boolean installAsDefault, OptionValues options) {
11341135
boolean useCache = !forceCompile && getArgumentToBind() == null;
11351136
if (useCache && graph == null) {
1136-
HashMap<ResolvedJavaMethod, InstalledCode> tlCache = cache.get();
1137-
InstalledCode cached = tlCache.get(installedCodeOwner);
1137+
HashMap<ResolvedJavaMethod, Pair<OptionValues, InstalledCode>> tlCache = cache.get();
1138+
Pair<OptionValues, InstalledCode> cached = tlCache.get(installedCodeOwner);
11381139
if (cached != null) {
1139-
if (cached.isValid()) {
1140-
return cached;
1140+
// Reuse the cached code is the it's still valid and the same options were used for
1141+
// the compilation.
1142+
if (cached.getRight().isValid() && options.getMap().equals(cached.getLeft().getMap())) {
1143+
GraalError.unimplemented("map value compare");
1144+
return cached.getRight();
11411145
} else {
11421146
tlCache.remove(installedCodeOwner);
11431147
}
@@ -1184,7 +1188,7 @@ protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, Str
11841188
}
11851189

11861190
if (useCache) {
1187-
cache.get().put(installedCodeOwner, installedCode);
1191+
cache.get().put(installedCodeOwner, Pair.create(options, installedCode));
11881192
}
11891193
return installedCode;
11901194
}

0 commit comments

Comments
 (0)