Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/Test8020215.java
41149 views
1
/*
2
* Copyright (c) 2013, 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 8020215
27
* @summary Different execution plan when using JIT vs interpreter
28
*
29
* @run main compiler.escapeAnalysis.Test8020215
30
*/
31
32
package compiler.escapeAnalysis;
33
34
import java.util.ArrayList;
35
import java.util.List;
36
37
public class Test8020215 {
38
public static class NamedObject {
39
public int id;
40
public String name;
41
public NamedObject(int id, String name) {
42
this.id = id;
43
this.name = name;
44
}
45
}
46
47
public static class NamedObjectList {
48
public List<NamedObject> namedObjectList = new ArrayList<NamedObject>();
49
50
public NamedObject getBest(int id) {
51
NamedObject bestObject = null;
52
for (NamedObject o : namedObjectList) {
53
bestObject = id==o.id ? getBetter(bestObject, o) : bestObject;
54
}
55
return (bestObject != null) ? bestObject : null;
56
}
57
58
private static NamedObject getBetter(NamedObject p1, NamedObject p2) {
59
return (p1 == null) ? p2 : (p2 == null) ? p1 : (p2.name.compareTo(p1.name) >= 0) ? p2 : p1;
60
}
61
}
62
63
static void test(NamedObjectList b, int i) {
64
NamedObject x = b.getBest(2);
65
// test
66
if (x == null) {
67
throw new RuntimeException("x should never be null here! (i=" + i + ")");
68
}
69
}
70
71
public static void main(String[] args) {
72
// setup
73
NamedObjectList b = new NamedObjectList();
74
for (int i = 0; i < 10000; i++) {
75
b.namedObjectList.add(new NamedObject(1, "2012-12-31"));
76
}
77
b.namedObjectList.add(new NamedObject(2, "2013-12-31"));
78
79
// execution
80
for (int i = 0; i < 12000; i++) {
81
test(b, i);
82
}
83
System.out.println("PASSED");
84
}
85
}
86
87