8038201: Clean up misleading usage of malloc() in init_system_properties_values()

Remove the misleading malloc macro and cleanup the code

Reviewed-by: dsamersoff, kvn
This commit is contained in:
Goetz Lindenmaier 2014-04-01 03:59:01 -07:00 committed by Goetz Lindenmaier
parent 4643207df7
commit f190cc8c67
5 changed files with 463 additions and 567 deletions

View file

@ -1672,7 +1672,7 @@ address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
//__ flush_bundle(); //__ flush_bundle();
address entry = __ pc(); address entry = __ pc();
char *bname = NULL; const char *bname = NULL;
uint tsize = 0; uint tsize = 0;
switch(state) { switch(state) {
case ftos: case ftos:

View file

@ -60,8 +60,8 @@
#include "runtime/sharedRuntime.hpp" #include "runtime/sharedRuntime.hpp"
#include "runtime/statSampler.hpp" #include "runtime/statSampler.hpp"
#include "runtime/stubRoutines.hpp" #include "runtime/stubRoutines.hpp"
#include "runtime/threadCritical.hpp"
#include "runtime/thread.inline.hpp" #include "runtime/thread.inline.hpp"
#include "runtime/threadCritical.hpp"
#include "runtime/timer.hpp" #include "runtime/timer.hpp"
#include "services/attachListener.hpp" #include "services/attachListener.hpp"
#include "services/runtimeService.hpp" #include "services/runtimeService.hpp"
@ -70,16 +70,6 @@
#include "utilities/events.hpp" #include "utilities/events.hpp"
#include "utilities/growableArray.hpp" #include "utilities/growableArray.hpp"
#include "utilities/vmError.hpp" #include "utilities/vmError.hpp"
#ifdef TARGET_ARCH_ppc
# include "assembler_ppc.inline.hpp"
# include "nativeInst_ppc.hpp"
#endif
#ifdef COMPILER1
#include "c1/c1_Runtime1.hpp"
#endif
#ifdef COMPILER2
#include "opto/runtime.hpp"
#endif
// put OS-includes here (sorted alphabetically) // put OS-includes here (sorted alphabetically)
#include <errno.h> #include <errno.h>
@ -378,13 +368,14 @@ void os::Aix::query_multipage_support() {
assert(_page_size == SIZE_4K, "surprise!"); assert(_page_size == SIZE_4K, "surprise!");
// query default data page size (default page size for C-Heap, pthread stacks and .bss). // Query default data page size (default page size for C-Heap, pthread stacks and .bss).
// Default data page size is influenced either by linker options (-bdatapsize) // Default data page size is influenced either by linker options (-bdatapsize)
// or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given, // or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given,
// default should be 4K. // default should be 4K.
size_t data_page_size = SIZE_4K; size_t data_page_size = SIZE_4K;
{ {
void* p = ::malloc(SIZE_16M); void* p = ::malloc(SIZE_16M);
guarantee(p != NULL, "malloc failed");
data_page_size = os::Aix::query_pagesize(p); data_page_size = os::Aix::query_pagesize(p);
::free(p); ::free(p);
} }
@ -511,85 +502,76 @@ query_multipage_support_end:
} // end os::Aix::query_multipage_support() } // end os::Aix::query_multipage_support()
// The code for this method was initially derived from the version in os_linux.cpp.
// The code for this method was initially derived from the version in os_linux.cpp
void os::init_system_properties_values() { void os::init_system_properties_values() {
// The next few definitions allow the code to be verbatim:
#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal)
#define DEFAULT_LIBPATH "/usr/lib:/lib" #define DEFAULT_LIBPATH "/usr/lib:/lib"
#define EXTENSIONS_DIR "/lib/ext" #define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed" #define ENDORSED_DIR "/lib/endorsed"
// Buffer that fits several sprintfs.
// Note that the space for the trailing null is provided
// by the nulls included by the sizeof operator.
const size_t bufsize =
MAX3((size_t)MAXPATHLEN, // For dll_dir & friends.
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR), // extensions dir
(size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// sysclasspath, java_home, dll_dir // sysclasspath, java_home, dll_dir
char *home_path; {
char *dll_path;
char *pslash; char *pslash;
char buf[MAXPATHLEN]; os::jvm_path(buf, bufsize);
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so. // Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can. // Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; // get rid of /libjvm.so *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; // get rid of /{client|server|hotspot} *pslash = '\0'; // Get rid of /{client|server|hotspot}.
} }
Arguments::set_dll_dir(buf);
dll_path = malloc(strlen(buf) + 1);
strcpy(dll_path, buf);
Arguments::set_dll_dir(dll_path);
if (pslash != NULL) { if (pslash != NULL) {
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; // get rid of /<arch> *pslash = '\0'; // Get rid of /<arch>.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; // get rid of /lib *pslash = '\0'; // Get rid of /lib.
} }
} }
} }
Arguments::set_java_home(buf);
set_boot_path('/', ':');
}
home_path = malloc(strlen(buf) + 1); // Where to look for native libraries.
strcpy(home_path, buf);
Arguments::set_java_home(home_path);
if (!set_boot_path('/', ':')) return; // On Aix we get the user setting of LIBPATH.
// Where to look for native libraries
// On Aix we get the user setting of LIBPATH
// Eventually, all the library path setting will be done here. // Eventually, all the library path setting will be done here.
char *ld_library_path; // Get the user setting of LIBPATH.
const char *v = ::getenv("LIBPATH");
// Construct the invariant part of ld_library_path. const char *v_colon = ":";
ld_library_path = (char *) malloc(sizeof(DEFAULT_LIBPATH)); if (v == NULL) { v = ""; v_colon = ""; }
sprintf(ld_library_path, DEFAULT_LIBPATH);
// Get the user setting of LIBPATH, and prepended it.
char *v = ::getenv("LIBPATH");
if (v == NULL) {
v = "";
}
char *t = ld_library_path;
// That's +1 for the colon and +1 for the trailing '\0'
ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
sprintf(ld_library_path, "%s:%s", v, t);
// Concatenate user and invariant part of ld_library_path.
// That's +1 for the colon and +1 for the trailing '\0'.
char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, strlen(v) + 1 + sizeof(DEFAULT_LIBPATH) + 1, mtInternal);
sprintf(ld_library_path, "%s%s" DEFAULT_LIBPATH, v, v_colon);
Arguments::set_library_path(ld_library_path); Arguments::set_library_path(ld_library_path);
FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
// Extensions directories // Extensions directories.
char* cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(EXTENSIONS_DIR)); sprintf(buf, "%s" EXTENSIONS_DIR, Arguments::get_java_home());
sprintf(cbuf, "%s" EXTENSIONS_DIR, Arguments::get_java_home()); Arguments::set_ext_dirs(buf);
Arguments::set_ext_dirs(cbuf);
// Endorsed standards default directory. // Endorsed standards default directory.
cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR)); sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
sprintf(cbuf, "%s" ENDORSED_DIR, Arguments::get_java_home()); Arguments::set_endorsed_dirs(buf);
Arguments::set_endorsed_dirs(cbuf);
FREE_C_HEAP_ARRAY(char, buf, mtInternal);
#undef malloc
#undef DEFAULT_LIBPATH #undef DEFAULT_LIBPATH
#undef EXTENSIONS_DIR #undef EXTENSIONS_DIR
#undef ENDORSED_DIR #undef ENDORSED_DIR

