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