hotspot/test/runtime/Thread/ThreadPriorities.java
author ykantser
Thu, 26 Mar 2015 16:36:56 +0100
changeset 29678 dd2f3932c21e
parent 28471 d86dbab0aedc
child 30604 b8d532cb6420
permissions -rw-r--r--
8075586: Add @modules as needed to the open hotspot tests Reviewed-by: sla, ctornqvi, lfoltan, mchung, alanb Contributed-by: alexander.kulyakhtin@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28471
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     1
/*
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28471
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
28471
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     4
 *
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     8
 *
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    13
 * accompanied this code).
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    14
 *
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    18
 *
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    21
 * questions.
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    22
 */
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    23
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    24
/*
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    25
 * @test
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    26
 * @bug     7194254
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    27
 * @summary Creates several threads with different java priorities and checks
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    28
 *      whether jstack reports correct priorities for them.
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    29
 *
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    30
 * @library /testlibrary
29678
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28471
diff changeset
    31
 * @modules java.base/sun.misc
dd2f3932c21e 8075586: Add @modules as needed to the open hotspot tests
ykantser
parents: 28471
diff changeset
    32
 *          java.management
28471
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    33
 * @run main ThreadPriorities
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    34
 */
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    35
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    36
import java.util.ArrayList;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    37
import java.util.concurrent.CyclicBarrier;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    38
import java.util.regex.Matcher;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    39
import java.util.regex.Pattern;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    40
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    41
import com.oracle.java.testlibrary.*;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    42
import static com.oracle.java.testlibrary.Asserts.*;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    43
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    44
public class ThreadPriorities {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    45
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    46
    public static void main(String[] args) throws Throwable {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    47
        final int NUMBER_OF_JAVA_PRIORITIES =
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    48
                Thread.MAX_PRIORITY - Thread.MIN_PRIORITY + 1;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    49
        final CyclicBarrier barrier =
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    50
                new CyclicBarrier(NUMBER_OF_JAVA_PRIORITIES + 1);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    51
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    52
        for (int p = Thread.MIN_PRIORITY; p <= Thread.MAX_PRIORITY; ++p) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    53
            final int priority = p;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    54
            new Thread("Priority=" + p) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    55
                {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    56
                    setPriority(priority);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    57
                }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    58
                public void run() {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    59
                    try {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    60
                        barrier.await(); // 1st
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    61
                        barrier.await(); // 2nd
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    62
                    } catch (Exception exc) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    63
                        // ignore
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    64
                    }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    65
                }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    66
            }.start();
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    67
        }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    68
        barrier.await(); // 1st
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    69
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    70
        int matches = 0;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    71
        ArrayList<String> failed = new ArrayList<>();
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    72
        ProcessBuilder pb = new ProcessBuilder(
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    73
                JDKToolFinder.getJDKTool("jstack"),
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    74
                String.valueOf(ProcessTools.getProcessId()));
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    75
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    76
        String[] output = new OutputAnalyzer(pb.start()).getOutput().split("\\n+");
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    77
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    78
        Pattern pattern = Pattern.compile(
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    79
                "\\\"Priority=(\\d+)\\\".* prio=(\\d+).*");
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    80
        for (String line : output) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    81
            Matcher matcher = pattern.matcher(line);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    82
            if (matcher.matches()) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    83
                matches += 1;
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    84
                String expected = matcher.group(1);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    85
                String actual = matcher.group(2);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    86
                if (!expected.equals(actual)) {
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    87
                    failed.add(line);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    88
                }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    89
            }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    90
        }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    91
        barrier.await(); // 2nd
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    92
        barrier.reset();
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    93
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    94
        assertEquals(matches, NUMBER_OF_JAVA_PRIORITIES);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    95
        assertTrue(failed.isEmpty(), failed.size() + ":" + failed);
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    96
    }
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    97
}
d86dbab0aedc 8060219: [TESTBUG] runtime/7194254/Test7194254.java fails to find jstack with modular image build
ctornqvi
parents:
diff changeset
    98