test/hotspot/jtreg/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformTestCommon.java
author vlivanov
Fri, 26 May 2017 18:39:27 +0300
changeset 48557 2e867226b914
parent 47216 71c04702a3d5
child 51411 4699147a4f91
permissions -rw-r--r--
8174962: Better interface invocations Reviewed-by: jrose, coleenp, ahgross, acorn, iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
     1
/*
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 41182
diff changeset
     2
 * Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved.
41182
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
46389
d55896236dfd 8177728: [TESTBUG] Improve CDS test utils
mseledtsov
parents: 41182
diff changeset
    24
import jdk.test.lib.cds.CDSTestUtils;
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    25
import jdk.test.lib.process.OutputAnalyzer;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    26
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    27
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    28
// This class contains methods common to all transformation test cases
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    29
public class TransformTestCommon {
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
    // get parameters to an agent depending on the test case
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    32
    // these parameters will instruct the agent which classes should be
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    33
    // transformed
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    34
    public static String getAgentParams(TestEntry entry,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    35
                                        String parent, String child) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    36
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    37
        if (entry.transformParent && entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    38
            return parent + "," + child;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    39
        if (entry.transformParent)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    40
            return parent;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    41
        if (entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    42
            return child;
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
        return "";
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
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    48
    private static void checkTransformationResults(TestEntry entry,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    49
                                                   OutputAnalyzer out)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    50
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    51
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    52
        if (entry.transformParent)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    53
            out.shouldContain(TransformUtil.ParentCheckPattern +
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    54
                              TransformUtil.AfterPattern);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    55
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    56
        if (entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    57
            out.shouldContain(TransformUtil.ChildCheckPattern +
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    58
                              TransformUtil.AfterPattern);
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
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
    private static void checkSharingByClass(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    63
                                            String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    64
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    65
48557
2e867226b914 8174962: Better interface invocations
vlivanov
parents: 47216
diff changeset
    66
        String parentSharedMatch = " " + parent + " source: shared objects file";
2e867226b914 8174962: Better interface invocations
vlivanov
parents: 47216
diff changeset
    67
        String childSharedMatch =  " " + child +  " source: shared objects file";
41182
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    68
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    69
        if (entry.isParentExpectedShared)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    70
            out.shouldContain(parentSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    71
        else
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    72
            out.shouldNotContain(parentSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    73
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    74
        if (entry.isChildExpectedShared)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    75
            out.shouldContain(childSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    76
        else
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    77
            out.shouldNotContain(childSharedMatch);
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
    // Both parent and child classes should be passed to ClassFileTransformer.transform()
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    82
    // exactly once.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    83
    private static void checkTransformationCounts(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    84
                                                  String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    85
        throws Exception {
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
        String patternBase = "TransformerAgent: SimpleTransformer called for: ";
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    88
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    89
        out.shouldContain(patternBase + child + "@1");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    90
        out.shouldContain(patternBase + parent + "@1");
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
        out.shouldNotContain(patternBase + child + "@2");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    93
        out.shouldNotContain(patternBase + parent + "@2");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    94
    }
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
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    97
    public static void checkResults(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    98
                                    String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    99
        throws Exception {
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
        // If we were not able to map an archive,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   102
        // then do not perform other checks, since
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   103
        // there was no sharing at all
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   104
        if (CDSTestUtils.isUnableToMap(out))
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   105
            return;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   106
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   107
        String childVmName = child.replace('.', '/');
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   108
        String parentVmName = parent.replace('.', '/');
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   109
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   110
        CDSTestUtils.checkExec(out);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   111
        checkTransformationCounts(entry, out, parentVmName, childVmName);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   112
        checkTransformationResults(entry, out);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   113
        checkSharingByClass(entry, out, parent, child);
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
}