59
59
import java .util .concurrent .ConcurrentHashMap ;
60
60
import java .util .function .Supplier ;
61
61
62
+ import org .graalvm .collections .Pair ;
62
63
import org .junit .After ;
63
64
import org .junit .Assert ;
64
65
import org .junit .Before ;
@@ -395,7 +396,7 @@ protected LIRSuites createLIRSuites(OptionValues opts) {
395
396
return ret ;
396
397
}
397
398
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 );
399
400
400
401
/**
401
402
* Reset the entire {@linkplain #cache} of {@linkplain InstalledCode}. Additionally, invalidate
@@ -404,8 +405,8 @@ protected LIRSuites createLIRSuites(OptionValues opts) {
404
405
*/
405
406
@ BeforeClass
406
407
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 ();
409
410
}
410
411
cache .get ().clear ();
411
412
}
@@ -1133,11 +1134,14 @@ protected final InstalledCode getCode(final ResolvedJavaMethod installedCodeOwne
1133
1134
protected InstalledCode getCode (final ResolvedJavaMethod installedCodeOwner , StructuredGraph graph , boolean forceCompile , boolean installAsDefault , OptionValues options ) {
1134
1135
boolean useCache = !forceCompile && getArgumentToBind () == null ;
1135
1136
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 );
1138
1139
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 ();
1141
1145
} else {
1142
1146
tlCache .remove (installedCodeOwner );
1143
1147
}
@@ -1184,7 +1188,7 @@ protected InstalledCode getCode(final ResolvedJavaMethod installedCodeOwner, Str
1184
1188
}
1185
1189
1186
1190
if (useCache ) {
1187
- cache .get ().put (installedCodeOwner , installedCode );
1191
+ cache .get ().put (installedCodeOwner , Pair . create ( options , installedCode ) );
1188
1192
}
1189
1193
return installedCode ;
1190
1194
}
0 commit comments