test/hotspot/jtreg/gc/TestAllocateHeapAt.java
author kkharbas
Wed, 29 Nov 2017 17:03:10 -0800
changeset 48153 cfa2c43e58c2
child 50525 767cdb97f103
permissions -rw-r--r--
8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices Summary: Sub-task to be used for implementation of JEP 316: Support heap allocation on alternative memory devices Reviewed-by: sangheki, 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
/*
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    24
/* @test TestAllocateHeapAt.java
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    25
 * @key gc
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    26
 * @summary Test to check allocation of Java Heap with AllocateHeapAt option
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    27
 * @library /test/lib
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    28
 * @modules java.base/jdk.internal.misc
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    29
 */
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    30
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    31
import jdk.test.lib.JDKToolFinder;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    32
import jdk.test.lib.process.ProcessTools;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    33
import jdk.test.lib.process.OutputAnalyzer;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    34
import java.util.ArrayList;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    35
import java.util.Collections;
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    36
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    37
public class TestAllocateHeapAt {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    38
  public static void main(String args[]) throws Exception {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    39
    ArrayList<String> vmOpts = new ArrayList();
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
    String testVmOptsStr = System.getProperty("test.java.opts");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    42
    if (!testVmOptsStr.isEmpty()) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    43
      String[] testVmOpts = testVmOptsStr.split(" ");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    44
      Collections.addAll(vmOpts, testVmOpts);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    45
    }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    46
    String test_dir = System.getProperty("test.dir", ".");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    47
    Collections.addAll(vmOpts, new String[] {"-XX:AllocateHeapAt=" + test_dir,
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    48
                                             "-Xlog:gc+heap=info",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    49
                                             "-Xmx32m",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    50
                                             "-Xms32m",
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    51
                                             "-version"});
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    52
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    53
    System.out.print("Testing:\n" + JDKToolFinder.getJDKTool("java"));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    54
    for (int i = 0; i < vmOpts.size(); i += 1) {
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    55
      System.out.print(" " + vmOpts.get(i));
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.println();
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    58
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    59
    ProcessBuilder pb =
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    60
      ProcessTools.createJavaProcessBuilder(vmOpts.toArray(new String[vmOpts.size()]));
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    61
    OutputAnalyzer output = new OutputAnalyzer(pb.start());
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
    System.out.println("Output:\n" + output.getOutput());
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    64
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    65
    output.shouldContain("Successfully allocated Java heap at location");
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    66
    output.shouldHaveExitValue(0);
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    67
  }
cfa2c43e58c2 8190308: Implementation: JEP 316: Heap Allocation on Alternative Memory Devices
kkharbas
parents:
diff changeset
    68
}