< prev index next >

test/jdk/java/lang/invoke/CallSiteTest.java

Print this page

        

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -22,43 +22,52 @@
  */
 
 /**
  * @test
  * @summary smoke tests for CallSite
- *
- * @build indify.Indify
- * @compile CallSiteTest.java
- * @run main/othervm/timeout=3600 -XX:+IgnoreUnrecognizedVMOptions -XX:-VerifyDependencies
- *      indify.Indify
- *      --expand-properties --classpath ${test.classes}
- *      --java test.java.lang.invoke.CallSiteTest
+ * @library /lib/testlibrary/bytecode /java/lang/invoke/common
+ * @build jdk.experimental.bytecode.BasicClassBuilder test.java.lang.invoke.lib.InstructionHelper
+ * @run main test.java.lang.invoke.CallSiteTest
  */
 
 package test.java.lang.invoke;
 
-import java.io.*;
-
-import java.lang.invoke.*;
-import static java.lang.invoke.MethodHandles.*;
-import static java.lang.invoke.MethodType.*;
+import java.lang.invoke.CallSite;
+import java.lang.invoke.MethodHandle;
+import java.lang.invoke.MethodHandles;
+import java.lang.invoke.MethodType;
+import java.lang.invoke.MutableCallSite;
+import java.lang.invoke.VolatileCallSite;
+
+import static java.lang.invoke.MethodHandles.Lookup;
+import static java.lang.invoke.MethodHandles.lookup;
+import static java.lang.invoke.MethodType.methodType;
+import static test.java.lang.invoke.lib.InstructionHelper.invokedynamic;
 
 public class CallSiteTest {
     private static final Class<?> CLASS = CallSiteTest.class;
 
-    private static CallSite mcs;
-    private static CallSite vcs;
-    private static MethodHandle mh_foo;
-    private static MethodHandle mh_bar;
+    private static final CallSite mcs;
+    private static final CallSite vcs;
+    private static final MethodHandle mh_foo;
+    private static final MethodHandle mh_bar;
 
+    private static final MethodHandle indy_mcs;
+    private static final MethodHandle indy_vcs;
     static {
         try {
-            mh_foo = lookup().findStatic(CLASS, "foo", methodType(int.class, int.class, int.class));
-            mh_bar = lookup().findStatic(CLASS, "bar", methodType(int.class, int.class, int.class));
+            MethodHandles.Lookup l = lookup();
+            mh_foo = l.findStatic(CLASS, "foo", methodType(int.class, int.class, int.class));
+            mh_bar = l.findStatic(CLASS, "bar", methodType(int.class, int.class, int.class));
             mcs = new MutableCallSite(mh_foo);
             vcs = new VolatileCallSite(mh_foo);
+
+            MethodType bsmType = methodType(CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
+            indy_mcs = invokedynamic(l, "mcs", methodType(int.class, int.class, int.class), "bsm_mcs", bsmType, S -> {});
+            indy_vcs = invokedynamic(l, "vcs", methodType(int.class, int.class, int.class), "bsm_vcs", bsmType, S -> {});
         } catch (Exception e) {
-            e.printStackTrace();
+            throw new Error(e);
         }
     }
 
     public static void main(String... av) throws Throwable {
         testMutableCallSite();

@@ -110,54 +119,28 @@
     }
 
     private static int runMutableCallSite() throws Throwable {
         int sum = 0;
         for (int i = 0; i < N; i++) {
-            sum += (int) INDY_mcs().invokeExact(i, i+1);
+            sum += (int) indy_mcs.invokeExact(i, i+1);
         }
         return sum;
     }
     private static int runVolatileCallSite() throws Throwable {
         int sum = 0;
         for (int i = 0; i < N; i++) {
-            sum += (int) INDY_vcs().invokeExact(i, i+1);
+            sum += (int) indy_vcs.invokeExact(i, i+1);
         }
         return sum;
     }
 
     static int foo(int a, int b) { return a + b; }
     static int bar(int a, int b) { return a - b; }
 
-    private static MethodType MT_bsm() {
-        shouldNotCallThis();
-        return methodType(CallSite.class, Lookup.class, String.class, MethodType.class);
-    }
-
-    private static CallSite bsm_mcs(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
+    static CallSite bsm_mcs(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
         return mcs;
     }
-    private static MethodHandle MH_bsm_mcs() throws ReflectiveOperationException {
-        shouldNotCallThis();
-        return lookup().findStatic(lookup().lookupClass(), "bsm_mcs", MT_bsm());
-    }
-    private static MethodHandle INDY_mcs() throws Throwable {
-        shouldNotCallThis();
-        return ((CallSite) MH_bsm_mcs().invoke(lookup(), "foo", methodType(int.class, int.class, int.class))).dynamicInvoker();
-    }
 
-    private static CallSite bsm_vcs(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
+    static CallSite bsm_vcs(Lookup caller, String name, MethodType type) throws ReflectiveOperationException {
         return vcs;
     }
-    private static MethodHandle MH_bsm_vcs() throws ReflectiveOperationException {
-        shouldNotCallThis();
-        return lookup().findStatic(lookup().lookupClass(), "bsm_vcs", MT_bsm());
-    }
-    private static MethodHandle INDY_vcs() throws Throwable {
-        shouldNotCallThis();
-        return ((CallSite) MH_bsm_vcs().invoke(lookup(), "foo", methodType(int.class, int.class, int.class))).dynamicInvoker();
-    }
-
-    private static void shouldNotCallThis() {
-        // if this gets called, the transformation has not taken place
-        throw new AssertionError("this code should be statically transformed away by Indify");
-    }
 }
< prev index next >