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 // 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 { 52 53 static int[] breakpointLines = { 54 62, 66, 63, 64, 65, 67 55 }; 56 57 public static void main(String[] args) { 58 test(); 59 } 60 61 private static void test() { 62 Runnable r = () -> { // B1: L62 63 String from = "lambda"; // B3: L63 64 System.out.println("Hello from " + from); // B4: L64 65 }; // B5: L65 66 r.run(); // B2: L66 67 System.out.println("Goodbye."); // B6: L67 68 } 69 } 70 71 72 /********** test program **********/ 73 74 public class LambdaBreakpointTest extends TestScaffold { 75 76 LambdaBreakpointTest (String args[]) { 77 super(args); 78 } 79 80 public static void main(String[] args) 81 throws Exception 82 { 83 new LambdaBreakpointTest (args).startTests(); 84 } 85 86 /********** test core **********/ 87 88 protected void runTests() 89 throws Exception 90 { 91 startToMain("LambdaBreakpointTestTarg"); 92 93 // Put a breakpoint on each location in the order they should happen 94 for (int line : LambdaBreakpointTestTarg.breakpointLines) { 95 System.out.println("Running to line: " + line); 96 BreakpointEvent be = resumeTo("LambdaBreakpointTestTarg", line); 97 int stoppedAt = be.location().lineNumber(); 98 System.out.println("Stopped at line: " + stoppedAt); 99 if (stoppedAt != line) { 100 throw new Exception("Stopped on the wrong line: " 101 + stoppedAt + " != " + line); 102 } 103 } 104 105 /* 106 * resume the target listening for events 107 */ 108 listenUntilVMDisconnect(); 109 } 110 }