hotspot/src/share/vm/runtime/rtmLocking.hpp
author ddmitriev
Fri, 11 Mar 2016 15:34:48 +0300
changeset 37075 65bfef79cfb9
parent 23491 f690330b10b9
permissions -rw-r--r--
8151304: Remove unused develop options(ClearInterpreterLocals and others) Reviewed-by: coleenp, jwilhelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23491
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     1
/*
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     4
 *
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     8
 *
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    13
 * accompanied this code).
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    14
 *
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    18
 *
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    21
 * questions.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    22
 *
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    23
 */
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    24
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    25
#ifndef SHARE_VM_RUNTIME_RTMLOCKING_HPP
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    26
#define SHARE_VM_RUNTIME_RTMLOCKING_HPP
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    27
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    28
// Generate RTM (Restricted Transactional Memory) locking code for all inflated
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    29
// locks when "UseRTMLocking" option is on with normal locking mechanism as fall back
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    30
// handler.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    31
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    32
// On abort/lock busy the lock will be retried a fixed number of times under RTM
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    33
// as specified by "RTMRetryCount" option. The locks which abort too often
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    34
// can be auto tuned or manually tuned.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    35
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    36
// Auto-tuning can be done on an option like UseRTMDeopt and it will need abort
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    37
// ratio calculation for each lock. The abort ratio will be calculated after
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    38
// "RTMAbortThreshold" number of aborts is reached. The formulas are:
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    39
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    40
//     Aborted transactions = abort_count * 100
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    41
//     All transactions = total_count *  RTMTotalCountIncrRate
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    42
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    43
//     Aborted transactions >= All transactions * RTMAbortRatio
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    44
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    45
// If "UseRTMDeopt" is on and the aborts ratio reaches "RTMAbortRatio"
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    46
// the method containing the lock will be deoptimized and recompiled with
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    47
// all locks as normal locks. If the abort ratio continues to remain low after
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    48
// "RTMLockingThreshold" locks are attempted, then the method will be deoptimized
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    49
// and recompiled with all locks as RTM locks without abort ratio calculation code.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    50
// The abort ratio calculation can be delayed by specifying flag
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    51
// -XX:RTMLockingCalculationDelay in millisecond.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    52
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    53
// For manual tuning the abort statistics for each lock needs to be provided
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    54
// to the user on some JVM option like "PrintPreciseRTMLockingStatistics".
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    55
// Based on the abort statistics users can create a .hotspot_compiler file
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    56
// or use -XX:CompileCommand=option,class::method,NoRTMLockEliding
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    57
// to specify for which methods to disable RTM locking.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    58
//
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    59
// When UseRTMForStackLocks option is enabled along with UseRTMLocking option,
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    60
// the RTM locking code is generated for stack locks too.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    61
// The retries, auto-tuning support and rtm locking statistics are all
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    62
// supported for stack locks just like inflated locks.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    63
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    64
// RTM locking counters
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    65
class RTMLockingCounters VALUE_OBJ_CLASS_SPEC {
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    66
 private:
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    67
  uintx _total_count; // Total RTM locks count
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    68
  uintx _abort_count; // Total aborts count
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    69
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    70
 public:
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    71
  enum { ABORT_STATUS_LIMIT = 6 };
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    72
  // Counters per RTM Abort Status. Incremented with +PrintPreciseRTMLockingStatistics
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    73
  // RTM uses the EAX register to communicate abort status to software.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    74
  // Following an RTM abort the EAX register has the following definition.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    75
  //
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    76
  //   EAX register bit position   Meaning
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    77
  //     0     Set if abort caused by XABORT instruction.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    78
  //     1     If set, the transaction may succeed on a retry. This bit is always clear if bit 0 is set.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    79
  //     2     Set if another logical processor conflicted with a memory address that was part of the transaction that aborted.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    80
  //     3     Set if an internal buffer overflowed.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    81
  //     4     Set if a debug breakpoint was hit.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    82
  //     5     Set if an abort occurred during execution of a nested transaction.
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    83
 private:
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    84
  uintx _abortX_count[ABORT_STATUS_LIMIT];
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    85
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    86
 public:
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    87
  static uintx _calculation_flag;
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    88
  static uintx* rtm_calculation_flag_addr() { return &_calculation_flag; }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    89
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    90
  static void init();
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    91
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    92
  RTMLockingCounters() : _total_count(0), _abort_count(0) {
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    93
    for (int i = 0; i < ABORT_STATUS_LIMIT; i++) {
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    94
      _abortX_count[i] = 0;
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    95
    }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    96
  }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    97
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    98
  uintx* total_count_addr()               { return &_total_count; }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
    99
  uintx* abort_count_addr()               { return &_abort_count; }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   100
  uintx* abortX_count_addr()              { return &_abortX_count[0]; }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   101
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   102
  static int total_count_offset()         { return (int)offset_of(RTMLockingCounters, _total_count); }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   103
  static int abort_count_offset()         { return (int)offset_of(RTMLockingCounters, _abort_count); }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   104
  static int abortX_count_offset()        { return (int)offset_of(RTMLockingCounters, _abortX_count[0]); }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   105
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   106
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   107
  bool nonzero() {  return (_abort_count + _total_count) > 0; }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   108
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   109
  void print_on(outputStream* st);
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   110
  void print() { print_on(tty); }
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   111
};
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   112
f690330b10b9 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
   113
#endif // SHARE_VM_RUNTIME_RTMLOCKING_HPP