test/compiler/8015436/Test8015436.java

Thu, 30 May 2013 11:46:39 -0700

author
sspitsyn
date
Thu, 30 May 2013 11:46:39 -0700
changeset 5209
fe00365c8f31
child 5215
2f004f9dc9e1
permissions
-rw-r--r--

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

     1 /*
     2  * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  */
    24 /*
    25  * @test
    26  * @bug 8015436
    27  * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added
    28  * @run main Test8015436
    29  *
    30  */
    32 /*
    33  * The test checks that a MemberName for the defaultMethod() is cached in
    34  * the class MemberNameTable without a crash in the VM fastdebug mode.
    35  * The original issue was that the InstanceKlass _initial_method_idnum was
    36  * not adjusted properly when the overpass methods are added to the class.
    37  * The expected/correct behavior: The test does not crash nor throw any exceptions.
    38  * All the invocations of the defaultMethod() must be completed successfully.
    39  */
    41 import java.lang.invoke.*;
    43 interface InterfaceWithDefaultMethod {
    44     public void someMethod();
    46     default public void defaultMethod(String str){
    47         System.out.println("defaultMethod() " + str);
    48     }
    49 }
    51 class Test8015436 implements InterfaceWithDefaultMethod {
    52     @Override
    53     public void someMethod() {
    54         System.out.println("someMethod() invoked");
    55     }
    57     public static void main(String[] args) throws Throwable {
    58         Test8015436 testObj = new Test8015436();
    59         testObj.someMethod();
    60         testObj.defaultMethod("invoked directly");
    62         MethodHandles.Lookup lookup = MethodHandles.lookup();
    63         MethodType   mt = MethodType.methodType(void.class, String.class);
    64         MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt);
    65         mh.invokeExact(testObj, "invoked via a MethodHandle");
    66     }
    67 }
    69 /*
    70  * A successful execution gives the output:
    71  *   someMethod() invoked
    72  *   defaultMethod() invoked directly
    73  *   defaultMethod() invoked via a MethodHandle
    74  */

mercurial