hotspot/src/os/aix/vm/porting_aix.hpp
author goetz
Thu, 19 Mar 2015 14:30:52 +0100
changeset 30198 ec621727bd41
parent 22831 1e2ba1d62103
child 31352 a6ab7217b5cc
permissions -rw-r--r--
8075505: aix: improve handling of native memory Reviewed-by: kvn, stuefe Contributed-by: thomas.stuefe@sap.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22831
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     1
/*
30198
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
     2
 * Copyright 2012, 2015 SAP AG. All rights reserved.
22831
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     4
 *
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     8
 *
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    13
 * accompanied this code).
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    14
 *
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    18
 *
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    21
 * questions.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    22
 *
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    23
 */
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    24
30198
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    25
#ifndef OS_AIX_VM_PORTING_AIX_HPP
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    26
#define OS_AIX_VM_PORTING_AIX_HPP
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    27
22831
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    28
#include <stddef.h>
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    29
30198
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    30
// PPC port only:
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    31
#define assert0(b) assert( (b), "" )
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    32
#define guarantee0(b) assert( (b), "" )
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    33
template <class T1, class T2> bool is_aligned_to(T1 what, T2 alignment) {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    34
  return  ( ((uintx)(what)) & (((uintx)(alignment)) - 1) ) == 0 ? true : false;
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    35
}
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    36
22831
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    37
// Header file to contain porting-relevant code which does not have a
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    38
// home anywhere else and which can not go into os_<platform>.h because
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    39
// that header is included inside the os class definition, hence all
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    40
// its content is part of the os class.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    41
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    42
// Aix' own version of dladdr().
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    43
// This function tries to mimick dladdr(3) on Linux
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    44
// (see http://linux.die.net/man/3/dladdr)
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    45
// dladdr(3) is not POSIX but a GNU extension, and is not available on AIX.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    46
//
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    47
// Differences between AIX dladdr and Linux dladdr:
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    48
//
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    49
// 1) Dl_info.dli_fbase: can never work, is disabled.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    50
//   A loaded image on AIX is divided in multiple segments, at least two
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    51
//   (text and data) but potentially also far more. This is because the loader may
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    52
//   load each member into an own segment, as for instance happens with the libC.a
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    53
// 2) Dl_info.dli_sname: This only works for code symbols (functions); for data, a
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    54
//   zero-length string is returned ("").
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    55
// 3) Dl_info.dli_saddr: For code, this will return the entry point of the function,
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    56
//   not the function descriptor.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    57
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    58
typedef struct {
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    59
  const char *dli_fname; // file path of loaded library
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    60
  // void *dli_fbase;
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    61
  const char *dli_sname; // symbol name; "" if not known
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    62
  void *dli_saddr;       // address of *entry* of function; not function descriptor;
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    63
} Dl_info;
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    64
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    65
// Note: we export this to use it inside J2se too
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    66
#ifdef __cplusplus
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    67
extern "C"
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    68
#endif
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    69
int dladdr(void *addr, Dl_info *info);
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    70
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    71
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    72
// The semantics in this file are thus that codeptr_t is a *real code ptr*.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    73
// This means that any function taking codeptr_t as arguments will assume
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    74
// a real codeptr and won't handle function descriptors (eg getFuncName),
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    75
// whereas functions taking address as args will deal with function
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    76
// descriptors (eg os::dll_address_to_library_name).
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    77
typedef unsigned int* codeptr_t;
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    78
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    79
// helper function - given a program counter, tries to locate the traceback table and
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    80
// returns info from it (like, most importantly, function name, displacement of the
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    81
// pc inside the function, and the traceback table itself.
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    82
#ifdef __cplusplus
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    83
extern "C"
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    84
#endif
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    85
int getFuncName(
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    86
      codeptr_t pc,                    // [in] program counter
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    87
      char* p_name, size_t namelen,    // [out] optional: user provided buffer for the function name
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    88
      int* p_displacement,             // [out] optional: displacement
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    89
      const struct tbtable** p_tb,     // [out] optional: ptr to traceback table to get further information
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    90
      char* p_errmsg, size_t errmsglen // [out] optional: user provided buffer for error messages
1e2ba1d62103 8023038: PPC64 (part 15): Platform files for AIX/PPC64 support
simonis
parents:
diff changeset
    91
    );
30198
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    92
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    93
// -------------------------------------------------------------------------
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    94
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    95
// A simple critical section which shall be based upon OS critical
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    96
// sections (CRITICAL_SECTION resp. Posix Mutex) and nothing else.
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    97
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    98
#include <pthread.h>
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
    99
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   100
namespace MiscUtils {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   101
  typedef pthread_mutex_t critsect_t;
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   102
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   103
  inline void init_critsect(MiscUtils::critsect_t* cs) {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   104
    pthread_mutex_init(cs, NULL);
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   105
  }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   106
  inline void free_critsect(MiscUtils::critsect_t* cs) {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   107
    pthread_mutex_destroy(cs);
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   108
  }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   109
  inline void enter_critsect(MiscUtils::critsect_t* cs) {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   110
    pthread_mutex_lock(cs);
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   111
  }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   112
  inline void leave_critsect(MiscUtils::critsect_t* cs) {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   113
    pthread_mutex_unlock(cs);
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   114
  }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   115
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   116
  // Need to wrap this in an object because we need to dynamically initialize
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   117
  // critical section (because of windows, where there is no way to initialize
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   118
  // a CRITICAL_SECTION statically. On Unix, we could use
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   119
  // PTHREAD_MUTEX_INITIALIZER)
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   120
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   121
  // Note: The critical section does NOT get cleaned up in the destructor. That is
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   122
  // by design: the CritSect class is only ever used as global objects whose
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   123
  // lifetime spans the whole VM life; in that context we don't want the lock to
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   124
  // be cleaned up when global C++ objects are destroyed, but to continue to work
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   125
  // correctly right to the very end of the process life.
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   126
  class CritSect {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   127
    critsect_t _cs;
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   128
  public:
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   129
    CritSect()        { init_critsect(&_cs); }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   130
    //~CritSect()       { free_critsect(&_cs); }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   131
    void enter()      { enter_critsect(&_cs); }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   132
    void leave()      { leave_critsect(&_cs); }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   133
  };
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   134
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   135
  class AutoCritSect {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   136
    CritSect* const _pcsobj;
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   137
  public:
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   138
    AutoCritSect(CritSect* pcsobj)
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   139
      : _pcsobj(pcsobj)
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   140
    {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   141
      _pcsobj->enter();
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   142
    }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   143
    ~AutoCritSect() {
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   144
      _pcsobj->leave();
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   145
    }
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   146
  };
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   147
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   148
}
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   149
ec621727bd41 8075505: aix: improve handling of native memory
goetz
parents: 22831
diff changeset
   150
#endif // OS_AIX_VM_PORTING_AIX_HPP