jdk/test/com/sun/jdi/AnyDebuggeeTest.java
author sjiang
Fri, 17 Jan 2014 15:58:18 +0100
changeset 22295 f140aab86aed
parent 5506 202f599c92aa
child 24973 8c4bc3fa4c4e
permissions -rw-r--r--
8029378: com/sun/jdi/BadHandshakeTest.java failed with java.util.concurrent.TimeoutException Reviewed-by: dholmes, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2005, 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
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 *  @bug 6224700
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary ReferenceType.nestedTypes() is too slow
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *  @author jjh
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *  @run build TestScaffold VMConnection TargetListener TargetAdapter
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 *  @run compile -g AnyDebuggeeTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main AnyDebuggeeeTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *  This test is intended to be run manually to investigate behaviors;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *  it is not an actual test of any specific functionality, it just
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  allows you to run the debugger part of this test on any debuggee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *  As set up, it prints the time to find all nested types and all
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *  subclasses in the debuggee, and so can be used to verify the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  fix for 6224700.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  For other investigations, edit this test to do whatever you want.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *  To run this test do this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *     runregress -no AnyDebuggeeTest <cmd line options>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  where <cmd line options> are the options to be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *  launch the debuggee, with the classname prefixed with @@.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *  For example, this would run java2d demo as the debuggee:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 *     runregress -no AnyDebuggeeTest -classpath $jdkDir/demo/jfc/Java2D/Java2Demo.jar \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 *                                    -client @@java2d.Java2Demo'
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * If <cmd line options> is not specified, then the AnyDebuggeeTarg class below
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * is run as the debuggee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import com.sun.jdi.request.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import javax.swing.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
class AnyDebuggeeTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    public static void main(String[] args){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
            javax.swing.UIManager.setLookAndFeel( javax.swing.UIManager.getSystemLookAndFeelClassName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } catch( Throwable exc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        JFrame f = new JFrame("JFrame");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
            Thread.sleep(60000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        } catch (InterruptedException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        System.out.println("Goodbye from NestedClassesTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
public class AnyDebuggeeTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static String targetName = "AnyDebuggeeTarg";
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    AnyDebuggeeTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static void main(String[] args)      throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
         * If args contains @@xxxx, then that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
         * name of the class we are to run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        for (int ii = 0; ii < args.length; ii ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (args[ii].startsWith("@@")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                targetName = args[ii] = args[ii].substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        new AnyDebuggeeTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        BreakpointEvent bpe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        bpe = startToMain(targetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // Let debuggee run for awhile to get classes loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        resumeForMsecs(20000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        List<ReferenceType> allClasses = vm().allClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        System.out.println( allClasses.size() + " classes");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        for(ReferenceType rt: allClasses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            if (rt instanceof ClassType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            List<ReferenceType> nested = rt.nestedTypes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            int sz = nested.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            size += sz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        long end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        System.out.println(size + " nested types took " + (end - start) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        for(ReferenceType rt: allClasses) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            if (rt instanceof ClassType) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                List<ClassType> subs = ((ClassType)rt).subclasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                int sz = subs.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                size += sz;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        System.out.println(size + " subclasses took " + (end - start) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            println("AnyDebuggeeTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw new Exception("AnyDebuggeeTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
}