jdk/test/com/sun/jdi/redefineMethod/RedefineTest.java
author dcubed
Mon, 23 Nov 2009 10:29:33 -0700
changeset 4325 38a035021ba1
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6903102: 3/3 fixes in nightly testing version of ShellScaffold.sh need to be committed Summary: Merge Jim's ShellScaffold.sh fixes with Tim's ShellScaffold.sh fixes. Reviewed-by: tbell
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 2002 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 4628726
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Test class redefinition - method data line numbers and local vars,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *  @author Robert Field
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @library ..
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *  @run compile -g RedefineTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  @run shell RedefineSetUp.sh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  @run main RedefineTest -repeat 3
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  @run main RedefineTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    /********** target program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
class RedefineTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        RedefineSubTarg.stemcp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        RedefineSubTarg sub = new RedefineSubTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
        sub.bottom();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        RedefineSubTarg.stnemcp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        RedefineSubTarg.stemcp();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
public class RedefineTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    static int redefineRepeat = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    int bpCnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    // isObsolete, linenumber, lv name, lv value, lv isArg
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    String[] before = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    "+ 3",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    "+ 6 eights 888 T",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    "+ 11 rot 4 F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    "+ 15",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
    "+ 20 myArg 56 T paramy 12 F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    "+ 24",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    "+ 28",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    "+ 33" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    String[] after = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    "+ 5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    "O",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    "O",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    "+ 16",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    "+ 21 whoseArg 56 T parawham 12 F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    "+ 25",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    "O",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    "+ 34" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    String[] shorter = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    "+ 5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    "+ 9 eights 88 T",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    "+ 13",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    "+ 16",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    "+ 21 whoseArg 56 T parawham 12 F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    "+ 25" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    String[] refresh = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    "+ 5",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    "+ 9 eights 88 T",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    "+ 13",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
    "+ 16",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    "+ 21 whoseArg 56 T parawham 12 F",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
    "+ 25",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    "+ 29",
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    "+ 34" };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    int[] bps = {7, 12, 16, 21, 25, 30, 34};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    String[][] bpPlaces = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        {"+ 16"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        {"+ 21 myArg 56 T paramy 12 F"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        {"+ 25"},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        {"+ 34"} };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    static String[] processArgs(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        if (args.length > 0 && args[0].equals("-repeat")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            redefineRepeat = Integer.decode(args[1]).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            String[] args2 = new String[args.length - 2];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            System.arraycopy(args, 2, args2, 0, args.length - 2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            return args2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            return args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    RedefineTest (String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        new RedefineTest(processArgs(args)).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /********** event handlers **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    public void breakpointReached(BreakpointEvent event) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        println("Got BreakpointEvent - " + event);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            checkFrames(event.thread(), bpPlaces[bpCnt++]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            if (bpCnt >= bpPlaces.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                eventRequestManager().deleteAllBreakpoints();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            failure("FAIL: breakpoint checking threw " + exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
    /********** test assists **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    // isObsolete, linenumber, lv name, lv value, lv isArg
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    // equals: ref type (always), method (not obsolete)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    void checkFrames(ThreadReference thread, String[] matchList) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        for (int i = 0; i < matchList.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            String match = matchList[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            StackFrame frame = thread.frame(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            Location loc = frame.location();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            ReferenceType refType = loc.declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            Method meth = loc.method();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            String errInfo = "\nframe " + i + ": " + loc + "\n  match: " + match;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (!findReferenceType("RedefineSubTarg").equals(refType)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                 failure("FAIL: Bad reference type - " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                 return; // might be bad class, but might have run past bottom
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            StringTokenizer st = new StringTokenizer(match);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            boolean expectObs = st.nextToken().equals("O");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            println("Frame " + i + ": " + meth);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            if (meth.isObsolete()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                if (!expectObs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    failure("FAIL: Method should NOT be obsolete - " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                if (expectObs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                    failure("FAIL: Method should be obsolete - " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    break; // no more data to read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                if (!findMethod(refType, meth.name(), meth.signature()).equals(meth)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                    failure("FAIL: Non matching method - " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                int line = loc.lineNumber();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                if (line != Integer.parseInt(st.nextToken())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                    failure("FAIL: Unexpected line number: " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                // local var matching
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                int lvCnt = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                    ++lvCnt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    String lvName = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    int lvValue = Integer.parseInt(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    boolean isArg = st.nextToken().equals("T");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                    LocalVariable lv = frame.visibleVariableByName(lvName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    if (lv == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                        failure("FAIL: local var not found: '" + lvName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                "' -- " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                        Value val = frame.getValue(lv);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                        int ival = ((IntegerValue)val).value();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                        if (ival != lvValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                            failure("FAIL: expected value: '" + lvValue +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                    "' got: '" + ival + "' -- " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                        if (lv.isArgument() != isArg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                            failure("FAIL: expected argument: '" + isArg +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                                    "' got: '" + lv.isArgument() + "' -- " + errInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                List locals = frame.visibleVariables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                if (locals.size() != lvCnt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                        failure("FAIL: expected '" + lvCnt +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                                "' locals were '" + locals.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                                "' -- " + errInfo + "' -- " + locals);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    void doRedefine(String fileName) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
        File phyl = new File(fileName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        byte[] bytes = new byte[(int)phyl.length()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        InputStream in = new FileInputStream(phyl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        in.read(bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        in.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        Map map = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        map.put(findReferenceType("RedefineSubTarg"), bytes);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            for (int i = 0; i < redefineRepeat; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                vm().redefineClasses(map);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        } catch (Exception thr) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            failure("FAIL: unexpected exception: " + thr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    ThreadReference toTop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        BreakpointEvent bpe = resumeTo("RedefineSubTarg", "top", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        return bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    void setBP(int line) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            Location loc = findLocation(findReferenceType("RedefineSubTarg"), line);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            final BreakpointRequest request =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                eventRequestManager().createBreakpointRequest(loc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            request.enable();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            failure("FAIL: Attempt to set BP at line " + line + " threw " + exc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    /********** test core **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        startToMain("RedefineTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        ThreadReference thread = toTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        println("------ Before Redefine ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        checkFrames(thread, before);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        println("------ After Redefine ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        doRedefine("Different_RedefineSubTarg.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        checkFrames(thread, after);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        println("------ Static 2 ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        toTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        checkFrames(thread, shorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        println("------ Instance ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        toTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        checkFrames(thread, shorter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        println("------ Re-entered ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        toTop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        checkFrames(thread, refresh);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        println("------ Breakpoints ------");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        doRedefine("RedefineSubTarg.class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        for (int i = 0; i < bps.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            setBP(bps[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
         * resume the target listening for events
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        listenUntilVMDisconnect();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        if (bpCnt != bpPlaces.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            failure("FAIL: Wrong number of breakpoints encountered: " + bpCnt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            println("RedefineTest(method): passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throw new Exception("RedefineTest(method): failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
}