hotspot/test/serviceability/sa/TestInstanceKlassSize.java
author alanb
Thu, 01 Dec 2016 08:56:41 +0000
changeset 42307 cefc81dc1d52
parent 42075 e5b263ac8c2e
child 42646 591ef3658bb0
permissions -rw-r--r--
8169069: Module system implementation refresh (11/2016) Reviewed-by: lfoltan, acorn, ctornqvi, mchung Contributed-by: lois.foltan@oracle.com, harold.seigel@oracle.com, alan.bateman@oracle.com, mandy.chung@oracle.com, serguei.spitsyn@oracle.com, george.triantafillou@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     1
/*
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     2
 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved.
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     4
 *
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     7
 * published by the Free Software Foundation.
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     8
 *
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    13
 * accompanied this code).
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    14
 *
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    18
 *
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    21
 * questions.
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    22
 */
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    23
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    24
import sun.jvm.hotspot.HotSpotAgent;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    25
import sun.jvm.hotspot.utilities.SystemDictionaryHelper;
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    26
import sun.jvm.hotspot.oops.InstanceKlass;
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    27
import sun.jvm.hotspot.debugger.*;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    28
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    29
import java.util.ArrayList;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    30
import java.util.List;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    31
import java.util.stream.Collectors;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    32
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    33
import jdk.test.lib.JDKToolLauncher;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    34
import jdk.test.lib.Platform;
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    35
import jdk.test.lib.process.ProcessTools;
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    36
import jdk.test.lib.process.OutputAnalyzer;
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    37
import jdk.test.lib.Utils;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    38
import jdk.test.lib.apps.LingeredApp;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    39
import jdk.test.lib.Asserts;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    40
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    41
import java.io.*;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    42
import java.util.*;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    43
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    44
/*
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    45
 * @test
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    46
 * @library /test/lib
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    47
 * @modules java.base/jdk.internal.misc
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    48
 * @compile -XDignore.symbol.file=true
42307
cefc81dc1d52 8169069: Module system implementation refresh (11/2016)
alanb
parents: 42075
diff changeset
    49
 *          --add-modules=jdk.hotspot.agent
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    50
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    51
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    52
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    53
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
40631
ed82623d7831 8157957: ClassNotFoundException: jdk.test.lib.JDKToolFinder
ctornqvi
parents: 40244
diff changeset
    54
 *          TestInstanceKlassSize.java
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    55
 * @run main/othervm
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    56
 *          --add-modules=jdk.hotspot.agent
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    57
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    58
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    59
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    60
 *          --add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
    61
 *          TestInstanceKlassSize
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    62
 */
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    63
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    64
public class TestInstanceKlassSize {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    65
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    66
    private static String getJcmdInstanceKlassSize(OutputAnalyzer output,
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    67
                                                   String instanceKlassName) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    68
        for (String s : output.asLines()) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    69
            if (s.contains(instanceKlassName)) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    70
                String tokens[];
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    71
                System.out.println(s);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    72
                tokens = s.split("\\s+");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    73
                return tokens[3];
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    74
            }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    75
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    76
        return null;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    77
    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    78
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    79
    private static OutputAnalyzer jcmd(Long pid,
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    80
                                       String... toolArgs) throws Exception {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    81
        ProcessBuilder processBuilder = new ProcessBuilder();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    82
        JDKToolLauncher launcher = JDKToolLauncher.createUsingTestJDK("jcmd");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    83
        launcher.addToolArg(Long.toString(pid));
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    84
        if (toolArgs != null) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    85
            for (String toolArg : toolArgs) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    86
                launcher.addToolArg(toolArg);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    87
            }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    88
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    89
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    90
        processBuilder.command(launcher.getCommand());
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    91
        System.out.println(
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    92
            processBuilder.command().stream().collect(Collectors.joining(" ")));
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    93
        return ProcessTools.executeProcess(processBuilder);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    94
    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    95
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    96
    private static void startMeWithArgs() throws Exception {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    97
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    98
        LingeredApp app = null;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
    99
        OutputAnalyzer output = null;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   100
        try {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   101
            List<String> vmArgs = new ArrayList<String>();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   102
            vmArgs.add("-XX:+UsePerfData");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   103
            vmArgs.addAll(Utils.getVmOptions());
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   104
            app = LingeredApp.startApp(vmArgs);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   105
            System.out.println ("Started LingeredApp with pid " + app.getPid());
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   106
        } catch (Exception ex) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   107
            ex.printStackTrace();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   108
            throw new RuntimeException(ex);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   109
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   110
        try {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   111
            String[] instanceKlassNames = new String[] {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   112
                                              " java.lang.Object",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   113
                                              " java.util.Vector",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   114
                                              " sun.util.PreHashedMap",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   115
                                              " java.lang.String",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   116
                                              " java.lang.Thread",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   117
                                              " java.lang.Byte",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   118
                                          };
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   119
            String[] toolArgs = {
40244
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 39999
diff changeset
   120
                "--add-modules=jdk.hotspot.agent",
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 39999
diff changeset
   121
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 39999
diff changeset
   122
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
b3055c216762 8136930: Simplify use of module-system options by custom launchers
hseigel
parents: 39999
diff changeset
   123
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.oops=ALL-UNNAMED",
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   124
                "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.debugger=ALL-UNNAMED",
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   125
                "TestInstanceKlassSize",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   126
                Long.toString(app.getPid())
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   127
            };
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   128
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   129
            OutputAnalyzer jcmdOutput = jcmd(
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   130
                           app.getPid(),
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   131
                           "GC.class_stats", "VTab,ITab,OopMap,KlassBytes");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   132
            ProcessBuilder processBuilder = ProcessTools
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   133
                                            .createJavaProcessBuilder(toolArgs);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   134
            output = ProcessTools.executeProcess(processBuilder);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   135
            System.out.println(output.getOutput());
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   136
            output.shouldHaveExitValue(0);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   137
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   138
            // Check whether the size matches that which jcmd outputs
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   139
            for (String instanceKlassName : instanceKlassNames) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   140
                System.out.println ("Trying to match for" + instanceKlassName);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   141
                String jcmdInstanceKlassSize = getJcmdInstanceKlassSize(
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   142
                                                      jcmdOutput,
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   143
                                                      instanceKlassName);
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   144
                Asserts.assertNotNull(jcmdInstanceKlassSize,
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   145
                    "Could not get the instance klass size from the jcmd output");
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   146
                for (String s : output.asLines()) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   147
                    if (s.contains(instanceKlassName)) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   148
                       Asserts.assertTrue(
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   149
                          s.contains(jcmdInstanceKlassSize),
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   150
                          "The size computed by SA for" +
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   151
                          instanceKlassName + " does not match.");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   152
                    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   153
                }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   154
            }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   155
        } finally {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   156
            LingeredApp.stopApp(app);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   157
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   158
    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   159
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   160
    private static void SAInstanceKlassSize(int pid,
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   161
                                            String[] SAInstanceKlassNames) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   162
        HotSpotAgent agent = new HotSpotAgent();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   163
        try {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   164
            agent.attach(pid);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   165
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   166
        catch (DebuggerException e) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   167
            System.out.println(e.getMessage());
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   168
            System.err.println("Unable to connect to process ID: " + pid);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   169
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   170
            agent.detach();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   171
            e.printStackTrace();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   172
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   173
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   174
        for (String SAInstanceKlassName : SAInstanceKlassNames) {
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   175
            InstanceKlass ik = SystemDictionaryHelper.findInstanceKlass(
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   176
                               SAInstanceKlassName);
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   177
            Asserts.assertNotNull(ik,
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   178
                String.format("Unable to find instance klass for %s", ik));
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   179
            System.out.println("SA: The size of " + SAInstanceKlassName +
40889
adf083cbc37f 8164562: serviceability/sa/TestInstanceKlassSizeForInterface.java: fails with NPE
dsamersoff
parents: 40631
diff changeset
   180
                               " is " + ik.getSize());
39999
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   181
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   182
        agent.detach();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   183
    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   184
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   185
    public static void main(String[] args) throws Exception {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   186
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   187
        if (!Platform.shouldSAAttach()) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   188
            System.out.println("SA attach not expected to work - test skipped.");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   189
            return;
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   190
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   191
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   192
        if (args == null || args.length == 0) {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   193
            System.out.println ("No args run. Starting with args now.");
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   194
            startMeWithArgs();
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   195
        } else {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   196
            String[] SAInstanceKlassNames = new String[] {
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   197
                                                "java.lang.Object",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   198
                                                "java.util.Vector",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   199
                                                "sun.util.PreHashedMap",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   200
                                                "java.lang.String",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   201
                                                "java.lang.Thread",
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   202
                                                "java.lang.Byte"
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   203
                                             };
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   204
            SAInstanceKlassSize(Integer.parseInt(args[0]), SAInstanceKlassNames);
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   205
        }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   206
    }
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   207
}
82ece130a37b 8145627: sun.jvm.hotspot.oops.InstanceKlass::getSize() returns the incorrect size and has no test
sspitsyn
parents:
diff changeset
   208