< prev index next >

src/os/aix/vm/porting_aix.hpp

Print this page
rev 7960 : 8075506: aix: improve handling of native memory
   1 /*
   2  * Copyright 2012, 2013 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 #include <stddef.h>
  26 







  27 // 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
  29 // that header is included inside the os class definition, hence all
  30 // its content is part of the os class.
  31 
  32 // Aix' own version of dladdr().
  33 // This function tries to mimick dladdr(3) on Linux
  34 // (see http://linux.die.net/man/3/dladdr)
  35 // dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
  36 //
  37 // Differences between AIX dladdr and Linux dladdr:
  38 //
  39 // 1) Dl_info.dli_fbase: can never work, is disabled.
  40 //   A loaded image on AIX is divided in multiple segments, at least two
  41 //   (text and data) but potentially also far more. This is because the loader may
  42 //   load each member into an own segment, as for instance happens with the libC.a
  43 // 2) Dl_info.dli_sname: This only works for code symbols (functions); for data, a
  44 //   zero-length string is returned ("").
  45 // 3) Dl_info.dli_saddr: For code, this will return the entry point of the function,
  46 //   not the function descriptor.


  62 // The semantics in this file are thus that codeptr_t is a *real code ptr*.
  63 // This means that any function taking codeptr_t as arguments will assume
  64 // a real codeptr and won't handle function descriptors (eg getFuncName),
  65 // whereas functions taking address as args will deal with function
  66 // descriptors (eg os::dll_address_to_library_name).
  67 typedef unsigned int* codeptr_t;
  68 
  69 // helper function - given a program counter, tries to locate the traceback table and
  70 // returns info from it (like, most importantly, function name, displacement of the
  71 // pc inside the function, and the traceback table itself.
  72 #ifdef __cplusplus
  73 extern "C"
  74 #endif
  75 int getFuncName(
  76       codeptr_t pc,                    // [in] program counter
  77       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
  78       int* p_displacement,             // [out] optional: displacement
  79       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
  81     );



























































   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 #ifndef OS_AIX_VM_PORTING_AIX_HPP
  26 #define OS_AIX_VM_PORTING_AIX_HPP
  27 
  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 
  37 // 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
  39 // that header is included inside the os class definition, hence all
  40 // its content is part of the os class.
  41 
  42 // Aix' own version of dladdr().
  43 // This function tries to mimick dladdr(3) on Linux
  44 // (see http://linux.die.net/man/3/dladdr)
  45 // dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
  46 //
  47 // Differences between AIX dladdr and Linux dladdr:
  48 //
  49 // 1) Dl_info.dli_fbase: can never work, is disabled.
  50 //   A loaded image on AIX is divided in multiple segments, at least two
  51 //   (text and data) but potentially also far more. This is because the loader may
  52 //   load each member into an own segment, as for instance happens with the libC.a
  53 // 2) Dl_info.dli_sname: This only works for code symbols (functions); for data, a
  54 //   zero-length string is returned ("").
  55 // 3) Dl_info.dli_saddr: For code, this will return the entry point of the function,
  56 //   not the function descriptor.


  72 // The semantics in this file are thus that codeptr_t is a *real code ptr*.
  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 
  79 // 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
  81 // pc inside the function, and the traceback table itself.
  82 #ifdef __cplusplus
  83 extern "C"
  84 #endif
  85 int getFuncName(
  86       codeptr_t pc,                    // [in] program counter
  87       char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
  88       int* p_displacement,             // [out] optional: displacement
  89       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
  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
< prev index next >