annotate src/share/vm/runtime/rtmLocking.hpp @ 18096:ca6d25be853b jdk8u25-b13

8044269: Analysis of archive files. Summary: Add checksum verification. Reviewed-by: iklam, dholmes, mschoene
author jiangli
date Tue, 12 Aug 2014 17:46:16 -0400
parents 606acabe7b5c
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17780
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
1 /*
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
4 *
606acabe7b5c 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
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
7 * published by the Free Software Foundation.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
8 *
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
13 * accompanied this code).
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
14 *
606acabe7b5c 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
606acabe7b5c 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,
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
18 *
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
21 * questions.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
22 *
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
23 */
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
24
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
25 #ifndef SHARE_VM_RUNTIME_RTMLOCKING_HPP
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
26 #define SHARE_VM_RUNTIME_RTMLOCKING_HPP
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
27
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
28 // Generate RTM (Restricted Transactional Memory) locking code for all inflated
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
30 // handler.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
31 //
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
33 // as specified by "RTMRetryCount" option. The locks which abort too often
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
34 // can be auto tuned or manually tuned.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
35 //
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
37 // ratio calculation for each lock. The abort ratio will be calculated after
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
38 // "RTMAbortThreshold" number of aborts is reached. The formulas are:
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
39 //
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
40 // Aborted transactions = abort_count * 100
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
41 // All transactions = total_count * RTMTotalCountIncrRate
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
42 //
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
43 // Aborted transactions >= All transactions * RTMAbortRatio
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
44 //
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
45 // If "UseRTMDeopt" is on and the aborts ratio reaches "RTMAbortRatio"
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
46 // the method containing the lock will be deoptimized and recompiled with
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
48 // "RTMLockingThreshold" locks are attempted, then the method will be deoptimized
606acabe7b5c 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.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
50 // The abort ratio calculation can be delayed by specifying flag
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
51 // -XX:RTMLockingCalculationDelay in millisecond.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
52 //
606acabe7b5c 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
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
54 // to the user on some JVM option like "PrintPreciseRTMLockingStatistics".
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
55 // Based on the abort statistics users can create a .hotspot_compiler file
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
56 // or use -XX:CompileCommand=option,class::method,NoRTMLockEliding
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
57 // to specify for which methods to disable RTM locking.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
58 //
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
59 // When UseRTMForStackLocks option is enabled along with UseRTMLocking option,
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
60 // the RTM locking code is generated for stack locks too.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
61 // The retries, auto-tuning support and rtm locking statistics are all
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
62 // supported for stack locks just like inflated locks.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
63
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
64 // RTM locking counters
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
65 class RTMLockingCounters VALUE_OBJ_CLASS_SPEC {
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
66 private:
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
67 uintx _total_count; // Total RTM locks count
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
68 uintx _abort_count; // Total aborts count
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
69
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
70 public:
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
71 enum { ABORT_STATUS_LIMIT = 6 };
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
72 // Counters per RTM Abort Status. Incremented with +PrintPreciseRTMLockingStatistics
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
73 // RTM uses the EAX register to communicate abort status to software.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
74 // Following an RTM abort the EAX register has the following definition.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
75 //
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
76 // EAX register bit position Meaning
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
77 // 0 Set if abort caused by XABORT instruction.
606acabe7b5c 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.
606acabe7b5c 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.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
80 // 3 Set if an internal buffer overflowed.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
81 // 4 Set if a debug breakpoint was hit.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
82 // 5 Set if an abort occurred during execution of a nested transaction.
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
83 private:
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
84 uintx _abortX_count[ABORT_STATUS_LIMIT];
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
85
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
86 public:
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
87 static uintx _calculation_flag;
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
88 static uintx* rtm_calculation_flag_addr() { return &_calculation_flag; }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
89
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
90 static void init();
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
91
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
92 RTMLockingCounters() : _total_count(0), _abort_count(0) {
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
93 for (int i = 0; i < ABORT_STATUS_LIMIT; i++) {
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
94 _abortX_count[i] = 0;
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
95 }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
96 }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
97
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
98 uintx* total_count_addr() { return &_total_count; }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
99 uintx* abort_count_addr() { return &_abort_count; }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
100 uintx* abortX_count_addr() { return &_abortX_count[0]; }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
101
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
102 static int total_count_offset() { return (int)offset_of(RTMLockingCounters, _total_count); }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
103 static int abort_count_offset() { return (int)offset_of(RTMLockingCounters, _abort_count); }
606acabe7b5c 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]); }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
105
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
106
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
107 bool nonzero() { return (_abort_count + _total_count) > 0; }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
108
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
109 void print_on(outputStream* st);
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
110 void print() { print_on(tty); }
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
111 };
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
112
606acabe7b5c 8031320: Use Intel RTM instructions for locks
kvn
parents:
diff changeset
113 #endif // SHARE_VM_RUNTIME_RTMLOCKING_HPP