From e7f3cc3cbc538468ebf64d6aaf229b4517db0586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20L=C3=A4ubrich?= Date: Fri, 27 Oct 2023 17:26:11 +0200 Subject: [PATCH] Add workaround for possible ApiTools leak 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 --- .../eclipse/tycho/apitools/ApiAnalysis.java | 3 +++ .../tycho/apitools/ApiAnalysisMojo.java | 26 ++++++++++++------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java index 0493e988b5..9a5fb0b1da 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysis.java @@ -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; @@ -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; } diff --git a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java index 566e32d9d5..8b0cc866f4 100644 --- a/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java +++ b/tycho-apitools-plugin/src/main/java/org/eclipse/tycho/apitools/ApiAnalysisMojo.java @@ -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()