Thu, 30 May 2013 11:46:39 -0700
8015436: compiler/ciReplay/TestSA.sh fails with assert() index is out of bounds
Summary: The InstanceKlass _initial_method_idnum value must be adjusted if overpass methods are added.
Reviewed-by: twisti, kvn
Contributed-by: serguei.spitsyn@oracle.com
src/share/vm/classfile/defaultMethods.cpp | file | annotate | diff | comparison | revisions | |
test/compiler/8015436/Test8015436.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/vm/classfile/defaultMethods.cpp Tue May 28 16:36:19 2013 -0700 1.2 +++ b/src/share/vm/classfile/defaultMethods.cpp Thu May 30 11:46:39 2013 -0700 1.3 @@ -1349,6 +1349,7 @@ 1.4 1.5 // Replace klass methods with new merged lists 1.6 klass->set_methods(merged_methods); 1.7 + klass->set_initial_method_idnum(new_size); 1.8 1.9 ClassLoaderData* cld = klass->class_loader_data(); 1.10 MetadataFactory::free_array(cld, original_methods);
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/compiler/8015436/Test8015436.java Thu May 30 11:46:39 2013 -0700 2.3 @@ -0,0 +1,74 @@ 2.4 +/* 2.5 + * Copyright (c) 2013, 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 + * @test 2.29 + * @bug 8015436 2.30 + * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added 2.31 + * @run main Test8015436 2.32 + * 2.33 + */ 2.34 + 2.35 +/* 2.36 + * The test checks that a MemberName for the defaultMethod() is cached in 2.37 + * the class MemberNameTable without a crash in the VM fastdebug mode. 2.38 + * The original issue was that the InstanceKlass _initial_method_idnum was 2.39 + * not adjusted properly when the overpass methods are added to the class. 2.40 + * The expected/correct behavior: The test does not crash nor throw any exceptions. 2.41 + * All the invocations of the defaultMethod() must be completed successfully. 2.42 + */ 2.43 + 2.44 +import java.lang.invoke.*; 2.45 + 2.46 +interface InterfaceWithDefaultMethod { 2.47 + public void someMethod(); 2.48 + 2.49 + default public void defaultMethod(String str){ 2.50 + System.out.println("defaultMethod() " + str); 2.51 + } 2.52 +} 2.53 + 2.54 +class Test8015436 implements InterfaceWithDefaultMethod { 2.55 + @Override 2.56 + public void someMethod() { 2.57 + System.out.println("someMethod() invoked"); 2.58 + } 2.59 + 2.60 + public static void main(String[] args) throws Throwable { 2.61 + Test8015436 testObj = new Test8015436(); 2.62 + testObj.someMethod(); 2.63 + testObj.defaultMethod("invoked directly"); 2.64 + 2.65 + MethodHandles.Lookup lookup = MethodHandles.lookup(); 2.66 + MethodType mt = MethodType.methodType(void.class, String.class); 2.67 + MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt); 2.68 + mh.invokeExact(testObj, "invoked via a MethodHandle"); 2.69 + } 2.70 +} 2.71 + 2.72 +/* 2.73 + * A successful execution gives the output: 2.74 + * someMethod() invoked 2.75 + * defaultMethod() invoked directly 2.76 + * defaultMethod() invoked via a MethodHandle 2.77 + */