src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8026324.02 Sdiff src/os/linux/vm

src/os/linux/vm/os_linux.cpp

Print this page




2026 // Most Linux distributions have a /etc/XXX-release file, which contains
2027 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2028 // file that also contains the OS version string. Some have more than one
2029 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2030 // /etc/redhat-release.), so the order is important.
2031 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2032 // their own specific XXX-release file as well as a redhat-release file.
2033 // Because of this the XXX-release file needs to be searched for before the
2034 // redhat-release file.
2035 // Since Red Hat has a lsb-release file that is not very descriptive the
2036 // search for redhat-release needs to be before lsb-release.
2037 // Since the lsb-release file is the new standard it needs to be searched
2038 // before the older style release files.
2039 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
2040 // next to last resort.  The os-release file is a new standard that contains
2041 // distribution information and the system-release file seems to be an old
2042 // standard that has been replaced by the lsb-release and os-release files.
2043 // Searching for the debian_version file is the last resort.  It contains
2044 // an informative string like "6.0.6" or "wheezy/sid". Because of this
2045 // "Debian " is printed before the contents of the debian_version file.

















2046 void os::Linux::print_distro_info(outputStream* st) {
2047   if (!_print_ascii_file("/etc/oracle-release", st) &&
2048       !_print_ascii_file("/etc/mandriva-release", st) &&
2049       !_print_ascii_file("/etc/mandrake-release", st) &&
2050       !_print_ascii_file("/etc/sun-release", st) &&
2051       !_print_ascii_file("/etc/redhat-release", st) &&
2052       !_print_ascii_file("/etc/lsb-release", st) &&
2053       !_print_ascii_file("/etc/SuSE-release", st) &&
2054       !_print_ascii_file("/etc/turbolinux-release", st) &&
2055       !_print_ascii_file("/etc/gentoo-release", st) &&
2056       !_print_ascii_file("/etc/ltib-release", st) &&
2057       !_print_ascii_file("/etc/angstrom-version", st) &&
2058       !_print_ascii_file("/etc/system-release", st) &&
2059       !_print_ascii_file("/etc/os-release", st)) {
2060 
2061     if (file_exists("/etc/debian_version")) {
2062       st->print("Debian ");
2063       _print_ascii_file("/etc/debian_version", st);
2064     } else {
2065       st->print("Linux");
2066     }
2067   }
2068   st->cr();
2069 }
2070 


















































2071 void os::Linux::print_libversion_info(outputStream* st) {
2072   // libc, pthread
2073   st->print("libc:");
2074   st->print("%s ", os::Linux::glibc_version());
2075   st->print("%s ", os::Linux::libpthread_version());
2076   st->cr();
2077 }
2078 
2079 void os::Linux::print_full_memory_info(outputStream* st) {
2080   st->print("\n/proc/meminfo:\n");
2081   _print_ascii_file("/proc/meminfo", st);
2082   st->cr();
2083 }
2084 
2085 void os::print_memory_info(outputStream* st) {
2086 
2087   st->print("Memory:");
2088   st->print(" %dk page", os::vm_page_size()>>10);
2089 
2090   // values in struct sysinfo are "unsigned long"


2131           st->print_raw(buf);
2132           fclose(fp);
2133           return true;
2134         }
2135       }
2136     }
2137     fclose(fp);
2138   }
2139 #endif // x86 platforms
2140   return false;
2141 }
2142 
2143 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2144   // Only print the model name if the platform provides this as a summary
2145   if (!print_model_name_and_flags(st, buf, buflen)) {
2146     st->print("\n/proc/cpuinfo:\n");
2147     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2148       st->print_cr("  <Not Available>");
2149     }
2150   }









































2151 }
2152 
2153 void os::print_siginfo(outputStream* st, void* siginfo) {
2154   const siginfo_t* si = (const siginfo_t*)siginfo;
2155 
2156   os::Posix::print_siginfo_brief(st, si);
2157 #if INCLUDE_CDS
2158   if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
2159       UseSharedSpaces) {
2160     FileMapInfo* mapinfo = FileMapInfo::current_info();
2161     if (mapinfo->is_in_shared_space(si->si_addr)) {
2162       st->print("\n\nError accessing class data sharing archive."   \
2163                 " Mapped file inaccessible during execution, "      \
2164                 " possible disk/network problem.");
2165     }
2166   }
2167 #endif
2168   st->cr();
2169 }
2170 




