jdk/test/com/sun/jdi/LineNumberOnBraceTest.java
author iignatyev
Mon, 03 Apr 2017 17:07:27 -0700
changeset 44529 c1e6dd7a7326
parent 30376 2ccf2cf7ea48
permissions -rw-r--r--
8177507: line number sensitive tests for jdi should be unified Reviewed-by: dholmes, mseledtsov, sspitsyn
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     1
/*
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     2
 * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     4
 *
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     7
 * published by the Free Software Foundation.
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     8
 *
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    13
 * accompanied this code).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    21
 * questions.
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    22
 */
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    23
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    24
//    THIS TEST IS LINE NUMBER SENSITIVE
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    25
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    26
/**
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    27
 * @test
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    28
 * @bug 4952629 4870514
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    29
 * @summary REGRESSION: javac generates a spurious line number entry on } else {
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    30
 * @author jjh
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    31
 *
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    32
 * @run build VMConnection TargetListener TargetAdapter
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    33
 * @run compile -g LineNumberOnBraceTest.java
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    34
 * @run driver LineNumberOnBraceTest
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
class LineNumberOnBraceTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    44
    public final static int STOP_LINE = 50;    // THIS MUST BE THE LINE NUMBER OF // STOP_LINE LINE
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    45
    public final static int STOP_LINE_2 = 56;  // THIS MUST BE THE LINE NUMBER OF // STOP_LINE_2 LINE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        if (args.length == 0) {
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    50
            System.out.println("No args to debuggee");             // STOP_LINE
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            System.out.println("Some args to debuggee");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        }
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    54
        if (args.length == 0) {                                    // STOP_LINE + 4
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            boolean b1 = false;
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    56
            if (b1) {                                              // STOP_LINE_2
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
                System.out.println("In 2nd else");                 // bug 4870514 is that we stop here.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            System.out.println("In 2nd else");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        }
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
    62
        System.out.println("Goodbye from LineNumberOnBraceTarg!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    // This isn't part of the test; it is just here
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    // so one can see what line numbers are generated for a finally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    public void exampleOfThrow() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            throw new Exception();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            System.out.println("caught exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            System.out.println("finally");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
public class LineNumberOnBraceTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    LineNumberOnBraceTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        new LineNumberOnBraceTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        BreakpointEvent bpe = startToMain("LineNumberOnBraceTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   103
        resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.STOP_LINE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        StepEvent stepev = stepOverLine(mainThread);       // step to 2nd if (args.length
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        // Bug 4952629 is that javac outputs a line number
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        // on the goto around the else which causes us to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        // be stopped at that goto instead of the println("Goodbye ...")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        int ln = stepev.location().lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        System.out.println("Debuggee is stopped at line " + ln);
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   112
        if (ln != LineNumberOnBraceTarg.STOP_LINE + 4) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            failure("FAIL: Bug 4952629: Should be at line " +
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   114
                    (LineNumberOnBraceTarg.STOP_LINE + 4) +
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                    ", am at " + ln);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            System.out.println("Passed test for 4952629");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // Test for bug 4870514
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   121
        System.out.println("Resuming to " + LineNumberOnBraceTarg.STOP_LINE_2);
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   122
        resumeTo("LineNumberOnBraceTarg", LineNumberOnBraceTarg.STOP_LINE_2);
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   123
        System.out.println("Stopped at " + LineNumberOnBraceTarg.STOP_LINE_2);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        stepev = stepOverLine(mainThread);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        ln = stepev.location().lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        System.out.println("Debuggee is stopped at line " + ln);
44529
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   127
        if (ln <= LineNumberOnBraceTarg.STOP_LINE_2 + 1) {
c1e6dd7a7326 8177507: line number sensitive tests for jdi should be unified
iignatyev
parents: 30376
diff changeset
   128
            failure("FAIL: bug 4870514: Incorrectly stopped at " + ln);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            System.out.println("Passed test for 4870514");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            println("LineNumberOnBraceTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            throw new Exception("LineNumberOnBraceTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
}