changeset 4874:fe00365c8f31

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
author sspitsyn
date Thu, 30 May 2013 11:46:39 -0700
parents a1ebd310d5c1
children a589c78a8811
files src/share/vm/classfile/defaultMethods.cpp test/compiler/8015436/Test8015436.java
diffstat 2 files changed, 75 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/classfile/defaultMethods.cpp	Tue May 28 16:36:19 2013 -0700
+++ b/src/share/vm/classfile/defaultMethods.cpp	Thu May 30 11:46:39 2013 -0700
@@ -1349,6 +1349,7 @@
 
   // Replace klass methods with new merged lists
   klass->set_methods(merged_methods);
+  klass->set_initial_method_idnum(new_size);
 
   ClassLoaderData* cld = klass->class_loader_data();
   MetadataFactory::free_array(cld, original_methods);
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/compiler/8015436/Test8015436.java	Thu May 30 11:46:39 2013 -0700
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 8015436
+ * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added
+ * @run main Test8015436
+ *
+ */
+
+/*
+ * The test checks that a MemberName for the defaultMethod() is cached in
+ * the class MemberNameTable without a crash in the VM fastdebug mode.
+ * The original issue was that the InstanceKlass _initial_method_idnum was
+ * not adjusted properly when the overpass methods are added to the class.
+ * The expected/correct behavior: The test does not crash nor throw any exceptions.
+ * All the invocations of the defaultMethod() must be completed successfully.
+ */
+
+import java.lang.invoke.*;
+
+interface InterfaceWithDefaultMethod {
+    public void someMethod();
+
+    default public void defaultMethod(String str){
+        System.out.println("defaultMethod() " + str);
+    }
+}
+
+class Test8015436 implements InterfaceWithDefaultMethod {
+    @Override
+    public void someMethod() {
+        System.out.println("someMethod() invoked");
+    }
+
+    public static void main(String[] args) throws Throwable {
+        Test8015436 testObj = new Test8015436();
+        testObj.someMethod();
+        testObj.defaultMethod("invoked directly");
+
+        MethodHandles.Lookup lookup = MethodHandles.lookup();
+        MethodType   mt = MethodType.methodType(void.class, String.class);
+        MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt);
+        mh.invokeExact(testObj, "invoked via a MethodHandle");
+    }
+}
+
+/*
+ * A successful execution gives the output:
+ *   someMethod() invoked
+ *   defaultMethod() invoked directly
+ *   defaultMethod() invoked via a MethodHandle
+ */