< prev index next >

test/compiler/runtime/cr8015436/Test8015436.java

Print this page
rev 11557 : 8132919: use package in compiler tests
Reviewed-by: duke


   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  */


   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  *
  29  * @run main compiler.runtime.cr8015436.Test8015436
  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 package compiler.runtime.cr8015436;
  42 
  43 import java.lang.invoke.MethodHandle;
  44 import java.lang.invoke.MethodHandles;
  45 import java.lang.invoke.MethodType;
  46 





  47 public class Test8015436 implements InterfaceWithDefaultMethod {
  48     @Override
  49     public void someMethod() {
  50         System.out.println("someMethod() invoked");
  51     }
  52 
  53     public static void main(String[] args) throws Throwable {
  54         Test8015436 testObj = new Test8015436();
  55         testObj.someMethod();
  56         testObj.defaultMethod("invoked directly");
  57 
  58         MethodHandles.Lookup lookup = MethodHandles.lookup();
  59         MethodType   mt = MethodType.methodType(void.class, String.class);
  60         MethodHandle mh = lookup.findVirtual(Test8015436.class, "defaultMethod", mt);
  61         mh.invokeExact(testObj, "invoked via a MethodHandle");
  62     }
  63 }
  64 
  65 interface InterfaceWithDefaultMethod {
  66     public void someMethod();
  67 
  68     default public void defaultMethod(String str){
  69         System.out.println("defaultMethod() " + str);
  70     }
  71 }
  72 /*
  73  * A successful execution gives the output:
  74  *   someMethod() invoked
  75  *   defaultMethod() invoked directly
  76  *   defaultMethod() invoked via a MethodHandle
  77  */
< prev index next >