annotate 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
rev   line source
stuefe@9665 1 /*
stuefe@9665 2 * Copyright 2012, 2015 SAP AG. All rights reserved.
stuefe@9665 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
stuefe@9665 4 *
stuefe@9665 5 * This code is free software; you can redistribute it and/or modify it
stuefe@9665 6 * under the terms of the GNU General Public License version 2 only, as
stuefe@9665 7 * published by the Free Software Foundation.
stuefe@9665 8 *
stuefe@9665 9 * This code is distributed in the hope that it will be useful, but WITHOUT
stuefe@9665 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
stuefe@9665 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
stuefe@9665 12 * version 2 for more details (a copy is included in the LICENSE file that
stuefe@9665 13 * accompanied this code).
stuefe@9665 14 *
stuefe@9665 15 * You should have received a copy of the GNU General Public License version
stuefe@9665 16 * 2 along with this work; if not, write to the Free Software Foundation,
stuefe@9665 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
stuefe@9665 18 *
stuefe@9665 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
stuefe@9665 20 * or visit www.oracle.com if you need additional information or have any
stuefe@9665 21 * questions.
stuefe@9665 22 *
stuefe@9665 23 */
stuefe@9665 24
stuefe@9665 25
stuefe@9665 26 #ifndef OS_AIX_VM_MISC_AIX_HPP
stuefe@9665 27 #define OS_AIX_VM_MISC_AIX_HPP
stuefe@9665 28
stuefe@9665 29 // misc_aix.hpp, misc_aix.cpp: convenience functions needed for the OpenJDK AIX
stuefe@9665 30 // port.
stuefe@9665 31 #include "utilities/globalDefinitions.hpp"
stuefe@9665 32
stuefe@9665 33 #include <pthread.h>
stuefe@9665 34
stuefe@9665 35 // Trace if verbose to tty.
stuefe@9665 36 #define trcVerbose(fmt, ...) { \
stuefe@9665 37 if (Verbose) { \
stuefe@9665 38 fprintf(stderr, fmt, ##__VA_ARGS__); \
stuefe@9665 39 fputc('\n', stderr); fflush(stderr); \
stuefe@9665 40 } \
stuefe@9665 41 }
stuefe@9665 42 #define ERRBYE(s) { trcVerbose(s); return -1; }
stuefe@9665 43 #define trc(fmt, ...)
stuefe@9665 44
stuefe@9665 45 #define assert0(b) assert((b), "")
stuefe@9665 46 #define guarantee0(b) guarantee((b), "")
stuefe@9665 47 template <class T1, class T2> bool is_aligned_to(T1 what, T2 alignment) {
stuefe@9665 48 return (((uintx)(what)) & (((uintx)(alignment)) - 1)) == 0 ? true : false;
stuefe@9665 49 }
stuefe@9665 50
stuefe@9665 51 // CritSect: simple critical section implementation using pthread mutexes.
stuefe@9665 52 namespace MiscUtils {
stuefe@9665 53 typedef pthread_mutex_t critsect_t;
stuefe@9665 54
stuefe@9665 55 void init_critsect(MiscUtils::critsect_t* cs);
stuefe@9665 56 void free_critsect(MiscUtils::critsect_t* cs);
stuefe@9665 57 void enter_critsect(MiscUtils::critsect_t* cs);
stuefe@9665 58 void leave_critsect(MiscUtils::critsect_t* cs);
stuefe@9665 59
stuefe@9665 60 // Need to wrap this in an object because we need to dynamically initialize
stuefe@9665 61 // critical section (because of windows, where there is no way to initialize
stuefe@9665 62 // a CRITICAL_SECTION statically. On Unix, we could use
stuefe@9665 63 // PTHREAD_MUTEX_INITIALIZER).
stuefe@9665 64
stuefe@9665 65 // Note: The critical section does NOT get cleaned up in the destructor. That is
stuefe@9665 66 // by design: the CritSect class is only ever used as global objects whose
stuefe@9665 67 // lifetime spans the whole VM life; in that context we don't want the lock to
stuefe@9665 68 // be cleaned up when global C++ objects are destroyed, but to continue to work
stuefe@9665 69 // correctly right to the very end of the process life.
stuefe@9665 70 class CritSect {
stuefe@9665 71 critsect_t _cs;
stuefe@9665 72 public:
stuefe@9665 73 CritSect() { init_critsect(&_cs); }
stuefe@9665 74 //~CritSect() { free_critsect(&_cs); }
stuefe@9665 75 void enter() { enter_critsect(&_cs); }
stuefe@9665 76 void leave() { leave_critsect(&_cs); }
stuefe@9665 77 };
stuefe@9665 78
stuefe@9665 79 class AutoCritSect {
stuefe@9665 80 CritSect* const _pcsobj;
stuefe@9665 81 public:
stuefe@9665 82 AutoCritSect(CritSect* pcsobj)
stuefe@9665 83 : _pcsobj(pcsobj)
stuefe@9665 84 {
stuefe@9665 85 _pcsobj->enter();
stuefe@9665 86 }
stuefe@9665 87 ~AutoCritSect() {
stuefe@9665 88 _pcsobj->leave();
stuefe@9665 89 }
stuefe@9665 90 };
stuefe@9665 91
stuefe@9665 92 // Returns true if pointer can be dereferenced without triggering a segment
stuefe@9665 93 // violation. Returns false if pointer is invalid.
stuefe@9665 94 // Note: Depends on stub routines; prior to stub routine generation, will
stuefe@9665 95 // always return true. Use CanUseSafeFetch32 to handle this case.
stuefe@9665 96 bool is_readable_pointer(const void* p);
stuefe@9665 97
stuefe@9665 98 }
stuefe@9665 99
stuefe@9665 100 #endif // OS_AIX_VM_MISC_AIX_HPP
stuefe@9665 101