Examples of MethodHandle


Examples of com.sun.tools.javac.jvm.Pool.MethodHandle

                    poolbuf.appendChar(pool.put(m.owner));
                    poolbuf.appendChar(pool.put(nameType(m)));
                } else {
                    //invokedynamic
                    DynamicMethodSymbol dynSym = (DynamicMethodSymbol)m;
                    MethodHandle handle = new MethodHandle(dynSym.bsmKind, dynSym.bsm, types);
                    DynamicMethod dynMeth = new DynamicMethod(dynSym, types);
                    bootstrapMethods.put(dynMeth, handle);
                    //init cp entries
                    pool.put(names.BootstrapMethods);
                    pool.put(handle);
                    for (Object staticArg : dynSym.staticArgs) {
                        pool.put(staticArg);
                    }
                    poolbuf.appendByte(CONSTANT_InvokeDynamic);
                    poolbuf.appendChar(bootstrapMethods.size() - 1);
                    poolbuf.appendChar(pool.put(nameType(dynSym)));
                }
            } else if (value instanceof VarSymbol) {
                VarSymbol v = (VarSymbol)value;
                poolbuf.appendByte(CONSTANT_Fieldref);
                poolbuf.appendChar(pool.put(v.owner));
                poolbuf.appendChar(pool.put(nameType(v)));
            } else if (value instanceof Name) {
                poolbuf.appendByte(CONSTANT_Utf8);
                byte[] bs = ((Name)value).toUtf();
                poolbuf.appendChar(bs.length);
                poolbuf.appendBytes(bs, 0, bs.length);
                if (bs.length > Pool.MAX_STRING_LENGTH)
                    throw new StringOverflow(value.toString());
            } else if (value instanceof ClassSymbol) {
                ClassSymbol c = (ClassSymbol)value;
                if (c.owner.kind == TYP) pool.put(c.owner);
                poolbuf.appendByte(CONSTANT_Class);
                if (c.type.hasTag(ARRAY)) {
                    poolbuf.appendChar(pool.put(typeSig(c.type)));
                } else {
                    poolbuf.appendChar(pool.put(names.fromUtf(externalize(c.flatname))));
                    enterInner(c);
                }
            } else if (value instanceof NameAndType) {
                NameAndType nt = (NameAndType)value;
                poolbuf.appendByte(CONSTANT_NameandType);
                poolbuf.appendChar(pool.put(nt.name));
                poolbuf.appendChar(pool.put(typeSig(nt.uniqueType.type)));
            } else if (value instanceof Integer) {
                poolbuf.appendByte(CONSTANT_Integer);
                poolbuf.appendInt(((Integer)value).intValue());
            } else if (value instanceof Long) {
                poolbuf.appendByte(CONSTANT_Long);
                poolbuf.appendLong(((Long)value).longValue());
                i++;
            } else if (value instanceof Float) {
                poolbuf.appendByte(CONSTANT_Float);
                poolbuf.appendFloat(((Float)value).floatValue());
            } else if (value instanceof Double) {
                poolbuf.appendByte(CONSTANT_Double);
                poolbuf.appendDouble(((Double)value).doubleValue());
                i++;
            } else if (value instanceof String) {
                poolbuf.appendByte(CONSTANT_String);
                poolbuf.appendChar(pool.put(names.fromString((String)value)));
            } else if (value instanceof UniqueType) {
                Type type = ((UniqueType)value).type;
                if (type instanceof MethodType) {
                    poolbuf.appendByte(CONSTANT_MethodType);
                    poolbuf.appendChar(pool.put(typeSig((MethodType)type)));
                } else {
                    if (type.hasTag(CLASS)) enterInner((ClassSymbol)type.tsym);
                    poolbuf.appendByte(CONSTANT_Class);
                    poolbuf.appendChar(pool.put(xClassName(type)));
                }
            } else if (value instanceof MethodHandle) {
                MethodHandle ref = (MethodHandle)value;
                poolbuf.appendByte(CONSTANT_MethodHandle);
                poolbuf.appendByte(ref.refKind);
                poolbuf.appendChar(pool.put(ref.refSym));
            } else {
                Assert.error("writePool " + value);
View Full Code Here

Examples of java.dyn.MethodHandle

        } else {
            site = new JRubyCallSite(type, CallType.FUNCTIONAL);
        }
       
        MethodType fallbackType = type.insertParameterTypes(0, JRubyCallSite.class);
        MethodHandle myFallback = MethodHandles.insertArguments(
                findStatic(InvokeDynamicSupport.class, "fallback",
                fallbackType),
                0,
                site);
        site.setTarget(myFallback);
