jdk/test/com/sun/jdi/AllLineLocations.java
author sla
Fri, 29 May 2015 11:05:52 +0200
changeset 30964 613fbce96e32
parent 30376 2ccf2cf7ea48
child 44423 306c020eb154
permissions -rw-r--r--
8081470: com/sun/jdi tests are failing with "Error. failed to clean up files after test" with jtreg 4.1 b12 Reviewed-by: mgerdin, brutisso, iignatyev
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) 1999, 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: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 4248728
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test ReferenceType.allLineLocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Gordon Hirsch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
    30
 *  @modules jdk.jdi
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run build JDIScaffold VMConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run compile -g RefTypes.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run build AllLineLocations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
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 AllLineLocations RefTypes
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.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
public class AllLineLocations extends JDIScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    final String[] args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
        new AllLineLocations(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    AllLineLocations(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        this.args = args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        connect(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
         * Get to a point where the classes are loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        BreakpointEvent bp = resumeTo("RefTypes", "loadClasses", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        stepOut(bp.thread());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
         * These classes should have no line numbers, except for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
         * one in the implicit constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        ReferenceType rt = findReferenceType("AllAbstract");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            throw new Exception("AllAbstract: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        List list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        if (list.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            throw new Exception("AllAbstract: incorrect number of line locations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        if (rt.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            throw new Exception("AllAbstract: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        Method method = findMethod(rt, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throw new Exception("AllAbstract.<init> not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        List list2 = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (!list2.equals(list)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            throw new Exception("AllAbstract: line locations in wrong method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
            throw new Exception("AllAbstract: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        System.out.println("AllAbstract: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        rt = findReferenceType("AllNative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            throw new Exception("AllNative: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        if (list.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            throw new Exception("AllNative: incorrect number of line locations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        if (rt.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            throw new Exception("AllNative: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        method = findMethod(rt, "<init>", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            throw new Exception("AllNative.<init> not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        list2 = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (!list2.equals(list)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            throw new Exception("AllNative: line locations in wrong method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            throw new Exception("AllNative: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        System.out.println("AllNative: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        rt = findReferenceType("Interface");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            throw new Exception("Interface: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        if (list.size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            throw new Exception("Interface: locations reported for abstract methods");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        System.out.println("Interface: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
         * These classes have line numbers in one method and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
         * in the implicit constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        rt = findReferenceType("Abstract");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            throw new Exception("Abstract: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (list.size() != 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            throw new Exception("Abstract: incorrect number of line locations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        method = findMethod(rt, "b", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            throw new Exception("Abstract.b not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        list2 = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        list.removeAll(list2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        // Remaining location should be in constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if ((list.size() != 1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            !(((Location)list.get(0)).method().name().equals("<init>"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            throw new Exception("Abstract: line locations in wrong method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        if (method.locationsOfLine(20).size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            throw new Exception("Abstract method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            throw new Exception("Abstract method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        method = findMethod(rt, "a", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            throw new Exception("Abstract method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        System.out.println("Abstract: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        rt = findReferenceType("Native");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            throw new Exception("Native: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        if (list.size() != 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            throw new Exception("Native: incorrect number of line locations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        if (rt.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            throw new Exception("Native: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        method = findMethod(rt, "b", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            throw new Exception("Native.b not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        list2 = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        list.removeAll(list2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // Remaining location should be in constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        if ((list.size() != 1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            !(((Location)list.get(0)).method().name().equals("<init>"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            throw new Exception("Native: line locations in wrong method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        if (method.locationsOfLine(30).size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            throw new Exception("Native method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new Exception("Native method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        method = findMethod(rt, "a", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (method.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            throw new Exception("Native method: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        System.out.println("Native: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        rt = findReferenceType("AbstractAndNative");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new Exception("AbstractAndNative: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        list = rt.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        if (list.size() != 5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            throw new Exception("AbstractAndNative: incorrect number of line locations");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        if (rt.locationsOfLine(5000).size() != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            throw new Exception("AbstractAndNative: incorrect locationsOfLine");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        method = findMethod(rt, "c", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            throw new Exception("AbstractAndNative.c not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        list2 = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        list.removeAll(list2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        // Remaining location should be in constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if ((list.size() != 1) ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            !(((Location)list.get(0)).method().name().equals("<init>"))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            throw new Exception("AbstractAndNative: line locations in wrong method");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        System.out.println("AbstractAndNative: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        // Allow application to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        resumeToVMDeath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
}