jdk/test/com/sun/jdi/ModificationWatchpoints.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2001 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *  @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 4409582
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test all info returned by modification watchpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  @author Daniel Prusa (or someone in the FFJ group)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @author Robert Field (modified to JDIScaffold)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @library scaffold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run build JDIScaffold VMConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run compile -g ModificationWatchpoints.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  @run main/othervm ModificationWatchpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
class ModificationWatchpointsTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static final int RepeatCount = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final byte ByteVal = -17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final char CharVal = 'Y';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final short ShortVal = -412;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final int IntVal = -711618;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final long LongVal = 0x1234567890123456L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final float FloatVal = 7.986f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final double DoubleVal = 3.14159265358979d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    public static final String StringVal = "OnceMore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    public static final Object ObjectVal = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static byte sByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static char sChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static short sShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static int sInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static long sLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static float sFloat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static double sDouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    static String sString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    static Object sObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    byte iByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    char iChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    short iShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    int iInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    long iLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    float iFloat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    double iDouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    String iString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    Object iObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    void iByteSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        iByte = ByteVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    void iCharSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        iChar = CharVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    void iShortSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        iShort = ShortVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    void iIntSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        iInt = IntVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    void iLongSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        iLong = LongVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    void iFloatSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        iFloat = FloatVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    void iDoubleSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        iDouble = DoubleVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    void iStringSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        iString = StringVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    void iObjectSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        iObject = ObjectVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    static void sByteSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        sByte = ByteVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    static void sCharSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        sChar = CharVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    static void sShortSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        sShort = ShortVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    static void sIntSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        sInt = IntVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    static void sLongSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        sLong = LongVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    static void sFloatSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        sFloat = FloatVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    static void sDoubleSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        sDouble = DoubleVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    static void sStringSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        sString = StringVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    static void sObjectSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        sObject = ObjectVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    void iUpdate(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        iByteSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        iCharSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        iShortSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        iIntSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        iLongSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        iFloatSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        iDoubleSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        iStringSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        iObjectSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    static void sUpdate(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        sByteSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        sCharSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        sShortSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        sIntSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        sLongSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        sFloatSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        sDoubleSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        sStringSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        sObjectSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        ModificationWatchpointsTarg targ = new ModificationWatchpointsTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        for (int i = RepeatCount; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            sUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            targ.iUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
public class ModificationWatchpoints extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    ReferenceType targ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    List allMWP = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    ModificationWatchpoints (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        new ModificationWatchpoints(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /********** event handlers **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public void fieldModified(ModificationWatchpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        MWP mwp = (MWP)event.request().getProperty("executor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        mwp.fieldModified(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    void set(String fieldName, String valString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        Value val = targ.getValue(targ.fieldByName(valString));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        MWP mwp = new MWP("ModificationWatchpointsTarg", fieldName, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        allMWP.add(mwp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        mwp.set();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
         * Get to the top of main():
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        BreakpointEvent bpe = startToMain("ModificationWatchpointsTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        targ = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * Set watchpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        set("iByte", "ByteVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        set("iChar", "CharVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        set("iShort", "ShortVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        set("iInt", "IntVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        set("iLong", "LongVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        set("iFloat", "FloatVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        set("iDouble", "DoubleVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        set("iString", "StringVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        set("iObject", "ObjectVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        set("sByte", "ByteVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        set("sChar", "CharVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        set("sShort", "ShortVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        set("sInt", "IntVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        set("sLong", "LongVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        set("sFloat", "FloatVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        set("sDouble", "DoubleVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        set("sString", "StringVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        set("sObject", "ObjectVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
            for (Iterator it = allMWP.iterator(); it.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                MWP mwp = (MWP)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                mwp.checkEventCounts(ModificationWatchpointsTarg.RepeatCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            println("ModificationWatchpoints: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            throw new Exception("ModificationWatchpoints: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /********** request wrapper **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
    class MWP {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        private final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        private final String fieldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        private final Value expectedValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        public int eventCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        public boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        public MWP(String className, String fieldName, Value value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            this.fieldName = fieldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            this.expectedValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
         * Sets watchpoint with specified properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        public void set() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            List classes = vm().classesByName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            if (classes.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                failure("Expected one class named " + className + " got " + classes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            set ((ReferenceType)classes.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
         * Sets watchpoint for given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        public void set(ReferenceType clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            Field f = clazz.fieldByName(fieldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            ModificationWatchpointRequest mwr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                       eventRequestManager().createModificationWatchpointRequest(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            mwr.putProperty("executor", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            mwr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            println("set watchpoint: " + className +"." + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        public void fieldModified(ModificationWatchpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            Value val = event.valueToBe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
           println("Watchpoint reached: " + className + "." + fieldName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                   ", new value: " + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            if (!val.equals(expectedValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                failure("FAILURE: value should be: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                        expectedValue.getClass() + ":" + expectedValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                        " has - " + val.getClass() + ":" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            if (!event.location().method().name().equals(fieldName + "Set")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                failure("FAILURE: occurred in wrong place: " + event.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            eventCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        public void checkEventCounts(int expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            if (eventCount != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                failure(className + "." + fieldName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                        " - only got " + eventCount + " events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
    } // MWP inner class .................
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
}