1.1 --- a/src/os/linux/vm/os_linux.cpp Fri Aug 18 09:33:59 2017 +0800 1.2 +++ b/src/os/linux/vm/os_linux.cpp Tue Aug 29 14:17:53 2017 +0800 1.3 @@ -357,140 +357,101 @@ 1.4 // Important note: if the location of libjvm.so changes this 1.5 // code needs to be changed accordingly. 1.6 1.7 - // The next few definitions allow the code to be verbatim: 1.8 -#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) 1.9 -#define getenv(n) ::getenv(n) 1.10 - 1.11 -/* 1.12 - * See ld(1): 1.13 - * The linker uses the following search paths to locate required 1.14 - * shared libraries: 1.15 - * 1: ... 1.16 - * ... 1.17 - * 7: The default directories, normally /lib and /usr/lib. 1.18 - */ 1.19 +// See ld(1): 1.20 +// The linker uses the following search paths to locate required 1.21 +// shared libraries: 1.22 +// 1: ... 1.23 +// ... 1.24 +// 7: The default directories, normally /lib and /usr/lib. 1.25 #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390) || defined(MIPS64)) 1.26 #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" 1.27 #else 1.28 #define DEFAULT_LIBPATH "/lib:/usr/lib" 1.29 #endif 1.30 1.31 +// Base path of extensions installed on the system. 1.32 +#define SYS_EXT_DIR "/usr/java/packages" 1.33 #define EXTENSIONS_DIR "/lib/ext" 1.34 #define ENDORSED_DIR "/lib/endorsed" 1.35 -#define REG_DIR "/usr/java/packages" 1.36 - 1.37 + 1.38 + // Buffer that fits several sprintfs. 1.39 + // Note that the space for the colon and the trailing null are provided 1.40 + // by the nulls included by the sizeof operator. 1.41 + const size_t bufsize = 1.42 + MAX3((size_t)MAXPATHLEN, // For dll_dir & friends. 1.43 + (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR), // extensions dir 1.44 + (size_t)MAXPATHLEN + sizeof(ENDORSED_DIR)); // endorsed dir 1.45 + char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal); 1.46 + 1.47 + // sysclasspath, java_home, dll_dir 1.48 { 1.49 - /* sysclasspath, java_home, dll_dir */ 1.50 - { 1.51 - char *home_path; 1.52 - char *dll_path; 1.53 - char *pslash; 1.54 - char buf[MAXPATHLEN]; 1.55 - os::jvm_path(buf, sizeof(buf)); 1.56 - 1.57 - // Found the full path to libjvm.so. 1.58 - // Now cut the path to <java_home>/jre if we can. 1.59 - *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ 1.60 + char *pslash; 1.61 + os::jvm_path(buf, bufsize); 1.62 + 1.63 + // Found the full path to libjvm.so. 1.64 + // Now cut the path to <java_home>/jre if we can. 1.65 + *(strrchr(buf, '/')) = '\0'; // Get rid of /libjvm.so. 1.66 + pslash = strrchr(buf, '/'); 1.67 + if (pslash != NULL) { 1.68 + *pslash = '\0'; // Get rid of /{client|server|hotspot}. 1.69 + } 1.70 + Arguments::set_dll_dir(buf); 1.71 + 1.72 + if (pslash != NULL) { 1.73 + pslash = strrchr(buf, '/'); 1.74 + if (pslash != NULL) { 1.75 + *pslash = '\0'; // Get rid of /<arch>. 1.76 pslash = strrchr(buf, '/'); 1.77 - if (pslash != NULL) 1.78 - *pslash = '\0'; /* get rid of /{client|server|hotspot} */ 1.79 - dll_path = malloc(strlen(buf) + 1); 1.80 - if (dll_path == NULL) 1.81 - return; 1.82 - strcpy(dll_path, buf); 1.83 - Arguments::set_dll_dir(dll_path); 1.84 - 1.85 if (pslash != NULL) { 1.86 - pslash = strrchr(buf, '/'); 1.87 - if (pslash != NULL) { 1.88 - *pslash = '\0'; /* get rid of /<arch> */ 1.89 - pslash = strrchr(buf, '/'); 1.90 - if (pslash != NULL) 1.91 - *pslash = '\0'; /* get rid of /lib */ 1.92 - } 1.93 + *pslash = '\0'; // Get rid of /lib. 1.94 } 1.95 - 1.96 - home_path = malloc(strlen(buf) + 1); 1.97 - if (home_path == NULL) 1.98 - return; 1.99 - strcpy(home_path, buf); 1.100 - Arguments::set_java_home(home_path); 1.101 - 1.102 - if (!set_boot_path('/', ':')) 1.103 - return; 1.104 + } 1.105 } 1.106 - 1.107 - /* 1.108 - * Where to look for native libraries 1.109 - * 1.110 - * Note: Due to a legacy implementation, most of the library path 1.111 - * is set in the launcher. This was to accomodate linking restrictions 1.112 - * on legacy Linux implementations (which are no longer supported). 1.113 - * Eventually, all the library path setting will be done here. 1.114 - * 1.115 - * However, to prevent the proliferation of improperly built native 1.116 - * libraries, the new path component /usr/java/packages is added here. 1.117 - * Eventually, all the library path setting will be done here. 1.118 - */ 1.119 - { 1.120 - char *ld_library_path; 1.121 - 1.122 - /* 1.123 - * Construct the invariant part of ld_library_path. Note that the 1.124 - * space for the colon and the trailing null are provided by the 1.125 - * nulls included by the sizeof operator (so actually we allocate 1.126 - * a byte more than necessary). 1.127 - */ 1.128 - ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + 1.129 - strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); 1.130 - sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch); 1.131 - 1.132 - /* 1.133 - * Get the user setting of LD_LIBRARY_PATH, and prepended it. It 1.134 - * should always exist (until the legacy problem cited above is 1.135 - * addressed). 1.136 - */ 1.137 - char *v = getenv("LD_LIBRARY_PATH"); 1.138 - if (v != NULL) { 1.139 - char *t = ld_library_path; 1.140 - /* That's +1 for the colon and +1 for the trailing '\0' */ 1.141 - ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1); 1.142 - sprintf(ld_library_path, "%s:%s", v, t); 1.143 - } 1.144 - Arguments::set_library_path(ld_library_path); 1.145 - } 1.146 - 1.147 - /* 1.148 - * Extensions directories. 1.149 - * 1.150 - * Note that the space for the colon and the trailing null are provided 1.151 - * by the nulls included by the sizeof operator (so actually one byte more 1.152 - * than necessary is allocated). 1.153 - */ 1.154 - { 1.155 - char *buf = malloc(strlen(Arguments::get_java_home()) + 1.156 - sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR)); 1.157 - sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR, 1.158 - Arguments::get_java_home()); 1.159 - Arguments::set_ext_dirs(buf); 1.160 - } 1.161 - 1.162 - /* Endorsed standards default directory. */ 1.163 - { 1.164 - char * buf; 1.165 - buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR)); 1.166 - sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); 1.167 - Arguments::set_endorsed_dirs(buf); 1.168 - } 1.169 - } 1.170 - 1.171 -#undef malloc 1.172 -#undef getenv 1.173 + Arguments::set_java_home(buf); 1.174 + set_boot_path('/', ':'); 1.175 + } 1.176 + 1.177 + // Where to look for native libraries. 1.178 + // 1.179 + // Note: Due to a legacy implementation, most of the library path 1.180 + // is set in the launcher. This was to accomodate linking restrictions 1.181 + // on legacy Linux implementations (which are no longer supported). 1.182 + // Eventually, all the library path setting will be done here. 1.183 + // 1.184 + // However, to prevent the proliferation of improperly built native 1.185 + // libraries, the new path component /usr/java/packages is added here. 1.186 + // Eventually, all the library path setting will be done here. 1.187 + { 1.188 + // Get the user setting of LD_LIBRARY_PATH, and prepended it. It 1.189 + // should always exist (until the legacy problem cited above is 1.190 + // addressed). 1.191 + const char *v = ::getenv("LD_LIBRARY_PATH"); 1.192 + const char *v_colon = ":"; 1.193 + if (v == NULL) { v = ""; v_colon = ""; } 1.194 + // That's +1 for the colon and +1 for the trailing '\0'. 1.195 + char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, 1.196 + strlen(v) + 1 + 1.197 + sizeof(SYS_EXT_DIR) + sizeof("/lib/") + strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH) + 1, 1.198 + mtInternal); 1.199 + sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib/%s:" DEFAULT_LIBPATH, v, v_colon, cpu_arch); 1.200 + Arguments::set_library_path(ld_library_path); 1.201 + FREE_C_HEAP_ARRAY(char, ld_library_path, mtInternal); 1.202 + } 1.203 + 1.204 + // Extensions directories. 1.205 + sprintf(buf, "%s" EXTENSIONS_DIR ":" SYS_EXT_DIR EXTENSIONS_DIR, Arguments::get_java_home()); 1.206 + Arguments::set_ext_dirs(buf); 1.207 + 1.208 + // Endorsed standards default directory. 1.209 + sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); 1.210 + Arguments::set_endorsed_dirs(buf); 1.211 + 1.212 + FREE_C_HEAP_ARRAY(char, buf, mtInternal); 1.213 + 1.214 +#undef DEFAULT_LIBPATH 1.215 +#undef SYS_EXT_DIR 1.216 #undef EXTENSIONS_DIR 1.217 #undef ENDORSED_DIR 1.218 - 1.219 - // Done 1.220 - return; 1.221 } 1.222 1.223 //////////////////////////////////////////////////////////////////////////////// 1.224 @@ -1997,6 +1958,7 @@ 1.225 {EM_S390, EM_S390, ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"}, 1.226 {EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"}, 1.227 {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"}, 1.228 + {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, 1.229 {EM_MIPS, EM_MIPS, ELFCLASS64, ELFDATA2LSB, (char*)"MIPS64 LE"}, 1.230 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, 1.231 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} 1.232 @@ -3306,82 +3268,126 @@ 1.233 1.234 static size_t _large_page_size = 0; 1.235 1.236 -void os::large_page_init() { 1.237 - if (!UseLargePages) { 1.238 - UseHugeTLBFS = false; 1.239 - UseSHM = false; 1.240 - return; 1.241 - } 1.242 - 1.243 - if (FLAG_IS_DEFAULT(UseHugeTLBFS) && FLAG_IS_DEFAULT(UseSHM)) { 1.244 - // If UseLargePages is specified on the command line try both methods, 1.245 - // if it's default, then try only HugeTLBFS. 1.246 - if (FLAG_IS_DEFAULT(UseLargePages)) { 1.247 - UseHugeTLBFS = true; 1.248 - } else { 1.249 - UseHugeTLBFS = UseSHM = true; 1.250 - } 1.251 - } 1.252 - 1.253 - if (LargePageSizeInBytes) { 1.254 - _large_page_size = LargePageSizeInBytes; 1.255 - } else { 1.256 - // large_page_size on Linux is used to round up heap size. x86 uses either 1.257 - // 2M or 4M page, depending on whether PAE (Physical Address Extensions) 1.258 - // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use 1.259 - // page as large as 256M. 1.260 - // 1.261 - // Here we try to figure out page size by parsing /proc/meminfo and looking 1.262 - // for a line with the following format: 1.263 - // Hugepagesize: 2048 kB 1.264 - // 1.265 - // If we can't determine the value (e.g. /proc is not mounted, or the text 1.266 - // format has been changed), we'll use the largest page size supported by 1.267 - // the processor. 1.268 +size_t os::Linux::find_large_page_size() { 1.269 + size_t large_page_size = 0; 1.270 + 1.271 + // large_page_size on Linux is used to round up heap size. x86 uses either 1.272 + // 2M or 4M page, depending on whether PAE (Physical Address Extensions) 1.273 + // mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use 1.274 + // page as large as 256M. 1.275 + // 1.276 + // Here we try to figure out page size by parsing /proc/meminfo and looking 1.277 + // for a line with the following format: 1.278 + // Hugepagesize: 2048 kB 1.279 + // 1.280 + // If we can't determine the value (e.g. /proc is not mounted, or the text 1.281 + // format has been changed), we'll use the largest page size supported by 1.282 + // the processor. 1.283 1.284 #ifndef ZERO 1.285 - _large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M) 1.286 - ARM_ONLY(2 * M) PPC_ONLY(4 * M) MIPS64_ONLY(4 * M); //In MIPS _large_page_size is seted 4*M. 1.287 + large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M) 1.288 + ARM_ONLY(2 * M) PPC_ONLY(4 * M) MIPS64_ONLY(4 * M); //In MIPS _large_page_size is seted 4*M. 1.289 #endif // ZERO 1.290 1.291 - FILE *fp = fopen("/proc/meminfo", "r"); 1.292 - if (fp) { 1.293 - while (!feof(fp)) { 1.294 - int x = 0; 1.295 - char buf[16]; 1.296 - if (fscanf(fp, "Hugepagesize: %d", &x) == 1) { 1.297 - if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) { 1.298 - _large_page_size = x * K; 1.299 - break; 1.300 - } 1.301 - } else { 1.302 - // skip to next line 1.303 - for (;;) { 1.304 - int ch = fgetc(fp); 1.305 - if (ch == EOF || ch == (int)'\n') break; 1.306 - } 1.307 + FILE *fp = fopen("/proc/meminfo", "r"); 1.308 + if (fp) { 1.309 + while (!feof(fp)) { 1.310 + int x = 0; 1.311 + char buf[16]; 1.312 + if (fscanf(fp, "Hugepagesize: %d", &x) == 1) { 1.313 + if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) { 1.314 + large_page_size = x * K; 1.315 + break; 1.316 + } 1.317 + } else { 1.318 + // skip to next line 1.319 + for (;;) { 1.320 + int ch = fgetc(fp); 1.321 + if (ch == EOF || ch == (int)'\n') break; 1.322 } 1.323 } 1.324 - fclose(fp); 1.325 } 1.326 - } 1.327 - 1.328 - // print a warning if any large page related flag is specified on command line 1.329 - bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS); 1.330 - 1.331 + fclose(fp); 1.332 + } 1.333 + 1.334 + if (!FLAG_IS_DEFAULT(LargePageSizeInBytes) && LargePageSizeInBytes != large_page_size) { 1.335 + warning("Setting LargePageSizeInBytes has no effect on this OS. Large page size is " 1.336 + SIZE_FORMAT "%s.", byte_size_in_proper_unit(large_page_size), 1.337 + proper_unit_for_byte_size(large_page_size)); 1.338 + } 1.339 + 1.340 + return large_page_size; 1.341 +} 1.342 + 1.343 +size_t os::Linux::setup_large_page_size() { 1.344 + _large_page_size = Linux::find_large_page_size(); 1.345 const size_t default_page_size = (size_t)Linux::page_size(); 1.346 if (_large_page_size > default_page_size) { 1.347 _page_sizes[0] = _large_page_size; 1.348 _page_sizes[1] = default_page_size; 1.349 _page_sizes[2] = 0; 1.350 } 1.351 - UseHugeTLBFS = UseHugeTLBFS && 1.352 - Linux::hugetlbfs_sanity_check(warn_on_failure, _large_page_size); 1.353 - 1.354 - if (UseHugeTLBFS) 1.355 + 1.356 + return _large_page_size; 1.357 +} 1.358 + 1.359 +bool os::Linux::setup_large_page_type(size_t page_size) { 1.360 + if (FLAG_IS_DEFAULT(UseHugeTLBFS) && 1.361 + FLAG_IS_DEFAULT(UseSHM) && 1.362 + FLAG_IS_DEFAULT(UseTransparentHugePages)) { 1.363 + 1.364 + // The type of large pages has not been specified by the user. 1.365 + 1.366 + // Try UseHugeTLBFS and then UseSHM. 1.367 + UseHugeTLBFS = UseSHM = true; 1.368 + 1.369 + // Don't try UseTransparentHugePages since there are known 1.370 + // performance issues with it turned on. This might change in the future. 1.371 + UseTransparentHugePages = false; 1.372 + } 1.373 + 1.374 + if (UseTransparentHugePages) { 1.375 + bool warn_on_failure = !FLAG_IS_DEFAULT(UseTransparentHugePages); 1.376 + if (transparent_huge_pages_sanity_check(warn_on_failure, page_size)) { 1.377 + UseHugeTLBFS = false; 1.378 + UseSHM = false; 1.379 + return true; 1.380 + } 1.381 + UseTransparentHugePages = false; 1.382 + } 1.383 + 1.384 + if (UseHugeTLBFS) { 1.385 + bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS); 1.386 + if (hugetlbfs_sanity_check(warn_on_failure, page_size)) { 1.387 + UseSHM = false; 1.388 + return true; 1.389 + } 1.390 + UseHugeTLBFS = false; 1.391 + } 1.392 + 1.393 + return UseSHM; 1.394 +} 1.395 + 1.396 +void os::large_page_init() { 1.397 + if (!UseLargePages && 1.398 + !UseTransparentHugePages && 1.399 + !UseHugeTLBFS && 1.400 + !UseSHM) { 1.401 + // Not using large pages. 1.402 + return; 1.403 + } 1.404 + 1.405 + if (!FLAG_IS_DEFAULT(UseLargePages) && !UseLargePages) { 1.406 + // The user explicitly turned off large pages. 1.407 + // Ignore the rest of the large pages flags. 1.408 + UseTransparentHugePages = false; 1.409 + UseHugeTLBFS = false; 1.410 UseSHM = false; 1.411 - 1.412 - UseLargePages = UseHugeTLBFS || UseSHM; 1.413 + return; 1.414 + } 1.415 + 1.416 + size_t large_page_size = Linux::setup_large_page_size(); 1.417 + UseLargePages = Linux::setup_large_page_type(large_page_size); 1.418 1.419 set_coredump_filter(); 1.420 } 1.421 @@ -4801,7 +4807,6 @@ 1.422 #else 1.423 address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); 1.424 #endif 1.425 - 1.426 guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" ); 1.427 1.428 os::set_polling_page( polling_page ); 1.429 @@ -4836,7 +4841,7 @@ 1.430 // size. Add a page for compiler2 recursion in main thread. 1.431 // Add in 2*BytesPerWord times page size to account for VM stack during 1.432 // class initialization depending on 32 or 64 bit VM. 1.433 - 1.434 + 1.435 /* 2014/1/2 Liao: JDK8 requires larger -Xss option. 1.436 * TongWeb cannot run with -Xss192K. 1.437 * We are not sure whether this causes errors, so simply print a warning. */ 1.438 @@ -4859,7 +4864,6 @@ 1.439 warning("JDK8 requires the stack size be at least %dk, the current value is %dk. " 1.440 "Resize -Xss for best performance.", os::Linux::min_stack_allowed/ K, ThreadStackSize); 1.441 } 1.442 - 1.443 // Make the stack size a multiple of the page size so that 1.444 // the yellow/red zones can be guarded. 1.445 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,