hotspot/test/runtime/SharedArchiveFile/serviceability/transformRelatedClasses/TransformTestCommon.java
author jiangli
Sun, 18 Sep 2016 21:10:48 -0400
changeset 41182 dbd59c1da636
child 46389 d55896236dfd
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 jdk.test.lib.process.OutputAnalyzer;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    25
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
// This class contains methods common to all transformation test cases
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    28
public class TransformTestCommon {
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
    // get parameters to an agent depending on the test case
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    31
    // these parameters will instruct the agent which classes should be
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    32
    // transformed
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    33
    public static String getAgentParams(TestEntry entry,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    34
                                        String parent, String child) {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    35
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    36
        if (entry.transformParent && entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    37
            return parent + "," + child;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    38
        if (entry.transformParent)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    39
            return parent;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    40
        if (entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    41
            return child;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    42
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    43
        return "";
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
    private static void checkTransformationResults(TestEntry entry,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    48
                                                   OutputAnalyzer out)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    49
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    50
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    51
        if (entry.transformParent)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    52
            out.shouldContain(TransformUtil.ParentCheckPattern +
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    53
                              TransformUtil.AfterPattern);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    54
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    55
        if (entry.transformChild)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    56
            out.shouldContain(TransformUtil.ChildCheckPattern +
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    57
                              TransformUtil.AfterPattern);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    58
    }
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
    private static void checkSharingByClass(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    62
                                            String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    63
        throws Exception {
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
        String parentSharedMatch = parent + " source: shared objects file";
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    66
        String childSharedMatch =  child +  " source: shared objects file";
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    67
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    68
        if (entry.isParentExpectedShared)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    69
            out.shouldContain(parentSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    70
        else
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    71
            out.shouldNotContain(parentSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    72
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    73
        if (entry.isChildExpectedShared)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    74
            out.shouldContain(childSharedMatch);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    75
        else
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    76
            out.shouldNotContain(childSharedMatch);
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
    // Both parent and child classes should be passed to ClassFileTransformer.transform()
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    81
    // exactly once.
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    82
    private static void checkTransformationCounts(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    83
                                                  String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    84
        throws Exception {
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
        String patternBase = "TransformerAgent: SimpleTransformer called for: ";
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
        out.shouldContain(patternBase + child + "@1");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    89
        out.shouldContain(patternBase + parent + "@1");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    90
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    91
        out.shouldNotContain(patternBase + child + "@2");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    92
        out.shouldNotContain(patternBase + parent + "@2");
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    93
    }
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
    public static void checkResults(TestEntry entry, OutputAnalyzer out,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    97
                                    String parent, String child)
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    98
        throws Exception {
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
    99
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   100
        // If we were not able to map an archive,
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   101
        // then do not perform other checks, since
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   102
        // there was no sharing at all
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   103
        if (CDSTestUtils.isUnableToMap(out))
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   104
            return;
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   105
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   106
        String childVmName = child.replace('.', '/');
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   107
        String parentVmName = parent.replace('.', '/');
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   108
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   109
        CDSTestUtils.checkExec(out);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   110
        checkTransformationCounts(entry, out, parentVmName, childVmName);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   111
        checkTransformationResults(entry, out);
dbd59c1da636 8078644: CDS needs to support JVMTI CFLH
jiangli
parents:
diff changeset
   112
        checkSharingByClass(entry, out, parent, child);
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
}