View file

@ -306,9 +306,6 @@ static const char *get_home() {
#endif #endif
void os::init_system_properties_values() { void os::init_system_properties_values() {
// char arch[12];
// sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
// The next steps are taken in the product version: // The next steps are taken in the product version:
// //
// Obtain the JAVA_HOME value from the location of libjvm.so. // Obtain the JAVA_HOME value from the location of libjvm.so.
@ -335,137 +332,164 @@ void os::init_system_properties_values() {
// Important note: if the location of libjvm.so changes this // Important note: if the location of libjvm.so changes this
// code needs to be changed accordingly. // code needs to be changed accordingly.
// The next few definitions allow the code to be verbatim: // See ld(1):
#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) // The linker uses the following search paths to locate required
#define getenv(n) ::getenv(n) // shared libraries:
// 1: ...
/* // ...
* See ld(1): // 7: The default directories, normally /lib and /usr/lib.
* The linker uses the following search paths to locate required
* shared libraries:
* 1: ...
* ...
* 7: The default directories, normally /lib and /usr/lib.
*/
#ifndef DEFAULT_LIBPATH #ifndef DEFAULT_LIBPATH
#define DEFAULT_LIBPATH "/lib:/usr/lib" #define DEFAULT_LIBPATH "/lib:/usr/lib"
#endif #endif
// Base path of extensions installed on the system.
#define SYS_EXT_DIR "/usr/java/packages"
#define EXTENSIONS_DIR "/lib/ext" #define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed" #define ENDORSED_DIR "/lib/endorsed"
#define REG_DIR "/usr/java/packages"
#ifdef __APPLE__ #ifndef __APPLE__
#define SYS_EXTENSIONS_DIR "/Library/Java/Extensions"
#define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java"
const char *user_home_dir = get_home();
// the null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir
int system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) +
sizeof(SYS_EXTENSIONS_DIRS);
#endif
// Buffer that fits several sprintfs.
// Note that the space for the colon and the trailing null are provided
// by the nulls included by the sizeof operator.
const size_t bufsize =
MAX3((size_t)MAXPATHLEN, // For dll_dir & friends.
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
(size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// sysclasspath, java_home, dll_dir
{ {
/* sysclasspath, java_home, dll_dir */
{
char *home_path;
char *dll_path;
char *pslash; char *pslash;
char buf[MAXPATHLEN]; os::jvm_path(buf, bufsize);
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so. // Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can. // Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /{client|server|hotspot} */ *pslash = '\0'; // Get rid of /{client|server|hotspot}.
dll_path = malloc(strlen(buf) + 1); }
if (dll_path == NULL) Arguments::set_dll_dir(buf);
return;
strcpy(dll_path, buf);
Arguments::set_dll_dir(dll_path);
if (pslash != NULL) { if (pslash != NULL) {
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; /* get rid of /<arch> (/lib on macosx) */ *pslash = '\0'; // Get rid of /<arch>.
#ifndef __APPLE__
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /lib */ *pslash = '\0'; // Get rid of /lib.
#endif
} }
} }
}
home_path = malloc(strlen(buf) + 1); Arguments::set_java_home(buf);
if (home_path == NULL) set_boot_path('/', ':');
return;
strcpy(home_path, buf);
Arguments::set_java_home(home_path);
if (!set_boot_path('/', ':'))
return;
} }
/* // Where to look for native libraries.
* Where to look for native libraries //
* // Note: Due to a legacy implementation, most of the library path
* Note: Due to a legacy implementation, most of the library path // is set in the launcher. This was to accomodate linking restrictions
* is set in the launcher. This was to accomodate linking restrictions // on legacy Bsd implementations (which are no longer supported).
* on legacy Bsd implementations (which are no longer supported). // Eventually, all the library path setting will be done here.
* Eventually, all the library path setting will be done here. //
* // However, to prevent the proliferation of improperly built native
* However, to prevent the proliferation of improperly built native // libraries, the new path component /usr/java/packages is added here.
* libraries, the new path component /usr/java/packages is added here. // Eventually, all the library path setting will be done here.
* Eventually, all the library path setting will be done here.
*/
{ {
char *ld_library_path; // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
// should always exist (until the legacy problem cited above is
/* // addressed).
* Construct the invariant part of ld_library_path. Note that the const char *v = ::getenv("LD_LIBRARY_PATH");
* space for the colon and the trailing null are provided by the const char *v_colon = ":";
* nulls included by the sizeof operator (so actually we allocate if (v == NULL) { v = ""; v_colon = ""; }
* a byte more than necessary). // That's +1 for the colon and +1 for the trailing '\0'.
*/ char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
#ifdef __APPLE__ strlen(v) + 1 +
ld_library_path = (char *) malloc(system_ext_size); sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
sprintf(ld_library_path, "%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS, user_home_dir); mtInternal);
#else sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + Arguments::set_library_path(ld_library_path);
strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch);
#endif
/*
* Get the user setting of LD_LIBRARY_PATH, and prepended it. It
* should always exist (until the legacy problem cited above is
* addressed).
*/
#ifdef __APPLE__
// Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code can specify a directory inside an app wrapper
char *l = getenv("JAVA_LIBRARY_PATH");
if (l != NULL) {
char *t = ld_library_path;
/* That's +1 for the colon and +1 for the trailing '\0' */
ld_library_path = (char *) malloc(strlen(l) + 1 + strlen(t) + 1);
sprintf(ld_library_path, "%s:%s", l, t);
free(t);
} }
char *v = getenv("DYLD_LIBRARY_PATH"); // Extensions directories.
#else sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
char *v = getenv("LD_LIBRARY_PATH"); Arguments::set_ext_dirs(buf);
#endif
if (v != NULL) { // Endorsed standards default directory.
char *t = ld_library_path; sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
/* That's +1 for the colon and +1 for the trailing '\0' */ Arguments::set_endorsed_dirs(buf);
ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
sprintf(ld_library_path, "%s:%s", v, t); FREE_C_HEAP_ARRAY(char, buf, mtInternal);
free(t);
#else // __APPLE__
#define SYS_EXTENSIONS_DIR "/Library/Java/Extensions"
#define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java"
const char *user_home_dir = get_home();
// The null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir.
size_t system_ext_size = strlen(user_home_dir) + sizeof(SYS_EXTENSIONS_DIR) +
sizeof(SYS_EXTENSIONS_DIRS);
// Buffer that fits several sprintfs.
// Note that the space for the colon and the trailing null are provided
// by the nulls included by the sizeof operator.
const size_t bufsize =
MAX3((size_t)MAXPATHLEN, // for dll_dir & friends.
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + system_ext_size, // extensions dir
(size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// sysclasspath, java_home, dll_dir
{
char *pslash;
os::jvm_path(buf, bufsize);
// Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/');
if (pslash != NULL) {
*pslash = '\0'; // Get rid of /{client|server|hotspot}.
}
Arguments::set_dll_dir(buf);
if (pslash != NULL) {
pslash = strrchr(buf, '/');
if (pslash != NULL) {
*pslash = '\0'; // Get rid of /lib.
}
}
Arguments::set_java_home(buf);
set_boot_path('/', ':');
} }
#ifdef __APPLE__ // Where to look for native libraries.
//
// Note: Due to a legacy implementation, most of the library path
// is set in the launcher. This was to accomodate linking restrictions
// on legacy Bsd implementations (which are no longer supported).
// Eventually, all the library path setting will be done here.
//
// However, to prevent the proliferation of improperly built native
// libraries, the new path component /usr/java/packages is added here.
// Eventually, all the library path setting will be done here.
{
// Get the user setting of LD_LIBRARY_PATH, and prepended it. It
// should always exist (until the legacy problem cited above is
// addressed).
// Prepend the default path with the JAVA_LIBRARY_PATH so that the app launcher code
// can specify a directory inside an app wrapper
const char *l = ::getenv("JAVA_LIBRARY_PATH");
const char *l_colon = ":";
if (l == NULL) { l = ""; l_colon = ""; }
const char *v = ::getenv("DYLD_LIBRARY_PATH");
const char *v_colon = ":";
if (v == NULL) { v = ""; v_colon = ""; }
// Apple's Java6 has "." at the beginning of java.library.path. // Apple's Java6 has "." at the beginning of java.library.path.
// OpenJDK on Windows has "." at the end of java.library.path. // OpenJDK on Windows has "." at the end of java.library.path.
// OpenJDK on Linux and Solaris don't have "." in java.library.path // OpenJDK on Linux and Solaris don't have "." in java.library.path
@ -474,60 +498,39 @@ void os::init_system_properties_values() {
// could cause a change in behavior, but Apple's Java6 behavior // could cause a change in behavior, but Apple's Java6 behavior
// can be achieved by putting "." at the beginning of the // can be achieved by putting "." at the beginning of the
// JAVA_LIBRARY_PATH environment variable. // JAVA_LIBRARY_PATH environment variable.
{ char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
char *t = ld_library_path; strlen(v) + 1 + strlen(l) + 1 +
// that's +3 for appending ":." and the trailing '\0' system_ext_size + 3,
ld_library_path = (char *) malloc(strlen(t) + 3); mtInternal);
sprintf(ld_library_path, "%s:%s", t, "."); sprintf(ld_library_path, "%s%s%s%s%s" SYS_EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS ":.",
free(t); v, v_colon, l, l_colon, user_home_dir);
}
#endif
Arguments::set_library_path(ld_library_path); Arguments::set_library_path(ld_library_path);
FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
} }
/* // Extensions directories.
* Extensions directories. //
* // Note that the space for the colon and the trailing null are provided
* Note that the space for the colon and the trailing null are provided // by the nulls included by the sizeof operator (so actually one byte more
* by the nulls included by the sizeof operator (so actually one byte more // than necessary is allocated).
* than necessary is allocated). sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":" SYS_EXTENSIONS_DIRS,
*/ user_home_dir, Arguments::get_java_home());
{
#ifdef __APPLE__
char *buf = malloc(strlen(Arguments::get_java_home()) +
sizeof(EXTENSIONS_DIR) + system_ext_size);
sprintf(buf, "%s" SYS_EXTENSIONS_DIR ":%s" EXTENSIONS_DIR ":"
SYS_EXTENSIONS_DIRS, user_home_dir, Arguments::get_java_home());
#else
char *buf = malloc(strlen(Arguments::get_java_home()) +
sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR));
sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR,
Arguments::get_java_home());
#endif
Arguments::set_ext_dirs(buf); Arguments::set_ext_dirs(buf);
}
/* Endorsed standards default directory. */ // Endorsed standards default directory.
{
char * buf;
buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
Arguments::set_endorsed_dirs(buf); Arguments::set_endorsed_dirs(buf);
}
}
#ifdef __APPLE__ FREE_C_HEAP_ARRAY(char, buf, mtInternal);
#undef SYS_EXTENSIONS_DIR #undef SYS_EXTENSIONS_DIR
#endif #undef SYS_EXTENSIONS_DIRS
#undef malloc
#undef getenv #endif // __APPLE__
#undef SYS_EXT_DIR
#undef EXTENSIONS_DIR #undef EXTENSIONS_DIR
#undef ENDORSED_DIR #undef ENDORSED_DIR
// Done
return;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -3091,7 +3094,7 @@ void os::Bsd::set_signal_handler(int sig, bool set_installed) {
sigAct.sa_sigaction = signalHandler; sigAct.sa_sigaction = signalHandler;
sigAct.sa_flags = SA_SIGINFO|SA_RESTART; sigAct.sa_flags = SA_SIGINFO|SA_RESTART;
} }
#if __APPLE__ #ifdef __APPLE__
// Needed for main thread as XNU (Mac OS X kernel) will only deliver SIGSEGV // Needed for main thread as XNU (Mac OS X kernel) will only deliver SIGSEGV
// (which starts as SIGBUS) on main thread with faulting address inside "stack+guard pages" // (which starts as SIGBUS) on main thread with faulting address inside "stack+guard pages"
// if the signal handler declares it will handle it on alternate stack. // if the signal handler declares it will handle it on alternate stack.

