Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/GarbageCollectionStart/gcstart001.java
40948 views
/*1* Copyright (c) 2003, 2018, 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*/2223package nsk.jvmti.GarbageCollectionStart;2425import java.io.*;26import java.math.*;2728import nsk.share.*;2930/**31* This test exercises the JVMTI event <code>GarbageCollectionStart</code>.32* <br>It verifies that this event is always sent as a matched pair with33* <code>GarbageCollectionFinish</code>.<br>34* All GarbageCollectionStart-GarbageCollectionFinish pairs are checked35* during the events themselves and, finally, during the <code>VMDeath</code>36* event.37*/38public class gcstart001 {39/* number of interations to provoke garbage collecting */40final static int ITERATIONS = 5;4142static {43try {44System.loadLibrary("gcstart001");45} catch (UnsatisfiedLinkError ule) {46System.err.println("Could not load \"gcstart001\" library");47System.err.println("java.library.path:"48+ System.getProperty("java.library.path"));49throw ule;50}51}5253public static void main(String[] argv) {54argv = nsk.share.jvmti.JVMTITest.commonInit(argv);5556// produce JCK-like exit status57System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);58}5960public static int run(String argv[], PrintStream out) {61return new gcstart001().runThis(argv, out);62}6364private int runThis(String argv[], PrintStream out) {65try {66for (int i=0; i<ITERATIONS; i++)67ClassUnloader.eatMemory(); // provoke garbage collecting68} catch (OutOfMemoryError e) {69// ignoring70}7172return Consts.TEST_PASSED;73}74}757677