< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page
rev 59103 : imported patch hotspot


 301     pticks->has_steal_ticks = false;
 302   }
 303 
 304   return true;
 305 }
 306 
 307 // Return true if user is running as root.
 308 
 309 bool os::have_special_privileges() {
 310   static bool init = false;
 311   static bool privileges = false;
 312   if (!init) {
 313     privileges = (getuid() != geteuid()) || (getgid() != getegid());
 314     init = true;
 315   }
 316   return privileges;
 317 }
 318 
 319 
 320 #ifndef SYS_gettid
 321 // i386: 224, ia64: 1105, amd64: 186, sparc 143
 322   #ifdef __ia64__
 323     #define SYS_gettid 1105
 324   #else
 325     #ifdef __i386__
 326       #define SYS_gettid 224
 327     #else
 328       #ifdef __amd64__
 329         #define SYS_gettid 186
 330       #else
 331         #ifdef __sparc__
 332           #define SYS_gettid 143
 333         #else
 334           #error define gettid for the arch
 335         #endif
 336       #endif
 337     #endif
 338   #endif
 339 #endif
 340 
 341 
 342 // pid_t gettid()
 343 //
 344 // Returns the kernel thread id of the currently running thread. Kernel
 345 // thread id is used to access /proc.
 346 pid_t os::Linux::gettid() {
 347   int rslt = syscall(SYS_gettid);
 348   assert(rslt != -1, "must be."); // old linuxthreads implementation?
 349   return (pid_t)rslt;
 350 }
 351 
 352 // Most versions of linux have a bug where the number of processors are
 353 // determined by looking at the /proc file system.  In a chroot environment,
 354 // the system call returns 1.
 355 static bool unsafe_chroot_detected = false;
 356 static const char *unstable_chroot_error = "/proc file system not found.\n"
 357                      "Java may be unstable running multithreaded in a chroot "
 358                      "environment on Linux when /proc filesystem is not mounted.";


 391   // If "/jre/lib/" does NOT appear at the right place in the path
 392   // instead of exit check for $JAVA_HOME environment variable.
 393   //
 394   // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
 395   // then we append a fake suffix "hotspot/libjvm.so" to this path so
 396   // it looks like libjvm.so is installed there
 397   // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so.
 398   //
 399   // Otherwise exit.
 400   //
 401   // Important note: if the location of libjvm.so changes this
 402   // code needs to be changed accordingly.
 403 
 404   // See ld(1):
 405   //      The linker uses the following search paths to locate required
 406   //      shared libraries:
 407   //        1: ...
 408   //        ...
 409   //        7: The default directories, normally /lib and /usr/lib.
 410 #ifndef OVERRIDE_LIBPATH
 411   #if defined(AMD64) || (defined(_LP64) && defined(SPARC)) || defined(PPC64) || defined(S390)
 412     #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
 413   #else
 414     #define DEFAULT_LIBPATH "/lib:/usr/lib"
 415   #endif
 416 #else
 417   #define DEFAULT_LIBPATH OVERRIDE_LIBPATH
 418 #endif
 419 
 420 // Base path of extensions installed on the system.
 421 #define SYS_EXT_DIR     "/usr/java/packages"
 422 #define EXTENSIONS_DIR  "/lib/ext"
 423 
 424   // Buffer that fits several sprintfs.
 425   // Note that the space for the colon and the trailing null are provided
 426   // by the nulls included by the sizeof operator.
 427   const size_t bufsize =
 428     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
 429          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
 430   char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 431 


