hotspot/test/compiler/jsr292/InvokerGC.java
changeset 37289 9989add27bf4
child 38152 80e5da81fb2c
child 37773 e5b3e9732c3c
equal deleted inserted replaced
37286:67b04a68b881 37289:9989add27bf4
       
     1 /*
       
     2  * Copyright (c) 2016, 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 8067247
       
    27  * @library /test/lib /compiler/whitebox /
       
    28  * @run main/bootclasspath -Xcomp -Xbatch
       
    29  *      -XX:CompileCommand=compileonly,InvokerGC::test
       
    30  *      -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI
       
    31  *      InvokerGC
       
    32  */
       
    33 
       
    34 import java.lang.invoke.*;
       
    35 import sun.hotspot.WhiteBox;
       
    36 
       
    37 public class InvokerGC {
       
    38     static final WhiteBox WB = WhiteBox.getWhiteBox();
       
    39 
       
    40     static MethodHandle mh;
       
    41     static {
       
    42         try {
       
    43             mh = MethodHandles.lookup().findStatic(InvokerGC.class, "dummy", MethodType.methodType(void.class));
       
    44         } catch (Exception e) {
       
    45             throw new Error(e);
       
    46         }
       
    47     }
       
    48 
       
    49     static void dummy() {}
       
    50 
       
    51     static void test() {
       
    52         try {
       
    53             mh.invoke();
       
    54         } catch (Throwable e) {
       
    55             throw new Error(e);
       
    56         }
       
    57     }
       
    58 
       
    59     public static void main(String[] args) throws Throwable {
       
    60         mh.invoke(); // Pre-generate an invoker for ()V signature
       
    61 
       
    62         test(); // trigger method compilation
       
    63         test();
       
    64 
       
    65         WB.fullGC(); // WB.fullGC has always clear softref policy.
       
    66 
       
    67         test();
       
    68 
       
    69         WB.clearInlineCaches(true); // Preserve static stubs.
       
    70 
       
    71         test(); // Trigger call site re-resolution. Invoker LambdaForm should stay the same.
       
    72 
       
    73         System.out.println("TEST PASSED");
       
    74     }
       
    75 }