From c83e0ac31beefa19739a4c33d88393dd5b68bca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Bulej?= Date: Thu, 5 Dec 2024 11:38:30 +0100 Subject: [PATCH] Comment on explicit closing of URLClassLoader instances Specifically, why we need it for benchmarks but not for plugins. --- .../main/java/org/renaissance/core/BenchmarkSuite.java | 4 ++++ .../src/main/java/org/renaissance/core/ModuleLoader.java | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/renaissance-core/src/main/java/org/renaissance/core/BenchmarkSuite.java b/renaissance-core/src/main/java/org/renaissance/core/BenchmarkSuite.java index 462a4d64..69588ffc 100644 --- a/renaissance-core/src/main/java/org/renaissance/core/BenchmarkSuite.java +++ b/renaissance-core/src/main/java/org/renaissance/core/BenchmarkSuite.java @@ -283,6 +283,10 @@ private static ClassLoader createClassLoaderFromPaths( throw new ExtensionException("malformed URL(s) in classpath specification"); } + // + // No need to explicitly close this URLClassLoader on exit, because it does not + // operate on files created by the harness that need to be deleted on exit. + // ClassLoader parent = ModuleLoader.class.getClassLoader(); return new URLClassLoader(classPathUrls, parent); } diff --git a/renaissance-core/src/main/java/org/renaissance/core/ModuleLoader.java b/renaissance-core/src/main/java/org/renaissance/core/ModuleLoader.java index 8f271083..b352a7af 100644 --- a/renaissance-core/src/main/java/org/renaissance/core/ModuleLoader.java +++ b/renaissance-core/src/main/java/org/renaissance/core/ModuleLoader.java @@ -158,6 +158,14 @@ ClassLoader createClassLoaderForModule(String name) throws ModuleLoadingExceptio name, filePaths.size(), makeClassPath(filePaths) )); + // + // Make sure to explicitly close this URLClassLoader on exit, because it operates + // on files created by the harness in the scratch directory hierarchy that need to + // be deleted on exit. Leaving the class loader open keeps the library JAR files + // open, preventing removal of the scratch directories. This is because on NFS, + // deleting an open file produces a NFS temporary file in the same directory, and + // on Windows, an open file cannot be deleted at all. + // return Cleaner.closeOnExit(new URLClassLoader(urls, thisClass.getClassLoader())); } catch (IOException e) {