author | fparain |
Fri, 11 Dec 2015 09:07:07 -0800 | |
changeset 35071 | a0910b1d3e0d |
parent 34145 | f8097485b483 |
child 35077 | 8b86440d3bf1 |
permissions | -rw-r--r-- |
10565 | 1 |
/* |
32080
9d2ace436482
8080298: Clean up os::...::supports_variable_stack_size()
dholmes
parents:
31377
diff
changeset
|
2 |
* Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved. |
10565 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#ifndef OS_BSD_VM_OS_BSD_HPP |
|
26 |
#define OS_BSD_VM_OS_BSD_HPP |
|
27 |
||
28 |
// Bsd_OS defines the interface to Bsd operating systems |
|
29 |
||
22852
1063026e8cee
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
goetz
parents:
20377
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:
20377
diff
changeset
|
31 |
static bool zero_page_read_protected() { return true; } |
1063026e8cee
8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
goetz
parents:
20377
diff
changeset
|
32 |
|
10565 | 33 |
#ifdef __APPLE__ |
34 |
// Mac OS X doesn't support clock_gettime. Stub out the type, it is |
|
35 |
// unused |
|
36 |
typedef int clockid_t; |
|
37 |
#endif |
|
38 |
||
39 |
class Bsd { |
|
40 |
friend class os; |
|
41 |
||
42 |
// For signal-chaining |
|
43 |
static bool libjsig_is_loaded; // libjsig that interposes sigaction(), |
|
44 |
// __sigaction(), signal() is loaded |
|
45 |
static struct sigaction *(*get_signal_action)(int); |
|
46 |
static struct sigaction *get_preinstalled_handler(int); |
|
47 |
static void save_preinstalled_handler(int, struct sigaction&); |
|
48 |
||
49 |
static void check_signal_handler(int sig); |
|
50 |
||
24239
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
51 |
#ifdef __APPLE__ |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
52 |
// mach_absolute_time |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
53 |
static mach_timebase_info_data_t _timebase_info; |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
54 |
static volatile uint64_t _max_abstime; |
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
55 |
#else |
10565 | 56 |
static int (*_clock_gettime)(clockid_t, struct timespec *); |
24239
db81abb281bc
8040140: System.nanoTime() is slow and non-monotonic on OS X
sla
parents:
22894
diff
changeset
|
57 |
#endif |
10565 | 58 |
|
59 |
static GrowableArray<int>* _cpu_to_node; |
|
60 |
||
61 |
protected: |
|
62 |
||
63 |
static julong _physical_memory; |
|
64 |
static pthread_t _main_thread; |
|
65 |
static int _page_size; |
|
66 |
||
67 |
static julong available_memory(); |
|
68 |
static julong physical_memory() { return _physical_memory; } |
|
69 |
static void initialize_system_info(); |
|
70 |
||
71 |
static void rebuild_cpu_to_node_map(); |
|
72 |
static GrowableArray<int>* cpu_to_node() { return _cpu_to_node; } |
|
73 |
||
74 |
static bool hugetlbfs_sanity_check(bool warn, size_t page_size); |
|
75 |
||
76 |
public: |
|
77 |
||
78 |
static void init_thread_fpu_state(); |
|
79 |
static pthread_t main_thread(void) { return _main_thread; } |
|
80 |
||
81 |
static void hotspot_sigmask(Thread* thread); |
|
82 |
||
83 |
static bool is_initial_thread(void); |
|
20377
393ee12eccc8
8022616: u4 should not be used as a type for thread_id
dsamersoff
parents:
18025
diff
changeset
|
84 |
static pid_t gettid(); |
10565 | 85 |
|
86 |
static int page_size(void) { return _page_size; } |
|
87 |
static void set_page_size(int val) { _page_size = val; } |
|
88 |
||
89 |
static address ucontext_get_pc(ucontext_t* uc); |
|
29573
2d800e5d575f
8074552: SafeFetch32 and SafeFetchN do not work in error handling
dholmes
parents:
26684
diff
changeset
|
90 |
static void ucontext_set_pc(ucontext_t* uc, address pc); |
10565 | 91 |
static intptr_t* ucontext_get_sp(ucontext_t* uc); |
92 |
static intptr_t* ucontext_get_fp(ucontext_t* uc); |
|
93 |
||
94 |
// For Analyzer Forte AsyncGetCallTrace profiling support: |
|
95 |
// |
|
96 |
// This interface should be declared in os_bsd_i486.hpp, but |
|
97 |
// that file provides extensions to the os class and not the |
|
98 |
// Bsd class. |
|
99 |
static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc, |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
100 |
intptr_t** ret_sp, intptr_t** ret_fp); |
10565 | 101 |
|
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34145
diff
changeset
|
102 |
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
|
103 |
|
10565 | 104 |
// This boolean allows users to forward their own non-matching signals |
105 |
// to JVM_handle_bsd_signal, harmlessly. |
|
106 |
static bool signal_handlers_are_installed; |
|
107 |
||
108 |
static int get_our_sigflags(int); |
|
109 |
static void set_our_sigflags(int, int); |
|
110 |
static void signal_sets_init(); |
|
111 |
static void install_signal_handlers(); |
|
112 |
static void set_signal_handler(int, bool); |
|
113 |
static bool is_sig_ignored(int sig); |
|
114 |
||
115 |
static sigset_t* unblocked_signals(); |
|
116 |
static sigset_t* vm_signals(); |
|
117 |
static sigset_t* allowdebug_blocked_signals(); |
|
118 |
||
119 |
// For signal-chaining |
|
120 |
static struct sigaction *get_chained_signal_action(int sig); |
|
121 |
static bool chained_handler(int sig, siginfo_t* siginfo, void* context); |
|
122 |
||
123 |
// Minimum stack size a thread can be created with (allowing |
|
124 |
// the VM to completely create the thread and enter user code) |
|
125 |
static size_t min_stack_allowed; |
|
126 |
||
127 |
// Return default stack size or guard size for the specified thread type |
|
128 |
static size_t default_stack_size(os::ThreadType thr_type); |
|
129 |
static size_t default_guard_size(os::ThreadType thr_type); |
|
130 |
||
131 |
// Real-time clock functions |
|
132 |
static void clock_init(void); |
|
133 |
||
134 |
// Stack repair handling |
|
135 |
||
136 |
// none present |
|
137 |
||
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
138 |
private: |
10565 | 139 |
typedef int (*sched_getcpu_func_t)(void); |
140 |
typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen); |
|
141 |
typedef int (*numa_max_node_func_t)(void); |
|
142 |
typedef int (*numa_available_func_t)(void); |
|
143 |
typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node); |
|
144 |
typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask); |
|
145 |
||
146 |
static sched_getcpu_func_t _sched_getcpu; |
|
147 |
static numa_node_to_cpus_func_t _numa_node_to_cpus; |
|
148 |
static numa_max_node_func_t _numa_max_node; |
|
149 |
static numa_available_func_t _numa_available; |
|
150 |
static numa_tonode_memory_func_t _numa_tonode_memory; |
|
151 |
static numa_interleave_memory_func_t _numa_interleave_memory; |
|
152 |
static unsigned long* _numa_all_nodes; |
|
153 |
||
154 |
static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; } |
|
155 |
static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; } |
|
156 |
static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; } |
|
157 |
static void set_numa_available(numa_available_func_t func) { _numa_available = func; } |
|
158 |
static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; } |
|
159 |
static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; } |
|
160 |
static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; } |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
161 |
public: |
10565 | 162 |
static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; } |
163 |
static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) { |
|
164 |
return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1; |
|
165 |
} |
|
166 |
static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; } |
|
167 |
static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; } |
|
168 |
static int numa_tonode_memory(void *start, size_t size, int node) { |
|
169 |
return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1; |
|
170 |
} |
|
171 |
static void numa_interleave_memory(void *start, size_t size) { |
|
172 |
if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) { |
|
173 |
_numa_interleave_memory(start, size, _numa_all_nodes); |
|
174 |
} |
|
175 |
} |
|
176 |
static int get_node_by_cpu(int cpu_id); |
|
177 |
}; |
|
178 |
||
179 |
||
13195 | 180 |
class PlatformEvent : public CHeapObj<mtInternal> { |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
181 |
private: |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
182 |
double CachePad[4]; // increase odds that _mutex is sole occupant of cache line |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
183 |
volatile int _Event; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
184 |
volatile int _nParked; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
185 |
pthread_mutex_t _mutex[1]; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
186 |
pthread_cond_t _cond[1]; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
187 |
double PostPad[2]; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
188 |
Thread * _Assoc; |
10565 | 189 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
190 |
public: // TODO-FIXME: make dtor private |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
191 |
~PlatformEvent() { guarantee(0, "invariant"); } |
10565 | 192 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
193 |
public: |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
194 |
PlatformEvent() { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
195 |
int status; |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
196 |
status = pthread_cond_init(_cond, NULL); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
197 |
assert_status(status == 0, status, "cond_init"); |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
198 |
status = pthread_mutex_init(_mutex, NULL); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
199 |
assert_status(status == 0, status, "mutex_init"); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
200 |
_Event = 0; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
201 |
_nParked = 0; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
202 |
_Assoc = NULL; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
203 |
} |
10565 | 204 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
205 |
// Use caution with reset() and fired() -- they may require MEMBARs |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
206 |
void reset() { _Event = 0; } |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
207 |
int fired() { return _Event; } |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
208 |
void park(); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
209 |
void unpark(); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
210 |
int park(jlong millis); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
211 |
void SetAssociation(Thread * a) { _Assoc = a; } |
18025 | 212 |
}; |
10565 | 213 |
|
13195 | 214 |
class PlatformParker : public CHeapObj<mtInternal> { |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
215 |
protected: |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
216 |
pthread_mutex_t _mutex[1]; |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
217 |
pthread_cond_t _cond[1]; |
10565 | 218 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
219 |
public: // TODO-FIXME: make dtor private |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
220 |
~PlatformParker() { guarantee(0, "invariant"); } |
10565 | 221 |
|
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
222 |
public: |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
223 |
PlatformParker() { |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
224 |
int status; |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
225 |
status = pthread_cond_init(_cond, NULL); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
226 |
assert_status(status == 0, status, "cond_init"); |
26684
d1221849ea3d
8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
26683
diff
changeset
|
227 |
status = pthread_mutex_init(_mutex, NULL); |
26683
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
228 |
assert_status(status == 0, status, "mutex_init"); |
a02753d5a0b2
8057107: cleanup indent white space issues prior to Contended Locking reorder and cache line bucket
dcubed
parents:
25472
diff
changeset
|
229 |
} |
18025 | 230 |
}; |
10565 | 231 |
|
232 |
#endif // OS_BSD_VM_OS_BSD_HPP |