test/hotspot/jtreg/runtime/NMT/JcmdSummaryClass.java
author zgu
Thu, 08 Feb 2018 13:21:22 -0500
changeset 48884 7e17b00dc245
parent 48873 9536c39ac6de
permissions -rw-r--r--
8196923: [REDO] NMT: Report array class count in NMT summary Summary: Added instance and array class counters in NMT summary report Reviewed-by: minqi, stuefe, coleenp

/*
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 * or visit www.oracle.com if you need additional information or have any
 * questions.
 */

 /*
 * @test
 * @bug 8193184
 * @key nmt
 * @summary Check class counters in summary report
 * @library /test/lib
 * @modules java.base/jdk.internal.misc
 *          java.management
 * @run main/othervm -Xbootclasspath/a:. -XX:NativeMemoryTracking=summary JcmdSummaryClass
 */

import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.JDKToolFinder;


import java.util.regex.*;

public class JcmdSummaryClass {

    public static void main(String args[]) throws Exception {
        ProcessBuilder pb = new ProcessBuilder();
        OutputAnalyzer output;
        // Grab my own PID
        String pid = Long.toString(ProcessTools.getProcessId());

        // Run 'jcmd <pid> VM.native_memory baseline=true'
        pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory"});
        pb.start().waitFor();

        String classes_line = "classes #\\d+";
        String instance_array_classes_line = "instance classes #\\d+, array classes #\\d+";
        output = new OutputAnalyzer(pb.start());
        output.shouldMatch(classes_line);
        output.shouldMatch(instance_array_classes_line);
    }
}