142N/A/*
2362N/A * Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
142N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
142N/A *
142N/A * This code is free software; you can redistribute it and/or modify it
142N/A * under the terms of the GNU General Public License version 2 only, as
142N/A * published by the Free Software Foundation.
142N/A *
142N/A * This code is distributed in the hope that it will be useful, but WITHOUT
142N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
142N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
142N/A * version 2 for more details (a copy is included in the LICENSE file that
142N/A * accompanied this code).
142N/A *
142N/A * You should have received a copy of the GNU General Public License version
142N/A * 2 along with this work; if not, write to the Free Software Foundation,
142N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
142N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
142N/A */
142N/A
142N/Aimport java.lang.instrument.Instrumentation;
142N/A
142N/Apublic class StressGetObjectSizeApp
142N/A extends ASimpleInstrumentationTestCase
142N/A{
142N/A
142N/A /**
142N/A * Constructor for StressGetObjectSizeApp.
142N/A * @param name
142N/A */
142N/A public StressGetObjectSizeApp(String name)
142N/A {
142N/A super(name);
142N/A }
142N/A
142N/A public static void
142N/A main (String[] args)
142N/A throws Throwable {
142N/A ATestCaseScaffold test = new StressGetObjectSizeApp(args[0]);
142N/A test.runTest();
142N/A }
142N/A
142N/A protected final void
142N/A doRunTest()
142N/A throws Throwable {
142N/A stressGetObjectSize();
142N/A }
142N/A
142N/A public void stressGetObjectSize() {
142N/A System.out.println("main: an object size=" +
142N/A fInst.getObjectSize(new Object()));
142N/A
142N/A RoundAndRound[] threads = new RoundAndRound[10];
142N/A for (int i = 0; i < threads.length; ++i) {
142N/A threads[i] = new RoundAndRound(fInst);
142N/A threads[i].start();
142N/A }
142N/A try {
142N/A Thread.sleep(500); // let all threads get going in their loops
142N/A } catch (InterruptedException ie) {
142N/A }
142N/A System.out.println("stressGetObjectSize: returning");
142N/A return;
142N/A }
142N/A
142N/A private static class RoundAndRound extends Thread {
142N/A private final Instrumentation inst;
142N/A private final Object anObject;
142N/A
142N/A public RoundAndRound(Instrumentation inst) {
142N/A this.inst = inst;
142N/A this.anObject = new Object();
142N/A setDaemon(true);
142N/A }
142N/A
142N/A public void run() {
142N/A long sum = 0;
142N/A while (true) {
142N/A sum += inst.getObjectSize(anObject);
142N/A }
142N/A }
142N/A }
142N/A}