Skip to content

Commit

Permalink
8328611: Thread safety issue in com.sun.tools.jdi.ReferenceTypeImpl::…
Browse files Browse the repository at this point in the history
…classObject

Reviewed-by: amenkov, sspitsyn
  • Loading branch information
plummercj committed May 30, 2024
1 parent 1d889e5 commit 922e312
Showing 1 changed file with 13 additions and 24 deletions.
37 changes: 13 additions & 24 deletions src/jdk.jdi/share/classes/com/sun/tools/jdi/ReferenceTypeImpl.java
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -182,8 +182,7 @@ public int compareTo(ReferenceType object) {

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
Expand All @@ -205,8 +204,7 @@ public String signature() {
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.
Expand All @@ -222,8 +220,7 @@ public String genericSignature() {

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;
Expand All @@ -239,9 +236,8 @@ public ModuleReference module() {
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());
Expand Down Expand Up @@ -694,17 +690,12 @@ public Map<Field,Value> getValues(List<? extends Field> theFields) {

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;
Expand Down Expand Up @@ -747,8 +738,7 @@ public List<String> sourcePaths(String stratumID)
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;
Expand Down Expand Up @@ -1065,13 +1055,12 @@ public byte[] constantPool() {
}
}

// 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) {
Expand Down

1 comment on commit 922e312

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.