Mercurial > hg > truffle
annotate test/compiler/EscapeAnalysis/Test8020215.java @ 18913:51680f58e681
Clean up in Kind class. Introduce Kind#getSlotCount and Kind#needsTwoSlots methods.
author | Thomas Wuerthinger <thomas.wuerthinger@oracle.com> |
---|---|
date | Tue, 20 Jan 2015 16:40:45 +0100 |
parents | c90c698831d7 |
children |
rev | line source |
---|---|
11163
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
1 /* |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
4 * |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
8 * |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
13 * accompanied this code). |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
14 * |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
18 * |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
21 * questions. |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
22 */ |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
23 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
24 /* |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
25 * @test |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
26 * @bug 8020215 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
27 * @summary Different execution plan when using JIT vs interpreter |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
28 * @run main Test8020215 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
29 */ |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
30 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
31 import java.util.ArrayList; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
32 import java.util.List; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
33 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
34 public class Test8020215 { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
35 public static class NamedObject { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
36 public int id; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
37 public String name; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
38 public NamedObject(int id, String name) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
39 this.id = id; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
40 this.name = name; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
41 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
42 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
43 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
44 public static class NamedObjectList { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
45 public List<NamedObject> namedObjectList = new ArrayList<NamedObject>(); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
46 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
47 public NamedObject getBest(int id) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
48 NamedObject bestObject = null; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
49 for (NamedObject o : namedObjectList) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
50 bestObject = id==o.id ? getBetter(bestObject, o) : bestObject; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
51 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
52 return (bestObject != null) ? bestObject : null; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
53 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
54 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
55 private static NamedObject getBetter(NamedObject p1, NamedObject p2) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
56 return (p1 == null) ? p2 : (p2 == null) ? p1 : (p2.name.compareTo(p1.name) >= 0) ? p2 : p1; |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
57 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
58 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
59 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
60 static void test(NamedObjectList b, int i) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
61 NamedObject x = b.getBest(2); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
62 // test |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
63 if (x == null) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
64 throw new RuntimeException("x should never be null here! (i=" + i + ")"); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
65 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
66 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
67 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
68 public static void main(String[] args) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
69 // setup |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
70 NamedObjectList b = new NamedObjectList(); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
71 for (int i = 0; i < 10000; i++) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
72 b.namedObjectList.add(new NamedObject(1, "2012-12-31")); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
73 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
74 b.namedObjectList.add(new NamedObject(2, "2013-12-31")); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
75 |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
76 // execution |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
77 for (int i = 0; i < 12000; i++) { |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
78 test(b, i); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
79 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
80 System.out.println("PASSED"); |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
81 } |
c90c698831d7
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
82 } |