diff --git a/java/src/main/java/ai/rapids/cudf/NativeDepsLoader.java b/java/src/main/java/ai/rapids/cudf/NativeDepsLoader.java
index 27322cca436..7ee590e3c82 100755
--- a/java/src/main/java/ai/rapids/cudf/NativeDepsLoader.java
+++ b/java/src/main/java/ai/rapids/cudf/NativeDepsLoader.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019-2022, NVIDIA CORPORATION.
+ * Copyright (c) 2019-2024, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public class NativeDepsLoader {
public static synchronized void loadNativeDeps() {
if (!loaded) {
try {
- loadNativeDeps(loadOrder);
+ loadNativeDeps(loadOrder, preserveDepsAfterLoad);
loaded = true;
} catch (Throwable t) {
log.error("Could not load cudf jni library...", t);
@@ -122,11 +122,53 @@ public static synchronized void loadNativeDeps() {
* @throws IOException on any error trying to load the libraries.
*/
public static void loadNativeDeps(String[] loadOrder) throws IOException {
+ loadNativeDeps(loadOrder, preserveDepsAfterLoad);
+ }
+
+ /**
+ * Allows other libraries to reuse the same native deps loading logic. Libraries will be searched
+ * for under ${os.arch}/${os.name}/ in the class path using the class loader for this class.
+ *
+ * Because this just loads the libraries and loading the libraries themselves needs to be a
+ * singleton operation it is recommended that any library using this provide their own wrapper
+ * function similar to
+ *
+ * private static boolean loaded = false; + * static synchronized void loadNativeDeps() { + * if (!loaded) { + * try { + * // If you also depend on the cudf liobrary being loaded, be sure it is loaded + * // first + * ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(); + * ai.rapids.cudf.NativeDepsLoader.loadNativeDeps(new String[]{...}); + * loaded = true; + * } catch (Throwable t) { + * log.error("Could not load ...", t); + * } + * } + * } + *+ * This function should be called from the static initialization block of any class that uses + * JNI. For example + *
+ * public class UsesJNI { + * static { + * MyNativeDepsLoader.loadNativeDeps(); + * } + * } + *+ * @param loadOrder the base name of the libraries. For example libfoo.so would be passed in as + * "foo". The libraries are loaded in the order provided. + * @param preserveDeps if false the dependencies will be deleted immediately after loading + * rather than on exit. + * @throws IOException on any error trying to load the libraries. + */ + public static void loadNativeDeps(String[] loadOrder, boolean preserveDeps) throws IOException { String os = System.getProperty("os.name"); String arch = System.getProperty("os.arch"); for (String toLoad : loadOrder) { - loadDep(os, arch, toLoad); + loadDep(os, arch, toLoad, preserveDeps); } } @@ -134,9 +176,11 @@ public static void loadNativeDeps(String[] loadOrder) throws IOException { * Load native dependencies in stages, where the dependency libraries in each stage * are loaded only after all libraries in earlier stages have completed loading. * @param loadOrder array of stages with an array of dependency library names in each stage + * @param preserveDeps if false the dependencies will be deleted immediately after loading + * rather than on exit. * @throws IOException on any error trying to load the libraries */ - private static void loadNativeDeps(String[][] loadOrder) throws IOException { + private static void loadNativeDeps(String[][] loadOrder, boolean preserveDeps) throws IOException { String os = System.getProperty("os.name"); String arch = System.getProperty("os.arch"); @@ -161,7 +205,7 @@ private static void loadNativeDeps(String[][] loadOrder) throws IOException { // Submit all dependencies in the stage to be loaded in parallel loadCompletionFutures.clear(); for (Future