Path: blob/master/test/hotspot/jtreg/compiler/escapeAnalysis/TestAllocatedEscapesPtrComparison.java
41149 views
/*1* Copyright 2014 Google, Inc. 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 804335426* @summary bcEscapeAnalyzer allocated_escapes not conservative enough27*28* @run main/othervm29* -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison::visitAndPop30* compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison31* @author Chuck Rasbold [email protected]32*/3334package compiler.escapeAnalysis;3536/*37* Test always passes with -XX:-OptmimizePtrCompare38*/3940import java.util.ArrayList;41import java.util.List;4243public class TestAllocatedEscapesPtrComparison {4445static TestAllocatedEscapesPtrComparison dummy;4647class Marker {48}4950List<Marker> markerList = new ArrayList<>();5152// Suppress compilation of this method, it must be processed53// by the bytecode escape analyzer.5455// Make a new marker and put it on the List56Marker getMarker() {57// result escapes through markerList58final Marker result = new Marker();59markerList.add(result);60return result;61}6263void visit(int depth) {64// Make a new marker65getMarker();6667// Call visitAndPop every once in a while68// Cap the depth of our recursive visits69if (depth % 10 == 2) {70visitAndPop(depth + 1);71} else if (depth < 15) {72visit(depth + 1);73}74}7576void visitAndPop(int depth) {77// Random dummy allocation to force EscapeAnalysis to process this method78dummy = new TestAllocatedEscapesPtrComparison();7980// Make a new marker81Marker marker = getMarker();8283visit(depth + 1);8485// Walk and pop the marker list up to the current marker86boolean found = false;87for (int i = markerList.size() - 1; i >= 0; i--) {88Marker removed = markerList.remove(i);8990// In the failure, EA mistakenly converts this comparison to false91if (removed == marker) {92found = true;93break;94}95}9697if (!found) {98throw new RuntimeException("test fails");99}100}101102103public static void main(String args[]) {104TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();105106// Warmup and run enough times107for (int i = 0; i < 20000; i++) {108tc.visit(0);109}110}111}112113114