Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Event/EXCEPTION/exception001a.java
41161 views
/*1* Copyright (c) 2001, 2018, 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// THIS TEST IS LINE NUMBER SENSITIVE2425package nsk.jdwp.Event.EXCEPTION;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031import java.io.*;3233/**34* This class represents debuggee part in the test.35*/36public class exception001a {3738static final int BREAKPOINT_LINE = 102;39static final int EXCEPTION_THROW_LINE = 114;40static final int EXCEPTION_CATCH_LINE = 121; // line number was changed due to 47401234142static ArgumentHandler argumentHandler = null;43static Log log = null;4445public static void main(String args[]) {46exception001a _exception001a = new exception001a();47System.exit(exception001.JCK_STATUS_BASE + _exception001a.runIt(args, System.err));48}4950public int runIt(String args[], PrintStream out) {51//make log for debugee messages52argumentHandler = new ArgumentHandler(args);53log = new Log(out, argumentHandler);5455// create tested thread56log.display("Creating tested thread");57TestedThreadClass thread = new TestedThreadClass(exception001.TESTED_THREAD_NAME);58log.display(" ... thread created");5960// create tested exception61log.display("Creating tested exception object");62TestedThreadClass.exception = new TestedExceptionClass("tested exception");63log.display(" ... exception object created");6465// start tested thread66log.display("Starting tested thread");67thread.start();68log.display(" ... thread started");6970// wait for thread finished71try {72log.display("Waiting for tested thread finished");73thread.join();74log.display(" ... thread finished");75} catch (InterruptedException e) {76log.complain("Interruption while waiting for tested thread finished");77return exception001.FAILED;78}7980// exit debugee81log.display("Debugee PASSED");82return exception001.PASSED;83}8485// tested class86public static class TestedThreadClass extends Thread {8788// static field with tested exception object89public static volatile TestedExceptionClass exception = null;9091public TestedThreadClass(String name) {92super(name);93}9495// reach breakpoint before testing exception96public void run() {97log.display("Tested thread: started");9899log.display("Breakpoint line reached");100// next line is for breakpoint101int foo = 0; // BREAKPOINT_LINE102log.display("Breakpoint line passed");103104methodForCatch();105106log.display("Tested thread: finished");107}108109// throw tested exception110public void methodForThrow() throws TestedExceptionClass {111log.display("Throwing tested exception:\n\t" + exception);112// next line is location of exception throw113throw exception; // EXCEPTION_THROW_LINE114}115116// catch tested exception117public void methodForCatch() {118try {119methodForThrow();120} catch (TestedExceptionClass e) { // EXCEPTION_CATCH_LINE121// due to evaluation of 4740123: "the first instruction at the target122// of the exception is code to assign to the formal parameter"123log.display("Caught tested exception:\n\t" + e);124}125}126127}128129// tested exception class130public static class TestedExceptionClass extends Exception {131public TestedExceptionClass(String message) {132super(message);133}134}135}136137138