Path: blob/master/test/hotspot/jtreg/vmTestbase/nsk/jdi/Accessible/isPackagePrivate/accipp001.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*/2223package nsk.jdi.Accessible.isPackagePrivate;2425import nsk.share.*;26import nsk.share.jpda.*;27import nsk.share.jdi.*;2829import com.sun.jdi.*;30import java.util.*;31import java.io.*;3233/**34* This test checks if the method <code>isPackagePrivate()</code>35* of the JDI interface <code>Accessible</code> works fine with36* the <code>ArrayType</code> sub-interface.37*/38public class accipp001 extends Log {39final static boolean MODE_VERBOSE = false;4041/** The main class names of the debugger & debugee applications. */42private final static String43thisClassName = "nsk.jdi.Accessible.isPackagePrivate.accipp001",44debugeeName = thisClassName + "a";454647static ArgumentHandler argsHandler;48private static Log logHandler;495051/** Debugee's classes which status (private or public) is known. */52private final static String knownClasses[][] = {53{"boolean", "public"},54{"byte" , "public"},55{"char" , "public"},56{"double" , "public"},57{"float" , "public"},58{"int" , "public"},59{"long" , "public"},60{"short" , "public"},6162{"java.lang.Boolean" , "public"},63{"java.lang.Byte" , "public"},64{"java.lang.Character", "public"},65{"java.lang.Double" , "public"},66{"java.lang.Float" , "public"},67{"java.lang.Integer" , "public"},68{"java.lang.Long" , "public"},69{"java.lang.Short" , "public"},70{"java.lang.String" , "public"},71{"java.lang.Object" , "public"},7273{thisClassName+"a", "public" },74{thisClassName+"e", "package private"},7576{debugeeName+"$U", "private" },77{debugeeName+"$V", "protected" },78{debugeeName+"$W", "public" },79{debugeeName+"$P", "package private"}80};8182/**83* Re-call to <code>run(args,out)</code>, and exit with84* either status 95 or 97 (JCK-like exit status).85*/86public static void main (String args[]) {87int exitCode = run(args,System.out);88System.exit(exitCode + 95);89}9091/**92* JCK-like entry point to the test: perform testing, and93* return exit code 0 (PASSED) or either 2 (FAILED).94*/95public static int run (String args[], PrintStream out) {96return new accipp001().runThis(args,out); // incarnate Log97}9899/**100* Non-static variant of the method <code>run(args,out)</code>101* can use Log features.102*/103private int runThis (String argv[], PrintStream out) {104105Debugee debugee;106107argsHandler = new ArgumentHandler(argv);108logHandler = new Log(out, argsHandler);109Binder binder = new Binder(argsHandler, logHandler);110111112if (argsHandler.verbose()) {113debugee = binder.bindToDebugee(debugeeName + " -vbs");114} else {115debugee = binder.bindToDebugee(debugeeName);116}117118IOPipe pipe = new IOPipe(debugee);119120121debugee.redirectStderr(out);122debugee.resume();123124String line = pipe.readln();125if (!line.equals("ready")) {126logHandler.complain("# Cannot recognize debugee's signal: " + line);127return 2;128};129130// ReferenceType classes[] = debugee.classes();131// for (int i=0; i<classes.length; i++) {132// ReferenceType t = classes[i];133// if (t.signature().startsWith("["))134// logHandler.display(t.name() + ": " + t.isPackagePrivate());135// };136137int errors = 0;138for (int i=0; i<knownClasses.length; i++) {139String basicName = knownClasses[i][0];140for (int indirectionLevel=1; indirectionLevel<5; indirectionLevel++) {141String brackets[] = {"", "[]", "[][]", "[][][]", "[][][][]"};142String className = basicName + brackets[indirectionLevel];143ReferenceType refType = debugee.classByName(className);144if (refType == null) {145logHandler.complain("Could not find class: " + className);146errors++;147continue;148};149boolean isPackagePrivate =150!knownClasses[i][1].equals("private") &&151!knownClasses[i][1].equals("public") &&152!knownClasses[i][1].equals("protected");153if (refType.isPackagePrivate() != isPackagePrivate) {154logHandler.complain("Class is not treated package private: "155+ className);156errors++;157continue;158};159logHandler.display(className + ": " + knownClasses[i][1]);160};161};162if (errors > 0) {163logHandler.complain("Errors revealed: " + errors);164return 2;165};166167pipe.println("quit");168debugee.waitFor();169170int status = debugee.getStatus();171if (status != 95) {172logHandler.complain("Debugee's exit status=" + status);173return 2;174};175176logHandler.display("Passed");177return 0;178}179}180181182