jdk/test/com/sun/jdi/MonitorFrameInfo.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 24973 8c4bc3fa4c4e
child 44423 306c020eb154
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 6230699
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test ThreadReference.ownedMonitorsAndFrames()
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
    28
 *  @bug 6701700
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
    29
 *  @summary MonitorInfo objects aren't invalidated when the owning thread is resumed
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @author Swamy Venkataramanappa
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
    32
 *  @modules jdk.jdi
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run compile -g MonitorFrameInfo.java
24973
8c4bc3fa4c4e 6622468: TEST_BUG: Time to retire the @debuggeeVMOptions mechanism used in the com.sun.jdi infrastructure
sla
parents: 5506
diff changeset
    35
 *  @run driver MonitorFrameInfo
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
class MonitorTestTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    static void foo3() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        System.out.println("executing foo3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    static void foo2() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    53
            System.out.println("executing foo2 " + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            foo3();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static void foo1() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        foo2();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        Object l1 = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        synchronized(l1) {
899
40d3416d937a 6730587: TEST: com/sun/jdi/MonitorFrameInfoTest.java fails with -server -Xcomp
jjh
parents: 836
diff changeset
    64
            System.out.println("executing main" + l1);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            foo1();
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class MonitorFrameInfo extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    List monitors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static int expectedCount = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    static int[] expectedDepth = { 1, 3 };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    static String[] expectedNames = {"foo3", "foo2", "foo1", "main"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    MonitorFrameInfo (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        new MonitorFrameInfo(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        BreakpointEvent bpe = startToMain("MonitorTestTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        int initialSize = mainThread.frames().size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        resumeTo("MonitorTestTarg", "foo3", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (!mainThread.frame(0).location().method().name()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                        .equals("foo3")) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   107
            failure("FAILED: frame failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        if (mainThread.frames().size() != (initialSize + 3)) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   111
            failure("FAILED: frames size failed");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        if (mainThread.frames().size() != mainThread.frameCount()) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   115
            failure("FAILED: frames size not equal to frameCount");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        /* Test monitor frame info.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        if (vm().canGetMonitorFrameInfo()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            System.out.println("Get monitors");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            monitors = mainThread.ownedMonitorsAndFrames();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            if (monitors.size() != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                failure("monitors count is not equal to expected count");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   126
            MonitorInfo mon = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            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
   128
                mon  = (MonitorInfo)monitors.get(j);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                System.out.println("Monitor obj " + mon.monitor() + "depth =" +mon.stackDepth());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                if (mon.stackDepth() != expectedDepth[j]) {
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   131
                    failure("FAILED: monitor stack depth is not equal to expected depth");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            }
836
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   134
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   135
            // 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
   136
            // 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
   137
            // 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
   138
            // 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
   139
            // resumed.
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   140
            stepOut(mainThread);
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   141
            boolean ok = false;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   142
            try {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   143
                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
   144
            } catch(InvalidStackFrameException ee) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   145
                // ok
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   146
                ok = true;
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   147
                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
   148
            }
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   149
            if (!ok) {
d81b1f62fb82 6700889: Thread resume invalidates all stack frames, even from other threads
jjh
parents: 2
diff changeset
   150
                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
   151
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            System.out.println("can not get monitors frame info");
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
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
         * resume until end
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            println("MonitorFrameInfo: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            throw new Exception("MonitorFrameInfo: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
}