Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/Test8020215.java
41149 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 802021526* @summary Different execution plan when using JIT vs interpreter27*28* @run main compiler.escapeAnalysis.Test802021529*/3031package compiler.escapeAnalysis;3233import java.util.ArrayList;34import java.util.List;3536public class Test8020215 {37public static class NamedObject {38public int id;39public String name;40public NamedObject(int id, String name) {41this.id = id;42this.name = name;43}44}4546public static class NamedObjectList {47public List<NamedObject> namedObjectList = new ArrayList<NamedObject>();4849public NamedObject getBest(int id) {50NamedObject bestObject = null;51for (NamedObject o : namedObjectList) {52bestObject = id==o.id ? getBetter(bestObject, o) : bestObject;53}54return (bestObject != null) ? bestObject : null;55}5657private static NamedObject getBetter(NamedObject p1, NamedObject p2) {58return (p1 == null) ? p2 : (p2 == null) ? p1 : (p2.name.compareTo(p1.name) >= 0) ? p2 : p1;59}60}6162static void test(NamedObjectList b, int i) {63NamedObject x = b.getBest(2);64// test65if (x == null) {66throw new RuntimeException("x should never be null here! (i=" + i + ")");67}68}6970public static void main(String[] args) {71// setup72NamedObjectList b = new NamedObjectList();73for (int i = 0; i < 10000; i++) {74b.namedObjectList.add(new NamedObject(1, "2012-12-31"));75}76b.namedObjectList.add(new NamedObject(2, "2013-12-31"));7778// execution79for (int i = 0; i < 12000; i++) {80test(b, i);81}82System.out.println("PASSED");83}84}858687