當前位置: 首頁>>代碼示例>>Java>>正文


Java CallSite類代碼示例

本文整理匯總了Java中java.lang.invoke.CallSite的典型用法代碼示例。如果您正苦於以下問題:Java CallSite類的具體用法?Java CallSite怎麽用?Java CallSite使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CallSite類屬於java.lang.invoke包,在下文中一共展示了CallSite類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import java.lang.invoke.CallSite; //導入依賴的package包/類
public static void main(String[] args) throws Throwable {
    l = MethodHandles.lookup();
    h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
    MethodType X = mt(int.class, LambdaReceiverBridge.class);
    MethodType A = mt(int.class, LambdaReceiver_A.class);
    MethodType mti = mt(IA.class);
    CallSite cs = LambdaMetafactory.altMetafactory(l, "m", mti,X,h,X,
                                      LambdaMetafactory.FLAG_BRIDGES, 1, A);
    IA p = (IA)cs.dynamicInvoker().invoke();
    LambdaReceiver_A lra = new LambdaReceiver_A();
    try {
        p.m(lra);
    } catch (ClassCastException cce) {
        return;
    }
    throw new AssertionError("CCE expected");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:LambdaReceiverBridge.java

示例2: generateMethodTest2

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method without extra args and
 *  args to the target method.
 */
private void generateMethodTest2(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test2", "()V",
      null, null);
  MethodType mt = MethodType.methodType(
          CallSite.class, MethodHandles.Lookup.class, String.class, MethodType.class);
  Handle bootstrap = new Handle( Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmLookupStatic", mt.toMethodDescriptorString(), false);
  mv.visitLdcInsn(new Boolean(true));
  mv.visitLdcInsn(new Byte((byte) 127));
  mv.visitLdcInsn(new Character('c'));
  mv.visitLdcInsn(new Short((short) 1024));
  mv.visitLdcInsn(new Integer(123456));
  mv.visitLdcInsn(new Float(1.2f));
  mv.visitLdcInsn(new Long(123456789));
  mv.visitLdcInsn(new Double(3.5123456789));
  mv.visitLdcInsn("String");
  mv.visitInvokeDynamicInsn("targetMethodTest2", "(ZBCSIFJDLjava/lang/String;)V", bootstrap);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:25,代碼來源:TestGenerator.java

示例3: generateMethodTest4

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invokespecial.
 */
private void generateMethodTest4(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test4", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle( Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallSite", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest5", "(Linvokecustom/InvokeCustom;)V", bootstrap,
      new Handle( Opcodes.H_INVOKESPECIAL, Type.getInternalName(Super.class),
          "targetMethodTest5", "()V", false));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:22,代碼來源:TestGenerator.java

示例4: generateMethodTest5

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that shadows another default method from a super interface.
 */
private void generateMethodTest5(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test5", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest6", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest6", "(Linvokecustom/I;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(I.class),
          "targetMethodTest6", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:23,代碼來源:TestGenerator.java

示例5: generateMethodTest6

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a default method into an interface
 *  that is at the end of a chain of interfaces.
 */
private void generateMethodTest6(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test6", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest7", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest7", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest7", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:23,代碼來源:TestGenerator.java

示例6: generateMethodTest7

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke interface. The target method is a method into an interface
 *  that is shadowed by another definition into a sub interfaces.
 */
private void generateMethodTest7(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test7", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest8", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest8", "(Linvokecustom/J;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEINTERFACE, Type.getInternalName(J.class),
          "targetMethodTest8", "()V", true));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:23,代碼來源:TestGenerator.java

示例7: generateMethodTest8

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke virtual. The target method is a method into an interface that is
 *  not shadowed by an implementation into a classes implementing the interface.
 */
private void generateMethodTest8(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test8", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest9", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest9", "(Linvokecustom/InvokeCustom;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEVIRTUAL, Type.getInternalName(InvokeCustom.class),
          "targetMethodTest9", "()V", false));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:23,代碼來源:TestGenerator.java

示例8: generateMethodTest9

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind invoke virtual. The target method is a method into a class implementing
 *  an abstract method and that shadows a default method from an interface.
 */
private void generateMethodTest9(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test9", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethodTest10", mt.toMethodDescriptorString(), false);
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("targetMethodTest10", "(Linvokecustom/InvokeCustom;)V", bootstrap,
      new Handle(Opcodes.H_INVOKEVIRTUAL, Type.getInternalName(InvokeCustom.class),
          "targetMethodTest10", "()V", false));
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:23,代碼來源:TestGenerator.java

示例9: generateMethodTest10

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get static. The method handle read a static field from a class.
 */
private void generateMethodTest10(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test10", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitInvokeDynamicInsn("staticField1", "()Ljava/lang/String;", bootstrap,
      new Handle(Opcodes.H_GETSTATIC, Type.getInternalName(InvokeCustom.class),
          "staticField1", "Ljava/lang/String;", false));
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:26,代碼來源:TestGenerator.java

示例10: generateMethodTest12

import java.lang.invoke.CallSite; //導入依賴的package包/類
/**
 *  Generate test with an invokedynamic, a static bootstrap method with an extra arg that is a
 *  MethodHandle of kind get instance. The method handle read an instance field from a class.
 */
private void generateMethodTest12(ClassVisitor cv) {
  MethodVisitor mv = cv.visitMethod(Opcodes.ACC_PUBLIC + Opcodes.ACC_STATIC, "test12", "()V",
      null, null);
  MethodType mt = MethodType.methodType(CallSite.class, MethodHandles.Lookup.class, String.class,
      MethodType.class, MethodHandle.class);
  Handle bootstrap = new Handle(Opcodes.H_INVOKESTATIC, Type.getInternalName(InvokeCustom.class),
      "bsmCreateCallCallingtargetMethod", mt.toMethodDescriptorString(), false);
  mv.visitFieldInsn(Opcodes.GETSTATIC,
      "java/lang/System",
      "out",
      "Ljava/io/PrintStream;");
  mv.visitTypeInsn(Opcodes.NEW, Type.getInternalName(InvokeCustom.class));
  mv.visitInsn(Opcodes.DUP);
  mv.visitMethodInsn(
      Opcodes.INVOKESPECIAL, Type.getInternalName(InvokeCustom.class), "<init>", "()V", false);
  mv.visitInvokeDynamicInsn("instanceField1", "(Linvokecustom/InvokeCustom;)Ljava/lang/String;",
      bootstrap, new Handle(Opcodes.H_GETFIELD, Type.getInternalName(InvokeCustom.class),
          "instanceField1", "Ljava/lang/String;", false));
  mv.visitMethodInsn(Opcodes.INVOKEVIRTUAL,
      "java/io/PrintStream",
      "println",
      "(Ljava/lang/String;)V", false);
  mv.visitInsn(Opcodes.RETURN);
  mv.visitMaxs(-1, -1);
}
 
開發者ID:inferjay,項目名稱:r8,代碼行數:30,代碼來源:TestGenerator.java

示例11: testOneType

import java.lang.invoke.CallSite; //導入依賴的package包/類
/** calls toString() on integers, twice */
public void testOneType() throws Throwable {
    CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), 
                                              "toString", 
                                              MethodType.methodType(String.class, Object.class), 
                                              0,
                                              DefBootstrap.METHOD_CALL, "");
    MethodHandle handle = site.dynamicInvoker();
    assertDepthEquals(site, 0);

    // invoke with integer, needs lookup
    assertEquals("5", (String)handle.invokeExact((Object)5));
    assertDepthEquals(site, 1);

    // invoked with integer again: should be cached
    assertEquals("6", (String)handle.invokeExact((Object)6));
    assertDepthEquals(site, 1);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:19,代碼來源:DefBootstrapTests.java

示例12: testTwoTypes

import java.lang.invoke.CallSite; //導入依賴的package包/類
public void testTwoTypes() throws Throwable {
    CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), 
                                              "toString", 
                                              MethodType.methodType(String.class, Object.class), 
                                              0,
                                              DefBootstrap.METHOD_CALL, "");
    MethodHandle handle = site.dynamicInvoker();
    assertDepthEquals(site, 0);

    assertEquals("5", (String)handle.invokeExact((Object)5));
    assertDepthEquals(site, 1);
    assertEquals("1.5", (String)handle.invokeExact((Object)1.5f));
    assertDepthEquals(site, 2);

    // both these should be cached
    assertEquals("6", (String)handle.invokeExact((Object)6));
    assertDepthEquals(site, 2);
    assertEquals("2.5", (String)handle.invokeExact((Object)2.5f));
    assertDepthEquals(site, 2);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:21,代碼來源:DefBootstrapTests.java

示例13: testTooManyTypes

import java.lang.invoke.CallSite; //導入依賴的package包/類
public void testTooManyTypes() throws Throwable {
    // if this changes, test must be rewritten
    assertEquals(5, DefBootstrap.PIC.MAX_DEPTH);
    CallSite site = DefBootstrap.bootstrap(MethodHandles.publicLookup(), 
                                              "toString", 
                                              MethodType.methodType(String.class, Object.class), 
                                              0,
                                              DefBootstrap.METHOD_CALL, "");
    MethodHandle handle = site.dynamicInvoker();
    assertDepthEquals(site, 0);

    assertEquals("5", (String)handle.invokeExact((Object)5));
    assertDepthEquals(site, 1);
    assertEquals("1.5", (String)handle.invokeExact((Object)1.5f));
    assertDepthEquals(site, 2);
    assertEquals("6", (String)handle.invokeExact((Object)6L));
    assertDepthEquals(site, 3);
    assertEquals("3.2", (String)handle.invokeExact((Object)3.2d));
    assertDepthEquals(site, 4);
    assertEquals("foo", (String)handle.invokeExact((Object)"foo"));
    assertDepthEquals(site, 5);
    assertEquals("c", (String)handle.invokeExact((Object)'c'));
    assertDepthEquals(site, 5);
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:DefBootstrapTests.java

示例14: relinkComposableInvoker

import java.lang.invoke.CallSite; //導入依賴的package包/類
private static void relinkComposableInvoker(final CallSite cs, final CompiledFunction inv, final boolean constructor) {
    final HandleAndAssumptions handleAndAssumptions = inv.getValidOptimisticInvocation(new Supplier<MethodHandle>() {
        @Override
        public MethodHandle get() {
            return inv.getInvokerOrConstructor(constructor);
        }
    });
    final MethodHandle handle = handleAndAssumptions.handle;
    final SwitchPoint assumptions = handleAndAssumptions.assumptions;
    final MethodHandle target;
    if(assumptions == null) {
        target = handle;
    } else {
        final MethodHandle relink = MethodHandles.insertArguments(RELINK_COMPOSABLE_INVOKER, 0, cs, inv, constructor);
        target = assumptions.guardWithTest(handle, MethodHandles.foldArguments(cs.dynamicInvoker(), relink));
    }
    cs.setTarget(target.asType(cs.type()));
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:19,代碼來源:CompiledFunction.java

示例15: main

import java.lang.invoke.CallSite; //導入依賴的package包/類
public static void main(String[] args) throws Throwable {
    l = MethodHandles.lookup();
    h = l.findVirtual(LambdaReceiver_A.class, "f", mt(int.class));
    MethodType X = mt(int.class, LambdaReceiver.class);
    MethodType A = mt(int.class, LambdaReceiver_A.class);
    MethodType mti = mt(IA.class);
    CallSite cs = LambdaMetafactory.metafactory(l, "m", mti,A,h,X);
    IA p = (IA)cs.dynamicInvoker().invoke();
    LambdaReceiver_A lra = new LambdaReceiver_A();
    try {
        p.m(lra);
    } catch (ClassCastException cce) {
        return;
    }
    throw new AssertionError("CCE expected");
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:LambdaReceiver.java


注:本文中的java.lang.invoke.CallSite類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。