src/hotspot/os/linux/os_linux.hpp
author naoto
Tue, 09 Jul 2019 08:05:38 -0700
changeset 55627 9c1885fb2a42
parent 54485 ddc19ea5059c
child 58654 562bf1878089
permissions -rw-r--r--
8227127: Era designator not displayed correctly using the COMPAT provider Reviewed-by: rriggs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51989
diff changeset
     2
 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
5547
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f4b087cbb361 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 3261
diff changeset
    21
 * questions.
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51989
diff changeset
    25
#ifndef OS_LINUX_OS_LINUX_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51989
diff changeset
    26
#define OS_LINUX_OS_LINUX_HPP
7397
5b173b4ca846 6989984: Use standard include model for Hospot
stefank
parents: 5547
diff changeset
    27
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
// Linux_OS defines the interface to Linux operating systems
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
22852
1063026e8cee 8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
goetz
parents: 19964
diff changeset
    30
// Information about the protection of the page at address '0' on this os.
1063026e8cee 8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
goetz
parents: 19964
diff changeset
    31
static bool zero_page_read_protected() { return true; }
1063026e8cee 8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
goetz
parents: 19964
diff changeset
    32
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
class Linux {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
  friend class os;
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents: 47216
diff changeset
    35
  friend class OSContainer;
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    36
  friend class TestReserveMemorySpecial;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
  static bool libjsig_is_loaded;        // libjsig that interposes sigaction(),
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
                                        // __sigaction(), signal() is loaded
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
  static struct sigaction *(*get_signal_action)(int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
  static void check_signal_handler(int sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
  static int (*_pthread_getcpuclockid)(pthread_t, clockid_t *);
27164
6523fa019ffa 7102541: RFE: os::set_native_thread_name() cleanups
sla
parents: 26684
diff changeset
    45
  static int (*_pthread_setname_np)(pthread_t, const char*);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
  static address   _initial_thread_stack_bottom;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
  static uintptr_t _initial_thread_stack_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
745
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
    50
  static const char *_glibc_version;
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
    51
  static const char *_libpthread_version;
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
  static bool _supports_fast_thread_cpu_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    55
  static GrowableArray<int>* _cpu_to_node;
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
    56
  static GrowableArray<int>* _nindex_to_node;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    57
36560
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    58
  // 0x00000000 = uninitialized,
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    59
  // 0x01000000 = kernel version unknown,
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    60
  // otherwise a 32-bit number:
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    61
  // Ox00AABBCC
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    62
  // AA, Major Version
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    63
  // BB, Minor Version
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    64
  // CC, Fix   Version
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    65
  static uint32_t _os_version;
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
    66
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
 protected:
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
  static julong _physical_memory;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    70
  static pthread_t _main_thread;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    71
  static Mutex* _createThread_lock;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    72
  static int _page_size;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    73
489c9b5090e2 Initial load
duke
parents:
diff changeset
    74
  static julong available_memory();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    75
  static julong physical_memory() { return _physical_memory; }
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents: 47216
diff changeset
    76
  static void set_physical_memory(julong phys_mem) { _physical_memory = phys_mem; }
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents: 47216
diff changeset
    77
  static int active_processor_count();
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents: 47216
diff changeset
    78
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  static void initialize_system_info();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
18069
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 18025
diff changeset
    81
  static int commit_memory_impl(char* addr, size_t bytes, bool exec);
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 18025
diff changeset
    82
  static int commit_memory_impl(char* addr, size_t bytes,
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 18025
diff changeset
    83
                                size_t alignment_hint, bool exec);
e6d4971c8650 8013057: assert(_needs_gc || SafepointSynchronize::is_at_safepoint()) failed: only read at safepoint
dcubed
parents: 18025
diff changeset
    84
745
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
    85
  static void set_glibc_version(const char *s)      { _glibc_version = s; }
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
    86
  static void set_libpthread_version(const char *s) { _libpthread_version = s; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    88
  static void rebuild_cpu_to_node_map();
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
    89
  static void rebuild_nindex_to_node_map();
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
    90
  static GrowableArray<int>* cpu_to_node()    { return _cpu_to_node; }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
    91
  static GrowableArray<int>* nindex_to_node()  { return _nindex_to_node; }
9335
7bdd2a3ab3d8 7034464: Support transparent large pages on Linux
iveresov
parents: 7397
diff changeset
    92
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    93
  static size_t find_large_page_size();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    94
  static size_t setup_large_page_size();
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    95
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    96
  static bool setup_large_page_type(size_t page_size);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
    97
  static bool transparent_huge_pages_sanity_check(bool warn, size_t pages_size);
9335
7bdd2a3ab3d8 7034464: Support transparent large pages on Linux
iveresov
parents: 7397
diff changeset
    98
  static bool hugetlbfs_sanity_check(bool warn, size_t page_size);
7bdd2a3ab3d8 7034464: Support transparent large pages on Linux
iveresov
parents: 7397
diff changeset
    99
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   100
  static char* reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   101
  static char* reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   102
  static char* reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   103
  static char* reserve_memory_special_huge_tlbfs_mixed(size_t bytes, size_t alignment, char* req_addr, bool exec);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   104
25946
1572c9f03fb9 8046598: Scalable Native memory tracking development
zgu
parents: 25472
diff changeset
   105
  static bool release_memory_special_impl(char* base, size_t bytes);
19546
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   106
  static bool release_memory_special_shm(char* base, size_t bytes);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   107
  static bool release_memory_special_huge_tlbfs(char* base, size_t bytes);
f6b7c9e96ea3 8007074: SIGSEGV at ParMarkBitMap::verify_clear()
stefank
parents: 18069
diff changeset
   108
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 10239
diff changeset
   109
  static void print_full_memory_info(outputStream* st);
47903
7f22774a5f42 8146115: Improve docker container detection and resource configuration usage
bobv
parents: 47216
diff changeset
   110
  static void print_container_info(outputStream* st);
54470
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   111
  static void print_steal_info(outputStream* st);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 10239
diff changeset
   112
  static void print_distro_info(outputStream* st);
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 10239
diff changeset
   113
  static void print_libversion_info(outputStream* st);
50504
6dfe5ae92fa8 8204598: add more thread-related system settings info to hs_error file on Linux
mbaesken
parents: 50177
diff changeset
   114
  static void print_proc_sys_info(outputStream* st);
51942
1d12935177ed 8210964: add more ld preloading related info to hs_error file on Linux
mbaesken
parents: 51225
diff changeset
   115
  static void print_ld_preload_file(outputStream* st);
12735
3e2e491f4f69 7165755: OS Information much longer on linux than other platforms
nloodin
parents: 10239
diff changeset
   116
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
 public:
54470
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   118
  struct CPUPerfTicks {
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   119
    uint64_t used;
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   120
    uint64_t usedKernel;
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   121
    uint64_t total;
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   122
    uint64_t steal;
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   123
    bool     has_steal_ticks;
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   124
  };
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   125
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   126
  // which_logical_cpu=-1 returns accumulated ticks for all cpus.
14986fb09d9a 8221535: add steal tick related information to hs_error file [linux]
mbaesken
parents: 54090
diff changeset
   127
  static bool get_tick_information(CPUPerfTicks* pticks, int which_logical_cpu);
15926
8e87d545195f 7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents: 15855
diff changeset
   128
  static bool _stack_is_executable;
16438
245d5c0a8dd8 8010389: After fix for 7107135 a failed dlopen() call results in a VM crash
iklam
parents: 15926
diff changeset
   129
  static void *dlopen_helper(const char *name, char *ebuf, int ebuflen);
245d5c0a8dd8 8010389: After fix for 7107135 a failed dlopen() call results in a VM crash
iklam
parents: 15926
diff changeset
   130
  static void *dll_load_in_vmthread(const char *name, char *ebuf, int ebuflen);
15926
8e87d545195f 7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents: 15855
diff changeset
   131
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   132
  static void init_thread_fpu_state();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   133
  static int  get_fpu_control_word();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   134
  static void set_fpu_control_word(int fpu_control);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   135
  static pthread_t main_thread(void)                                { return _main_thread; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   136
  // returns kernel thread id (similar to LWP id on Solaris), which can be
489c9b5090e2 Initial load
duke
parents:
diff changeset
   137
  // used to access /proc
489c9b5090e2 Initial load
duke
parents:
diff changeset
   138
  static pid_t gettid();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   139
  static void set_createThread_lock(Mutex* lk)                      { _createThread_lock = lk; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   140
  static Mutex* createThread_lock(void)                             { return _createThread_lock; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   141
  static void hotspot_sigmask(Thread* thread);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   142
489c9b5090e2 Initial load
duke
parents:
diff changeset
   143
  static address   initial_thread_stack_bottom(void)                { return _initial_thread_stack_bottom; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   144
  static uintptr_t initial_thread_stack_size(void)                  { return _initial_thread_stack_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   145
489c9b5090e2 Initial load
duke
parents:
diff changeset
   146
  static int page_size(void)                                        { return _page_size; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   147
  static void set_page_size(int val)                                { _page_size = val; }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   148
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   149
  static address   ucontext_get_pc(const ucontext_t* uc);
29573
2d800e5d575f 8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents: 27164
diff changeset
   150
  static void ucontext_set_pc(ucontext_t* uc, address pc);
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   151
  static intptr_t* ucontext_get_sp(const ucontext_t* uc);
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   152
  static intptr_t* ucontext_get_fp(const ucontext_t* uc);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   153
489c9b5090e2 Initial load
duke
parents:
diff changeset
   154
  // For Analyzer Forte AsyncGetCallTrace profiling support:
489c9b5090e2 Initial load
duke
parents:
diff changeset
   155
  //
489c9b5090e2 Initial load
duke
parents:
diff changeset
   156
  // This interface should be declared in os_linux_i486.hpp, but
489c9b5090e2 Initial load
duke
parents:
diff changeset
   157
  // that file provides extensions to the os class and not the
489c9b5090e2 Initial load
duke
parents:
diff changeset
   158
  // Linux class.
35077
8b86440d3bf1 8145114: const-correctness for ucontext_t* reading functions
stuefe
parents: 35071
diff changeset
   159
  static ExtendedPC fetch_frame_from_ucontext(Thread* thread, const ucontext_t* uc,
26683
a02753d5a0b2 8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents: 25946
diff changeset
   160
                                              intptr_t** ret_sp, intptr_t** ret_fp);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   161
35071
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34145
diff changeset
   162
  static bool get_frame_at_stack_banging_point(JavaThread* thread, ucontext_t* uc, frame* fr);
a0910b1d3e0d 8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents: 34145
diff changeset
   163
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   164
  // This boolean allows users to forward their own non-matching signals
489c9b5090e2 Initial load
duke
parents:
diff changeset
   165
  // to JVM_handle_linux_signal, harmlessly.
489c9b5090e2 Initial load
duke
parents:
diff changeset
   166
  static bool signal_handlers_are_installed;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   167
489c9b5090e2 Initial load
duke
parents:
diff changeset
   168
  static int get_our_sigflags(int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   169
  static void set_our_sigflags(int, int);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   170
  static void signal_sets_init();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   171
  static void install_signal_handlers();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   172
  static void set_signal_handler(int, bool);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   173
489c9b5090e2 Initial load
duke
parents:
diff changeset
   174
  static sigset_t* unblocked_signals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   175
  static sigset_t* vm_signals();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   176
489c9b5090e2 Initial load
duke
parents:
diff changeset
   177
  // For signal-chaining
489c9b5090e2 Initial load
duke
parents:
diff changeset
   178
  static struct sigaction *get_chained_signal_action(int sig);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   179
  static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   180
489c9b5090e2 Initial load
duke
parents:
diff changeset
   181
  // GNU libc and libpthread version strings
745
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
   182
  static const char *glibc_version()          { return _glibc_version; }
47129a5cacd3 6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents: 388
diff changeset
   183
  static const char *libpthread_version()     { return _libpthread_version; }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   184
489c9b5090e2 Initial load
duke
parents:
diff changeset
   185
  static void libpthread_init();
46512
1ba5728eda0d 8181319: Make os::Linux::sched_getcpu() available even when UseNUMA is false
pliden
parents: 46510
diff changeset
   186
  static void sched_getcpu_init();
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   187
  static bool libnuma_init();
2753
1e9bbaae891b 6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents: 1615
diff changeset
   188
  static void* libnuma_dlsym(void* handle, const char* name);
46510
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   189
  // libnuma v2 (libnuma_1.2) symbols
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   190
  static void* libnuma_v2_dlsym(void* handle, const char* name);
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   191
41070
496463b4e206 8140520: segfault on solaris-amd64 with "-XX:VMThreadStackSize=1" option
rdurbin
parents: 39390
diff changeset
   192
  // Return default guard size for the specified thread type
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   193
  static size_t default_guard_size(os::ThreadType thr_type);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   194
489c9b5090e2 Initial load
duke
parents:
diff changeset
   195
  static void capture_initial_stack(size_t max_size);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   196
489c9b5090e2 Initial load
duke
parents:
diff changeset
   197
  // Stack overflow handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   198
  static bool manually_expand_stack(JavaThread * t, address addr);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   199
  static int max_register_window_saves_before_flushing();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   200
489c9b5090e2 Initial load
duke
parents:
diff changeset
   201
  // fast POSIX clocks support
489c9b5090e2 Initial load
duke
parents:
diff changeset
   202
  static void fast_thread_clock_init(void);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   203
489c9b5090e2 Initial load
duke
parents:
diff changeset
   204
  static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   205
    return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   206
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   207
489c9b5090e2 Initial load
duke
parents:
diff changeset
   208
  static bool supports_fast_thread_cpu_time() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   209
    return _supports_fast_thread_cpu_time;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   210
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   211
489c9b5090e2 Initial load
duke
parents:
diff changeset
   212
  static jlong fast_thread_cpu_time(clockid_t clockid);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   213
36560
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
   214
  static void initialize_os_info();
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
   215
  static bool os_version_is_known();
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
   216
  static uint32_t os_version();
59ca2b7f6162 8150353: PPC64LE: Support RTM on linux
kvn
parents: 35077
diff changeset
   217
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   218
  // Stack repair handling
489c9b5090e2 Initial load
duke
parents:
diff changeset
   219
489c9b5090e2 Initial load
duke
parents:
diff changeset
   220
  // none present
489c9b5090e2 Initial load
duke
parents:
diff changeset
   221
26683
a02753d5a0b2 8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents: 25946
diff changeset
   222
 private:
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   223
  static void numa_init();
49407
7fa5375fa6fd 8197429: Increased stack guard causes segfaults on x86-32
aph
parents: 48005
diff changeset
   224
  static void expand_stack_to(address bottom);
7fa5375fa6fd 8197429: Increased stack guard causes segfaults on x86-32
aph
parents: 48005
diff changeset
   225
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   226
  typedef int (*sched_getcpu_func_t)(void);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   227
  typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   228
  typedef int (*numa_max_node_func_t)(void);
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   229
  typedef int (*numa_num_configured_nodes_func_t)(void);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   230
  typedef int (*numa_available_func_t)(void);
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   231
  typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   232
  typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
46510
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   233
  typedef void (*numa_interleave_memory_v2_func_t)(void *start, size_t size, struct bitmask* mask);
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   234
  typedef struct bitmask* (*numa_get_membind_func_t)(void);
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   235
  typedef struct bitmask* (*numa_get_interleave_mask_func_t)(void);
46510
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   236
19726
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   237
  typedef void (*numa_set_bind_policy_func_t)(int policy);
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   238
  typedef int (*numa_bitmask_isbitset_func_t)(struct bitmask *bmp, unsigned int n);
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   239
  typedef int (*numa_distance_func_t)(int node1, int node2);
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   240
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   241
  static sched_getcpu_func_t _sched_getcpu;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   242
  static numa_node_to_cpus_func_t _numa_node_to_cpus;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   243
  static numa_max_node_func_t _numa_max_node;
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   244
  static numa_num_configured_nodes_func_t _numa_num_configured_nodes;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   245
  static numa_available_func_t _numa_available;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   246
  static numa_tonode_memory_func_t _numa_tonode_memory;
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   247
  static numa_interleave_memory_func_t _numa_interleave_memory;
46510
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   248
  static numa_interleave_memory_v2_func_t _numa_interleave_memory_v2;
19726
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   249
  static numa_set_bind_policy_func_t _numa_set_bind_policy;
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   250
  static numa_bitmask_isbitset_func_t _numa_bitmask_isbitset;
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   251
  static numa_distance_func_t _numa_distance;
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   252
  static numa_get_membind_func_t _numa_get_membind;
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   253
  static numa_get_interleave_mask_func_t _numa_get_interleave_mask;
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   254
  static unsigned long* _numa_all_nodes;
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   255
  static struct bitmask* _numa_all_nodes_ptr;
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   256
  static struct bitmask* _numa_nodes_ptr;
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   257
  static struct bitmask* _numa_interleave_bitmask;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   258
  static struct bitmask* _numa_membind_bitmask;
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   259
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   260
  static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   261
  static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   262
  static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   263
  static void set_numa_num_configured_nodes(numa_num_configured_nodes_func_t func) { _numa_num_configured_nodes = func; }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   264
  static void set_numa_available(numa_available_func_t func) { _numa_available = func; }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   265
  static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   266
  static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
46510
8cc204b35e39 8181055: PPC64: "mbind: Invalid argument" still seen after 8175813
zgu
parents: 46507
diff changeset
   267
  static void set_numa_interleave_memory_v2(numa_interleave_memory_v2_func_t func) { _numa_interleave_memory_v2 = func; }
19726
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   268
  static void set_numa_set_bind_policy(numa_set_bind_policy_func_t func) { _numa_set_bind_policy = func; }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   269
  static void set_numa_bitmask_isbitset(numa_bitmask_isbitset_func_t func) { _numa_bitmask_isbitset = func; }
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   270
  static void set_numa_distance(numa_distance_func_t func) { _numa_distance = func; }
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   271
  static void set_numa_get_membind(numa_get_membind_func_t func) { _numa_get_membind = func; }
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   272
  static void set_numa_get_interleave_mask(numa_get_interleave_mask_func_t func) { _numa_get_interleave_mask = func; }
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   273
  static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
49410
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   274
  static void set_numa_all_nodes_ptr(struct bitmask **ptr) { _numa_all_nodes_ptr = (ptr == NULL ? NULL : *ptr); }
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   275
  static void set_numa_nodes_ptr(struct bitmask **ptr) { _numa_nodes_ptr = (ptr == NULL ? NULL : *ptr); }
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   276
  static void set_numa_interleave_bitmask(struct bitmask* ptr)     { _numa_interleave_bitmask = ptr ;   }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   277
  static void set_numa_membind_bitmask(struct bitmask* ptr)        { _numa_membind_bitmask = ptr ;      }
10239
c7af330d33d9 7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents: 9335
diff changeset
   278
  static int sched_getcpu_syscall(void);
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   279
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   280
  enum NumaAllocationPolicy{
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   281
    NotInitialized,
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   282
    Membind,
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   283
    Interleave
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   284
  };
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   285
  static NumaAllocationPolicy _current_numa_policy;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   286
26683
a02753d5a0b2 8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents: 25946
diff changeset
   287
 public:
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   288
  static int sched_getcpu()  { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   289
  static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   290
    return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   291
  }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   292
  static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   293
  static int numa_num_configured_nodes() {
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   294
    return _numa_num_configured_nodes != NULL ? _numa_num_configured_nodes() : -1;
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   295
  }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   296
  static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   297
  static int numa_tonode_memory(void *start, size_t size, int node) {
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   298
    return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   299
  }
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   300
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   301
  static bool is_running_in_interleave_mode() {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   302
    return _current_numa_policy == Interleave;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   303
  }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   304
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   305
  static void set_configured_numa_policy(NumaAllocationPolicy numa_policy) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   306
    _current_numa_policy = numa_policy;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   307
  }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   308
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   309
  static NumaAllocationPolicy identify_numa_policy() {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   310
    for (int node = 0; node <= Linux::numa_max_node(); node++) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   311
      if (Linux::_numa_bitmask_isbitset(Linux::_numa_interleave_bitmask, node)) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   312
        return Interleave;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   313
      }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   314
    }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   315
    return Membind;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   316
  }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   317
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   318
  static void numa_interleave_memory(void *start, size_t size) {
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   319
    // Prefer v2 API
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   320
    if (_numa_interleave_memory_v2 != NULL) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   321
      if (is_running_in_interleave_mode()) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   322
        _numa_interleave_memory_v2(start, size, _numa_interleave_bitmask);
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   323
      } else if (_numa_membind_bitmask != NULL) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   324
        _numa_interleave_memory_v2(start, size, _numa_membind_bitmask);
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   325
      }
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   326
    } else if (_numa_interleave_memory != NULL) {
1615
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   327
      _numa_interleave_memory(start, size, _numa_all_nodes);
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   328
    }
b46d9f19bde2 6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents: 781
diff changeset
   329
  }
19726
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   330
  static void numa_set_bind_policy(int policy) {
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   331
    if (_numa_set_bind_policy != NULL) {
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   332
      _numa_set_bind_policy(policy);
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   333
    }
c086d352d3f7 8016155: SIGBUS when running Kitchensink with ParallelScavenge and ParallelOld
mgerdin
parents: 18069
diff changeset
   334
  }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   335
  static int numa_distance(int node1, int node2) {
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   336
    return _numa_distance != NULL ? _numa_distance(node1, node2) : -1;
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   337
  }
388
bcc631c5bbec 6684395: Port NUMA-aware allocator to linux
iveresov
parents: 1
diff changeset
   338
  static int get_node_by_cpu(int cpu_id);
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   339
  static int get_existing_num_nodes();
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   340
  // Check if numa node is configured (non-zero memory node).
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   341
  static bool is_node_in_configured_nodes(unsigned int n) {
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   342
    if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) {
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   343
      return _numa_bitmask_isbitset(_numa_all_nodes_ptr, n);
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   344
    } else
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   345
      return false;
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   346
  }
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   347
  // Check if numa node exists in the system (including zero memory nodes).
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   348
  static bool is_node_in_existing_nodes(unsigned int n) {
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   349
    if (_numa_bitmask_isbitset != NULL && _numa_nodes_ptr != NULL) {
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   350
      return _numa_bitmask_isbitset(_numa_nodes_ptr, n);
49410
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   351
    } else if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) {
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   352
      // Not all libnuma API v2 implement numa_nodes_ptr, so it's not possible
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   353
      // to trust the API version for checking its absence. On the other hand,
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   354
      // numa_nodes_ptr found in libnuma 2.0.9 and above is the only way to get
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   355
      // a complete view of all numa nodes in the system, hence numa_nodes_ptr
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   356
      // is used to handle CPU and nodes on architectures (like PowerPC) where
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   357
      // there can exist nodes with CPUs but no memory or vice-versa and the
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   358
      // nodes may be non-contiguous. For most of the architectures, like
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   359
      // x86_64, numa_node_ptr presents the same node set as found in
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   360
      // numa_all_nodes_ptr so it's possible to use numa_all_nodes_ptr as a
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   361
      // substitute.
7fb0ad2d8749 8198794: Hotspot crash on Cassandra 3.11.1 startup with libnuma 2.0.3
gromero
parents: 49407
diff changeset
   362
      return _numa_bitmask_isbitset(_numa_all_nodes_ptr, n);
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   363
    } else
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   364
      return false;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   365
  }
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   366
  // Check if node is in bound node set.
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   367
  static bool is_node_in_bound_nodes(int node) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   368
    if (_numa_bitmask_isbitset != NULL) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   369
      if (is_running_in_interleave_mode()) {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   370
        return _numa_bitmask_isbitset(_numa_interleave_bitmask, node);
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   371
      } else {
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   372
        return _numa_membind_bitmask != NULL ? _numa_bitmask_isbitset(_numa_membind_bitmask, node) : false;
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   373
      }
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   374
    }
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   375
    return false;
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   376
  }
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   377
  // Check if bound to only one numa node.
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   378
  // Returns true if bound to a single numa node, otherwise returns false.
53362
ef09fd205ef0 8213827: NUMA heap allocation does not respect process membind/interleave settings
tschatzl
parents: 53244
diff changeset
   379
  static bool is_bound_to_single_node() {
51225
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   380
    int nodes = 0;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   381
    struct bitmask* bmp = NULL;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   382
    unsigned int node = 0;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   383
    unsigned int highest_node_number = 0;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   384
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   385
    if (_numa_get_membind != NULL && _numa_max_node != NULL && _numa_bitmask_isbitset != NULL) {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   386
      bmp = _numa_get_membind();
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   387
      highest_node_number = _numa_max_node();
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   388
    } else {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   389
      return false;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   390
    }
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   391
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   392
    for (node = 0; node <= highest_node_number; node++) {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   393
      if (_numa_bitmask_isbitset(bmp, node)) {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   394
        nodes++;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   395
      }
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   396
    }
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   397
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   398
    if (nodes == 1) {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   399
      return true;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   400
    } else {
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   401
      return false;
50eb2c0f252b 8189922: UseNUMA memory interleaving vs membind
gromero
parents: 50504
diff changeset
   402
    }
46442
b833f0dbbb5b 8175813: PPC64: "mbind: Invalid argument" when -XX:+UseNUMA is used
gromero
parents: 41070
diff changeset
   403
  }
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
   404
};
489c9b5090e2 Initial load
duke
parents:
diff changeset
   405
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 51989
diff changeset
   406
#endif // OS_LINUX_OS_LINUX_HPP