test/jdk/com/sun/jdi/MonitorFrameInfo.java
author clanger
Thu, 17 Oct 2019 22:41:36 +0200
changeset 58681 5f14a659a8cb
parent 47216 71c04702a3d5
permissions -rw-r--r--
8232370: Refactor some com.sun.jdi tests to enable IDE integration Reviewed-by: amenkov, cjplummer, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
     2
 * Copyright (c) 2005, 2019, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1247
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    26
 * @bug 6230699
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    27
 * @summary Test ThreadReference.ownedMonitorsAndFrames()
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    28
 * @bug 6701700
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    29
 * @summary MonitorInfo objects aren't invalidated when the owning thread is resumed
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    30
 * @author Swamy Venkataramanappa
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    32
 * @run build TestScaffold VMConnection TargetListener TargetAdapter
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    33
 * @run compile -g MonitorFrameInfo.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30376
diff changeset
    34
 * @run driver MonitorFrameInfo
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 */
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    36
import java.util.List;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    38
import com.sun.jdi.InvalidStackFrameException;
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    39
import com.sun.jdi.MonitorInfo;
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    40
import com.sun.jdi.ReferenceType;
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    41
import com.sun.jdi.ThreadReference;
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    42
import com.sun.jdi.event.BreakpointEvent;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    46
class MonitorFrameInfoTarg {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    static void foo3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        System.out.println("executing foo3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    static void foo2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    54
            System.out.println("executing foo2 " + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            foo3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static void foo1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        foo2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    65
            System.out.println("executing main" + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            foo1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class MonitorFrameInfo extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    ThreadReference mainThread;
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    76
    List<MonitorInfo> monitors;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static int expectedCount = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static int[] expectedDepth = { 1, 3 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    static String[] expectedNames = {"foo3", "foo2", "foo1", "main"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    MonitorFrameInfo (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        new MonitorFrameInfo(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         */
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
    98
        BreakpointEvent bpe = startToMain("MonitorFrameInfoTarg");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        int initialSize = mainThread.frames().size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
58681
5f14a659a8cb 8232370: Refactor some com.sun.jdi tests to enable IDE integration
clanger
parents: 47216
diff changeset
   104
        resumeTo("MonitorFrameInfoTarg", "foo3", "()V");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        if (!mainThread.frame(0).location().method().name()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                        .equals("foo3")) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   108
            failure("FAILED: frame failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        if (mainThread.frames().size() != (initialSize + 3)) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   112
            failure("FAILED: frames size failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        if (mainThread.frames().size() != mainThread.frameCount()) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   116
            failure("FAILED: frames size not equal to frameCount");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        /* Test monitor frame info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        if (vm().canGetMonitorFrameInfo()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.out.println("Get monitors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            monitors = mainThread.ownedMonitorsAndFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            if (monitors.size() != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                failure("monitors count is not equal to expected count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   127
            MonitorInfo mon = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            for (int j=0; j < monitors.size(); j++) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   129
                mon  = (MonitorInfo)monitors.get(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                System.out.println("Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                if (mon.stackDepth() != expectedDepth[j]) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   132
                    failure("FAILED: monitor stack depth is not equal to expected depth");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   135
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   136
            // The last gotten monInfo is in mon.   When we resume the thread,
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   137
            // it should become invalid.  We will step out of the top frame
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   138
            // so that the frame depth in this mon object will no longer be correct.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   139
            // That is why the monInfo's have to become invalid when the thread is
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   140
            // resumed.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   141
            stepOut(mainThread);
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   142
            boolean ok = false;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   143
            try {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   144
                System.out.println("*** Saved Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth());
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   145
            } catch(InvalidStackFrameException ee) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   146
                // ok
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   147
                ok = true;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   148
                System.out.println("Got expected InvalidStackFrameException after a resume");
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   149
            }
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   150
            if (!ok) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   151
                failure("FAILED: MonitorInfo object was not invalidated by a resume");
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   152
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            System.out.println("can not get monitors frame info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * resume until end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            println("MonitorFrameInfo: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new Exception("MonitorFrameInfo: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
}