31 #include "code/vtableStubs.hpp" |
31 #include "code/vtableStubs.hpp" |
32 #include "compiler/compileBroker.hpp" |
32 #include "compiler/compileBroker.hpp" |
33 #include "compiler/disassembler.hpp" |
33 #include "compiler/disassembler.hpp" |
34 #include "interpreter/interpreter.hpp" |
34 #include "interpreter/interpreter.hpp" |
35 #include "logging/log.hpp" |
35 #include "logging/log.hpp" |
|
36 #include "logging/logStream.hpp" |
36 #include "memory/allocation.inline.hpp" |
37 #include "memory/allocation.inline.hpp" |
37 #include "memory/filemap.hpp" |
38 #include "memory/filemap.hpp" |
38 #include "oops/oop.inline.hpp" |
39 #include "oops/oop.inline.hpp" |
39 #include "os_linux.inline.hpp" |
40 #include "os_linux.inline.hpp" |
|
41 #include "os_posix.inline.hpp" |
40 #include "os_share_linux.hpp" |
42 #include "os_share_linux.hpp" |
41 #include "osContainer_linux.hpp" |
43 #include "osContainer_linux.hpp" |
42 #include "prims/jniFastGetField.hpp" |
44 #include "prims/jniFastGetField.hpp" |
43 #include "prims/jvm_misc.hpp" |
45 #include "prims/jvm_misc.hpp" |
44 #include "runtime/arguments.hpp" |
46 #include "runtime/arguments.hpp" |
126 #define MAX_SECS 100000000 |
130 #define MAX_SECS 100000000 |
127 |
131 |
128 // for timer info max values which include all bits |
132 // for timer info max values which include all bits |
129 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
133 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
130 |
134 |
131 #define LARGEPAGES_BIT (1 << 6) |
135 enum CoredumpFilterBit { |
132 #define DAX_SHARED_BIT (1 << 8) |
136 FILE_BACKED_PVT_BIT = 1 << 2, |
|
137 FILE_BACKED_SHARED_BIT = 1 << 3, |
|
138 LARGEPAGES_BIT = 1 << 6, |
|
139 DAX_SHARED_BIT = 1 << 8 |
|
140 }; |
|
141 |
133 //////////////////////////////////////////////////////////////////////////////// |
142 //////////////////////////////////////////////////////////////////////////////// |
134 // global variables |
143 // global variables |
135 julong os::Linux::_physical_memory = 0; |
144 julong os::Linux::_physical_memory = 0; |
136 |
145 |
137 address os::Linux::_initial_thread_stack_bottom = NULL; |
146 address os::Linux::_initial_thread_stack_bottom = NULL; |
138 uintptr_t os::Linux::_initial_thread_stack_size = 0; |
147 uintptr_t os::Linux::_initial_thread_stack_size = 0; |
139 |
148 |
140 int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL; |
|
141 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; |
149 int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; |
142 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL; |
150 int (*os::Linux::_pthread_setname_np)(pthread_t, const char*) = NULL; |
143 Mutex* os::Linux::_createThread_lock = NULL; |
|
144 pthread_t os::Linux::_main_thread; |
151 pthread_t os::Linux::_main_thread; |
145 int os::Linux::_page_size = -1; |
152 int os::Linux::_page_size = -1; |
146 bool os::Linux::_supports_fast_thread_cpu_time = false; |
153 bool os::Linux::_supports_fast_thread_cpu_time = false; |
147 uint32_t os::Linux::_os_version = 0; |
|
148 const char * os::Linux::_glibc_version = NULL; |
154 const char * os::Linux::_glibc_version = NULL; |
149 const char * os::Linux::_libpthread_version = NULL; |
155 const char * os::Linux::_libpthread_version = NULL; |
150 |
156 |
151 static jlong initial_time_count=0; |
157 static jlong initial_time_count=0; |
152 |
158 |
217 } |
223 } |
218 |
224 |
219 phys_mem = Linux::physical_memory(); |
225 phys_mem = Linux::physical_memory(); |
220 log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem); |
226 log_trace(os)("total system memory: " JLONG_FORMAT, phys_mem); |
221 return phys_mem; |
227 return phys_mem; |
|
228 } |
|
229 |
|
230 static uint64_t initial_total_ticks = 0; |
|
231 static uint64_t initial_steal_ticks = 0; |
|
232 static bool has_initial_tick_info = false; |
|
233 |
|
234 static void next_line(FILE *f) { |
|
235 int c; |
|
236 do { |
|
237 c = fgetc(f); |
|
238 } while (c != '\n' && c != EOF); |
|
239 } |
|
240 |
|
241 bool os::Linux::get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu) { |
|
242 FILE* fh; |
|
243 uint64_t userTicks, niceTicks, systemTicks, idleTicks; |
|
244 // since at least kernel 2.6 : iowait: time waiting for I/O to complete |
|
245 // irq: time servicing interrupts; softirq: time servicing softirqs |
|
246 uint64_t iowTicks = 0, irqTicks = 0, sirqTicks= 0; |
|
247 // steal (since kernel 2.6.11): time spent in other OS when running in a virtualized environment |
|
248 uint64_t stealTicks = 0; |
|
249 // guest (since kernel 2.6.24): time spent running a virtual CPU for guest OS under the |
|
250 // control of the Linux kernel |
|
251 uint64_t guestNiceTicks = 0; |
|
252 int logical_cpu = -1; |
|
253 const int required_tickinfo_count = (which_logical_cpu == -1) ? 4 : 5; |
|
254 int n; |
|
255 |
|
256 memset(pticks, 0, sizeof(CPUPerfTicks)); |
|
257 |
|
258 if ((fh = fopen("/proc/stat", "r")) == NULL) { |
|
259 return false; |
|
260 } |
|
261 |
|
262 if (which_logical_cpu == -1) { |
|
263 n = fscanf(fh, "cpu " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " |
|
264 UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " |
|
265 UINT64_FORMAT " " UINT64_FORMAT " ", |
|
266 &userTicks, &niceTicks, &systemTicks, &idleTicks, |
|
267 &iowTicks, &irqTicks, &sirqTicks, |
|
268 &stealTicks, &guestNiceTicks); |
|
269 } else { |
|
270 // Move to next line |
|
271 next_line(fh); |
|
272 |
|
273 // find the line for requested cpu faster to just iterate linefeeds? |
|
274 for (int i = 0; i < which_logical_cpu; i++) { |
|
275 next_line(fh); |
|
276 } |
|
277 |
|
278 n = fscanf(fh, "cpu%u " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " |
|
279 UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " UINT64_FORMAT " " |
|
280 UINT64_FORMAT " " UINT64_FORMAT " ", |
|
281 &logical_cpu, &userTicks, &niceTicks, |
|
282 &systemTicks, &idleTicks, &iowTicks, &irqTicks, &sirqTicks, |
|
283 &stealTicks, &guestNiceTicks); |
|
284 } |
|
285 |
|
286 fclose(fh); |
|
287 if (n < required_tickinfo_count || logical_cpu != which_logical_cpu) { |
|
288 return false; |
|
289 } |
|
290 pticks->used = userTicks + niceTicks; |
|
291 pticks->usedKernel = systemTicks + irqTicks + sirqTicks; |
|
292 pticks->total = userTicks + niceTicks + systemTicks + idleTicks + |
|
293 iowTicks + irqTicks + sirqTicks + stealTicks + guestNiceTicks; |
|
294 |
|
295 if (n > required_tickinfo_count + 3) { |
|
296 pticks->steal = stealTicks; |
|
297 pticks->has_steal_ticks = true; |
|
298 } else { |
|
299 pticks->steal = 0; |
|
300 pticks->has_steal_ticks = false; |
|
301 } |
|
302 |
|
303 return true; |
222 } |
304 } |
223 |
305 |
224 // Return true if user is running as root. |
306 // Return true if user is running as root. |
225 |
307 |
226 bool os::have_special_privileges() { |
308 bool os::have_special_privileges() { |
339 // Note that the space for the colon and the trailing null are provided |
424 // Note that the space for the colon and the trailing null are provided |
340 // by the nulls included by the sizeof operator. |
425 // by the nulls included by the sizeof operator. |
341 const size_t bufsize = |
426 const size_t bufsize = |
342 MAX2((size_t)MAXPATHLEN, // For dll_dir & friends. |
427 MAX2((size_t)MAXPATHLEN, // For dll_dir & friends. |
343 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir |
428 (size_t)MAXPATHLEN + sizeof(EXTENSIONS_DIR) + sizeof(SYS_EXT_DIR) + sizeof(EXTENSIONS_DIR)); // extensions dir |
344 char *buf = (char *)NEW_C_HEAP_ARRAY(char, bufsize, mtInternal); |
429 char *buf = NEW_C_HEAP_ARRAY(char, bufsize, mtInternal); |
345 |
430 |
346 // sysclasspath, java_home, dll_dir |
431 // sysclasspath, java_home, dll_dir |
347 { |
432 { |
348 char *pslash; |
433 char *pslash; |
349 os::jvm_path(buf, bufsize); |
434 os::jvm_path(buf, bufsize); |
388 // addressed). |
473 // addressed). |
389 const char *v = ::getenv("LD_LIBRARY_PATH"); |
474 const char *v = ::getenv("LD_LIBRARY_PATH"); |
390 const char *v_colon = ":"; |
475 const char *v_colon = ":"; |
391 if (v == NULL) { v = ""; v_colon = ""; } |
476 if (v == NULL) { v = ""; v_colon = ""; } |
392 // That's +1 for the colon and +1 for the trailing '\0'. |
477 // That's +1 for the colon and +1 for the trailing '\0'. |
393 char *ld_library_path = (char *)NEW_C_HEAP_ARRAY(char, |
478 char *ld_library_path = NEW_C_HEAP_ARRAY(char, |
394 strlen(v) + 1 + |
479 strlen(v) + 1 + |
395 sizeof(SYS_EXT_DIR) + sizeof("/lib/") + sizeof(DEFAULT_LIBPATH) + 1, |
480 sizeof(SYS_EXT_DIR) + sizeof("/lib/") + sizeof(DEFAULT_LIBPATH) + 1, |
396 mtInternal); |
481 mtInternal); |
397 sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib:" DEFAULT_LIBPATH, v, v_colon); |
482 sprintf(ld_library_path, "%s%s" SYS_EXT_DIR "/lib:" DEFAULT_LIBPATH, v, v_colon); |
398 Arguments::set_library_path(ld_library_path); |
483 Arguments::set_library_path(ld_library_path); |
399 FREE_C_HEAP_ARRAY(char, ld_library_path); |
484 FREE_C_HEAP_ARRAY(char, ld_library_path); |
400 } |
485 } |
401 |
486 |
682 // initialize floating point control register |
770 // initialize floating point control register |
683 os::Linux::init_thread_fpu_state(); |
771 os::Linux::init_thread_fpu_state(); |
684 |
772 |
685 // handshaking with parent thread |
773 // handshaking with parent thread |
686 { |
774 { |
687 MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag); |
775 MutexLocker ml(sync, Mutex::_no_safepoint_check_flag); |
688 |
776 |
689 // notify parent thread |
777 // notify parent thread |
690 osthread->set_state(INITIALIZED); |
778 osthread->set_state(INITIALIZED); |
691 sync->notify_all(); |
779 sync->notify_all(); |
692 |
780 |
693 // wait until os::start_thread() |
781 // wait until os::start_thread() |
694 while (osthread->get_state() == INITIALIZED) { |
782 while (osthread->get_state() == INITIALIZED) { |
695 sync->wait(Mutex::_no_safepoint_check_flag); |
783 sync->wait_without_safepoint_check(); |
696 } |
784 } |
697 } |
785 } |
|
786 |
|
787 assert(osthread->pthread_id() != 0, "pthread_id was not set as expected"); |
698 |
788 |
699 // call one more level start routine |
789 // call one more level start routine |
700 thread->run(); |
790 thread->call_run(); |
|
791 |
|
792 // Note: at this point the thread object may already have deleted itself. |
|
793 // Prevent dereferencing it from here on out. |
|
794 thread = NULL; |
701 |
795 |
702 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", |
796 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", |
703 os::current_thread_id(), (uintx) pthread_self()); |
797 os::current_thread_id(), (uintx) pthread_self()); |
704 |
798 |
705 // If a thread has not deleted itself ("delete this") as part of its |
|
706 // termination sequence, we have to ensure thread-local-storage is |
|
707 // cleared before we actually terminate. No threads should ever be |
|
708 // deleted asynchronously with respect to their termination. |
|
709 if (Thread::current_or_null_safe() != NULL) { |
|
710 assert(Thread::current_or_null_safe() == thread, "current thread is wrong"); |
|
711 thread->clear_thread_current(); |
|
712 } |
|
713 |
|
714 return 0; |
799 return 0; |
|
800 } |
|
801 |
|
802 // On Linux, glibc places static TLS blocks (for __thread variables) on |
|
803 // the thread stack. This decreases the stack size actually available |
|
804 // to threads. |
|
805 // |
|
806 // For large static TLS sizes, this may cause threads to malfunction due |
|
807 // to insufficient stack space. This is a well-known issue in glibc: |
|
808 // http://sourceware.org/bugzilla/show_bug.cgi?id=11787. |
|
809 // |
|
810 // As a workaround, we call a private but assumed-stable glibc function, |
|
811 // __pthread_get_minstack() to obtain the minstack size and derive the |
|
812 // static TLS size from it. We then increase the user requested stack |
|
813 // size by this TLS size. |
|
814 // |
|
815 // Due to compatibility concerns, this size adjustment is opt-in and |
|
816 // controlled via AdjustStackSizeForTLS. |
|
817 typedef size_t (*GetMinStack)(const pthread_attr_t *attr); |
|
818 |
|
819 GetMinStack _get_minstack_func = NULL; |
|
820 |
|
821 static void get_minstack_init() { |
|
822 _get_minstack_func = |
|
823 (GetMinStack)dlsym(RTLD_DEFAULT, "__pthread_get_minstack"); |
|
824 log_info(os, thread)("Lookup of __pthread_get_minstack %s", |
|
825 _get_minstack_func == NULL ? "failed" : "succeeded"); |
|
826 } |
|
827 |
|
828 // Returns the size of the static TLS area glibc puts on thread stacks. |
|
829 // The value is cached on first use, which occurs when the first thread |
|
830 // is created during VM initialization. |
|
831 static size_t get_static_tls_area_size(const pthread_attr_t *attr) { |
|
832 size_t tls_size = 0; |
|
833 if (_get_minstack_func != NULL) { |
|
834 // Obtain the pthread minstack size by calling __pthread_get_minstack. |
|
835 size_t minstack_size = _get_minstack_func(attr); |
|
836 |
|
837 // Remove non-TLS area size included in minstack size returned |
|
838 // by __pthread_get_minstack() to get the static TLS size. |
|
839 // In glibc before 2.27, minstack size includes guard_size. |
|
840 // In glibc 2.27 and later, guard_size is automatically added |
|
841 // to the stack size by pthread_create and is no longer included |
|
842 // in minstack size. In both cases, the guard_size is taken into |
|
843 // account, so there is no need to adjust the result for that. |
|
844 // |
|
845 // Although __pthread_get_minstack() is a private glibc function, |
|
846 // it is expected to have a stable behavior across future glibc |
|
847 // versions while glibc still allocates the static TLS blocks off |
|
848 // the stack. Following is glibc 2.28 __pthread_get_minstack(): |
|
849 // |
|
850 // size_t |
|
851 // __pthread_get_minstack (const pthread_attr_t *attr) |
|
852 // { |
|
853 // return GLRO(dl_pagesize) + __static_tls_size + PTHREAD_STACK_MIN; |
|
854 // } |
|
855 // |
|
856 // |
|
857 // The following 'minstack_size > os::vm_page_size() + PTHREAD_STACK_MIN' |
|
858 // if check is done for precaution. |
|
859 if (minstack_size > (size_t)os::vm_page_size() + PTHREAD_STACK_MIN) { |
|
860 tls_size = minstack_size - os::vm_page_size() - PTHREAD_STACK_MIN; |
|
861 } |
|
862 } |
|
863 |
|
864 log_info(os, thread)("Stack size adjustment for TLS is " SIZE_FORMAT, |
|
865 tls_size); |
|
866 return tls_size; |
715 } |
867 } |
716 |
868 |
717 bool os::create_thread(Thread* thread, ThreadType thr_type, |
869 bool os::create_thread(Thread* thread, ThreadType thr_type, |
718 size_t req_stack_size) { |
870 size_t req_stack_size) { |
719 assert(thread->osthread() == NULL, "caller responsible"); |
871 assert(thread->osthread() == NULL, "caller responsible"); |
737 pthread_attr_init(&attr); |
889 pthread_attr_init(&attr); |
738 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
890 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
739 |
891 |
740 // Calculate stack size if it's not specified by caller. |
892 // Calculate stack size if it's not specified by caller. |
741 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size); |
893 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size); |
742 // In the Linux NPTL pthread implementation the guard size mechanism |
894 // In glibc versions prior to 2.7 the guard size mechanism |
743 // is not implemented properly. The posix standard requires adding |
895 // is not implemented properly. The posix standard requires adding |
744 // the size of the guard pages to the stack size, instead Linux |
896 // the size of the guard pages to the stack size, instead Linux |
745 // takes the space out of 'stacksize'. Thus we adapt the requested |
897 // takes the space out of 'stacksize'. Thus we adapt the requested |
746 // stack_size by the size of the guard pages to mimick proper |
898 // stack_size by the size of the guard pages to mimick proper |
747 // behaviour. However, be careful not to end up with a size |
899 // behaviour. However, be careful not to end up with a size |
748 // of zero due to overflow. Don't add the guard page in that case. |
900 // of zero due to overflow. Don't add the guard page in that case. |
749 size_t guard_size = os::Linux::default_guard_size(thr_type); |
901 size_t guard_size = os::Linux::default_guard_size(thr_type); |
750 if (stack_size <= SIZE_MAX - guard_size) { |
902 // Configure glibc guard page. Must happen before calling |
751 stack_size += guard_size; |
903 // get_static_tls_area_size(), which uses the guard_size. |
|
904 pthread_attr_setguardsize(&attr, guard_size); |
|
905 |
|
906 size_t stack_adjust_size = 0; |
|
907 if (AdjustStackSizeForTLS) { |
|
908 // Adjust the stack_size for on-stack TLS - see get_static_tls_area_size(). |
|
909 stack_adjust_size += get_static_tls_area_size(&attr); |
|
910 } else { |
|
911 stack_adjust_size += guard_size; |
|
912 } |
|
913 |
|
914 stack_adjust_size = align_up(stack_adjust_size, os::vm_page_size()); |
|
915 if (stack_size <= SIZE_MAX - stack_adjust_size) { |
|
916 stack_size += stack_adjust_size; |
752 } |
917 } |
753 assert(is_aligned(stack_size, os::vm_page_size()), "stack_size not aligned"); |
918 assert(is_aligned(stack_size, os::vm_page_size()), "stack_size not aligned"); |
754 |
919 |
755 int status = pthread_attr_setstacksize(&attr, stack_size); |
920 int status = pthread_attr_setstacksize(&attr, stack_size); |
756 assert_status(status == 0, status, "pthread_attr_setstacksize"); |
921 assert_status(status == 0, status, "pthread_attr_setstacksize"); |
757 |
|
758 // Configure glibc guard page. |
|
759 pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type)); |
|
760 |
922 |
761 ThreadState state; |
923 ThreadState state; |
762 |
924 |
763 { |
925 { |
764 pthread_t tid; |
926 pthread_t tid; |
769 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
931 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
770 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
932 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
771 } else { |
933 } else { |
772 log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.", |
934 log_warning(os, thread)("Failed to start thread - pthread_create failed (%s) for attributes: %s.", |
773 os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
935 os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
|
936 // Log some OS information which might explain why creating the thread failed. |
|
937 log_info(os, thread)("Number of threads approx. running in the VM: %d", Threads::number_of_threads()); |
|
938 LogStream st(Log(os, thread)::info()); |
|
939 os::Posix::print_rlimit_info(&st); |
|
940 os::print_memory_info(&st); |
|
941 os::Linux::print_proc_sys_info(&st); |
|
942 os::Linux::print_container_info(&st); |
774 } |
943 } |
775 |
944 |
776 pthread_attr_destroy(&attr); |
945 pthread_attr_destroy(&attr); |
777 |
946 |
778 if (ret != 0) { |
947 if (ret != 0) { |
1216 assert(status != -1, "linux error"); |
1387 assert(status != -1, "linux error"); |
1217 seconds = jlong(time.tv_sec); |
1388 seconds = jlong(time.tv_sec); |
1218 nanos = jlong(time.tv_usec) * 1000; |
1389 nanos = jlong(time.tv_usec) * 1000; |
1219 } |
1390 } |
1220 |
1391 |
1221 |
|
1222 #ifndef CLOCK_MONOTONIC |
|
1223 #define CLOCK_MONOTONIC (1) |
|
1224 #endif |
|
1225 |
|
1226 void os::Linux::clock_init() { |
|
1227 // we do dlopen's in this particular order due to bug in linux |
|
1228 // dynamical loader (see 6348968) leading to crash on exit |
|
1229 void* handle = dlopen("librt.so.1", RTLD_LAZY); |
|
1230 if (handle == NULL) { |
|
1231 handle = dlopen("librt.so", RTLD_LAZY); |
|
1232 } |
|
1233 |
|
1234 if (handle) { |
|
1235 int (*clock_getres_func)(clockid_t, struct timespec*) = |
|
1236 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres"); |
|
1237 int (*clock_gettime_func)(clockid_t, struct timespec*) = |
|
1238 (int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime"); |
|
1239 if (clock_getres_func && clock_gettime_func) { |
|
1240 // See if monotonic clock is supported by the kernel. Note that some |
|
1241 // early implementations simply return kernel jiffies (updated every |
|
1242 // 1/100 or 1/1000 second). It would be bad to use such a low res clock |
|
1243 // for nano time (though the monotonic property is still nice to have). |
|
1244 // It's fixed in newer kernels, however clock_getres() still returns |
|
1245 // 1/HZ. We check if clock_getres() works, but will ignore its reported |
|
1246 // resolution for now. Hopefully as people move to new kernels, this |
|
1247 // won't be a problem. |
|
1248 struct timespec res; |
|
1249 struct timespec tp; |
|
1250 if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 && |
|
1251 clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) { |
|
1252 // yes, monotonic clock is supported |
|
1253 _clock_gettime = clock_gettime_func; |
|
1254 return; |
|
1255 } else { |
|
1256 // close librt if there is no monotonic clock |
|
1257 dlclose(handle); |
|
1258 } |
|
1259 } |
|
1260 } |
|
1261 warning("No monotonic clock was available - timed services may " \ |
|
1262 "be adversely affected if the time-of-day clock changes"); |
|
1263 } |
|
1264 |
|
1265 #ifndef SYS_clock_getres |
|
1266 #if defined(X86) || defined(PPC64) || defined(S390) |
|
1267 #define SYS_clock_getres AMD64_ONLY(229) IA32_ONLY(266) PPC64_ONLY(247) S390_ONLY(261) |
|
1268 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
|
1269 #else |
|
1270 #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" |
|
1271 #define sys_clock_getres(x,y) -1 |
|
1272 #endif |
|
1273 #else |
|
1274 #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
|
1275 #endif |
|
1276 |
|
1277 void os::Linux::fast_thread_clock_init() { |
1392 void os::Linux::fast_thread_clock_init() { |
1278 if (!UseLinuxPosixThreadCPUClocks) { |
1393 if (!UseLinuxPosixThreadCPUClocks) { |
1279 return; |
1394 return; |
1280 } |
1395 } |
1281 clockid_t clockid; |
1396 clockid_t clockid; |
1282 struct timespec tp; |
1397 struct timespec tp; |
1283 int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) = |
1398 int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) = |
1284 (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid"); |
1399 (int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid"); |
1285 |
1400 |
1286 // Switch to using fast clocks for thread cpu time if |
1401 // Switch to using fast clocks for thread cpu time if |
1287 // the sys_clock_getres() returns 0 error code. |
1402 // the clock_getres() returns 0 error code. |
1288 // Note, that some kernels may support the current thread |
1403 // Note, that some kernels may support the current thread |
1289 // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks |
1404 // clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks |
1290 // returned by the pthread_getcpuclockid(). |
1405 // returned by the pthread_getcpuclockid(). |
1291 // If the fast Posix clocks are supported then the sys_clock_getres() |
1406 // If the fast Posix clocks are supported then the clock_getres() |
1292 // must return at least tp.tv_sec == 0 which means a resolution |
1407 // must return at least tp.tv_sec == 0 which means a resolution |
1293 // better than 1 sec. This is extra check for reliability. |
1408 // better than 1 sec. This is extra check for reliability. |
1294 |
1409 |
1295 if (pthread_getcpuclockid_func && |
1410 if (pthread_getcpuclockid_func && |
1296 pthread_getcpuclockid_func(_main_thread, &clockid) == 0 && |
1411 pthread_getcpuclockid_func(_main_thread, &clockid) == 0 && |
1297 sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) { |
1412 os::Posix::clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) { |
1298 _supports_fast_thread_cpu_time = true; |
1413 _supports_fast_thread_cpu_time = true; |
1299 _pthread_getcpuclockid = pthread_getcpuclockid_func; |
1414 _pthread_getcpuclockid = pthread_getcpuclockid_func; |
1300 } |
1415 } |
1301 } |
1416 } |
1302 |
1417 |
1303 jlong os::javaTimeNanos() { |
1418 jlong os::javaTimeNanos() { |
1304 if (os::supports_monotonic_clock()) { |
1419 if (os::supports_monotonic_clock()) { |
1305 struct timespec tp; |
1420 struct timespec tp; |
1306 int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp); |
1421 int status = os::Posix::clock_gettime(CLOCK_MONOTONIC, &tp); |
1307 assert(status == 0, "gettime error"); |
1422 assert(status == 0, "gettime error"); |
1308 jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec); |
1423 jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec); |
1309 return result; |
1424 return result; |
1310 } else { |
1425 } else { |
1311 timeval time; |
1426 timeval time; |
1697 if (failed_to_read_elf_head) { |
1821 if (failed_to_read_elf_head) { |
1698 // file i/o error - report dlerror() msg |
1822 // file i/o error - report dlerror() msg |
1699 return NULL; |
1823 return NULL; |
1700 } |
1824 } |
1701 |
1825 |
|
1826 if (elf_head.e_ident[EI_DATA] != LITTLE_ENDIAN_ONLY(ELFDATA2LSB) BIG_ENDIAN_ONLY(ELFDATA2MSB)) { |
|
1827 // handle invalid/out of range endianness values |
|
1828 if (elf_head.e_ident[EI_DATA] == 0 || elf_head.e_ident[EI_DATA] > 2) { |
|
1829 return NULL; |
|
1830 } |
|
1831 |
|
1832 #if defined(VM_LITTLE_ENDIAN) |
|
1833 // VM is LE, shared object BE |
|
1834 elf_head.e_machine = be16toh(elf_head.e_machine); |
|
1835 #else |
|
1836 // VM is BE, shared object LE |
|
1837 elf_head.e_machine = le16toh(elf_head.e_machine); |
|
1838 #endif |
|
1839 } |
|
1840 |
1702 typedef struct { |
1841 typedef struct { |
1703 Elf32_Half code; // Actual value as defined in elf.h |
1842 Elf32_Half code; // Actual value as defined in elf.h |
1704 Elf32_Half compat_class; // Compatibility of archs at VM's sense |
1843 Elf32_Half compat_class; // Compatibility of archs at VM's sense |
1705 unsigned char elf_class; // 32 or 64 bit |
1844 unsigned char elf_class; // 32 or 64 bit |
1706 unsigned char endianess; // MSB or LSB |
1845 unsigned char endianness; // MSB or LSB |
1707 char* name; // String representation |
1846 char* name; // String representation |
1708 } arch_t; |
1847 } arch_t; |
1709 |
1848 |
1710 #ifndef EM_486 |
1849 #ifndef EM_486 |
1711 #define EM_486 6 /* Intel 80486 */ |
1850 #define EM_486 6 /* Intel 80486 */ |
1728 {EM_SH, EM_SH, ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"}, |
1867 {EM_SH, EM_SH, ELFCLASS32, ELFDATA2LSB, (char*)"SuperH"}, |
1729 #else |
1868 #else |
1730 {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
1869 {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
1731 {EM_SH, EM_SH, ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"}, |
1870 {EM_SH, EM_SH, ELFCLASS32, ELFDATA2MSB, (char*)"SuperH BE"}, |
1732 #endif |
1871 #endif |
1733 {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM"}, |
1872 {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM"}, |
1734 {EM_S390, EM_S390, ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"}, |
1873 // we only support 64 bit z architecture |
|
1874 {EM_S390, EM_S390, ELFCLASS64, ELFDATA2MSB, (char*)"IBM System/390"}, |
1735 {EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"}, |
1875 {EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"}, |
1736 {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"}, |
1876 {EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"}, |
1737 {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, |
1877 {EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, |
1738 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, |
1878 {EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, |
1739 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}, |
1879 {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"}, |
1775 #else |
1915 #else |
1776 #error Method os::dll_load requires that one of following is defined:\ |
1916 #error Method os::dll_load requires that one of following is defined:\ |
1777 AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, S390, SH, __sparc |
1917 AARCH64, ALPHA, ARM, AMD64, IA32, IA64, M68K, MIPS, MIPSEL, PARISC, __powerpc__, __powerpc64__, S390, SH, __sparc |
1778 #endif |
1918 #endif |
1779 |
1919 |
1780 // Identify compatability class for VM's architecture and library's architecture |
1920 // Identify compatibility class for VM's architecture and library's architecture |
1781 // Obtain string descriptions for architectures |
1921 // Obtain string descriptions for architectures |
1782 |
1922 |
1783 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
1923 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
1784 int running_arch_index=-1; |
1924 int running_arch_index=-1; |
1785 |
1925 |
1799 // Even though running architecture detection failed |
1939 // Even though running architecture detection failed |
1800 // we may still continue with reporting dlerror() message |
1940 // we may still continue with reporting dlerror() message |
1801 return NULL; |
1941 return NULL; |
1802 } |
1942 } |
1803 |
1943 |
1804 if (lib_arch.endianess != arch_array[running_arch_index].endianess) { |
|
1805 ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)"); |
|
1806 return NULL; |
|
1807 } |
|
1808 |
|
1809 #ifndef S390 |
|
1810 if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) { |
|
1811 ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)"); |
|
1812 return NULL; |
|
1813 } |
|
1814 #endif // !S390 |
|
1815 |
|
1816 if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) { |
1944 if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) { |
1817 if (lib_arch.name!=NULL) { |
1945 if (lib_arch.name != NULL) { |
1818 ::snprintf(diag_msg_buf, diag_msg_max_length-1, |
1946 ::snprintf(diag_msg_buf, diag_msg_max_length-1, |
1819 " (Possible cause: can't load %s-bit .so on a %s-bit platform)", |
1947 " (Possible cause: can't load %s .so on a %s platform)", |
1820 lib_arch.name, arch_array[running_arch_index].name); |
1948 lib_arch.name, arch_array[running_arch_index].name); |
1821 } else { |
1949 } else { |
1822 ::snprintf(diag_msg_buf, diag_msg_max_length-1, |
1950 ::snprintf(diag_msg_buf, diag_msg_max_length-1, |
1823 " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)", |
1951 " (Possible cause: can't load this .so (machine code=0x%x) on a %s platform)", |
1824 lib_arch.code, |
1952 lib_arch.code, arch_array[running_arch_index].name); |
1825 arch_array[running_arch_index].name); |
1953 } |
1826 } |
1954 return NULL; |
|
1955 } |
|
1956 |
|
1957 if (lib_arch.endianness != arch_array[running_arch_index].endianness) { |
|
1958 ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: endianness mismatch)"); |
|
1959 return NULL; |
|
1960 } |
|
1961 |
|
1962 // ELF file class/capacity : 0 - invalid, 1 - 32bit, 2 - 64bit |
|
1963 if (lib_arch.elf_class > 2 || lib_arch.elf_class < 1) { |
|
1964 ::snprintf(diag_msg_buf, diag_msg_max_length-1, " (Possible cause: invalid ELF file class)"); |
|
1965 return NULL; |
|
1966 } |
|
1967 |
|
1968 if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) { |
|
1969 ::snprintf(diag_msg_buf, diag_msg_max_length-1, |
|
1970 " (Possible cause: architecture word width mismatch, can't load %d-bit .so on a %d-bit platform)", |
|
1971 (int) lib_arch.elf_class * 32, arch_array[running_arch_index].elf_class * 32); |
|
1972 return NULL; |
1827 } |
1973 } |
1828 |
1974 |
1829 return NULL; |
1975 return NULL; |
1830 } |
1976 } |
1831 |
1977 |
1832 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, |
1978 void * os::Linux::dlopen_helper(const char *filename, char *ebuf, |
1833 int ebuflen) { |
1979 int ebuflen) { |
1834 void * result = ::dlopen(filename, RTLD_LAZY); |
1980 void * result = ::dlopen(filename, RTLD_LAZY); |
1835 if (result == NULL) { |
1981 if (result == NULL) { |
1836 ::strncpy(ebuf, ::dlerror(), ebuflen - 1); |
1982 const char* error_report = ::dlerror(); |
1837 ebuf[ebuflen-1] = '\0'; |
1983 if (error_report == NULL) { |
|
1984 error_report = "dlerror returned no error description"; |
|
1985 } |
|
1986 if (ebuf != NULL && ebuflen > 0) { |
|
1987 ::strncpy(ebuf, error_report, ebuflen-1); |
|
1988 ebuf[ebuflen-1]='\0'; |
|
1989 } |
|
1990 Events::log(NULL, "Loading shared library %s failed, %s", filename, error_report); |
|
1991 log_info(os)("shared library load of %s failed, %s", filename, error_report); |
|
1992 } else { |
|
1993 Events::log(NULL, "Loaded shared library %s", filename); |
|
1994 log_info(os)("shared library load of %s was successful", filename); |
1838 } |
1995 } |
1839 return result; |
1996 return result; |
1840 } |
1997 } |
1841 |
1998 |
1842 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, |
1999 void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, |
2131 st->print("\n/proc/meminfo:\n"); |
2298 st->print("\n/proc/meminfo:\n"); |
2132 _print_ascii_file("/proc/meminfo", st); |
2299 _print_ascii_file("/proc/meminfo", st); |
2133 st->cr(); |
2300 st->cr(); |
2134 } |
2301 } |
2135 |
2302 |
|
2303 void os::Linux::print_ld_preload_file(outputStream* st) { |
|
2304 _print_ascii_file("/etc/ld.so.preload", st, "\n/etc/ld.so.preload:"); |
|
2305 st->cr(); |
|
2306 } |
|
2307 |
2136 void os::Linux::print_container_info(outputStream* st) { |
2308 void os::Linux::print_container_info(outputStream* st) { |
2137 if (!OSContainer::is_containerized()) { |
2309 if (!OSContainer::is_containerized()) { |
2138 return; |
2310 return; |
2139 } |
2311 } |
2140 |
2312 |
2141 st->print("container (cgroup) information:\n"); |
2313 st->print("container (cgroup) information:\n"); |
2142 |
2314 |
2143 const char *p_ct = OSContainer::container_type(); |
2315 const char *p_ct = OSContainer::container_type(); |
2144 st->print("container_type: %s\n", p_ct != NULL ? p_ct : "failed"); |
2316 st->print("container_type: %s\n", p_ct != NULL ? p_ct : "not supported"); |
2145 |
2317 |
2146 char *p = OSContainer::cpu_cpuset_cpus(); |
2318 char *p = OSContainer::cpu_cpuset_cpus(); |
2147 st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "failed"); |
2319 st->print("cpu_cpuset_cpus: %s\n", p != NULL ? p : "not supported"); |
2148 free(p); |
2320 free(p); |
2149 |
2321 |
2150 p = OSContainer::cpu_cpuset_memory_nodes(); |
2322 p = OSContainer::cpu_cpuset_memory_nodes(); |
2151 st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "failed"); |
2323 st->print("cpu_memory_nodes: %s\n", p != NULL ? p : "not supported"); |
2152 free(p); |
2324 free(p); |
2153 |
2325 |
2154 int i = OSContainer::active_processor_count(); |
2326 int i = OSContainer::active_processor_count(); |
|
2327 st->print("active_processor_count: "); |
2155 if (i > 0) { |
2328 if (i > 0) { |
2156 st->print("active_processor_count: %d\n", i); |
2329 st->print("%d\n", i); |
2157 } else { |
2330 } else { |
2158 st->print("active_processor_count: failed\n"); |
2331 st->print("not supported\n"); |
2159 } |
2332 } |
2160 |
2333 |
2161 i = OSContainer::cpu_quota(); |
2334 i = OSContainer::cpu_quota(); |
2162 st->print("cpu_quota: %d\n", i); |
2335 st->print("cpu_quota: "); |
|
2336 if (i > 0) { |
|
2337 st->print("%d\n", i); |
|
2338 } else { |
|
2339 st->print("%s\n", i == OSCONTAINER_ERROR ? "not supported" : "no quota"); |
|
2340 } |
2163 |
2341 |
2164 i = OSContainer::cpu_period(); |
2342 i = OSContainer::cpu_period(); |
2165 st->print("cpu_period: %d\n", i); |
2343 st->print("cpu_period: "); |
|
2344 if (i > 0) { |
|
2345 st->print("%d\n", i); |
|
2346 } else { |
|
2347 st->print("%s\n", i == OSCONTAINER_ERROR ? "not supported" : "no period"); |
|
2348 } |
2166 |
2349 |
2167 i = OSContainer::cpu_shares(); |
2350 i = OSContainer::cpu_shares(); |
2168 st->print("cpu_shares: %d\n", i); |
2351 st->print("cpu_shares: "); |
|
2352 if (i > 0) { |
|
2353 st->print("%d\n", i); |
|
2354 } else { |
|
2355 st->print("%s\n", i == OSCONTAINER_ERROR ? "not supported" : "no shares"); |
|
2356 } |
2169 |
2357 |
2170 jlong j = OSContainer::memory_limit_in_bytes(); |
2358 jlong j = OSContainer::memory_limit_in_bytes(); |
2171 st->print("memory_limit_in_bytes: " JLONG_FORMAT "\n", j); |
2359 st->print("memory_limit_in_bytes: "); |
|
2360 if (j > 0) { |
|
2361 st->print(JLONG_FORMAT "\n", j); |
|
2362 } else { |
|
2363 st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); |
|
2364 } |
2172 |
2365 |
2173 j = OSContainer::memory_and_swap_limit_in_bytes(); |
2366 j = OSContainer::memory_and_swap_limit_in_bytes(); |
2174 st->print("memory_and_swap_limit_in_bytes: " JLONG_FORMAT "\n", j); |
2367 st->print("memory_and_swap_limit_in_bytes: "); |
|
2368 if (j > 0) { |
|
2369 st->print(JLONG_FORMAT "\n", j); |
|
2370 } else { |
|
2371 st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); |
|
2372 } |
2175 |
2373 |
2176 j = OSContainer::memory_soft_limit_in_bytes(); |
2374 j = OSContainer::memory_soft_limit_in_bytes(); |
2177 st->print("memory_soft_limit_in_bytes: " JLONG_FORMAT "\n", j); |
2375 st->print("memory_soft_limit_in_bytes: "); |
|
2376 if (j > 0) { |
|
2377 st->print(JLONG_FORMAT "\n", j); |
|
2378 } else { |
|
2379 st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); |
|
2380 } |
2178 |
2381 |
2179 j = OSContainer::OSContainer::memory_usage_in_bytes(); |
2382 j = OSContainer::OSContainer::memory_usage_in_bytes(); |
2180 st->print("memory_usage_in_bytes: " JLONG_FORMAT "\n", j); |
2383 st->print("memory_usage_in_bytes: "); |
|
2384 if (j > 0) { |
|
2385 st->print(JLONG_FORMAT "\n", j); |
|
2386 } else { |
|
2387 st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); |
|
2388 } |
2181 |
2389 |
2182 j = OSContainer::OSContainer::memory_max_usage_in_bytes(); |
2390 j = OSContainer::OSContainer::memory_max_usage_in_bytes(); |
2183 st->print("memory_max_usage_in_bytes: " JLONG_FORMAT "\n", j); |
2391 st->print("memory_max_usage_in_bytes: "); |
|
2392 if (j > 0) { |
|
2393 st->print(JLONG_FORMAT "\n", j); |
|
2394 } else { |
|
2395 st->print("%s\n", j == OSCONTAINER_ERROR ? "not supported" : "unlimited"); |
|
2396 } |
2184 st->cr(); |
2397 st->cr(); |
|
2398 } |
|
2399 |
|
2400 void os::Linux::print_steal_info(outputStream* st) { |
|
2401 if (has_initial_tick_info) { |
|
2402 CPUPerfTicks pticks; |
|
2403 bool res = os::Linux::get_tick_information(&pticks, -1); |
|
2404 |
|
2405 if (res && pticks.has_steal_ticks) { |
|
2406 uint64_t steal_ticks_difference = pticks.steal - initial_steal_ticks; |
|
2407 uint64_t total_ticks_difference = pticks.total - initial_total_ticks; |
|
2408 double steal_ticks_perc = 0.0; |
|
2409 if (total_ticks_difference != 0) { |
|
2410 steal_ticks_perc = (double) steal_ticks_difference / total_ticks_difference; |
|
2411 } |
|
2412 st->print_cr("Steal ticks since vm start: " UINT64_FORMAT, steal_ticks_difference); |
|
2413 st->print_cr("Steal ticks percentage since vm start:%7.3f", steal_ticks_perc); |
|
2414 } |
|
2415 } |
2185 } |
2416 } |
2186 |
2417 |
2187 void os::print_memory_info(outputStream* st) { |
2418 void os::print_memory_info(outputStream* st) { |
2188 |
2419 |
2189 st->print("Memory:"); |
2420 st->print("Memory:"); |
2930 libnuma_dlsym(handle, "numa_bitmask_isbitset"))); |
3131 libnuma_dlsym(handle, "numa_bitmask_isbitset"))); |
2931 set_numa_distance(CAST_TO_FN_PTR(numa_distance_func_t, |
3132 set_numa_distance(CAST_TO_FN_PTR(numa_distance_func_t, |
2932 libnuma_dlsym(handle, "numa_distance"))); |
3133 libnuma_dlsym(handle, "numa_distance"))); |
2933 set_numa_get_membind(CAST_TO_FN_PTR(numa_get_membind_func_t, |
3134 set_numa_get_membind(CAST_TO_FN_PTR(numa_get_membind_func_t, |
2934 libnuma_v2_dlsym(handle, "numa_get_membind"))); |
3135 libnuma_v2_dlsym(handle, "numa_get_membind"))); |
|
3136 set_numa_get_interleave_mask(CAST_TO_FN_PTR(numa_get_interleave_mask_func_t, |
|
3137 libnuma_v2_dlsym(handle, "numa_get_interleave_mask"))); |
2935 |
3138 |
2936 if (numa_available() != -1) { |
3139 if (numa_available() != -1) { |
2937 set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes")); |
3140 set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes")); |
2938 set_numa_all_nodes_ptr((struct bitmask **)libnuma_dlsym(handle, "numa_all_nodes_ptr")); |
3141 set_numa_all_nodes_ptr((struct bitmask **)libnuma_dlsym(handle, "numa_all_nodes_ptr")); |
2939 set_numa_nodes_ptr((struct bitmask **)libnuma_dlsym(handle, "numa_nodes_ptr")); |
3142 set_numa_nodes_ptr((struct bitmask **)libnuma_dlsym(handle, "numa_nodes_ptr")); |
|
3143 set_numa_interleave_bitmask(_numa_get_interleave_mask()); |
|
3144 set_numa_membind_bitmask(_numa_get_membind()); |
2940 // Create an index -> node mapping, since nodes are not always consecutive |
3145 // Create an index -> node mapping, since nodes are not always consecutive |
2941 _nindex_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true); |
3146 _nindex_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true); |
2942 rebuild_nindex_to_node_map(); |
3147 rebuild_nindex_to_node_map(); |
2943 // Create a cpu -> node mapping |
3148 // Create a cpu -> node mapping |
2944 _cpu_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true); |
3149 _cpu_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true); |
2997 for (size_t i = 0; i < node_num; i++) { |
3202 for (size_t i = 0; i < node_num; i++) { |
2998 // Check if node is configured (not a memory-less node). If it is not, find |
3203 // Check if node is configured (not a memory-less node). If it is not, find |
2999 // the closest configured node. Check also if node is bound, i.e. it's allowed |
3204 // the closest configured node. Check also if node is bound, i.e. it's allowed |
3000 // to allocate memory from the node. If it's not allowed, map cpus in that node |
3205 // to allocate memory from the node. If it's not allowed, map cpus in that node |
3001 // to the closest node from which memory allocation is allowed. |
3206 // to the closest node from which memory allocation is allowed. |
3002 if (!isnode_in_configured_nodes(nindex_to_node()->at(i)) || |
3207 if (!is_node_in_configured_nodes(nindex_to_node()->at(i)) || |
3003 !isnode_in_bound_nodes(nindex_to_node()->at(i))) { |
3208 !is_node_in_bound_nodes(nindex_to_node()->at(i))) { |
3004 closest_distance = INT_MAX; |
3209 closest_distance = INT_MAX; |
3005 // Check distance from all remaining nodes in the system. Ignore distance |
3210 // Check distance from all remaining nodes in the system. Ignore distance |
3006 // from itself, from another non-configured node, and from another non-bound |
3211 // from itself, from another non-configured node, and from another non-bound |
3007 // node. |
3212 // node. |
3008 for (size_t m = 0; m < node_num; m++) { |
3213 for (size_t m = 0; m < node_num; m++) { |
3009 if (m != i && |
3214 if (m != i && |
3010 isnode_in_configured_nodes(nindex_to_node()->at(m)) && |
3215 is_node_in_configured_nodes(nindex_to_node()->at(m)) && |
3011 isnode_in_bound_nodes(nindex_to_node()->at(m))) { |
3216 is_node_in_bound_nodes(nindex_to_node()->at(m))) { |
3012 distance = numa_distance(nindex_to_node()->at(i), nindex_to_node()->at(m)); |
3217 distance = numa_distance(nindex_to_node()->at(i), nindex_to_node()->at(m)); |
3013 // If a closest node is found, update. There is always at least one |
3218 // If a closest node is found, update. There is always at least one |
3014 // configured and bound node in the system so there is always at least |
3219 // configured and bound node in the system so there is always at least |
3015 // one node close. |
3220 // one node close. |
3016 if (distance != 0 && distance < closest_distance) { |
3221 if (distance != 0 && distance < closest_distance) { |
3061 os::Linux::numa_interleave_memory_v2_func_t os::Linux::_numa_interleave_memory_v2; |
3266 os::Linux::numa_interleave_memory_v2_func_t os::Linux::_numa_interleave_memory_v2; |
3062 os::Linux::numa_set_bind_policy_func_t os::Linux::_numa_set_bind_policy; |
3267 os::Linux::numa_set_bind_policy_func_t os::Linux::_numa_set_bind_policy; |
3063 os::Linux::numa_bitmask_isbitset_func_t os::Linux::_numa_bitmask_isbitset; |
3268 os::Linux::numa_bitmask_isbitset_func_t os::Linux::_numa_bitmask_isbitset; |
3064 os::Linux::numa_distance_func_t os::Linux::_numa_distance; |
3269 os::Linux::numa_distance_func_t os::Linux::_numa_distance; |
3065 os::Linux::numa_get_membind_func_t os::Linux::_numa_get_membind; |
3270 os::Linux::numa_get_membind_func_t os::Linux::_numa_get_membind; |
|
3271 os::Linux::numa_get_interleave_mask_func_t os::Linux::_numa_get_interleave_mask; |
|
3272 os::Linux::NumaAllocationPolicy os::Linux::_current_numa_policy; |
3066 unsigned long* os::Linux::_numa_all_nodes; |
3273 unsigned long* os::Linux::_numa_all_nodes; |
3067 struct bitmask* os::Linux::_numa_all_nodes_ptr; |
3274 struct bitmask* os::Linux::_numa_all_nodes_ptr; |
3068 struct bitmask* os::Linux::_numa_nodes_ptr; |
3275 struct bitmask* os::Linux::_numa_nodes_ptr; |
|
3276 struct bitmask* os::Linux::_numa_interleave_bitmask; |
|
3277 struct bitmask* os::Linux::_numa_membind_bitmask; |
3069 |
3278 |
3070 bool os::pd_uncommit_memory(char* addr, size_t size) { |
3279 bool os::pd_uncommit_memory(char* addr, size_t size) { |
3071 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, |
3280 uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, |
3072 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); |
3281 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); |
3073 return res != (uintptr_t) MAP_FAILED; |
3282 return res != (uintptr_t) MAP_FAILED; |
3345 // protection of malloc'ed or statically allocated memory). Check the |
3554 // protection of malloc'ed or statically allocated memory). Check the |
3346 // caller if you hit this assert. |
3555 // caller if you hit this assert. |
3347 assert(addr == bottom, "sanity check"); |
3556 assert(addr == bottom, "sanity check"); |
3348 |
3557 |
3349 size = align_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size()); |
3558 size = align_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size()); |
|
3559 Events::log(NULL, "Protecting memory [" INTPTR_FORMAT "," INTPTR_FORMAT "] with protection modes %x", p2i(bottom), p2i(bottom+size), prot); |
3350 return ::mprotect(bottom, size, prot) == 0; |
3560 return ::mprotect(bottom, size, prot) == 0; |
3351 } |
3561 } |
3352 |
3562 |
3353 // Set protections specified |
3563 // Set protections specified |
3354 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, |
3564 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, |
3443 // - (bit 5) hugetlb private memory |
3651 // - (bit 5) hugetlb private memory |
3444 // - (bit 6) hugetlb shared memory |
3652 // - (bit 6) hugetlb shared memory |
3445 // - (bit 7) dax private memory |
3653 // - (bit 7) dax private memory |
3446 // - (bit 8) dax shared memory |
3654 // - (bit 8) dax shared memory |
3447 // |
3655 // |
3448 static void set_coredump_filter(bool largepages, bool dax_shared) { |
3656 static void set_coredump_filter(CoredumpFilterBit bit) { |
3449 FILE *f; |
3657 FILE *f; |
3450 long cdm; |
3658 long cdm; |
3451 bool filter_changed = false; |
|
3452 |
3659 |
3453 if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) { |
3660 if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) { |
3454 return; |
3661 return; |
3455 } |
3662 } |
3456 |
3663 |
3457 if (fscanf(f, "%lx", &cdm) != 1) { |
3664 if (fscanf(f, "%lx", &cdm) != 1) { |
3458 fclose(f); |
3665 fclose(f); |
3459 return; |
3666 return; |
3460 } |
3667 } |
3461 |
3668 |
|
3669 long saved_cdm = cdm; |
3462 rewind(f); |
3670 rewind(f); |
3463 |
3671 cdm |= bit; |
3464 if (largepages && (cdm & LARGEPAGES_BIT) == 0) { |
3672 |
3465 cdm |= LARGEPAGES_BIT; |
3673 if (cdm != saved_cdm) { |
3466 filter_changed = true; |
|
3467 } |
|
3468 if (dax_shared && (cdm & DAX_SHARED_BIT) == 0) { |
|
3469 cdm |= DAX_SHARED_BIT; |
|
3470 filter_changed = true; |
|
3471 } |
|
3472 if (filter_changed) { |
|
3473 fprintf(f, "%#lx", cdm); |
3674 fprintf(f, "%#lx", cdm); |
3474 } |
3675 } |
3475 |
3676 |
3476 fclose(f); |
3677 fclose(f); |
3477 } |
3678 } |
3992 |
4193 |
3993 // Reserve memory at an arbitrary address, only if that area is |
4194 // Reserve memory at an arbitrary address, only if that area is |
3994 // available (and not reserved for something else). |
4195 // available (and not reserved for something else). |
3995 |
4196 |
3996 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
4197 char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
3997 const int max_tries = 10; |
|
3998 char* base[max_tries]; |
|
3999 size_t size[max_tries]; |
|
4000 const size_t gap = 0x000000; |
|
4001 |
|
4002 // Assert only that the size is a multiple of the page size, since |
4198 // Assert only that the size is a multiple of the page size, since |
4003 // that's all that mmap requires, and since that's all we really know |
4199 // that's all that mmap requires, and since that's all we really know |
4004 // about at this low abstraction level. If we need higher alignment, |
4200 // about at this low abstraction level. If we need higher alignment, |
4005 // we can either pass an alignment to this method or verify alignment |
4201 // we can either pass an alignment to this method or verify alignment |
4006 // in one of the methods further up the call chain. See bug 5044738. |
4202 // in one of the methods further up the call chain. See bug 5044738. |
4019 if (addr != NULL) { |
4215 if (addr != NULL) { |
4020 // mmap() is successful but it fails to reserve at the requested address |
4216 // mmap() is successful but it fails to reserve at the requested address |
4021 anon_munmap(addr, bytes); |
4217 anon_munmap(addr, bytes); |
4022 } |
4218 } |
4023 |
4219 |
4024 int i; |
4220 return NULL; |
4025 for (i = 0; i < max_tries; ++i) { |
|
4026 base[i] = reserve_memory(bytes); |
|
4027 |
|
4028 if (base[i] != NULL) { |
|
4029 // Is this the block we wanted? |
|
4030 if (base[i] == requested_addr) { |
|
4031 size[i] = bytes; |
|
4032 break; |
|
4033 } |
|
4034 |
|
4035 // Does this overlap the block we wanted? Give back the overlapped |
|
4036 // parts and try again. |
|
4037 |
|
4038 ptrdiff_t top_overlap = requested_addr + (bytes + gap) - base[i]; |
|
4039 if (top_overlap >= 0 && (size_t)top_overlap < bytes) { |
|
4040 unmap_memory(base[i], top_overlap); |
|
4041 base[i] += top_overlap; |
|
4042 size[i] = bytes - top_overlap; |
|
4043 } else { |
|
4044 ptrdiff_t bottom_overlap = base[i] + bytes - requested_addr; |
|
4045 if (bottom_overlap >= 0 && (size_t)bottom_overlap < bytes) { |
|
4046 unmap_memory(requested_addr, bottom_overlap); |
|
4047 size[i] = bytes - bottom_overlap; |
|
4048 } else { |
|
4049 size[i] = bytes; |
|
4050 } |
|
4051 } |
|
4052 } |
|
4053 } |
|
4054 |
|
4055 // Give back the unused reserved pieces. |
|
4056 |
|
4057 for (int j = 0; j < i; ++j) { |
|
4058 if (base[j] != NULL) { |
|
4059 unmap_memory(base[j], size[j]); |
|
4060 } |
|
4061 } |
|
4062 |
|
4063 if (i < max_tries) { |
|
4064 return requested_addr; |
|
4065 } else { |
|
4066 return NULL; |
|
4067 } |
|
4068 } |
|
4069 |
|
4070 size_t os::read(int fd, void *buf, unsigned int nBytes) { |
|
4071 return ::read(fd, buf, nBytes); |
|
4072 } |
|
4073 |
|
4074 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) { |
|
4075 return ::pread(fd, buf, nBytes, offset); |
|
4076 } |
|
4077 |
|
4078 // Short sleep, direct OS call. |
|
4079 // |
|
4080 // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee |
|
4081 // sched_yield(2) will actually give up the CPU: |
|
4082 // |
|
4083 // * Alone on this pariticular CPU, keeps running. |
|
4084 // * Before the introduction of "skip_buddy" with "compat_yield" disabled |
|
4085 // (pre 2.6.39). |
|
4086 // |
|
4087 // So calling this with 0 is an alternative. |
|
4088 // |
|
4089 void os::naked_short_sleep(jlong ms) { |
|
4090 struct timespec req; |
|
4091 |
|
4092 assert(ms < 1000, "Un-interruptable sleep, short time use only"); |
|
4093 req.tv_sec = 0; |
|
4094 if (ms > 0) { |
|
4095 req.tv_nsec = (ms % 1000) * 1000000; |
|
4096 } else { |
|
4097 req.tv_nsec = 1; |
|
4098 } |
|
4099 |
|
4100 nanosleep(&req, NULL); |
|
4101 |
|
4102 return; |
|
4103 } |
4221 } |
4104 |
4222 |
4105 // Sleep forever; naked call to OS-specific sleep; use with CAUTION |
4223 // Sleep forever; naked call to OS-specific sleep; use with CAUTION |
4106 void os::infinite_sleep() { |
4224 void os::infinite_sleep() { |
4107 while (true) { // sleep forever ... |
4225 while (true) { // sleep forever ... |
4131 // The following code actually changes the niceness of kernel-thread/LWP. It |
4259 // The following code actually changes the niceness of kernel-thread/LWP. It |
4132 // has an assumption that setpriority() only modifies one kernel-thread/LWP, |
4260 // has an assumption that setpriority() only modifies one kernel-thread/LWP, |
4133 // not the entire user process, and user level threads are 1:1 mapped to kernel |
4261 // not the entire user process, and user level threads are 1:1 mapped to kernel |
4134 // threads. It has always been the case, but could change in the future. For |
4262 // threads. It has always been the case, but could change in the future. For |
4135 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). |
4263 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). |
4136 // It is only used when ThreadPriorityPolicy=1 and requires root privilege. |
4264 // It is only used when ThreadPriorityPolicy=1 and may require system level permission |
|
4265 // (e.g., root privilege or CAP_SYS_NICE capability). |
4137 |
4266 |
4138 int os::java_to_os_priority[CriticalPriority + 1] = { |
4267 int os::java_to_os_priority[CriticalPriority + 1] = { |
4139 19, // 0 Entry should never be used |
4268 19, // 0 Entry should never be used |
4140 |
4269 |
4141 4, // 1 MinPriority |
4270 4, // 1 MinPriority |
4155 -5 // 11 CriticalPriority |
4284 -5 // 11 CriticalPriority |
4156 }; |
4285 }; |
4157 |
4286 |
4158 static int prio_init() { |
4287 static int prio_init() { |
4159 if (ThreadPriorityPolicy == 1) { |
4288 if (ThreadPriorityPolicy == 1) { |
4160 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 |
|
4161 // if effective uid is not root. Perhaps, a more elegant way of doing |
|
4162 // this is to test CAP_SYS_NICE capability, but that will require libcap.so |
|
4163 if (geteuid() != 0) { |
4289 if (geteuid() != 0) { |
4164 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { |
4290 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { |
4165 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); |
4291 warning("-XX:ThreadPriorityPolicy=1 may require system level permission, " \ |
|
4292 "e.g., being the root user. If the necessary permission is not " \ |
|
4293 "possessed, changes to priority will be silently ignored."); |
4166 } |
4294 } |
4167 ThreadPriorityPolicy = 0; |
|
4168 } |
4295 } |
4169 } |
4296 } |
4170 if (UseCriticalJavaThreadPriority) { |
4297 if (UseCriticalJavaThreadPriority) { |
4171 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority]; |
4298 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority]; |
4172 } |
4299 } |
4702 // For reference, please, see IEEE Std 1003.1-2004: |
4811 // For reference, please, see IEEE Std 1003.1-2004: |
4703 // http://www.unix.org/single_unix_specification |
4812 // http://www.unix.org/single_unix_specification |
4704 |
4813 |
4705 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) { |
4814 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) { |
4706 struct timespec tp; |
4815 struct timespec tp; |
4707 int rc = os::Linux::clock_gettime(clockid, &tp); |
4816 int rc = os::Posix::clock_gettime(clockid, &tp); |
4708 assert(rc == 0, "clock_gettime is expected to return 0 code"); |
4817 assert(rc == 0, "clock_gettime is expected to return 0 code"); |
4709 |
4818 |
4710 return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec; |
4819 return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec; |
4711 } |
|
4712 |
|
4713 void os::Linux::initialize_os_info() { |
|
4714 assert(_os_version == 0, "OS info already initialized"); |
|
4715 |
|
4716 struct utsname _uname; |
|
4717 |
|
4718 uint32_t major; |
|
4719 uint32_t minor; |
|
4720 uint32_t fix; |
|
4721 |
|
4722 int rc; |
|
4723 |
|
4724 // Kernel version is unknown if |
|
4725 // verification below fails. |
|
4726 _os_version = 0x01000000; |
|
4727 |
|
4728 rc = uname(&_uname); |
|
4729 if (rc != -1) { |
|
4730 |
|
4731 rc = sscanf(_uname.release,"%d.%d.%d", &major, &minor, &fix); |
|
4732 if (rc == 3) { |
|
4733 |
|
4734 if (major < 256 && minor < 256 && fix < 256) { |
|
4735 // Kernel version format is as expected, |
|
4736 // set it overriding unknown state. |
|
4737 _os_version = (major << 16) | |
|
4738 (minor << 8 ) | |
|
4739 (fix << 0 ) ; |
|
4740 } |
|
4741 } |
|
4742 } |
|
4743 } |
|
4744 |
|
4745 uint32_t os::Linux::os_version() { |
|
4746 assert(_os_version != 0, "not initialized"); |
|
4747 return _os_version & 0x00FFFFFF; |
|
4748 } |
|
4749 |
|
4750 bool os::Linux::os_version_is_known() { |
|
4751 assert(_os_version != 0, "not initialized"); |
|
4752 return _os_version & 0x01000000 ? false : true; |
|
4753 } |
4820 } |
4754 |
4821 |
4755 ///// |
4822 ///// |
4756 // glibc on Linux platform uses non-documented flag |
4823 // glibc on Linux platform uses non-documented flag |
4757 // to indicate, that some special sort of signal |
4824 // to indicate, that some special sort of signal |
4969 } |
5036 } |
4970 init_page_sizes((size_t) Linux::page_size()); |
5037 init_page_sizes((size_t) Linux::page_size()); |
4971 |
5038 |
4972 Linux::initialize_system_info(); |
5039 Linux::initialize_system_info(); |
4973 |
5040 |
4974 Linux::initialize_os_info(); |
5041 os::Linux::CPUPerfTicks pticks; |
|
5042 bool res = os::Linux::get_tick_information(&pticks, -1); |
|
5043 |
|
5044 if (res && pticks.has_steal_ticks) { |
|
5045 has_initial_tick_info = true; |
|
5046 initial_total_ticks = pticks.total; |
|
5047 initial_steal_ticks = pticks.steal; |
|
5048 } |
4975 |
5049 |
4976 // _main_thread points to the thread that created/loaded the JVM. |
5050 // _main_thread points to the thread that created/loaded the JVM. |
4977 Linux::_main_thread = pthread_self(); |
5051 Linux::_main_thread = pthread_self(); |
4978 |
|
4979 Linux::clock_init(); |
|
4980 initial_time_count = javaTimeNanos(); |
|
4981 |
5052 |
4982 // retrieve entry point for pthread_setname_np |
5053 // retrieve entry point for pthread_setname_np |
4983 Linux::_pthread_setname_np = |
5054 Linux::_pthread_setname_np = |
4984 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
5055 (int(*)(pthread_t, const char*))dlsym(RTLD_DEFAULT, "pthread_setname_np"); |
4985 |
5056 |
4986 os::Posix::init(); |
5057 os::Posix::init(); |
|
5058 |
|
5059 initial_time_count = javaTimeNanos(); |
|
5060 |
|
5061 // Always warn if no monotonic clock available |
|
5062 if (!os::Posix::supports_monotonic_clock()) { |
|
5063 warning("No monotonic clock was available - timed services may " \ |
|
5064 "be adversely affected if the time-of-day clock changes"); |
|
5065 } |
4987 } |
5066 } |
4988 |
5067 |
4989 // To install functions for atexit system call |
5068 // To install functions for atexit system call |
4990 extern "C" { |
5069 extern "C" { |
4991 static void perfMemory_exit_helper() { |
5070 static void perfMemory_exit_helper() { |
4995 |
5074 |
4996 void os::pd_init_container_support() { |
5075 void os::pd_init_container_support() { |
4997 OSContainer::init(); |
5076 OSContainer::init(); |
4998 } |
5077 } |
4999 |
5078 |
|
5079 void os::Linux::numa_init() { |
|
5080 |
|
5081 // Java can be invoked as |
|
5082 // 1. Without numactl and heap will be allocated/configured on all nodes as |
|
5083 // per the system policy. |
|
5084 // 2. With numactl --interleave: |
|
5085 // Use numa_get_interleave_mask(v2) API to get nodes bitmask. The same |
|
5086 // API for membind case bitmask is reset. |
|
5087 // Interleave is only hint and Kernel can fallback to other nodes if |
|
5088 // no memory is available on the target nodes. |
|
5089 // 3. With numactl --membind: |
|
5090 // Use numa_get_membind(v2) API to get nodes bitmask. The same API for |
|
5091 // interleave case returns bitmask of all nodes. |
|
5092 // numa_all_nodes_ptr holds bitmask of all nodes. |
|
5093 // numa_get_interleave_mask(v2) and numa_get_membind(v2) APIs returns correct |
|
5094 // bitmask when externally configured to run on all or fewer nodes. |
|
5095 |
|
5096 if (!Linux::libnuma_init()) { |
|
5097 UseNUMA = false; |
|
5098 } else { |
|
5099 if ((Linux::numa_max_node() < 1) || Linux::is_bound_to_single_node()) { |
|
5100 // If there's only one node (they start from 0) or if the process |
|
5101 // is bound explicitly to a single node using membind, disable NUMA. |
|
5102 UseNUMA = false; |
|
5103 } else { |
|
5104 |
|
5105 LogTarget(Info,os) log; |
|
5106 LogStream ls(log); |
|
5107 |
|
5108 Linux::set_configured_numa_policy(Linux::identify_numa_policy()); |
|
5109 |
|
5110 struct bitmask* bmp = Linux::_numa_membind_bitmask; |
|
5111 const char* numa_mode = "membind"; |
|
5112 |
|
5113 if (Linux::is_running_in_interleave_mode()) { |
|
5114 bmp = Linux::_numa_interleave_bitmask; |
|
5115 numa_mode = "interleave"; |
|
5116 } |
|
5117 |
|
5118 ls.print("UseNUMA is enabled and invoked in '%s' mode." |
|
5119 " Heap will be configured using NUMA memory nodes:", numa_mode); |
|
5120 |
|
5121 for (int node = 0; node <= Linux::numa_max_node(); node++) { |
|
5122 if (Linux::_numa_bitmask_isbitset(bmp, node)) { |
|
5123 ls.print(" %d", node); |
|
5124 } |
|
5125 } |
|
5126 } |
|
5127 } |
|
5128 |
|
5129 if (UseParallelGC && UseNUMA && UseLargePages && !can_commit_large_page_memory()) { |
|
5130 // With SHM and HugeTLBFS large pages we cannot uncommit a page, so there's no way |
|
5131 // we can make the adaptive lgrp chunk resizing work. If the user specified both |
|
5132 // UseNUMA and UseLargePages (or UseSHM/UseHugeTLBFS) on the command line - warn |
|
5133 // and disable adaptive resizing. |
|
5134 if (UseAdaptiveSizePolicy || UseAdaptiveNUMAChunkSizing) { |
|
5135 warning("UseNUMA is not fully compatible with SHM/HugeTLBFS large pages, " |
|
5136 "disabling adaptive resizing (-XX:-UseAdaptiveSizePolicy -XX:-UseAdaptiveNUMAChunkSizing)"); |
|
5137 UseAdaptiveSizePolicy = false; |
|
5138 UseAdaptiveNUMAChunkSizing = false; |
|
5139 } |
|
5140 } |
|
5141 |
|
5142 if (!UseNUMA && ForceNUMA) { |
|
5143 UseNUMA = true; |
|
5144 } |
|
5145 } |
|
5146 |
5000 // this is called _after_ the global arguments have been parsed |
5147 // this is called _after_ the global arguments have been parsed |
5001 jint os::init_2(void) { |
5148 jint os::init_2(void) { |
|
5149 |
|
5150 // This could be set after os::Posix::init() but all platforms |
|
5151 // have to set it the same so we have to mirror Solaris. |
|
5152 DEBUG_ONLY(os::set_mutex_init_done();) |
5002 |
5153 |
5003 os::Posix::init_2(); |
5154 os::Posix::init_2(); |
5004 |
5155 |
5005 Linux::fast_thread_clock_init(); |
5156 Linux::fast_thread_clock_init(); |
5006 |
5157 |
5015 // Initialize data for jdk.internal.misc.Signal |
5166 // Initialize data for jdk.internal.misc.Signal |
5016 if (!ReduceSignalUsage) { |
5167 if (!ReduceSignalUsage) { |
5017 jdk_misc_signal_init(); |
5168 jdk_misc_signal_init(); |
5018 } |
5169 } |
5019 |
5170 |
|
5171 if (AdjustStackSizeForTLS) { |
|
5172 get_minstack_init(); |
|
5173 } |
|
5174 |
5020 // Check and sets minimum stack sizes against command line options |
5175 // Check and sets minimum stack sizes against command line options |
5021 if (Posix::set_minimum_stack_sizes() == JNI_ERR) { |
5176 if (Posix::set_minimum_stack_sizes() == JNI_ERR) { |
5022 return JNI_ERR; |
5177 return JNI_ERR; |
5023 } |
5178 } |
5024 |
5179 |
|
5180 #if defined(IA32) |
|
5181 // Need to ensure we've determined the process's initial stack to |
|
5182 // perform the workaround |
|
5183 Linux::capture_initial_stack(JavaThread::stack_size_at_create()); |
|
5184 workaround_expand_exec_shield_cs_limit(); |
|
5185 #else |
5025 suppress_primordial_thread_resolution = Arguments::created_by_java_launcher(); |
5186 suppress_primordial_thread_resolution = Arguments::created_by_java_launcher(); |
5026 if (!suppress_primordial_thread_resolution) { |
5187 if (!suppress_primordial_thread_resolution) { |
5027 Linux::capture_initial_stack(JavaThread::stack_size_at_create()); |
5188 Linux::capture_initial_stack(JavaThread::stack_size_at_create()); |
5028 } |
5189 } |
5029 |
|
5030 #if defined(IA32) |
|
5031 workaround_expand_exec_shield_cs_limit(); |
|
5032 #endif |
5190 #endif |
5033 |
5191 |
5034 Linux::libpthread_init(); |
5192 Linux::libpthread_init(); |
5035 Linux::sched_getcpu_init(); |
5193 Linux::sched_getcpu_init(); |
5036 log_info(os)("HotSpot is running with %s, %s", |
5194 log_info(os)("HotSpot is running with %s, %s", |
5037 Linux::glibc_version(), Linux::libpthread_version()); |
5195 Linux::glibc_version(), Linux::libpthread_version()); |
5038 |
5196 |
5039 if (UseNUMA) { |
5197 if (UseNUMA) { |
5040 if (!Linux::libnuma_init()) { |
5198 Linux::numa_init(); |
5041 UseNUMA = false; |
|
5042 } else { |
|
5043 if ((Linux::numa_max_node() < 1) || Linux::isbound_to_single_node()) { |
|
5044 // If there's only one node (they start from 0) or if the process |
|
5045 // is bound explicitly to a single node using membind, disable NUMA. |
|
5046 UseNUMA = false; |
|
5047 } |
|
5048 } |
|
5049 |
|
5050 if (UseParallelGC && UseNUMA && UseLargePages && !can_commit_large_page_memory()) { |
|
5051 // With SHM and HugeTLBFS large pages we cannot uncommit a page, so there's no way |
|
5052 // we can make the adaptive lgrp chunk resizing work. If the user specified both |
|
5053 // UseNUMA and UseLargePages (or UseSHM/UseHugeTLBFS) on the command line - warn |
|
5054 // and disable adaptive resizing. |
|
5055 if (UseAdaptiveSizePolicy || UseAdaptiveNUMAChunkSizing) { |
|
5056 warning("UseNUMA is not fully compatible with SHM/HugeTLBFS large pages, " |
|
5057 "disabling adaptive resizing (-XX:-UseAdaptiveSizePolicy -XX:-UseAdaptiveNUMAChunkSizing)"); |
|
5058 UseAdaptiveSizePolicy = false; |
|
5059 UseAdaptiveNUMAChunkSizing = false; |
|
5060 } |
|
5061 } |
|
5062 |
|
5063 if (!UseNUMA && ForceNUMA) { |
|
5064 UseNUMA = true; |
|
5065 } |
|
5066 } |
5199 } |
5067 |
5200 |
5068 if (MaxFDLimit) { |
5201 if (MaxFDLimit) { |
5069 // set the number of file descriptors to max. print out error |
5202 // set the number of file descriptors to max. print out error |
5070 // if getrlimit/setrlimit fails but continue regardless. |
5203 // if getrlimit/setrlimit fails but continue regardless. |
6075 // mapping will serve as a value for a "good" req_addr (case 2). The second |
6209 // mapping will serve as a value for a "good" req_addr (case 2). The second |
6076 // mapping, still intact, as "bad" req_addr (case 3). |
6210 // mapping, still intact, as "bad" req_addr (case 3). |
6077 ::munmap(mapping1, mapping_size); |
6211 ::munmap(mapping1, mapping_size); |
6078 |
6212 |
6079 // Case 1 |
6213 // Case 1 |
6080 test_log("%s, req_addr NULL:", __FUNCTION__); |
|
6081 test_log("size align result"); |
|
6082 |
|
6083 for (int i = 0; i < num_sizes; i++) { |
6214 for (int i = 0; i < num_sizes; i++) { |
6084 const size_t size = sizes[i]; |
6215 const size_t size = sizes[i]; |
6085 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6216 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6086 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, NULL, false); |
6217 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, NULL, false); |
6087 test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " -> " PTR_FORMAT " %s", |
|
6088 size, alignment, p2i(p), (p != NULL ? "" : "(failed)")); |
|
6089 if (p != NULL) { |
6218 if (p != NULL) { |
6090 assert(is_aligned(p, alignment), "must be"); |
6219 assert(is_aligned(p, alignment), "must be"); |
6091 small_page_write(p, size); |
6220 small_page_write(p, size); |
6092 os::Linux::release_memory_special_huge_tlbfs(p, size); |
6221 os::Linux::release_memory_special_huge_tlbfs(p, size); |
6093 } |
6222 } |
6094 } |
6223 } |
6095 } |
6224 } |
6096 |
6225 |
6097 // Case 2 |
6226 // Case 2 |
6098 test_log("%s, req_addr non-NULL:", __FUNCTION__); |
|
6099 test_log("size align req_addr result"); |
|
6100 |
|
6101 for (int i = 0; i < num_sizes; i++) { |
6227 for (int i = 0; i < num_sizes; i++) { |
6102 const size_t size = sizes[i]; |
6228 const size_t size = sizes[i]; |
6103 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6229 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6104 char* const req_addr = align_up(mapping1, alignment); |
6230 char* const req_addr = align_up(mapping1, alignment); |
6105 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false); |
6231 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false); |
6106 test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " -> " PTR_FORMAT " %s", |
|
6107 size, alignment, p2i(req_addr), p2i(p), |
|
6108 ((p != NULL ? (p == req_addr ? "(exact match)" : "") : "(failed)"))); |
|
6109 if (p != NULL) { |
6232 if (p != NULL) { |
6110 assert(p == req_addr, "must be"); |
6233 assert(p == req_addr, "must be"); |
6111 small_page_write(p, size); |
6234 small_page_write(p, size); |
6112 os::Linux::release_memory_special_huge_tlbfs(p, size); |
6235 os::Linux::release_memory_special_huge_tlbfs(p, size); |
6113 } |
6236 } |
6114 } |
6237 } |
6115 } |
6238 } |
6116 |
6239 |
6117 // Case 3 |
6240 // Case 3 |
6118 test_log("%s, req_addr non-NULL with preexisting mapping:", __FUNCTION__); |
|
6119 test_log("size align req_addr result"); |
|
6120 |
|
6121 for (int i = 0; i < num_sizes; i++) { |
6241 for (int i = 0; i < num_sizes; i++) { |
6122 const size_t size = sizes[i]; |
6242 const size_t size = sizes[i]; |
6123 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6243 for (size_t alignment = ag; is_aligned(size, alignment); alignment *= 2) { |
6124 char* const req_addr = align_up(mapping2, alignment); |
6244 char* const req_addr = align_up(mapping2, alignment); |
6125 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false); |
6245 char* p = os::Linux::reserve_memory_special_huge_tlbfs_mixed(size, alignment, req_addr, false); |
6126 test_log(SIZE_FORMAT_HEX " " SIZE_FORMAT_HEX " " PTR_FORMAT " -> " PTR_FORMAT " %s", |
|
6127 size, alignment, p2i(req_addr), p2i(p), ((p != NULL ? "" : "(failed)"))); |
|
6128 // as the area around req_addr contains already existing mappings, the API should always |
6246 // as the area around req_addr contains already existing mappings, the API should always |
6129 // return NULL (as per contract, it cannot return another address) |
6247 // return NULL (as per contract, it cannot return another address) |
6130 assert(p == NULL, "must be"); |
6248 assert(p == NULL, "must be"); |
6131 } |
6249 } |
6132 } |
6250 } |