1 /* 2 * Copyright (c) 1999, 2018, 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 /** 25 * @test 26 * @bug 4248728 27 * @summary Test ReferenceType.allLineLocations 28 * @author Gordon Hirsch 29 * 30 * @run build TestScaffold VMConnection 31 * @run compile -g RefTypes.java 32 * @run build AllLineLocations 33 * 34 * @run driver AllLineLocations RefTypes 35 */ 36 import com.sun.jdi.*; 37 import com.sun.jdi.event.*; 38 import com.sun.jdi.request.*; 39 40 import java.util.List; 41 42 public class AllLineLocations extends TestScaffold { 43 main(String args[])44 public static void main(String args[]) throws Exception { 45 new AllLineLocations(args).startTests(); 46 } 47 AllLineLocations(String args[])48 AllLineLocations(String args[]) { 49 super(args); 50 } 51 runTests()52 protected void runTests() throws Exception { 53 54 /* 55 * Get to a point where the classes are loaded. 56 */ 57 BreakpointEvent bp = startTo("RefTypes", "loadClasses", "()V"); 58 stepOut(bp.thread()); 59 60 /* 61 * These classes should have no line numbers, except for 62 * one in the implicit constructor. 63 */ 64 ReferenceType rt = findReferenceType("AllAbstract"); 65 if (rt == null) { 66 throw new Exception("AllAbstract: not loaded"); 67 } 68 List list = rt.allLineLocations(); 69 if (list.size() != 1) { 70 throw new Exception("AllAbstract: incorrect number of line locations"); 71 } 72 if (rt.locationsOfLine(5000).size() != 0) { 73 throw new Exception("AllAbstract: incorrect locationsOfLine"); 74 } 75 Method method = findMethod(rt, "<init>", "()V"); 76 if (method == null) { 77 throw new Exception("AllAbstract.<init> not found"); 78 } 79 List list2 = method.allLineLocations(); 80 if (!list2.equals(list)) { 81 throw new Exception("AllAbstract: line locations in wrong method"); 82 } 83 if (method.locationsOfLine(5000).size() != 0) { 84 throw new Exception("AllAbstract: incorrect locationsOfLine"); 85 } 86 System.out.println("AllAbstract: passed"); 87 88 rt = findReferenceType("AllNative"); 89 if (rt == null) { 90 throw new Exception("AllNative: not loaded"); 91 } 92 list = rt.allLineLocations(); 93 if (list.size() != 1) { 94 throw new Exception("AllNative: incorrect number of line locations"); 95 } 96 if (rt.locationsOfLine(5000).size() != 0) { 97 throw new Exception("AllNative: incorrect locationsOfLine"); 98 } 99 method = findMethod(rt, "<init>", "()V"); 100 if (method == null) { 101 throw new Exception("AllNative.<init> not found"); 102 } 103 list2 = method.allLineLocations(); 104 if (!list2.equals(list)) { 105 throw new Exception("AllNative: line locations in wrong method"); 106 } 107 if (method.locationsOfLine(5000).size() != 0) { 108 throw new Exception("AllNative: incorrect locationsOfLine"); 109 } 110 System.out.println("AllNative: passed"); 111 112 rt = findReferenceType("Interface"); 113 if (rt == null) { 114 throw new Exception("Interface: not loaded"); 115 } 116 list = rt.allLineLocations(); 117 if (list.size() != 0) { 118 throw new Exception("Interface: locations reported for abstract methods"); 119 } 120 System.out.println("Interface: passed"); 121 122 /* 123 * These classes have line numbers in one method and 124 * in the implicit constructor. 125 */ 126 rt = findReferenceType("Abstract"); 127 if (rt == null) { 128 throw new Exception("Abstract: not loaded"); 129 } 130 list = rt.allLineLocations(); 131 if (list.size() != 5) { 132 throw new Exception("Abstract: incorrect number of line locations"); 133 } 134 method = findMethod(rt, "b", "()V"); 135 if (method == null) { 136 throw new Exception("Abstract.b not found"); 137 } 138 list2 = method.allLineLocations(); 139 list.removeAll(list2); 140 141 // Remaining location should be in constructor 142 if ((list.size() != 1) || 143 !(((Location)list.get(0)).method().name().equals("<init>"))) { 144 throw new Exception("Abstract: line locations in wrong method"); 145 } 146 if (method.locationsOfLine(20).size() != 1) { 147 throw new Exception("Abstract method: incorrect locationsOfLine"); 148 } 149 if (method.locationsOfLine(5000).size() != 0) { 150 throw new Exception("Abstract method: incorrect locationsOfLine"); 151 } 152 method = findMethod(rt, "a", "()V"); 153 if (method.locationsOfLine(5000).size() != 0) { 154 throw new Exception("Abstract method: incorrect locationsOfLine"); 155 } 156 System.out.println("Abstract: passed"); 157 158 rt = findReferenceType("Native"); 159 if (rt == null) { 160 throw new Exception("Native: not loaded"); 161 } 162 list = rt.allLineLocations(); 163 if (list.size() != 5) { 164 throw new Exception("Native: incorrect number of line locations"); 165 } 166 if (rt.locationsOfLine(5000).size() != 0) { 167 throw new Exception("Native: incorrect locationsOfLine"); 168 } 169 method = findMethod(rt, "b", "()V"); 170 if (method == null) { 171 throw new Exception("Native.b not found"); 172 } 173 list2 = method.allLineLocations(); 174 list.removeAll(list2); 175 176 // Remaining location should be in constructor 177 if ((list.size() != 1) || 178 !(((Location)list.get(0)).method().name().equals("<init>"))) { 179 throw new Exception("Native: line locations in wrong method"); 180 } 181 if (method.locationsOfLine(30).size() != 1) { 182 throw new Exception("Native method: incorrect locationsOfLine"); 183 } 184 if (method.locationsOfLine(5000).size() != 0) { 185 throw new Exception("Native method: incorrect locationsOfLine"); 186 } 187 method = findMethod(rt, "a", "()V"); 188 if (method.locationsOfLine(5000).size() != 0) { 189 throw new Exception("Native method: incorrect locationsOfLine"); 190 } 191 System.out.println("Native: passed"); 192 193 rt = findReferenceType("AbstractAndNative"); 194 if (rt == null) { 195 throw new Exception("AbstractAndNative: not loaded"); 196 } 197 list = rt.allLineLocations(); 198 if (list.size() != 5) { 199 throw new Exception("AbstractAndNative: incorrect number of line locations"); 200 } 201 if (rt.locationsOfLine(5000).size() != 0) { 202 throw new Exception("AbstractAndNative: incorrect locationsOfLine"); 203 } 204 method = findMethod(rt, "c", "()V"); 205 if (method == null) { 206 throw new Exception("AbstractAndNative.c not found"); 207 } 208 list2 = method.allLineLocations(); 209 list.removeAll(list2); 210 211 // Remaining location should be in constructor 212 if ((list.size() != 1) || 213 !(((Location)list.get(0)).method().name().equals("<init>"))) { 214 throw new Exception("AbstractAndNative: line locations in wrong method"); 215 } 216 System.out.println("AbstractAndNative: passed"); 217 218 // Allow application to complete 219 resumeToVMDisconnect(); 220 } 221 } 222