0N/A/*
2362N/A * Copyright (c) 2003, 2004, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 4421040
0N/A * @summary JPDA: Add support for JSR-014 Generics
0N/A *
0N/A * @author jjh
0N/A *
0N/A * @run build TestScaffold VMConnection TargetListener TargetAdapter
1485N/A * @run compile -g GenericsTest.java
0N/A * @run main GenericsTest
0N/A */
0N/Aimport com.sun.jdi.*;
0N/Aimport com.sun.jdi.event.*;
0N/Aimport com.sun.jdi.request.*;
0N/A
0N/Aimport java.util.*;
0N/A
0N/A /********** target program **********/
0N/A
0N/Aclass GenericsTarg {
0N/A static Gen1<String> genField = new Gen1<String>();;
0N/A static Sub1 sub1Field = new Sub1();
0N/A
0N/A String[] strArray = null;
0N/A int intField = 0;
0N/A Object objField;
0N/A public static void main(String[] args){
0N/A //genField.print();
0N/A System.out.println("Goodbye from GenericsTarg!");
0N/A }
0N/A}
0N/Aclass Gen1<tt> {
0N/A tt field1;
0N/A Gen1() {
0N/A System.out.println("Gen1<tt> ctor called");
0N/A }
0N/A tt method1(tt p1) {
0N/A Gen1<String> xxx = null;
0N/A System.out.println("method1: param is " + p1);
0N/A return p1;
0N/A }
0N/A String method2() {
0N/A String str = "This local variable is not generic";
0N/A return str;
0N/A }
0N/A}
0N/A
0N/Aclass Sub1 extends Gen1<String> {
0N/A String method1(String p1) {
0N/A System.out.println("method1 has been overridden: param is " + p1);
0N/A return "hi";
0N/A }
0N/A}
0N/A
0N/A /********** test program **********/
0N/A
0N/Apublic class GenericsTest extends TestScaffold {
0N/A ReferenceType targetClass;
0N/A ThreadReference mainThread;
0N/A static boolean useOld;
0N/A
0N/A GenericsTest (String args[]) {
0N/A super(args);
0N/A }
0N/A
0N/A public static void main(String[] args) throws Exception {
0N/A /*
0N/A * The 1.5 FE must be able to talk to a 1.4 BE, ie, JDWP version <= 1.4.
0N/A * This is hard to test since this test file must be compiled with
0N/A * -source 1.5 which will cause its class file to be version 49 which
0N/A * won't run on a pre 1.5 JDK. We can simulate this though
0N/A * by passing
0N/A * -xjdk <pathname>
0N/A * to this test which causes the debuggee to be run on that JDK.
0N/A * This should be a version of 1.5 that accepts classfile version 49,
0N/A * but which still contains the 1.4 version of JDWP.
0N/A * This trick verifies that the calls to genericSignature() methods
0N/A * in the test do not cause the generic JDWP commands to be issued.
0N/A * The value to use for this is currently:
0N/A * /java/re/jdk/1.5/promoted/all/b17/binaries/solaris-sparc
0N/A */
0N/A if (args.length > 1 && args[0].equals("-xjdk")) {
0N/A System.setProperty("java.home", args[1]);
0N/A useOld = true;
0N/A
0N/A // Delete this arg
0N/A String[] args1 = new String[args.length - 2];
0N/A for (int ii = 0; ii < args.length -2; ii++) {
0N/A args1[ii] = args[ii + 2];
0N/A }
0N/A args = args1;
0N/A }
0N/A
0N/A new GenericsTest(args).startTests();
0N/A }
0N/A
0N/A /********** test core **********/
0N/A
0N/A protected void runTests() throws Exception {
0N/A /*
0N/A * Get to the top of main()
0N/A * to determine targetClass and mainThread
0N/A */
0N/A BreakpointEvent bpe = startToMain("GenericsTarg");
0N/A targetClass = bpe.location().declaringType();
0N/A {
0N/A /*
0N/A * Prove that arrays aren't broken and that
0N/A * null is returned if there is no generic signature
0N/A */
0N/A Field strArray = targetClass.fieldByName("strArray");
0N/A ReferenceType fieldType = (ReferenceType)(strArray.type());
0N/A String genSig = fieldType.genericSignature();
0N/A System.out.println("strArray name = " + strArray);
0N/A System.out.println(" type = " + fieldType);
0N/A System.out.println(" sig = " + fieldType.signature());
0N/A System.out.println(" genSig = " + genSig);
0N/A if (!useOld && genSig != null) {
0N/A failure("FAILED: Expected generic signature = null for "
0N/A + fieldType.name() + ", received: " + genSig);
0N/A }
0N/A }
0N/A {
0N/A // prove that primitives aren't broken.
0N/A Field intField = targetClass.fieldByName("intField");
0N/A Type fieldType = (Type)(intField.type());
0N/A System.out.println("intField name = " + intField);
0N/A System.out.println(" type = " + fieldType);
0N/A System.out.println(" sig = " + fieldType.signature());
0N/A }
0N/A
0N/A Field genField = targetClass.fieldByName("genField");
0N/A ReferenceType gen1Class = (ReferenceType)(genField.type());
0N/A String genSig;
0N/A String expected;
0N/A {
0N/A // Verify genericSignature for a class
0N/A expected = "<tt:Ljava/lang/Object;>Ljava/lang/Object;";
0N/A genSig = gen1Class.genericSignature();
0N/A System.out.println("genField name = " + genField);
0N/A System.out.println(" type = " + gen1Class);
0N/A System.out.println(" sig = " + gen1Class.signature());
0N/A System.out.println(" genSig = " + genSig);
0N/A if (!useOld && !expected.equals(genSig)) {
0N/A failure("FAILED: Expected generic signature for gen1: " +
0N/A expected + ", received: " + genSig);
0N/A }
0N/A }
0N/A {
0N/A // Verify genericSignature() for a field
0N/A List genFields = gen1Class.fields();
0N/A Field field1 = (Field)genFields.get(0);
0N/A // there is only one field
0N/A expected = "Ttt;";
0N/A genSig = field1.genericSignature();
0N/A System.out.println("field1 name = " + field1);
0N/A System.out.println(" type = " + gen1Class.signature());
0N/A System.out.println(" sig = " + field1.signature());
0N/A System.out.println(" gen sig = " + genSig);
0N/A if (!useOld && !expected.equals(genSig)) {
0N/A failure("FAILED: Expected generic signature for field1: " +
0N/A expected + ", received: " + genSig);
0N/A }
0N/A }
0N/A {
0N/A // Verify genericSignature() for a method
0N/A List genMethods = gen1Class.methodsByName("method1");
0N/A // There is only uno
0N/A Method method1 = (Method)genMethods.get(0);
0N/A expected = "(Ttt;)Ttt;";
0N/A genSig = method1.genericSignature();
0N/A System.out.println("method1 name = " + method1);
0N/A System.out.println(" type = " + gen1Class.signature());
0N/A System.out.println(" sig = " + method1.signature());
0N/A System.out.println(" gen sig = " + genSig);
0N/A System.out.println(" bridge = " + method1.isBridge());
0N/A if (!useOld && !expected.equals(genSig)) {
0N/A failure("FAILED: Expected generic signature for method1: " +
0N/A expected + ", received: " + genSig);
0N/A }
0N/A
0N/A // Verify this is not a bridge method
0N/A if (method1.isBridge()) {
0N/A failure("FAILED: Expected gen1.method1 to not be a bridge"
0N/A + " method but it is");
0N/A }
0N/A
0N/A // Verify genericSignature for a local var
0N/A List localVars = method1.variables();
0N/A String[] expectedGenSigs = { "Ttt", "Gen1<String>" };
0N/A for ( int ii = 0 ; ii < localVars.size(); ii++) {
0N/A expected = expectedGenSigs[ii];
0N/A LocalVariable pp = (LocalVariable)localVars.get(ii);
0N/A genSig = pp.genericSignature();
0N/A System.out.println(" local var " + ii + " = " + pp.name());
0N/A System.out.println(" sig = " + pp.signature());
0N/A System.out.println(" gen sig = " + genSig);
0N/A //jjh Uncomment when generics for local vars are available from
0N/A //jjh javac and hotspot. See:
0N/A //jjh 4914602 LVT entries for classfile version > 49 must be converted
0N/A //jjh if (!useOld && !expected.equals(genSig)) {
0N/A //jjh failure("FAILED: Expected generic signature for local var: " +
0N/A //jjh expected + ", received: " + genSig);
0N/A //jjh }
0N/A }
0N/A }
0N/A {
0N/A // Verify genericSignature() for a method2
0N/A List genMethods = gen1Class.methodsByName("method2");
0N/A // There is only uno
0N/A Method method2 = (Method)genMethods.get(0);
0N/A expected = "null";
0N/A genSig = method2.genericSignature();
0N/A genSig = (genSig == null) ? "null" : genSig;
0N/A System.out.println("method2 name = " + method2);
0N/A System.out.println(" type = " + gen1Class.signature());
0N/A System.out.println(" sig = " + method2.signature());
0N/A System.out.println(" gen sig = " + genSig);
0N/A System.out.println(" bridge = " + method2.isBridge());
0N/A if (!useOld && !expected.equals(genSig)) {
0N/A failure("FAILED: Expected generic signature for method2: " +
0N/A expected + ", received: " + genSig);
0N/A }
0N/A
0N/A // Verify this is not a bridge method
0N/A if (method2.isBridge()) {
0N/A failure("FAILED: Expected gen1.method2 to not be a bridge"
0N/A + " method but it is");
0N/A }
0N/A
0N/A // Verify genericSignature for a local var
0N/A List localVars = method2.variables();
0N/A expected = "null";
0N/A for ( int ii = 0 ; ii < localVars.size(); ii++) {
0N/A LocalVariable pp = (LocalVariable)localVars.get(ii);
0N/A genSig = pp.genericSignature();
0N/A genSig = (genSig == null) ? "null" : genSig;
0N/A
0N/A System.out.println(" local var " + ii + " = " + pp.name());
0N/A System.out.println(" sig = " + pp.signature());
0N/A System.out.println(" gen sig = " + genSig);
0N/A if (!useOld && !expected.equals(genSig)) {
0N/A failure("FAILED: Expected generic signature for local var: " +
0N/A expected + ", received: " + genSig);
0N/A }
0N/A }
0N/A }
0N/A {
0N/A Field sub1Field = targetClass.fieldByName("sub1Field");
0N/A ReferenceType sub1Class = (ReferenceType)(sub1Field.type());
0N/A List<Method> sub1Methods = sub1Class.methodsByName("method1");
0N/A for (Method mm: sub1Methods) {
0N/A System.out.println("method is: " + mm);
0N/A }
0N/A /*
0N/A * There should be two methods - the first is the
0N/A * method1 defined in Sub1, and the 2nd is a javac generated
0N/A * bridge method.
0N/A */
0N/A Method method1 = (Method)sub1Methods.get(1);
0N/A System.out.println("\nmethod1 name = " + method1);
0N/A System.out.println(" sig = " + method1.signature());
0N/A System.out.println(" bridge = " + method1.isBridge());
0N/A if (!useOld && !method1.isBridge()) {
0N/A failure("FAILED: Expected Sub1.method1 to be a bridge method"
0N/A + " but it isn't");
0N/A }
0N/A
0N/A }
0N/A {
0N/A // Verify genericSignature for a non generic class
0N/A genSig = targetClass.genericSignature();
0N/A if (genSig != null) {
0N/A failure("FAILED: Expected generic signature = null for "
0N/A + targetClass.name() + ", received: " + genSig);
0N/A }
0N/A }
0N/A {
0N/A // Verify genericSignature for a non generic field
0N/A Field objField = targetClass.fieldByName("objField");
0N/A genSig = objField.genericSignature();
0N/A if (genSig != null) {
0N/A failure("FAILED: Expected generic signature = null for "
0N/A + objField.name() + ", received: " + genSig);
0N/A }
0N/A }
0N/A {
0N/A // Verify genericSignature for a non generic method
0N/A List methods = targetClass.methodsByName("main");
0N/A Method main = (Method)methods.get(0);
0N/A genSig = main.genericSignature();
0N/A if (genSig != null) {
0N/A failure("FAILED: Expected generic signature = null for "
0N/A + main.name() + ", received: " + genSig);
0N/A }
0N/A }
0N/A if (0 == 1) {
0N/A mainThread = bpe.thread();
0N/A EventRequestManager erm = vm().eventRequestManager();
0N/A StepRequest request = erm.createStepRequest(mainThread,
0N/A StepRequest.STEP_LINE,
0N/A StepRequest.STEP_INTO);
0N/A request.enable();
0N/A }
0N/A
0N/A /*
0N/A * resume the target listening for events
0N/A */
0N/A listenUntilVMDisconnect();
0N/A
0N/A /*
0N/A * deal with results of test
0N/A * if anything has called failure("foo") testFailed will be true
0N/A */
0N/A if (!testFailed) {
0N/A println("GenericsTest: passed");
0N/A } else {
0N/A throw new Exception("GenericsTest: failed");
0N/A }
0N/A }
0N/A}