Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/AttachOnDemand/attach009/attach009Target.java
40951 views
/*1* Copyright (c) 2007, 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*/22package nsk.jvmti.AttachOnDemand.attach009;2324import nsk.share.aod.TargetApplicationWaitingAgents;2526class FirstLoadedClass {2728}2930class ClassToLoad0 {3132}3334class ClassToLoad1 {3536}3738class ClassToLoad2 {3940}4142class LastLoadedClass {4344}4546public class attach009Target extends TargetApplicationWaitingAgents {4748private void loadClass(String className) {49try {50Class.forName(className, true, this.getClass().getClassLoader());51} catch (Throwable t ){52setStatusFailed("Unexpected exception during class loading: " + t);53t.printStackTrace(log.getOutStream());54}55}5657class ClassLoadingThread extends Thread {5859String className;6061ClassLoadingThread(String className) {62this.className = className;63}6465public void run() {66log.display(Thread.currentThread() + " is loading class '" + className + "'");67loadClass(className);68}69}7071protected void targetApplicationActions() throws Throwable {72/*73* Test checks that ClassLoad event can be enabled only for one thread74* (for target application thread executing method targetApplicationActions()).75*76* Method targetApplicationActions() does following:77* - loads class 'FirstLoadedClass', after this ClassLoad evens enabled only for the current thread78* - starts several threads loading classes (for these threads ClassLoad events shoudn't be generated)79* - loads class 'LastLoadedClass', after this test agent should finish work80*/8182ClassLoadingThread classLoadingThreads[] = new ClassLoadingThread[3];83for (int i = 0; i < classLoadingThreads.length; i++) {84classLoadingThreads[i] = new ClassLoadingThread("nsk.jvmti.AttachOnDemand.attach009.ClassToLoad" + i);85classLoadingThreads[i].setName("ClassLoadingThread-" + i);86}8788loadClass("nsk.jvmti.AttachOnDemand.attach009.FirstLoadedClass");8990for (ClassLoadingThread classLoadingThread : classLoadingThreads)91classLoadingThread.start();9293for (ClassLoadingThread classLoadingThread : classLoadingThreads)94classLoadingThread.join();9596loadClass("nsk.jvmti.AttachOnDemand.attach009.LastLoadedClass");97}9899public static void main(String[] args) {100new attach009Target().runTargetApplication(args);101}102}103104105