Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/CompiledMethodLoad/compmethload001.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.CompiledMethodLoad;2425import java.io.*;2627import nsk.share.*;2829/**30* This test exercises the JVMTI event <code>CompiledMethodLoad</code>.31* <br>It creates an instance of tested class 'HotClass'. Then special32* method 'hotMethod' is called in a loop in order to be compiled/inlined.33* The CompiledMethodLoad events, if they occur, must be sent only34* during the live phase of the VM execution.35*/36public class compmethload001 {37/* number of interations to provoke method compiling */38final static int ITERATIONS = 10000;3940static {41try {42System.loadLibrary("compmethload001");43} catch (UnsatisfiedLinkError ule) {44System.err.println("Could not load \"compmethload001\" library");45System.err.println("java.library.path:"46+ System.getProperty("java.library.path"));47throw ule;48}49}5051native int check();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 compmethload001().runThis(argv, out);62}6364private int runThis(String argv[], PrintStream out) {65HotClass hotCls = new HotClass(ITERATIONS);6667hotCls.entryMethod(); /* provoke method compiling */6869return check();70}7172/**73* Dummy class used only to provoke method compiling/inlining74* and, thus, CompiledMethodLoad event generation.75*/76class HotClass {77StringBuffer strBuf;78int iter;7980HotClass(int iter) {81strBuf = new StringBuffer(iter);82this.iter = iter;83}8485void entryMethod() {86for (int i=0; i<iter; i++)87hotMethod(i);88}8990void hotMethod(int i) {91strBuf.append(Integer.toString(i) + " ");92}93}94}959697