Path: blob/master/test/hotspot/jtreg/compiler/runtime/cr8015436/Test8015436.java
41153 views
/*1* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 801543626* @summary the IK _initial_method_idnum value must be adjusted if overpass methods are added27* @library /test/lib /28* @modules java.base/jdk.internal.misc29* @build compiler.runtime.cr8015436.Test801543630*31* @run driver compiler.runtime.cr8015436.Driver801543632*/3334/*35* The test checks that a MemberName for the defaultMethod() is cached in36* the class MemberNameTable without a crash in the VM fastdebug mode.37* The original issue was that the InstanceKlass _initial_method_idnum was38* not adjusted properly when the overpass methods are added to the class.39* The expected/correct behavior: The test does not crash nor throw any exceptions.40* All the invocations of the defaultMethod() must be completed successfully.41*/4243package compiler.runtime.cr8015436;4445import java.lang.invoke.MethodHandle;46import java.lang.invoke.MethodHandles;47import java.lang.invoke.MethodType;4849public class Test8015436 implements InterfaceWithDefaultMethod {50public static final String SOME_MTD_INVOKED = "someMethod() invoked";51public static final String DEFAULT_MTD_INVOKED_DIRECTLY = "defaultMethod() invoked directly";52public static final String DEFAULT_MTD_INVOKED_MH = "defaultMethod() invoked via a MethodHandle";5354@Override55public void someMethod() {56System.out.println(SOME_MTD_INVOKED);57}5859public static void main(String[] args) throws Throwable {60Test8015436 testObj = new Test8015436();61testObj.someMethod();62testObj.defaultMethod(DEFAULT_MTD_INVOKED_DIRECTLY);6364MethodHandles.Lookup lookup = MethodHandles.lookup();65MethodType mt = MethodType.methodType(void.class, String.class);66MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt);67mh.invokeExact(testObj, DEFAULT_MTD_INVOKED_MH);68}69}7071interface InterfaceWithDefaultMethod {72public void someMethod();7374default public void defaultMethod(String str){75System.out.println(str);76}77}78/*79* A successful execution gives the output:80* someMethod() invoked81* defaultMethod() invoked directly82* defaultMethod() invoked via a MethodHandle83*/848586