Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/StackFrame/SetValues/setvalues001a.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.SetValues;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 setvalues001a {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[]) {56setvalues001a _setvalues001a = new setvalues001a();57System.exit(setvalues001.JCK_STATUS_BASE + _setvalues001a.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 running further70synchronized (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);7778OriginalValuesClass original = new OriginalValuesClass();79TargetValuesClass target = new TargetValuesClass();8081// start the thread and wait for notification from it82synchronized (threadReady) {83TestedObjectClass.thread.start();84try {85threadReady.wait();86// send debugger signal READY87log.display("Sending signal to debugger: " + setvalues001.READY);88pipe.println(setvalues001.READY);89} catch (InterruptedException e) {90log.complain("Interruption while waiting for thread started: " + e);91pipe.println(setvalues001.ERROR);92// exit debuggee93log.complain("Debugee FAILED");94return setvalues001.FAILED;95}96}9798// wait for signal RUN from debugeer99log.display("Waiting for signal from debugger: " + setvalues001.RUN);100String signal = pipe.readln();101log.display("Received signal from debugger: " + signal);102103// check received signal104if (signal == null || !signal.equals(setvalues001.RUN)) {105log.complain("Unexpected communication signal from debugee: " + signal106+ " (expected: " + setvalues001.RUN + ")");107// skip checking for new values108TestedObjectClass.object.checking = false;109// exit debuggee110log.complain("Debugee FAILED");111return setvalues001.FAILED;112}113114// allow started thread to run and finish115}116117// wait for tested thread finished118try {119log.display("Waiting for tested thread finished");120TestedObjectClass.thread.join();121} catch (InterruptedException e) {122log.complain("Interruption while waiting for tested thread finished:\n\t"123+ e);124// exit debuggee125log.complain("Debugee FAILED");126return setvalues001.FAILED;127}128129// confirm that new values of local variables are correct130if (TestedObjectClass.object.different == 0) {131log.display("Sending signal to debugger: " + setvalues001.DONE);132pipe.println(setvalues001.DONE);133} else {134log.complain("Values of " + TestedObjectClass.object.different +135" local variables have not been set correctly");136log.display("Sending signal to debugger: " + setvalues001.ERROR);137pipe.println(setvalues001.ERROR);138}139140// wait for signal QUIT from debugeer141log.display("Waiting for signal from debugger: " + setvalues001.QUIT);142String signal = pipe.readln();143log.display("Received signal from debugger: " + signal);144145// check received signal146if (signal == null || !signal.equals(setvalues001.QUIT)) {147log.complain("Unexpected communication signal from debugee: " + signal148+ " (expected: " + setvalues001.QUIT + ")");149// exit debuggee150log.complain("Debugee FAILED");151return setvalues001.FAILED;152}153154// exit debugee155log.display("Debugee PASSED");156return setvalues001.PASSED;157}158159// tested thread class160public static class TestedThreadClass extends Thread {161162public TestedThreadClass(String name) {163super(name);164}165166public void run() {167log.display("Tested thread started");168169// invoke tested method for the tested object from the tested thread170TestedObjectClass.object.testedMethod();171172log.display("Tested thread finished");173}174175}176177// tested object class178public static class TestedObjectClass {179180// field with the tested thread and object values181public static volatile TestedThreadClass thread = null;182public static volatile TestedObjectClass object = null;183184// allow to check new values of local variables185public volatile boolean checking = true;186// number of variables with unexpected new values187public volatile int different = 0;188189// tested method with local variables190public void testedMethod() {191192// local variables193boolean booleanValue = OriginalValuesClass.booleanValue;194byte byteValue = OriginalValuesClass.byteValue;195char charValue = OriginalValuesClass.charValue;196int intValue = OriginalValuesClass.intValue;197short shortValue = OriginalValuesClass.shortValue;198long longValue = OriginalValuesClass.longValue;199float floatValue = OriginalValuesClass.floatValue;200double doubleValue = OriginalValuesClass.doubleValue;201String stringValue = OriginalValuesClass.stringValue;202Object objectValue = OriginalValuesClass.objectValue;203204log.display("Tested frame entered");205206// notify debuggee that tested thread ready for testing207synchronized (threadReady) {208threadReady.notifyAll();209}210211// wait for lock object released212synchronized (threadLock) {213log.display("Checking that values have been set correctly:");214}215216// check new values of local variables217if (checking) {218219// check value of the variable220if (booleanValue != TargetValuesClass.booleanValue) {221different++;222log.complain(" booleanValue = " + booleanValue + "\n"223+ " setting: " + OriginalValuesClass.booleanValue224+ " -> " + TargetValuesClass.booleanValue);225if (booleanValue == OriginalValuesClass.booleanValue) {226log.complain(" not changed!");227} else {228log.complain(" changed incorrectly!");229}230} else {231log.display(" booleanValue: " + OriginalValuesClass.booleanValue232+ " -> " + TargetValuesClass.booleanValue);233}234235// check value of the variable236if (byteValue != TargetValuesClass.byteValue) {237different++;238log.complain(" byteValue = " + byteValue + "\n"239+ " setting: " + OriginalValuesClass.byteValue240+ " -> " + TargetValuesClass.byteValue);241if (byteValue == OriginalValuesClass.byteValue) {242log.complain(" not changed!");243} else {244log.complain(" changed incorrectly!");245}246} else {247log.display(" byteValue: " + OriginalValuesClass.byteValue248+ " -> " + TargetValuesClass.byteValue);249}250251// check value of the variable252if (charValue != TargetValuesClass.charValue) {253different++;254log.complain(" charValue = " + charValue + "\n"255+ " setting: " + OriginalValuesClass.charValue256+ " -> " + TargetValuesClass.charValue);257if (charValue == OriginalValuesClass.charValue) {258log.complain(" not changed!");259} else {260log.complain(" changed incorrectly!");261}262} else {263log.display(" charValue: " + OriginalValuesClass.charValue264+ " -> " + TargetValuesClass.charValue);265}266267// check value of the variable268if (intValue != TargetValuesClass.intValue) {269different++;270log.complain(" intValue = " + intValue + "\n"271+ " setting: " + OriginalValuesClass.intValue272+ " -> " + TargetValuesClass.intValue);273if (intValue == OriginalValuesClass.intValue) {274log.complain(" not changed!");275} else {276log.complain(" changed incorrectly!");277}278} else {279log.display(" intValue: " + OriginalValuesClass.intValue280+ " -> " + TargetValuesClass.intValue);281}282283// check value of the variable284if (shortValue != TargetValuesClass.shortValue) {285different++;286log.complain(" shortValue = " + shortValue + "\n"287+ " setting: " + OriginalValuesClass.shortValue288+ " -> " + TargetValuesClass.shortValue);289if (shortValue == OriginalValuesClass.shortValue) {290log.complain(" not changed!");291} else {292log.complain(" changed incorrectly!");293}294} else {295log.display(" shortValue: " + OriginalValuesClass.shortValue296+ " -> " + TargetValuesClass.shortValue);297}298299// check value of the variable300if (longValue != TargetValuesClass.longValue) {301different++;302log.complain(" longValue = " + longValue + "\n"303+ " setting: " + OriginalValuesClass.longValue304+ " -> " + TargetValuesClass.longValue);305if (longValue == OriginalValuesClass.longValue) {306log.complain(" not changed!");307} else {308log.complain(" changed incorrectly!");309}310} else {311log.display(" longValue: " + OriginalValuesClass.longValue312+ " -> " + TargetValuesClass.longValue);313}314315// check value of the variable316if (floatValue != TargetValuesClass.floatValue) {317different++;318log.complain(" floatValue = " + floatValue + "\n"319+ " setting: " + OriginalValuesClass.floatValue320+ " -> " + TargetValuesClass.floatValue);321if (floatValue == OriginalValuesClass.floatValue) {322log.complain(" not changed!");323} else {324log.complain(" changed incorrectly!");325}326} else {327log.display(" floatValue: " + OriginalValuesClass.floatValue328+ " -> " + TargetValuesClass.floatValue);329}330331// check value of the variable332if (doubleValue != TargetValuesClass.doubleValue) {333different++;334log.complain(" doubleValue = " + doubleValue + "\n"335+ " setting: " + OriginalValuesClass.doubleValue336+ " -> " + TargetValuesClass.doubleValue);337if (doubleValue == OriginalValuesClass.doubleValue) {338log.complain(" not changed!");339} else {340log.complain(" changed incorrectly!");341}342} else {343log.display(" doubleValue: " + OriginalValuesClass.doubleValue344+ " -> " + TargetValuesClass.doubleValue);345}346347// check value of the variable348if (stringValue != TargetValuesClass.stringValue) {349different++;350log.complain(" stringValue = " + stringValue + "\n"351+ " setting: " + OriginalValuesClass.stringValue352+ " -> " + TargetValuesClass.stringValue);353if (stringValue == OriginalValuesClass.stringValue) {354log.complain(" not changed!");355} else {356log.complain(" changed incorrectly!");357}358} else {359log.display(" stringValue: " + OriginalValuesClass.stringValue360+ " -> " + TargetValuesClass.stringValue);361}362363// check value of the variable364if (objectValue != TargetValuesClass.objectValue) {365different++;366log.complain(" objectValue = " + objectValue + "\n"367+ " setting: " + OriginalValuesClass.objectValue368+ " -> " + TargetValuesClass.objectValue);369if (objectValue == OriginalValuesClass.objectValue) {370log.complain(" not changed!");371} else {372log.complain(" changed incorrectly!");373}374} else {375log.display(" objectValue: " + OriginalValuesClass.objectValue376+ " -> " + TargetValuesClass.objectValue);377}378}379380log.display("Tested frame dropped");381}382383}384385// class with the original values of static fields386public static class OriginalValuesClass {387static final boolean booleanValue = true;388static final byte byteValue = (byte)0x01;389static final char charValue = 'Z';390static final int intValue = 100;391static final short shortValue = (short)10;392static final long longValue = (long)1000000;393static final float floatValue = (float)3.14;394static final double doubleValue = (double)2.8e-12;395static final String stringValue = "text";396static final Object objectValue = new OriginalValuesClass();397}398399// class with the original values of static fields400public static class TargetValuesClass {401static final boolean booleanValue = false;402static final byte byteValue = (byte)0x0F;403static final char charValue = 'A';404static final int intValue = 999;405static final short shortValue = (short)88;406static final long longValue = (long)11111111;407static final float floatValue = (float)7.19;408static final double doubleValue = (double)4.6e24;409static final String stringValue = "new text";410static final Object objectValue = new TargetValuesClass();411}412413}414415416