0N/A/*
2362N/A * Copyright (c) 2001, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4409582
0N/A * @summary Test all info returned by modification watchpoints
0N/A *
0N/A * @author Daniel Prusa (or someone in the FFJ group)
0N/A * @author Robert Field (modified to JDIScaffold)
0N/A *
0N/A * @library scaffold
0N/A * @run build JDIScaffold VMConnection
0N/A * @run compile -g ModificationWatchpoints.java
0N/A * @run main/othervm ModificationWatchpoints
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/Aimport java.util.*;
0N/A
0N/A /********** target program **********/
0N/A
0N/Aclass ModificationWatchpointsTarg {
0N/A public static final int RepeatCount = 3;
0N/A
0N/A public static final byte ByteVal = -17;
0N/A public static final char CharVal = 'Y';
0N/A public static final short ShortVal = -412;
0N/A public static final int IntVal = -711618;
0N/A public static final long LongVal = 0x1234567890123456L;
0N/A public static final float FloatVal = 7.986f;
0N/A public static final double DoubleVal = 3.14159265358979d;
0N/A public static final String StringVal = "OnceMore";
0N/A public static final Object ObjectVal = new Object();
0N/A
0N/A static byte sByte;
0N/A static char sChar;
0N/A static short sShort;
0N/A static int sInt;
0N/A static long sLong;
0N/A static float sFloat;
0N/A static double sDouble;
0N/A static String sString;
0N/A static Object sObject;
0N/A
0N/A byte iByte;
0N/A char iChar;
0N/A short iShort;
0N/A int iInt;
0N/A long iLong;
0N/A float iFloat;
0N/A double iDouble;
0N/A String iString;
0N/A Object iObject;
0N/A
0N/A void iByteSet() {
0N/A iByte = ByteVal;
0N/A }
0N/A
0N/A void iCharSet() {
0N/A iChar = CharVal;
0N/A }
0N/A
0N/A void iShortSet() {
0N/A iShort = ShortVal;
0N/A }
0N/A
0N/A void iIntSet() {
0N/A iInt = IntVal;
0N/A }
0N/A
0N/A void iLongSet() {
0N/A iLong = LongVal;
0N/A }
0N/A
0N/A void iFloatSet() {
0N/A iFloat = FloatVal;
0N/A }
0N/A
0N/A void iDoubleSet() {
0N/A iDouble = DoubleVal;
0N/A }
0N/A
0N/A void iStringSet() {
0N/A iString = StringVal;
0N/A }
0N/A
0N/A void iObjectSet() {
0N/A iObject = ObjectVal;
0N/A }
0N/A
0N/A static void sByteSet() {
0N/A sByte = ByteVal;
0N/A }
0N/A
0N/A static void sCharSet() {
0N/A sChar = CharVal;
0N/A }
0N/A
0N/A static void sShortSet() {
0N/A sShort = ShortVal;
0N/A }
0N/A
0N/A static void sIntSet() {
0N/A sInt = IntVal;
0N/A }
0N/A
0N/A static void sLongSet() {
0N/A sLong = LongVal;
0N/A }
0N/A
0N/A static void sFloatSet() {
0N/A sFloat = FloatVal;
0N/A }
0N/A
0N/A static void sDoubleSet() {
0N/A sDouble = DoubleVal;
0N/A }
0N/A
0N/A static void sStringSet() {
0N/A sString = StringVal;
0N/A }
0N/A
0N/A static void sObjectSet() {
0N/A sObject = ObjectVal;
0N/A }
0N/A
0N/A void iUpdate(){
0N/A iByteSet();
0N/A iCharSet();
0N/A iShortSet();
0N/A iIntSet();
0N/A iLongSet();
0N/A iFloatSet();
0N/A iDoubleSet();
0N/A iStringSet();
0N/A iObjectSet();
0N/A }
0N/A
0N/A static void sUpdate(){
0N/A sByteSet();
0N/A sCharSet();
0N/A sShortSet();
0N/A sIntSet();
0N/A sLongSet();
0N/A sFloatSet();
0N/A sDoubleSet();
0N/A sStringSet();
0N/A sObjectSet();
0N/A }
0N/A
0N/A public static void main(String[] args){
0N/A ModificationWatchpointsTarg targ = new ModificationWatchpointsTarg();
0N/A for (int i = RepeatCount; i > 0; i--) {
0N/A sUpdate();
0N/A targ.iUpdate();
0N/A }
0N/A }
0N/A}
0N/A
0N/Apublic class ModificationWatchpoints extends TestScaffold {
0N/A ReferenceType targ;
0N/A List allMWP = new ArrayList();
0N/A
0N/A ModificationWatchpoints (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A new ModificationWatchpoints(args).startTests();
0N/A }
0N/A
0N/A /********** event handlers **********/
0N/A
0N/A public void fieldModified(ModificationWatchpointEvent event) {
0N/A MWP mwp = (MWP)event.request().getProperty("executor");
0N/A mwp.fieldModified(event);
0N/A }
0N/A
0N/A
0N/A /********** test core **********/
0N/A
0N/A void set(String fieldName, String valString) {
0N/A Value val = targ.getValue(targ.fieldByName(valString));
0N/A MWP mwp = new MWP("ModificationWatchpointsTarg", fieldName, val);
0N/A allMWP.add(mwp);
0N/A mwp.set();
0N/A }
0N/A
0N/A protected void runTests() throws Exception {
0N/A /*
0N/A * Get to the top of main():
0N/A */
0N/A BreakpointEvent bpe = startToMain("ModificationWatchpointsTarg");
0N/A targ = bpe.location().declaringType();
0N/A
0N/A /*
0N/A * Set watchpoints
0N/A */
0N/A set("iByte", "ByteVal");
0N/A set("iChar", "CharVal");
0N/A set("iShort", "ShortVal");
0N/A set("iInt", "IntVal");
0N/A set("iLong", "LongVal");
0N/A set("iFloat", "FloatVal");
0N/A set("iDouble", "DoubleVal");
0N/A set("iString", "StringVal");
0N/A set("iObject", "ObjectVal");
0N/A
0N/A set("sByte", "ByteVal");
0N/A set("sChar", "CharVal");
0N/A set("sShort", "ShortVal");
0N/A set("sInt", "IntVal");
0N/A set("sLong", "LongVal");
0N/A set("sFloat", "FloatVal");
0N/A set("sDouble", "DoubleVal");
0N/A set("sString", "StringVal");
0N/A set("sObject", "ObjectVal");
0N/A
0N/A listenUntilVMDisconnect();
0N/A
0N/A if (!testFailed) {
0N/A for (Iterator it = allMWP.iterator(); it.hasNext();) {
0N/A MWP mwp = (MWP)it.next();
0N/A mwp.checkEventCounts(ModificationWatchpointsTarg.RepeatCount);
0N/A }
0N/A }
0N/A
0N/A if (!testFailed) {
0N/A println("ModificationWatchpoints: passed");
0N/A } else {
0N/A throw new Exception("ModificationWatchpoints: failed");
0N/A }
0N/A }
0N/A
0N/A /********** request wrapper **********/
0N/A
0N/A class MWP {
0N/A private final String className;
0N/A private final String fieldName;
0N/A private final Value expectedValue;
0N/A public int eventCount = 0;
0N/A public boolean failed = false;
0N/A
0N/A public MWP(String className, String fieldName, Value value) {
0N/A this.className = className;
0N/A this.fieldName = fieldName;
0N/A this.expectedValue = value;
0N/A }
0N/A
0N/A /*
0N/A * Sets watchpoint with specified properties.
0N/A */
0N/A public void set() {
0N/A List classes = vm().classesByName(className);
0N/A if (classes.size() != 1) {
0N/A failure("Expected one class named " + className + " got " + classes.size());
0N/A }
0N/A
0N/A set ((ReferenceType)classes.get(0));
0N/A }
0N/A
0N/A /**
0N/A * Sets watchpoint for given class.
0N/A */
0N/A public void set(ReferenceType clazz) {
0N/A Field f = clazz.fieldByName(fieldName);
0N/A ModificationWatchpointRequest mwr =
0N/A eventRequestManager().createModificationWatchpointRequest(f);
0N/A mwr.putProperty("executor", this);
0N/A mwr.enable();
0N/A println("set watchpoint: " + className +"." + f);
0N/A }
0N/A
0N/A public void fieldModified(ModificationWatchpointEvent event) {
0N/A Value val = event.valueToBe();
0N/A println("Watchpoint reached: " + className + "." + fieldName +
0N/A ", new value: " + val);
0N/A if (!val.equals(expectedValue)) {
0N/A failure("FAILURE: value should be: " +
0N/A expectedValue.getClass() + ":" + expectedValue +
0N/A " has - " + val.getClass() + ":" + val);
0N/A }
0N/A if (!event.location().method().name().equals(fieldName + "Set")) {
0N/A failure("FAILURE: occurred in wrong place: " + event.location());
0N/A }
0N/A eventCount++;
0N/A }
0N/A
0N/A public void checkEventCounts(int expectedCount) {
0N/A if (eventCount != expectedCount) {
0N/A failure(className + "." + fieldName +
0N/A " - only got " + eventCount + " events");
0N/A }
0N/A }
0N/A
0N/A } // MWP inner class .................
0N/A}