test/hotspot/jtreg/gc/epsilon/TestObjects.java
author shade
Wed, 30 May 2018 11:22:56 +0200
branchepsilon-gc-branch
changeset 56629 98acdabed742
parent 56540 ada11a8e2ebc
permissions -rw-r--r--
Make sure C2 configurations are executed in tests
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     1
/*
56350
56014b46de69 Update copyrights
shade
parents: 55767
diff changeset
     2
 * Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved.
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     4
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     7
 * published by the Free Software Foundation.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     8
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    13
 * accompanied this code).
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    14
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    18
 *
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    21
 * questions.
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    22
 */
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    23
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    24
/**
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    25
 * @test TestObjects
56540
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    26
 * @key gc
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    27
 * @requires vm.gc.Epsilon
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    28
 * @summary Epsilon is able to allocate objects, and does not corrupt their state
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    29
 *
56540
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    30
 * @run main/othervm -Xmx128m                                        -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    31
 * @run main/othervm -Xmx128m -Xint                                  -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    32
 * @run main/othervm -Xmx128m -Xbatch -Xcomp                         -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    33
 * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
56629
98acdabed742 Make sure C2 configurations are executed in tests
shade
parents: 56540
diff changeset
    34
 * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:-TieredCompilation  -XX:+UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    35
 *
56540
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    36
 * @run main/othervm -Xmx128m                                        -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    37
 * @run main/othervm -Xmx128m -Xint                                  -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    38
 * @run main/othervm -Xmx128m -Xbatch -Xcomp                         -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    39
 * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:TieredStopAtLevel=1 -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
56629
98acdabed742 Make sure C2 configurations are executed in tests
shade
parents: 56540
diff changeset
    40
 * @run main/othervm -Xmx128m -Xbatch -Xcomp -XX:-TieredCompilation  -XX:-UseTLAB -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC TestObjects
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    41
 */
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    42
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    43
import java.util.Random;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    44
56540
ada11a8e2ebc Refactor test handling with @requires
shade
parents: 56350
diff changeset
    45
public class TestObjects {
55767
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    46
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    47
  static long SEED = Long.getLong("seed", System.nanoTime());
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    48
  static int COUNT = Integer.getInteger("count", 1_000_000); // ~24 MB allocation
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    49
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    50
  static MyObject[] arr;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    51
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    52
  public static void main(String[] args) throws Exception {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    53
    Random r = new Random(SEED);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    54
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    55
    arr = new MyObject[COUNT];
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    56
    for (int c = 0; c < COUNT; c++) {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    57
      arr[c] = new MyObject(r.nextInt());
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    58
    }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    59
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    60
    r = new Random(SEED);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    61
    for (int c = 0; c < COUNT; c++) {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    62
      int expected = r.nextInt();
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    63
      int actual = arr[c].id();
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    64
      if (expected != actual) {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    65
        throw new IllegalStateException("Failure: expected = " + expected + ", actual = " + actual);
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    66
      }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    67
    }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    68
  }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    69
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    70
  public static class MyObject {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    71
    int id;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    72
    public MyObject(int id) {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    73
      this.id = id;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    74
    }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    75
    public int id() {
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    76
      return id;
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    77
    }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    78
  }
8e22715afabc Initial import of Epsilon sources from jdk10/sandbox
shade
parents:
diff changeset
    79
}