Mercurial > hg > truffle
annotate graal/com.oracle.graal.snippets.test/src/com/oracle/graal/snippets/MonitorTest.java @ 6398:bced4f3a4174
removed old EscapeAnalysisPhase
author | Lukas Stadler <lukas.stadler@jku.at> |
---|---|
date | Fri, 14 Sep 2012 15:16:50 +0200 |
parents | 4b8a9dee2bff |
children | e8b025eb340d |
rev | line source |
---|---|
6371
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
1 /* |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
2 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
4 * |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
8 * |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
13 * accompanied this code). |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
14 * |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
18 * |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
21 * questions. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
22 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
23 package com.oracle.graal.snippets; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
24 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
25 import org.junit.*; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
26 |
6398
bced4f3a4174
removed old EscapeAnalysisPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
6371
diff
changeset
|
27 import com.oracle.graal.compiler.phases.ea.*; |
6371
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
28 import com.oracle.graal.compiler.test.*; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
29 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
30 public class MonitorTest extends GraalCompilerTest { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
31 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
32 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
33 public void test0() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
34 test("lockObjectSimple", new Object(), "test1"); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
35 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
36 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
37 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
38 public void test0_1() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
39 test("lockThisSimple", "test1"); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
40 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
41 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
42 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
43 public void test0_2() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
44 test("lockObjectSimple", null, "test1"); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
45 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
46 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
47 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
48 public void test1_1() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
49 test("lockObject", new Object(), "test1", new String[1]); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
50 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
51 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
52 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
53 public void test1_2() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
54 test("lockObject", null, "test1_1", new String[1]); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
55 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
56 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
57 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
58 public void test2() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
59 test("lockThis", "test2", new String[1]); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
60 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
61 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
62 /** |
6398
bced4f3a4174
removed old EscapeAnalysisPhase
Lukas Stadler <lukas.stadler@jku.at>
parents:
6371
diff
changeset
|
63 * Tests monitor operations on {@link PartialEscapeAnalysisPhase virtual objects}. |
6371
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
64 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
65 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
66 public void test3() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
67 test("lockLocalObject", "test3", new String[1]); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
68 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
69 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
70 /** |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
71 * Tests recursive locking of objects which should be biasable. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
72 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
73 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
74 public void test4() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
75 Chars src = new Chars("1234567890".toCharArray()); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
76 Chars dst = new Chars(src.data.length); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
77 test("copyObj", src, dst, 100); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
78 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
79 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
80 /** |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
81 * Tests recursive locking of objects which do not appear to be biasable. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
82 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
83 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
84 public void test5() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
85 char[] src = "1234567890".toCharArray(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
86 char[] dst = new char[src.length]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
87 test("copyArr", src, dst, 100); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
88 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
89 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
90 /** |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
91 * Extends {@link #test4()} with contention. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
92 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
93 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
94 public void test6() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
95 Chars src = new Chars("1234567890".toCharArray()); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
96 Chars dst = new Chars(src.data.length); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
97 int n = Runtime.getRuntime().availableProcessors(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
98 testN(n, "copyObj", src, dst, 100); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
99 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
100 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
101 /** |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
102 * Extends {@link #test5()} with contention. |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
103 */ |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
104 @Test |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
105 public void test7() { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
106 char[] src = "1234567890".toCharArray(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
107 char[] dst = new char[src.length]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
108 int n = Runtime.getRuntime().availableProcessors(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
109 testN(n, "copyArr", src, dst, 100); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
110 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
111 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
112 private static String setAndGet(String[] box, String value) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
113 synchronized (box) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
114 box[0] = null; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
115 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
116 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
117 // Do a GC while a object is locked (by the caller) |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
118 System.gc(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
119 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
120 synchronized (box) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
121 box[0] = value; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
122 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
123 return box[0]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
124 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
125 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
126 public static String lockObjectSimple(Object o, String value) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
127 synchronized (o) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
128 return value; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
129 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
130 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
131 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
132 public String lockThisSimple(String value) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
133 synchronized (this) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
134 return value; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
135 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
136 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
137 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
138 public static String lockObject(Object o, String value, String[] box) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
139 synchronized (o) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
140 return setAndGet(box, value); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
141 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
142 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
143 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
144 public String lockThis(String value, String[] box) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
145 synchronized (this) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
146 return setAndGet(box, value); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
147 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
148 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
149 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
150 public static String lockLocalObject(String value, String[] box) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
151 Object o = new Object(); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
152 synchronized (o) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
153 return setAndGet(box, value); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
154 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
155 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
156 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
157 static class Chars { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
158 final char[] data; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
159 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
160 public Chars(int size) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
161 this.data = new char[size]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
162 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
163 public Chars(char[] data) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
164 this.data = data; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
165 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
166 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
167 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
168 public static String copyObj(Chars src, Chars dst, int n) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
169 System.out.println(Thread.currentThread().getName() + " reps=" + n + ", src.length=" + src.data.length); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
170 int total = 0; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
171 for (int j = 0; j < n; j++) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
172 for (int i = 0; i < src.data.length; i++) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
173 synchronized (src) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
174 synchronized (dst) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
175 synchronized (src) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
176 synchronized (dst) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
177 dst.data[i] = src.data[i]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
178 total++; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
179 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
180 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
181 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
182 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
183 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
184 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
185 System.out.println(Thread.currentThread().getName() + " total " + total); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
186 return new String(dst.data); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
187 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
188 |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
189 public static String copyArr(char[] src, char[] dst, int n) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
190 System.out.println(Thread.currentThread().getName() + " reps=" + n + ", src.length=" + src.length); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
191 int total = 0; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
192 for (int j = 0; j < n; j++) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
193 for (int i = 0; i < src.length; i++) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
194 synchronized (src) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
195 synchronized (dst) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
196 synchronized (src) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
197 synchronized (dst) { |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
198 dst[i] = src[i]; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
199 total++; |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
200 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
201 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
202 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
203 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
204 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
205 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
206 System.out.println(Thread.currentThread().getName() + " total " + total); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
207 return new String(dst); |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
208 } |
4b8a9dee2bff
added tests for monitor snippets
Doug Simon <doug.simon@oracle.com>
parents:
diff
changeset
|
209 } |