8272158: SoftReference related bugs under memory pressure
Reviewed-by: jjg
This commit is contained in:
parent
7a5b37b8ca
commit
5db36cedc9
@ -270,9 +270,6 @@ public abstract class MemberSummaryBuilder extends AbstractMemberBuilder {
|
||||
new DocFinder.Input(utils, member));
|
||||
if (inheritedDoc.holder != null
|
||||
&& !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);
|
||||
}
|
||||
}
|
||||
|
@ -31,6 +31,7 @@ import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.lang.model.element.Element;
|
||||
import javax.lang.model.element.ExecutableElement;
|
||||
import javax.lang.model.element.ModuleElement;
|
||||
import javax.lang.model.element.PackageElement;
|
||||
import javax.lang.model.element.TypeElement;
|
||||
@ -87,7 +88,6 @@ public class CommentHelper {
|
||||
public final TreePath path;
|
||||
public final DocCommentTree dcTree;
|
||||
public final Element element;
|
||||
private Element overriddenElement;
|
||||
|
||||
public static final String SPACER = " ";
|
||||
|
||||
@ -106,13 +106,6 @@ public class CommentHelper {
|
||||
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) {
|
||||
switch (dtree.getKind()) {
|
||||
case AUTHOR:
|
||||
@ -679,22 +672,28 @@ public class CommentHelper {
|
||||
}
|
||||
|
||||
public DocTreePath getDocTreePath(DocTree dtree) {
|
||||
if (dcTree == null && overriddenElement != null) {
|
||||
// This is an inherited comment, return path from ancestor.
|
||||
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
|
||||
} else if (path == null || dcTree == null || dtree == null) {
|
||||
if (dcTree == null && element instanceof ExecutableElement ee) {
|
||||
return getInheritedDocTreePath(dtree, ee);
|
||||
}
|
||||
if (path == null || dcTree == null || dtree == null) {
|
||||
return null;
|
||||
}
|
||||
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.
|
||||
return configuration.utils.getCommentHelper(overriddenElement).getDocTreePath(dtree);
|
||||
return getInheritedDocTreePath(dtree, ee);
|
||||
}
|
||||
return dtPath;
|
||||
}
|
||||
|
||||
public Element getOverriddenElement() {
|
||||
return overriddenElement;
|
||||
private DocTreePath getInheritedDocTreePath(DocTree dtree, ExecutableElement ee) {
|
||||
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("::");
|
||||
sb.append(element);
|
||||
sb.append(", overriddenElement=");
|
||||
if (overriddenElement != null) {
|
||||
sb.append(overriddenElement.getEnclosingElement());
|
||||
sb.append("::");
|
||||
sb.append(overriddenElement);
|
||||
} else {
|
||||
sb.append("<none>");
|
||||
}
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
@ -947,13 +947,14 @@ public class VisibleMemberTable {
|
||||
Map<ExecutableElement, SoftReference<ImplementedMethods>> implementMethodsFinders = new HashMap<>();
|
||||
|
||||
private ImplementedMethods getImplementedMethodsFinder(ExecutableElement method) {
|
||||
SoftReference<ImplementedMethods> imf = implementMethodsFinders.get(method);
|
||||
// IMF does not exist or referent was gc'ed away ?
|
||||
if (imf == null || imf.get() == null) {
|
||||
imf = new SoftReference<>(new ImplementedMethods(method));
|
||||
implementMethodsFinders.put(method, imf);
|
||||
SoftReference<ImplementedMethods> ref = implementMethodsFinders.get(method);
|
||||
ImplementedMethods imf = ref == null ? null : ref.get();
|
||||
// imf does not exist or was gc'ed away?
|
||||
if (imf == null) {
|
||||
imf = new ImplementedMethods(method);
|
||||
implementMethodsFinders.put(method, new SoftReference<>(imf));
|
||||
}
|
||||
return imf.get();
|
||||
return imf;
|
||||
}
|
||||
|
||||
public List<ExecutableElement> getImplementedMethods(ExecutableElement method) {
|
||||
|
Loading…
Reference in New Issue
Block a user