Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/FrameCount/framecnt001a.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*/2223package nsk.jdwp.ThreadReference.FrameCount;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdwp.*;2829import java.io.*;3031/**32* This class represents debuggee part in the test.33*/34public class framecnt001a {3536// name for the tested thread37public static final String THREAD_NAME = "TestedThreadName";38public static final String FIELD_NAME = "thread";3940// frames count for tested thread in recursive method invokation41public static final int FRAMES_COUNT = 10;4243// notification object to notify debuggee that thread is ready44private static Object threadReady = new Object();45// lock object to prevent thread from exit46private static Object threadLock = new Object();4748// scaffold objects49private static volatile ArgumentHandler argumentHandler = null;50private static volatile Log log = null;5152public static void main(String args[]) {53framecnt001a _framecnt001a = new framecnt001a();54System.exit(framecnt001.JCK_STATUS_BASE + _framecnt001a.runIt(args, System.err));55}5657public int runIt(String args[], PrintStream out) {58//make log for debugee messages59argumentHandler = new ArgumentHandler(args);60log = new Log(out, argumentHandler);6162// make communication pipe to debugger63log.display("Creating pipe");64IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6566// lock the object to prevent thread from exit67synchronized (threadLock) {6869// load tested class and create tested thread70log.display("Creating object of tested class");71TestedClass.thread = new TestedClass(THREAD_NAME);7273// start the thread and wait for notification from it74synchronized (threadReady) {75TestedClass.thread.start();76try {77threadReady.wait();78// send debugger signal READY79log.display("Sending signal to debugger: " + framecnt001.READY);80pipe.println(framecnt001.READY);81} catch (InterruptedException e) {82log.complain("Interruption while waiting for thread started: " + e);83pipe.println(framecnt001.ERROR);84}85}8687// wait for signal QUIT from debugeer88log.display("Waiting for signal from debugger: " + framecnt001.QUIT);89String signal = pipe.readln();90log.display("Received signal from debugger: " + signal);9192// check received signal93if (signal == null || !signal.equals(framecnt001.QUIT)) {94log.complain("Unexpected communication signal from debugee: " + signal95+ " (expected: " + framecnt001.QUIT + ")");96log.display("Debugee FAILED");97return framecnt001.FAILED;98}99100// allow started thread to exit101}102103// exit debugee104log.display("Debugee PASSED");105return framecnt001.PASSED;106}107108// tested thread class109public static class TestedClass extends Thread {110111// field with the tested Thread value112public static volatile TestedClass thread = null;113114int frames = 0;115116TestedClass(String name) {117super(name);118}119120// start the thread and recursive invoke makeFrames()121public void run() {122log.display("Tested thread started");123124// make remaining frames already having one125frames = 1;126makeFrames(FRAMES_COUNT - frames);127}128129// recursive make thread frames and notify debuggee130public void makeFrames(int count) {131frames++;132count--;133int local = frames + count;134if (count > 0) {135makeFrames(count);136} else {137log.display("Thread frames made: " + frames);138139// notify debuggee that thread ready for testing140synchronized (threadReady) {141threadReady.notifyAll();142}143144// wait for lock object released145synchronized (threadLock) {146log.display("Tested thread finished");147}148}149}150151}152153}154155156