src/os/solaris/vm/os_solaris.cpp

Print this page




1907       if (pelements[i] != NULL) {
1908         FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
1909       }
1910     }
1911     if (pelements != NULL) {
1912       FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
1913     }
1914   } else {
1915     snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
1916     retval = true;
1917   }
1918   return retval;
1919 }
1920 
1921 // check if addr is inside libjvm.so
1922 bool os::address_is_in_vm(address addr) {
1923   static address libjvm_base_addr;
1924   Dl_info dlinfo;
1925 
1926   if (libjvm_base_addr == NULL) {
1927     dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo);
1928     libjvm_base_addr = (address)dlinfo.dli_fbase;

1929     assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
1930   }
1931 
1932   if (dladdr((void *)addr, &dlinfo)) {
1933     if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
1934   }
1935 
1936   return false;
1937 }
1938 
1939 typedef int (*dladdr1_func_type) (void *, Dl_info *, void **, int);
1940 static dladdr1_func_type dladdr1_func = NULL;
1941 
1942 bool os::dll_address_to_function_name(address addr, char *buf,
1943                                       int buflen, int * offset) {



1944   Dl_info dlinfo;
1945 
1946   // dladdr1_func was initialized in os::init()
1947   if (dladdr1_func){
1948       // yes, we have dladdr1
1949 
1950       // Support for dladdr1 is checked at runtime; it may be
1951       // available even if the vm is built on a machine that does
1952       // not have dladdr1 support.  Make sure there is a value for
1953       // RTLD_DL_SYMENT.
1954       #ifndef RTLD_DL_SYMENT
1955       #define RTLD_DL_SYMENT 1
1956       #endif
1957 #ifdef _LP64
1958       Elf64_Sym * info;
1959 #else
1960       Elf32_Sym * info;
1961 #endif
1962       if (dladdr1_func((void *)addr, &dlinfo, (void **)&info,
1963                        RTLD_DL_SYMENT)) {
1964         if ((char *)dlinfo.dli_saddr + info->st_size > (char *)addr) {
1965           if (buf != NULL) {
1966             if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen))


1967               jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
1968             }
1969             if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
1970             return true;
1971         }
1972       }
1973       if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) {

1974         if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
1975            buf, buflen, offset, dlinfo.dli_fname)) {
1976           return true;
1977         }
1978       }
1979       if (buf != NULL) buf[0] = '\0';

1980       if (offset != NULL) *offset  = -1;
1981       return false;
1982   } else {
1983       // no, only dladdr is available
1984       if (dladdr((void *)addr, &dlinfo)) {
1985         if (buf != NULL) {
1986           if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen))

1987             jio_snprintf(buf, buflen, dlinfo.dli_sname);
1988         }
1989         if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
1990         return true;
1991       } else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) {


1992         if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
1993           buf, buflen, offset, dlinfo.dli_fname)) {
1994           return true;
1995         }
1996       }
1997       if (buf != NULL) buf[0] = '\0';

