|
1 /* |
|
2 * Copyright (c) 2019, 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 8233529 |
|
27 * @summary Verify that correct loops are selected when trying to remove main/post. |
|
28 * @run main/othervm -XX:-TieredCompilation -Xbatch |
|
29 * -XX:CompileCommand=compileonly,compiler.loopopts.TestRemoveMainPostLoops::test |
|
30 * compiler.loopopts.TestRemoveMainPostLoops |
|
31 */ |
|
32 |
|
33 package compiler.loopopts; |
|
34 |
|
35 public class TestRemoveMainPostLoops { |
|
36 static int cnt1 = 0; |
|
37 int cnt2 = 0; |
|
38 |
|
39 void testCallee() { |
|
40 // (5) Only main and post loops are created (no pre loop -> "PeelMainPost") and main is unrolled. |
|
41 for (int i = 0; i < 100; ++i) { |
|
42 // (4) Inner loop is fully unrolled and removed. |
|
43 for (int j = 0; j < 10; ++j) { |
|
44 cnt1 += j; |
|
45 } |
|
46 } |
|
47 } |
|
48 |
|
49 void test() { |
|
50 for (int i = 0; i < 10_000; ++i) { |
|
51 // (0) testCallee method is inlined |
|
52 testCallee(); |
|
53 cnt2 = 0; |
|
54 // (1) OSR compilation is triggered in this loop. |
|
55 // (2) Pre-/main-/post loops are created. |
|
56 // (3) Main and post loops found empty and removed. |
|
57 // (6) Pre loop is found empty, attempt to remove main and post loop then incorrectly selects main from (5). |
|
58 for (int j = 0; j < 10; ++j) { |
|
59 cnt2 = cnt1 + j; |
|
60 } |
|
61 } |
|
62 } |
|
63 |
|
64 public static void main(String[] strArr) { |
|
65 TestRemoveMainPostLoops test = new TestRemoveMainPostLoops(); |
|
66 for (int i = 0; i < 100; i++) { |
|
67 cnt1 = 0; |
|
68 test.cnt2 = 0; |
|
69 test.test(); |
|
70 if (cnt1 != 45000000 || test.cnt2 != 45000009) { |
|
71 throw new RuntimeException("Incorrect result: " + cnt1 + " " + test.cnt2); |
|
72 } |
|
73 } |
|
74 } |
|
75 } |