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 */ 23 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 */ 31 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 */ 40 41 import java.lang.invoke.*; 42 43 interface InterfaceWithDefaultMethod { 44 public void someMethod(); 45 46 default public void defaultMethod(String str){ 47 System.out.println("defaultMethod() " + str); 48 } 49 } 50 51 public class Test8015436 implements InterfaceWithDefaultMethod { 52 @Override 53 public void someMethod() { 54 System.out.println("someMethod() invoked"); 55 } 56 57 public static void main(String[] args) throws Throwable { 58 Test8015436 testObj = new Test8015436(); 59 testObj.someMethod(); 60 testObj.defaultMethod("invoked directly"); 61 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 } 68 69 /* 70 * A successful execution gives the output: 71 * someMethod() invoked 72 * defaultMethod() invoked directly 73 * defaultMethod() invoked via a MethodHandle 74 */