Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/ThisObject/thisobject001a.java
41162 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.StackFrame.ThisObject;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 thisobject001a {3536// name of the tested object and thread classes37public static final String OBJECT_CLASS_NAME = "TestedObjectClass";38public static final String THREAD_CLASS_NAME = "TestedThreadClass";39public static final String THREAD_NAME = "TestedThreadName";4041// name of the static fields with the tested object values42public static final String THREAD_FIELD_NAME = "thread";43public static final String OBJECT_FIELD_NAME = "object";4445// notification object to notify debuggee that thread is ready46private static Object threadReady = new Object();47// lock object to prevent thread from exit48private static Object threadLock = new Object();4950// scaffold objects51private static volatile ArgumentHandler argumentHandler = null;52private static volatile Log log = null;5354public static void main(String args[]) {55thisobject001a _thisobject001a = new thisobject001a();56System.exit(thisobject001.JCK_STATUS_BASE + _thisobject001a.runIt(args, System.err));57}5859public int runIt(String args[], PrintStream out) {60//make log for debugee messages61argumentHandler = new ArgumentHandler(args);62log = new Log(out, argumentHandler);6364// make communication pipe to debugger65log.display("Creating pipe");66IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6768// lock the object to prevent thread from exit69synchronized (threadLock) {7071// load tested class and create tested thread and object72log.display("Creating object of tested class");73TestedObjectClass.object = new TestedObjectClass();74log.display("Creating tested thread");75TestedObjectClass.thread = new TestedThreadClass(THREAD_NAME);7677// start the thread and wait for notification from it78synchronized (threadReady) {79TestedObjectClass.thread.start();80try {81threadReady.wait();82// send debugger signal READY83log.display("Sending signal to debugger: " + thisobject001.READY);84pipe.println(thisobject001.READY);85} catch (InterruptedException e) {86log.complain("Interruption while waiting for thread started: " + e);87pipe.println(thisobject001.ERROR);88}89}9091// wait for signal QUIT from debugeer92log.display("Waiting for signal from debugger: " + thisobject001.QUIT);93String signal = pipe.readln();94log.display("Received signal from debugger: " + signal);9596// check received signal97if (signal == null || !signal.equals(thisobject001.QUIT)) {98log.complain("Unexpected communication signal from debugee: " + signal99+ " (expected: " + thisobject001.QUIT + ")");100log.complain("Debugee FAILED");101return thisobject001.FAILED;102}103104// allow started thread to finish105}106107// wait for tested thread finished108try {109log.display("Waiting for tested thread finished");110TestedObjectClass.thread.join();111} catch (InterruptedException e) {112log.complain("Interruption while waiting for tested thread finished:\n\t"113+ e);114log.complain("Debugee FAILED");115return thisobject001.FAILED;116}117118// exit debugee119log.display("Debugee PASSED");120return thisobject001.PASSED;121}122123// tested thread class124public static class TestedThreadClass extends Thread {125126TestedThreadClass(String name) {127super(name);128}129130public void run() {131log.display("Tested thread started");132133// invoke tested method for the tested object from the tested thread134int foo = 100;135TestedObjectClass.object.testedMethod(foo);136137log.display("Tested thread finished");138}139140}141142// tested object class143public static class TestedObjectClass {144145// field with the tested thread and object values146public static volatile TestedThreadClass thread = null;147public static volatile TestedObjectClass object = null;148149public void testedMethod(int foo) {150log.display("Tested frame entered");151152// local variables153int boo = foo;154155// notify debuggee that tested thread ready for testing156synchronized (threadReady) {157threadReady.notifyAll();158}159160// wait for lock object released161synchronized (threadLock) {162log.display("Tested frame dropped");163}164}165166}167168}169170171