Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/util/Collections/ViewSynch.java
38812 views
1
/*
2
* Copyright (c) 1999, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/**
25
* @test
26
* @bug 4268780
27
* @summary Collection-views of submap-views of synchronized-views of
28
* SortedMap objects do not synchronize on the correct object.
29
* (Got that?)
30
*/
31
32
import java.util.*;
33
34
public class ViewSynch {
35
static final Integer ZERO = new Integer(0);
36
static final Int INT_ZERO = new Int(0);
37
static final Int INT_ONE = new Int(1);
38
static SortedMap m = Collections.synchronizedSortedMap(new TreeMap());
39
static Map m2 = m.tailMap(ZERO);
40
static Collection c = m2.values();
41
42
public static void main(String[] args) {
43
for (int i=0; i<10000; i++)
44
m.put(new Integer(i), INT_ZERO);
45
46
new Thread() {
47
public void run() {
48
for (int i=0; i<100; i++) {
49
Thread.yield();
50
m.remove(ZERO);
51
m.put(ZERO, INT_ZERO);
52
}
53
}
54
}.start();
55
56
c.contains(INT_ONE);
57
}
58
}
59
60
/**
61
* Like Integer, except yields while doing equals comparison, to allow
62
* for interleaving.
63
*/
64
class Int {
65
Integer x;
66
Int(int i) {x = new Integer(i);}
67
68
public boolean equals(Object o) {
69
Thread.yield();
70
Int i = (Int)o;
71
return x.equals(i.x);
72
}
73
74
public int hashCode() {return x.hashCode();}
75
}
76
77