jdk/test/com/sun/jdi/InstancesTest.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2005-2006 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 5024119
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 *  @summary Add ReferenceType.getAllInstances () method to JDI.
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 InstancesTest.java
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 *  @run main InstancesTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *  To run this test do this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 *     runregress -no InstancesTest <cmd line options>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 *  where <cmd line options> are the options to be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 *  launch the debuggee, with the classname prefixed with @@.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *  For example, this would run java2d demo as the debuggee:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *     runregress -no InstancesTest -classpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 *                                    $jdkDir/demo/jfc/Java2D/Java2Demo.jar \
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *                                    -client @@java2d.Java2Demo
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * In this mode, the specified debuggee is launched in debug mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the debugger waits 20 secs, and then connects to the debuggee, suspends
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * it, and 'debugs' it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * If <cmd line options> is not specified, then the InstancesTarg class below
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * is run as the debuggee.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import com.sun.jdi.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import com.sun.jdi.event.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import com.sun.jdi.request.*;
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 InstancesFiller {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    // This many instances of this are created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    static int FILLER_COUNT = 200000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    static InstancesFiller[] lotsAndLots = new InstancesFiller[
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                                               InstancesFiller.FILLER_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    int xx;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    InstancesFiller(int p1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
        xx = p1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
class InstancesTarg {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
    // This many instances + 1 of this class are created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
    static int TARG_COUNT = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    static InstancesTarg theInstancesTarg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    static InstancesTarg[] allInstancesTargs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    // Each instance will point to the theInstancesTarg
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    InstancesTarg oneInstancesTarg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    public static void bkpt() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    public static void main(String[] args) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        System.out.println("Howdy!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
        for (int ii = 0; ii < InstancesFiller.lotsAndLots.length; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
            InstancesFiller.lotsAndLots[ii] = new InstancesFiller(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        theInstancesTarg = new InstancesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        allInstancesTargs = new InstancesTarg[InstancesTarg.TARG_COUNT];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        for (int ii = 0; ii < InstancesTarg.TARG_COUNT; ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            allInstancesTargs[ii] = new InstancesTarg();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            allInstancesTargs[ii].oneInstancesTarg = theInstancesTarg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        bkpt();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        System.out.println("Goodbye from InstancesTarg!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
/********** test program **********/
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
public class InstancesTest extends TestScaffold {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    static String targetName = "InstancesTarg";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
    ReferenceType targetClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
    ThreadReference mainThread;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    InstancesTest(String args[]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        super(args);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
         * If args contains @@xxxx, then that is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
         * name of the class we are to run.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        for (int ii = 0; ii < args.length; ii ++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            if (args[ii].startsWith("@@")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                targetName = args[ii] = args[ii].substring(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        new InstancesTest(args).startTests();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * Used to sort a list of ReferenceTypes by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * instance count.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    class ToSort implements Comparable<ToSort> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        long count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        ReferenceType rt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        public ToSort(long count, ReferenceType rt) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            this.count = count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            this.rt = rt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        public int compareTo(ToSort obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            if (count < obj.count) return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            if (count == obj.count) return 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected void runTests() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
         * Get to the top of main()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
         * to determine targetClass and mainThread
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        int CUT_OFF = 1000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        BreakpointEvent bpe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        bpe = startToMain(targetName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        targetClass = bpe.location().declaringType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        mainThread = bpe.thread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        if (targetName.equals("InstancesTarg")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            resumeTo("InstancesTarg", "bkpt", "()V");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            // Let debuggee run for awhile to get classes loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            vm().resume();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                System.err.println("Press <enter> to continue");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                System.in.read();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                System.err.println("running...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            vm().suspend();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        // Get all classes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        long start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        List<ReferenceType> allClasses = vm().allClasses();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        long end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        System.out.println( allClasses.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                            " classes from vm.allClasses() took " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                            (end - start) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        long[] counts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        // Test for NPE
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            boolean pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                counts = vm().instanceCounts(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            } catch (NullPointerException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            if (!pass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                failure("failure: NullPointerException not thrown on instanceCounts(null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        // Test for 0 length array
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            List<ReferenceType>someClasses = new ArrayList(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            counts = vm().instanceCounts(someClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            if (counts.length != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                failure("failure: instanceCounts with a zero length array fails: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                        counts.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        // Test various values of maxInstances
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        if (targetClass.name().equals("InstancesTarg")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            List<ObjectReference> noInstances = targetClass.instances(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            if (noInstances.size() != InstancesTarg.TARG_COUNT + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                failure("failure: instances(0): " + noInstances.size() + ", for " + targetClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            noInstances = targetClass.instances(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            if (noInstances.size() != 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
                failure("failure: instances(1): " + noInstances.size() + ", for " + targetClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            boolean pass = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                noInstances = targetClass.instances(-1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            } catch (IllegalArgumentException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                pass = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            if (!pass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                failure("failure: instances(-1) did not get an exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
        // Instance counts for all classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        counts = vm().instanceCounts(allClasses);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        if (counts.length == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            System.out.println("failure: No instances found");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            throw new Exception("InstancesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        // Create a list of ReferenceTypes sorted by instance count
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        int size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        List<ToSort> sorted = new ArrayList(allClasses.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        for (int ii = 0; ii < allClasses.size(); ii++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            System.out.println(counts[ii] + "   " + allClasses.get(ii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            size += counts[ii];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            ToSort tos = new ToSort(counts[ii], allClasses.get(ii));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            sorted.add(tos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        System.out.println("instance counts for " + counts.length +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                           " classes got " + size + " instances and took " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                            (end - start) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        boolean gotInstancesFiller = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        boolean gotInstancesTarg = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        Collections.sort(sorted);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        for (int ii = sorted.size() - 1; ii >= 0 ; ii--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            ToSort xxx = sorted.get(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            if (xxx.count <= CUT_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            if (xxx.rt.name().equals("InstancesFiller") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                xxx.count == InstancesFiller.FILLER_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                gotInstancesFiller = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            if (xxx.rt.name().equals("InstancesTarg") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                xxx.count == InstancesTarg.TARG_COUNT + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
                gotInstancesTarg = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
        if (!gotInstancesFiller) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                failure("failure: Expected " + InstancesFiller.FILLER_COUNT +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                        " instances of InstancesFiller");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (!gotInstancesTarg) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            failure("failure: Expected " + (InstancesTarg.TARG_COUNT + 1) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    " instances of InstancesTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        // Instances, one class at a time, in sorted order, printing each line
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        if (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            System.out.println("\nGetting instances for one class " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                               "at a time (limited) in sorted order");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            List<ReferenceType> rtList = new ArrayList(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            rtList.add(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            long start1 = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            size = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            long count = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            for (int ii = sorted.size() - 1; ii >= 0 ; ii--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                ToSort xxx = sorted.get(ii);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                if (xxx.count <= CUT_OFF) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                rtList.set(0, xxx.rt);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                start = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
                List<ObjectReference> oneInstances = xxx.rt.instances(19999999);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
                size += oneInstances.size();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                count++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
                System.out.println("Expected " + xxx.count + " instances, got " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                                   oneInstances.size() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
                                   " instances for " + sorted.get(ii).rt +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
                                   " in " + (end - start) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                if (xxx.rt.name().equals("InstancesFiller") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
                    oneInstances.size() != InstancesFiller.FILLER_COUNT) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    failure("failure: Expected " + InstancesFiller.FILLER_COUNT +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                            " instances of InstancesFiller");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                if (xxx.rt.name().equals("InstancesTarg") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                    oneInstances.size() != InstancesTarg.TARG_COUNT + 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                    failure("failure: Expected " + (InstancesTarg.TARG_COUNT + 1) +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                            " instances of InstancesTarg");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            end = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            System.out.println(size + " instances via making one vm.instances" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                               " call for each of " + count +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                               " classes took " + (end - start1) + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
            System.out.println("Per class = " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                               (end - start) / allClasses.size() + " ms");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
         * deal with results of test
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
         * if anything has called failure("foo") testFailed will be true
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        if (!testFailed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
            println("InstancesTest: passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            throw new Exception("InstancesTest: failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
}