test/hotspot/jtreg/serviceability/sa/TestRevPtrsForInvokeDynamic.java
author ihse
Tue, 20 Feb 2018 21:47:54 +0100
changeset 48923 b75c9e2e3b1f
parent 47569 28f78d145691
child 50791 b1e90a8a876c
permissions -rw-r--r--
8198450: Make jdk.internal.vm.compiler/module-info.java.extra reproducable Reviewed-by: erikj, mchung
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
/*
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
     2
 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
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
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    39
/*
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
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    42
 * @requires os.family != "mac"
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 (!Platform.shouldSAAttach()) {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    84
            System.out.println(
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    85
               "SA attach not expected to work - test skipped.");
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    86
            return;
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    87
        }
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
        if (args == null || args.length == 0) {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    90
            try {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    91
                List<String> vmArgs = new ArrayList<String>();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    92
                vmArgs.add("-XX:+UsePerfData");
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    93
                vmArgs.addAll(Utils.getVmOptions());
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
                theApp = new LingeredAppWithInvokeDynamic();
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    96
                LingeredApp.startApp(vmArgs, theApp);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    97
                createAnotherToAttach(theApp.getPid());
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    98
            } finally {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
    99
                LingeredApp.stopApp(theApp);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   100
            }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   101
        } else {
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   102
            computeReversePointers(args[0]);
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   103
        }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   104
    }
28f78d145691 8175816: SA: HSDB: Compute Liveness results in java.lang.IndexOutOfBoundsException
ysuenaga
parents:
diff changeset
   105
}