Skip to content

Commit 1377605

Browse files
committed
[GR-36579] Temporary workaround for GR-33896 until GR-36494 is merged
PullRequest: graal/10895
2 parents a63cf8a + 7cd0caf commit 1377605

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,27 @@ private Class<?> findLoadedClass0(String name) {
208208
* boot class loader.
209209
*/
210210
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.NewInstance, declClass = ConcurrentHashMap.class)//
211-
ConcurrentHashMap<?, ?> classLoaderValueMap;
211+
volatile ConcurrentHashMap<?, ?> classLoaderValueMap;
212+
213+
/**
214+
* This substitution is a temporary workaround for GR-33896 until GR-36494 is merged.
215+
*/
216+
@Substitute //
217+
@TargetElement(onlyWith = JDK17OrLater.class) //
218+
@SuppressWarnings({"unused"}) //
219+
ConcurrentHashMap<?, ?> createOrGetClassLoaderValueMap() {
220+
ConcurrentHashMap<?, ?> result = classLoaderValueMap;
221+
if (result == null) {
222+
// Checkstyle: allow synchronization
223+
synchronized (this) {
224+
result = classLoaderValueMap;
225+
if (result == null) {
226+
classLoaderValueMap = result = new ConcurrentHashMap<>();
227+
}
228+
}
229+
}
230+
return result;
231+
}
212232

213233
@Alias
214234
native Stream<Package> packages();

0 commit comments

Comments
 (0)