Wed, 05 Feb 2014 15:14:47 -0800
8032010: Attempt to resolve abstract method in concrete class fails with AbstractMethodError
Summary: removing a check in LinkResolver::resolve_method() to conform with a change in JVMS-8 5.4.3.3. Method Resolution
Reviewed-by: coleenp, lfoltan
1.1 --- a/src/share/vm/interpreter/linkResolver.cpp Fri Feb 07 18:30:27 2014 -0500 1.2 +++ b/src/share/vm/interpreter/linkResolver.cpp Wed Feb 05 15:14:47 2014 -0800 1.3 @@ -564,16 +564,7 @@ 1.4 } 1.5 } 1.6 1.7 - // 5. check if method is concrete 1.8 - if (resolved_method->is_abstract() && !resolved_klass->is_abstract()) { 1.9 - ResourceMark rm(THREAD); 1.10 - THROW_MSG(vmSymbols::java_lang_AbstractMethodError(), 1.11 - Method::name_and_sig_as_C_string(resolved_klass(), 1.12 - method_name, 1.13 - method_signature)); 1.14 - } 1.15 - 1.16 - // 6. access checks, access checking may be turned off when calling from within the VM. 1.17 + // 5. access checks, access checking may be turned off when calling from within the VM. 1.18 if (check_access) { 1.19 assert(current_klass.not_null() , "current_klass should not be null"); 1.20
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/runtime/lambda-features/TestConcreteClassWithAbstractMethod.java Wed Feb 05 15:14:47 2014 -0800 2.3 @@ -0,0 +1,181 @@ 2.4 +/* 2.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + * 2.26 + */ 2.27 + 2.28 +/* 2.29 + * @test 2.30 + * @bug 8032010 2.31 + * @summary method lookup on an abstract method in a concrete class should be successful 2.32 + * @run main TestConcreteClassWithAbstractMethod 2.33 + */ 2.34 + 2.35 +import jdk.internal.org.objectweb.asm.ClassWriter; 2.36 +import jdk.internal.org.objectweb.asm.MethodVisitor; 2.37 + 2.38 +import static jdk.internal.org.objectweb.asm.Opcodes.*; 2.39 + 2.40 +/* 2.41 + * class T1 { public int m() {} } 2.42 + * class T2 { public abstract int m(); } 2.43 + * class T3 { public int m() {} } 2.44 + * 2.45 + * Call site: T3.test() { invokevirtual T2.m() } 2.46 + * T3.m() should be invoked 2.47 + */ 2.48 +public class TestConcreteClassWithAbstractMethod { 2.49 + static final String classT1 = "p1.T1"; 2.50 + static final String classT2 = "p1.T2"; 2.51 + static final String classT3 = "p1.T3"; 2.52 + 2.53 + static final String callerName = classT3; 2.54 + 2.55 + public static void main(String[] args) throws Exception { 2.56 + ClassLoader cl = new ClassLoader() { 2.57 + public Class<?> loadClass(String name) throws ClassNotFoundException { 2.58 + if (findLoadedClass(name) != null) { 2.59 + return findLoadedClass(name); 2.60 + } 2.61 + 2.62 + if (classT1.equals(name)) { 2.63 + byte[] classFile = dumpT1(); 2.64 + return defineClass(classT1, classFile, 0, classFile.length); 2.65 + } 2.66 + if (classT2.equals(name)) { 2.67 + byte[] classFile = dumpT2(); 2.68 + return defineClass(classT2, classFile, 0, classFile.length); 2.69 + } 2.70 + if (classT3.equals(name)) { 2.71 + byte[] classFile = dumpT3(); 2.72 + return defineClass(classT3, classFile, 0, classFile.length); 2.73 + } 2.74 + 2.75 + return super.loadClass(name); 2.76 + } 2.77 + }; 2.78 + 2.79 + cl.loadClass(classT1); 2.80 + cl.loadClass(classT2); 2.81 + cl.loadClass(classT3); 2.82 + 2.83 + //cl.loadClass(callerName).getDeclaredMethod("m"); 2.84 + cl.loadClass(callerName).newInstance(); 2.85 + 2.86 + int result = (Integer)cl.loadClass(callerName).getDeclaredMethod("test").invoke(null); 2.87 + System.out.println(""+result); 2.88 + } 2.89 + 2.90 + public static byte[] dumpT1() { 2.91 + ClassWriter cw = new ClassWriter(0); 2.92 + MethodVisitor mv; 2.93 + 2.94 + cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T1", null, "java/lang/Object", null); 2.95 + { 2.96 + mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 2.97 + mv.visitCode(); 2.98 + mv.visitVarInsn(ALOAD, 0); 2.99 + mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); 2.100 + mv.visitInsn(RETURN); 2.101 + mv.visitMaxs(1, 1); 2.102 + mv.visitEnd(); 2.103 + } 2.104 + { 2.105 + mv = cw.visitMethod(ACC_PUBLIC, "m", "()I", null, null); 2.106 + mv.visitCode(); 2.107 + mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); 2.108 + mv.visitLdcInsn("p1/T1.m()"); 2.109 + mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false); 2.110 + mv.visitIntInsn(BIPUSH, 3); 2.111 + mv.visitInsn(IRETURN); 2.112 + mv.visitMaxs(2, 1); 2.113 + mv.visitEnd(); 2.114 + } 2.115 + cw.visitEnd(); 2.116 + 2.117 + return cw.toByteArray(); 2.118 + } 2.119 + 2.120 + public static byte[] dumpT2() { 2.121 + ClassWriter cw = new ClassWriter(0); 2.122 + MethodVisitor mv; 2.123 + 2.124 + cw.visit(52, ACC_PUBLIC | ACC_SUPER, "p1/T2", null, "p1/T1", null); 2.125 + { 2.126 + mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 2.127 + mv.visitCode(); 2.128 + mv.visitVarInsn(ALOAD, 0); 2.129 + mv.visitMethodInsn(INVOKESPECIAL, "p1/T1", "<init>", "()V", false); 2.130 + mv.visitInsn(RETURN); 2.131 + mv.visitMaxs(1, 1); 2.132 + mv.visitEnd(); 2.133 + } 2.134 + { 2.135 + mv = cw.visitMethod(ACC_PUBLIC + ACC_ABSTRACT, "m", "()I", null, null); 2.136 + mv.visitEnd(); 2.137 + } 2.138 + cw.visitEnd(); 2.139 + 2.140 + return cw.toByteArray(); 2.141 + } 2.142 + 2.143 + public static byte[] dumpT3() { 2.144 + ClassWriter cw = new ClassWriter(0); 2.145 + MethodVisitor mv; 2.146 + 2.147 + cw.visit(52, ACC_PUBLIC + ACC_SUPER, "p1/T3", null, "p1/T2", null); 2.148 + 2.149 + { 2.150 + mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null); 2.151 + mv.visitCode(); 2.152 + mv.visitVarInsn(ALOAD, 0); 2.153 + mv.visitMethodInsn(INVOKESPECIAL, "p1/T2", "<init>", "()V", false); 2.154 + mv.visitInsn(RETURN); 2.155 + mv.visitMaxs(1, 1); 2.156 + mv.visitEnd(); 2.157 + } 2.158 + { 2.159 + mv = cw.visitMethod(ACC_PUBLIC, "m", "()I", null, null); 2.160 + mv.visitCode(); 2.161 + mv.visitFieldInsn(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"); 2.162 + mv.visitLdcInsn("p1/T3.m()"); 2.163 + mv.visitMethodInsn(INVOKEVIRTUAL, "java/io/PrintStream", "print", "(Ljava/lang/String;)V", false); 2.164 + mv.visitIntInsn(BIPUSH, 2); 2.165 + mv.visitInsn(IRETURN); 2.166 + mv.visitMaxs(2, 1); 2.167 + mv.visitEnd(); 2.168 + } 2.169 + { 2.170 + mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "test", "()I", null, null); 2.171 + mv.visitCode(); 2.172 + mv.visitTypeInsn(NEW, "p1/T3"); 2.173 + mv.visitInsn(DUP); 2.174 + mv.visitMethodInsn(INVOKESPECIAL, "p1/T3", "<init>", "()V", false); 2.175 + mv.visitMethodInsn(INVOKEVIRTUAL, "p1/T2", "m", "()I", false); 2.176 + mv.visitInsn(IRETURN); 2.177 + mv.visitMaxs(3, 2); 2.178 + mv.visitEnd(); 2.179 + } 2.180 + cw.visitEnd(); 2.181 + 2.182 + return cw.toByteArray(); 2.183 + } 2.184 +}