hotspot/test/compiler/escapeAnalysis/TestAllocatedEscapesPtrComparison.java
author ppunegov
Tue, 24 Nov 2015 21:03:39 +0300
changeset 34218 4b22b04519e6
parent 27699 9913b19c0948
child 40059 c2304140ed64
permissions -rw-r--r--
8142967: [TESTBUG] Compiler control tests get NullPointerException Summary: Fix incoorect build jtreg tags Reviewed-by: iignatyev, neliasso
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
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    27
 * @summary  bcEscapeAnalyzer allocated_escapes not conservative enough
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    28
 * @run main/othervm -XX:CompileOnly=.visitAndPop TestAllocatedEscapesPtrComparison
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    29
 * @author Chuck Rasbold rasbold@google.com
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    30
 */
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    31
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    32
/*
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    33
 * Test always passes with -XX:-OptmimizePtrCompare
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    34
 */
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    35
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    36
import java.util.ArrayList;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    37
import java.util.List;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    38
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    39
public class TestAllocatedEscapesPtrComparison {
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
  static TestAllocatedEscapesPtrComparison dummy;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    42
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    43
  class Marker {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    44
  }
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
  List<Marker> markerList = new ArrayList<>();
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
  // 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
    49
  // by the bytecode escape analyzer.
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
  // 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
    52
  Marker getMarker() {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    53
    // result escapes through markerList
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    54
    final Marker result = new Marker();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    55
    markerList.add(result);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    56
    return result;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    57
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    58
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    59
  void visit(int depth) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    60
    // Make a new marker
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    61
    getMarker();
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
    // 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
    64
    // 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
    65
    if (depth % 10 == 2) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    66
      visitAndPop(depth + 1);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    67
    } else if (depth < 15) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    68
      visit(depth + 1);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    69
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    70
  }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    71
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    72
   void visitAndPop(int depth) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    73
    // 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
    74
    dummy = new TestAllocatedEscapesPtrComparison();
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
    // Make a new marker
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    77
    Marker marker = getMarker();
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    78
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    79
    visit(depth + 1);
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
    // 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
    82
    boolean found = false;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    83
    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
    84
      Marker removed = markerList.remove(i);
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
      // 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
    87
      if (removed == marker) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    88
        found = true;
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    89
        break;
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
    }
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    92
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    93
    if (!found) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    94
      throw new RuntimeException("test fails");
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
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
    99
  public static void main(String args[]) {
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   100
    TestAllocatedEscapesPtrComparison tc = new TestAllocatedEscapesPtrComparison();
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
    // Warmup and run enough times
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   103
    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
   104
      tc.visit(0);
2a4db2c09547 8043354: 8043354: Make is_return_allocated() respect allocated objects than can method-escape
rasbold
parents:
diff changeset
   105
    }
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
}