hotspot/test/serviceability/dcmd/compiler/CodelistTest.java
author miauno
Fri, 30 Jan 2015 20:00:57 +0100
changeset 28821 f7820f311663
parent 26941 96aa76b27b9c
child 29678 dd2f3932c21e
permissions -rw-r--r--
8071908: Port internal Diagnostic Command tests and test framework to jtreg Reviewed-by: jbachorik, egahlin, ykantser, mtobiass
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     1
/*
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     4
 *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     8
 *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    13
 * accompanied this code).
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    14
 *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    18
 *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    21
 * questions.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    22
 */
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    23
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    24
/*
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    25
 * @test CodelistTest
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    26
 * @bug 8054889
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    27
 * @library /testlibrary
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    28
 * @build com.oracle.java.testlibrary.*
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    29
 * @build com.oracle.java.testlibrary.dcmd.*
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    30
 * @build MethodIdentifierParser
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    31
 * @run testng CodelistTest
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    32
 * @summary Test of diagnostic command Compiler.codelist
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    33
 */
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    34
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    35
import org.testng.annotations.Test;
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    36
import org.testng.Assert;
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    37
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    38
import com.oracle.java.testlibrary.OutputAnalyzer;
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    39
import com.oracle.java.testlibrary.dcmd.CommandExecutor;
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    40
import com.oracle.java.testlibrary.dcmd.JMXExecutor;
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    41
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    42
import java.lang.reflect.Method;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    43
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    44
public class CodelistTest {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    45
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    46
    /**
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    47
     * This test calls Jcmd (diagnostic command tool) Compiler.codelist and then parses the output,
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    48
     * making sure that the first methods in the list is valid by reflection.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    49
     *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    50
     * Output example:
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    51
     *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    52
     * 6 0 java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V [0x00007f7b49200910, 0x00007f7b49200aa0 - 0x00007f7b49200d30]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    53
     * 2 3 java.lang.String.indexOf(II)I [0x00007f7b49200d90, 0x00007f7b49200f60 - 0x00007f7b49201490]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    54
     * 7 3 java.lang.Math.min(II)I [0x00007f7b4922f010, 0x00007f7b4922f180 - 0x00007f7b4922f338]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    55
     * 8 3 java.lang.String.equals(Ljava/lang/Object;)Z [0x00007f7b4922fb10, 0x00007f7b4922fd40 - 0x00007f7b49230698]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    56
     * 9 3 java.lang.AbstractStringBuilder.ensureCapacityInternal(I)V [0x00007f7b49232010, 0x00007f7b492321a0 - 0x00007f7b49232510]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    57
     * 10 1 java.lang.Object.<init>()V [0x00007f7b49233e90, 0x00007f7b49233fe0 - 0x00007f7b49234118]
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    58
     *
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    59
     */
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    60
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    61
    public void run(CommandExecutor executor) {
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    62
        int ok   = 0;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    63
        int fail = 0;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    64
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    65
        // Get output from dcmd (diagnostic command)
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    66
        OutputAnalyzer output = executor.execute("Compiler.codelist");
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    67
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    68
        // Grab a method name from the output
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    69
        int count = 0;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    70
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    71
        for (String line : output.asLines()) {
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    72
            count++;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    73
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    74
            String[] parts = line.split(" ");
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    75
            // int compileID = Integer.parseInt(parts[0]);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    76
            // int compileLevel = Integer.parseInt(parts[1]);
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    77
            String methodPrintedInLogFormat = parts[2];
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    78
26941
96aa76b27b9c 8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents: 26587
diff changeset
    79
            // skip inits, clinits and methodHandles - they can not be reflected
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    80
            if (methodPrintedInLogFormat.contains("<init>")) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    81
                continue;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    82
            }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    83
            if (methodPrintedInLogFormat.contains("<clinit>")) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    84
                continue;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    85
            }
26941
96aa76b27b9c 8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents: 26587
diff changeset
    86
            if (methodPrintedInLogFormat.contains("MethodHandle")) {
96aa76b27b9c 8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents: 26587
diff changeset
    87
                continue;
96aa76b27b9c 8058891: serviceability/dcmd/CodelistTest.java - fails on all platforms
neliasso
parents: 26587
diff changeset
    88
            }
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    89
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    90
            MethodIdentifierParser mf = new MethodIdentifierParser(methodPrintedInLogFormat);
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    91
            Method m = null;
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    92
            try {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    93
                m = mf.getMethod();
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    94
            } catch (NoSuchMethodException e) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    95
                m = null;
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    96
            } catch (ClassNotFoundException e) {
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
    97
                Assert.fail("Test error: Caught unexpected exception", e);
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    98
            }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
    99
            if (m == null) {
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   100
                Assert.fail("Test failed on: " + methodPrintedInLogFormat);
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   101
            }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   102
            if (count > 10) {
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   103
                // Testing 10 entries is enough. Lets not waste time.
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   104
                break;
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   105
            }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   106
        }
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   107
    }
28821
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   108
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   109
    @Test
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   110
    public void jmx() {
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   111
        run(new JMXExecutor());
f7820f311663 8071908: Port internal Diagnostic Command tests and test framework to jtreg
miauno
parents: 26941
diff changeset
   112
    }
26587
e8b28fa936af 8054889: Compiler team's implementation task
neliasso
parents:
diff changeset
   113
}