os_aix.hpp revision 9665:ce87b1141c12
1/*
2 * Copyright (c) 1999, 2015, Oracle and/or its affiliates. All rights reserved.
3 * Copyright 2013, 2015 SAP AG. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 *
24 */
25
26#ifndef OS_AIX_VM_OS_AIX_HPP
27#define OS_AIX_VM_OS_AIX_HPP
28
29// Information about the protection of the page at address '0' on this os.
30static bool zero_page_read_protected() { return false; }
31
32// Class Aix defines the interface to the Aix operating systems.
33
34class Aix {
35  friend class os;
36
37  static bool libjsig_is_loaded;        // libjsig that interposes sigaction(),
38                                        // __sigaction(), signal() is loaded
39  static struct sigaction *(*get_signal_action)(int);
40  static struct sigaction *get_preinstalled_handler(int);
41  static void save_preinstalled_handler(int, struct sigaction&);
42
43  static void check_signal_handler(int sig);
44
45 private:
46
47  static julong _physical_memory;
48  static pthread_t _main_thread;
49  static Mutex* _createThread_lock;
50  static int _page_size;
51
52  // Page size of newly created pthreads.
53  static int _stack_page_size;
54
55  // -1 = uninitialized, 0 = AIX, 1 = OS/400 (PASE)
56  static int _on_pase;
57
58  // -1 = uninitialized, otherwise 16 bit number:
59  //  lower 8 bit - minor version
60  //  higher 8 bit - major version
61  //  For AIX, e.g. 0x0601 for AIX 6.1
62  //  for OS/400 e.g. 0x0504 for OS/400 V5R4
63  static int _os_version;
64
65  // 4 Byte kernel version: Version, Release, Tech Level, Service Pack.
66  static unsigned int _os_kernel_version;
67
68  // -1 = uninitialized,
69  //  0 - SPEC1170 not requested (XPG_SUS_ENV is OFF or not set)
70  //  1 - SPEC1170 requested (XPG_SUS_ENV is ON)
71  static int _xpg_sus_mode;
72
73  // -1 = uninitialized,
74  //  0 - EXTSHM=OFF or not set
75  //  1 - EXTSHM=ON
76  static int _extshm;
77
78  static julong available_memory();
79  static julong physical_memory() { return _physical_memory; }
80  static void initialize_system_info();
81
82  // OS recognitions (PASE/AIX, OS level) call this before calling any
83  // one of Aix::on_pase(), Aix::os_version().
84  static void initialize_os_info();
85
86  // Scan environment for important settings which might effect the
87  // VM. Trace out settings. Warn about invalid settings and/or
88  // correct them.
89  //
90  // Must run after os::Aix::initialue_os_info().
91  static void scan_environment();
92
93  // Initialize libo4 (on PASE) and libperfstat (on AIX). Call this
94  // before relying on functions from either lib, e.g. Aix::get_meminfo().
95  static void initialize_libo4();
96  static void initialize_libperfstat();
97
98 public:
99  static void init_thread_fpu_state();
100  static pthread_t main_thread(void)                                { return _main_thread; }
101  static void set_createThread_lock(Mutex* lk)                      { _createThread_lock = lk; }
102  static Mutex* createThread_lock(void)                             { return _createThread_lock; }
103  static void hotspot_sigmask(Thread* thread);
104
105  // Given an address, returns the size of the page backing that address
106  static size_t query_pagesize(void* p);
107
108  // Return `true' if the calling thread is the primordial thread. The
109  // primordial thread is the thread which contains the main function,
110  // *not* necessarily the thread which initialized the VM by calling
111  // JNI_CreateJavaVM.
112  static bool is_primordial_thread(void);
113
114  static int page_size(void) {
115    assert(_page_size != -1, "not initialized");
116    return _page_size;
117  }
118
119  // Accessor methods for stack page size which may be different from usual page size.
120  static int stack_page_size(void) {
121    assert(_stack_page_size != -1, "not initialized");
122    return _stack_page_size;
123  }
124
125  // This is used to scale stack space (guard pages etc.). The name is somehow misleading.
126  static int vm_default_page_size(void ) { return 8*K; }
127
128  static address   ucontext_get_pc(const ucontext_t* uc);
129  static intptr_t* ucontext_get_sp(ucontext_t* uc);
130  static intptr_t* ucontext_get_fp(ucontext_t* uc);
131  // Set PC into context. Needed for continuation after signal.
132  static void ucontext_set_pc(ucontext_t* uc, address pc);
133
134  // This boolean allows users to forward their own non-matching signals
135  // to JVM_handle_aix_signal, harmlessly.
136  static bool signal_handlers_are_installed;
137
138  static int get_our_sigflags(int);
139  static void set_our_sigflags(int, int);
140  static void signal_sets_init();
141  static void install_signal_handlers();
142  static void set_signal_handler(int, bool);
143  static bool is_sig_ignored(int sig);
144
145  static sigset_t* unblocked_signals();
146  static sigset_t* vm_signals();
147  static sigset_t* allowdebug_blocked_signals();
148
149  // For signal-chaining
150  static struct sigaction *get_chained_signal_action(int sig);
151  static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
152
153  // libpthread version string
154  static void libpthread_init();
155
156  // Minimum stack size a thread can be created with (allowing
157  // the VM to completely create the thread and enter user code)
158  static size_t min_stack_allowed;
159
160  // Return default stack size or guard size for the specified thread type
161  static size_t default_stack_size(os::ThreadType thr_type);
162  static size_t default_guard_size(os::ThreadType thr_type);
163
164  // Function returns true if we run on OS/400 (pase), false if we run
165  // on AIX.
166  static bool on_pase() {
167    assert(_on_pase != -1, "not initialized");
168    return _on_pase ? true : false;
169  }
170
171  // Function returns true if we run on AIX, false if we run on OS/400
172  // (pase).
173  static bool on_aix() {
174    assert(_on_pase != -1, "not initialized");
175    return _on_pase ? false : true;
176  }
177
178  // -1 = uninitialized, otherwise 16 bit number:
179  // lower 8 bit - minor version
180  // higher 8 bit - major version
181  // For AIX, e.g. 0x0601 for AIX 6.1
182  // for OS/400 e.g. 0x0504 for OS/400 V5R4
183  static int os_version () {
184    assert(_os_version != -1, "not initialized");
185    return _os_version;
186  }
187
188  // Get 4 byte AIX kernel version number:
189  // highest 2 bytes: Version, Release
190  // if available: lowest 2 bytes: Tech Level, Service Pack.
191  static unsigned int os_kernel_version() {
192    if (_os_kernel_version) return _os_kernel_version;
193    return os_version() << 16;
194  }
195
196  // Convenience method: returns true if running on PASE V5R4 or older.
197  static bool on_pase_V5R4_or_older() {
198    return on_pase() && os_version() <= 0x0504;
199  }
200
201  // Convenience method: returns true if running on AIX 5.3 or older.
202  static bool on_aix_53_or_older() {
203    return on_aix() && os_version() <= 0x0503;
204  }
205
206  // Returns true if we run in SPEC1170 compliant mode (XPG_SUS_ENV=ON).
207  static bool xpg_sus_mode() {
208    assert(_xpg_sus_mode != -1, "not initialized");
209    return _xpg_sus_mode;
210  }
211
212  // Returns true if EXTSHM=ON.
213  static bool extshm() {
214    assert(_extshm != -1, "not initialized");
215    return _extshm;
216  }
217
218  // result struct for get_meminfo()
219  struct meminfo_t {
220
221    // Amount of virtual memory (in units of 4 KB pages)
222    unsigned long long virt_total;
223
224    // Amount of real memory, in bytes
225    unsigned long long real_total;
226
227    // Amount of free real memory, in bytes
228    unsigned long long real_free;
229
230    // Total amount of paging space, in bytes
231    unsigned long long pgsp_total;
232
233    // Amount of free paging space, in bytes
234    unsigned long long pgsp_free;
235
236  };
237
238  // Functions to retrieve memory information on AIX, PASE.
239  // (on AIX, using libperfstat, on PASE with libo4.so).
240  // Returns true if ok, false if error.
241  static bool get_meminfo(meminfo_t* pmi);
242
243};
244
245
246class PlatformEvent : public CHeapObj<mtInternal> {
247  private:
248    double CachePad [4];   // increase odds that _mutex is sole occupant of cache line
249    volatile int _Event;
250    volatile int _nParked;
251    pthread_mutex_t _mutex  [1];
252    pthread_cond_t  _cond   [1];
253    double PostPad  [2];
254    Thread * _Assoc;
255
256  public:       // TODO-FIXME: make dtor private
257    ~PlatformEvent() { guarantee (0, "invariant"); }
258
259  public:
260    PlatformEvent() {
261      int status;
262      status = pthread_cond_init (_cond, NULL);
263      assert_status(status == 0, status, "cond_init");
264      status = pthread_mutex_init (_mutex, NULL);
265      assert_status(status == 0, status, "mutex_init");
266      _Event   = 0;
267      _nParked = 0;
268      _Assoc   = NULL;
269    }
270
271    // Use caution with reset() and fired() -- they may require MEMBARs
272    void reset() { _Event = 0; }
273    int  fired() { return _Event; }
274    void park ();
275    void unpark ();
276    int  TryPark ();
277    int  park (jlong millis);
278    void SetAssociation (Thread * a) { _Assoc = a; }
279};
280
281class PlatformParker : public CHeapObj<mtInternal> {
282  protected:
283    pthread_mutex_t _mutex [1];
284    pthread_cond_t  _cond  [1];
285
286  public:       // TODO-FIXME: make dtor private
287    ~PlatformParker() { guarantee (0, "invariant"); }
288
289  public:
290    PlatformParker() {
291      int status;
292      status = pthread_cond_init (_cond, NULL);
293      assert_status(status == 0, status, "cond_init");
294      status = pthread_mutex_init (_mutex, NULL);
295      assert_status(status == 0, status, "mutex_init");
296    }
297};
298
299#endif // OS_AIX_VM_OS_AIX_HPP
300