2026 // Most Linux distributions have a /etc/XXX-release file, which contains
2027 // the OS version string. Newer Linux distributions have a /etc/lsb-release
2028 // file that also contains the OS version string. Some have more than one
2029 // /etc/XXX-release file (e.g. Mandrake has both /etc/mandrake-release and
2030 // /etc/redhat-release.), so the order is important.
2031 // Any Linux that is based on Redhat (i.e. Oracle, Mandrake, Sun JDS...) have
2032 // their own specific XXX-release file as well as a redhat-release file.
2033 // Because of this the XXX-release file needs to be searched for before the
2034 // redhat-release file.
2035 // Since Red Hat has a lsb-release file that is not very descriptive the
2036 // search for redhat-release needs to be before lsb-release.
2037 // Since the lsb-release file is the new standard it needs to be searched
2038 // before the older style release files.
2039 // Searching system-release (Red Hat) and os-release (other Linuxes) are a
2040 // next to last resort.  The os-release file is a new standard that contains
2041 // distribution information and the system-release file seems to be an old
2042 // standard that has been replaced by the lsb-release and os-release files.
2043 // Searching for the debian_version file is the last resort.  It contains
2044 // an informative string like "6.0.6" or "wheezy/sid". Because of this
2045 // "Debian " is printed before the contents of the debian_version file.
2046 
2047 const char* distro_files[] = {
2048   "/etc/oracle-release",
2049   "/etc/mandriva-release",
2050   "/etc/mandrake-release",
2051   "/etc/sun-release",
2052   "/etc/redhat-release",
2053   "/etc/lsb-release",
2054   "/etc/SuSE-release",
2055   "/etc/turbolinux-release",
2056   "/etc/gentoo-release",
2057   "/etc/ltib-release",
2058   "/etc/angstrom-version",
2059   "/etc/system-release",
2060   "/etc/os-release",
2061   NULL };
2062 
2063 void os::Linux::print_distro_info(outputStream* st) {
2064   for (int i = 0;; i++) {
2065     const char* file = distro_files[i];
2066     if (file == NULL) {
2067       break;  // done
2068     }
2069     // If file prints, we found it.
2070     if (_print_ascii_file(file, st)) {
2071       return;
2072     }
2073   }



2074 
2075   if (file_exists("/etc/debian_version")) {
2076     st->print("Debian ");
2077     _print_ascii_file("/etc/debian_version", st);
2078   } else {
2079     st->print("Linux");
2080   }

2081   st->cr();
2082 }
2083 
2084 static void parse_os_info(char* distro, size_t length, const char* file) {
2085   FILE* fp = fopen(file, "r");
2086   if (fp != NULL) {
2087     char buf[256];
2088     // get last line of the file.
2089     while (!feof(fp)) {
2090       fgets(buf, sizeof(buf), fp);
2091     }
2092     // Edit out ubuntu things
2093     if (strstr(buf, "DISTRIB_DESCRIPTION=") != NULL) {
2094       char* ptr = strstr(buf, "\"");
2095       if (ptr != NULL) {
2096         ptr++; // go beyond first "
2097         char* nl = strchr(ptr, '\"');
2098         if (nl != NULL) *nl = '\0';
2099         strncpy(distro, ptr, length);
2100         fclose(fp);
2101         return;
2102       }
2103     } else {
2104       // if not Ubuntu, print out whole line minus \n
2105       char* nl = strchr(buf, '\n');
2106       if (nl != NULL) *nl = '\0';
2107       strncpy(distro, buf, length);
2108       fclose(fp);
2109       return;
2110     }
2111   }
2112 }
2113 
2114 void os::get_summary_os_info(char* buf, size_t buflen) {
2115   for (int i = 0;; i++) {
2116     const char* file = distro_files[i];
2117     if (file == NULL) {
2118       break; // ran out of distro_files
2119     }
2120     if (file_exists(file)) {
2121       parse_os_info(buf, buflen, file);
2122       return;
2123     }
2124   }
2125   // special case for debian
2126   if (file_exists("/etc/debian_version")) {
2127     strncpy(buf, "Debian ", buflen);
2128     parse_os_info(&buf[7], buflen-7, "/etc/debian_version");
2129   } else {
2130     strncpy(buf, "Linux", buflen);
2131   }
2132 }
2133 
2134 void os::Linux::print_libversion_info(outputStream* st) {
2135   // libc, pthread
2136   st->print("libc:");
2137   st->print("%s ", os::Linux::glibc_version());
2138   st->print("%s ", os::Linux::libpthread_version());
2139   st->cr();
2140 }
2141 
2142 void os::Linux::print_full_memory_info(outputStream* st) {
2143   st->print("\n/proc/meminfo:\n");
2144   _print_ascii_file("/proc/meminfo", st);
2145   st->cr();
2146 }
2147 
2148 void os::print_memory_info(outputStream* st) {
2149 
2150   st->print("Memory:");
2151   st->print(" %dk page", os::vm_page_size()>>10);
2152 
2153   // values in struct sysinfo are "unsigned long"


2194           st->print_raw(buf);
2195           fclose(fp);
2196           return true;
2197         }
2198       }
2199     }
2200     fclose(fp);
2201   }
2202 #endif // x86 platforms
2203   return false;
2204 }
2205 
2206 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2207   // Only print the model name if the platform provides this as a summary
2208   if (!print_model_name_and_flags(st, buf, buflen)) {
2209     st->print("\n/proc/cpuinfo:\n");
2210     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2211       st->print_cr("  <Not Available>");
2212     }
2213   }
2214 }
2215 
2216 const char* search_string = IA32_ONLY("model name") AMD64_ONLY("model name") 
2217                             IA64_ONLY("") SPARC_ONLY("cpu")
2218                             ARM32_ONLY("Processor") PPC_ONLY("Processor") AARCH64_ONLY("Processor");
2219 
2220 // Parses the cpuinfo file for string representing the model name.
2221 void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
2222   FILE* fp = fopen("/proc/cpuinfo", "r");
2223   if (fp != NULL) {
2224     while (!feof(fp)) {
2225       char buf[256];
2226       if (fgets(buf, sizeof(buf), fp)) {
2227         char* start = strstr(buf, search_string);
2228         if (start != NULL) {
2229           char *ptr = start + strlen(search_string);
2230           char *end = buf + strlen(buf);
2231           while (ptr != end) {
2232              // skip whitespace and colon for the rest of the name.
2233              if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') {
2234                break;
2235              }
2236              ptr++;
2237           }
2238           if (ptr != end) {
2239             // reasonable string, get rid of newline and keep the rest
2240             char* nl = strchr(buf, '\n');
2241             if (nl != NULL) *nl = '\0';
2242             strncpy(cpuinfo, ptr, length);
2243             fclose(fp);
2244             return;
2245           }
2246         }
2247       }
2248     }
2249   }
2250   // cpuinfo not found or parsing failed, just print generic string.  The entire
2251   // /proc/cpuinfo file will be printed later in the file (or enough of it for x86)
2252   strncpy(cpuinfo, IA32_ONLY("x86 IA32") AMD64_ONLY("x86 IA64") 
2253                    IA64_ONLY("IA64") SPARC_ONLY("sparcv9")
2254                    ARM32_ONLY("ARM32") PPC_ONLY("PPC64") AARCH64_ONLY("AArch64"), length);
2255 }
2256 
2257 void os::print_siginfo(outputStream* st, void* siginfo) {
2258   const siginfo_t* si = (const siginfo_t*)siginfo;
2259 
2260   os::Posix::print_siginfo_brief(st, si);
2261 #if INCLUDE_CDS
2262   if (si && (si->si_signo == SIGBUS || si->si_signo == SIGSEGV) &&
2263       UseSharedSpaces) {
2264     FileMapInfo* mapinfo = FileMapInfo::current_info();
2265     if (mapinfo->is_in_shared_space(si->si_addr)) {
2266       st->print("\n\nError accessing class data sharing archive."   \
2267                 " Mapped file inaccessible during execution, "      \
2268                 " possible disk/network problem.");
2269     }
2270   }
2271 #endif
2272   st->cr();
2273 }
2274 


src/os/linux/vm/os_linux.cpp
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File