Skip to content

Commit b2bf2d2

Browse files
JakubVanekDavid Holmes
authored andcommitted
8214332: Add a flag for overriding default JNI library search path
Reviewed-by: erikj, dholmes
1 parent 9aff87e commit b2bf2d2

8 files changed

Lines changed: 58 additions & 5 deletions

File tree

doc/building.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,10 @@ <h4 id="configure-arguments-for-tailoring-the-build">Configure Arguments for Tai
464464
<li><code>--with-jvm-features=&lt;feature&gt;[,&lt;feature&gt;...]</code> - Use the specified JVM features when building Hotspot. The list of features will be enabled on top of the default list. For the <code>custom</code> JVM variant, this default list is empty. A complete list of available JVM features can be found using <code>bash configure --help</code>.</li>
465465
<li><code>--with-target-bits=&lt;bits&gt;</code> - Create a target binary suitable for running on a <code>&lt;bits&gt;</code> platform. Use this to create 32-bit output on a 64-bit build platform, instead of doing a full cross-compile. (This is known as a <em>reduced</em> build.)</li>
466466
</ul>
467+
<p>On Linux, BSD and AIX, it is possible to override where Java by default searches for runtime/JNI libraries. This can be useful in situations where there is a special shared directory for system JNI libraries. This setting can in turn be overriden at runtime by setting the <code>java.library.path</code> property.</p>
468+
<ul>
469+
<li><code>--with-jni-libpath=&lt;path&gt;</code> - Use the specified path as a default when searching for runtime libraries.</li>
470+
</ul>
467471
<h4 id="configure-arguments-for-native-compilation">Configure Arguments for Native Compilation</h4>
468472
<ul>
469473
<li><code>--with-devkit=&lt;path&gt;</code> - Use this devkit for compilers, tools and resources</li>

doc/building.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,14 @@ features, use `bash configure --help=short` instead.)
662662
platform, instead of doing a full cross-compile. (This is known as a
663663
*reduced* build.)
664664
665+
On Linux, BSD and AIX, it is possible to override where Java by default
666+
searches for runtime/JNI libraries. This can be useful in situations where
667+
there is a special shared directory for system JNI libraries. This setting
668+
can in turn be overriden at runtime by setting the `java.library.path` property.
669+
670+
* `--with-jni-libpath=<path>` - Use the specified path as a default
671+
when searching for runtime libraries.
672+
665673
#### Configure Arguments for Native Compilation
666674
667675
* `--with-devkit=<path>` - Use this devkit for compilers, tools and resources

make/autoconf/jdk-options.m4

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,28 @@ AC_DEFUN_ONCE([JDKOPT_SETUP_JDK_OPTIONS],
244244
COPYRIGHT_YEAR=`$DATE +'%Y'`
245245
fi
246246
AC_SUBST(COPYRIGHT_YEAR)
247+
248+
# Override default library path
249+
AC_ARG_WITH([jni-libpath], [AS_HELP_STRING([--with-jni-libpath],
250+
[override default JNI library search path])])
251+
AC_MSG_CHECKING([for jni library path])
252+
if test "x${with_jni_libpath}" = "x" || test "x${with_jni_libpath}" = "xno"; then
253+
AC_MSG_RESULT([default])
254+
elif test "x${with_jni_libpath}" = "xyes"; then
255+
AC_MSG_RESULT([invalid])
256+
AC_MSG_ERROR([The --with-jni-libpath option requires an argument.])
257+
else
258+
HOTSPOT_OVERRIDE_LIBPATH=${with_jni_libpath}
259+
if test "x$OPENJDK_TARGET_OS" != "xlinux" &&
260+
test "x$OPENJDK_TARGET_OS" != "xbsd" &&
261+
test "x$OPENJDK_TARGET_OS" != "xaix"; then
262+
AC_MSG_RESULT([fail])
263+
AC_MSG_ERROR([Overriding JNI library path is supported only on Linux, BSD and AIX.])
264+
fi
265+
AC_MSG_RESULT(${HOTSPOT_OVERRIDE_LIBPATH})
266+
fi
267+
AC_SUBST(HOTSPOT_OVERRIDE_LIBPATH)
268+
247269
])
248270

249271
###############################################################################

make/autoconf/spec.gmk.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,9 @@ VALID_JVM_VARIANTS := @VALID_JVM_VARIANTS@
275275
# Control wether Hotspot builds gtest tests
276276
BUILD_GTEST := @BUILD_GTEST@
277277

278+
# Allow overriding the default hotspot library path
279+
HOTSPOT_OVERRIDE_LIBPATH := @HOTSPOT_OVERRIDE_LIBPATH@
280+
278281
# Control use of precompiled header in hotspot libjvm build
279282
USE_PRECOMPILED_HEADER := @USE_PRECOMPILED_HEADER@
280283

make/hotspot/lib/JvmFlags.gmk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,7 @@ JVM_CFLAGS += \
9595
ifeq ($(USE_PRECOMPILED_HEADER), false)
9696
JVM_CFLAGS += -DDONT_USE_PRECOMPILED_HEADER
9797
endif
98+
99+
ifneq ($(HOTSPOT_OVERRIDE_LIBPATH), )
100+
JVM_CFLAGS += -DOVERRIDE_LIBPATH='"$(HOTSPOT_OVERRIDE_LIBPATH)"'
101+
endif

src/hotspot/os/aix/os_aix.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,11 @@ static void query_multipage_support() {
541541

542542
void os::init_system_properties_values() {
543543

544-
#define DEFAULT_LIBPATH "/lib:/usr/lib"
544+
#ifndef OVERRIDE_LIBPATH
545+
#define DEFAULT_LIBPATH "/lib:/usr/lib"
546+
#else
547+
#define DEFAULT_LIBPATH OVERRIDE_LIBPATH
548+
#endif
545549
#define EXTENSIONS_DIR "/lib/ext"
546550

547551
// Buffer that fits several sprintfs.

src/hotspot/os/bsd/os_bsd.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,11 @@ void os::init_system_properties_values() {
316316
// ...
317317
// 7: The default directories, normally /lib and /usr/lib.
318318
#ifndef DEFAULT_LIBPATH
319-
#define DEFAULT_LIBPATH "/lib:/usr/lib"
319+
#ifndef OVERRIDE_LIBPATH
320+
#define DEFAULT_LIBPATH "/lib:/usr/lib"
321+
#else
322+
#define DEFAULT_LIBPATH OVERRIDE_LIBPATH
323+
#endif
320324
#endif
321325

322326
// Base path of extensions installed on the system.

src/hotspot/os/linux/os_linux.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,14 @@ void os::init_system_properties_values() {
323323
// 1: ...
324324
// ...
325325
// 7: The default directories, normally /lib and /usr/lib.
326-
#if defined(AMD64) || (defined(_LP64) && defined(SPARC)) || defined(PPC64) || defined(S390)
327-
#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
326+
#ifndef OVERRIDE_LIBPATH
327+
#if defined(AMD64) || (defined(_LP64) && defined(SPARC)) || defined(PPC64) || defined(S390)
328+
#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
329+
#else
330+
#define DEFAULT_LIBPATH "/lib:/usr/lib"
331+
#endif
328332
#else
329-
#define DEFAULT_LIBPATH "/lib:/usr/lib"
333+
#define DEFAULT_LIBPATH OVERRIDE_LIBPATH
330334
#endif
331335

332336
// Base path of extensions installed on the system.

0 commit comments

Comments
 (0)