comparison src/os/aix/vm/misc_aix.hpp @ 9665:4338b5465f50

8140645: Recent Developments for AIX Summary: Port recent developments from SAP for AIX to the OpenJDK Reviewed-by: goetz
author stuefe
date Fri, 30 Oct 2015 12:36:54 +0100
parents
children ce87b1141c12
comparison
equal deleted inserted replaced
-1:000000000000 0:a0e31a7ead2d
1 /*
2 * Copyright 2012, 2015 SAP AG. 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
26 #ifndef OS_AIX_VM_MISC_AIX_HPP
27 #define OS_AIX_VM_MISC_AIX_HPP
28
29 // misc_aix.hpp, misc_aix.cpp: convenience functions needed for the OpenJDK AIX
30 // port.
31 #include "utilities/globalDefinitions.hpp"
32
33 #include <pthread.h>
34
35 // Trace if verbose to tty.
36 #define trcVerbose(fmt, ...) { \
37 if (Verbose) { \
38 fprintf(stderr, fmt, ##__VA_ARGS__); \
39 fputc('\n', stderr); fflush(stderr); \
40 } \
41 }
42 #define ERRBYE(s) { trcVerbose(s); return -1; }
43 #define trc(fmt, ...)
44
45 #define assert0(b) assert((b), "")
46 #define guarantee0(b) guarantee((b), "")
47 template <class T1, class T2> bool is_aligned_to(T1 what, T2 alignment) {
48 return (((uintx)(what)) & (((uintx)(alignment)) - 1)) == 0 ? true : false;
49 }
50
51 // CritSect: simple critical section implementation using pthread mutexes.
52 namespace MiscUtils {
53 typedef pthread_mutex_t critsect_t;
54
55 void init_critsect(MiscUtils::critsect_t* cs);
56 void free_critsect(MiscUtils::critsect_t* cs);
57 void enter_critsect(MiscUtils::critsect_t* cs);
58 void leave_critsect(MiscUtils::critsect_t* cs);
59
60 // Need to wrap this in an object because we need to dynamically initialize
61 // critical section (because of windows, where there is no way to initialize
62 // a CRITICAL_SECTION statically. On Unix, we could use
63 // PTHREAD_MUTEX_INITIALIZER).
64
65 // Note: The critical section does NOT get cleaned up in the destructor. That is
66 // by design: the CritSect class is only ever used as global objects whose
67 // lifetime spans the whole VM life; in that context we don't want the lock to
68 // be cleaned up when global C++ objects are destroyed, but to continue to work
69 // correctly right to the very end of the process life.
70 class CritSect {
71 critsect_t _cs;
72 public:
73 CritSect() { init_critsect(&_cs); }
74 //~CritSect() { free_critsect(&_cs); }
75 void enter() { enter_critsect(&_cs); }
76 void leave() { leave_critsect(&_cs); }
77 };
78
79 class AutoCritSect {
80 CritSect* const _pcsobj;
81 public:
82 AutoCritSect(CritSect* pcsobj)
83 : _pcsobj(pcsobj)
84 {
85 _pcsobj->enter();
86 }
87 ~AutoCritSect() {
88 _pcsobj->leave();
89 }
90 };
91
92 // Returns true if pointer can be dereferenced without triggering a segment
93 // violation. Returns false if pointer is invalid.
94 // Note: Depends on stub routines; prior to stub routine generation, will
95 // always return true. Use CanUseSafeFetch32 to handle this case.
96 bool is_readable_pointer(const void* p);
97
98 }
99
100 #endif // OS_AIX_VM_MISC_AIX_HPP
101