jdk/test/com/sun/jdi/Vars.java
author iignatyev
Wed, 15 Mar 2017 22:48:59 -0700
changeset 44423 306c020eb154
parent 30964 613fbce96e32
permissions -rw-r--r--
8176176: fix @modules in jdk_svc tests Reviewed-by: shurailine, sspitsyn
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) 2000, 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
 * @summary Test Method.variables() and the like.
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    27
 * @author Robert Field
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *
44423
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    29
 * @run build JDIScaffold VMConnection
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    30
 * @run compile -g Vars.java
306c020eb154 8176176: fix @modules in jdk_svc tests
iignatyev
parents: 30964
diff changeset
    31
 * @run driver Vars
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * This class is internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
abstract class AbstractTestVars {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
    abstract float test1(String blah, int i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    native int test2(double k, boolean b);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    String test3(short sh, long lo) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        String st = "roses";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        return st;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * This class is internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
class TestVars extends AbstractTestVars {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
    float test1(String blah, int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
        return (float)1.1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    void hi() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        new TestVars().hi();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * "Vars" test runs TestVars and makes LocalVariable queries
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
public class Vars extends JDIScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    final String[] args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    Vars(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.args = args;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        new Vars(args).runTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    static final int VARIABLES = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static final int BYNAME = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    static final int ARGUMENTS = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    String testCase(Method method, int which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            List vars;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            switch (which) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                case VARIABLES:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    vars = method.variables();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                case BYNAME:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                    vars = method.variablesByName("st");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                case ARGUMENTS:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    vars = method.arguments();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    throw new InternalException("should not happen");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            StringBuffer sb = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            for (Iterator it = vars.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
                LocalVariable lv = (LocalVariable)it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                if (sb.length() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    sb.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
                sb.append(lv.name());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        } catch (Exception exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            String st = exc.getClass().getName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            int inx = st.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return st.substring(inx+1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Sets failed if fails.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    void test(Method method, int which, String name, String expected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        String got = testCase(method, which);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        if (got.equals(expected)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            System.out.println(name + ": got expected: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            System.out.println(name + ": ERROR expected: " + expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            System.out.println("      got: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    void test2(Method method, int which, String name, String expected, String expected2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        String got = testCase(method, which);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        if (got.equals(expected) || got.equals(expected2)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            System.out.println(name + ": got expected: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            System.out.println(name + ": ERROR expected: " + expected);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            System.out.println("      got: " + got);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        List argList = new ArrayList(Arrays.asList(args));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        argList.add("TestVars");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        System.out.println("run args: " + argList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        connect((String[])argList.toArray(args));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        waitForVMStart();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
         * Get to a point where the classes are loaded.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        BreakpointEvent bp = resumeTo("TestVars", "hi", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
         * These classes should have no line numbers, except for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
         * one in the implicit constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        ReferenceType rt = findReferenceType("AbstractTestVars");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (rt == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            throw new Exception("AbstractTestVars: not loaded");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        Method method = findMethod(rt, "test1", "(Ljava/lang/String;I)F");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        test(method, VARIABLES, "abstract/variables",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        test(method, BYNAME, "abstract/variablesByName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        test(method, ARGUMENTS, "abstract/arguments",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        method = findMethod(rt, "test2", "(DZ)I");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        test(method, VARIABLES, "native/variables",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
        test(method, BYNAME, "native/variablesByName",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        test(method, ARGUMENTS, "native/arguments",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
             "AbsentInformationException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        method = findMethod(rt, "test3", "(SJ)Ljava/lang/String;");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        if (method == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throw new Exception("Method not found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        // javac can put these in whatever order it desires.  hopper
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        // does it one way and mantis another.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        test2(method, VARIABLES, "normal/variables", "sh,lo,st", "st,sh,lo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        test(method, BYNAME, "normal/variablesByName", "st");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        test(method, ARGUMENTS, "normal/arguments", "sh,lo");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        // Allow application to complete
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        resumeToVMDeath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        if (failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throw new Exception("Vars: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            System.out.println("Vars: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
}