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