author | sjiang |
Fri, 17 Jan 2014 15:58:18 +0100 | |
changeset 22295 | f140aab86aed |
parent 21371 | 8da9c7389e29 |
child 24973 | 8c4bc3fa4c4e |
permissions | -rw-r--r-- |
21371
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
1 |
/* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
4 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
8 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
13 |
* accompanied this code). |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
14 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
18 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
21 |
* questions. |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
22 |
*/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
23 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
24 |
/********** LINE NUMBER SENSITIVE! *****************************************************************/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
25 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
26 |
/** |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
27 |
* @test |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
28 |
* @summary Test setting breakpoints on lambda calls |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
29 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
30 |
* @author Staffan Larsen |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
31 |
* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
32 |
* @run build TestScaffold VMConnection TargetListener TargetAdapter |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
33 |
* @run compile -g LambdaBreakpointTest.java |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
34 |
* @run main LambdaBreakpointTest |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
35 |
*/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
36 |
import java.util.List; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
37 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
38 |
import com.sun.jdi.LocalVariable; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
39 |
import com.sun.jdi.Location; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
40 |
import com.sun.jdi.Method; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
41 |
import com.sun.jdi.ObjectReference; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
42 |
import com.sun.jdi.ReferenceType; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
43 |
import com.sun.jdi.StackFrame; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
44 |
import com.sun.jdi.StringReference; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
45 |
import com.sun.jdi.ThreadReference; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
46 |
import com.sun.jdi.event.BreakpointEvent; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
47 |
import com.sun.jdi.event.StepEvent; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
48 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
49 |
/********** target program **********/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
50 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
51 |
class LambdaBreakpointTestTarg { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
52 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
53 |
static int[] breakpointLines = { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
54 |
62, 66, 63, 64, 65, 67 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
55 |
}; |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
56 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
57 |
public static void main(String[] args) { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
58 |
test(); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
59 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
60 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
61 |
private static void test() { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
62 |
Runnable r = () -> { // B1: L62 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
63 |
String from = "lambda"; // B3: L63 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
64 |
System.out.println("Hello from " + from); // B4: L64 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
65 |
}; // B5: L65 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
66 |
r.run(); // B2: L66 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
67 |
System.out.println("Goodbye."); // B6: L67 |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
68 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
69 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
70 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
71 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
72 |
/********** test program **********/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
73 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
74 |
public class LambdaBreakpointTest extends TestScaffold { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
75 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
76 |
LambdaBreakpointTest (String args[]) { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
77 |
super(args); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
78 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
79 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
80 |
public static void main(String[] args) |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
81 |
throws Exception |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
82 |
{ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
83 |
new LambdaBreakpointTest (args).startTests(); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
84 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
85 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
86 |
/********** test core **********/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
87 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
88 |
protected void runTests() |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
89 |
throws Exception |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
90 |
{ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
91 |
startToMain("LambdaBreakpointTestTarg"); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
92 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
93 |
// Put a breakpoint on each location in the order they should happen |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
94 |
for (int line : LambdaBreakpointTestTarg.breakpointLines) { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
95 |
System.out.println("Running to line: " + line); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
96 |
BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
97 |
int stoppedAt = be.location().lineNumber(); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
98 |
System.out.println("Stopped at line: " + stoppedAt); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
99 |
if (stoppedAt != line) { |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
100 |
throw new Exception("Stopped on the wrong line: " |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
101 |
+ stoppedAt + " != " + line); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
102 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
103 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
104 |
|
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
105 |
/* |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
106 |
* resume the target listening for events |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
107 |
*/ |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
108 |
listenUntilVMDisconnect(); |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
109 |
} |
8da9c7389e29
8027371: Add JDI tests for breakpointing and stepping in lambda code
sla
parents:
diff
changeset
|
110 |
} |