8272158: SoftReference related bugs under memory pressure

Reviewed-by: jjg
This commit is contained in:
Hannes Wallnöfer 2021-08-16 07:46:29 +00:00
parent 7a5b37b8ca
commit 5db36cedc9
3 changed files with 22 additions and 33 deletions

View File

@ -270,9 +270,6 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
new DocFinder.Input(utils, member)); new DocFinder.Input(utils, member));
if (inheritedDoc.holder != null if (inheritedDoc.holder != null
&& !utils.getFirstSentenceTrees(inheritedDoc.holder).isEmpty()) { && !utils.getFirstSentenceTrees(inheritedDoc.holder).isEmpty()) {
// let the comment helper know of the overridden element
CommentHelper ch = utils.getCommentHelper(member);
ch.setOverrideElement(inheritedDoc.holder);
firstSentenceTags = utils.getFirstSentenceTrees(inheritedDoc.holder); firstSentenceTags = utils.getFirstSentenceTrees(inheritedDoc.holder);
} }
} }

View File

@ -31,6 +31,7 @@ import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.lang.model.element.Element; import javax.lang.model.element.Element;
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.ModuleElement; import javax.lang.model.element.ModuleElement;
import javax.lang.model.element.PackageElement; import javax.lang.model.element.PackageElement;
import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeElement;
@ -87,7 +88,6 @@ public class CommentHelper {
public final TreePath path; public final TreePath path;
public final DocCommentTree dcTree; public final DocCommentTree dcTree;
public final Element element; public final Element element;
private Element overriddenElement;
public static final String SPACER = " "; public static final String SPACER = " ";
@ -106,13 +106,6 @@ public class CommentHelper {
this.dcTree = dcTree; this.dcTree = dcTree;
} }
public void setOverrideElement(Element ove) {
if (this.element == ove) {
throw new AssertionError("cannot set given element as overridden element");
}
overriddenElement = ove;
}
public String getTagName(DocTree dtree) { public String getTagName(DocTree dtree) {
switch (dtree.getKind()) { switch (dtree.getKind()) {
case AUTHOR: case AUTHOR:
@ -679,22 +672,28 @@ public class CommentHelper {
} }
public DocTreePath getDocTreePath(DocTree dtree) { public DocTreePath getDocTreePath(DocTree dtree) {
if (dcTree == null && overriddenElement != null) { if (dcTree == null && element instanceof ExecutableElement ee) {
// This is an inherited comment, return path from ancestor. return getInheritedDocTreePath(dtree, ee);
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree); }
} else if (path == null || dcTree == null || dtree == null) { if (path == null || dcTree == null || dtree == null) {
return null; return null;
} }
DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree); DocTreePath dtPath = DocTreePath.getPath(path, dcTree, dtree);
if (dtPath == null && overriddenElement != null) { if (dtPath == null && element instanceof ExecutableElement ee) {
// The overriding element has a doc tree, but it doesn't contain what we're looking for. // The overriding element has a doc tree, but it doesn't contain what we're looking for.
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree); return getInheritedDocTreePath(dtree, ee);
} }
return dtPath; return dtPath;
} }
public Element getOverriddenElement() { private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) {
return overriddenElement; Utils utils = configuration.utils;
DocFinder.Output inheritedDoc =
DocFinder.search(configuration,
new DocFinder.Input(utils, ee));
return inheritedDoc == null || inheritedDoc.holder == ee
? null
: utils.getCommentHelper(inheritedDoc.holder).getDocTreePath(dtree);
} }
/** /**
@ -708,14 +707,6 @@ public class CommentHelper {
sb.append(element.getEnclosingElement()); sb.append(element.getEnclosingElement());
sb.append("::"); sb.append("::");
sb.append(element); sb.append(element);
sb.append(", overriddenElement=");
if (overriddenElement != null) {
sb.append(overriddenElement.getEnclosingElement());
sb.append("::");
sb.append(overriddenElement);
} else {
sb.append("<none>");
}
sb.append('}'); sb.append('}');
return sb.toString(); return sb.toString();
} }

View File

@ -947,13 +947,14 @@ public class VisibleMemberTable {
Map<ExecutableElement, SoftReference<ImplementedMethods>> implementMethodsFinders = new HashMap<>(); Map<ExecutableElement, SoftReference<ImplementedMethods>> implementMethodsFinders = new HashMap<>();
private ImplementedMethods getImplementedMethodsFinder(ExecutableElement method) { private ImplementedMethods getImplementedMethodsFinder(ExecutableElement method) {
SoftReference<ImplementedMethods> imf = implementMethodsFinders.get(method); SoftReference<ImplementedMethods> ref = implementMethodsFinders.get(method);
// IMF does not exist or referent was gc'ed away ? ImplementedMethods imf = ref == null ? null : ref.get();
if (imf == null || imf.get() == null) { // imf does not exist or was gc'ed away?
imf = new SoftReference<>(new ImplementedMethods(method)); if (imf == null) {
implementMethodsFinders.put(method, imf); imf = new ImplementedMethods(method);
implementMethodsFinders.put(method, new SoftReference<>(imf));
} }
return imf.get(); return imf;
} }
public List<ExecutableElement> getImplementedMethods(ExecutableElement method) { public List<ExecutableElement> getImplementedMethods(ExecutableElement method) {