Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/ThreadReference/Frames/frames001a.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.Frames;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 frames001a {3536// name for the tested thread37public static final String THREAD_NAME = "TestedThreadName";38public static final String FIELD_NAME = "thread";39public static final String METHOD_NAME = "makeFrames";4041// frames count for tested thread in recursive method invokation42public static final int FRAMES_COUNT = 10;4344// notification object to notify debuggee that thread is ready45private static Object threadReady = new Object();46// lock object to prevent thread from exit47private static Object threadLock = new Object();4849// scaffold objects50private static volatile ArgumentHandler argumentHandler = null;51private static volatile Log log = null;5253public static void main(String args[]) {54frames001a _frames001a = new frames001a();55System.exit(frames001.JCK_STATUS_BASE + _frames001a.runIt(args, System.err));56}5758public int runIt(String args[], PrintStream out) {59//make log for debugee messages60argumentHandler = new ArgumentHandler(args);61log = new Log(out, argumentHandler);6263// make communication pipe to debugger64log.display("Creating pipe");65IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6667// lock the object to prevent thread from exit68synchronized (threadLock) {6970// load tested class and create tested thread71log.display("Creating object of tested class");72TestedClass.thread = new TestedClass(THREAD_NAME);7374// start the thread and wait for notification from it75synchronized (threadReady) {76TestedClass.thread.start();77try {78threadReady.wait();79// send debugger signal READY80log.display("Sending signal to debugger: " + frames001.READY);81pipe.println(frames001.READY);82} catch (InterruptedException e) {83log.complain("Interruption while waiting for thread started: " + e);84pipe.println(frames001.ERROR);85}86}8788// wait for signal QUIT from debugeer89log.display("Waiting for signal from debugger: " + frames001.QUIT);90String signal = pipe.readln();91log.display("Received signal from debugger: " + signal);9293// check received signal94if (signal == null || !signal.equals(frames001.QUIT)) {95log.complain("Unexpected communication signal from debugee: " + signal96+ " (expected: " + frames001.QUIT + ")");97log.display("Debugee FAILED");98return frames001.FAILED;99}100101// allow started thread to exit102}103104// exit debugee105log.display("Debugee PASSED");106return frames001.PASSED;107}108109// tested thread class110public static class TestedClass extends Thread {111112// field with the tested Thread value113public static volatile TestedClass thread = null;114115int frames = 0;116117TestedClass(String name) {118super(name);119}120121// start the thread and recursive invoke makeFrames()122public void run() {123log.display("Tested thread started");124125// make remaining frames already having one126frames = 1;127makeFrames(FRAMES_COUNT - frames);128129}130131// recursive make thread frames and notify debuggee132public void makeFrames(int count) {133frames++;134count--;135int local = frames + count;136if (count > 0) {137makeFrames(count);138} else {139log.display("Thread frames made: " + frames);140141// notify debuggee that thread ready for testing142synchronized (threadReady) {143threadReady.notifyAll();144}145146// wait for lock object released147synchronized (threadLock) {148log.display("Tested thread finished");149}150151}152}153154}155156}157158159