Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdwp/Method/VariableTableWithGeneric/vartblwithgen001.java
41161 views
/*1* Copyright (c) 2004, 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.Method.VariableTableWithGeneric;2425import java.io.*;2627import nsk.share.*;28import nsk.share.jpda.*;29import nsk.share.jdwp.*;3031/**32* Test for JDWP command: Method.VariableTableWithGeneric.33*34* See vartblwithgen001.README for description of test execution.35*36* This class represents debugger part of the test.37* Test is executed by invoking method runIt().38* JDWP command is tested in the method testCommand().39*40* @see #runIt()41* @see #testCommand()42*/43public class vartblwithgen001 {4445// exit status constants46static final int JCK_STATUS_BASE = 95;47static final int PASSED = 0;48static final int FAILED = 2;4950// communication signals constants51static final String READY = "ready";52static final String QUIT = "quit";5354// package and classes names constants55static final String PACKAGE_NAME = "nsk.jdwp.Method.VariableTableWithGeneric";56static final String TEST_CLASS_NAME = PACKAGE_NAME + "." + "vartblwithgen001";57static final String DEBUGEE_CLASS_NAME = TEST_CLASS_NAME + "a";5859// tested JDWP command constants60static final String JDWP_COMMAND_NAME = "Method.VariableTableWithGeneric";61static final int JDWP_COMMAND_ID = JDWP.Command.Method.VariableTableWithGeneric;6263// tested class name and signature constants64static final String TESTED_CLASS_NAME = DEBUGEE_CLASS_NAME + "$" + "TestedClass";65static final String TESTED_CLASS_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + ";";66static final String THIS_GENERIC_SIGNATURE = "L" + TESTED_CLASS_NAME.replace('.', '/') + "<TT;TN;>" + ";";6768// tested types signature conatants69static final String OBJECT_CLASS_SIGNATURE = "Ljava/lang/Object;";70static final String STRING_CLASS_SIGNATURE = "Ljava/lang/String;";717273// tested method name constant74static final String TESTED_METHOD_NAME = "testedMethod";7576// list of tested variables names and signatures77static final String variablesList[][] = {7879// synthetic arguments80{"this", TESTED_CLASS_SIGNATURE, THIS_GENERIC_SIGNATURE},8182// not generic arguments83{"arg11PrimBoolean", "Z", ""},84{"arg12PrimInt", "I", ""},85{"arg13Object", "Ljava/lang/Object;", ""},86{"arg14String", "Ljava/lang/String;", ""},87{"arg15PrimArrShort", "[S", ""},88{"arg16ObjArrObject", "[Ljava/lang/Object;", ""},8990// generic arguments91{"arg21GenObject", "Ljava/lang/Object;", "TT;"},92{"arg22GenNumber", "Ljava/lang/Number;", "TN;"},93{"arg23GenObjectArr", "[Ljava/lang/Object;", "[TT;"},94{"arg24GenNumberArr", "[Ljava/lang/Number;", "[TN;"},95{"arg25GenObjectList", "Ljava/util/List;", "Ljava/util/List<TT;>;"},96{"arg26GenNumberList", "Ljava/util/List;", "Ljava/util/List<TN;>;"},97{"arg27GenObjectDerivedList", "Ljava/util/List;", "Ljava/util/List<+TT;>;"},98{"arg28GenNumberDerivedList", "Ljava/util/List;", "Ljava/util/List<+TN;>;"},99100// not generic variables101{"var11PrimBoolean", "Z", ""},102{"var12PrimInt", "I", ""},103{"var13Object", "Ljava/lang/Object;", ""},104{"var14String", "Ljava/lang/String;", ""},105{"var15PrimArrShort", "[S", ""},106{"var16ObjArrObject", "[Ljava/lang/Object;", ""},107108// generic variables109{"var21GenObject", "Ljava/lang/Object;", "TT;"},110{"var22GenNumber", "Ljava/lang/Number;", "TN;"},111{"var23GenObjectArr", "[Ljava/lang/Object;", "[TT;"},112{"var24GenNumberArr", "[Ljava/lang/Number;", "[TN;"},113{"var25GenObjectList", "Ljava/util/List;", "Ljava/util/List<TT;>;"},114{"var26GenNumberList", "Ljava/util/List;", "Ljava/util/List<TN;>;"},115{"var27GenObjectDerivedList", "Ljava/util/List;", "Ljava/util/List<+TT;>;"},116{"var28GenNumberDerivedList", "Ljava/util/List;", "Ljava/util/List<+TN;>;"},117118};119static final int variablesCount = variablesList.length;120121// usual scaffold objects122ArgumentHandler argumentHandler = null;123Log log = null;124Binder binder = null;125Debugee debugee = null;126Transport transport = null;127IOPipe pipe = null;128129// test passed or not130boolean success = true;131132// -------------------------------------------------------------------133134/**135* Start test from command line.136*/137public static void main (String argv[]) {138System.exit(run(argv,System.out) + JCK_STATUS_BASE);139}140141/**142* Start JCK-compilant test.143*/144public static int run(String argv[], PrintStream out) {145return new vartblwithgen001().runIt(argv, out);146}147148// -------------------------------------------------------------------149150/**151* Perform test execution.152*/153public int runIt(String argv[], PrintStream out) {154155// make log for debugger messages156argumentHandler = new ArgumentHandler(argv);157log = new Log(out, argumentHandler);158159// execute test and display results160try {161log.display("\n>>> Preparing debugee for testing \n");162163// launch debuggee164binder = new Binder(argumentHandler, log);165log.display("Launching debugee");166debugee = binder.bindToDebugee(DEBUGEE_CLASS_NAME);167transport = debugee.getTransport();168pipe = debugee.createIOPipe();169170// make debuggee ready for testing171prepareDebugee();172173// work with prepared debuggee174try {175log.display("\n>>> Obtaining requred data from debugee \n");176177// query debuggee for classID of tested class178log.display("Getting classID by signature:\n"179+ " " + TESTED_CLASS_SIGNATURE);180long classID = debugee.getReferenceTypeID(TESTED_CLASS_SIGNATURE);181log.display(" got classID: " + classID);182183// query debuggee for methodID of tested method (declared in the class)184log.display("Getting methodID by name: " + TESTED_METHOD_NAME);185long methodID = debugee.getMethodID(classID, TESTED_METHOD_NAME, true);186log.display(" got methodID: " + methodID);187188// perform testing JDWP command189log.display("\n>>> Testing JDWP command \n");190testCommand(classID, methodID);191192} finally {193// quit debugee194log.display("\n>>> Finishing test \n");195quitDebugee();196}197198} catch (Failure e) {199log.complain("TEST FAILED: " + e.getMessage());200success = false;201} catch (Exception e) {202e.printStackTrace(out);203log.complain("Caught unexpected exception while running the test:\n\t" + e);204success = false;205}206207if (!success) {208log.complain("TEST FAILED");209return FAILED;210}211212out.println("TEST PASSED");213return PASSED;214215}216217/**218* Prepare debugee for testing and waiting for ready signal.219*/220void prepareDebugee() {221// wait for VM_INIT event from debugee222log.display("Waiting for VM_INIT event");223debugee.waitForVMInit();224225// query debugee for VM-dependent ID sizes226log.display("Querying for IDSizes");227debugee.queryForIDSizes();228229// resume initially suspended debugee230log.display("Resuming debugee VM");231debugee.resume();232233// wait for READY signal from debugee234log.display("Waiting for signal from debugee: " + READY);235String signal = pipe.readln();236log.display("Received signal from debugee: " + signal);237if (! signal.equals(READY)) {238throw new TestBug("Unexpected signal received from debugee: " + signal239+ " (expected: " + READY + ")");240}241}242243/**244* Sending debugee signal to quit and waiting for it exits.245*/246void quitDebugee() {247// send debugee signal to quit248log.display("Sending signal to debugee: " + QUIT);249pipe.println(QUIT);250251// wait for debugee exits252log.display("Waiting for debugee exits");253int code = debugee.waitFor();254255// analize debugee exit status code256if (code == JCK_STATUS_BASE + PASSED) {257log.display("Debugee PASSED with exit code: " + code);258} else {259log.complain("Debugee FAILED with exit code: " + code);260success = false;261}262}263264/**265* Perform testing JDWP command for specified TypeID.266*/267void testCommand(long classID, long methodID) {268// create command packet and fill requred out data269log.display("Create command packet:");270log.display("Command: " + JDWP_COMMAND_NAME);271CommandPacket command = new CommandPacket(JDWP_COMMAND_ID);272log.display(" referenceTypeID: " + classID);273command.addReferenceTypeID(classID);274log.display(" methodID: " + methodID);275command.addMethodID(methodID);276command.setLength();277278// send command packet to debugee279try {280log.display("Sending command packet:\n" + command);281transport.write(command);282} catch (IOException e) {283log.complain("Unable to send command packet:\n\t" + e);284success = false;285return;286}287288ReplyPacket reply = new ReplyPacket();289290// receive reply packet from debugee291try {292log.display("Waiting for reply packet");293transport.read(reply);294log.display("Reply packet received:\n" + reply);295} catch (IOException e) {296log.complain("Unable to read reply packet:\n\t" + e);297success = false;298return;299}300301// check reply packet header302try{303log.display("Checking reply packet header");304reply.checkHeader(command.getPacketID());305} catch (BoundException e) {306log.complain("Bad header of reply packet:\n\t" + e.getMessage());307success = false;308}309310// start parsing reply packet data311log.display("Parsing reply packet:");312reply.resetPosition();313314// clear list of found variables315int[] foundVariablesList = new int[variablesCount];316for (int i = 0; i < variablesCount; i++) {317foundVariablesList[i] = 0;318}319320// extract and check reply data321322// extract number of argumnets323int argCount = 0;324try {325argCount = reply.getInt();326log.display(" argCount: " + argCount);327} catch (BoundException e) {328log.complain("Unable to extract number of arguments from reply packet:\n\t"329+ e.getMessage());330success = false;331return;332}333334// check that number of arguments is not negative335if (argCount < 0) {336log.complain("Negative of arguments in reply packet: " + argCount);337success = false;338}339340// extract number of slots341int slots = 0;342try {343slots = reply.getInt();344log.display(" slots: " + slots);345} catch (BoundException e) {346log.complain("Unable to extract number of slots from reply packet:\n\t"347+ e.getMessage());348success = false;349return;350}351352// check that number of slots is not negative353if (slots < 0) {354log.complain("Negative value of end code index in reply packet: " + slots);355success = false;356}357358// check that start code is not less than expected359if (slots < variablesCount) {360log.complain("Number of slots (" + slots361+ ") is less than expected (" + variablesCount + ")");362success = false;363}364365// extract and check each slot attributes366for (int i = 0; i < slots; i++) {367log.display(" slot #" + i + ":");368369// extract code index of a slot370long codeIndex = 0;371try {372codeIndex = reply.getLong();373log.display(" codeIndex: " + codeIndex);374} catch (BoundException e) {375log.complain("Unable to extract code index of slot #" + i376+ " from reply packet:\n\t"377+ e.getMessage());378success = false;379return;380}381382// check that code index is not negative383if (codeIndex < 0) {384log.complain("Negative code index of slot #" + i + ":" + codeIndex);385success = false;386}387388// extract name of a slot389String name = null;390try {391name = reply.getString();392log.display(" name: " + name);393} catch (BoundException e) {394log.complain("Unable to extract name of slot #" + i395+ " from reply packet:\n\t"396+ e.getMessage());397success = false;398return;399}400401// extract signature of a slot402String signature = null;403try {404signature = reply.getString();405log.display(" signature: " + signature);406} catch (BoundException e) {407log.complain("Unable to extract signature of slot #" + i408+ " from reply packet:\n\t"409+ e.getMessage());410success = false;411return;412}413414// extract generic signature of a slot415String genericSignature = null;416try {417genericSignature = reply.getString();418log.display(" generic: " + genericSignature);419} catch (BoundException e) {420log.complain("Unable to extract generic signature of slot #" + i421+ " from reply packet:\n\t"422+ e.getMessage());423success = false;424return;425}426427// extract code length428int length = 0;429try {430length = reply.getInt();431log.display(" length: " + length);432} catch (BoundException e) {433log.complain("Unable to extract code length for slot #" + i434+ " from reply packet:\n\t"435+ e.getMessage());436success = false;437return;438}439440// extract code length441int slot = 0;442try {443slot = reply.getInt();444log.display(" slot: " + length);445} catch (BoundException e) {446log.complain("Unable to extract slot index of slot #" + i447+ " from reply packet:\n\t"448+ e.getMessage());449success = false;450return;451}452453// find slot name into list of expected variables454int found = -1;455for (int j = 0; j < variablesCount; j++) {456if (variablesList[j][0].equals(name)) {457found = j;458break;459}460}461462// check if slot is found and not duplicated463if (found >= 0) {464if (foundVariablesList[found] > 0) {465log.complain("Slot #" + i + " is duplicated "466+ foundVariablesList[found] + " times: "467+ name);468success = false;469/*470} else {471log.display("Found expected variable #" + found + ": "472+ variablesList[found][0]);473*/474}475foundVariablesList[found]++;476477// check slot signature478if (!variablesList[found][1].equals(signature)) {479log.complain("Unexpected signature for slot #" + i + ": " + signature480+ " (expected: " + variablesList[found][1] + ")");481success = false;482}483484// check slot generic signature485if (variablesList[found][2] == null && genericSignature != null) {486log.complain("Unexpected generic signature for slot #" + i + ": " + genericSignature487+ " (expected: " + variablesList[found][2] + ")");488success = false;489} else if (!variablesList[found][2].equals(genericSignature)) {490log.complain("Unexpected generic signature for slot #" + i + ": " + genericSignature491+ " (expected: " + variablesList[found][2] + ")");492success = false;493}494495} else {496log.display("Unexpected slot #" + i + " (may be synthetic): " + name);497}498499// check that code length is not negative500if (length < 0) {501log.complain("Code length for slot #" + i + " is negative: " + length);502success = false;503}504505// check that slot index is not negative506if (slot < 0) {507log.complain("Index of slot #" + i + " is negative: " + slot);508success = false;509}510}511512// check for extra data in reply packet513if (!reply.isParsed()) {514log.complain("Extra trailing bytes found in reply packet at: "515+ reply.offsetString());516success = false;517}518519// check that all expected variables found520for (int i = 0; i < variablesCount; i++) {521if (foundVariablesList[i] <= 0) {522log.complain("No slot found in reply packet for variable: "523+ variablesList[i][0]);524success = false;525}526}527528}529530}531532533