Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jvmti/ClassFileLoadHook/classfloadhk002.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.ClassFileLoadHook;2425import java.io.*;2627import jdk.test.lib.Utils;28import nsk.share.*;29import nsk.share.jvmti.*;3031/**32* Debuggee class of JVMTI test.33*/34public class classfloadhk002 extends DebugeeClass {3536/** Load native library if required. */37static {38System.loadLibrary("classfloadhk002");39}4041/** Run test from command line. */42public static void main(String argv[]) {43argv = nsk.share.jvmti.JVMTITest.commonInit(argv);4445// JCK-compatible exit46System.exit(run(argv, System.out) + Consts.JCK_STATUS_BASE);47}4849/** Run test from JCK-compatible environment. */50public static int run(String argv[], PrintStream out) {51return new classfloadhk002().runIt(argv, out);52}5354/* =================================================================== */5556/* constant names */57public static final String PACKAGE_NAME = "nsk.jvmti.ClassFileLoadHook";58public static final String TESTED_CLASS_NAME = PACKAGE_NAME + ".classfloadhk002r";5960/* scaffold objects */61ArgumentHandler argHandler = null;62Log log = null;63long timeout = 0;64int status = Consts.TEST_PASSED;6566/* original bytecode of tested class */67public static byte origClassBytes[] = null;6869/** Run debuggee code. */70public int runIt(String argv[], PrintStream out) {71argHandler = new ArgumentHandler(argv);72log = new Log(out, argHandler);73timeout = argHandler.getWaitTime() * 60 * 1000; // milliseconds7475String args[] = argHandler.getArguments();76if (args.length <= 0) {77throw new Failure("Path for tested class file to load not specified");78}7980log.display("Reading original bytecode of tested class: \n\t" + TESTED_CLASS_NAME);81try {82origClassBytes = readBytes(TESTED_CLASS_NAME);83} catch (IOException e) {84throw new Failure("IOException in reading bytecode of tested class file:\n\t" + e);85}8687log.display("Sync: debugee ready to load tested class");88status = checkStatus(status);8990try {91log.display("Loading tested class: " + TESTED_CLASS_NAME);92Class testedClass = Class.forName(TESTED_CLASS_NAME);93} catch (ClassNotFoundException e) {94throw new Failure("No tested class file found: \n\t" + e);95}9697log.display("Sync: tested class loaded");98status = checkStatus(status);99100return status;101}102103/** Read classfile for class name. */104public static byte[] readBytes(String classname) throws IOException {105String filename = ClassFileFinder.findClassFile(classname, Utils.TEST_CLASS_PATH).toString();106FileInputStream in = new FileInputStream(filename);107byte[] bytes = new byte[in.available()];108in.read(bytes);109in.close();110return bytes;111}112}113114115