< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page




1401       // won't be a problem.
1402       struct timespec res;
1403       struct timespec tp;
1404       if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
1405           clock_gettime_func(CLOCK_MONOTONIC, &tp)  == 0) {
1406         // yes, monotonic clock is supported
1407         _clock_gettime = clock_gettime_func;
1408         return;
1409       } else {
1410         // close librt if there is no monotonic clock
1411         dlclose(handle);
1412       }
1413     }
1414   }
1415   warning("No monotonic clock was available - timed services may " \
1416           "be adversely affected if the time-of-day clock changes");
1417 }
1418 
1419 #ifndef SYS_clock_getres
1420 
1421 #if defined(IA32) || defined(AMD64)
1422 #define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229)
1423 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
1424 #else
1425 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
1426 #define sys_clock_getres(x,y)  -1
1427 #endif
1428 
1429 #else
1430 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
1431 #endif
1432 
1433 void os::Linux::fast_thread_clock_init() {
1434   if (!UseLinuxPosixThreadCPUClocks) {
1435     return;
1436   }
1437   clockid_t clockid;
1438   struct timespec tp;
1439   int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
1440       (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
1441 
1442   // Switch to using fast clocks for thread cpu time if


1934         (::read(file_descriptor, &elf_head,sizeof(elf_head)))) ;
1935 
1936   ::close(file_descriptor);
1937   if (failed_to_read_elf_head) {
1938     // file i/o error - report dlerror() msg
1939     return NULL;
1940   }
1941 
1942   typedef struct {
1943     Elf32_Half  code;         // Actual value as defined in elf.h
1944     Elf32_Half  compat_class; // Compatibility of archs at VM's sense
1945     char        elf_class;    // 32 or 64 bit
1946     char        endianess;    // MSB or LSB
1947     char*       name;         // String representation
1948   } arch_t;
1949 
1950   #ifndef EM_486
1951   #define EM_486          6               /* Intel 80486 */
1952   #endif
1953 




1954   static const arch_t arch_array[]={
1955     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1956     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1957     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1958     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
1959     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1960     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1961     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
1962     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1963 #if defined(VM_LITTLE_ENDIAN)
1964     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64 LE"},
1965 #else
1966     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
1967 #endif
1968     {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
1969     {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
1970     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1971     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1972     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1973     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1974     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}

1975   };
1976 
1977   #if  (defined IA32)
1978     static  Elf32_Half running_arch_code=EM_386;
1979   #elif   (defined AMD64)
1980     static  Elf32_Half running_arch_code=EM_X86_64;
1981   #elif  (defined IA64)
1982     static  Elf32_Half running_arch_code=EM_IA_64;
1983   #elif  (defined __sparc) && (defined _LP64)
1984     static  Elf32_Half running_arch_code=EM_SPARCV9;
1985   #elif  (defined __sparc) && (!defined _LP64)
1986     static  Elf32_Half running_arch_code=EM_SPARC;
1987   #elif  (defined __powerpc64__)
1988     static  Elf32_Half running_arch_code=EM_PPC64;
1989   #elif  (defined __powerpc__)
1990     static  Elf32_Half running_arch_code=EM_PPC;
1991   #elif  (defined ARM)
1992     static  Elf32_Half running_arch_code=EM_ARM;
1993   #elif  (defined S390)
1994     static  Elf32_Half running_arch_code=EM_S390;
1995   #elif  (defined ALPHA)
1996     static  Elf32_Half running_arch_code=EM_ALPHA;
1997   #elif  (defined MIPSEL)
1998     static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
1999   #elif  (defined PARISC)
2000     static  Elf32_Half running_arch_code=EM_PARISC;
2001   #elif  (defined MIPS)
2002     static  Elf32_Half running_arch_code=EM_MIPS;
2003   #elif  (defined M68K)
2004     static  Elf32_Half running_arch_code=EM_68K;


2005   #else
2006     #error Method os::dll_load requires that one of following is defined:\
2007          IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K
2008   #endif
2009 
2010   // Identify compatability class for VM's architecture and library's architecture
2011   // Obtain string descriptions for architectures
2012 
2013   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
2014   int running_arch_index=-1;
2015 
2016   for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
2017     if (running_arch_code == arch_array[i].code) {
2018       running_arch_index    = i;
2019     }
2020     if (lib_arch.code == arch_array[i].code) {
2021       lib_arch.compat_class = arch_array[i].compat_class;
2022       lib_arch.name         = arch_array[i].name;
2023     }
2024   }
2025 
2026   assert(running_arch_index != -1,
2027     "Didn't find running architecture code (running_arch_code) in arch_array");


2926     if (Linux::isnode_in_configured_nodes(node)) {
2927       ids[i++] = node;
2928     }
2929   }
2930   return i;
2931 }
2932 
2933 bool os::get_page_info(char *start, page_info* info) {
2934   return false;
2935 }
2936 
2937 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2938   return end;
2939 }
2940 
2941 
2942 int os::Linux::sched_getcpu_syscall(void) {
2943   unsigned int cpu = 0;
2944   int retval = -1;
2945 
2946 #if defined(IA32)
2947 # ifndef SYS_getcpu
2948 # define SYS_getcpu 318
2949 # endif
2950   retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
2951 #elif defined(AMD64)
2952 // Unfortunately we have to bring all these macros here from vsyscall.h
2953 // to be able to compile on old linuxes.
2954 # define __NR_vgetcpu 2
2955 # define VSYSCALL_START (-10UL << 20)
2956 # define VSYSCALL_SIZE 1024
2957 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2958   typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2959   vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2960   retval = vgetcpu(&cpu, NULL, NULL);





2961 #endif
2962 
2963   return (retval == -1) ? retval : cpu;
2964 }
2965 
2966 // Something to do with the numa-aware allocator needs these symbols
2967 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2968 extern "C" JNIEXPORT void numa_error(char *where) { }
2969 extern "C" JNIEXPORT int fork1() { return fork(); }
2970 
2971 // Handle request to load libnuma symbol version 1.1 (API v1). If it fails
2972 // load symbol from base version instead.
2973 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2974   void *f = dlvsym(handle, name, "libnuma_1.1");
2975   if (f == NULL) {
2976     f = dlsym(handle, name);
2977   }
2978   return f;
2979 }
2980 


