src/hotspot/os/aix/libodm_aix.hpp
author serb
Sun, 24 Jun 2018 16:35:21 -0700
changeset 50834 9cf279436b9d
parent 47216 71c04702a3d5
child 53244 9807daeb47c4
permissions -rw-r--r--
8205153: Delete "standard instructions" machinery in the open automated tests Reviewed-by: prr
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     1
/*
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     2
 * Copyright (c) 2015, 2015, Oracle and/or its affiliates. All rights reserved.
35594
cc13089c6327 8147937: Adapt SAP copyrights to new company name.
goetz
parents: 35063
diff changeset
     3
 * Copyright (c) 2015, 2015 SAP SE. All rights reserved.
35063
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     5
 *
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     6
 * This code is free software; you can redistribute it and/or modify it
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     7
 * under the terms of the GNU General Public License version 2 only, as
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     8
 * published by the Free Software Foundation.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
     9
 *
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    10
 * This code is distributed in the hope that it will be useful, but WITHOUT
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    13
 * version 2 for more details (a copy is included in the LICENSE file that
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    14
 * accompanied this code).
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    15
 *
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    16
 * You should have received a copy of the GNU General Public License version
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    17
 * 2 along with this work; if not, write to the Free Software Foundation,
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    19
 *
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    21
 * or visit www.oracle.com if you need additional information or have any
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    22
 * questions.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    23
 *
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    24
 */
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    25
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    26
// Encapsulates the libodm library and provides more convenient interfaces.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    27
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    28
#ifndef OS_AIX_VM_LIBODM_AIX_HPP
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    29
#define OS_AIX_VM_LIBODM_AIX_HPP
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    30
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    31
#include <odmi.h>
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    32
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    33
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    34
// The purpose of this code is to dynamically load the libodm library
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    35
// instead of statically linking against it. The library is AIX-specific.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    36
// It only exists on AIX, not on PASE. In order to share binaries
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    37
// between AIX and PASE, we can't directly link against it.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    38
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    39
typedef int          (*fun_odm_initialize )(void);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    40
typedef char*        (*fun_odm_set_path   )(char*);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    41
typedef CLASS_SYMBOL (*fun_odm_mount_class)(char*);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    42
typedef void*        (*fun_odm_get_obj    )(CLASS_SYMBOL, char*, void*, int);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    43
typedef int          (*fun_odm_terminate  )(void);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    44
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    45
class dynamicOdm {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    46
  void *_libhandle;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    47
 protected:
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    48
  fun_odm_initialize  _odm_initialize;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    49
  fun_odm_set_path    _odm_set_path;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    50
  fun_odm_mount_class _odm_mount_class;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    51
  fun_odm_get_obj     _odm_get_obj;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    52
  fun_odm_terminate   _odm_terminate;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    53
 public:
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    54
  dynamicOdm();
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    55
  ~dynamicOdm();
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    56
  bool odm_loaded() {return _libhandle != NULL; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    57
};
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    58
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    59
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    60
// We provide a more convenient interface for odm access and
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    61
// especially to determine the exact AIX kernel version.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    62
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    63
class odmWrapper : private dynamicOdm {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    64
  CLASS_SYMBOL _odm_class;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    65
  char *_data;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    66
  bool _initialized;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    67
  void clean_data();
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    68
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    69
 public:
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    70
  // Make sure everything gets initialized and cleaned up properly.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    71
  explicit odmWrapper(char* odm_class_name, char* odm_path = NULL) : _odm_class((CLASS_SYMBOL)-1),
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    72
                                                                     _data(NULL), _initialized(false) {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    73
    if (!odm_loaded()) { return; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    74
    _initialized = ((*_odm_initialize)() != -1);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    75
    if (_initialized) {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    76
      if (odm_path) { (*_odm_set_path)(odm_path); }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    77
      _odm_class = (*_odm_mount_class)(odm_class_name);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    78
    }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    79
  }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    80
  ~odmWrapper() {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    81
    if (_initialized) { (*_odm_terminate)(); clean_data(); }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    82
  }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    83
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    84
  CLASS_SYMBOL odm_class() { return _odm_class; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    85
  bool has_class() { return odm_class() != (CLASS_SYMBOL)-1; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    86
  int class_offset(char *field, bool is_aix_5);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    87
  char* data() { return _data; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    88
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    89
  char* retrieve_obj(char* name = NULL) {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    90
    clean_data();
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    91
    char *cnp = (char*)(void*)(*_odm_get_obj)(odm_class(), name, NULL, (name == NULL) ? ODM_NEXT : ODM_FIRST);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    92
    if (cnp != (char*)-1) { _data = cnp; }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    93
    return data();
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    94
  }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    95
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    96
  int read_short(int offs) {
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    97
    short *addr = (short*)(data() + offs);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    98
    return *addr;
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
    99
  }
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   100
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   101
  // Determine the exact AIX kernel version as 4 byte value.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   102
  // The high order 2 bytes must be initialized already. They can be determined by uname.
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   103
  static void determine_os_kernel_version(uint32_t* p_ver);
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   104
};
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   105
cb24277be2e7 8144847: PPC64: Update Transactional Memory and Atomic::cmpxchg code
mdoerr
parents:
diff changeset
   106
#endif // OS_AIX_VM_LIBODM_AIX_HPP