test/jdk/com/sun/jdi/MonitorFrameInfo.java
author amenkov
Fri, 21 Sep 2018 11:28:14 -0700
changeset 51837 46ca82c15f6c
parent 47216 71c04702a3d5
child 58681 5f14a659a8cb
permissions -rw-r--r--
8210760: [TEST] rewrite com/sun/jdi shell tests to java version - step4 Reviewed-by: jcbeyler, sspitsyn, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
     2
 * Copyright (c) 2005, 2015, 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
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class MonitorTestTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    static void foo3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        System.out.println("executing foo3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    static void foo2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    52
            System.out.println("executing foo2 " + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            foo3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static void foo1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        foo2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    63
            System.out.println("executing main" + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
            foo1();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class MonitorFrameInfo extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    List monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static int expectedCount = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static int[] expectedDepth = { 1, 3 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static String[] expectedNames = {"foo3", "foo2", "foo1", "main"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    MonitorFrameInfo (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        new MonitorFrameInfo(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        BreakpointEvent bpe = startToMain("MonitorTestTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        int initialSize = mainThread.frames().size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        resumeTo("MonitorTestTarg", "foo3", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        if (!mainThread.frame(0).location().method().name()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
                        .equals("foo3")) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   106
            failure("FAILED: frame failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (mainThread.frames().size() != (initialSize + 3)) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   110
            failure("FAILED: frames size failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        if (mainThread.frames().size() != mainThread.frameCount()) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   114
            failure("FAILED: frames size not equal to frameCount");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        /* Test monitor frame info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if (vm().canGetMonitorFrameInfo()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            System.out.println("Get monitors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            monitors = mainThread.ownedMonitorsAndFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (monitors.size() != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                failure("monitors count is not equal to expected count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   125
            MonitorInfo mon = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            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
   127
                mon  = (MonitorInfo)monitors.get(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                System.out.println("Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                if (mon.stackDepth() != expectedDepth[j]) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   130
                    failure("FAILED: monitor stack depth is not equal to expected depth");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   133
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   134
            // 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
   135
            // 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
   136
            // 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
   137
            // 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
   138
            // resumed.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   139
            stepOut(mainThread);
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   140
            boolean ok = false;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   141
            try {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   142
                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
   143
            } catch(InvalidStackFrameException ee) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   144
                // ok
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   145
                ok = true;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   146
                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
   147
            }
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   148
            if (!ok) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   149
                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
   150
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            System.out.println("can not get monitors frame info");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
         * resume until end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            println("MonitorFrameInfo: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throw new Exception("MonitorFrameInfo: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
}