sspitsyn@5209: /* sspitsyn@5209: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. sspitsyn@5209: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. sspitsyn@5209: * sspitsyn@5209: * This code is free software; you can redistribute it and/or modify it sspitsyn@5209: * under the terms of the GNU General Public License version 2 only, as sspitsyn@5209: * published by the Free Software Foundation. sspitsyn@5209: * sspitsyn@5209: * This code is distributed in the hope that it will be useful, but WITHOUT sspitsyn@5209: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or sspitsyn@5209: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License sspitsyn@5209: * version 2 for more details (a copy is included in the LICENSE file that sspitsyn@5209: * accompanied this code). sspitsyn@5209: * sspitsyn@5209: * You should have received a copy of the GNU General Public License version sspitsyn@5209: * 2 along with this work; if not, write to the Free Software Foundation, sspitsyn@5209: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. sspitsyn@5209: * sspitsyn@5209: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA sspitsyn@5209: * or visit www.oracle.com if you need additional information or have any sspitsyn@5209: * questions. sspitsyn@5209: */ sspitsyn@5209: sspitsyn@5209: /* sspitsyn@5209: * @test sspitsyn@5209: * @bug 8015436 sspitsyn@5209: * @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added sspitsyn@5209: * @run main Test8015436 sspitsyn@5209: * sspitsyn@5209: */ sspitsyn@5209: sspitsyn@5209: /* sspitsyn@5209: * The test checks that a MemberName for the defaultMethod() is cached in sspitsyn@5209: * the class MemberNameTable without a crash in the VM fastdebug mode. sspitsyn@5209: * The original issue was that the InstanceKlass _initial_method_idnum was sspitsyn@5209: * not adjusted properly when the overpass methods are added to the class. sspitsyn@5209: * The expected/correct behavior: The test does not crash nor throw any exceptions. sspitsyn@5209: * All the invocations of the defaultMethod() must be completed successfully. sspitsyn@5209: */ sspitsyn@5209: sspitsyn@5209: import java.lang.invoke.*; sspitsyn@5209: sspitsyn@5209: interface InterfaceWithDefaultMethod { sspitsyn@5209: public void someMethod(); sspitsyn@5209: sspitsyn@5209: default public void defaultMethod(String str){ sspitsyn@5209: System.out.println("defaultMethod() " + str); sspitsyn@5209: } sspitsyn@5209: } sspitsyn@5209: sspitsyn@5209: class Test8015436 implements InterfaceWithDefaultMethod { sspitsyn@5209: @Override sspitsyn@5209: public void someMethod() { sspitsyn@5209: System.out.println("someMethod() invoked"); sspitsyn@5209: } sspitsyn@5209: sspitsyn@5209: public static void main(String[] args) throws Throwable { sspitsyn@5209: Test8015436 testObj = new Test8015436(); sspitsyn@5209: testObj.someMethod(); sspitsyn@5209: testObj.defaultMethod("invoked directly"); sspitsyn@5209: sspitsyn@5209: MethodHandles.Lookup lookup = MethodHandles.lookup(); sspitsyn@5209: MethodType mt = MethodType.methodType(void.class, String.class); sspitsyn@5209: MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt); sspitsyn@5209: mh.invokeExact(testObj, "invoked via a MethodHandle"); sspitsyn@5209: } sspitsyn@5209: } sspitsyn@5209: sspitsyn@5209: /* sspitsyn@5209: * A successful execution gives the output: sspitsyn@5209: * someMethod() invoked sspitsyn@5209: * defaultMethod() invoked directly sspitsyn@5209: * defaultMethod() invoked via a MethodHandle sspitsyn@5209: */