View file

@ -319,9 +319,6 @@ void os::Linux::initialize_system_info() {
} }
void os::init_system_properties_values() { void os::init_system_properties_values() {
// char arch[12];
// sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
// The next steps are taken in the product version: // The next steps are taken in the product version:
// //
// Obtain the JAVA_HOME value from the location of libjvm.so. // Obtain the JAVA_HOME value from the location of libjvm.so.
@ -348,140 +345,101 @@ void os::init_system_properties_values() {
// Important note: if the location of libjvm.so changes this // Important note: if the location of libjvm.so changes this
// code needs to be changed accordingly. // code needs to be changed accordingly.
// The next few definitions allow the code to be verbatim: // See ld(1):
#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) // The linker uses the following search paths to locate required
#define getenv(n) ::getenv(n) // shared libraries:
// 1: ...
/* // ...
* See ld(1): // 7: The default directories, normally /lib and /usr/lib.
* The linker uses the following search paths to locate required
* shared libraries:
* 1: ...
* ...
* 7: The default directories, normally /lib and /usr/lib.
*/
#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
#else #else
#define DEFAULT_LIBPATH "/lib:/usr/lib" #define DEFAULT_LIBPATH "/lib:/usr/lib"
#endif #endif
// Base path of extensions installed on the system.
#define SYS_EXT_DIR "/usr/java/packages"
#define EXTENSIONS_DIR "/lib/ext" #define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed" #define ENDORSED_DIR "/lib/endorsed"
#define REG_DIR "/usr/java/packages"
// Buffer that fits several sprintfs.
// Note that the space for the colon and the trailing null are provided
// by the nulls included by the sizeof operator.
const size_t bufsize =
MAX3((size_t)MAXPATHLEN, // For dll_dir & friends.
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
(size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// sysclasspath, java_home, dll_dir
{ {
/* sysclasspath, java_home, dll_dir */
{
char *home_path;
char *dll_path;
char *pslash; char *pslash;
char buf[MAXPATHLEN]; os::jvm_path(buf, bufsize);
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so. // Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can. // Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /{client|server|hotspot} */ *pslash = '\0'; // Get rid of /{client|server|hotspot}.
dll_path = malloc(strlen(buf) + 1); }
if (dll_path == NULL) Arguments::set_dll_dir(buf);
return;
strcpy(dll_path, buf);
Arguments::set_dll_dir(dll_path);
if (pslash != NULL) { if (pslash != NULL) {
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; /* get rid of /<arch> */ *pslash = '\0'; // Get rid of /<arch>.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /lib */ *pslash = '\0'; // Get rid of /lib.
} }
} }
}
home_path = malloc(strlen(buf) + 1); Arguments::set_java_home(buf);
if (home_path == NULL) set_boot_path('/', ':');
return;
strcpy(home_path, buf);
Arguments::set_java_home(home_path);
if (!set_boot_path('/', ':'))
return;
} }
/* // Where to look for native libraries.
* Where to look for native libraries //
* // Note: Due to a legacy implementation, most of the library path
* Note: Due to a legacy implementation, most of the library path // is set in the launcher. This was to accomodate linking restrictions
* is set in the launcher. This was to accomodate linking restrictions // on legacy Linux implementations (which are no longer supported).
* on legacy Linux implementations (which are no longer supported). // Eventually, all the library path setting will be done here.
* Eventually, all the library path setting will be done here. //
* // However, to prevent the proliferation of improperly built native
* However, to prevent the proliferation of improperly built native // libraries, the new path component /usr/java/packages is added here.
* libraries, the new path component /usr/java/packages is added here. // Eventually, all the library path setting will be done here.
* Eventually, all the library path setting will be done here.
*/
{ {
char *ld_library_path; // Get the user setting of LD_LIBRARY_PATH, and prepended it. It
// should always exist (until the legacy problem cited above is
/* // addressed).
* Construct the invariant part of ld_library_path. Note that the const char *v = ::getenv("LD_LIBRARY_PATH");
* space for the colon and the trailing null are provided by the const char *v_colon = ":";
* nulls included by the sizeof operator (so actually we allocate if (v == NULL) { v = ""; v_colon = ""; }
* a byte more than necessary). // That's +1 for the colon and +1 for the trailing '\0'.
*/ char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char,
ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + strlen(v) + 1 +
strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1,
sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch); mtInternal);
sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch);
/*
* Get the user setting of LD_LIBRARY_PATH, and prepended it. It
* should always exist (until the legacy problem cited above is
* addressed).
*/
char *v = getenv("LD_LIBRARY_PATH");
if (v != NULL) {
char *t = ld_library_path;
/* That's +1 for the colon and +1 for the trailing '\0' */
ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1);
sprintf(ld_library_path, "%s:%s", v, t);
}
Arguments::set_library_path(ld_library_path); Arguments::set_library_path(ld_library_path);
FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal);
} }
/* // Extensions directories.
* Extensions directories. sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
*
* Note that the space for the colon and the trailing null are provided
* by the nulls included by the sizeof operator (so actually one byte more
* than necessary is allocated).
*/
{
char *buf = malloc(strlen(Arguments::get_java_home()) +
sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR));
sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR,
Arguments::get_java_home());
Arguments::set_ext_dirs(buf); Arguments::set_ext_dirs(buf);
}
/* Endorsed standards default directory. */ // Endorsed standards default directory.
{
char * buf;
buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
Arguments::set_endorsed_dirs(buf); Arguments::set_endorsed_dirs(buf);
}
}
#undef malloc FREE_C_HEAP_ARRAY(char, buf, mtInternal);
#undef getenv
#undef DEFAULT_LIBPATH
#undef SYS_EXT_DIR
#undef EXTENSIONS_DIR #undef EXTENSIONS_DIR
#undef ENDORSED_DIR #undef ENDORSED_DIR
// Done
return;
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -580,9 +580,6 @@ bool os::have_special_privileges() {
void os::init_system_properties_values() { void os::init_system_properties_values() {
char arch[12];
sysinfo(SI_ARCHITECTURE, arch, sizeof(arch));
// The next steps are taken in the product version: // The next steps are taken in the product version:
// //
// Obtain the JAVA_HOME value from the location of libjvm.so. // Obtain the JAVA_HOME value from the location of libjvm.so.
@ -609,59 +606,51 @@ void os::init_system_properties_values() {
// Important note: if the location of libjvm.so changes this // Important note: if the location of libjvm.so changes this
// code needs to be changed accordingly. // code needs to be changed accordingly.
// The next few definitions allow the code to be verbatim: // Base path of extensions installed on the system.
#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) #define SYS_EXT_DIR "/usr/jdk/packages"
#define free(p) FREE_C_HEAP_ARRAY(char, p, mtInternal)
#define getenv(n) ::getenv(n)
#define EXTENSIONS_DIR "/lib/ext" #define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed" #define ENDORSED_DIR "/lib/endorsed"
#define COMMON_DIR "/usr/jdk/packages"
char cpu_arch[12];
// Buffer that fits several sprintfs.
// Note that the space for the colon and the trailing null are provided
// by the nulls included by the sizeof operator.
const size_t bufsize =
MAX4((size_t)MAXPATHLEN, // For dll_dir & friends.
sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch), // invariant ld_library_path
(size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir
(size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir
char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
// sysclasspath, java_home, dll_dir
{ {
/* sysclasspath, java_home, dll_dir */
{
char *home_path;
char *dll_path;
char *pslash; char *pslash;
char buf[MAXPATHLEN]; os::jvm_path(buf, bufsize);
os::jvm_path(buf, sizeof(buf));
// Found the full path to libjvm.so. // Found the full path to libjvm.so.
// Now cut the path to <java_home>/jre if we can. // Now cut the path to <java_home>/jre if we can.
*(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /{client|server|hotspot} */ *pslash = '\0'; // Get rid of /{client|server|hotspot}.
dll_path = malloc(strlen(buf) + 1); }
if (dll_path == NULL) Arguments::set_dll_dir(buf);
return;
strcpy(dll_path, buf);
Arguments::set_dll_dir(dll_path);
if (pslash != NULL) { if (pslash != NULL) {
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) { if (pslash != NULL) {
*pslash = '\0'; /* get rid of /<arch> */ *pslash = '\0'; // Get rid of /<arch>.
pslash = strrchr(buf, '/'); pslash = strrchr(buf, '/');
if (pslash != NULL) if (pslash != NULL) {
*pslash = '\0'; /* get rid of /lib */ *pslash = '\0'; // Get rid of /lib.
} }
} }
}
home_path = malloc(strlen(buf) + 1); Arguments::set_java_home(buf);
if (home_path == NULL) set_boot_path('/', ':');
return;
strcpy(home_path, buf);
Arguments::set_java_home(home_path);
if (!set_boot_path('/', ':'))
return;
} }
/* // Where to look for native libraries.
* Where to look for native libraries
*/
{ {
// Use dlinfo() to determine the correct java.library.path. // Use dlinfo() to determine the correct java.library.path.
// //
@ -679,29 +668,26 @@ void os::init_system_properties_values() {
// get here with any/all of the LD_LIBRARY_PATH[_32|64] // get here with any/all of the LD_LIBRARY_PATH[_32|64]
// settings. Again, dlinfo does exactly what we want. // settings. Again, dlinfo does exactly what we want.
Dl_serinfo _info, *info = &_info; Dl_serinfo info_sz, *info = &info_sz;
Dl_serpath *path; Dl_serpath *path;
char *library_path; char *library_path;
char *common_path; char *common_path = buf;
int i;
// determine search path count and required buffer size // Determine search path count and required buffer size.
if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) { if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) {
FREE_C_HEAP_ARRAY(char, buf, mtInternal);
vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror()); vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror());
} }
// allocate new buffer and initialize // Allocate new buffer and initialize.
info = (Dl_serinfo*)malloc(_info.dls_size); info = (Dl_serinfo*)NEW_C_HEAP_ARRAY(char, info_sz.dls_size, mtInternal);
if (info == NULL) { info->dls_size = info_sz.dls_size;
vm_exit_out_of_memory(_info.dls_size, OOM_MALLOC_ERROR, info->dls_cnt = info_sz.dls_cnt;
"init_system_properties_values info");
}
info->dls_size = _info.dls_size;
info->dls_cnt = _info.dls_cnt;
// obtain search path information // Obtain search path information.
if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) { if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) {
free(info); FREE_C_HEAP_ARRAY(char, buf, mtInternal);
FREE_C_HEAP_ARRAY(char, info, mtInternal);
vm_exit_during_initialization("dlinfo SERINFO request", dlerror()); vm_exit_during_initialization("dlinfo SERINFO request", dlerror());
} }
@ -716,41 +702,26 @@ void os::init_system_properties_values() {
// libraries, the new path component /usr/jdk/packages is added here. // libraries, the new path component /usr/jdk/packages is added here.
// Determine the actual CPU architecture. // Determine the actual CPU architecture.
char cpu_arch[12];
sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch)); sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch));
#ifdef _LP64 #ifdef _LP64
// If we are a 64-bit vm, perform the following translations: // If we are a 64-bit vm, perform the following translations:
// sparc -> sparcv9 // sparc -> sparcv9
// i386 -> amd64 // i386 -> amd64
if (strcmp(cpu_arch, "sparc") == 0) if (strcmp(cpu_arch, "sparc") == 0) {
strcat(cpu_arch, "v9"); strcat(cpu_arch, "v9");
else if (strcmp(cpu_arch, "i386") == 0) } else if (strcmp(cpu_arch, "i386") == 0) {
strcpy(cpu_arch, "amd64"); strcpy(cpu_arch, "amd64");
}
#endif #endif
// Construct the invariant part of ld_library_path. Note that the // Construct the invariant part of ld_library_path.
// space for the colon and the trailing null are provided by the sprintf(common_path, SYS_EXT_DIR "/lib/%s", cpu_arch);
// nulls included by the sizeof operator.
size_t bufsize = sizeof(COMMON_DIR) + sizeof("/lib/") + strlen(cpu_arch);
common_path = malloc(bufsize);
if (common_path == NULL) {
free(info);
vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
"init_system_properties_values common_path");
}
sprintf(common_path, COMMON_DIR "/lib/%s", cpu_arch);
// struct size is more than sufficient for the path components obtained // Struct size is more than sufficient for the path components obtained
// through the dlinfo() call, so only add additional space for the path // through the dlinfo() call, so only add additional space for the path
// components explicitly added here. // components explicitly added here.
bufsize = info->dls_size + strlen(common_path); size_t library_path_size = info->dls_size + strlen(common_path);
library_path = malloc(bufsize); library_path = (char *)NEW_C_HEAP_ARRAY(char, library_path_size, mtInternal);
if (library_path == NULL) {
free(info);
free(common_path);
vm_exit_out_of_memory(bufsize, OOM_MALLOC_ERROR,
"init_system_properties_values library_path");
}
library_path[0] = '\0'; library_path[0] = '\0';
// Construct the desired Java library path from the linker's library // Construct the desired Java library path from the linker's library
@ -760,10 +731,11 @@ void os::init_system_properties_values() {
// components specific to the Java VM after those components specified // components specific to the Java VM after those components specified
// in LD_LIBRARY_PATH (if any) but before those added by the ld.so // in LD_LIBRARY_PATH (if any) but before those added by the ld.so
// infrastructure. // infrastructure.
if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it.
strcpy(library_path, common_path); strcpy(library_path, common_path);
} else { } else {
int inserted = 0; int inserted = 0;
int i;
for (i = 0; i < info->dls_cnt; i++, path++) { for (i = 0; i < info->dls_cnt; i++, path++) {
uint_t flags = path->dls_flags & LA_SER_MASK; uint_t flags = path->dls_flags & LA_SER_MASK;
if (((flags & LA_SER_LIBPATH) == 0) && !inserted) { if (((flags & LA_SER_LIBPATH) == 0) && !inserted) {
@ -774,7 +746,7 @@ void os::init_system_properties_values() {
strcat(library_path, path->dls_name); strcat(library_path, path->dls_name);
strcat(library_path, os::path_separator()); strcat(library_path, os::path_separator());
} }
// eliminate trailing path separator // Eliminate trailing path separator.
library_path[strlen(library_path)-1] = '\0'; library_path[strlen(library_path)-1] = '\0';
} }
@ -782,45 +754,26 @@ void os::init_system_properties_values() {
// tty->print_raw("init_system_properties_values: native lib path: "); // tty->print_raw("init_system_properties_values: native lib path: ");
// tty->print_raw_cr(library_path); // tty->print_raw_cr(library_path);
// callee copies into its own buffer // Callee copies into its own buffer.
Arguments::set_library_path(library_path); Arguments::set_library_path(library_path);
free(common_path); FREE_C_HEAP_ARRAY(char, library_path, mtInternal);
free(library_path); FREE_C_HEAP_ARRAY(char, info, mtInternal);
free(info);
} }
/* // Extensions directories.
* Extensions directories. sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home());
*
* Note that the space for the colon and the trailing null are provided
* by the nulls included by the sizeof operator (so actually one byte more
* than necessary is allocated).
*/
{
char *buf = (char *) malloc(strlen(Arguments::get_java_home()) +
sizeof(EXTENSIONS_DIR) + sizeof(COMMON_DIR) +
sizeof(EXTENSIONS_DIR));
sprintf(buf, "%s" EXTENSIONS_DIR ":" COMMON_DIR EXTENSIONS_DIR,
Arguments::get_java_home());
Arguments::set_ext_dirs(buf); Arguments::set_ext_dirs(buf);
}
/* Endorsed standards default directory. */ // Endorsed standards default directory.
{
char * buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR));
sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home());
Arguments::set_endorsed_dirs(buf); Arguments::set_endorsed_dirs(buf);
}
}
#undef malloc FREE_C_HEAP_ARRAY(char, buf, mtInternal);
#undef free
#undef getenv #undef SYS_EXT_DIR
#undef EXTENSIONS_DIR #undef EXTENSIONS_DIR
#undef ENDORSED_DIR #undef ENDORSED_DIR
#undef COMMON_DIR
} }
void os::breakpoint() { void os::breakpoint() {