Skip to content
Permalink
Browse files
8272158: SoftReference related bugs under memory pressure
Reviewed-by: jjg
  • Loading branch information
hns committed Aug 16, 2021
1 parent 7a5b37b commit 5db36cedc91d0954ececd309a5f8f59ea828f6c1
@@ -270,9 +270,6 @@ private void buildSummary(MemberSummaryWriter writer,
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.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 final TreePath path;
public final DocCommentTree dcTree;
public final Element element;
private Element overriddenElement;

public static final String SPACER = " ";

@@ -106,13 +106,6 @@ public CommentHelper(BaseConfiguration configuration, Element element, TreePath
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 ReferenceTree getType(DocTree dtree) {
}

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 String toString() {
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 @@ private void computeVisibleProperties(LocalMemberTable lmt) {
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) {

1 comment on commit 5db36ce

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 5db36ce Aug 16, 2021

Please sign in to comment.