From 922e312b0ab3ac54979ffdc53a8d8338e52234df Mon Sep 17 00:00:00 2001 From: Chris Plummer Date: Thu, 30 May 2024 18:03:44 +0000 Subject: [PATCH] 8328611: Thread safety issue in com.sun.tools.jdi.ReferenceTypeImpl::classObject Reviewed-by: amenkov, sspitsyn --- .../com/sun/tools/jdi/ReferenceTypeImpl.java | 37 +++++++------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java b/src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java index 9c60f7a3465..10be49c53c9 100644 --- a/src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java +++ b/src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 1998, 2024, 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 @@ -182,8 +182,7 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp public String signature() { if (signature == null) { - // Does not need synchronization, since worst-case - // static info is fetched twice + // Does not need synchronization. Worst case is static info is fetched twice. if (vm.canGet1_5LanguageFeatures()) { /* * we might as well get both the signature and the @@ -205,8 +204,7 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp public String genericSignature() { // This gets both the signature and the generic signature if (vm.canGet1_5LanguageFeatures() && !genericSignatureGotten) { - // Does not need synchronization, since worst-case - // static info is fetched twice + // Does not need synchronization. Worst case is static info is fetched twice. JDWP.ReferenceType.SignatureWithGeneric result; try { result = JDWP.ReferenceType.SignatureWithGeneric. @@ -222,8 +220,7 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp public ClassLoaderReference classLoader() { if (!isClassLoaderCached) { - // Does not need synchronization, since worst-case - // static info is fetched twice + // Does not need synchronization. Worst case is static info is fetched twice. try { classLoader = JDWP.ReferenceType.ClassLoader. process(vm, this).classLoader; @@ -239,9 +236,8 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp if (module != null) { return module; } - // Does not need synchronization, since worst-case - // static info is fetched twice try { + // Does not need synchronization. Worst case is static info is fetched twice. ModuleReferenceImpl m = JDWP.ReferenceType.Module. process(vm, this).module; module = vm.getModule(m.ref()); @@ -694,17 +690,12 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp public ClassObjectReference classObject() { if (classObject == null) { - // Are classObjects unique for an Object, or - // created each time? Is this spec'ed? - synchronized(this) { - if (classObject == null) { - try { - classObject = JDWP.ReferenceType.ClassObject. - process(vm, this).classObject; - } catch (JDWPException exc) { - throw exc.toJDIException(); - } - } + // Does not need synchronization. Worst case is static info is fetched twice. + try { + classObject = JDWP.ReferenceType.ClassObject. + process(vm, this).classObject; + } catch (JDWPException exc) { + throw exc.toJDIException(); } } return classObject; @@ -747,8 +738,7 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp String baseSourceName() throws AbsentInformationException { String bsn = baseSourceName; if (bsn == null) { - // Does not need synchronization, since worst-case - // static info is fetched twice + // Does not need synchronization. Worst case is static info is fetched twice. try { bsn = JDWP.ReferenceType.SourceFile. process(vm, this).sourceFile; @@ -1065,13 +1055,12 @@ public abstract class ReferenceTypeImpl extends TypeImpl implements ReferenceTyp } } - // Does not need synchronization, since worst-case - // static info is fetched twice void getModifiers() { if (modifiers != -1) { return; } try { + // Does not need synchronization. Worst case is static info is fetched twice. modifiers = JDWP.ReferenceType.Modifiers. process(vm, this).modBits; } catch (JDWPException exc) {