3494 static size_t _large_page_size = 0;
3495 
3496 size_t os::Linux::find_large_page_size() {
3497   size_t large_page_size = 0;
3498 
3499   // large_page_size on Linux is used to round up heap size. x86 uses either
3500   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3501   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3502   // page as large as 256M.
3503   //
3504   // Here we try to figure out page size by parsing /proc/meminfo and looking
3505   // for a line with the following format:
3506   //    Hugepagesize:     2048 kB
3507   //
3508   // If we can't determine the value (e.g. /proc is not mounted, or the text
3509   // format has been changed), we'll use the largest page size supported by
3510   // the processor.
3511 
3512 #ifndef ZERO
3513   large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3514                      ARM_ONLY(2 * M) PPC_ONLY(4 * M);
3515 #endif // ZERO
3516 
3517   FILE *fp = fopen("/proc/meminfo", "r");
3518   if (fp) {
3519     while (!feof(fp)) {
3520       int x = 0;
3521       char buf[16];
3522       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3523         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3524           large_page_size = x * K;
3525           break;
3526         }
3527       } else {
3528         // skip to next line
3529         for (;;) {
3530           int ch = fgetc(fp);
3531           if (ch == EOF || ch == (int)'\n') break;
3532         }
3533       }
3534     }




1401       // won't be a problem.
1402       struct timespec res;
1403       struct timespec tp;
1404       if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 &&
1405           clock_gettime_func(CLOCK_MONOTONIC, &tp)  == 0) {
1406         // yes, monotonic clock is supported
1407         _clock_gettime = clock_gettime_func;
1408         return;
1409       } else {
1410         // close librt if there is no monotonic clock
1411         dlclose(handle);
1412       }
1413     }
1414   }
1415   warning("No monotonic clock was available - timed services may " \
1416           "be adversely affected if the time-of-day clock changes");
1417 }
1418 
1419 #ifndef SYS_clock_getres
1420 
1421 #if defined(IA32) || defined(AMD64) || defined(AARCH64)
1422 #define SYS_clock_getres IA32_ONLY(266)  AMD64_ONLY(229) AARCH64_ONLY(114)
1423 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
1424 #else
1425 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time"
1426 #define sys_clock_getres(x,y)  -1
1427 #endif
1428 
1429 #else
1430 #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
1431 #endif
1432 
1433 void os::Linux::fast_thread_clock_init() {
1434   if (!UseLinuxPosixThreadCPUClocks) {
1435     return;
1436   }
1437   clockid_t clockid;
1438   struct timespec tp;
1439   int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) =
1440       (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid");
1441 
1442   // Switch to using fast clocks for thread cpu time if


1934         (::read(file_descriptor, &elf_head,sizeof(elf_head)))) ;
1935 
1936   ::close(file_descriptor);
1937   if (failed_to_read_elf_head) {
1938     // file i/o error - report dlerror() msg
1939     return NULL;
1940   }
1941 
1942   typedef struct {
1943     Elf32_Half  code;         // Actual value as defined in elf.h
1944     Elf32_Half  compat_class; // Compatibility of archs at VM's sense
1945     char        elf_class;    // 32 or 64 bit
1946     char        endianess;    // MSB or LSB
1947     char*       name;         // String representation
1948   } arch_t;
1949 
1950   #ifndef EM_486
1951   #define EM_486          6               /* Intel 80486 */
1952   #endif
1953 
1954   #ifndef EM_AARCH64
1955   #define EM_AARCH64    183
1956   #endif
1957 
1958   static const arch_t arch_array[]={
1959     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1960     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
1961     {EM_IA_64,       EM_IA_64,   ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"},
1962     {EM_X86_64,      EM_X86_64,  ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"},
1963     {EM_SPARC,       EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1964     {EM_SPARC32PLUS, EM_SPARC,   ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"},
1965     {EM_SPARCV9,     EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"},
1966     {EM_PPC,         EM_PPC,     ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"},
1967 #if defined(VM_LITTLE_ENDIAN)
1968     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2LSB, (char*)"Power PC 64 LE"},
1969 #else
1970     {EM_PPC64,       EM_PPC64,   ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"},
1971 #endif
1972     {EM_ARM,         EM_ARM,     ELFCLASS32,   ELFDATA2LSB, (char*)"ARM"},
1973     {EM_S390,        EM_S390,    ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"},
1974     {EM_ALPHA,       EM_ALPHA,   ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"},
1975     {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"},
1976     {EM_MIPS,        EM_MIPS,    ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"},
1977     {EM_PARISC,      EM_PARISC,  ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"},
1978     {EM_68K,         EM_68K,     ELFCLASS32, ELFDATA2MSB, (char*)"M68k"},
1979     {EM_AARCH64,     EM_AARCH64, ELFCLASS64, ELFDATA2LSB, (char*)"AARCH64"},
1980   };
1981 
1982   #if  (defined IA32)
1983     static  Elf32_Half running_arch_code=EM_386;
1984   #elif   (defined AMD64)
1985     static  Elf32_Half running_arch_code=EM_X86_64;
1986   #elif  (defined IA64)
1987     static  Elf32_Half running_arch_code=EM_IA_64;
1988   #elif  (defined __sparc) && (defined _LP64)
1989     static  Elf32_Half running_arch_code=EM_SPARCV9;
1990   #elif  (defined __sparc) && (!defined _LP64)
1991     static  Elf32_Half running_arch_code=EM_SPARC;
1992   #elif  (defined __powerpc64__)
1993     static  Elf32_Half running_arch_code=EM_PPC64;
1994   #elif  (defined __powerpc__)
1995     static  Elf32_Half running_arch_code=EM_PPC;
1996   #elif  (defined ARM)
1997     static  Elf32_Half running_arch_code=EM_ARM;
1998   #elif  (defined S390)
1999     static  Elf32_Half running_arch_code=EM_S390;
2000   #elif  (defined ALPHA)
2001     static  Elf32_Half running_arch_code=EM_ALPHA;
2002   #elif  (defined MIPSEL)
2003     static  Elf32_Half running_arch_code=EM_MIPS_RS3_LE;
2004   #elif  (defined PARISC)
2005     static  Elf32_Half running_arch_code=EM_PARISC;
2006   #elif  (defined MIPS)
2007     static  Elf32_Half running_arch_code=EM_MIPS;
2008   #elif  (defined M68K)
2009     static  Elf32_Half running_arch_code=EM_68K;
2010   #elif  (defined AARCH64)
2011     static  Elf32_Half running_arch_code=EM_AARCH64;
2012   #else
2013     #error Method os::dll_load requires that one of following is defined:\
2014       IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K, AARCH64
2015   #endif
2016 
2017   // Identify compatability class for VM's architecture and library's architecture
2018   // Obtain string descriptions for architectures
2019 
2020   arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL};
2021   int running_arch_index=-1;
2022 
2023   for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) {
2024     if (running_arch_code == arch_array[i].code) {
2025       running_arch_index    = i;
2026     }
2027     if (lib_arch.code == arch_array[i].code) {
2028       lib_arch.compat_class = arch_array[i].compat_class;
2029       lib_arch.name         = arch_array[i].name;
2030     }
2031   }
2032 
2033   assert(running_arch_index != -1,
2034     "Didn't find running architecture code (running_arch_code) in arch_array");


2933     if (Linux::isnode_in_configured_nodes(node)) {
2934       ids[i++] = node;
2935     }
2936   }
2937   return i;
2938 }
2939 
2940 bool os::get_page_info(char *start, page_info* info) {
2941   return false;
2942 }
2943 
2944 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) {
2945   return end;
2946 }
2947 
2948 
2949 int os::Linux::sched_getcpu_syscall(void) {
2950   unsigned int cpu = 0;
2951   int retval = -1;
2952 
2953 #if defined(AMD64)





2954 // Unfortunately we have to bring all these macros here from vsyscall.h
2955 // to be able to compile on old linuxes.
2956 # define __NR_vgetcpu 2
2957 # define VSYSCALL_START (-10UL << 20)
2958 # define VSYSCALL_SIZE 1024
2959 # define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr))
2960   typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache);
2961   vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu);
2962   retval = vgetcpu(&cpu, NULL, NULL);
2963 #elif defined(IA32) || defined(AARCH64)
2964 # ifndef SYS_getcpu
2965 #  define SYS_getcpu AARCH64_ONLY(168) NOT_AARCH64(318)
2966 # endif
2967   retval = syscall(SYS_getcpu, &cpu, NULL, NULL);
2968 #endif
2969 
2970   return (retval == -1) ? retval : cpu;
2971 }
2972 
2973 // Something to do with the numa-aware allocator needs these symbols
2974 extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { }
2975 extern "C" JNIEXPORT void numa_error(char *where) { }
2976 extern "C" JNIEXPORT int fork1() { return fork(); }
2977 
2978 // Handle request to load libnuma symbol version 1.1 (API v1). If it fails
2979 // load symbol from base version instead.
2980 void* os::Linux::libnuma_dlsym(void* handle, const char *name) {
2981   void *f = dlvsym(handle, name, "libnuma_1.1");
2982   if (f == NULL) {
2983     f = dlsym(handle, name);
2984   }
2985   return f;
2986 }
2987 


3501 static size_t _large_page_size = 0;
3502 
3503 size_t os::Linux::find_large_page_size() {
3504   size_t large_page_size = 0;
3505 
3506   // large_page_size on Linux is used to round up heap size. x86 uses either
3507   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3508   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3509   // page as large as 256M.
3510   //
3511   // Here we try to figure out page size by parsing /proc/meminfo and looking
3512   // for a line with the following format:
3513   //    Hugepagesize:     2048 kB
3514   //
3515   // If we can't determine the value (e.g. /proc is not mounted, or the text
3516   // format has been changed), we'll use the largest page size supported by
3517   // the processor.
3518 
3519 #ifndef ZERO
3520   large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3521                      ARM_ONLY(2 * M) PPC_ONLY(4 * M) AARCH64_ONLY(2 * M);
3522 #endif // ZERO
3523 
3524   FILE *fp = fopen("/proc/meminfo", "r");
3525   if (fp) {
3526     while (!feof(fp)) {
3527       int x = 0;
3528       char buf[16];
3529       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3530         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3531           large_page_size = x * K;
3532           break;
3533         }
3534       } else {
3535         // skip to next line
3536         for (;;) {
3537           int ch = fgetc(fp);
3538           if (ch == EOF || ch == (int)'\n') break;
3539         }
3540       }
3541     }


< prev index next >