Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001.java
41161 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.jdwp.VirtualMachine.AllClassesWithGeneric;2425import java.io.*;26import java.util.*;2728import nsk.share.*;29import nsk.share.jpda.*;30import nsk.share.jdwp.*;3132/**33* This test checks that the JDWP command <code>AllClassesWithGeneric</code>34* from the <code>VirtualMachine</code> command set returns generic signature35* information properly.<br>36* Debuggee part of the test creates instances of several tested classes. Some37* of the classes are generic. Debugger part obtains signature information of38* all loaded classes by sending the tested JDWP command. Proper generic39* signature should be returned for each tested class which is generic, or40* an empty string for non-generic one. All tested classes should be found41* in reply packet as well.42*/43public class allclswithgeneric001 {44static final String DEBUGGEE_CLASS =45"nsk.jdwp.VirtualMachine.AllClassesWithGeneric.allclswithgeneric001t";4647static final String JDWP_COMMAND_NAME = "VirtualMachine.AllClassesWithGeneric";48static final int JDWP_COMMAND_ID =49JDWP.Command.VirtualMachine.AllClassesWithGeneric;5051static final String COMMAND_READY = "ready";52static final String COMMAND_QUIT = "quit";5354static final String[][] classes = {55{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001t;",56"NULL"},5758{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001b;",59"<L:Ljava/lang/String;>Ljava/lang/Object;"},6061{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001c;",62"<A:Ljava/lang/Object;B:Ljava/lang/Integer;>Ljava/lang/Object;"},6364{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001d;",65"<T:Ljava/lang/Object;>Ljava/lang/Object;Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if<TT;>;"},6667{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001e;",68"NULL"},6970{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if;",71"<I:Ljava/lang/Object;>Ljava/lang/Object;"},7273{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001f;",74"NULL"},7576{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001g;",77"<E:Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001e;:Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if;>Ljava/lang/Object;"},7879{"Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001h;",80"<A1:Ljava/lang/Object;B1:Ljava/lang/Object;C1:Ljava/lang/Object;>Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001d<TA1;>;Lnsk/jdwp/VirtualMachine/AllClassesWithGeneric/allclswithgeneric001if2<TA1;TB1;TC1;>;"}81};8283static final int CLS_NUM = classes.length;8485private int foundClasses[] = new int[CLS_NUM];8687private Log log;8889public static void main(String argv[]) {90System.exit(run(argv,System.out) + Consts.JCK_STATUS_BASE);91}9293public static int run(String argv[], PrintStream out) {94return new allclswithgeneric001().runThis(argv, out);95}9697public int runThis(String argv[], PrintStream out) {98ArgumentHandler argumentHandler = new ArgumentHandler(argv);99log = new Log(out, argumentHandler);100boolean result = true;101102try {103for(int i=0; i<CLS_NUM; i++)104foundClasses[i] = 0;105106Binder binder = new Binder(argumentHandler, log);107108log.display("Starting debuggee VM ...");109Debugee debuggee = binder.bindToDebugee(DEBUGGEE_CLASS);110111Transport transport = debuggee.getTransport();112IOPipe pipe = debuggee.createIOPipe();113114log.display("Waiting for VM_INIT event ...");115debuggee.waitForVMInit();116117log.display("Querying for IDSizes ...");118debuggee.queryForIDSizes();119120log.display("Resuming debuggee VM ...");121debuggee.resume();122123log.display("Waiting for command: " + COMMAND_READY124+ " ...");125String cmd = pipe.readln();126log.display(" ... Received command: " + cmd);127128try {129/////// begin test of JDWP command130log.display("\n>>>>>> Create command " + JDWP_COMMAND_NAME);131CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);132133log.display("Sending command packet:\n" + command);134transport.write(command);135136log.display("\nWaiting for reply packet ...");137ReplyPacket reply = new ReplyPacket();138transport.read(reply);139log.display(" ... Reply packet received:\n" + reply);140141log.display("\nChecking reply packet header");142reply.checkHeader(command.getPacketID());143144/* parsing of reply data:145int classes - Number of reference types that follow146147---- Repeated 'classes' times:148byte refTypeTag - Kind of following reference type.149referenceTypeID typeID - Loaded reference type.150string signature - The JNI signature for the loaded reference type.151string genericSignature - The generic signature for the loaded reference type152or an empty string if there is none.153int status - The current class status.154----155*/156log.display("\nParsing reply packet:");157reply.resetPosition();158159int cls_num = reply.getInt();160log.display("\tclasses: " + cls_num);161162for (int i=0; i<cls_num; i++) {163byte refTypeTag = reply.getByte();164long typeID = reply.getReferenceTypeID();165String signature = reply.getString();166String genSignature = reply.getString();167int status = reply.getInt();168169int idx = findClass(signature);170if (idx != -1) {171foundClasses[idx]++;172173log.display("\n--> found tested class "174+ classes[idx][0] + " :"175+ "\n\t\trefTypeTag: " + refTypeTag176+ "\n\t\ttypeID: " + typeID177+ "\n\t\tsignature: " + signature);178179if (genSignature.length() == 0) // a non-generic class180genSignature = "NULL";181if (!genSignature.equals(classes[idx][1])) {182log.complain("TEST FAILED: Unexpected generic signature of tested class #"183+ (i+1) + " (" + classes[idx][0] + ")"184+ " in the reply packet:"185+ "\n\tGot: " + genSignature186+ "\n\tExpected: " + classes[idx][1] + "\n");187result = false;188}189else190log.display("\t\tgeneric signature: " + genSignature);191192log.display("\t\tstatus: " + status);193}194}195196if (!reply.isParsed()) {197log.complain("TEST FAILED: Extra trailing bytes found in reply packet at: "198+ reply.currentPosition());199result = false;200} else201log.display("\n<<<<<< Reply packet parsed");202/////// end test of JDWP command203204for (int i=0; i<CLS_NUM; i++)205if (foundClasses[i] != 1) {206result = false;207log.complain("TEST FAILED: Unexpected number of reference types for the tested class\n\t"208+ classes[i][0] + "\n\tin reply packet on "209+ JDWP_COMMAND_NAME210+ ":\n\tGot: " + foundClasses[i]211+ "\n\tExpected: 1");212}213214} catch (Exception e) {215e.printStackTrace(out);216log.complain("Caught exception while testing JDWP command: "217+ e);218result = false;219} finally {220log.display("Sending command: " + COMMAND_QUIT + " ...");221pipe.println(COMMAND_QUIT);222223log.display("Waiting for debuggee exits ...");224int code = debuggee.waitFor();225if (code == Consts.JCK_STATUS_BASE + Consts.TEST_PASSED) {226log.display(" ... Debuggee PASSED with the exit code: "227+ code);228} else {229log.complain(" ... Debuggee FAILED with the exit code: "230+ code);231result = false;232}233}234235} catch (Exception e) {236e.printStackTrace(out);237log.complain("Caught unexpected exception while communicating with debugee: "238+ e);239result = false;240}241242if (!result)243return Consts.TEST_FAILED;244245return Consts.TEST_PASSED;246}247248private int findClass(String cls) {249for (int i=0; i<CLS_NUM; i++)250if (cls.equals(classes[i][0]))251return i; // the tested class found252253return -1; // the tested class not found254}255}256257258