< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page




2072 static void _print_ascii_file_h(const char* header, const char* filename, outputStream* st) {
2073   st->print_cr("%s:", header);
2074   if (!_print_ascii_file(filename, st)) {
2075     st->print_cr("<Not Available>");
2076   }
2077 }
2078 
2079 void os::print_dll_info(outputStream *st) {
2080   st->print_cr("Dynamic libraries:");
2081 
2082   char fname[32];
2083   pid_t pid = os::Linux::gettid();
2084 
2085   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
2086 
2087   if (!_print_ascii_file(fname, st)) {
2088     st->print("Can not get library information for pid = %d\n", pid);
2089   }
2090 }
2091 
2092 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
2093   FILE *procmapsFile = NULL;















2094 
2095   // Open the procfs maps file for the current process
2096   if ((procmapsFile = fopen("/proc/self/maps", "r")) != NULL) {
2097     // Allocate PATH_MAX for file name plus a reasonable size for other fields.
2098     char line[PATH_MAX + 100];
2099 
2100     // Read line by line from 'file'
2101     while (fgets(line, sizeof(line), procmapsFile) != NULL) {
2102       u8 base, top, inode;
2103       char name[sizeof(line)];
2104 
2105       // Parse fields from line, discard perms, offset and device
2106       int matches = sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %*s %*s %*s " INT64_FORMAT " %s",
2107              &base, &top, &inode, name);
2108       // the last entry 'name' is empty for some entries, so we might have 3 matches instead of 4 for some lines
2109       if (matches < 3) continue;
2110       if (matches == 3) name[0] = '\0';
2111 
2112       // Filter by inode 0 so that we only get file system mapped files.
2113       if (inode != 0) {
2114 
2115         // Call callback with the fields of interest
2116         if(callback(name, (address)base, (address)top, param)) {
2117           // Oops abort, callback aborted
2118           fclose(procmapsFile);
2119           return 1;
2120         }




2121       }
2122     }
2123     fclose(procmapsFile);
2124   }
2125   return 0;






2126 }
2127 
2128 void os::print_os_info_brief(outputStream* st) {
2129   os::Linux::print_distro_info(st);
2130 
2131   os::Posix::print_uname_info(st);
2132 
2133   os::Linux::print_libversion_info(st);
2134 
2135 }
2136 
2137 void os::print_os_info(outputStream* st) {
2138   st->print("OS:");
2139 
2140   os::Linux::print_distro_info(st);
2141 
2142   os::Posix::print_uname_info(st);
2143 
2144   os::Linux::print_uptime_info(st);
2145 




2072 static void _print_ascii_file_h(const char* header, const char* filename, outputStream* st) {
2073   st->print_cr("%s:", header);
2074   if (!_print_ascii_file(filename, st)) {
2075     st->print_cr("<Not Available>");
2076   }
2077 }
2078 
2079 void os::print_dll_info(outputStream *st) {
2080   st->print_cr("Dynamic libraries:");
2081 
2082   char fname[32];
2083   pid_t pid = os::Linux::gettid();
2084 
2085   jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
2086 
2087   if (!_print_ascii_file(fname, st)) {
2088     st->print("Can not get library information for pid = %d\n", pid);
2089   }
2090 }
2091 
2092 struct loaded_modules_info_param {
2093   os::LoadedModulesCallbackFunc callback;
2094   void *param;
2095 };
2096 
2097 static int dl_iterate_callback(struct dl_phdr_info *info, size_t size, void *data) {
2098   if ((info->dlpi_name == NULL) || (*info->dlpi_name == '\0')) {
2099     return 0;
2100   }
2101 
2102   struct loaded_modules_info_param *callback_param = reinterpret_cast<struct loaded_modules_info_param *>(data);
2103   address base = NULL;
2104   address top = NULL;
2105   for (int idx = 0; idx < info->dlpi_phnum; idx++) {
2106     const ElfW(Phdr) *phdr = info->dlpi_phdr + idx;
2107     if (phdr->p_type == PT_LOAD) {
2108       address raw_phdr_base = reinterpret_cast<address>(info->dlpi_addr + phdr->p_vaddr);
2109 
2110       address phdr_base = align_down(raw_phdr_base, phdr->p_align);
2111       if ((base == NULL) || (base > phdr_base)) {
2112         base = phdr_base;






















2113       }
2114 
2115       address phdr_top = align_up(raw_phdr_base + phdr->p_memsz, phdr->p_align);
2116       if ((top == NULL) || (top < phdr_top)) {
2117         top = phdr_top;
2118       }
2119     }

2120   }
2121 
2122   return callback_param->callback(info->dlpi_name, base, top, callback_param->param);
2123 }
2124 
2125 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
2126   struct loaded_modules_info_param callback_param = {callback, param};
2127   return dl_iterate_phdr(&dl_iterate_callback, &callback_param);
2128 }
2129 
2130 void os::print_os_info_brief(outputStream* st) {
2131   os::Linux::print_distro_info(st);
2132 
2133   os::Posix::print_uname_info(st);
2134 
2135   os::Linux::print_libversion_info(st);
2136 
2137 }
2138 
2139 void os::print_os_info(outputStream* st) {
2140   st->print("OS:");
2141 
2142   os::Linux::print_distro_info(st);
2143 
2144   os::Posix::print_uname_info(st);
2145 
2146   os::Linux::print_uptime_info(st);
2147 


< prev index next >