Path: blob/master/test/jdk/java/lang/instrument/ManyMethodsBenchmarkAgent.java
41149 views
/*1* Copyright (c) 2015, 2016, 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 804624626* @summary Tests and benchmarks the JVMTI RedefineClasses when a27* single class (and its parent) contains many methods.28*29* @modules jdk.compiler30* java.instrument31* jdk.zipfs32* @run build ManyMethodsBenchmarkApp ManyMethodsBenchmarkAgent33* @run shell MakeJAR3.sh ManyMethodsBenchmarkAgent 'Can-Retransform-Classes: true'34* @run main/othervm -javaagent:ManyMethodsBenchmarkAgent.jar ManyMethodsBenchmarkApp35*/36import java.lang.instrument.*;3738public class ManyMethodsBenchmarkAgent39{40public static boolean fail = false;41public static boolean completed = false;42private static Instrumentation instrumentation;4344public static void45premain( String agentArgs,46Instrumentation instrumentation) {47System.out.println("ManyMethodsBenchmarkAgent started");48ManyMethodsBenchmarkAgent.instrumentation = instrumentation;49System.out.println("ManyMethodsBenchmarkAgent finished");50}5152static void instr() {53System.out.println("ManyMethodsBenchmarkAgent.instr started");5455Class[] allClasses = instrumentation.getAllLoadedClasses();5657for (int i = 0; i < allClasses.length; i++) {58Class klass = allClasses[i];59String name = klass.getName();60if (!name.equals("Base")) {61continue;62}63System.err.println("Instrumenting the class: " + klass);6465try {66instrumentation.retransformClasses(klass);67} catch (Throwable e) {68System.err.println("Error: bad return from retransform: " + klass);69System.err.println(" ERROR: " + e);70fail = true;71}72}73completed = true;74System.out.println("ManyMethodsBenchmarkAgent.instr finished");75}7677}787980