Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Field/isTransient/istrans001.java
41161 views
/*1* Copyright (c) 2000, 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*/222324package nsk.jdi.Field.isTransient;2526import nsk.share.*;27import nsk.share.jpda.*;28import nsk.share.jdi.*;2930import com.sun.jdi.*;31import java.util.*;32import java.io.*;3334public class istrans001 {35final static String IS_TRANS = "transient";36final static String NOT_TRANS = "";37final static int TOTAL_FIELDS = 216;38final static String FIELDS_TYPE_NAME[][] = {39{"z0", NOT_TRANS},40{"z1", NOT_TRANS},41{"z2", NOT_TRANS},42{"b0", NOT_TRANS},43{"b1", NOT_TRANS},44{"b2", NOT_TRANS},45{"c0", NOT_TRANS},46{"c1", NOT_TRANS},47{"c2", NOT_TRANS},48{"d0", NOT_TRANS},49{"d1", NOT_TRANS},50{"d2", NOT_TRANS},51{"f0", NOT_TRANS},52{"f1", NOT_TRANS},53{"f2", NOT_TRANS},54{"i0", NOT_TRANS},55{"i1", NOT_TRANS},56{"i2", NOT_TRANS},57{"l0", NOT_TRANS},58{"l1", NOT_TRANS},59{"l2", NOT_TRANS},6061{"z0T", IS_TRANS},62{"z1T", IS_TRANS},63{"z2T", IS_TRANS},64{"b0T", IS_TRANS},65{"b1T", IS_TRANS},66{"b2T", IS_TRANS},67{"c0T", IS_TRANS},68{"c1T", IS_TRANS},69{"c2T", IS_TRANS},70{"d0T", IS_TRANS},71{"d1T", IS_TRANS},72{"d2T", IS_TRANS},73{"f0T", IS_TRANS},74{"f1T", IS_TRANS},75{"f2T", IS_TRANS},76{"i0T", IS_TRANS},77{"i1T", IS_TRANS},78{"i2T", IS_TRANS},79{"l0T", IS_TRANS},80{"l1T", IS_TRANS},81{"l2T", IS_TRANS},8283{"lS0", NOT_TRANS},84{"lS1", NOT_TRANS},85{"lS2", NOT_TRANS},86{"lP0", NOT_TRANS},87{"lP1", NOT_TRANS},88{"lP2", NOT_TRANS},89{"lU0", NOT_TRANS},90{"lU1", NOT_TRANS},91{"lU2", NOT_TRANS},92{"lR0", NOT_TRANS},93{"lR1", NOT_TRANS},94{"lR2", NOT_TRANS},95{"lV0", NOT_TRANS},96{"lV1", NOT_TRANS},97{"lV2", NOT_TRANS},98{"lF0", NOT_TRANS},99{"lF1", NOT_TRANS},100{"lF2", NOT_TRANS},101102{"lS0T", IS_TRANS},103{"lS1T", IS_TRANS},104{"lS2T", IS_TRANS},105{"lP0T", IS_TRANS},106{"lP1T", IS_TRANS},107{"lP2T", IS_TRANS},108{"lU0T", IS_TRANS},109{"lU1T", IS_TRANS},110{"lU2T", IS_TRANS},111{"lR0T", IS_TRANS},112{"lR1T", IS_TRANS},113{"lR2T", IS_TRANS},114{"lV0T", IS_TRANS},115{"lV1T", IS_TRANS},116{"lV2T", IS_TRANS},117{"lF0T", IS_TRANS},118{"lF1T", IS_TRANS},119{"lF2T", IS_TRANS},120121{"X0", NOT_TRANS},122{"X1", NOT_TRANS},123{"X2", NOT_TRANS},124{"Z0", NOT_TRANS},125{"Z1", NOT_TRANS},126{"Z2", NOT_TRANS},127{"B0", NOT_TRANS},128{"B1", NOT_TRANS},129{"B2", NOT_TRANS},130{"C0", NOT_TRANS},131{"C1", NOT_TRANS},132{"C2", NOT_TRANS},133{"D0", NOT_TRANS},134{"D1", NOT_TRANS},135{"D2", NOT_TRANS},136{"F0", NOT_TRANS},137{"F1", NOT_TRANS},138{"F2", NOT_TRANS},139{"I0", NOT_TRANS},140{"I1", NOT_TRANS},141{"I2", NOT_TRANS},142{"L0", NOT_TRANS},143{"L1", NOT_TRANS},144{"L2", NOT_TRANS},145{"S0", NOT_TRANS},146{"S1", NOT_TRANS},147{"S2", NOT_TRANS},148{"O0", NOT_TRANS},149{"O1", NOT_TRANS},150{"O2", NOT_TRANS},151152{"X0T", IS_TRANS},153{"X1T", IS_TRANS},154{"X2T", IS_TRANS},155{"Z0T", IS_TRANS},156{"Z1T", IS_TRANS},157{"Z2T", IS_TRANS},158{"B0T", IS_TRANS},159{"B1T", IS_TRANS},160{"B2T", IS_TRANS},161{"C0T", IS_TRANS},162{"C1T", IS_TRANS},163{"C2T", IS_TRANS},164{"D0T", IS_TRANS},165{"D1T", IS_TRANS},166{"D2T", IS_TRANS},167{"F0T", IS_TRANS},168{"F1T", IS_TRANS},169{"F2T", IS_TRANS},170{"I0T", IS_TRANS},171{"I1T", IS_TRANS},172{"I2T", IS_TRANS},173{"L0T", IS_TRANS},174{"L1T", IS_TRANS},175{"L2T", IS_TRANS},176{"S0T", IS_TRANS},177{"S1T", IS_TRANS},178{"S2T", IS_TRANS},179{"O0T", IS_TRANS},180{"O1T", IS_TRANS},181{"O2T", IS_TRANS},182183{"LS0", NOT_TRANS},184{"LS1", NOT_TRANS},185{"LS2", NOT_TRANS},186{"LP0", NOT_TRANS},187{"LP1", NOT_TRANS},188{"LP2", NOT_TRANS},189{"LU0", NOT_TRANS},190{"LU1", NOT_TRANS},191{"LU2", NOT_TRANS},192{"LR0", NOT_TRANS},193{"LR1", NOT_TRANS},194{"LR2", NOT_TRANS},195{"LV0", NOT_TRANS},196{"LV1", NOT_TRANS},197{"LV2", NOT_TRANS},198{"LF0", NOT_TRANS},199{"LF1", NOT_TRANS},200{"LF2", NOT_TRANS},201202{"LS0T", IS_TRANS},203{"LS1T", IS_TRANS},204{"LS2T", IS_TRANS},205{"LP0T", IS_TRANS},206{"LP1T", IS_TRANS},207{"LP2T", IS_TRANS},208{"LU0T", IS_TRANS},209{"LU1T", IS_TRANS},210{"LU2T", IS_TRANS},211{"LR0T", IS_TRANS},212{"LR1T", IS_TRANS},213{"LR2T", IS_TRANS},214{"LV0T", IS_TRANS},215{"LV1T", IS_TRANS},216{"LV2T", IS_TRANS},217{"LF0T", IS_TRANS},218{"LF1T", IS_TRANS},219{"LF2T", IS_TRANS},220221{"E0", NOT_TRANS},222{"E1", NOT_TRANS},223{"E2", NOT_TRANS},224225{"E0T", IS_TRANS},226{"E1T", IS_TRANS},227{"E2T", IS_TRANS},228229{"ES0", NOT_TRANS},230{"ES1", NOT_TRANS},231{"ES2", NOT_TRANS},232{"EP0", NOT_TRANS},233{"EP1", NOT_TRANS},234{"EP2", NOT_TRANS},235{"EU0", NOT_TRANS},236{"EU1", NOT_TRANS},237{"EU2", NOT_TRANS},238{"ER0", NOT_TRANS},239{"ER1", NOT_TRANS},240{"ER2", NOT_TRANS},241{"EV0", NOT_TRANS},242{"EV1", NOT_TRANS},243{"EV2", NOT_TRANS},244{"EF0", NOT_TRANS},245{"EF1", NOT_TRANS},246{"EF2", NOT_TRANS},247248{"ES0T", IS_TRANS},249{"ES1T", IS_TRANS},250{"ES2T", IS_TRANS},251{"EP0T", IS_TRANS},252{"EP1T", IS_TRANS},253{"EP2T", IS_TRANS},254{"EU0T", IS_TRANS},255{"EU1T", IS_TRANS},256{"EU2T", IS_TRANS},257{"ER0T", IS_TRANS},258{"ER1T", IS_TRANS},259{"ER2T", IS_TRANS},260{"EV0T", IS_TRANS},261{"EV1T", IS_TRANS},262{"EV2T", IS_TRANS},263{"EF0T", IS_TRANS},264{"EF1T", IS_TRANS},265{"EF2T", IS_TRANS}266};267private static Log log;268private final static String prefix = "nsk.jdi.Field.isTransient.";269private final static String className = "istrans001";270private final static String debugerName = prefix + className;271private final static String debugeeName = debugerName + "a";272273public static void main(String argv[]) {274System.exit(95 + run(argv, System.out));275}276277public static int run(String argv[], PrintStream out) {278ArgumentHandler argHandler = new ArgumentHandler(argv);279log = new Log(out, argHandler);280Binder binder = new Binder(argHandler, log);281Debugee debugee = binder.bindToDebugee(debugeeName282+ (argHandler.verbose() ? " -verbose" : ""));283IOPipe pipe = new IOPipe(debugee);284boolean testFailed = false;285List fields;286287// Connect with debugee and resume it288debugee.redirectStderr(out);289debugee.resume();290String line = pipe.readln();291if (line == null) {292log.complain("debuger FAILURE> UNEXPECTED debugee's signal - null");293return 2;294}295if (!line.equals("ready")) {296log.complain("debuger FAILURE> UNEXPECTED debugee's signal - "297+ line);298return 2;299}300else {301log.display("debuger> debugee's \"ready\" signal recieved.");302}303304// Get all fields from debugee305ReferenceType refType = debugee.classByName(debugeeName);306if (refType == null) {307log.complain("debuger FAILURE> Class " + debugeeName308+ " not found.");309return 2;310}311try {312fields = refType.allFields();313} catch (Exception e) {314log.complain("debuger FAILURE> Can't get fields from class");315log.complain("debuger FAILURE> Exception: " + e);316return 2;317}318int totalFields = fields.size();319if (totalFields < 1) {320log.complain("debuger FAILURE> Total number of fields read "321+ totalFields + ", should be " + TOTAL_FIELDS);322return 2;323}324log.display("debuger> Total fields found: " + totalFields);325Iterator fieldsIterator = fields.iterator();326for (int i = 0; fieldsIterator.hasNext(); i++) {327Field field = (Field)fieldsIterator.next();328boolean isTrans = field.isTransient();329String name = field.name();330String realIsTrans;331332if (name == null) {333log.complain("debuger FAILURE 1> Name is null for " + i334+ " field");335testFailed = true;336continue;337}338log.display("debuger> " + i + " field (" + name + "), "339+ "isTransient = " + isTrans + " read.");340try {341realIsTrans = getTransByName(name);342} catch (Error e) {343log.complain("debuger FAILURE 2> Unexpected Error " + e);344return 2;345}346// isTransient() returns true if the field is transient,347// returns false if the field is not transient348if ((isTrans && !realIsTrans.equals(IS_TRANS)) ||349(!isTrans && realIsTrans.equals(IS_TRANS))350) {351log.complain("debuger FAILURE 3> " + i + " field " + name352+ ": read field.isTransient() = " + isTrans353+ " real isTransient should be " + realIsTrans);354testFailed = true;355}356}357pipe.println("quit");358debugee.waitFor();359360int status = debugee.getStatus();361if (testFailed) {362log.complain("debuger FAILURE> TEST FAILED");363return 2;364} else {365if (status == 95) {366log.display("debuger> expected Debugee's exit "367+ "status - " + status);368return 0;369} else {370log.complain("debuger FAILURE> UNEXPECTED Debugee's exit "371+ "status (not 95) - " + status);372return 2;373}374}375}376377private static String getTransByName(String name)378throws Error379{380for (int i = 0; i < TOTAL_FIELDS; i++) {381String fieldName = FIELDS_TYPE_NAME[i][0];382if (fieldName.equals(name)) {383return FIELDS_TYPE_NAME[i][1];384}385}386throw new Error("Error in test. Unknown field " + name);387}388}389390391