hotspot/src/os/aix/vm/porting_aix.hpp
changeset 33743 e21d93a9e062
parent 31352 a6ab7217b5cc
child 35594 cc13089c6327
child 35515 179755aaa4e0
equal deleted inserted replaced
33742:cff2b8a9e2c5 33743:e21d93a9e062
    24 
    24 
    25 #ifndef OS_AIX_VM_PORTING_AIX_HPP
    25 #ifndef OS_AIX_VM_PORTING_AIX_HPP
    26 #define OS_AIX_VM_PORTING_AIX_HPP
    26 #define OS_AIX_VM_PORTING_AIX_HPP
    27 
    27 
    28 #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 }
       
    36 
    29 
    37 // Header file to contain porting-relevant code which does not have a
    30 // Header file to contain porting-relevant code which does not have a
    38 // home anywhere else and which can not go into os_<platform>.h because
    31 // home anywhere else and which can not go into os_<platform>.h because
    39 // that header is included inside the os class definition, hence all
    32 // that header is included inside the os class definition, hence all
    40 // its content is part of the os class.
    33 // its content is part of the os class.
    66 #ifdef __cplusplus
    59 #ifdef __cplusplus
    67 extern "C"
    60 extern "C"
    68 #endif
    61 #endif
    69 int dladdr(void *addr, Dl_info *info);
    62 int dladdr(void *addr, Dl_info *info);
    70 
    63 
       
    64 typedef unsigned int* codeptr_t;
    71 
    65 
    72 // The semantics in this file are thus that codeptr_t is a *real code ptr*.
    66 struct tbtable;
    73 // This means that any function taking codeptr_t as arguments will assume
       
    74 // a real codeptr and won't handle function descriptors (eg getFuncName),
       
    75 // whereas functions taking address as args will deal with function
       
    76 // descriptors (eg os::dll_address_to_library_name).
       
    77 typedef unsigned int* codeptr_t;
       
    78 
    67 
    79 // helper function - given a program counter, tries to locate the traceback table and
    68 // helper function - given a program counter, tries to locate the traceback table and
    80 // returns info from it (like, most importantly, function name, displacement of the
    69 // returns info from it (like, most importantly, function name, displacement of the
    81 // pc inside the function, and the traceback table itself.
    70 // pc inside the function, and the traceback table itself.
    82 #ifdef __cplusplus
    71 #ifdef __cplusplus
    85 int getFuncName(
    74 int getFuncName(
    86       codeptr_t pc,                    // [in] program counter
    75       codeptr_t pc,                    // [in] program counter
    87       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
    76       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
    88       int* p_displacement,             // [out] optional: displacement
    77       int* p_displacement,             // [out] optional: displacement
    89       const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
    78       const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
    90       char* p_errmsg, size_t errmsglen,// [out] optional: user provided buffer for error messages
    79       char* p_errmsg, size_t errmsglen, // [out] optional: user provided buffer for error messages
    91       bool demangle = true             // [in] whether to demangle the name
    80       bool demangle                    // [in] whether to demangle the name
    92     );
    81     );
    93 
    82 
    94 // -------------------------------------------------------------------------
    83 #endif // OS_AIX_VM_PORTING_AIX_HPP
    95 
    84 
    96 // A simple critical section which shall be based upon OS critical
       
    97 // sections (CRITICAL_SECTION resp. Posix Mutex) and nothing else.
       
    98 
       
    99 #include <pthread.h>
       
   100 
       
   101 namespace MiscUtils {
       
   102   typedef pthread_mutex_t critsect_t;
       
   103 
       
   104   inline void init_critsect(MiscUtils::critsect_t* cs) {
       
   105     pthread_mutex_init(cs, NULL);
       
   106   }
       
   107   inline void free_critsect(MiscUtils::critsect_t* cs) {
       
   108     pthread_mutex_destroy(cs);
       
   109   }
       
   110   inline void enter_critsect(MiscUtils::critsect_t* cs) {
       
   111     pthread_mutex_lock(cs);
       
   112   }
       
   113   inline void leave_critsect(MiscUtils::critsect_t* cs) {
       
   114     pthread_mutex_unlock(cs);
       
   115   }
       
   116 
       
   117   // Need to wrap this in an object because we need to dynamically initialize
       
   118   // critical section (because of windows, where there is no way to initialize
       
   119   // a CRITICAL_SECTION statically. On Unix, we could use
       
   120   // PTHREAD_MUTEX_INITIALIZER)
       
   121 
       
   122   // Note: The critical section does NOT get cleaned up in the destructor. That is
       
   123   // by design: the CritSect class is only ever used as global objects whose
       
   124   // lifetime spans the whole VM life; in that context we don't want the lock to
       
   125   // be cleaned up when global C++ objects are destroyed, but to continue to work
       
   126   // correctly right to the very end of the process life.
       
   127   class CritSect {
       
   128     critsect_t _cs;
       
   129   public:
       
   130     CritSect()        { init_critsect(&_cs); }
       
   131     //~CritSect()       { free_critsect(&_cs); }
       
   132     void enter()      { enter_critsect(&_cs); }
       
   133     void leave()      { leave_critsect(&_cs); }
       
   134   };
       
   135 
       
   136   class AutoCritSect {
       
   137     CritSect* const _pcsobj;
       
   138   public:
       
   139     AutoCritSect(CritSect* pcsobj)
       
   140       : _pcsobj(pcsobj)
       
   141     {
       
   142       _pcsobj->enter();
       
   143     }
       
   144     ~AutoCritSect() {
       
   145       _pcsobj->leave();
       
   146     }
       
   147   };
       
   148 
       
   149 }
       
   150 
       
   151 #endif // OS_AIX_VM_PORTING_AIX_HPP