annotate graal/com.oracle.graal.hotspot.test/src/com/oracle/graal/hotspot/test/HotSpotMonitorValueTest.java @ 15511:ef1342e0f9f2

Merge (update state flag after initialization to allow other compiler threads to execute)
author Lukas Stadler <lukas.stadler@oracle.com>
date Mon, 05 May 2014 18:39:09 +0200
parents 96bb07a5d667
children 7b09605b29c5
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 import com.oracle.graal.hotspot.meta.*;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
39
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
40 public class HotSpotMonitorValueTest extends GraalCompilerTest {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
41
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
42 @Override
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
43 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
44 for (Infopoint i : compResult.getInfopoints()) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
45 if (i instanceof Call) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
46 Call call = (Call) i;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
47 if (call.target instanceof ResolvedJavaMethod) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
48 ResolvedJavaMethod target = (ResolvedJavaMethod) call.target;
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
49 if (target.equals(lookupObjectWait())) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
50 BytecodeFrame frame = call.debugInfo.frame();
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
51 BytecodeFrame caller = frame.caller();
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
52 assertNotNull(caller);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
53 assertNull(caller.caller());
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
54 assertEquals(2, frame.numLocks);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
55 assertEquals(2, caller.numLocks);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
56 HotSpotMonitorValue lock1 = (HotSpotMonitorValue) frame.getLockValue(0);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
57 HotSpotMonitorValue lock2 = (HotSpotMonitorValue) frame.getLockValue(1);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
58 HotSpotMonitorValue lock3 = (HotSpotMonitorValue) caller.getLockValue(0);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
59 HotSpotMonitorValue lock4 = (HotSpotMonitorValue) caller.getLockValue(1);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
60
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
61 List<HotSpotMonitorValue> locks = Arrays.asList(lock1, lock2, lock3, lock4);
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
62 for (HotSpotMonitorValue lock : locks) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
63 for (HotSpotMonitorValue other : locks) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
64 if (other != lock) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
65 // 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
66 assertThat(lock.getSlot(), not(other.getSlot()));
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 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
69 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
70 assertEquals(lock3.getOwner(), lock4.getOwner());
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
71 assertThat(lock1.getOwner(), not(lock2.getOwner()));
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
72 return super.addMethod(method, compResult);
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 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
77 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
78 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
79
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
80 private ResolvedJavaMethod lookupObjectWait() {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
81 try {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
82 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
83 } catch (Exception e) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
84 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
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
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
88 @Test
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
89 public void test() {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
90 test("testSnippet", "a", "b");
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
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
93 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
94 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
95 synchronized (b) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
96 a.wait(5);
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
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
101 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
102 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
103 synchronized (a) {
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
104 locks2(a, b);
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 }
2a4569fa9aa4 fixed bug (properly) in nested lock depth computation
Doug Simon <doug.simon@oracle.com>
parents:
diff changeset
108 }