test/hotspot/jtreg/gc/TestAllocateHeapAt.java
author lkorinth
Mon, 28 Jan 2019 15:53:56 +0100
changeset 53523 4c5184c56dc2
parent 51949 2a1e47af3c6b
child 53694 a0a327cae58f
permissions -rw-r--r--
8214799: Add package declaration to each JTREG test case in the gc folder Reviewed-by: lmesnik, tschatzl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     1
/*
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51949
diff changeset
     2
 * Copyright (c) 2017, 2019, Oracle and/or its affiliates. All rights reserved.
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     4
 *
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     7
 * published by the Free Software Foundation.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     8
 *
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    13
 * accompanied this code).
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    14
 *
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    18
 *
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    21
 * questions.
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    22
 */
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    23
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51949
diff changeset
    24
package gc;
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51949
diff changeset
    25
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    26
/* @test TestAllocateHeapAt.java
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    27
 * @key gc
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    28
 * @summary Test to check allocation of Java Heap with AllocateHeapAt option
51949
2a1e47af3c6b 8211208: make AllocateHeapAt an unsupported option on AIX
mbaesken
parents: 50525
diff changeset
    29
 * @requires vm.gc != "Z" & os.family != "aix"
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    30
 * @library /test/lib
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    31
 * @modules java.base/jdk.internal.misc
53523
4c5184c56dc2 8214799: Add package declaration to each JTREG test case in the gc folder
lkorinth
parents: 51949
diff changeset
    32
 * @run main gc.TestAllocateHeapAt
48153
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    33
 */
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    34
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    35
import jdk.test.lib.JDKToolFinder;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    37
import jdk.test.lib.process.OutputAnalyzer;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    38
import java.util.ArrayList;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    39
import java.util.Collections;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    40
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    41
public class TestAllocateHeapAt {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    42
  public static void main(String args[]) throws Exception {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    43
    ArrayList<String> vmOpts = new ArrayList();
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    44
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    45
    String testVmOptsStr = System.getProperty("test.java.opts");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    46
    if (!testVmOptsStr.isEmpty()) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    47
      String[] testVmOpts = testVmOptsStr.split(" ");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    48
      Collections.addAll(vmOpts, testVmOpts);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    49
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    50
    String test_dir = System.getProperty("test.dir", ".");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    51
    Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + test_dir,
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    52
                                             "-Xlog:gc+heap=info",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    53
                                             "-Xmx32m",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    54
                                             "-Xms32m",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    55
                                             "-version"});
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    56
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    57
    System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    58
    for (int i = 0; i < vmOpts.size(); i += 1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    59
      System.out.print(" " + vmOpts.get(i));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    60
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    61
    System.out.println();
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    62
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    63
    ProcessBuilder pb =
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    64
      ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    65
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    66
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    67
    System.out.println("Output:\n" + output.getOutput());
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    68
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    69
    output.shouldContain("Successfully allocated Java heap at location");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    70
    output.shouldHaveExitValue(0);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    71
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    72
}