1841   typedef struct {
1842     Elf32_Half    code;         // Actual value as defined in elf.h
1843     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
1844     unsigned char elf_class;    // 32 or 64 bit
1845     unsigned char endianness;   // MSB or LSB
1846     char*         name;         // String representation
1847   } arch_t;
1848 
1849 #ifndef EM_AARCH64
1850   #define EM_AARCH64    183               /* ARM AARCH64 */
1851 #endif
1852 #ifndef EM_RISCV
1853   #define EM_RISCV      243               /* RISC-V */
1854 #endif
1855 
1856   static const arch_t arch_array[]={
1857     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1858     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1859     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1860     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
1861     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1862     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1863     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
1864     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1865 #if defined(VM_LITTLE_ENDIAN)
1866     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64 LE"},
1867     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"},
1868 #else
1869     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
1870     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"},
1871 #endif
1872     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM"},
1873     // we only support 64 bit z architecture
1874     {EM_S390,        EM_S390,    ELFCLASS64, ELFDATA2MSB, (char*)"IBM System/390"},
1875     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1876     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1877     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1878     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1879     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
1880     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
1881     {EM_RISCV,       EM_RISCV,   ELFCLASS64, ELFDATA2LSB, (char*)"RISC-V"},
1882   };
1883 
1884 #if  (defined IA32)
1885   static  Elf32_Half running_arch_code=EM_386;
1886 #elif   (defined AMD64) || (defined X32)
1887   static  Elf32_Half running_arch_code=EM_X86_64;
1888 #elif  (defined IA64)
1889   static  Elf32_Half running_arch_code=EM_IA_64;
1890 #elif  (defined __sparc) && (defined _LP64)
1891   static  Elf32_Half running_arch_code=EM_SPARCV9;
1892 #elif  (defined __sparc) && (!defined _LP64)
1893   static  Elf32_Half running_arch_code=EM_SPARC;
1894 #elif  (defined __powerpc64__)
1895   static  Elf32_Half running_arch_code=EM_PPC64;
1896 #elif  (defined __powerpc__)
1897   static  Elf32_Half running_arch_code=EM_PPC;
1898 #elif  (defined AARCH64)
1899   static  Elf32_Half running_arch_code=EM_AARCH64;
1900 #elif  (defined ARM)
1901   static  Elf32_Half running_arch_code=EM_ARM;
1902 #elif  (defined S390)
1903   static  Elf32_Half running_arch_code=EM_S390;
1904 #elif  (defined ALPHA)
1905   static  Elf32_Half running_arch_code=EM_ALPHA;
1906 #elif  (defined MIPSEL)
1907   static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
1908 #elif  (defined PARISC)
1909   static  Elf32_Half running_arch_code=EM_PARISC;
1910 #elif  (defined MIPS)
1911   static  Elf32_Half running_arch_code=EM_MIPS;
1912 #elif  (defined M68K)
1913   static  Elf32_Half running_arch_code=EM_68K;
1914 #elif  (defined SH)
1915   static  Elf32_Half running_arch_code=EM_SH;
1916 #elif  (defined RISCV)
1917   static  Elf32_Half running_arch_code=EM_RISCV;
1918 #else
1919     #error Method os::dll_load requires that one of following is defined:\
1920         AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, RISCV, S390, SH, __sparc
1921 #endif
1922 
1923   // Identify compatibility class for VM's architecture and library's architecture
1924   // Obtain string descriptions for architectures
1925 
1926   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
1927   int running_arch_index=-1;
1928 
1929   for (unsigned int i=0; i < ARRAY_SIZE(arch_array); i++) {
1930     if (running_arch_code == arch_array[i].code) {
1931       running_arch_index    = i;
1932     }
1933     if (lib_arch.code == arch_array[i].code) {
1934       lib_arch.compat_class = arch_array[i].compat_class;
1935       lib_arch.name         = arch_array[i].name;
1936     }
1937   }
1938 
1939   assert(running_arch_index != -1,
1940          "Didn't find running architecture code (running_arch_code) in arch_array");


