jdk/test/com/sun/jdi/LineNumberInfo.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 2 90ce3da70b43
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1999, 2006, 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 4238644 4238643 4238641 4944198
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test javac regressions in the generation of line number info
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author Gordon Hirsch
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g LineNumberInfo.java ControlFlow.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run main LineNumberInfo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
public class LineNumberInfo extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
     * These two arrays are used to validate the line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
     * information returned by JDI. There are limitations to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
     * this approach:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
     * - there are no strict rules about
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
     *   what constitutes the "right" line number mapping, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
     *   this kind of test may have false negatives with other
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
     *   compilers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * - this test is also sensitive to the compiler's code generation;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     *   if that changes, this test will likely need updating.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * - this test assumes that JDI code index == class file
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *   byte code index which may not be true in all VMs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * - To find the values for these tables, compile ControlFlow.java and then
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     *   do:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     *   javap -classpath _jj1.solaris-sparc/JTwork/classes/com/sun/jdi \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *                    -l ControlFlow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    final int[] lineNumbers = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        15,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        16,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        19,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        20,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        22,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        25,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        26,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        28,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        33,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        34,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        36,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        37,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        36,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
        40,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        41,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        42,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        45,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        46,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        45,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
        49,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        51,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        53,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        55,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        57,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        59,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        60,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        62,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        65,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        67,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        69,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        71,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        73,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        75,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    final int[] codeIndices = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        0  ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        7  ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        15 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        22 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        33 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        43 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        50 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        60 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        68 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        76 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        77 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        85 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        93 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        96 ,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        107,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        111,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        119,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        129,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        139,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        178,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        184,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        240,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        250,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        260,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        270,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        280,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        288,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        291,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        301,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        336,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        346,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        356,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        366,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        376,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        384
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    LineNumberInfo(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    public static void main(String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        new LineNumberInfo(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        startUp("ControlFlow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // Get the ControlFlow class loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        ClassPrepareEvent event = resumeToPrepareOf("ControlFlow");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        ClassType clazz = (ClassType)event.referenceType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        Method method = clazz.concreteMethodByName("go", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        List locations = method.allLineLocations();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        if (lineNumbers.length != codeIndices.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            failure("FAILED: Bad test. Line number and code index arrays " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                 "must be equal in size");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        if (locations.size() != codeIndices.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            // Help the tester see why it failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            Iterator iter = locations.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                Location location = (Location)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                System.err.println("location=" + location);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            failure("FAILED: Bad line number table size: jdi=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                 locations.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                 ", test=" + codeIndices.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        int i = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        Iterator iter = locations.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            Location location = (Location)iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            if (location.codeIndex() != codeIndices[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                failure("FAILED: Code index mismatch: jdi=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                                    location.codeIndex() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                                    ", test=" + codeIndices[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            if (location.lineNumber() != lineNumbers[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                failure("FAILED: Line number mismatch: jdi=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                    location.lineNumber() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                                    ", test=" + lineNumbers[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            i++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        // Allow application to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            println("LineNumberInfo: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            throw new Exception("LineNumberInfo: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
}