test/jdk/com/sun/jdi/ModificationWatchpoints.java
author psomashe
Fri, 16 Feb 2018 11:22:53 -0800
changeset 49009 1ecb986334cb
parent 47216 71c04702a3d5
permissions -rw-r--r--
4916621: Update those still using JDIScaffold to use TestScaffold instead. Summary: update remaining tests using JDIScaffold to using TestScaffold instead. Reviewed-by: sspitsyn, cjplummer
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 24973
diff changeset
     2
 * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/**
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    25
 * @test
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    26
 * @bug 4409582
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    27
 * @summary Test all info returned by modification watchpoints
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    28
 * @author Daniel Prusa (or someone in the FFJ group)
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
    29
 * @author Robert Field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
49009
1ecb986334cb 4916621: Update those still using JDIScaffold to use TestScaffold instead.
psomashe
parents: 47216
diff changeset
    31
 * @run build TestScaffold VMConnection
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    32
 * @run compile -g ModificationWatchpoints.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    33
 * @run driver ModificationWatchpoints
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
class ModificationWatchpointsTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public static final int RepeatCount = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    public static final byte ByteVal = -17;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    public static final char CharVal = 'Y';
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static final short ShortVal = -412;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    public static final int IntVal = -711618;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    public static final long LongVal = 0x1234567890123456L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    public static final float FloatVal = 7.986f;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    public static final double DoubleVal = 3.14159265358979d;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    public static final String StringVal = "OnceMore";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public static final Object ObjectVal = new Object();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    static byte sByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    static char sChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static short sShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    static int sInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static long sLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    static float sFloat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static double sDouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static String sString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    static Object sObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    byte iByte;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    char iChar;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    short iShort;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    int iInt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    long iLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    float iFloat;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    double iDouble;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    String iString;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    Object iObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    void iByteSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        iByte = ByteVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    void iCharSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        iChar = CharVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    void iShortSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        iShort = ShortVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    void iIntSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        iInt = IntVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    void iLongSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        iLong = LongVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    void iFloatSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        iFloat = FloatVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    void iDoubleSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        iDouble = DoubleVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    void iStringSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
        iString = StringVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    void iObjectSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        iObject = ObjectVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    static void sByteSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        sByte = ByteVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    static void sCharSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        sChar = CharVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    static void sShortSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        sShort = ShortVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    static void sIntSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        sInt = IntVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    static void sLongSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        sLong = LongVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    static void sFloatSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        sFloat = FloatVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    static void sDoubleSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        sDouble = DoubleVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    static void sStringSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        sString = StringVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    static void sObjectSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        sObject = ObjectVal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    void iUpdate(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        iByteSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        iCharSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        iShortSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        iIntSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        iLongSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        iFloatSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        iDoubleSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        iStringSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        iObjectSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
    static void sUpdate(){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        sByteSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        sCharSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        sShortSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        sIntSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        sLongSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        sFloatSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        sDoubleSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        sStringSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        sObjectSet();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        ModificationWatchpointsTarg targ = new ModificationWatchpointsTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        for (int i = RepeatCount; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            sUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            targ.iUpdate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
public class ModificationWatchpoints extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    ReferenceType targ;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
    List allMWP = new ArrayList();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    ModificationWatchpoints (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        new ModificationWatchpoints(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /********** event handlers **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    public void fieldModified(ModificationWatchpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        MWP mwp = (MWP)event.request().getProperty("executor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        mwp.fieldModified(event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    void set(String fieldName, String valString) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        Value val = targ.getValue(targ.fieldByName(valString));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        MWP mwp = new MWP("ModificationWatchpointsTarg", fieldName, val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        allMWP.add(mwp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        mwp.set();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * Get to the top of main():
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        BreakpointEvent bpe = startToMain("ModificationWatchpointsTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        targ = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * Set watchpoints
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        set("iByte", "ByteVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        set("iChar", "CharVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        set("iShort", "ShortVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        set("iInt", "IntVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        set("iLong", "LongVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        set("iFloat", "FloatVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        set("iDouble", "DoubleVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        set("iString", "StringVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        set("iObject", "ObjectVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        set("sByte", "ByteVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        set("sChar", "CharVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        set("sShort", "ShortVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        set("sInt", "IntVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        set("sLong", "LongVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        set("sFloat", "FloatVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        set("sDouble", "DoubleVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        set("sString", "StringVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        set("sObject", "ObjectVal");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            for (Iterator it = allMWP.iterator(); it.hasNext();) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                MWP mwp = (MWP)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                mwp.checkEventCounts(ModificationWatchpointsTarg.RepeatCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            println("ModificationWatchpoints: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
            throw new Exception("ModificationWatchpoints: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    /********** request wrapper **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    class MWP {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        private final String className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        private final String fieldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        private final Value expectedValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        public int eventCount = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        public boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        public MWP(String className, String fieldName, Value value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            this.className = className;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            this.fieldName = fieldName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            this.expectedValue = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
         * Sets watchpoint with specified properties.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        public void set() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            List classes = vm().classesByName(className);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            if (classes.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                failure("Expected one class named " + className + " got " + classes.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            set ((ReferenceType)classes.get(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
         * Sets watchpoint for given class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        public void set(ReferenceType clazz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            Field f = clazz.fieldByName(fieldName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            ModificationWatchpointRequest mwr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                       eventRequestManager().createModificationWatchpointRequest(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            mwr.putProperty("executor", this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            mwr.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            println("set watchpoint: " + className +"." + f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        public void fieldModified(ModificationWatchpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            Value val = event.valueToBe();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
           println("Watchpoint reached: " + className + "." + fieldName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                   ", new value: " + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (!val.equals(expectedValue)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                failure("FAILURE: value should be: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                        expectedValue.getClass() + ":" + expectedValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
                        " has - " + val.getClass() + ":" + val);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (!event.location().method().name().equals(fieldName + "Set")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                failure("FAILURE: occurred in wrong place: " + event.location());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            eventCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        public void checkEventCounts(int expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            if (eventCount != expectedCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                failure(className + "." + fieldName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                        " - only got " + eventCount + " events");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    } // MWP inner class .................
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
}