< prev index next >

src/os/linux/vm/os_linux.cpp

Print this page




 210   return privileges;
 211 }
 212 
 213 
 214 #ifndef SYS_gettid
 215 // i386: 224, ia64: 1105, amd64: 186, sparc 143
 216   #ifdef __ia64__
 217     #define SYS_gettid 1105
 218   #elif __i386__
 219     #define SYS_gettid 224
 220   #elif __amd64__
 221     #define SYS_gettid 186
 222   #elif __sparc__
 223     #define SYS_gettid 143
 224   #else
 225     #error define gettid for the arch
 226   #endif
 227 #endif
 228 
 229 // Cpu architecture string
 230 #if   defined(ZERO)
 231 static char cpu_arch[] = ZERO_LIBARCH;
 232 #elif defined(IA64)
 233 static char cpu_arch[] = "ia64";
 234 #elif defined(IA32)
 235 static char cpu_arch[] = "i386";
 236 #elif defined(AMD64)
 237 static char cpu_arch[] = "amd64";
 238 #elif defined(ARM)
 239 static char cpu_arch[] = "arm";
 240 #elif defined(PPC32)
 241 static char cpu_arch[] = "ppc";
 242 #elif defined(PPC64)
 243 static char cpu_arch[] = "ppc64";
 244 #elif defined(SPARC)
 245   #ifdef _LP64
 246 static char cpu_arch[] = "sparcv9";
 247   #else
 248 static char cpu_arch[] = "sparc";
 249   #endif
 250 #elif defined(AARCH64)
 251 static char cpu_arch[] = "aarch64";
 252 #else
 253   #error Add appropriate cpu_arch setting
 254 #endif
 255 
 256 
 257 // pid_t gettid()
 258 //
 259 // Returns the kernel thread id of the currently running thread. Kernel
 260 // thread id is used to access /proc.
 261 //
 262 // (Note that getpid() on LinuxThreads returns kernel thread id too; but
 263 // on NPTL, it returns the same pid for all threads, as required by POSIX.)
 264 //
 265 pid_t os::Linux::gettid() {
 266   int rslt = syscall(SYS_gettid);
 267   if (rslt == -1) {
 268     // old kernel, no NPTL support
 269     return getpid();
 270   } else {
 271     return (pid_t)rslt;
 272   }
 273 }
 274 


3279 static size_t _large_page_size = 0;
3280 
3281 size_t os::Linux::find_large_page_size() {
3282   size_t large_page_size = 0;
3283 
3284   // large_page_size on Linux is used to round up heap size. x86 uses either
3285   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3286   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3287   // page as large as 256M.
3288   //
3289   // Here we try to figure out page size by parsing /proc/meminfo and looking
3290   // for a line with the following format:
3291   //    Hugepagesize:     2048 kB
3292   //
3293   // If we can't determine the value (e.g. /proc is not mounted, or the text
3294   // format has been changed), we'll use the largest page size supported by
3295   // the processor.
3296 
3297 #ifndef ZERO
3298   large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3299                      ARM_ONLY(2 * M) PPC_ONLY(4 * M) AARCH64_ONLY(2 * M);
3300 #endif // ZERO
3301 
3302   FILE *fp = fopen("/proc/meminfo", "r");
3303   if (fp) {
3304     while (!feof(fp)) {
3305       int x = 0;
3306       char buf[16];
3307       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3308         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3309           large_page_size = x * K;
3310           break;
3311         }
3312       } else {
3313         // skip to next line
3314         for (;;) {
3315           int ch = fgetc(fp);
3316           if (ch == EOF || ch == (int)'\n') break;
3317         }
3318       }
3319     }




 210   return privileges;
 211 }
 212 
 213 
 214 #ifndef SYS_gettid
 215 // i386: 224, ia64: 1105, amd64: 186, sparc 143
 216   #ifdef __ia64__
 217     #define SYS_gettid 1105
 218   #elif __i386__
 219     #define SYS_gettid 224
 220   #elif __amd64__
 221     #define SYS_gettid 186
 222   #elif __sparc__
 223     #define SYS_gettid 143
 224   #else
 225     #error define gettid for the arch
 226   #endif
 227 #endif
 228 
 229 // Cpu architecture string
 230 static char cpu_arch[] = HOTSPOT_LIB_ARCH;
























 231 
 232 
 233 // pid_t gettid()
 234 //
 235 // Returns the kernel thread id of the currently running thread. Kernel
 236 // thread id is used to access /proc.
 237 //
 238 // (Note that getpid() on LinuxThreads returns kernel thread id too; but
 239 // on NPTL, it returns the same pid for all threads, as required by POSIX.)
 240 //
 241 pid_t os::Linux::gettid() {
 242   int rslt = syscall(SYS_gettid);
 243   if (rslt == -1) {
 244     // old kernel, no NPTL support
 245     return getpid();
 246   } else {
 247     return (pid_t)rslt;
 248   }
 249 }
 250 


3255 static size_t _large_page_size = 0;
3256 
3257 size_t os::Linux::find_large_page_size() {
3258   size_t large_page_size = 0;
3259 
3260   // large_page_size on Linux is used to round up heap size. x86 uses either
3261   // 2M or 4M page, depending on whether PAE (Physical Address Extensions)
3262   // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use
3263   // page as large as 256M.
3264   //
3265   // Here we try to figure out page size by parsing /proc/meminfo and looking
3266   // for a line with the following format:
3267   //    Hugepagesize:     2048 kB
3268   //
3269   // If we can't determine the value (e.g. /proc is not mounted, or the text
3270   // format has been changed), we'll use the largest page size supported by
3271   // the processor.
3272 
3273 #ifndef ZERO
3274   large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M)
3275                      ARM32_ONLY(2 * M) PPC_ONLY(4 * M) AARCH64_ONLY(2 * M);
3276 #endif // ZERO
3277 
3278   FILE *fp = fopen("/proc/meminfo", "r");
3279   if (fp) {
3280     while (!feof(fp)) {
3281       int x = 0;
3282       char buf[16];
3283       if (fscanf(fp, "Hugepagesize: %d", &x) == 1) {
3284         if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) {
3285           large_page_size = x * K;
3286           break;
3287         }
3288       } else {
3289         // skip to next line
3290         for (;;) {
3291           int ch = fgetc(fp);
3292           if (ch == EOF || ch == (int)'\n') break;
3293         }
3294       }
3295     }


< prev index next >