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