View Full Code Here

Examples of java.dyn.MethodHandle

                        return createNativeGWT(nativeCall, test, fallback, entry, site);
                    }
                }
            }
        }
        MethodHandle myTest = MethodHandles.insertArguments(test, 0, entry.token);
        MethodHandle myTarget = MethodHandles.insertArguments(target, 0, entry);
        MethodHandle myFallback = MethodHandles.insertArguments(fallback, 0, site);
        MethodHandle guardWithTest = MethodHandles.guardWithTest(myTest, myTarget, myFallback);
       
        return MethodHandles.convertArguments(guardWithTest, site.type());
    }
View Full Code Here

Examples of java.dyn.MethodHandle

    }

    private static MethodHandle createNativeGWT(DynamicMethod.NativeCall nativeCall, MethodHandle test, MethodHandle fallback, CacheEntry entry, JRubyCallSite site) {
        try {
            boolean isStatic = nativeCall.isStatic();
            MethodHandle nativeTarget;
            if (isStatic) {
                nativeTarget = MethodHandles.lookup().findStatic(
                        nativeCall.getNativeTarget(),
                        nativeCall.getNativeName(),
                        MethodType.methodType(nativeCall.getNativeReturn(),
                        nativeCall.getNativeSignature()));
            } else {
                nativeTarget = MethodHandles.lookup().findVirtual(
                        nativeCall.getNativeTarget(),
                        nativeCall.getNativeName(),
                        MethodType.methodType(nativeCall.getNativeReturn(),
                        nativeCall.getNativeSignature()));
            }
            int argCount = getArgCount(nativeCall.getNativeSignature(), nativeCall.isStatic());
            switch (argCount) {
                case 0:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), isStatic ? new int[] {0, 2} : new int[] {2, 0});
                    break;
                case -1:
                case 1:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), isStatic ? new int[] {0, 2, 4} : new int[] {2, 0, 4});
                    break;
                case 2:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), isStatic ? new int[] {0, 2, 4, 5} : new int[] {2, 0, 4, 5});
                    break;
                case 3:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), isStatic ? new int[] {0, 2, 4, 5, 6} : new int[] {2, 0, 4, 5, 6});
                    break;
                default:
                    throw new RuntimeException("unknown arg count: " + argCount);
            }
            MethodHandle myFallback = MethodHandles.insertArguments(fallback, 0, site);
            MethodHandle myTest = MethodHandles.insertArguments(test, 0, entry.token);
            MethodHandle gwt = MethodHandles.guardWithTest(myTest, nativeTarget, myFallback);
            return MethodHandles.convertArguments(gwt, site.type());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of java.dyn.MethodHandle

        }
    }

    private static MethodHandle createRubyGWT(DynamicMethod.NativeCall nativeCall, MethodHandle test, MethodHandle fallback, CacheEntry entry, JRubyCallSite site) {
        try {
            MethodHandle nativeTarget;
            nativeTarget = MethodHandles.lookup().findStatic(
                    nativeCall.getNativeTarget(),
                    nativeCall.getNativeName(),
                    MethodType.methodType(nativeCall.getNativeReturn(),
                    nativeCall.getNativeSignature()));
            CompiledMethod cm = (CompiledMethod)entry.method;
            nativeTarget = MethodHandles.insertArguments(nativeTarget, 0, cm.getScriptObject());
            nativeTarget = MethodHandles.insertArguments(nativeTarget, nativeTarget.type().parameterCount() - 1, Block.NULL_BLOCK);
            int argCount = getRubyArgCount(nativeCall.getNativeSignature());
            switch (argCount) {
                case 0:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), new int[] {0, 2});
                    break;
                case -1:
                case 1:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), new int[] {0, 2, 4});
                    break;
                case 2:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), new int[] {0, 2, 4, 5});
                    break;
                case 3:
                    nativeTarget = MethodHandles.permuteArguments(nativeTarget, site.type(), new int[] {0, 2, 4, 5, 6});
                    break;
                default:
                    throw new RuntimeException("unknown arg count: " + argCount);
            }
            MethodHandle myFallback = MethodHandles.insertArguments(fallback, 0, site);
            MethodHandle myTest = MethodHandles.insertArguments(test, 0, entry.token);
            MethodHandle gwt = MethodHandles.guardWithTest(myTest, nativeTarget, myFallback);
            return MethodHandles.convertArguments(gwt, site.type());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

        Class< ? > class1,
        Class< ? > class2)
    {
        int rank = Math.max(RANK_MAP.get(class1), RANK_MAP.get(class2));
        String mangledName = opName + rank;
        MethodHandle mh = BINARY_CACHE.get(mangledName);
        if (mh != null) {
            return mh;
        }

        for (; rank < PRIMITIVE_ARRAY.length;) {
View Full Code Here

Examples of java.lang.invoke.MethodHandle

            // don't forget that && and || are lazy !!
            // System.out.println("fallback called with "+opName+'('+v1.getClass()+','+v2.getClass()+')');

            Class< ? extends Object> class1 = v1.getClass();
            Class< ? extends Object> class2 = v2.getClass();
            MethodHandle op = lookupBinaryOp(opName, class1, class2);

            // convert arguments
            MethodType type = type();
            MethodType opType = op.type();
            if (opType.parameterType(0) == String.class) {
                if (opType.parameterType(1) == String.class) {
                    op = MethodHandles.filterArguments(op,
                            0,
                            TO_STRING,
                            TO_STRING);
                } else {
                    op = MethodHandles.filterArguments(op, 0, TO_STRING);
                    op = MethodHandles.explicitCastArguments(op, type);
                }
            } else {
                if (opType.parameterType(1) == String.class) {
                    op = MethodHandles.filterArguments(op, 1, TO_STRING);
                }
                op = MethodHandles.explicitCastArguments(op, type);
            }

            // prepare guard
            MethodHandle guard = MethodHandles.guardWithTest(TEST1.bindTo(class1),
                    MethodHandles.guardWithTest(TEST2.bindTo(class2),
                            op,
                            fallback),
                    fallback);
View Full Code Here

Examples of java.lang.invoke.MethodHandle

  protected synchronized void resetCache() {
    this.cache = new CacheEntry[0];
  }

  private MethodHandle lookupMethodForNil() {
    MethodHandle castHandle = findMethodForNil();
    addCacheEntry(null, castHandle);
    return castHandle;
  }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

    addCacheEntry(null, castHandle);
    return castHandle;
  }

  private MethodHandle lookupMethod(final Class receiverClass) {
    MethodHandle castHandle = findMethod(receiverClass);
    addCacheEntry(receiverClass, castHandle);
    return castHandle;
  }
View Full Code Here

Examples of java.lang.invoke.MethodHandle

    return false;
  }

  private MethodHandle getGuardedMethod(CacheEntry entry,
      MethodHandle fallback) {
    MethodHandle test = entry.receiverClass == null ? NIL_TEST_METHOD_HANDLE
         : MethodHandles.insertArguments(
        TYPE_TEST_METHOD_HANDLE, 1, entry.receiverClass);
    Class[] tail = ArrayExtensions.tail(type.parameterArray());
    test = MethodHandles.dropArguments(test, 1, tail);
    test = test.asType(MethodType.methodType(Boolean.TYPE,
        type.parameterArray()));
    MethodHandle guard1 = MethodHandles.guardWithTest(test,
        entry.methodHandle, fallback);
    return guard1;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.