2558 
2559 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2560   // Only print the model name if the platform provides this as a summary
2561   if (!print_model_name_and_flags(st, buf, buflen)) {
2562     st->print("\n/proc/cpuinfo:\n");
2563     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2564       st->print_cr("  <Not Available>");
2565     }
2566   }
2567   print_sys_devices_cpu_info(st, buf, buflen);
2568 }
2569 
2570 #if defined(AMD64) || defined(IA32) || defined(X32)
2571 const char* search_string = "model name";
2572 #elif defined(M68K)
2573 const char* search_string = "CPU";
2574 #elif defined(PPC64)
2575 const char* search_string = "cpu";
2576 #elif defined(S390)
2577 const char* search_string = "machine =";
2578 #elif defined(SPARC)
2579 const char* search_string = "cpu";
2580 #else
2581 const char* search_string = "Processor";
2582 #endif
2583 
2584 // Parses the cpuinfo file for string representing the model name.
2585 void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
2586   FILE* fp = fopen("/proc/cpuinfo", "r");
2587   if (fp != NULL) {
2588     while (!feof(fp)) {
2589       char buf[256];
2590       if (fgets(buf, sizeof(buf), fp)) {
2591         char* start = strstr(buf, search_string);
2592         if (start != NULL) {
2593           char *ptr = start + strlen(search_string);
2594           char *end = buf + strlen(buf);
2595           while (ptr != end) {
2596              // skip whitespace and colon for the rest of the name.
2597              if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') {
2598                break;
2599              }


2611       }
2612     }
2613     fclose(fp);
2614   }
2615   // cpuinfo not found or parsing failed, just print generic string.  The entire
2616   // /proc/cpuinfo file will be printed later in the file (or enough of it for x86)
2617 #if   defined(AARCH64)
2618   strncpy(cpuinfo, "AArch64", length);
2619 #elif defined(AMD64)
2620   strncpy(cpuinfo, "x86_64", length);
2621 #elif defined(ARM)  // Order wrt. AARCH64 is relevant!
2622   strncpy(cpuinfo, "ARM", length);
2623 #elif defined(IA32)
2624   strncpy(cpuinfo, "x86_32", length);
2625 #elif defined(IA64)
2626   strncpy(cpuinfo, "IA64", length);
2627 #elif defined(PPC)
2628   strncpy(cpuinfo, "PPC64", length);
2629 #elif defined(S390)
2630   strncpy(cpuinfo, "S390", length);
2631 #elif defined(SPARC)
2632   strncpy(cpuinfo, "sparcv9", length);
2633 #elif defined(ZERO_LIBARCH)
2634   strncpy(cpuinfo, ZERO_LIBARCH, length);
2635 #else
2636   strncpy(cpuinfo, "unknown", length);
2637 #endif
2638 }
2639 
2640 static void print_signal_handler(outputStream* st, int sig,
2641                                  char* buf, size_t buflen);
2642 
2643 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
2644   st->print_cr("Signal Handlers:");
2645   print_signal_handler(st, SIGSEGV, buf, buflen);
2646   print_signal_handler(st, SIGBUS , buf, buflen);
2647   print_signal_handler(st, SIGFPE , buf, buflen);
2648   print_signal_handler(st, SIGPIPE, buf, buflen);
2649   print_signal_handler(st, SIGXFSZ, buf, buflen);
2650   print_signal_handler(st, SIGILL , buf, buflen);
2651   print_signal_handler(st, SR_signum, buf, buflen);
2652   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);


