hotspot/src/os/aix/vm/porting_aix.hpp
changeset 30198 ec621727bd41
parent 22831 1e2ba1d62103
child 31352 a6ab7217b5cc
equal deleted inserted replaced
30197:5b5007789e4f 30198:ec621727bd41
     1 /*
     1 /*
     2  * Copyright 2012, 2013 SAP AG. All rights reserved.
     2  * Copyright 2012, 2015 SAP AG. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     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
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    20  * or visit www.oracle.com if you need additional information or have any
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    21  * questions.
    22  *
    22  *
    23  */
    23  */
    24 
    24 
       
    25 #ifndef OS_AIX_VM_PORTING_AIX_HPP
       
    26 #define OS_AIX_VM_PORTING_AIX_HPP
       
    27 
    25 #include <stddef.h>
    28 #include <stddef.h>
       
    29 
       
    30 // PPC port only:
       
    31 #define assert0(b) assert( (b), "" )
       
    32 #define guarantee0(b) assert( (b), "" )
       
    33 template <class T1, class T2> bool is_aligned_to(T1 what, T2 alignment) {
       
    34   return  ( ((uintx)(what)) & (((uintx)(alignment)) - 1) ) == 0 ? true : false;
       
    35 }
    26 
    36 
    27 // Header file to contain porting-relevant code which does not have a
    37 // Header file to contain porting-relevant code which does not have a
    28 // home anywhere else and which can not go into os_<platform>.h because
    38 // home anywhere else and which can not go into os_<platform>.h because
    29 // that header is included inside the os class definition, hence all
    39 // that header is included inside the os class definition, hence all
    30 // its content is part of the os class.
    40 // its content is part of the os class.
    77       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
    87       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
    78       int* p_displacement,             // [out] optional: displacement
    88       int* p_displacement,             // [out] optional: displacement
    79       const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
    89       const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
    80       char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
    90       char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
    81     );
    91     );
       
    92 
       
    93 // -------------------------------------------------------------------------
       
    94 
       
    95 // A simple critical section which shall be based upon OS critical
       
    96 // sections (CRITICAL_SECTION resp. Posix Mutex) and nothing else.
       
    97 
       
    98 #include <pthread.h>
       
    99 
       
   100 namespace MiscUtils {
       
   101   typedef pthread_mutex_t critsect_t;
       
   102 
       
   103   inline void init_critsect(MiscUtils::critsect_t* cs) {
       
   104     pthread_mutex_init(cs, NULL);
       
   105   }
       
   106   inline void free_critsect(MiscUtils::critsect_t* cs) {
       
   107     pthread_mutex_destroy(cs);
       
   108   }
       
   109   inline void enter_critsect(MiscUtils::critsect_t* cs) {
       
   110     pthread_mutex_lock(cs);
       
   111   }
       
   112   inline void leave_critsect(MiscUtils::critsect_t* cs) {
       
   113     pthread_mutex_unlock(cs);
       
   114   }
       
   115 
       
   116   // Need to wrap this in an object because we need to dynamically initialize
       
   117   // critical section (because of windows, where there is no way to initialize
       
   118   // a CRITICAL_SECTION statically. On Unix, we could use
       
   119   // PTHREAD_MUTEX_INITIALIZER)
       
   120 
       
   121   // Note: The critical section does NOT get cleaned up in the destructor. That is
       
   122   // by design: the CritSect class is only ever used as global objects whose
       
   123   // lifetime spans the whole VM life; in that context we don't want the lock to
       
   124   // be cleaned up when global C++ objects are destroyed, but to continue to work
       
   125   // correctly right to the very end of the process life.
       
   126   class CritSect {
       
   127     critsect_t _cs;
       
   128   public:
       
   129     CritSect()        { init_critsect(&_cs); }
       
   130     //~CritSect()       { free_critsect(&_cs); }
       
   131     void enter()      { enter_critsect(&_cs); }
       
   132     void leave()      { leave_critsect(&_cs); }
       
   133   };
       
   134 
       
   135   class AutoCritSect {
       
   136     CritSect* const _pcsobj;
       
   137   public:
       
   138     AutoCritSect(CritSect* pcsobj)
       
   139       : _pcsobj(pcsobj)
       
   140     {
       
   141       _pcsobj->enter();
       
   142     }
       
   143     ~AutoCritSect() {
       
   144       _pcsobj->leave();
       
   145     }
       
   146   };
       
   147 
       
   148 }
       
   149 
       
   150 #endif // OS_AIX_VM_PORTING_AIX_HPP