src/os/aix/vm/os_aix.cpp

Print this page
rev 6140 : 8038201: Clean up misleading usage of malloc() in init_system_properties_values()
Summary: Add missing freeing of memory or use local variable. Also add a 'const' to avoid gcc write-string warnings on ppc.

*** 58,87 **** #include "runtime/osThread.hpp" #include "runtime/perfMemory.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/statSampler.hpp" #include "runtime/stubRoutines.hpp" - #include "runtime/threadCritical.hpp" #include "runtime/thread.inline.hpp" #include "runtime/timer.hpp" #include "services/attachListener.hpp" #include "services/runtimeService.hpp" #include "utilities/decoder.hpp" #include "utilities/defaultStream.hpp" #include "utilities/events.hpp" #include "utilities/growableArray.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) #include <errno.h> #include <fcntl.h> #include <inttypes.h> --- 58,77 ---- #include "runtime/osThread.hpp" #include "runtime/perfMemory.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/statSampler.hpp" #include "runtime/stubRoutines.hpp" #include "runtime/thread.inline.hpp" + #include "runtime/threadCritical.hpp" #include "runtime/timer.hpp" #include "services/attachListener.hpp" #include "services/runtimeService.hpp" #include "utilities/decoder.hpp" #include "utilities/defaultStream.hpp" #include "utilities/events.hpp" #include "utilities/growableArray.hpp" #include "utilities/vmError.hpp" // put OS-includes here (sorted alphabetically) #include <errno.h> #include <fcntl.h> #include <inttypes.h>
*** 376,392 **** // This really would surprise me. assert(_page_size == SIZE_4K, "surprise!"); ! // 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) // or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given, // default should be 4K. size_t data_page_size = SIZE_4K; { void* p = ::malloc(SIZE_16M); data_page_size = os::Aix::query_pagesize(p); ::free(p); } // query default shm page size (LDR_CNTRL SHMPSIZE) --- 366,383 ---- // This really would surprise me. assert(_page_size == SIZE_4K, "surprise!"); ! // 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) // or by environment variable LDR_CNTRL (suboption DATAPSIZE). If none is given, // default should be 4K. size_t data_page_size = SIZE_4K; { void* p = ::malloc(SIZE_16M); + guarantee(p != NULL, "malloc failed"); data_page_size = os::Aix::query_pagesize(p); ::free(p); } // query default shm page size (LDR_CNTRL SHMPSIZE)
*** 509,597 **** fprintf(stderr, "Multipage error details: %d\n", g_multipage_error); } } // end os::Aix::query_multipage_support() ! ! // The code for this method was initially derived from the version in os_linux.cpp 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 EXTENSIONS_DIR "/lib/ext" #define ENDORSED_DIR "/lib/endorsed" // sysclasspath, java_home, dll_dir ! char *home_path; ! char *dll_path; char *pslash; ! char buf[MAXPATHLEN]; ! os::jvm_path(buf, sizeof(buf)); // 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} } ! ! dll_path = malloc(strlen(buf) + 1); ! strcpy(dll_path, buf); ! Arguments::set_dll_dir(dll_path); if (pslash != NULL) { pslash = strrchr(buf, '/'); if (pslash != NULL) { ! *pslash = '\0'; // get rid of /<arch> pslash = strrchr(buf, '/'); if (pslash != NULL) { ! *pslash = '\0'; // get rid of /lib } } } ! home_path = malloc(strlen(buf) + 1); ! strcpy(home_path, buf); ! Arguments::set_java_home(home_path); ! ! if (!set_boot_path('/', ':')) return; ! // 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. ! char *ld_library_path; ! ! // Construct the invariant part of ld_library_path. ! ld_library_path = (char *) malloc(sizeof(DEFAULT_LIBPATH)); ! 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); ! Arguments::set_library_path(ld_library_path); ! // Extensions directories ! char* cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(EXTENSIONS_DIR)); ! sprintf(cbuf, "%s" EXTENSIONS_DIR, Arguments::get_java_home()); ! Arguments::set_ext_dirs(cbuf); // Endorsed standards default directory. ! cbuf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR)); ! sprintf(cbuf, "%s" ENDORSED_DIR, Arguments::get_java_home()); ! Arguments::set_endorsed_dirs(cbuf); - #undef malloc #undef DEFAULT_LIBPATH #undef EXTENSIONS_DIR #undef ENDORSED_DIR } --- 500,581 ---- fprintf(stderr, "Multipage error details: %d\n", g_multipage_error); } } // end os::Aix::query_multipage_support() ! // The code for this method was initially derived from the version in os_linux.cpp. void os::init_system_properties_values() { ! #define DEFAULT_LIBPATH "/usr/lib:/lib" #define EXTENSIONS_DIR "/lib/ext" #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 ! { 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 /<arch>. pslash = strrchr(buf, '/'); if (pslash != NULL) { ! *pslash = '\0'; // Get rid of /lib. } } } + Arguments::set_java_home(buf); ! if (!set_boot_path('/', ':')) { ! return; ! } ! } ! // 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. ! // Get the user setting of LIBPATH. char *v = ::getenv("LIBPATH"); if (v == NULL) { v = ""; } ! // 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", v, DEFAULT_LIBPATH); Arguments::set_library_path(ld_library_path); + FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal); ! // Extensions directories. ! sprintf(buf, "%s" EXTENSIONS_DIR, Arguments::get_java_home()); ! Arguments::set_ext_dirs(buf); // Endorsed standards default directory. ! sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); ! Arguments::set_endorsed_dirs(buf); #undef DEFAULT_LIBPATH #undef EXTENSIONS_DIR #undef ENDORSED_DIR }