test/hotspot/jtreg/runtime/clone/NoClones.jasm
changeset 48463 474cec233fb2
equal deleted inserted replaced
48462:0bce2ae39928 48463:474cec233fb2
       
     1 /*
       
     2  * Copyright (c) 2017, 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 /*
       
    26  * @test
       
    27  * @bug 8154587
       
    28  * @summary Check that a NoSuchMethodError exception gets thrown if invokeinterface
       
    29  *          calls clone() and there is no public implementation of clone().
       
    30  * @compile NoClones.jasm
       
    31  * @run main NoClones
       
    32  */
       
    33 
       
    34 // The below .jasm code implements the following java code:
       
    35 //
       
    36 // interface I1 { }
       
    37 //
       
    38 //
       
    39 // public class NoClones {
       
    40 //
       
    41 //    interface I2 extends I1 { }
       
    42 //
       
    43 //    static class C implements I2 { }
       
    44 //
       
    45 //    static Object test(I2 i) { return i.clone(); }
       
    46 //
       
    47 //    public static void main(String[] args) {
       
    48 //        try {
       
    49 //            String s = (String)test(new C());
       
    50 //            throw new RuntimeException("Expected NSME not thrown");
       
    51 //        } catch (java.lang.NoSuchMethodError e) {
       
    52 //            if (!e.toString().contains("I2.clone")) {
       
    53 //                throw new RuntimeException("Wrong NoSuchMethodError exception thrown");
       
    54 //            }
       
    55 //        }
       
    56 //    }
       
    57 // }
       
    58 
       
    59 
       
    60 interface I1 version 53:0 { } // end Class I1
       
    61 
       
    62 
       
    63 interface  NoClones$I2 implements I1 version 53:0 {
       
    64 
       
    65     static abstract interface InnerClass I2=class NoClones$I2 of class NoClones;
       
    66 
       
    67 } // end Class NoClones$I2
       
    68 
       
    69 
       
    70 super class NoClones$C implements NoClones$I2 version 53:0 {
       
    71 
       
    72     Method "<init>":"()V" stack 1 locals 1 {
       
    73         aload_0;
       
    74         invokespecial    Method java/lang/Object."<init>":"()V";
       
    75         return;
       
    76     }
       
    77 
       
    78     static InnerClass C=class NoClones$C of class NoClones;
       
    79     static abstract interface InnerClass I2=class NoClones$I2 of class NoClones;
       
    80 
       
    81 } // end Class NoClones$C
       
    82 
       
    83 
       
    84 super public class NoClones version 53:0 {
       
    85 
       
    86     public Method "<init>":"()V" stack 1 locals 1 {
       
    87         aload_0;
       
    88         invokespecial    Method java/lang/Object."<init>":"()V";
       
    89         return;
       
    90     }
       
    91 
       
    92     static Method test:"(LNoClones$I2;)Ljava/lang/Object;" stack 1 locals 1 {
       
    93         aload_0;
       
    94         invokeinterface    InterfaceMethod NoClones$I2.clone:"()Ljava/lang/Object;",  1;
       
    95         areturn;
       
    96     }
       
    97 
       
    98     public static Method main:"([Ljava/lang/String;)V" stack 3 locals 2 {
       
    99         try t0;
       
   100         new    class NoClones$C;
       
   101         dup;
       
   102         invokespecial    Method NoClones$C."<init>":"()V";
       
   103         invokestatic    Method test:"(LNoClones$I2;)Ljava/lang/Object;";
       
   104         checkcast    class java/lang/String;
       
   105         astore_1;
       
   106         new    class java/lang/RuntimeException;
       
   107         dup;
       
   108         ldc    String "Expected NSME not thrown";
       
   109         invokespecial    Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V";
       
   110         athrow;
       
   111         endtry t0;
       
   112         catch t0 java/lang/NoSuchMethodError;
       
   113         stack_frame_type stack1;
       
   114         stack_map class java/lang/NoSuchMethodError;
       
   115         astore_1;
       
   116         aload_1;
       
   117         invokevirtual    Method java/lang/NoSuchMethodError.toString:"()Ljava/lang/String;";
       
   118         ldc    String "I2.clone";
       
   119         invokevirtual    Method java/lang/String.contains:"(Ljava/lang/CharSequence;)Z";
       
   120         ifne    L47;
       
   121         new    class java/lang/RuntimeException;
       
   122         dup;
       
   123         ldc    String "Wrong NoSuchMethodError exception thrown";
       
   124         invokespecial    Method java/lang/RuntimeException."<init>":"(Ljava/lang/String;)V";
       
   125         athrow;
       
   126       L47:  stack_frame_type same;
       
   127         return;
       
   128     }
       
   129 
       
   130     static InnerClass C=class NoClones$C of class NoClones;
       
   131     static abstract interface InnerClass I2=class NoClones$I2 of class NoClones;
       
   132 
       
   133 } // end Class NoClones