Skip to content

Commit

Permalink
Attempt to cleanup context upon usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Sep 23, 2024
1 parent 578c052 commit df73b2d
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.javac/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-23">
<attributes>
<attribute name="module" value="true"/>
<attribute name="add-exports" value="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED:jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets.snippet=ALL-UNNAMED:jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets=ALL-UNNAMED"/>
<attribute name="add-exports" value="jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED:jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED:jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets.snippet=ALL-UNNAMED:jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets=ALL-UNNAMED"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="bin"/>
Expand Down
2 changes: 2 additions & 0 deletions org.eclipse.jdt.core.javac/META-INF/p2.inf
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ jdk.compiler/com.sun.tools.javac.processing=ALL-UNNAMED\n\
jdk.compiler/com.sun.tools.javac.jvm=ALL-UNNAMED\n\
--add-opens\n\
jdk.compiler/com.sun.tools.javac.model=ALL-UNNAMED\n\
--add-opens\n\
jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED\n\
-DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver\n\
-DAbstractImageBuilder.compilerFactory=org.eclipse.jdt.internal.javac.JavacCompilerFactory\n\
-DCompilationUnit.DOM_BASED_OPERATIONS=true\n\
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ private void resolve() {
// symbols not already present: analyze
try {
this.javac.analyze();
JavacCompilationUnitResolver.cleanUp(this.context);
} catch (IOException e) {
ILog.get().error(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import com.sun.tools.javac.parser.ScannerFactory;
import com.sun.tools.javac.parser.Tokens.Comment.CommentStyle;
import com.sun.tools.javac.parser.Tokens.TokenKind;
import com.sun.tools.javac.platform.PlatformDescription;
import com.sun.tools.javac.tree.JCTree.JCClassDecl;
import com.sun.tools.javac.tree.JCTree.JCCompilationUnit;
import com.sun.tools.javac.util.Context;
Expand Down Expand Up @@ -628,6 +629,7 @@ public Void visitClass(ClassTree node, Void p) {
if ((flags & ICompilationUnit.FORCE_PROBLEM_DETECTION) != 0
|| (aptPath != null && aptPath.iterator().hasNext())) {
task.analyze();
cleanUp(context);
}

Throwable cachedThrown = null;
Expand Down Expand Up @@ -718,6 +720,8 @@ public void postVisit(ASTNode node) {
JavacBindingResolver resolver = new JavacBindingResolver(javaProject, task, context, converter, workingCopyOwner);
resolver.isRecoveringBindings = (flags & ICompilationUnit.ENABLE_BINDINGS_RECOVERY) != 0;
ast.setBindingResolver(resolver);
} else {
cleanUp(context);
}
//
ast.setOriginalModificationCount(ast.modificationCount()); // "un-dirty" AST so Rewrite can process it
Expand Down Expand Up @@ -1012,7 +1016,30 @@ private boolean configureAPIfNecessary(JavacFileManager fileManager) {
}
}
}

return false;
}

/**
* Cleanup a context from elements that become useless upon analysis.
* Elements that can still be useful (eg names, types) for binding resolution must
* be retained.
* @param context the context to clean up
*/
public static void cleanUp(Context context) {
// Some ZipFileSystem instances are still retained, while they don't seem
// useful at that stage. They're references by classSymbol->classfile (which
// is a ZipPath) -> ZipFileSystem -> cen (the bytes we don't care about anymore,
// but that we cannot dispose/free).
// Maybe this can be fixed in JDK cleaning the "cen" on ZipFileSystem#close ?
// Maybe we can try to get rid of all classfile field values on Symbols, or replace them by empty variants?
//
try {
PlatformDescription platform = context.get(PlatformDescription.class);
if (platform != null) platform.close();
JavaFileManager fileManager = context.get(JavaFileManager.class);
if (fileManager != null) fileManager.close();
} catch (IOException ex) {
ILog.get().error(ex.getMessage(), ex);
}
}
}
2 changes: 1 addition & 1 deletion org.eclipse.jdt.core.tests.javac/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
</plugins>
</build>
<properties>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=21 -DCompilationUnit.DOM_BASED_OPERATIONS=true -DSourceIndexer.DOM_BASED_INDEXER=true -DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver -DAbstractImageBuilder.compiler=org.eclipse.jdt.internal.javac.JavacCompiler --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets.snippet=ALL-UNNAMED --add-opens jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets=ALL-UNNAMED</tycho.surefire.argLine>
<tycho.surefire.argLine>--add-modules ALL-SYSTEM -Dcompliance=21 -DCompilationUnit.DOM_BASED_OPERATIONS=true -DSourceIndexer.DOM_BASED_INDEXER=true -DICompilationUnitResolver=org.eclipse.jdt.core.dom.JavacCompilationUnitResolver -DAbstractImageBuilder.compiler=org.eclipse.jdt.internal.javac.JavacCompiler --add-opens jdk.compiler/com.sun.tools.javac.main=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.comp=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED --add-opens jdk.compiler/com.sun.tools.javac.platform=ALL-UNNAMED --add-opens jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets.snippet=ALL-UNNAMED --add-opens jdk.javadoc/jdk.javadoc.internal.doclets.formats.html.taglets=ALL-UNNAMED</tycho.surefire.argLine>
</properties>
</profile>
</profiles>
Expand Down

0 comments on commit df73b2d

Please sign in to comment.