3791   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3792   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3793   // page as large as 256M.
3794   //
3795   // Here we try to figure out page size by parsing /proc/meminfo and looking
3796   // for a line with the following format:
3797   //    Hugepagesize:     2048 kB
3798   //
3799   // If we can't determine the value (e.g. /proc is not mounted, or the text
3800   // format has been changed), we'll use the largest page size supported by
3801   // the processor.
3802 
3803 #ifndef ZERO
3804   large_page_size =
3805     AARCH64_ONLY(2 * M)
3806     AMD64_ONLY(2 * M)
3807     ARM32_ONLY(2 * M)
3808     IA32_ONLY(4 * M)
3809     IA64_ONLY(256 * M)
3810     PPC_ONLY(4 * M)
3811     S390_ONLY(1 * M)
3812     SPARC_ONLY(4 * M);
3813 #endif // ZERO
3814 
3815   FILE *fp = fopen("/proc/meminfo", "r");
3816   if (fp) {
3817     while (!feof(fp)) {
3818       int x = 0;
3819       char buf[16];
3820       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3821         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3822           large_page_size = x * K;
3823           break;
3824         }
3825       } else {
3826         // skip to next line
3827         for (;;) {
3828           int ch = fgetc(fp);
3829           if (ch == EOF || ch == (int)'\n') break;
3830         }
3831       }
3832     }




 301     pticks->has_steal_ticks = false;
 302   }
 303 
 304   return true;
 305 }
 306 
 307 // Return true if user is running as root.
 308 
 309 bool os::have_special_privileges() {
 310   static bool init = false;
 311   static bool privileges = false;
 312   if (!init) {
 313     privileges = (getuid() != geteuid()) || (getgid() != getegid());
 314     init = true;
 315   }
 316   return privileges;
 317 }
 318 
 319 
 320 #ifndef SYS_gettid
 321 // i386: 224, ia64: 1105, amd64: 186
 322   #ifdef __ia64__
 323     #define SYS_gettid 1105
 324   #else
 325     #ifdef __i386__
 326       #define SYS_gettid 224
 327     #else
 328       #ifdef __amd64__
 329         #define SYS_gettid 186
 330       #else



 331         #error define gettid for the arch
 332       #endif
 333     #endif
 334   #endif

 335 #endif
 336 
 337 
 338 // pid_t gettid()
 339 //
 340 // Returns the kernel thread id of the currently running thread. Kernel
 341 // thread id is used to access /proc.
 342 pid_t os::Linux::gettid() {
 343   int rslt = syscall(SYS_gettid);
 344   assert(rslt != -1, "must be."); // old linuxthreads implementation?
 345   return (pid_t)rslt;
 346 }
 347 
 348 // Most versions of linux have a bug where the number of processors are
 349 // determined by looking at the /proc file system.  In a chroot environment,
 350 // the system call returns 1.
 351 static bool unsafe_chroot_detected = false;
 352 static const char *unstable_chroot_error = "/proc file system not found.\n"
 353                      "Java may be unstable running multithreaded in a chroot "
 354                      "environment on Linux when /proc filesystem is not mounted.";


 387   // If "/jre/lib/" does NOT appear at the right place in the path
 388   // instead of exit check for $JAVA_HOME environment variable.
 389   //
 390   // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>,
 391   // then we append a fake suffix "hotspot/libjvm.so" to this path so
 392   // it looks like libjvm.so is installed there
 393   // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so.
 394   //
 395   // Otherwise exit.
 396   //
 397   // Important note: if the location of libjvm.so changes this
 398   // code needs to be changed accordingly.
 399 
 400   // See ld(1):
 401   //      The linker uses the following search paths to locate required
 402   //      shared libraries:
 403   //        1: ...
 404   //        ...
 405   //        7: The default directories, normally /lib and /usr/lib.
 406 #ifndef OVERRIDE_LIBPATH
 407   #if defined(AMD64) || defined(PPC64) || defined(S390)
 408     #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
 409   #else
 410     #define DEFAULT_LIBPATH "/lib:/usr/lib"
 411   #endif
 412 #else
 413   #define DEFAULT_LIBPATH OVERRIDE_LIBPATH
 414 #endif
 415 
 416 // Base path of extensions installed on the system.
 417 #define SYS_EXT_DIR     "/usr/java/packages"
 418 #define EXTENSIONS_DIR  "/lib/ext"
 419 
 420   // Buffer that fits several sprintfs.
 421   // Note that the space for the colon and the trailing null are provided
 422   // by the nulls included by the sizeof operator.
 423   const size_t bufsize =
 424     MAX2((size_t)MAXPATHLEN,  // For dll_dir & friends.
 425          (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir
 426   char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal);
 427 


1837   typedef struct {
1838     Elf32_Half    code;         // Actual value as defined in elf.h
1839     Elf32_Half    compat_class; // Compatibility of archs at VM's sense
1840     unsigned char elf_class;    // 32 or 64 bit
1841     unsigned char endianness;   // MSB or LSB
1842     char*         name;         // String representation
1843   } arch_t;
1844 
1845 #ifndef EM_AARCH64
1846   #define EM_AARCH64    183               /* ARM AARCH64 */
1847 #endif
1848 #ifndef EM_RISCV
1849   #define EM_RISCV      243               /* RISC-V */
1850 #endif
1851 
1852   static const arch_t arch_array[]={
1853     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1854     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1855     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1856     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},



1857     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1858 #if defined(VM_LITTLE_ENDIAN)
1859     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64 LE"},
1860     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"},
1861 #else
1862     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
1863     {EM_SH,          EM_SH,      ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"},
1864 #endif
1865     {EM_ARM,         EM_ARM,     ELFCLASS32, ELFDATA2LSB, (char*)"ARM"},
1866     // we only support 64 bit z architecture
1867     {EM_S390,        EM_S390,    ELFCLASS64, ELFDATA2MSB, (char*)"IBM System/390"},
1868     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1869     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1870     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1871     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1872     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
1873     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
1874     {EM_RISCV,       EM_RISCV,   ELFCLASS64, ELFDATA2LSB, (char*)"RISC-V"},
1875   };
1876 
1877 #if  (defined IA32)
1878   static  Elf32_Half running_arch_code=EM_386;
1879 #elif   (defined AMD64) || (defined X32)
1880   static  Elf32_Half running_arch_code=EM_X86_64;
1881 #elif  (defined IA64)
1882   static  Elf32_Half running_arch_code=EM_IA_64;




1883 #elif  (defined __powerpc64__)
1884   static  Elf32_Half running_arch_code=EM_PPC64;
1885 #elif  (defined __powerpc__)
1886   static  Elf32_Half running_arch_code=EM_PPC;
1887 #elif  (defined AARCH64)
1888   static  Elf32_Half running_arch_code=EM_AARCH64;
1889 #elif  (defined ARM)
1890   static  Elf32_Half running_arch_code=EM_ARM;
1891 #elif  (defined S390)
1892   static  Elf32_Half running_arch_code=EM_S390;
1893 #elif  (defined ALPHA)
1894   static  Elf32_Half running_arch_code=EM_ALPHA;
1895 #elif  (defined MIPSEL)
1896   static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
1897 #elif  (defined PARISC)
1898   static  Elf32_Half running_arch_code=EM_PARISC;
1899 #elif  (defined MIPS)
1900   static  Elf32_Half running_arch_code=EM_MIPS;
1901 #elif  (defined M68K)
1902   static  Elf32_Half running_arch_code=EM_68K;
1903 #elif  (defined SH)
1904   static  Elf32_Half running_arch_code=EM_SH;
1905 #elif  (defined RISCV)
1906   static  Elf32_Half running_arch_code=EM_RISCV;
1907 #else
1908     #error Method os::dll_load requires that one of following is defined:\
1909         AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, RISCV, S390, SH
1910 #endif
1911 
1912   // Identify compatibility class for VM's architecture and library's architecture
1913   // Obtain string descriptions for architectures
1914 
1915   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
1916   int running_arch_index=-1;
1917 
1918   for (unsigned int i=0; i < ARRAY_SIZE(arch_array); i++) {
1919     if (running_arch_code == arch_array[i].code) {
1920       running_arch_index    = i;
1921     }
1922     if (lib_arch.code == arch_array[i].code) {
1923       lib_arch.compat_class = arch_array[i].compat_class;
1924       lib_arch.name         = arch_array[i].name;
1925     }
1926   }
1927 
1928   assert(running_arch_index != -1,
1929          "Didn't find running architecture code (running_arch_code) in arch_array");


2547 
2548 void os::pd_print_cpu_info(outputStream* st, char* buf, size_t buflen) {
2549   // Only print the model name if the platform provides this as a summary
2550   if (!print_model_name_and_flags(st, buf, buflen)) {
2551     st->print("\n/proc/cpuinfo:\n");
2552     if (!_print_ascii_file("/proc/cpuinfo", st)) {
2553       st->print_cr("  <Not Available>");
2554     }
2555   }
2556   print_sys_devices_cpu_info(st, buf, buflen);
2557 }
2558 
2559 #if defined(AMD64) || defined(IA32) || defined(X32)
2560 const char* search_string = "model name";
2561 #elif defined(M68K)
2562 const char* search_string = "CPU";
2563 #elif defined(PPC64)
2564 const char* search_string = "cpu";
2565 #elif defined(S390)
2566 const char* search_string = "machine =";


2567 #else
2568 const char* search_string = "Processor";
2569 #endif
2570 
2571 // Parses the cpuinfo file for string representing the model name.
2572 void os::get_summary_cpu_info(char* cpuinfo, size_t length) {
2573   FILE* fp = fopen("/proc/cpuinfo", "r");
2574   if (fp != NULL) {
2575     while (!feof(fp)) {
2576       char buf[256];
2577       if (fgets(buf, sizeof(buf), fp)) {
2578         char* start = strstr(buf, search_string);
2579         if (start != NULL) {
2580           char *ptr = start + strlen(search_string);
2581           char *end = buf + strlen(buf);
2582           while (ptr != end) {
2583              // skip whitespace and colon for the rest of the name.
2584              if (*ptr != ' ' && *ptr != '\t' && *ptr != ':') {
2585                break;
2586              }


2598       }
2599     }
2600     fclose(fp);
2601   }
2602   // cpuinfo not found or parsing failed, just print generic string.  The entire
2603   // /proc/cpuinfo file will be printed later in the file (or enough of it for x86)
2604 #if   defined(AARCH64)
2605   strncpy(cpuinfo, "AArch64", length);
2606 #elif defined(AMD64)
2607   strncpy(cpuinfo, "x86_64", length);
2608 #elif defined(ARM)  // Order wrt. AARCH64 is relevant!
2609   strncpy(cpuinfo, "ARM", length);
2610 #elif defined(IA32)
2611   strncpy(cpuinfo, "x86_32", length);
2612 #elif defined(IA64)
2613   strncpy(cpuinfo, "IA64", length);
2614 #elif defined(PPC)
2615   strncpy(cpuinfo, "PPC64", length);
2616 #elif defined(S390)
2617   strncpy(cpuinfo, "S390", length);


2618 #elif defined(ZERO_LIBARCH)
2619   strncpy(cpuinfo, ZERO_LIBARCH, length);
2620 #else
2621   strncpy(cpuinfo, "unknown", length);
2622 #endif
2623 }
2624 
2625 static void print_signal_handler(outputStream* st, int sig,
2626                                  char* buf, size_t buflen);
2627 
2628 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) {
2629   st->print_cr("Signal Handlers:");
2630   print_signal_handler(st, SIGSEGV, buf, buflen);
2631   print_signal_handler(st, SIGBUS , buf, buflen);
2632   print_signal_handler(st, SIGFPE , buf, buflen);
2633   print_signal_handler(st, SIGPIPE, buf, buflen);
2634   print_signal_handler(st, SIGXFSZ, buf, buflen);
2635   print_signal_handler(st, SIGILL , buf, buflen);
2636   print_signal_handler(st, SR_signum, buf, buflen);
2637   print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen);


3776   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3777   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3778   // page as large as 256M.
3779   //
3780   // Here we try to figure out page size by parsing /proc/meminfo and looking
3781   // for a line with the following format:
3782   //    Hugepagesize:     2048 kB
3783   //
3784   // If we can't determine the value (e.g. /proc is not mounted, or the text
3785   // format has been changed), we'll use the largest page size supported by
3786   // the processor.
3787 
3788 #ifndef ZERO
3789   large_page_size =
3790     AARCH64_ONLY(2 * M)
3791     AMD64_ONLY(2 * M)
3792     ARM32_ONLY(2 * M)
3793     IA32_ONLY(4 * M)
3794     IA64_ONLY(256 * M)
3795     PPC_ONLY(4 * M)
3796     S390_ONLY(1 * M);

3797 #endif // ZERO
3798 
3799   FILE *fp = fopen("/proc/meminfo", "r");
3800   if (fp) {
3801     while (!feof(fp)) {
3802       int x = 0;
3803       char buf[16];
3804       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3805         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3806           large_page_size = x * K;
3807           break;
3808         }
3809       } else {
3810         // skip to next line
3811         for (;;) {
3812           int ch = fgetc(fp);
3813           if (ch == EOF || ch == (int)'\n') break;
3814         }
3815       }
3816     }


< prev index next >