Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/GetValues/getvalues001a.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.GetValues;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 getvalues001a {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";44public static final String OBJECT_METHOD_NAME = "testedMethod";4546// notification object to notify debuggee that thread is ready47private static Object threadReady = new Object();48// lock object to prevent thread from exit49private static Object threadLock = new Object();5051// scaffold objects52private static volatile ArgumentHandler argumentHandler = null;53private static volatile Log log = null;5455public static void main(String args[]) {56getvalues001a _getvalues001a = new getvalues001a();57System.exit(getvalues001.JCK_STATUS_BASE + _getvalues001a.runIt(args, System.err));58}5960public int runIt(String args[], PrintStream out) {61//make log for debugee messages62argumentHandler = new ArgumentHandler(args);63log = new Log(out, argumentHandler);6465// make communication pipe to debugger66log.display("Creating pipe");67IOPipe pipe = argumentHandler.createDebugeeIOPipe(log);6869// lock the object to prevent thread from exit70synchronized (threadLock) {7172// load tested class and create tested thread and object73log.display("Creating object of tested class");74TestedObjectClass.object = new TestedObjectClass();75log.display("Creating tested thread");76TestedObjectClass.thread = new TestedThreadClass(THREAD_NAME);7778// start the thread and wait for notification from it79synchronized (threadReady) {80TestedObjectClass.thread.start();81try {82threadReady.wait();83// send debugger signal READY84log.display("Sending signal to debugger: " + getvalues001.READY);85pipe.println(getvalues001.READY);86} catch (InterruptedException e) {87log.complain("Interruption while waiting for thread started: " + e);88pipe.println(getvalues001.ERROR);89}90}9192// wait for signal QUIT from debugeer93log.display("Waiting for signal from debugger: " + getvalues001.QUIT);94String signal = pipe.readln();95log.display("Received signal from debugger: " + signal);9697// check received signal98if (signal == null || !signal.equals(getvalues001.QUIT)) {99log.complain("Unexpected communication signal from debugee: " + signal100+ " (expected: " + getvalues001.QUIT + ")");101log.complain("Debugee FAILED");102return getvalues001.FAILED;103}104105// allow started thread to finish106}107108// wait for tested thread finished109try {110log.display("Waiting for tested thread finished");111TestedObjectClass.thread.join();112} catch (InterruptedException e) {113log.complain("Interruption while waiting for tested thread finished:\n\t"114+ e);115log.complain("Debugee FAILED");116return getvalues001.FAILED;117}118119// exit debugee120log.display("Debugee PASSED");121return getvalues001.PASSED;122}123124// tested thread class125public static class TestedThreadClass extends Thread {126127TestedThreadClass(String name) {128super(name);129}130131public void run() {132log.display("Tested thread started");133134// invoke tested method for the tested object from the tested thread135TestedObjectClass.object.testedMethod();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() {150// local variables151boolean booleanValue = true;152byte byteValue = (byte)0x0F;153char charValue = 'Z';154int intValue = 100;155short shortValue = (short)10;156long longValue = (long)1000000;157float floatValue = (float)3.14;158double doubleValue = (double)2.8e-12;159Object objectValue = null;160161log.display("Tested frame entered");162163// notify debuggee that tested thread ready for testing164synchronized (threadReady) {165threadReady.notifyAll();166}167168// wait for lock object released169synchronized (threadLock) {170log.display("Tested frame dropped");171}172}173174}175176}177178179