hotspot/test/runtime/SharedArchiveFile/CDSTestUtils.java
author jiangli
Sun, 18 Sep 2016 21:10:48 -0400
changeset 41182 dbd59c1da636
permissions -rw-r--r--
8078644: CDS needs to support JVMTI CFLH Summary: Support posting CLFH for shared classes. Tests are contributed by Misha Seledtsov. Reviewed-by: iklam, coleenp, acorn, dcubed, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     1
/*
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     4
 *
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     7
 * published by the Free Software Foundation.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     8
 *
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    13
 * accompanied this code).
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    14
 *
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    18
 *
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    21
 * questions.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    22
 */
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    23
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    24
import java.io.IOException;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    25
import java.io.File;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    26
import java.io.FileOutputStream;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    27
import java.io.PrintStream;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    28
import jdk.test.lib.process.OutputAnalyzer;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    29
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    30
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    31
// This class contains common test utilities for CDS testing
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    32
public class CDSTestUtils {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    33
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    34
    // check result of 'dump' operation
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    35
    public static void checkDump(OutputAnalyzer output, String... extraMatches)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    36
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    37
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    38
        output.shouldContain("Loading classes to share");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    39
        output.shouldHaveExitValue(0);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    40
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    41
        for (String match : extraMatches) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    42
            output.shouldContain(match);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    43
        }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    44
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    45
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    46
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    47
    // check the output for indication that mapping of the archive failed
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    48
    public static boolean isUnableToMap(OutputAnalyzer output) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    49
        String outStr = output.getOutput();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    50
        if ((output.getExitValue() == 1) && (
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    51
            outStr.contains("Unable to reserve shared space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    52
            outStr.contains("Unable to map ReadOnly shared space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    53
            outStr.contains("Unable to map ReadWrite shared space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    54
            outStr.contains("Unable to map MiscData shared space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    55
            outStr.contains("Unable to map MiscCode shared space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    56
            outStr.contains("Unable to map shared string space at required address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    57
            outStr.contains("Could not allocate metaspace at a compatible address") ||
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    58
            outStr.contains("Unable to allocate shared string space: range is not within java heap") ))
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    59
        {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    60
            return true;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    61
        }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    62
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    63
        return false;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    64
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    65
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    66
    // check result of 'exec' operation, that is when JVM is run using the archive
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    67
    public static void checkExec(OutputAnalyzer output, String... extraMatches) throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    68
        if (isUnableToMap(output)) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    69
            System.out.println("Unable to map shared archive: test did not complete; assumed PASS");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    70
            return;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    71
        }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    72
        output.shouldContain("sharing");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    73
        output.shouldHaveExitValue(0);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    74
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    75
        for (String match : extraMatches) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    76
            output.shouldContain(match);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    77
        }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    78
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    79
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    80
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    81
    // get the file object for the test artifact
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    82
    private static File getTestArtifactFile(String prefix, String name) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    83
        File dir = new File(System.getProperty("test.classes", "."));
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    84
        return new File(dir, prefix + name);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    85
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    86
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    87
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    88
    // create file containing the specified class list
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    89
    public static File makeClassList(String testCaseName, String classes[])
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    90
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    91
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    92
        File classList = getTestArtifactFile(testCaseName, "test.classlist");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    93
        FileOutputStream fos = new FileOutputStream(classList);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    94
        PrintStream ps = new PrintStream(fos);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    95
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    96
        addToClassList(ps, classes);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    97
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    98
        ps.close();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    99
        fos.close();
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   100
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   101
        return classList;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   102
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   103
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   104
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   105
    private static void addToClassList(PrintStream ps, String classes[])
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   106
        throws IOException
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   107
    {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   108
        if (classes != null) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   109
            for (String s : classes) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   110
                ps.println(s);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   111
            }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   112
        }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   113
    }
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   114
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   115
}