author | ccheung |
Fri, 04 Oct 2013 21:00:43 -0700 | |
changeset 20384 | 49bfb2ec8f8f |
parent 18955 | be9410d4a97c |
permissions | -rw-r--r-- |
18955
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
1 |
/* |
be9410d4a97c
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. |
be9410d4a97c
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. |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
4 |
* |
be9410d4a97c
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 |
be9410d4a97c
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 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
8 |
* |
be9410d4a97c
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 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
be9410d4a97c
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 |
be9410d4a97c
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 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
13 |
* accompanied this code). |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
14 |
* |
be9410d4a97c
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 |
be9410d4a97c
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, |
be9410d4a97c
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. |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
18 |
* |
be9410d4a97c
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 |
be9410d4a97c
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 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
21 |
* questions. |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
22 |
*/ |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
23 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
24 |
/* |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
25 |
* @test |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
26 |
* @bug 8020215 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
27 |
* @summary Different execution plan when using JIT vs interpreter |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
28 |
* @run main Test8020215 |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
29 |
*/ |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
30 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
31 |
import java.util.ArrayList; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
32 |
import java.util.List; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
33 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
34 |
public class Test8020215 { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
35 |
public static class NamedObject { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
36 |
public int id; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
37 |
public String name; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
38 |
public NamedObject(int id, String name) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
39 |
this.id = id; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
40 |
this.name = name; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
41 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
42 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
43 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
44 |
public static class NamedObjectList { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
45 |
public List<NamedObject> namedObjectList = new ArrayList<NamedObject>(); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
46 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
47 |
public NamedObject getBest(int id) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
48 |
NamedObject bestObject = null; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
49 |
for (NamedObject o : namedObjectList) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
50 |
bestObject = id==o.id ? getBetter(bestObject, o) : bestObject; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
51 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
52 |
return (bestObject != null) ? bestObject : null; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
53 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
54 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
55 |
private static NamedObject getBetter(NamedObject p1, NamedObject p2) { |
be9410d4a97c
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; |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
57 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
58 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
59 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
60 |
static void test(NamedObjectList b, int i) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
61 |
NamedObject x = b.getBest(2); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
62 |
// test |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
63 |
if (x == null) { |
be9410d4a97c
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 + ")"); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
65 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
66 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
67 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
68 |
public static void main(String[] args) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
69 |
// setup |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
70 |
NamedObjectList b = new NamedObjectList(); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
71 |
for (int i = 0; i < 10000; i++) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
72 |
b.namedObjectList.add(new NamedObject(1, "2012-12-31")); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
73 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
74 |
b.namedObjectList.add(new NamedObject(2, "2013-12-31")); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
75 |
|
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
76 |
// execution |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
77 |
for (int i = 0; i < 12000; i++) { |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
78 |
test(b, i); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
79 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
80 |
System.out.println("PASSED"); |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
81 |
} |
be9410d4a97c
8020215: Different execution plan when using JIT vs interpreter
kvn
parents:
diff
changeset
|
82 |
} |