8302822: Method/Field/Constructor/RecordComponent::getGenericInfo() is not thread safe

Reviewed-by: stsypanov, redestad
This commit is contained in:
Chen Liang 2023-06-01 15:31:51 +00:00 committed by Claes Redestad
parent c6f20db945
commit be36096a19
4 changed files with 16 additions and 8 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -82,7 +82,7 @@ public final class Method extends Executable {
// Generics and annotations support
private final transient String signature;
// generic info repository; lazily initialized
private transient MethodRepository genericInfo;
private transient volatile MethodRepository genericInfo;
private final byte[] annotations;
private final byte[] parameterAnnotations;
private final byte[] annotationDefault;
@ -108,11 +108,13 @@ public final class Method extends Executable {
// Accessor for generic info repository
@Override
MethodRepository getGenericInfo() {
var genericInfo = this.genericInfo;
// lazily initialize repository if necessary
if (genericInfo == null) {
// create and cache generic info repository
genericInfo = MethodRepository.make(getGenericSignature(),
getFactory());
this.genericInfo = genericInfo;
}
return genericInfo; //return cached repository
}