1998       if (offset != NULL) *offset  = -1;
1999       return false;
2000   }
2001 }
2002 
2003 bool os::dll_address_to_library_name(address addr, char* buf,
2004                                      int buflen, int* offset) {



2005   Dl_info dlinfo;
2006 
2007   if (dladdr((void*)addr, &dlinfo)){
2008      if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
2009      if (offset) *offset = addr - (address)dlinfo.dli_fbase;




2010      return true;
2011   } else {
2012      if (buf) buf[0] = '\0';
2013      if (offset) *offset = -1;
2014      return false;
2015   }
2016 }
2017 
2018 // Prints the names and full paths of all opened dynamic libraries
2019 // for current process
2020 void os::print_dll_info(outputStream * st) {
2021     Dl_info dli;
2022     void *handle;
2023     Link_map *map;
2024     Link_map *p;
2025 
2026     st->print_cr("Dynamic libraries:"); st->flush();
2027 
2028     if (!dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli)) {

2029         st->print_cr("Error: Cannot print dynamic libraries.");
2030         return;
2031     }
2032     handle = dlopen(dli.dli_fname, RTLD_LAZY);
2033     if (handle == NULL) {
2034         st->print_cr("Error: Cannot print dynamic libraries.");
2035         return;
2036     }
2037     dlinfo(handle, RTLD_DI_LINKMAP, &map);
2038     if (map == NULL) {
2039         st->print_cr("Error: Cannot print dynamic libraries.");
2040         return;
2041     }
2042 
2043     while (map->l_prev != NULL)
2044         map = map->l_prev;
2045 
2046     while (map != NULL) {
2047         st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
2048         map = map->l_next;


2458 
2459 static char saved_jvm_path[MAXPATHLEN] = { 0 };
2460 
2461 // Find the full path to the current module, libjvm.so
2462 void os::jvm_path(char *buf, jint buflen) {
2463   // Error checking.
2464   if (buflen < MAXPATHLEN) {
2465     assert(false, "must use a large-enough buffer");
2466     buf[0] = '\0';
2467     return;
2468   }
2469   // Lazy resolve the path to current module.
2470   if (saved_jvm_path[0] != 0) {
2471     strcpy(buf, saved_jvm_path);
2472     return;
2473   }
2474 
2475   Dl_info dlinfo;
2476   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
2477   assert(ret != 0, "cannot locate libjvm");

2478   realpath((char *)dlinfo.dli_fname, buf);




2479 
2480   if (Arguments::created_by_gamma_launcher()) {
2481     // Support for the gamma launcher.  Typical value for buf is
2482     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".  If "/jre/lib/" appears at
2483     // the right place in the string, then assume we are installed in a JDK and
2484     // we're done.  Otherwise, check for a JAVA_HOME environment variable and fix
2485     // up the path so it looks like libjvm.so is installed there (append a
2486     // fake suffix hotspot/libjvm.so).
2487     const char *p = buf + strlen(buf) - 1;
2488     for (int count = 0; p > buf && count < 5; ++count) {
2489       for (--p; p > buf && *p != '/'; --p)
2490         /* empty */ ;
2491     }
2492 
2493     if (strncmp(p, "/jre/lib/", 9) != 0) {
2494       // Look for JAVA_HOME in the environment.
2495       char* java_home_var = ::getenv("JAVA_HOME");
2496       if (java_home_var != NULL && java_home_var[0] != 0) {
2497         char cpu_arch[12];
2498         char* jrelib_p;


6060     return false;
6061   }
6062 }
6063 
6064 // System loadavg support.  Returns -1 if load average cannot be obtained.
6065 // Return the load average for our processor set if the primitive exists
6066 // (Solaris 9 and later).  Otherwise just return system wide loadavg.
6067 int os::loadavg(double loadavg[], int nelem) {
6068   if (pset_getloadavg_ptr != NULL) {
6069     return (*pset_getloadavg_ptr)(PS_MYID, loadavg, nelem);
6070   } else {
6071     return ::getloadavg(loadavg, nelem);
6072   }
6073 }
6074 
6075 //---------------------------------------------------------------------------------
6076 
6077 bool os::find(address addr, outputStream* st) {
6078   Dl_info dlinfo;
6079   memset(&dlinfo, 0, sizeof(dlinfo));
6080   if (dladdr(addr, &dlinfo)) {
6081 #ifdef _LP64
6082     st->print("0x%016lx: ", addr);
6083 #else
6084     st->print("0x%08x: ", addr);
6085 #endif
6086     if (dlinfo.dli_sname != NULL)
6087       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
6088     else if (dlinfo.dli_fname)
6089       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
6090     else
6091       st->print("<absolute address>");
6092     if (dlinfo.dli_fname)  st->print(" in %s", dlinfo.dli_fname);
6093 #ifdef _LP64
6094     if (dlinfo.dli_fbase)  st->print(" at 0x%016lx", dlinfo.dli_fbase);
6095 #else
6096     if (dlinfo.dli_fbase)  st->print(" at 0x%08x", dlinfo.dli_fbase);
6097 #endif
6098     st->cr();
6099 
6100     if (Verbose) {
6101       // decode some bytes around the PC
6102       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
6103       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
6104       address       lowest = (address) dlinfo.dli_sname;
6105       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
6106       if (begin < lowest)  begin = lowest;
6107       Dl_info dlinfo2;
6108       if (dladdr(end, &dlinfo2) && dlinfo2.dli_saddr != dlinfo.dli_saddr
6109           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
6110         end = (address) dlinfo2.dli_saddr;
6111       Disassembler::decode(begin, end, st);
6112     }
6113     return true;
6114   }
6115   return false;
6116 }
6117 
6118 // Following function has been added to support HotSparc's libjvm.so running
6119 // under Solaris production JDK 1.2.2 / 1.3.0.  These came from
6120 // src/solaris/hpi/native_threads in the EVM codebase.
6121 //
6122 // NOTE: This is no longer needed in the 1.3.1 and 1.4 production release
6123 // libraries and should thus be removed. We will leave it behind for a while
6124 // until we no longer want to able to run on top of 1.3.0 Solaris production
6125 // JDK. See 4341971.
6126 
6127 #define STACK_SLACK 0x800
6128 




1907       if (pelements[i] != NULL) {
1908         FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal);
1909       }
1910     }
1911     if (pelements != NULL) {
1912       FREE_C_HEAP_ARRAY(char*, pelements, mtInternal);
1913     }
1914   } else {
1915     snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
1916     retval = true;
1917   }
1918   return retval;
1919 }
1920 
1921 // check if addr is inside libjvm.so
1922 bool os::address_is_in_vm(address addr) {
1923   static address libjvm_base_addr;
1924   Dl_info dlinfo;
1925 
1926   if (libjvm_base_addr == NULL) {
1927     if (dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo) != 0) {
1928       libjvm_base_addr = (address)dlinfo.dli_fbase;
1929     }
1930     assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm");
1931   }
1932 
1933   if (dladdr((void *)addr, &dlinfo) != 0) {
1934     if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true;
1935   }
1936 
1937   return false;
1938 }
1939 
1940 typedef int (*dladdr1_func_type) (void *, Dl_info *, void **, int);
1941 static dladdr1_func_type dladdr1_func = NULL;
1942 
1943 bool os::dll_address_to_function_name(address addr, char *buf,
1944                                       int buflen, int * offset) {
1945   // buf is not optional, but offset is optional
1946   assert(buf != NULL, "sanity check");
1947 
1948   Dl_info dlinfo;
1949 
1950   // dladdr1_func was initialized in os::init()
1951   if (dladdr1_func != NULL) {
1952       // yes, we have dladdr1
1953 
1954       // Support for dladdr1 is checked at runtime; it may be
1955       // available even if the vm is built on a machine that does
1956       // not have dladdr1 support.  Make sure there is a value for
1957       // RTLD_DL_SYMENT.
1958       #ifndef RTLD_DL_SYMENT
1959       #define RTLD_DL_SYMENT 1
1960       #endif
1961 #ifdef _LP64
1962       Elf64_Sym * info;
1963 #else
1964       Elf32_Sym * info;
1965 #endif
1966       if (dladdr1_func((void *)addr, &dlinfo, (void **)&info,
1967                        RTLD_DL_SYMENT) != 0) {
1968         // see if we have a matching symbol that covers our address
1969         if (dlinfo.dli_saddr != NULL &&
1970             (char *)dlinfo.dli_saddr + info->st_size > (char *)addr) {
1971           if (dlinfo.dli_sname != NULL) {
1972             if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
1973               jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname);
1974             }
1975             if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
1976             return true;
1977           }
1978         }
1979         // no matching symbol so try for just file info
1980         if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
1981           if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
1982                               buf, buflen, offset, dlinfo.dli_fname)) {
1983             return true;
1984           }
1985         }
1986       }
1987       buf[0] = '\0';
1988       if (offset != NULL) *offset  = -1;
1989       return false;
1990   } else {
1991       // no, only dladdr is available
1992       if (dladdr((void *)addr, &dlinfo) != 0) {
1993         // see if we have a matching symbol
1994         if (dlinfo.dli_saddr != NULL && dlinfo.dli_sname != NULL) {
1995           if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) {
1996             jio_snprintf(buf, buflen, dlinfo.dli_sname);
1997           }
1998           if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
1999           return true;
2000         }
2001         // no matching symbol so try for just file info
2002         if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != NULL) {
2003           if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
2004                               buf, buflen, offset, dlinfo.dli_fname)) {
2005             return true;
2006           }
2007         }
2008       }
2009       buf[0] = '\0';
2010       if (offset != NULL) *offset  = -1;
2011       return false;
2012   }
2013 }
2014 
2015 bool os::dll_address_to_library_name(address addr, char* buf,
2016                                      int buflen, int* offset) {
2017   // buf is not optional, but offset is optional
2018   assert(buf != NULL, "sanity check");
2019 
2020   Dl_info dlinfo;
2021 
2022   if (dladdr((void*)addr, &dlinfo) != 0) {
2023      if (dlinfo.dli_fname != NULL) {
2024        jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
2025      }
2026      if (dlinfo.dli_fbase != NULL && offset != NULL) {
2027        *offset = addr - (address)dlinfo.dli_fbase;
2028      }
2029      return true;
2030   } else {
2031      buf[0] = '\0';
2032      if (offset) *offset = -1;
2033      return false;
2034   }
2035 }
2036 
2037 // Prints the names and full paths of all opened dynamic libraries
2038 // for current process
2039 void os::print_dll_info(outputStream * st) {
2040     Dl_info dli;
2041     void *handle;
2042     Link_map *map;
2043     Link_map *p;
2044 
2045     st->print_cr("Dynamic libraries:"); st->flush();
2046 
2047     if (dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli) == 0 ||
2048         dli.dli_fname == NULL) {
2049         st->print_cr("Error: Cannot print dynamic libraries.");
2050         return;
2051     }
2052     handle = dlopen(dli.dli_fname, RTLD_LAZY);
2053     if (handle == NULL) {
2054         st->print_cr("Error: Cannot print dynamic libraries.");
2055         return;
2056     }
2057     dlinfo(handle, RTLD_DI_LINKMAP, &map);
2058     if (map == NULL) {
2059         st->print_cr("Error: Cannot print dynamic libraries.");
2060         return;
2061     }
2062 
2063     while (map->l_prev != NULL)
2064         map = map->l_prev;
2065 
2066     while (map != NULL) {
2067         st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
2068         map = map->l_next;


2478 
2479 static char saved_jvm_path[MAXPATHLEN] = { 0 };
2480 
2481 // Find the full path to the current module, libjvm.so
2482 void os::jvm_path(char *buf, jint buflen) {
2483   // Error checking.
2484   if (buflen < MAXPATHLEN) {
2485     assert(false, "must use a large-enough buffer");
2486     buf[0] = '\0';
2487     return;
2488   }
2489   // Lazy resolve the path to current module.
2490   if (saved_jvm_path[0] != 0) {
2491     strcpy(buf, saved_jvm_path);
2492     return;
2493   }
2494 
2495   Dl_info dlinfo;
2496   int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo);
2497   assert(ret != 0, "cannot locate libjvm");
2498   if (ret != 0 && dlinfo.dli_fname != NULL) {
2499     realpath((char *)dlinfo.dli_fname, buf);
2500   } else {
2501     buf[0] = '\0';
2502     return;
2503   }
2504 
2505   if (Arguments::created_by_gamma_launcher()) {
2506     // Support for the gamma launcher.  Typical value for buf is
2507     // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so".  If "/jre/lib/" appears at
2508     // the right place in the string, then assume we are installed in a JDK and
2509     // we're done.  Otherwise, check for a JAVA_HOME environment variable and fix
2510     // up the path so it looks like libjvm.so is installed there (append a
2511     // fake suffix hotspot/libjvm.so).
2512     const char *p = buf + strlen(buf) - 1;
2513     for (int count = 0; p > buf && count < 5; ++count) {
2514       for (--p; p > buf && *p != '/'; --p)
2515         /* empty */ ;
2516     }
2517 
2518     if (strncmp(p, "/jre/lib/", 9) != 0) {
2519       // Look for JAVA_HOME in the environment.
2520       char* java_home_var = ::getenv("JAVA_HOME");
2521       if (java_home_var != NULL && java_home_var[0] != 0) {
2522         char cpu_arch[12];
2523         char* jrelib_p;


6085     return false;
6086   }
6087 }
6088 
6089 // System loadavg support.  Returns -1 if load average cannot be obtained.
6090 // Return the load average for our processor set if the primitive exists
6091 // (Solaris 9 and later).  Otherwise just return system wide loadavg.
6092 int os::loadavg(double loadavg[], int nelem) {
6093   if (pset_getloadavg_ptr != NULL) {
6094     return (*pset_getloadavg_ptr)(PS_MYID, loadavg, nelem);
6095   } else {
6096     return ::getloadavg(loadavg, nelem);
6097   }
6098 }
6099 
6100 //---------------------------------------------------------------------------------
6101 
6102 bool os::find(address addr, outputStream* st) {
6103   Dl_info dlinfo;
6104   memset(&dlinfo, 0, sizeof(dlinfo));
6105   if (dladdr(addr, &dlinfo) != 0) {
6106 #ifdef _LP64
6107     st->print("0x%016lx: ", addr);
6108 #else
6109     st->print("0x%08x: ", addr);
6110 #endif
6111     if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) {
6112       st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr);
6113     } else if (dlinfo.dli_fbase != NULL)
6114       st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase);
6115     else
6116       st->print("<absolute address>");
6117     if (dlinfo.dli_fname != NULL)  st->print(" in %s", dlinfo.dli_fname);
6118 #ifdef _LP64
6119     if (dlinfo.dli_fbase != NULL)  st->print(" at 0x%016lx", dlinfo.dli_fbase);
6120 #else
6121     if (dlinfo.dli_fbase != NULL)  st->print(" at 0x%08x", dlinfo.dli_fbase);
6122 #endif
6123     st->cr();
6124 
6125     if (Verbose) {
6126       // decode some bytes around the PC
6127       address begin = clamp_address_in_page(addr-40, addr, os::vm_page_size());
6128       address end   = clamp_address_in_page(addr+40, addr, os::vm_page_size());
6129       address       lowest = (address) dlinfo.dli_sname;
6130       if (!lowest)  lowest = (address) dlinfo.dli_fbase;
6131       if (begin < lowest)  begin = lowest;
6132       Dl_info dlinfo2;
6133       if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr
6134           && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin)
6135         end = (address) dlinfo2.dli_saddr;
6136       Disassembler::decode(begin, end, st);
6137     }
6138     return true;
6139   }
6140   return false;
6141 }
6142 
6143 // Following function has been added to support HotSparc's libjvm.so running
6144 // under Solaris production JDK 1.2.2 / 1.3.0.  These came from
6145 // src/solaris/hpi/native_threads in the EVM codebase.
6146 //
6147 // NOTE: This is no longer needed in the 1.3.1 and 1.4 production release
6148 // libraries and should thus be removed. We will leave it behind for a while
6149 // until we no longer want to able to run on top of 1.3.0 Solaris production
6150 // JDK. See 4341971.
6151 
6152 #define STACK_SLACK 0x800
6153