1 /* 2 * Copyright (c) 2013, 2015, 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 /********** LINE NUMBER SENSITIVE! *****************************************************************/ 25 26 /** 27 * @test 28 * @summary Test setting breakpoints on lambda calls 29 * 30 * @author Staffan Larsen 31 * 32 * @modules jdk.jdi 33 * @run build TestScaffold VMConnection TargetListener TargetAdapter 34 * @run compile -g LambdaBreakpointTest.java 35 * @run driver LambdaBreakpointTest 36 */ 37 import java.util.List; 38 39 import com.sun.jdi.LocalVariable; 40 import com.sun.jdi.Location; 41 import com.sun.jdi.Method; 42 import com.sun.jdi.ObjectReference; 43 import com.sun.jdi.ReferenceType; 44 import com.sun.jdi.StackFrame; 45 import com.sun.jdi.StringReference; 46 import com.sun.jdi.ThreadReference; 47 import com.sun.jdi.event.BreakpointEvent; 48 import com.sun.jdi.event.StepEvent; 49 50 /********** target program **********/ 51 52 class LambdaBreakpointTestTarg { 53 54 static int[] breakpointLines = { 55 63, 67, 64, 65, 66, 68 56 }; 57 58 public static void main(String[] args) { 59 test(); 60 } 61 62 private static void test() { 63 Runnable r = () -> { // B1: L62 64 String from = "lambda"; // B3: L63 65 System.out.println("Hello from " + from); // B4: L64 66 }; // B5: L65 67 r.run(); // B2: L66 68 System.out.println("Goodbye."); // B6: L67 69 } 70 } 71 72 73 /********** test program **********/ 74 75 public class LambdaBreakpointTest extends TestScaffold { 76 77 LambdaBreakpointTest (String args[]) { 78 super(args); 79 } 80 81 public static void main(String[] args) 82 throws Exception 83 { 84 new LambdaBreakpointTest (args).startTests(); 85 } 86 87 /********** test core **********/ 88 89 protected void runTests() 90 throws Exception 91 { 92 startToMain("LambdaBreakpointTestTarg"); 93 94 // Put a breakpoint on each location in the order they should happen 95 for (int line : LambdaBreakpointTestTarg.breakpointLines) { 96 System.out.println("Running to line: " + line); 97 BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line); 98 int stoppedAt = be.location().lineNumber(); 99 System.out.println("Stopped at line: " + stoppedAt); 100 if (stoppedAt != line) { 101 throw new Exception("Stopped on the wrong line: " 102 + stoppedAt + " != " + line); 103 } 104 } 105 106 /* 107 * resume the target listening for events 108 */ 109 listenUntilVMDisconnect(); 110 } 111 }