Path: blob/master/test/jdk/java/lang/instrument/GetObjectSizeTest.java
41149 views
/*1* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 488279826* @summary round-trip test for getObjectSize (does it return, and is the result non-zero?)27* @author Gabriel Adauto, Wily Technology28*29* @run build GetObjectSizeTest30* @run shell MakeJAR.sh basicAgent31* @run main/othervm -javaagent:basicAgent.jar GetObjectSizeTest GetObjectSizeTest32*/33import java.util.*;3435public class36GetObjectSizeTest37extends ASimpleInstrumentationTestCase38{3940/**41* Constructor for GetObjectSizeTest.42* @param name43*/44public GetObjectSizeTest(String name)45{46super(name);47}4849public static void50main (String[] args)51throws Throwable {52ATestCaseScaffold test = new GetObjectSizeTest(args[0]);53test.runTest();54}5556protected final void57doRunTest()58throws Throwable {59testGetObjectSize();60}6162/*63* Lame test just to show we can do the roundtrip64*/65public void66testGetObjectSize()67{68Object[] objects = new Object[] {69"Hello World",70new Integer(8),71this,72new StringBuffer("Another test object"),73new Vector(99),74// Add more objects here75};76for (int i = 0; i < objects.length; i++)77{78Object o = objects[i];79long size = fInst.getObjectSize(o);80assertTrue(size > 0);81}82}8384}858687