jdk/test/java/lang/instrument/StressGetObjectSizeApp.java
author chegar
Tue, 09 Aug 2011 16:39:04 +0100
changeset 10150 dee4cb73adc3
parent 5506 202f599c92aa
permissions -rw-r--r--
7073295: TEST_BUG: test/java/lang/instrument/ManifestTest.sh causing havoc (win) Reviewed-by: mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
282
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 282
diff changeset
     2
 * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
282
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     4
 *
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     8
 *
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    13
 * accompanied this code).
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    14
 *
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 282
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 282
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 282
diff changeset
    21
 * questions.
282
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    22
 */
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    23
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    24
import java.lang.instrument.Instrumentation;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    25
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    26
public class StressGetObjectSizeApp
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    27
    extends ASimpleInstrumentationTestCase
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    28
{
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    29
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    30
    /**
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    31
     * Constructor for StressGetObjectSizeApp.
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    32
     * @param name
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    33
     */
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    34
    public StressGetObjectSizeApp(String name)
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    35
    {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    36
        super(name);
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    37
    }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    38
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    39
    public static void
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    40
    main (String[] args)
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    41
        throws Throwable {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    42
        ATestCaseScaffold   test = new StressGetObjectSizeApp(args[0]);
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    43
        test.runTest();
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    44
    }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    45
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    46
    protected final void
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    47
    doRunTest()
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    48
        throws Throwable {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    49
        stressGetObjectSize();
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    50
    }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    51
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    52
    public void stressGetObjectSize() {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    53
        System.out.println("main: an object size=" +
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    54
            fInst.getObjectSize(new Object()));
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    55
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    56
        RoundAndRound[] threads = new RoundAndRound[10];
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    57
        for (int i = 0; i < threads.length; ++i) {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    58
            threads[i] = new RoundAndRound(fInst);
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    59
            threads[i].start();
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    60
        }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    61
        try {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    62
            Thread.sleep(500); // let all threads get going in their loops
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    63
        } catch (InterruptedException ie) {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    64
        }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    65
        System.out.println("stressGetObjectSize: returning");
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    66
        return;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    67
    }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    68
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    69
    private static class RoundAndRound extends Thread {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    70
        private final Instrumentation inst;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    71
        private final Object anObject;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    72
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    73
        public RoundAndRound(Instrumentation inst) {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    74
            this.inst = inst;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    75
            this.anObject = new Object();
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    76
            setDaemon(true);
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    77
        }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    78
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    79
        public void run() {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    80
            long sum = 0;
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    81
            while (true) {
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    82
              sum += inst.getObjectSize(anObject);
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    83
            }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    84
        }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    85
    }
bca3e5a71df1 6572160: 3/3 Instrumentation.getObjectSize triggers JVM crash in JPLISAssert in shutdown
dcubed
parents:
diff changeset
    86
}