Skip to content

Commit 7ddd316

Browse files
committed
Added more detail about where libraries are loaded from to DumpInfo.
1 parent ddb9385 commit 7ddd316

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

jostle/src/main/java/org/openssl/jostle/Loader.java

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public class Loader
8888
private static List<String> loadedLibs = new ArrayList<>();
8989
private static boolean extractOpenSSL = true;
9090
private static boolean fixedInstallDir = false;
91+
private static String installDir;
9192

9293
public static void load()
9394
{
@@ -123,11 +124,11 @@ private static void loadImpl()
123124
extractOpenSSL = Properties.isOverrideSet(OPENSSL_EXTRACT, true);
124125
interfaceResolutionStrategy = Strings.toLowerCase(Properties.getPropertyValue(LOADER_INTERFACE, "auto"));
125126

126-
String libDir = Properties.getPropertyValue(LIB_INSTALL_DIR);
127-
if (libDir == null)
127+
installDir = Properties.getPropertyValue(LIB_INSTALL_DIR);
128+
if (installDir == null)
128129
{
129130
L.fine(String.format("%s is not set so using java.io.tmpdir property", LIB_INSTALL_DIR));
130-
libDir = Properties.getPropertyValue("java.io.tmpdir");
131+
installDir = Properties.getPropertyValue("java.io.tmpdir");
131132
} else
132133
{
133134
fixedInstallDir = true;
@@ -136,7 +137,7 @@ private static void loadImpl()
136137
//
137138
// Unable to resolve a temporary directory root!
138139
//
139-
if (libDir == null)
140+
if (installDir == null)
140141
{
141142
throw new IOException("Unable to resolve a temporary directory");
142143
}
@@ -282,7 +283,7 @@ private static void loadImpl()
282283
{
283284
String version = JostleProvider.INFO.substring(JostleProvider.INFO.lastIndexOf('v') + 1);
284285

285-
installRootDir = LoaderUtils.createVersionedTempDir(libDir, version);
286+
installRootDir = LoaderUtils.createVersionedTempDir(installDir, version);
286287
} else
287288
{
288289
installRootDir = LoaderUtils.createTempDir("jostle");
@@ -383,7 +384,8 @@ private static void extractAndLoad(File installRootDir, String libRootInJar, Ext
383384
throws Exception
384385
{
385386
String pathInJar = libRootInJar + "/" + extraction.name;
386-
File libFile = LoaderUtils.extractFromClasspath(installRootDir, pathInJar, extraction.name);
387+
String[] sources = new String[2];
388+
File libFile = LoaderUtils.extractFromClasspath(installRootDir, pathInJar, extraction.name, sources);
387389
if (libFile == null)
388390
{
389391
throw new IOException(String.format("extraction file '%s' not found", pathInJar));
@@ -392,7 +394,16 @@ private static void extractAndLoad(File installRootDir, String libRootInJar, Ext
392394
L.fine(String.format("Wrote %s to %s, %d bytes", extraction.name, libFile.getAbsoluteFile(), libFile.length()));
393395
}
394396
System.load(libFile.getAbsolutePath());
395-
loadedLibs.add("Extracted: " + pathInJar);
397+
398+
399+
if (sources[0] != null && sources[1] != null)
400+
{
401+
loadedLibs.add("Loaded: " + sources[1]);
402+
loadedLibs.add(" Compared to: " + sources[0]);
403+
} else
404+
{
405+
loadedLibs.add("Extracted: " + sources[0]);
406+
}
396407
}
397408

398409
/**
@@ -463,6 +474,15 @@ public static boolean isFFI()
463474
return Extractions.Type.FFI == interfaceType;
464475
}
465476

477+
public static String getInstallDir()
478+
{
479+
return installDir;
480+
}
481+
482+
public static boolean isFixedInstallDir() {
483+
return fixedInstallDir;
484+
}
485+
466486
private static class Extractions
467487
{
468488

jostle/src/main/java/org/openssl/jostle/LoaderUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,14 @@ public File run()
189189
}
190190
}
191191

192-
static File extractFromClasspath(File tmpDir, String pathInJar, String name)
192+
static File extractFromClasspath(File tmpDir, String pathInJar, String name, String[] sources)
193193
throws Exception
194194
{
195195
return AccessController.doPrivileged(new PrivilegedAction<File>()
196196
{
197197
public File run()
198198
{
199+
sources[0] = pathInJar;
199200
InputStream in = Loader.class.getResourceAsStream(pathInJar);
200201
if (in == null)
201202
{
@@ -218,6 +219,7 @@ public File run()
218219
{
219220
if (isContentSame(fin, in))
220221
{
222+
sources[1] = savedFile.getAbsolutePath();
221223
return savedFile;
222224
}
223225

jostle/src/main/java/org/openssl/jostle/util/DumpInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ public static void main(String[] args) throws Exception
5757
System.out.println(" Loader Message: " + Loader.getMessage());
5858
System.out.println(" Loader Interface Resolution Strategy: " + Loader.getInterfaceResolutionStrategy());
5959
System.out.println(" Loader Interface: " + Loader.getInterfaceTypeName());
60+
61+
if (Loader.isFixedInstallDir()) {
62+
System.out.println(" Using Fixed Install Dir: "+Loader.getInstallDir());
63+
} else {
64+
System.out.println(" Using Install Dir: "+Loader.getInstallDir());
65+
}
66+
6067
System.out.println(" Loaded Native Libraries:");
6168
Loader.getLoadedLibs().forEach(it -> {
6269
System.out.println(" " + it);

0 commit comments

Comments
 (0)