Skip to content

Commit 5db36ce

Browse files
committedAug 16, 2021
8272158: SoftReference related bugs under memory pressure
Reviewed-by: jjg
1 parent 7a5b37b commit 5db36ce

File tree

3 files changed

+22
-33
lines changed

3 files changed

+22
-33
lines changed
 

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/builders/MemberSummaryBuilder.java

-3
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ private void buildSummary(MemberSummaryWriter writer,
270270
new DocFinder.Input(utils, member));
271271
if (inheritedDoc.holder != null
272272
&& !utils.getFirstSentenceTrees(inheritedDoc.holder).isEmpty()) {
273-
// let the comment helper know of the overridden element
274-
CommentHelper ch = utils.getCommentHelper(member);
275-
ch.setOverrideElement(inheritedDoc.holder);
276273
firstSentenceTags = utils.getFirstSentenceTrees(inheritedDoc.holder);
277274
}
278275
}

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/CommentHelper.java

+15-24
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.stream.Collectors;
3232

3333
import javax.lang.model.element.Element;
34+
import javax.lang.model.element.ExecutableElement;
3435
import javax.lang.model.element.ModuleElement;
3536
import javax.lang.model.element.PackageElement;
3637
import javax.lang.model.element.TypeElement;
@@ -87,7 +88,6 @@ public class CommentHelper {
8788
public final TreePath path;
8889
public final DocCommentTree dcTree;
8990
public final Element element;
90-
private Element overriddenElement;
9191

9292
public static final String SPACER = " ";
9393

@@ -106,13 +106,6 @@ public CommentHelper(BaseConfiguration configuration, Element element, TreePath
106106
this.dcTree = dcTree;
107107
}
108108

109-
public void setOverrideElement(Element ove) {
110-
if (this.element == ove) {
111-
throw new AssertionError("cannot set given element as overridden element");
112-
}
113-
overriddenElement = ove;
114-
}
115-
116109
public String getTagName(DocTree dtree) {
117110
switch (dtree.getKind()) {
118111
case AUTHOR:
@@ -679,22 +672,28 @@ public ReferenceTree getType(DocTree dtree) {
679672
}
680673

681674
public DocTreePath getDocTreePath(DocTree dtree) {
682-
if (dcTree == null && overriddenElement != null) {
683-
// This is an inherited comment, return path from ancestor.
684-
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
685-
} else if (path == null || dcTree == null || dtree == null) {
675+
if (dcTree == null && element instanceof ExecutableElement ee) {
676+
return getInheritedDocTreePath(dtree, ee);
677+
}
678+
if (path == null || dcTree == null || dtree == null) {
686679
return null;
687680
}
688681
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
689-
if (dtPath == null && overriddenElement != null) {
682+
if (dtPath == null && element instanceof ExecutableElement ee) {
690683
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
691-
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
684+
return getInheritedDocTreePath(dtree, ee);
692685
}
693686
return dtPath;
694687
}
695688

696-
public Element getOverriddenElement() {
697-
return overriddenElement;
689+
private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) {
690+
Utils utils = configuration.utils;
691+
DocFinder.Output inheritedDoc =
692+
DocFinder.search(configuration,
693+
new DocFinder.Input(utils, ee));
694+
return inheritedDoc == null || inheritedDoc.holder == ee
695+
? null
696+
: utils.getCommentHelper(inheritedDoc.holder).getDocTreePath(dtree);
698697
}
699698

700699
/**
@@ -708,14 +707,6 @@ public String toString() {
708707
sb.append(element.getEnclosingElement());
709708
sb.append("::");
710709
sb.append(element);
711-
sb.append(", overriddenElement=");
712-
if (overriddenElement != null) {
713-
sb.append(overriddenElement.getEnclosingElement());
714-
sb.append("::");
715-
sb.append(overriddenElement);
716-
} else {
717-
sb.append("<none>");
718-
}
719710
sb.append('}');
720711
return sb.toString();
721712
}

‎src/jdk.javadoc/share/classes/jdk/javadoc/internal/doclets/toolkit/util/VisibleMemberTable.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -947,13 +947,14 @@ private void computeVisibleProperties(LocalMemberTable lmt) {
947947
Map<ExecutableElement, SoftReference<ImplementedMethods>> implementMethodsFinders = new HashMap<>();
948948

949949
private ImplementedMethods getImplementedMethodsFinder(ExecutableElement method) {
950-
SoftReference<ImplementedMethods> imf = implementMethodsFinders.get(method);
951-
// IMF does not exist or referent was gc'ed away ?
952-
if (imf == null || imf.get() == null) {
953-
imf = new SoftReference<>(new ImplementedMethods(method));
954-
implementMethodsFinders.put(method, imf);
950+
SoftReference<ImplementedMethods> ref = implementMethodsFinders.get(method);
951+
ImplementedMethods imf = ref == null ? null : ref.get();
952+
// imf does not exist or was gc'ed away?
953+
if (imf == null) {
954+
imf = new ImplementedMethods(method);
955+
implementMethodsFinders.put(method, new SoftReference<>(imf));
955956
}
956-
return imf.get();
957+
return imf;
957958
}
958959

959960
public List<ExecutableElement> getImplementedMethods(ExecutableElement method) {

0 commit comments

Comments
 (0)
Please sign in to comment.