test/hotspot/jtreg/compiler/escapeAnalysis/TestAllocatedEscapesPtrComparison.java
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 40059 hotspot/test/compiler/escapeAnalysis/TestAllocatedEscapesPtrComparison.java@c2304140ed64
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24449
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     1
/*
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     2
 * Copyright 2014 Google, Inc.  All Rights Reserved.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     4
 *
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     8
 *
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    13
 * accompanied this code).
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    14
 *
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    18
 *
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    21
 * questions.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    22
 */
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    23
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    24
/*
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    25
 * @test
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    26
 * @bug 8043354
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    27
 * @summary bcEscapeAnalyzer allocated_escapes not conservative enough
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    28
 *
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    29
 * @run main/othervm
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    30
 *      -XX:CompileCommand=compileonly,compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison::visitAndPop
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    31
 *      compiler.escapeAnalysis.TestAllocatedEscapesPtrComparison
24449
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    32
 * @author Chuck Rasbold rasbold@google.com
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    33
 */
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    34
40059
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    35
package compiler.escapeAnalysis;
c2304140ed64 8132919: Put compiler tests in packages
tpivovarova
parents: 27699
diff changeset
    36
24449
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    37
/*
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    38
 * Test always passes with -XX:-OptmimizePtrCompare
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    39
 */
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    40
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    41
import java.util.ArrayList;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    42
import java.util.List;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    43
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    44
public class TestAllocatedEscapesPtrComparison {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    45
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    46
  static TestAllocatedEscapesPtrComparison dummy;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    47
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    48
  class Marker {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    49
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    50
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    51
  List<Marker> markerList = new ArrayList<>();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    52
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    53
  // Suppress compilation of this method, it must be processed
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    54
  // by the bytecode escape analyzer.
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    55
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    56
  // Make a new marker and put it on the List
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    57
  Marker getMarker() {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    58
    // result escapes through markerList
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    59
    final Marker result = new Marker();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    60
    markerList.add(result);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    61
    return result;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    62
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    63
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    64
  void visit(int depth) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    65
    // Make a new marker
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    66
    getMarker();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    67
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    68
    // Call visitAndPop every once in a while
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    69
    // Cap the depth of our recursive visits
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    70
    if (depth % 10 == 2) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    71
      visitAndPop(depth + 1);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    72
    } else if (depth < 15) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    73
      visit(depth + 1);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    74
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    75
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    76
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    77
   void visitAndPop(int depth) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    78
    // Random dummy allocation to force EscapeAnalysis to process this method
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    79
    dummy = new TestAllocatedEscapesPtrComparison();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    80
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    81
    // Make a new marker
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    82
    Marker marker = getMarker();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    83
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    84
    visit(depth + 1);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    85
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    86
    // Walk and pop the marker list up to the current marker
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    87
    boolean found = false;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    88
    for (int i = markerList.size() - 1; i >= 0; i--) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    89
      Marker removed = markerList.remove(i);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    90
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    91
      // In the failure, EA mistakenly converts this comparison to false
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    92
      if (removed == marker) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    93
        found = true;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    94
        break;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    95
      }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    96
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    97
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    98
    if (!found) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    99
      throw new RuntimeException("test fails");
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   100
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   101
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   102
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   103
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   104
  public static void main(String args[]) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   105
    TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   106
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   107
    // Warmup and run enough times
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   108
    for (int i = 0; i < 20000; i++) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   109
      tc.visit(0);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   110
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   111
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   112
}