os_solaris.hpp revision 7064:cde40424bcd4
1/*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
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_SOLARIS_VM_OS_SOLARIS_HPP
26#define OS_SOLARIS_VM_OS_SOLARIS_HPP
27
28// Solaris_OS defines the interface to Solaris operating systems
29
30// Information about the protection of the page at address '0' on this os.
31static bool zero_page_read_protected() { return true; }
32
33class Solaris {
34  friend class os;
35
36 private:
37
38  // Support for "new" libthread APIs for getting & setting thread context (2.8)
39  #define TRS_VALID       0
40  #define TRS_NONVOLATILE 1
41  #define TRS_LWPID       2
42  #define TRS_INVALID     3
43
44  // initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization
45  static int_fnP_mutex_tP _mutex_lock;
46  static int_fnP_mutex_tP _mutex_trylock;
47  static int_fnP_mutex_tP _mutex_unlock;
48  static int_fnP_mutex_tP_i_vP _mutex_init;
49  static int_fnP_mutex_tP _mutex_destroy;
50  static int _mutex_scope;
51
52  static int_fnP_cond_tP_mutex_tP_timestruc_tP _cond_timedwait;
53  static int_fnP_cond_tP_mutex_tP _cond_wait;
54  static int_fnP_cond_tP _cond_signal;
55  static int_fnP_cond_tP _cond_broadcast;
56  static int_fnP_cond_tP_i_vP _cond_init;
57  static int_fnP_cond_tP _cond_destroy;
58  static int _cond_scope;
59
60  typedef uintptr_t       lgrp_cookie_t;
61  typedef id_t            lgrp_id_t;
62  typedef int             lgrp_rsrc_t;
63  typedef enum lgrp_view {
64        LGRP_VIEW_CALLER,       /* what's available to the caller */
65        LGRP_VIEW_OS            /* what's available to operating system */
66  } lgrp_view_t;
67
68  typedef uint_t (*getisax_func_t)(uint32_t* array, uint_t n);
69
70  typedef lgrp_id_t (*lgrp_home_func_t)(idtype_t idtype, id_t id);
71  typedef lgrp_cookie_t (*lgrp_init_func_t)(lgrp_view_t view);
72  typedef int (*lgrp_fini_func_t)(lgrp_cookie_t cookie);
73  typedef lgrp_id_t (*lgrp_root_func_t)(lgrp_cookie_t cookie);
74  typedef int (*lgrp_children_func_t)(lgrp_cookie_t  cookie,  lgrp_id_t  parent,
75                                      lgrp_id_t *lgrp_array, uint_t lgrp_array_size);
76  typedef int (*lgrp_resources_func_t)(lgrp_cookie_t  cookie,  lgrp_id_t  lgrp,
77                                      lgrp_id_t *lgrp_array, uint_t lgrp_array_size,
78                                      lgrp_rsrc_t type);
79  typedef int (*lgrp_nlgrps_func_t)(lgrp_cookie_t cookie);
80  typedef int (*lgrp_cookie_stale_func_t)(lgrp_cookie_t cookie);
81  typedef int (*meminfo_func_t)(const uint64_t inaddr[],   int addr_count,
82                                const uint_t  info_req[],  int info_count,
83                                uint64_t  outdata[], uint_t validity[]);
84
85  static getisax_func_t _getisax;
86
87  static lgrp_home_func_t _lgrp_home;
88  static lgrp_init_func_t _lgrp_init;
89  static lgrp_fini_func_t _lgrp_fini;
90  static lgrp_root_func_t _lgrp_root;
91  static lgrp_children_func_t _lgrp_children;
92  static lgrp_resources_func_t _lgrp_resources;
93  static lgrp_nlgrps_func_t _lgrp_nlgrps;
94  static lgrp_cookie_stale_func_t _lgrp_cookie_stale;
95  static lgrp_cookie_t _lgrp_cookie;
96
97  static meminfo_func_t _meminfo;
98
99  // Large Page Support
100  static bool is_valid_page_size(size_t bytes);
101  static size_t page_size_for_alignment(size_t alignment);
102  static bool setup_large_pages(caddr_t start, size_t bytes, size_t align);
103
104  static void init_thread_fpu_state(void);
105
106  static void try_enable_extended_io();
107
108  // For signal-chaining
109  static unsigned long sigs;                 // mask of signals that have
110                                             // preinstalled signal handlers
111  static struct sigaction *(*get_signal_action)(int);
112  static struct sigaction *get_preinstalled_handler(int);
113  static int (*get_libjsig_version)();
114  static void save_preinstalled_handler(int, struct sigaction&);
115  static void check_signal_handler(int sig);
116  // For overridable signals
117  static int _SIGinterrupt;                  // user-overridable INTERRUPT_SIGNAL
118  static int _SIGasync;                      // user-overridable ASYNC_SIGNAL
119  static void set_SIGinterrupt(int newsig) { _SIGinterrupt = newsig; }
120  static void set_SIGasync(int newsig) { _SIGasync = newsig; }
121
122 public:
123  // Large Page Support--ISM.
124  static bool largepage_range(char* addr, size_t size);
125
126  static int SIGinterrupt() { return _SIGinterrupt; }
127  static int SIGasync() { return _SIGasync; }
128  static address handler_start, handler_end; // start and end pc of thr_sighndlrinfo
129
130  static bool valid_stack_address(Thread* thread, address sp);
131  static bool valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect);
132  static ucontext_t* get_valid_uc_in_signal_handler(Thread* thread,
133    ucontext_t* uc);
134
135  static ExtendedPC  ucontext_get_ExtendedPC(ucontext_t* uc);
136  static intptr_t*   ucontext_get_sp(ucontext_t* uc);
137  // ucontext_get_fp() is only used by Solaris X86 (see note below)
138  static intptr_t*   ucontext_get_fp(ucontext_t* uc);
139  static address    ucontext_get_pc(ucontext_t* uc);
140
141  // For Analyzer Forte AsyncGetCallTrace profiling support:
142  // Parameter ret_fp is only used by Solaris X86.
143  //
144  // We should have different declarations of this interface in
145  // os_solaris_i486.hpp and os_solaris_sparc.hpp, but that file
146  // provides extensions to the os class and not the Solaris class.
147  static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,
148    intptr_t** ret_sp, intptr_t** ret_fp);
149
150  static void hotspot_sigmask(Thread* thread);
151
152  // SR_handler
153  static void SR_handler(Thread* thread, ucontext_t* uc);
154 protected:
155  // Solaris-specific interface goes here
156  static julong available_memory();
157  static julong physical_memory() { return _physical_memory; }
158  static julong _physical_memory;
159  static void initialize_system_info();
160  static int _dev_zero_fd;
161  static int get_dev_zero_fd() { return _dev_zero_fd; }
162  static void set_dev_zero_fd(int fd) { _dev_zero_fd = fd; }
163  static int commit_memory_impl(char* addr, size_t bytes, bool exec);
164  static int commit_memory_impl(char* addr, size_t bytes,
165                                size_t alignment_hint, bool exec);
166  static char* mmap_chunk(char *addr, size_t size, int flags, int prot);
167  static char* anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed);
168  static bool mpss_sanity_check(bool warn, size_t * page_size);
169
170  // Workaround for 4352906. thr_stksegment sometimes returns
171  // a bad value for the primordial thread's stack base when
172  // it is called more than one time.
173  // Workaround is to cache the initial value to avoid further
174  // calls to thr_stksegment.
175  // It appears that someone (Hotspot?) is trashing the user's
176  // proc_t structure (note that this is a system struct).
177  static address _main_stack_base;
178
179  static void print_distro_info(outputStream* st);
180  static void print_libversion_info(outputStream* st);
181
182 public:
183  static void libthread_init();
184  static void synchronization_init();
185  static bool liblgrp_init();
186  // Load miscellaneous symbols.
187  static void misc_sym_init();
188  // This boolean allows users to forward their own non-matching signals
189  // to JVM_handle_solaris_signal, harmlessly.
190  static bool signal_handlers_are_installed;
191
192  static void signal_sets_init();
193  static void install_signal_handlers();
194  static void set_signal_handler(int sig, bool set_installed, bool oktochain);
195  static void init_signal_mem();
196  static bool is_sig_ignored(int sig);
197  static void set_our_sigflags(int, int);
198  static int get_our_sigflags(int);
199
200  // For signal-chaining
201  static bool libjsig_is_loaded; // libjsig that interposes sigaction(),
202                                 // signal(), sigset() is loaded
203  static struct sigaction *get_chained_signal_action(int sig);
204  static bool chained_handler(int sig, siginfo_t *siginfo, void *context);
205
206  // Allows us to switch between lwp and thread -based synchronization
207  static int mutex_lock(mutex_t *mx)    { return _mutex_lock(mx); }
208  static int mutex_trylock(mutex_t *mx) { return _mutex_trylock(mx); }
209  static int mutex_unlock(mutex_t *mx)  { return _mutex_unlock(mx); }
210  static int mutex_init(mutex_t *mx)    { return _mutex_init(mx, os::Solaris::mutex_scope(), NULL); }
211  static int mutex_destroy(mutex_t *mx) { return _mutex_destroy(mx); }
212  static int mutex_scope()              { return _mutex_scope; }
213
214  static void set_mutex_lock(int_fnP_mutex_tP func)      { _mutex_lock = func; }
215  static void set_mutex_trylock(int_fnP_mutex_tP func)   { _mutex_trylock = func; }
216  static void set_mutex_unlock(int_fnP_mutex_tP func)    { _mutex_unlock = func; }
217  static void set_mutex_init(int_fnP_mutex_tP_i_vP func) { _mutex_init = func; }
218  static void set_mutex_destroy(int_fnP_mutex_tP func)   { _mutex_destroy = func; }
219  static void set_mutex_scope(int scope)                 { _mutex_scope = scope; }
220
221  static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst)
222                                                { return _cond_timedwait(cv, mx, abst); }
223  static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); }
224  static int cond_signal(cond_t *cv)            { return _cond_signal(cv); }
225  static int cond_broadcast(cond_t *cv)         { return _cond_broadcast(cv); }
226  static int cond_init(cond_t *cv)              { return _cond_init(cv, os::Solaris::cond_scope(), NULL); }
227  static int cond_destroy(cond_t *cv)           { return _cond_destroy(cv); }
228  static int cond_scope()                       { return _cond_scope; }
229
230  static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func)
231                                                           { _cond_timedwait = func; }
232  static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; }
233  static void set_cond_signal(int_fnP_cond_tP func)        { _cond_signal = func; }
234  static void set_cond_broadcast(int_fnP_cond_tP func)     { _cond_broadcast = func; }
235  static void set_cond_init(int_fnP_cond_tP_i_vP func)     { _cond_init = func; }
236  static void set_cond_destroy(int_fnP_cond_tP func)       { _cond_destroy = func; }
237  static void set_cond_scope(int scope)                    { _cond_scope = scope; }
238
239  static void set_lgrp_home(lgrp_home_func_t func) { _lgrp_home = func; }
240  static void set_lgrp_init(lgrp_init_func_t func) { _lgrp_init = func; }
241  static void set_lgrp_fini(lgrp_fini_func_t func) { _lgrp_fini = func; }
242  static void set_lgrp_root(lgrp_root_func_t func) { _lgrp_root = func; }
243  static void set_lgrp_children(lgrp_children_func_t func)   { _lgrp_children = func; }
244  static void set_lgrp_resources(lgrp_resources_func_t func) { _lgrp_resources = func; }
245  static void set_lgrp_nlgrps(lgrp_nlgrps_func_t func)       { _lgrp_nlgrps = func; }
246  static void set_lgrp_cookie_stale(lgrp_cookie_stale_func_t func) { _lgrp_cookie_stale = func; }
247  static void set_lgrp_cookie(lgrp_cookie_t cookie)  { _lgrp_cookie = cookie; }
248
249  static id_t lgrp_home(idtype_t type, id_t id)      { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; }
250  static lgrp_cookie_t lgrp_init(lgrp_view_t view)   { return _lgrp_init != NULL ? _lgrp_init(view) : 0; }
251  static int lgrp_fini(lgrp_cookie_t cookie)         { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; }
252  static lgrp_id_t lgrp_root(lgrp_cookie_t cookie)   { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; };
253  static int lgrp_children(lgrp_cookie_t  cookie,  lgrp_id_t  parent,
254                    lgrp_id_t *lgrp_array, uint_t lgrp_array_size) {
255    return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1;
256  }
257  static int lgrp_resources(lgrp_cookie_t  cookie,  lgrp_id_t  lgrp,
258                            lgrp_id_t *lgrp_array, uint_t lgrp_array_size,
259                            lgrp_rsrc_t type) {
260    return _lgrp_resources != NULL ? _lgrp_resources(cookie, lgrp, lgrp_array, lgrp_array_size, type) : -1;
261  }
262
263  static int lgrp_nlgrps(lgrp_cookie_t cookie)       { return _lgrp_nlgrps != NULL ? _lgrp_nlgrps(cookie) : -1; }
264  static int lgrp_cookie_stale(lgrp_cookie_t cookie) {
265    return _lgrp_cookie_stale != NULL ? _lgrp_cookie_stale(cookie) : -1;
266  }
267  static lgrp_cookie_t lgrp_cookie()                 { return _lgrp_cookie; }
268
269  static bool supports_getisax()                     { return _getisax != NULL; }
270  static uint_t getisax(uint32_t* array, uint_t n);
271
272  static void set_meminfo(meminfo_func_t func)       { _meminfo = func; }
273  static int meminfo (const uint64_t inaddr[],   int addr_count,
274                     const uint_t  info_req[],  int info_count,
275                     uint64_t  outdata[], uint_t validity[]) {
276    return _meminfo != NULL ? _meminfo(inaddr, addr_count, info_req, info_count,
277                                       outdata, validity) : -1;
278  }
279
280  static sigset_t* unblocked_signals();
281  static sigset_t* vm_signals();
282  static sigset_t* allowdebug_blocked_signals();
283
284  // %%% Following should be promoted to os.hpp:
285  // Trace number of created threads
286  static          jint  _os_thread_limit;
287  static volatile jint  _os_thread_count;
288
289  // Minimum stack size a thread can be created with (allowing
290  // the VM to completely create the thread and enter user code)
291
292  static size_t min_stack_allowed;
293
294  // Stack overflow handling
295
296  static int max_register_window_saves_before_flushing();
297
298  // Stack repair handling
299
300  // none present
301
302};
303
304class PlatformEvent : public CHeapObj<mtInternal> {
305  private:
306    double CachePad[4];   // increase odds that _mutex is sole occupant of cache line
307    volatile int _Event;
308    int _nParked;
309    int _pipev[2];
310    mutex_t _mutex[1];
311    cond_t  _cond[1];
312    double PostPad[2];
313
314  protected:
315    // Defining a protected ctor effectively gives us an abstract base class.
316    // That is, a PlatformEvent can never be instantiated "naked" but only
317    // as a part of a ParkEvent (recall that ParkEvent extends PlatformEvent).
318    // TODO-FIXME: make dtor private
319    ~PlatformEvent() { guarantee(0, "invariant"); }
320    PlatformEvent() {
321      int status;
322      status = os::Solaris::cond_init(_cond);
323      assert_status(status == 0, status, "cond_init");
324      status = os::Solaris::mutex_init(_mutex);
325      assert_status(status == 0, status, "mutex_init");
326      _Event   = 0;
327      _nParked = 0;
328      _pipev[0] = _pipev[1] = -1;
329    }
330
331  public:
332    // Exercise caution using reset() and fired() -- they may require MEMBARs
333    void reset() { _Event = 0; }
334    int  fired() { return _Event; }
335    void park();
336    int  park(jlong millis);
337    void unpark();
338};
339
340class PlatformParker : public CHeapObj<mtInternal> {
341  protected:
342    mutex_t _mutex[1];
343    cond_t  _cond[1];
344
345  public:       // TODO-FIXME: make dtor private
346    ~PlatformParker() { guarantee(0, "invariant"); }
347
348  public:
349    PlatformParker() {
350      int status;
351      status = os::Solaris::cond_init(_cond);
352      assert_status(status == 0, status, "cond_init");
353      status = os::Solaris::mutex_init(_mutex);
354      assert_status(status == 0, status, "mutex_init");
355    }
356};
357
358#endif // OS_SOLARIS_VM_OS_SOLARIS_HPP
359