Path: blob/master/test/hotspot/jtreg/runtime/InvocationTests/invokevirtual/Generator.java
40948 views
/*1* Copyright (c) 2009, 2019, 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*22*/2324package invokevirtual;2526import static jdk.internal.org.objectweb.asm.Opcodes.ACC_ABSTRACT;27import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC;28import shared.AbstractGenerator;29import shared.AccessType;3031import java.util.HashMap;32import java.util.Map;3334public class Generator extends AbstractGenerator {35public Generator(String[] args) {36super(args);37}3839public static void main (String[] args) throws Exception {40new Generator(args).run();41}4243protected Checker getChecker(Class paramClass, Class targetClass) {44return new Checker(paramClass, targetClass);45}4647private void run() throws Exception {48// Specify package names49String pkg1 = "a.";50String pkg2 = "b.";51String pkg3 = "c.";52String[] packages = new String[] { "", pkg1, pkg2, pkg3 };5354boolean isPassed = true;5556// Hierarchy57// The following triples will be used during further58// hierarchy construction and will specify packages for A, B and C59String[][] packageSets = new String[][] {60{ "", "", "" }61, { "", pkg1, pkg1 }62, { "", pkg1, pkg2 }63, { pkg1, pkg1, pkg1 }64, { pkg1, pkg1, pkg2 }65, { pkg1, pkg2, pkg1 }66, { pkg1, pkg2, pkg2 }67};6869String [] header = new String[] {70String.format("%30s %45s %20s", "Method access modifiers", "Call site location", "Status")71, String.format("%4s %-12s %-12s %-12s %7s %7s %7s %7s %7s %7s"72, " # "73, "A.m()"74, "B.m()"75, "C.m()"76, " A "77, "pkgA "78, " B "79, " pkgB"80, " C "81, "pkgC "82)83, "-------------------------------------------------------------------------------------------------"84};8586for (String str : header) {87System.out.println(str);88}8990for (String[] pkgSet : packageSets) {91String packageA = pkgSet[0];92String packageB = pkgSet[1];93String packageC = pkgSet[2];9495String classNameA = packageA + "A";96String classNameB = packageB + "B";97String classNameC = packageC + "C";9899String staticCallerParam = classNameA;100101// For all possible access modifier combinations102for (AccessType accessA : AccessType.values()) {103for (AccessType accessB : AccessType.values()) {104for (AccessType accessC : AccessType.values()) {105106if (accessA == AccessType.UNDEF) {107continue;108}109110for (int I = 0; I < 4; I++) {111boolean isAbstractA = ((I & 1) != 0);112boolean isAbstractB = ((I & 2) != 0);113114Map<String, byte[]> classes = new HashMap<String, byte[]>();115116// Generate class A117classes.put(118classNameA119, new ClassGenerator( classNameA120, "java.lang.Object"121, ACC_PUBLIC | (isAbstractA ? ACC_ABSTRACT : 0))122.addTargetMethod( accessA123, (isAbstractA ? ACC_ABSTRACT : 0))124.addCaller(staticCallerParam)125.getClassFile()126);127128// Generate class B129classes.put(130classNameB131, new ClassGenerator( classNameB132, classNameA133, ACC_PUBLIC | (isAbstractB ? ACC_ABSTRACT : 0))134.addTargetMethod( accessB135, (isAbstractB ? ACC_ABSTRACT : 0))136.addCaller(staticCallerParam)137.getClassFile()138);139140// Generate class C141classes.put(142classNameC143, new ClassGenerator(classNameC, classNameB)144.addTargetMethod(accessC)145.addCaller(staticCallerParam)146.getClassFile()147);148149// Generate package callers150for (String pkg : packages) {151classes.put(152pkg+"Caller"153, new ClassGenerator(pkg+"Caller")154.addCaller(staticCallerParam)155.getClassFile()156);157}158159String[] callSites = new String[] {160classNameA161, packageA+"Caller"162, classNameB163, packageB+"Caller"164, classNameC165, packageC+"Caller"166};167168169String caseDescription =170String.format("%-12s %-12s %-12s| "171, (isAbstractA ? "! " : " ") + classNameA + " " + accessA172, (isAbstractB ? "! " : " ") + classNameB + " " + accessB173, classNameC + " " + accessC174);175176boolean result = exec(classes, caseDescription, staticCallerParam, classNameC, callSites);177isPassed = isPassed && result;178}179}180}181}182}183184// Print footer185for (int i = header.length-1; i >= 0; i--) {186System.out.println(header[i]);187}188189if (executeTests) {190System.out.printf("\nEXECUTION STATUS: %s\n", (isPassed? "PASSED" : "FAILED"));191}192}193}194195196