Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/com/sun/jdi/AllLineLocations.java
38855 views
/*1* Copyright (c) 1999, 2000, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 424872826* @summary Test ReferenceType.allLineLocations27* @author Gordon Hirsch28*29* @run build JDIScaffold VMConnection30* @run compile -g RefTypes.java31* @run build AllLineLocations32*33* @run main AllLineLocations RefTypes34*/35import com.sun.jdi.*;36import com.sun.jdi.event.*;37import com.sun.jdi.request.*;3839import java.util.List;4041public class AllLineLocations extends JDIScaffold {42final String[] args;4344public static void main(String args[]) throws Exception {45new AllLineLocations(args).startTests();46}4748AllLineLocations(String args[]) {49super();50this.args = args;51}5253protected void runTests() throws Exception {54connect(args);55waitForVMStart();5657/*58* Get to a point where the classes are loaded.59*/60BreakpointEvent bp = resumeTo("RefTypes", "loadClasses", "()V");61stepOut(bp.thread());6263/*64* These classes should have no line numbers, except for65* one in the implicit constructor.66*/67ReferenceType rt = findReferenceType("AllAbstract");68if (rt == null) {69throw new Exception("AllAbstract: not loaded");70}71List list = rt.allLineLocations();72if (list.size() != 1) {73throw new Exception("AllAbstract: incorrect number of line locations");74}75if (rt.locationsOfLine(5000).size() != 0) {76throw new Exception("AllAbstract: incorrect locationsOfLine");77}78Method method = findMethod(rt, "<init>", "()V");79if (method == null) {80throw new Exception("AllAbstract.<init> not found");81}82List list2 = method.allLineLocations();83if (!list2.equals(list)) {84throw new Exception("AllAbstract: line locations in wrong method");85}86if (method.locationsOfLine(5000).size() != 0) {87throw new Exception("AllAbstract: incorrect locationsOfLine");88}89System.out.println("AllAbstract: passed");9091rt = findReferenceType("AllNative");92if (rt == null) {93throw new Exception("AllNative: not loaded");94}95list = rt.allLineLocations();96if (list.size() != 1) {97throw new Exception("AllNative: incorrect number of line locations");98}99if (rt.locationsOfLine(5000).size() != 0) {100throw new Exception("AllNative: incorrect locationsOfLine");101}102method = findMethod(rt, "<init>", "()V");103if (method == null) {104throw new Exception("AllNative.<init> not found");105}106list2 = method.allLineLocations();107if (!list2.equals(list)) {108throw new Exception("AllNative: line locations in wrong method");109}110if (method.locationsOfLine(5000).size() != 0) {111throw new Exception("AllNative: incorrect locationsOfLine");112}113System.out.println("AllNative: passed");114115rt = findReferenceType("Interface");116if (rt == null) {117throw new Exception("Interface: not loaded");118}119list = rt.allLineLocations();120if (list.size() != 0) {121throw new Exception("Interface: locations reported for abstract methods");122}123System.out.println("Interface: passed");124125/*126* These classes have line numbers in one method and127* in the implicit constructor.128*/129rt = findReferenceType("Abstract");130if (rt == null) {131throw new Exception("Abstract: not loaded");132}133list = rt.allLineLocations();134if (list.size() != 5) {135throw new Exception("Abstract: incorrect number of line locations");136}137method = findMethod(rt, "b", "()V");138if (method == null) {139throw new Exception("Abstract.b not found");140}141list2 = method.allLineLocations();142list.removeAll(list2);143144// Remaining location should be in constructor145if ((list.size() != 1) ||146!(((Location)list.get(0)).method().name().equals("<init>"))) {147throw new Exception("Abstract: line locations in wrong method");148}149if (method.locationsOfLine(20).size() != 1) {150throw new Exception("Abstract method: incorrect locationsOfLine");151}152if (method.locationsOfLine(5000).size() != 0) {153throw new Exception("Abstract method: incorrect locationsOfLine");154}155method = findMethod(rt, "a", "()V");156if (method.locationsOfLine(5000).size() != 0) {157throw new Exception("Abstract method: incorrect locationsOfLine");158}159System.out.println("Abstract: passed");160161rt = findReferenceType("Native");162if (rt == null) {163throw new Exception("Native: not loaded");164}165list = rt.allLineLocations();166if (list.size() != 5) {167throw new Exception("Native: incorrect number of line locations");168}169if (rt.locationsOfLine(5000).size() != 0) {170throw new Exception("Native: incorrect locationsOfLine");171}172method = findMethod(rt, "b", "()V");173if (method == null) {174throw new Exception("Native.b not found");175}176list2 = method.allLineLocations();177list.removeAll(list2);178179// Remaining location should be in constructor180if ((list.size() != 1) ||181!(((Location)list.get(0)).method().name().equals("<init>"))) {182throw new Exception("Native: line locations in wrong method");183}184if (method.locationsOfLine(30).size() != 1) {185throw new Exception("Native method: incorrect locationsOfLine");186}187if (method.locationsOfLine(5000).size() != 0) {188throw new Exception("Native method: incorrect locationsOfLine");189}190method = findMethod(rt, "a", "()V");191if (method.locationsOfLine(5000).size() != 0) {192throw new Exception("Native method: incorrect locationsOfLine");193}194System.out.println("Native: passed");195196rt = findReferenceType("AbstractAndNative");197if (rt == null) {198throw new Exception("AbstractAndNative: not loaded");199}200list = rt.allLineLocations();201if (list.size() != 5) {202throw new Exception("AbstractAndNative: incorrect number of line locations");203}204if (rt.locationsOfLine(5000).size() != 0) {205throw new Exception("AbstractAndNative: incorrect locationsOfLine");206}207method = findMethod(rt, "c", "()V");208if (method == null) {209throw new Exception("AbstractAndNative.c not found");210}211list2 = method.allLineLocations();212list.removeAll(list2);213214// Remaining location should be in constructor215if ((list.size() != 1) ||216!(((Location)list.get(0)).method().name().equals("<init>"))) {217throw new Exception("AbstractAndNative: line locations in wrong method");218}219System.out.println("AbstractAndNative: passed");220221// Allow application to complete222resumeToVMDeath();223}224}225226227