test/tools/javac/meth/TestCP.java

Wed, 05 Jan 2011 09:59:01 +0000

author
mcimadamore
date
Wed, 05 Jan 2011 09:59:01 +0000
changeset 810
15484cb7e5ae
parent 716
493ecc8111ba
child 820
2d5aff89aaa3
permissions
-rw-r--r--

7010194: several langtools regression failures after JSR 292 changes (b123)
Summary: Some regression tests rely on unsupported JSR 292 features
Reviewed-by: jjg

mcimadamore@716 1 /*
mcimadamore@716 2 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
mcimadamore@716 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
mcimadamore@716 4 *
mcimadamore@716 5 * This code is free software; you can redistribute it and/or modify it
mcimadamore@716 6 * under the terms of the GNU General Public License version 2 only, as
mcimadamore@716 7 * published by the Free Software Foundation.
mcimadamore@716 8 *
mcimadamore@716 9 * This code is distributed in the hope that it will be useful, but WITHOUT
mcimadamore@716 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
mcimadamore@716 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
mcimadamore@716 12 * version 2 for more details (a copy is included in the LICENSE file that
mcimadamore@716 13 * accompanied this code).
mcimadamore@716 14 *
mcimadamore@716 15 * You should have received a copy of the GNU General Public License version
mcimadamore@716 16 * 2 along with this work; if not, write to the Free Software Foundation,
mcimadamore@716 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
mcimadamore@716 18 *
mcimadamore@716 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
mcimadamore@716 20 * or visit www.oracle.com if you need additional information or have any
mcimadamore@716 21 * questions.
mcimadamore@716 22 */
mcimadamore@716 23
mcimadamore@716 24 /*
mcimadamore@716 25 * @test
mcimadamore@716 26 * @bug 6991980
mcimadamore@716 27 * @summary polymorphic signature calls don't share the same CP entries
mcimadamore@716 28 * @run main TestCP
mcimadamore@716 29 */
mcimadamore@716 30
mcimadamore@716 31 import com.sun.tools.classfile.Instruction;
mcimadamore@716 32 import com.sun.tools.classfile.Attribute;
mcimadamore@716 33 import com.sun.tools.classfile.ClassFile;
mcimadamore@716 34 import com.sun.tools.classfile.Code_attribute;
mcimadamore@716 35 import com.sun.tools.classfile.ConstantPool.*;
mcimadamore@716 36 import com.sun.tools.classfile.Method;
mcimadamore@716 37
mcimadamore@716 38 import java.dyn.*;
mcimadamore@716 39 import java.io.*;
mcimadamore@716 40
mcimadamore@716 41 public class TestCP {
mcimadamore@716 42
mcimadamore@716 43 static class TestClass {
mcimadamore@716 44 void test(MethodHandle mh) throws Throwable {
mcimadamore@716 45 Number n = mh.<Number>invokeExact("daddy",1,'n');
mcimadamore@716 46 n = (Number)mh.invokeExact("bunny",1,'d');
mcimadamore@716 47 }
mcimadamore@716 48 }
mcimadamore@716 49
mcimadamore@716 50 static final String PS_TYPE = "(Ljava/lang/String;IC)Ljava/lang/Number;";
mcimadamore@716 51 static final int PS_CALLS_COUNT = 2;
mcimadamore@716 52 static final String SUBTEST_NAME = TestClass.class.getName() + ".class";
mcimadamore@716 53 static final String TEST_METHOD_NAME = "test";
mcimadamore@716 54
mcimadamore@716 55 public static void main(String... args) throws Exception {
mcimadamore@716 56 new TestCP().run();
mcimadamore@716 57 }
mcimadamore@716 58
mcimadamore@716 59 public void run() throws Exception {
mcimadamore@716 60 String workDir = System.getProperty("test.classes");
mcimadamore@716 61 File compiledTest = new File(workDir, SUBTEST_NAME);
mcimadamore@716 62 verifyMethodHandleInvocationDescriptors(compiledTest);
mcimadamore@716 63 }
mcimadamore@716 64
mcimadamore@716 65 void verifyMethodHandleInvocationDescriptors(File f) {
mcimadamore@716 66 System.err.println("verify: " + f);
mcimadamore@716 67 try {
mcimadamore@716 68 int count = 0;
mcimadamore@716 69 ClassFile cf = ClassFile.read(f);
mcimadamore@716 70 Method testMethod = null;
mcimadamore@716 71 for (Method m : cf.methods) {
mcimadamore@716 72 if (m.getName(cf.constant_pool).equals(TEST_METHOD_NAME)) {
mcimadamore@716 73 testMethod = m;
mcimadamore@716 74 break;
mcimadamore@716 75 }
mcimadamore@716 76 }
mcimadamore@716 77 if (testMethod == null) {
mcimadamore@716 78 throw new Error("Test method not found");
mcimadamore@716 79 }
mcimadamore@716 80 Code_attribute ea = (Code_attribute)testMethod.attributes.get(Attribute.Code);
mcimadamore@716 81 if (testMethod == null) {
mcimadamore@716 82 throw new Error("Code attribute for test() method not found");
mcimadamore@716 83 }
mcimadamore@716 84 int instr_count = 0;
mcimadamore@716 85 int cp_entry = -1;
mcimadamore@716 86
mcimadamore@716 87 for (Instruction i : ea.getInstructions()) {
mcimadamore@716 88 if (i.getMnemonic().equals("invokevirtual")) {
mcimadamore@716 89 instr_count++;
mcimadamore@716 90 if (cp_entry == -1) {
mcimadamore@716 91 cp_entry = i.getUnsignedShort(1);
mcimadamore@716 92 } else if (cp_entry != i.getUnsignedShort(1)) {
mcimadamore@716 93 throw new Error("Unexpected CP entry in polymorphic signature call");
mcimadamore@716 94 }
mcimadamore@716 95 CONSTANT_Methodref_info methRef =
mcimadamore@716 96 (CONSTANT_Methodref_info)cf.constant_pool.get(cp_entry);
mcimadamore@716 97 String type = methRef.getNameAndTypeInfo().getType();
mcimadamore@716 98 if (!type.equals(PS_TYPE)) {
mcimadamore@716 99 throw new Error("Unexpected type in polymorphic signature call: " + type);
mcimadamore@716 100 }
mcimadamore@716 101 }
mcimadamore@716 102 }
mcimadamore@716 103 if (instr_count != PS_CALLS_COUNT) {
mcimadamore@716 104 throw new Error("Wrong number of polymorphic signature call found: " + instr_count);
mcimadamore@716 105 }
mcimadamore@716 106 } catch (Exception e) {
mcimadamore@716 107 e.printStackTrace();
mcimadamore@716 108 throw new Error("error reading " + f +": " + e);
mcimadamore@716 109 }
mcimadamore@716 110 }
mcimadamore@716 111 }

mercurial