test/hotspot/jtreg/serviceability/sa/TestRevPtrsForInvokeDynamic.java
author sspitsyn
Tue, 26 Jun 2018 13:50:59 -0700
changeset 50802 fa380b3b2b7d
parent 50791 b1e90a8a876c
permissions -rw-r--r--
8205721: Problem list serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorStatArrayCorrectnessTest.java Summary: Add the test to the ProblemList.txt Reviewed-by: dcubed
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
47569
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     1
/*
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47569
diff changeset
     2
 * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
47569
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     4
 *
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     7
 * published by the Free Software Foundation.
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     8
 *
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    13
 * accompanied this code).
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    14
 *
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    18
 *
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    21
 * questions.
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    22
 */
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    23
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    24
import java.util.ArrayList;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    25
import java.util.List;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    26
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    27
import sun.jvm.hotspot.HotSpotAgent;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    28
import sun.jvm.hotspot.utilities.ReversePtrsAnalysis;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    29
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    30
import jdk.test.lib.apps.LingeredApp;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    31
import jdk.test.lib.Asserts;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    32
import jdk.test.lib.JDKToolFinder;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    33
import jdk.test.lib.JDKToolLauncher;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    34
import jdk.test.lib.Platform;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    35
import jdk.test.lib.process.OutputAnalyzer;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    36
import jdk.test.lib.process.ProcessTools;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    37
import jdk.test.lib.Utils;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    38
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47569
diff changeset
    39
/**
47569
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    40
 * @test
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    41
 * @library /test/lib
50791
b1e90a8a876c 8205419: [testbug] TestJmapCore failing without SA: introduce @requires vm.hasSAandCanAttach
goetz
parents: 47569
diff changeset
    42
 * @requires vm.hasSAandCanAttach & os.family != "mac"
47569
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    43
 * @modules java.base/jdk.internal.misc
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    44
 *          jdk.hotspot.agent/sun.jvm.hotspot
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    45
 *          jdk.hotspot.agent/sun.jvm.hotspot.utilities
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    46
 * @run main/othervm TestRevPtrsForInvokeDynamic
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    47
 */
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    48
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    49
public class TestRevPtrsForInvokeDynamic {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    50
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    51
    private static LingeredAppWithInvokeDynamic theApp = null;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    52
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    53
    private static void computeReversePointers(String pid) throws Exception {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    54
        HotSpotAgent agent = new HotSpotAgent();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    55
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    56
        try {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    57
            agent.attach(Integer.parseInt(pid));
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    58
            ReversePtrsAnalysis analysis = new ReversePtrsAnalysis();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    59
            analysis.run();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    60
        } finally {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    61
            agent.detach();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    62
        }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    63
    }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    64
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    65
    private static void createAnotherToAttach(long lingeredAppPid)
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    66
                                                         throws Exception {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    67
        String[] toolArgs = {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    68
            "--add-modules=jdk.hotspot.agent",
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    69
            "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot=ALL-UNNAMED",
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    70
            "--add-exports=jdk.hotspot.agent/sun.jvm.hotspot.utilities=ALL-UNNAMED",
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    71
            "TestRevPtrsForInvokeDynamic",
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    72
            Long.toString(lingeredAppPid)
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    73
        };
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    74
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    75
        // Start a new process to attach to the lingered app
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    76
        ProcessBuilder processBuilder = ProcessTools.createJavaProcessBuilder(toolArgs);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    77
        OutputAnalyzer SAOutput = ProcessTools.executeProcess(processBuilder);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    78
        SAOutput.shouldHaveExitValue(0);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    79
        System.out.println(SAOutput.getOutput());
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    80
    }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    81
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    82
    public static void main (String... args) throws Exception {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    83
        if (args == null || args.length == 0) {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    84
            try {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    85
                List<String> vmArgs = new ArrayList<String>();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    86
                vmArgs.add("-XX:+UsePerfData");
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    87
                vmArgs.addAll(Utils.getVmOptions());
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    88
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    89
                theApp = new LingeredAppWithInvokeDynamic();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    90
                LingeredApp.startApp(vmArgs, theApp);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    91
                createAnotherToAttach(theApp.getPid());
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    92
            } finally {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    93
                LingeredApp.stopApp(theApp);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    94
            }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    95
        } else {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    96
            computeReversePointers(args[0]);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    97
        }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    98
    }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    99
}