Skip to content

Commit

Permalink
Add workaround for possible ApiTools leak
Browse files Browse the repository at this point in the history
Currently PDEState.querySystemPackages leads to multiple
JRTUtil.getJrtSystem calls that get cached forever.

This adds the following workaround:
1) make sure only one analysis run in parallel
2) clear the cache after the analysis runs
  • Loading branch information
laeubi committed Oct 27, 2023
1 parent 712efe1 commit e7f3cc3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.internal.compiler.util.JRTUtil;
import org.eclipse.jdt.internal.launching.LaunchingPlugin;
import org.eclipse.osgi.service.resolver.ResolverError;
import org.eclipse.pde.api.tools.internal.BundleListTargetLocation;
Expand Down Expand Up @@ -165,6 +166,8 @@ public void aboutToRun(IJobChangeEvent event) {
analyzer.dispose();
ResourcesPlugin.getWorkspace().save(true, new NullProgressMonitor());
}
JRTUtil.reset(); // reclaim space due to loaded multiple JRTUtil should better be fixed to not
// use that much space
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,22 @@ public void execute() throws MojoExecutionException, MojoFailureException {
throw new MojoFailureException("Start Framework failed!", e);
}
ApiAnalysisResult analysisResult;
try {
ApiAnalysis analysis = new ApiAnalysis(baselineBundles, dependencyBundles,
project.getName(), fileToPath(apiFilter), fileToPath(apiPreferences),
fileToPath(project.getBasedir()), debug, fileToPath(project.getArtifact().getFile()),
stringToPath(project.getBuild().getOutputDirectory()));
analysisResult = eclipseFramework.execute(analysis);
} catch (Exception e) {
throw new MojoExecutionException("Execute ApiApplication failed", e);
} finally {
eclipseFramework.close();
synchronized (ApiAnalysisMojo.class) {
// due to
// https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/issues/3885#note_1266412 we
// can not execute more than one analysis without excessive memory consumption
// unless this is fixed it is safer to only run one analysis at a time
try {
ApiAnalysis analysis = new ApiAnalysis(baselineBundles, dependencyBundles, project.getName(),
fileToPath(apiFilter), fileToPath(apiPreferences), fileToPath(project.getBasedir()), debug,
fileToPath(project.getArtifact().getFile()),
stringToPath(project.getBuild().getOutputDirectory()));
analysisResult = eclipseFramework.execute(analysis);
} catch (Exception e) {
throw new MojoExecutionException("Execute ApiApplication failed", e);
} finally {
eclipseFramework.close();
}
}
log.info("API Analysis finished in " + time(start) + ".");
analysisResult.resolveErrors()
Expand Down

0 comments on commit e7f3cc3

Please sign in to comment.