annotate graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/replacements/MonitorSnippets.java @ 9015:92d2bedb5dfc

Change of Snippet template and instantiation process
author Christian Wimmer <christian.wimmer@oracle.com>
date Thu, 11 Apr 2013 14:22:03 -0700
parents ce5750014c3d
children 5e1465ec46d6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
23 package com.oracle.graal.hotspot.replacements;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import static com.oracle.graal.hotspot.nodes.BeginLockScopeNode.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import static com.oracle.graal.hotspot.nodes.DirectCompareAndSwapNode.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27 import static com.oracle.graal.hotspot.nodes.EndLockScopeNode.*;
6453
3bba61323b38 added VMErrorNode intrinsic to support handling fatal errors in snippets
Doug Simon <doug.simon@oracle.com>
parents: 6451
diff changeset
28 import static com.oracle.graal.hotspot.nodes.VMErrorNode.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
29 import static com.oracle.graal.hotspot.replacements.HotSpotSnippetUtils.*;
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
30 import static com.oracle.graal.replacements.SnippetTemplate.*;
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
31 import static com.oracle.graal.replacements.nodes.BranchProbabilityNode.*;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import java.util.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.api.code.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
36 import com.oracle.graal.api.meta.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.graph.*;
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
38 import com.oracle.graal.graph.Node.NodeIntrinsic;
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
39 import com.oracle.graal.graph.iterators.*;
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
40 import com.oracle.graal.hotspot.meta.*;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 import com.oracle.graal.hotspot.nodes.*;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 import com.oracle.graal.nodes.*;
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
43 import com.oracle.graal.nodes.extended.*;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 import com.oracle.graal.nodes.java.*;
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
45 import com.oracle.graal.nodes.java.MethodCallTargetNode.InvokeKind;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 import com.oracle.graal.nodes.spi.*;
6526
ee651c726397 split phases out of graal.phases project into graal.phases.common project
Doug Simon <doug.simon@oracle.com>
parents: 6525
diff changeset
47 import com.oracle.graal.phases.common.*;
8415
2361bf148c06 rename packages: *snippets* -> *replacements*
Doug Simon <doug.simon@oracle.com>
parents: 8413
diff changeset
48 import com.oracle.graal.replacements.*;
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
49 import com.oracle.graal.replacements.Snippet.ConstantParameter;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
50 import com.oracle.graal.replacements.SnippetTemplate.AbstractTemplates;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
51 import com.oracle.graal.replacements.SnippetTemplate.Arguments;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
52 import com.oracle.graal.replacements.SnippetTemplate.SnippetInfo;
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
53 import com.oracle.graal.word.*;
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 /**
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 * Snippets used for implementing the monitorenter and monitorexit instructions.
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
57 *
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
58 * The locking algorithm used is described in the paper <a
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
59 * href="http://dl.acm.org/citation.cfm?id=1167515.1167496"> Eliminating synchronization-related
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
60 * atomic operations with biased locking and bulk rebiasing</a> by Kenneth Russell and David
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
61 * Detlefs.
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 */
8413
d9347ee39fbe rename: SnippetsInterface -> Snippets
Doug Simon <doug.simon@oracle.com>
parents: 7868
diff changeset
63 public class MonitorSnippets implements Snippets {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
65 /**
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
66 * Monitor operations on objects whose type contains this substring will be traced.
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
67 */
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
68 private static final String TRACE_TYPE_FILTER = System.getProperty("graal.monitors.trace.typeFilter");
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
70 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
71 * Monitor operations in methods whose fully qualified name contains this substring will be
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
72 * traced.
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
73 */
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
74 private static final String TRACE_METHOD_FILTER = System.getProperty("graal.monitors.trace.methodFilter");
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
75
6453
3bba61323b38 added VMErrorNode intrinsic to support handling fatal errors in snippets
Doug Simon <doug.simon@oracle.com>
parents: 6451
diff changeset
76 public static final boolean CHECK_BALANCED_MONITORS = Boolean.getBoolean("graal.monitors.checkBalanced");
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
77
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
79 public static void monitorenter(Object object, @ConstantParameter boolean checkNull, @ConstantParameter boolean trace) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 verifyOop(object);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81
6716
536dbb4dd212 removed null check from UnsafeLoadNode, UnsafeStoreNode, ReadNode and WriteNode as it violates the sun.misc.Unsafe API
Doug Simon <doug.simon@oracle.com>
parents: 6673
diff changeset
82 if (checkNull && object == null) {
536dbb4dd212 removed null check from UnsafeLoadNode, UnsafeStoreNode, ReadNode and WriteNode as it violates the sun.misc.Unsafe API
Doug Simon <doug.simon@oracle.com>
parents: 6673
diff changeset
83 DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException);
536dbb4dd212 removed null check from UnsafeLoadNode, UnsafeStoreNode, ReadNode and WriteNode as it violates the sun.misc.Unsafe API
Doug Simon <doug.simon@oracle.com>
parents: 6673
diff changeset
84 }
536dbb4dd212 removed null check from UnsafeLoadNode, UnsafeStoreNode, ReadNode and WriteNode as it violates the sun.misc.Unsafe API
Doug Simon <doug.simon@oracle.com>
parents: 6673
diff changeset
85
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86 // Load the mark word - this includes a null-check on object
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6389
diff changeset
87 final Word mark = loadWordFromObject(object, markOffset());
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
89 final Word lock = beginLockScope(false);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
91 trace(trace, " object: 0x%016lx\n", Word.fromObject(object));
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
92 trace(trace, " lock: 0x%016lx\n", lock);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
93 trace(trace, " mark: 0x%016lx\n", mark);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
94
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
95 incCounter();
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
96
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 if (useBiasedLocking()) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 // See whether the lock is currently biased toward our thread and
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99 // whether the epoch is still valid.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 // Note that the runtime guarantees sufficient alignment of JavaThread
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 // pointers to allow age to be placed into low bits.
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
102 final Word biasableLockBits = mark.and(biasedLockMaskInPlace());
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 // First check to see whether biasing is enabled for this object
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
105 if (biasableLockBits.notEqual(Word.unsigned(biasedLockPattern()))) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 // Biasing not enabled -> fall through to lightweight locking
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 } else {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
108 probability(FREQUENT_PROBABILITY);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
109 // The bias pattern is present in the object's mark word. Need to check
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
110 // whether the bias owner and the epoch are both still current.
6950
41938af2b3d8 modifications to support non-perm-gen changes in HotSpot
Doug Simon <doug.simon@oracle.com>
parents: 6673
diff changeset
111 Word hub = loadHub(object);
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
112 final Word prototypeMarkWord = hub.readWord(prototypeMarkWordOffset(), PROTOTYPE_MARK_WORD_LOCATION);
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6389
diff changeset
113 final Word thread = thread();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
114 final Word tmp = prototypeMarkWord.or(thread).xor(mark).and(~ageMaskInPlace());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
115 trace(trace, "prototypeMarkWord: 0x%016lx\n", prototypeMarkWord);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
116 trace(trace, " thread: 0x%016lx\n", thread);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
117 trace(trace, " tmp: 0x%016lx\n", tmp);
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
118 if (tmp.equal(0)) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
119 // Object is already biased to current thread -> done
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
120 probability(FREQUENT_PROBABILITY);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
121 traceObject(trace, "+lock{bias:existing}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
122 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
123 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
124
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
125 // At this point we know that the mark word has the bias pattern and
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
126 // that we are not the bias owner in the current epoch. We need to
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
127 // figure out more details about the state of the mark word in order to
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
128 // know what operations can be legally performed on the object's
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
129 // mark word.
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
130
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
131 // If the low three bits in the xor result aren't clear, that means
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
132 // the prototype header is no longer biasable and we have to revoke
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
133 // the bias on this object.
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
134 if (tmp.and(biasedLockMaskInPlace()).equal(0)) {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
135 probability(FREQUENT_PROBABILITY);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
136 // Biasing is still enabled for object's type. See whether the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
137 // epoch of the current bias is still valid, meaning that the epoch
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
138 // bits of the mark word are equal to the epoch bits of the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
139 // prototype mark word. (Note that the prototype mark word's epoch bits
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
140 // only change at a safepoint.) If not, attempt to rebias the object
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
141 // toward the current thread. Note that we must be absolutely sure
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
142 // that the current epoch is invalid in order to do this because
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
143 // otherwise the manipulations it performs on the mark word are
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
144 // illegal.
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
145 if (tmp.and(epochMaskInPlace()).equal(0)) {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
146 probability(FREQUENT_PROBABILITY);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
147 // The epoch of the current bias is still valid but we know nothing
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
148 // about the owner; it might be set or it might be clear. Try to
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
149 // acquire the bias of the object using an atomic operation. If this
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
150 // fails we will go in to the runtime to revoke the object's bias.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
151 // Note that we first construct the presumed unbiased header so we
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
152 // don't accidentally blow away another thread's valid bias.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
153 Word unbiasedMark = mark.and(biasedLockMaskInPlace() | ageMaskInPlace() | epochMaskInPlace());
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
154 Word biasedMark = unbiasedMark.or(thread);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
155 trace(trace, " unbiasedMark: 0x%016lx\n", unbiasedMark);
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
156 trace(trace, " biasedMark: 0x%016lx\n", biasedMark);
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
157 if (compareAndSwap(object, markOffset(), unbiasedMark, biasedMark, MARK_WORD_LOCATION).equal(unbiasedMark)) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
158 // Object is now biased to current thread -> done
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
159 traceObject(trace, "+lock{bias:acquired}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
160 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
161 }
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
162 // If the biasing toward our thread failed, this means that another thread
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
163 // owns the bias and we need to revoke that bias. The revocation will occur
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
164 // in the interpreter runtime.
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
165 probability(DEOPT_PATH_PROBABILITY);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
166 traceObject(trace, "+lock{stub:revoke}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
167 MonitorEnterStubCall.call(object, lock);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
168 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
169 } else {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
170 // At this point we know the epoch has expired, meaning that the
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
171 // current bias owner, if any, is actually invalid. Under these
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
172 // circumstances _only_, are we allowed to use the current mark word
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
173 // value as the comparison value when doing the CAS to acquire the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
174 // bias in the current epoch. In other words, we allow transfer of
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
175 // the bias from one thread to another directly in this situation.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
176 Word biasedMark = prototypeMarkWord.or(thread);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
177 trace(trace, " biasedMark: 0x%016lx\n", biasedMark);
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
178 if (compareAndSwap(object, markOffset(), mark, biasedMark, MARK_WORD_LOCATION).equal(mark)) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
179 // Object is now biased to current thread -> done
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
180 traceObject(trace, "+lock{bias:transfer}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
181 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
182 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
183 // If the biasing toward our thread failed, then another thread
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
184 // succeeded in biasing it toward itself and we need to revoke that
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
185 // bias. The revocation will occur in the runtime in the slow case.
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
186 probability(DEOPT_PATH_PROBABILITY);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
187 traceObject(trace, "+lock{stub:epoch-expired}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
188 MonitorEnterStubCall.call(object, lock);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
189 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
190 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
191 } else {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
192 // The prototype mark word doesn't have the bias bit set any
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
193 // more, indicating that objects of this data type are not supposed
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
194 // to be biased any more. We are going to try to reset the mark of
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
195 // this object to the prototype value and fall through to the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
196 // CAS-based locking scheme. Note that if our CAS fails, it means
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
197 // that another thread raced us for the privilege of revoking the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
198 // bias of this particular object, so it's okay to continue in the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
199 // normal locking code.
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
200 Word result = compareAndSwap(object, markOffset(), mark, prototypeMarkWord, MARK_WORD_LOCATION);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
201
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
202 // Fall through to the normal CAS-based lock, because no matter what
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
203 // the result of the above CAS, some thread must have succeeded in
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
204 // removing the bias bit from the object's header.
6424
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
205
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
206 if (ENABLE_BREAKPOINT) {
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
207 bkpt(object, mark, tmp, result);
be2f614bdeac fixed bug in MonitorSnippets and enabled them for general use
Doug Simon <doug.simon@oracle.com>
parents: 6419
diff changeset
208 }
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
209 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
210 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
211 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
212
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
213 // Create the unlocked mark word pattern
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
214 Word unlockedMark = mark.or(unlockedMask());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
215 trace(trace, " unlockedMark: 0x%016lx\n", unlockedMark);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
216
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
217 // Copy this unlocked mark word into the lock slot on the stack
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
218 lock.writeWord(lockDisplacedMarkOffset(), unlockedMark, DISPLACED_MARK_WORD_LOCATION);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
219
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
220 // Test if the object's mark word is unlocked, and if so, store the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
221 // (address of) the lock slot into the object's mark word.
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
222 Word currentMark = compareAndSwap(object, markOffset(), unlockedMark, lock, MARK_WORD_LOCATION);
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
223 if (currentMark.notEqual(unlockedMark)) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
224 trace(trace, " currentMark: 0x%016lx\n", currentMark);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
225 // The mark word in the object header was not the same.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
226 // Either the object is locked by another thread or is already locked
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
227 // by the current thread. The latter is true if the mark word
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
228 // is a stack pointer into the current thread's stack, i.e.:
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
229 //
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
230 // 1) (currentMark & aligned_mask) == 0
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
231 // 2) rsp <= currentMark
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
232 // 3) currentMark <= rsp + page_size
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
233 //
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
234 // These 3 tests can be done by evaluating the following expression:
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
235 //
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
236 // (currentMark - rsp) & (aligned_mask - page_size)
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
237 //
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
238 // assuming both the stack pointer and page_size have their least
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
239 // significant 2 bits cleared and page_size is a power of 2
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
240 final Word alignedMask = Word.unsigned(wordSize() - 1);
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6389
diff changeset
241 final Word stackPointer = stackPointer();
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
242 if (currentMark.subtract(stackPointer).and(alignedMask.subtract(pageSize())).notEqual(0)) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
243 // Most likely not a recursive lock, go into a slow runtime call
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
244 probability(DEOPT_PATH_PROBABILITY);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
245 traceObject(trace, "+lock{stub:failed-cas}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
246 MonitorEnterStubCall.call(object, lock);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
247 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
248 } else {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
249 // Recursively locked => write 0 to the lock slot
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
250 lock.writeWord(lockDisplacedMarkOffset(), Word.zero(), DISPLACED_MARK_WORD_LOCATION);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
251 traceObject(trace, "+lock{recursive}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
252 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
253 } else {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
254 traceObject(trace, "+lock{cas}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
255 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
256 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
257
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
258 @Snippet
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
259 public static void monitorenterEliminated() {
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
260 incCounter();
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
261 beginLockScope(true);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
262 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
263
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
264 /**
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
265 * Calls straight out to the monitorenter stub.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
266 */
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
267 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
268 public static void monitorenterStub(Object object, @ConstantParameter boolean checkNull, @ConstantParameter boolean trace) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
269 verifyOop(object);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
270 incCounter();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
271 if (checkNull && object == null) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
272 DeoptimizeNode.deopt(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.NullCheckException);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
273 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
274 // BeginLockScope nodes do not read from object so a use of object
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
275 // cannot float about the null check above
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
276 final Word lock = beginLockScope(false);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
277 traceObject(trace, "+lock{stub}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
278 MonitorEnterStubCall.call(object, lock);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
279 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
280
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
281 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
282 public static void monitorexit(Object object, @ConstantParameter boolean trace) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
283 trace(trace, " object: 0x%016lx\n", Word.fromObject(object));
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
284 if (useBiasedLocking()) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
285 // Check for biased locking unlock case, which is a no-op
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
286 // Note: we do not have to check the thread ID for two reasons.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
287 // First, the interpreter checks for IllegalMonitorStateException at
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
288 // a higher level. Second, if the bias was revoked while we held the
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
289 // lock, the object could not be rebiased toward another thread, so
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
290 // the bias bit would be clear.
6419
b74402a7079b fixed oopmap bug caused by unsafe mixing of word and object values
Doug Simon <doug.simon@oracle.com>
parents: 6389
diff changeset
291 final Word mark = loadWordFromObject(object, markOffset());
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
292 trace(trace, " mark: 0x%016lx\n", mark);
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
293 if (mark.and(biasedLockMaskInPlace()).equal(Word.unsigned(biasedLockPattern()))) {
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
294 probability(FREQUENT_PROBABILITY);
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
295 endLockScope();
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
296 decCounter();
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
297 traceObject(trace, "-lock{bias}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
298 return;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
299 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
300 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
301
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
302 final Word lock = CurrentLockNode.currentLock();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
303
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
304 // Load displaced mark
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
305 final Word displacedMark = lock.readWord(lockDisplacedMarkOffset(), DISPLACED_MARK_WORD_LOCATION);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
306 trace(trace, " displacedMark: 0x%016lx\n", displacedMark);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
307
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
308 if (displacedMark.equal(0)) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
309 // Recursive locking => done
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
310 traceObject(trace, "-lock{recursive}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
311 } else {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
312 verifyOop(object);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
313 // Test if object's mark word is pointing to the displaced mark word, and if so, restore
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
314 // the displaced mark in the object - if the object's mark word is not pointing to
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
315 // the displaced mark word, do unlocking via runtime call.
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
316 if (DirectCompareAndSwapNode.compareAndSwap(object, markOffset(), lock, displacedMark, MARK_WORD_LOCATION).notEqual(lock)) {
7490
4c474119df1c Probabilities for the monitor snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7300
diff changeset
317 // The object's mark word was not pointing to the displaced header,
4c474119df1c Probabilities for the monitor snippets
Gilles Duboscq <duboscq@ssw.jku.at>
parents: 7300
diff changeset
318 // we do unlocking via runtime call.
7554
9472211c812b named constants for snippet probabilities (likely, frequent, fast_path, deopt), see CR-7
Lukas Stadler <lukas.stadler@jku.at>
parents: 7530
diff changeset
319 probability(DEOPT_PATH_PROBABILITY);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
320 traceObject(trace, "-lock{stub}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
321 MonitorExitStubCall.call(object);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
322 } else {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
323 traceObject(trace, "-lock{cas}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
324 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
325 }
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
326 endLockScope();
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
327 decCounter();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
328 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
329
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
330 /**
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
331 * Calls straight out to the monitorexit stub.
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
332 */
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
333 @Snippet
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
334 public static void monitorexitStub(Object object, @ConstantParameter boolean trace) {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
335 verifyOop(object);
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
336 traceObject(trace, "-lock{stub}", object);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
337 MonitorExitStubCall.call(object);
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
338 endLockScope();
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
339 decCounter();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
340 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
341
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
342 @Snippet
6436
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
343 public static void monitorexitEliminated() {
5395ecdfce8a move monitors into FrameState (fixes subtle issues for tail duplication and other optimizations)
Lukas Stadler <lukas.stadler@jku.at>
parents: 6424
diff changeset
344 endLockScope();
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
345 decCounter();
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
346 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
347
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
348 private static void traceObject(boolean enabled, String action, Object object) {
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
349 if (enabled) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
350 Log.print(action);
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
351 Log.print(' ');
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
352 Log.printlnObject(object);
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
353 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
354 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
355
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
356 private static void trace(boolean enabled, String format, WordBase value) {
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
357 if (enabled) {
7300
2912b72d840a More complete and reusable Word type
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7276
diff changeset
358 Log.printf(format, value.rawValue());
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
359 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
360 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
361
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
362 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
363 * Leaving the breakpoint code in to provide an example of how to use the {@link BreakpointNode}
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
364 * intrinsic.
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
365 */
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
366 private static final boolean ENABLE_BREAKPOINT = false;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
367
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
368 private static final Object MONITOR_COUNTER_LOCATION = LocationNode.createLocation("MonitorCounter");
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
369
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
370 @NodeIntrinsic(BreakpointNode.class)
6458
fb66841a0994 made all @NodeIntrinsic annotated methods be native (this is a requirement now enforced during snippet intrinsification)
Doug Simon <doug.simon@oracle.com>
parents: 6453
diff changeset
371 static native void bkpt(Object object, Word mark, Word tmp, Word value);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
372
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
373 private static void incCounter() {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
374 if (CHECK_BALANCED_MONITORS) {
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
375 final Word counter = MonitorCounterNode.counter();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
376 final int count = counter.readInt(0, MONITOR_COUNTER_LOCATION);
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
377 counter.writeInt(0, count + 1, MONITOR_COUNTER_LOCATION);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
378 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
379 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
380
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
381 private static void decCounter() {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
382 if (CHECK_BALANCED_MONITORS) {
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
383 final Word counter = MonitorCounterNode.counter();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
384 final int count = counter.readInt(0, MONITOR_COUNTER_LOCATION);
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
385 counter.writeInt(0, count - 1, MONITOR_COUNTER_LOCATION);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
386 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
387 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
388
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
389 @Snippet
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
390 private static void initCounter() {
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
391 final Word counter = MonitorCounterNode.counter();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
392 counter.writeInt(0, 0, MONITOR_COUNTER_LOCATION);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
393 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
394
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
395 @Snippet
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
396 private static void checkCounter(String errMsg) {
6954
0e20ad1ea98b removed WordStamp (and a nasty bug associated with its misusage)
Doug Simon <doug.simon@oracle.com>
parents: 6952
diff changeset
397 final Word counter = MonitorCounterNode.counter();
7868
7a5bbcc36bb2 add location identity to Pointer read and write operations
Lukas Stadler <lukas.stadler@jku.at>
parents: 7708
diff changeset
398 final int count = counter.readInt(0, MONITOR_COUNTER_LOCATION);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
399 if (count != 0) {
6453
3bba61323b38 added VMErrorNode intrinsic to support handling fatal errors in snippets
Doug Simon <doug.simon@oracle.com>
parents: 6451
diff changeset
400 vmError(errMsg, count);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
401 }
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
402 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
403
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
404 public static class Templates extends AbstractTemplates {
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
405
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
406 private final SnippetInfo monitorenter = snippet(MonitorSnippets.class, "monitorenter");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
407 private final SnippetInfo monitorexit = snippet(MonitorSnippets.class, "monitorexit");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
408 private final SnippetInfo monitorenterStub = snippet(MonitorSnippets.class, "monitorenterStub");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
409 private final SnippetInfo monitorexitStub = snippet(MonitorSnippets.class, "monitorexitStub");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
410 private final SnippetInfo monitorenterEliminated = snippet(MonitorSnippets.class, "monitorenterEliminated");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
411 private final SnippetInfo monitorexitEliminated = snippet(MonitorSnippets.class, "monitorexitEliminated");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
412 private final SnippetInfo initCounter = snippet(MonitorSnippets.class, "initCounter");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
413 private final SnippetInfo checkCounter = snippet(MonitorSnippets.class, "checkCounter");
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
414
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
415 private final boolean useFastLocking;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
416
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8586
diff changeset
417 public Templates(CodeCacheProvider runtime, Replacements replacements, TargetDescription target, boolean useFastLocking) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
418 super(runtime, replacements, target);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
419 this.useFastLocking = useFastLocking;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
420 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
421
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
422 public void lower(MonitorEnterNode monitorenterNode, @SuppressWarnings("unused") LoweringTool tool) {
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
423 StructuredGraph graph = (StructuredGraph) monitorenterNode.graph();
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
424 checkBalancedMonitors(graph);
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
425 FrameState stateAfter = monitorenterNode.stateAfter();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
426
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
427 Arguments args;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
428 if (monitorenterNode.eliminated()) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
429 args = new Arguments(monitorenterEliminated);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
430 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
431 if (useFastLocking) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
432 args = new Arguments(monitorenter);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
433 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
434 args = new Arguments(monitorenterStub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
435 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
436 args.add("object", monitorenterNode.object());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
437 args.addConst("checkNull", !monitorenterNode.object().stamp().nonNull());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
438 args.addConst("trace", isTracingEnabledForType(monitorenterNode.object()) || isTracingEnabledForMethod(stateAfter.method()) || isTracingEnabledForMethod(graph.method()));
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
439 }
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
440
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
441 Map<Node, Node> nodes = template(args).instantiate(runtime, monitorenterNode, DEFAULT_REPLACER, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
442
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
443 for (Node n : nodes.values()) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
444 if (n instanceof BeginLockScopeNode) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
445 BeginLockScopeNode begin = (BeginLockScopeNode) n;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
446 begin.setStateAfter(stateAfter);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
447 }
8586
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
448 if (n instanceof MonitorReference) {
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
449 ((MonitorReference) n).setLockDepth(monitorenterNode.getLockDepth());
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
450 }
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
451 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
452 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
453
7701
47467b2c3fc5 Use equal() and notEqual() instead of == and != to compare words
Christian Wimmer <christian.wimmer@oracle.com>
parents: 7660
diff changeset
454 public void lower(MonitorExitNode monitorexitNode, @SuppressWarnings("unused") LoweringTool tool) {
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
455 StructuredGraph graph = (StructuredGraph) monitorexitNode.graph();
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
456 FrameState stateAfter = monitorexitNode.stateAfter();
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
457
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
458 Arguments args;
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
459 if (monitorexitNode.eliminated()) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
460 args = new Arguments(monitorexitEliminated);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
461 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
462 if (useFastLocking) {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
463 args = new Arguments(monitorexit);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
464 } else {
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
465 args = new Arguments(monitorexitStub);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
466 }
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
467 args.add("object", monitorexitNode.object());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
468 args.addConst("trace", isTracingEnabledForType(monitorexitNode.object()) || isTracingEnabledForMethod(stateAfter.method()) || isTracingEnabledForMethod(graph.method()));
6389
2d84f74e394c enabled type-filter based logging of (snippet-based) monitor operations with the "graal.monitorsnippets.log" system property
Doug Simon <doug.simon@oracle.com>
parents: 6386
diff changeset
469 }
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
470
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
471 Map<Node, Node> nodes = template(args).instantiate(runtime, monitorexitNode, DEFAULT_REPLACER, args);
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
472
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
473 for (Node n : nodes.values()) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
474 if (n instanceof EndLockScopeNode) {
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
475 EndLockScopeNode end = (EndLockScopeNode) n;
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
476 end.setStateAfter(stateAfter);
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
477 }
8586
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
478 if (n instanceof MonitorReference) {
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
479 ((MonitorReference) n).setLockDepth(monitorexitNode.getLockDepth());
82f6a25321b8 modeling of lock state removed from LIR and runtime specific debug info for locks moved into runtime specific classes
Doug Simon <doug.simon@oracle.com>
parents: 8422
diff changeset
480 }
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
481 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
482 }
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
483
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
484 static boolean isTracingEnabledForType(ValueNode object) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
485 ResolvedJavaType type = object.objectStamp().type();
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
486 if (TRACE_TYPE_FILTER == null) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
487 return false;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
488 } else {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
489 if (TRACE_TYPE_FILTER.length() == 0) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
490 return true;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
491 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
492 if (type == null) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
493 return false;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
494 }
6539
2463eb24b644 Cleanup of Graal API: Rename methods so that it follows the getXxx naming convention and so that they are similar to the names of the java.lang.reflect classes. Remove unused methods.
Christian Wimmer <christian.wimmer@oracle.com>
parents: 6526
diff changeset
495 return (type.getName().contains(TRACE_TYPE_FILTER));
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
496 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
497 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
498
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
499 static boolean isTracingEnabledForMethod(ResolvedJavaMethod method) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
500 if (TRACE_METHOD_FILTER == null) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
501 return false;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
502 } else {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
503 if (TRACE_METHOD_FILTER.length() == 0) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
504 return true;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
505 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
506 if (method == null) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
507 return false;
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
508 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
509 return (MetaUtil.format("%H.%n", method).contains(TRACE_METHOD_FILTER));
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
510 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
511 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
512
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
513 /**
7530
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
514 * If balanced monitor checking is enabled then nodes are inserted at the start and all
5e3d1a68664e applied mx eclipseformat to all Java files
Doug Simon <doug.simon@oracle.com>
parents: 7490
diff changeset
515 * return points of the graph to initialize and check the monitor counter respectively.
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
516 */
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
517 private void checkBalancedMonitors(StructuredGraph graph) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
518 if (CHECK_BALANCED_MONITORS) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
519 NodeIterable<MonitorCounterNode> nodes = graph.getNodes().filter(MonitorCounterNode.class);
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
520 if (nodes.isEmpty()) {
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
521 // Only insert the nodes if this is the first monitorenter being lowered.
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
522 JavaType returnType = initCounter.getMethod().getSignature().getReturnType(initCounter.getMethod().getDeclaringClass());
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
523 MethodCallTargetNode callTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, initCounter.getMethod(), new ValueNode[0], returnType));
7660
0b646334c5f7 keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7556
diff changeset
524 InvokeNode invoke = graph.add(new InvokeNode(callTarget, 0));
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
525 invoke.setStateAfter(graph.start().stateAfter());
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
526 graph.addAfterFixed(graph.start(), invoke);
8627
75db7afee829 implemented lazy installation of replacements (GRAAL-137)
Doug Simon <doug.simon@oracle.com>
parents: 8586
diff changeset
527
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
528 StructuredGraph inlineeGraph = replacements.getSnippet(initCounter.getMethod());
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
529 InliningUtil.inline(invoke, inlineeGraph, false);
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
530
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
531 List<ReturnNode> rets = graph.getNodes().filter(ReturnNode.class).snapshot();
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
532 for (ReturnNode ret : rets) {
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
533 returnType = checkCounter.getMethod().getSignature().getReturnType(checkCounter.getMethod().getDeclaringClass());
7143
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
534 Object msg = ((HotSpotRuntime) runtime).registerGCRoot("unbalanced monitors in " + MetaUtil.format("%H.%n(%p)", graph.method()) + ", count = %d");
445193cc2a7d added support for writing stubs in Java and wrote the TLAB fast refill stub
Doug Simon <doug.simon@oracle.com>
parents: 7075
diff changeset
535 ConstantNode errMsg = ConstantNode.forObject(msg, runtime, graph);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
536 callTarget = graph.add(new MethodCallTargetNode(InvokeKind.Static, checkCounter.getMethod(), new ValueNode[]{errMsg}, returnType));
7660
0b646334c5f7 keep track of leafGraphIds only at the StructuredGraph level (see GRAAL-60)
Lukas Stadler <lukas.stadler@jku.at>
parents: 7556
diff changeset
537 invoke = graph.add(new InvokeNode(callTarget, 0));
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
538 List<ValueNode> stack = Collections.emptyList();
6673
a52320a6bbda remove InliningIdentifier
Lukas Stadler <lukas.stadler@jku.at>
parents: 6568
diff changeset
539 FrameState stateAfter = new FrameState(graph.method(), FrameState.AFTER_BCI, new ValueNode[0], stack, new ValueNode[0], false, false);
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
540 invoke.setStateAfter(graph.add(stateAfter));
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
541 graph.addBeforeFixed(ret, invoke);
9015
92d2bedb5dfc Change of Snippet template and instantiation process
Christian Wimmer <christian.wimmer@oracle.com>
parents: 8637
diff changeset
542 inlineeGraph = replacements.getSnippet(checkCounter.getMethod());
6451
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
543 InliningUtil.inline(invoke, inlineeGraph, false);
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
544 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
545 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
546 }
c9f45d2d96cf fixed bug in monitor snippets; they are now used for general lowering of monitor operations
Doug Simon <doug.simon@oracle.com>
parents: 6436
diff changeset
547 }
6386
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
548 }
abeeb57b655d added MonitorSnippets which passes MonitorTest but is not yet enabled for general lowering
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
549 }