annotate graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotMonitorValueTest.java @ 19940:077c16efeb6d

Add option to print CompileQueue occupancy from LogCompilation output
author Tom Rodriguez <tom.rodriguez@oracle.com>
date Tue, 17 Mar 2015 19:21:54 -0700
parents b6beb2161e7a
children 93c50cefb9e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13506
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
1 /*
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
4 *
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
7 * published by the Free Software Foundation.
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
8 *
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
13 * accompanied this code).
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
14 *
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
18 *
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
21 * questions.
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
22 */
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
23 package com.oracle.graal.hotspot.test;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
24
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
25 import static org.hamcrest.CoreMatchers.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
26 import static org.junit.Assert.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
27
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
28 import java.util.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
29
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
30 import org.junit.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
31
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
32 import com.oracle.graal.api.code.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
33 import com.oracle.graal.api.code.CompilationResult.Call;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
34 import com.oracle.graal.api.code.CompilationResult.Infopoint;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
35 import com.oracle.graal.api.meta.*;
15193
96bb07a5d667 Spit up and move GraalInternalError.
Josef Eisl <josef.eisl@jku.at>
parents: 13506
diff changeset
36 import com.oracle.graal.compiler.common.*;
13506
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
37 import com.oracle.graal.compiler.test.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
38
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39 public class HotSpotMonitorValueTest extends GraalCompilerTest {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41 @Override
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 protected InstalledCode addMethod(ResolvedJavaMethod method, CompilationResult compResult) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 for (Infopoint i : compResult.getInfopoints()) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
44 if (i instanceof Call) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 Call call = (Call) i;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 if (call.target instanceof ResolvedJavaMethod) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 if (target.equals(lookupObjectWait())) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 BytecodeFrame frame = call.debugInfo.frame();
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 BytecodeFrame caller = frame.caller();
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 assertNotNull(caller);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 assertNull(caller.caller());
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15193
diff changeset
53 assertDeepEquals(2, frame.numLocks);
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15193
diff changeset
54 assertDeepEquals(2, caller.numLocks);
19595
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
55 StackLockValue lock1 = (StackLockValue) frame.getLockValue(0);
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
56 StackLockValue lock2 = (StackLockValue) frame.getLockValue(1);
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
57 StackLockValue lock3 = (StackLockValue) caller.getLockValue(0);
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
58 StackLockValue lock4 = (StackLockValue) caller.getLockValue(1);
13506
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59
19595
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
60 List<StackLockValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
61 for (StackLockValue lock : locks) {
b6beb2161e7a Move stack monitor value into api.code
Tom Rodriguez <tom.rodriguez@oracle.com>
parents: 15622
diff changeset
62 for (StackLockValue other : locks) {
13506
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 if (other != lock) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 // Every lock must have a different stack slot
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 assertThat(lock.getSlot(), not(other.getSlot()));
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
66 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
67 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
68 }
15622
7b09605b29c5 renamed GraalTest.assertEquals* to assertDeepEquals to avoid confusion with JUnit API methods
Doug Simon <doug.simon@oracle.com>
parents: 15193
diff changeset
69 assertDeepEquals(lock3.getOwner(), lock4.getOwner());
13506
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 assertThat(lock1.getOwner(), not(lock2.getOwner()));
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 return super.addMethod(method, compResult);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
73 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
74 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
75 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
76 throw new AssertionError("Could not find debug info for call to Object.wait(long)");
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
78
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79 private ResolvedJavaMethod lookupObjectWait() {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 try {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 return getMetaAccess().lookupJavaMethod(Object.class.getDeclaredMethod("wait", long.class));
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 } catch (Exception e) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
83 throw new GraalInternalError("Could not find Object.wait(long): %s", e);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
85 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
86
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
87 @Test
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 public void test() {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 test("testSnippet", "a", "b");
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
91
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
92 private static void locks2(Object a, Object b) throws InterruptedException {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
94 synchronized (b) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 a.wait(5);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
97 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
98 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
99
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
100 public static void testSnippet(Object a, Object b) throws InterruptedException {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
102 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 locks2(a, b);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
105 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
106 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
107 }