Java Code Examples for sun.invoke.util.BytecodeDescriptor#unparse()

The following examples show how to use sun.invoke.util.BytecodeDescriptor#unparse() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MemberName.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/** Utility method to produce the signature of this member,
 *  used within the class file format to describe its type.
 */
public String getSignature() {
    if (type == null) {
        expandFromVM();
        if (type == null) {
            return null;
        }
    }
    if (isInvocable())
        return BytecodeDescriptor.unparse(getMethodType());
    else
        return BytecodeDescriptor.unparse(getFieldType());
}
 
Example 2
Source File: MemberName.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/** Utility method to produce the signature of this member,
 *  used within the class file format to describe its type.
 */
public String getSignature() {
    if (type == null) {
        expandFromVM();
        if (type == null) {
            return null;
        }
    }
    if (isInvocable())
        return BytecodeDescriptor.unparse(getMethodType());
    else
        return BytecodeDescriptor.unparse(getFieldType());
}
 
Example 3
Source File: MemberName.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/** Utility method to produce the signature of this member,
 *  used within the class file format to describe its type.
 */
public String getSignature() {
    if (type == null) {
        expandFromVM();
        if (type == null) {
            return null;
        }
    }
    if (isInvocable())
        return BytecodeDescriptor.unparse(getMethodType());
    else
        return BytecodeDescriptor.unparse(getFieldType());
}
 
Example 4
Source File: MemberName.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/** Utility method to produce the signature of this member,
 *  used within the class file format to describe its type.
 */
public String getSignature() {
    if (type == null) {
        expandFromVM();
        if (type == null) {
            return null;
        }
    }
    if (isInvocable())
        return BytecodeDescriptor.unparse(getMethodType());
    else
        return BytecodeDescriptor.unparse(getFieldType());
}
 
Example 5
Source File: MemberName.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
List<MemberName> getMembers(Class<?> defc,
        String matchName, Object matchType,
        int matchFlags, Class<?> lookupClass) {
    matchFlags &= ALLOWED_FLAGS;
    String matchSig = null;
    if (matchType != null) {
        matchSig = BytecodeDescriptor.unparse(matchType);
        if (matchSig.startsWith("("))
            matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
        else
            matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
    }
    final int BUF_MAX = 0x2000;
    int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
    MemberName[] buf = newMemberBuffer(len1);
    int totalCount = 0;
    ArrayList<MemberName[]> bufs = null;
    int bufCount = 0;
    for (;;) {
        bufCount = MethodHandleNatives.getMembers(defc,
                matchName, matchSig, matchFlags,
                lookupClass,
                totalCount, buf);
        if (bufCount <= buf.length) {
            if (bufCount < 0)  bufCount = 0;
            totalCount += bufCount;
            break;
        }
        // JVM returned to us with an intentional overflow!
        totalCount += buf.length;
        int excess = bufCount - buf.length;
        if (bufs == null)  bufs = new ArrayList<>(1);
        bufs.add(buf);
        int len2 = buf.length;
        len2 = Math.max(len2, excess);
        len2 = Math.max(len2, totalCount / 4);
        buf = newMemberBuffer(Math.min(BUF_MAX, len2));
    }
    ArrayList<MemberName> result = new ArrayList<>(totalCount);
    if (bufs != null) {
        for (MemberName[] buf0 : bufs) {
            Collections.addAll(result, buf0);
        }
    }
    result.addAll(Arrays.asList(buf).subList(0, bufCount));
    // Signature matching is not the same as type matching, since
    // one signature might correspond to several types.
    // So if matchType is a Class or MethodType, refilter the results.
    if (matchType != null && matchType != matchSig) {
        for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
            MemberName m = it.next();
            if (!matchType.equals(m.getType()))
                it.remove();
        }
    }
    return result;
}
 
Example 6
Source File: MethodType.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 7
Source File: MethodType.java    From Java8CN with Apache License 2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 8
Source File: MethodType.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 9
Source File: MethodType.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 10
Source File: MemberName.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
List<MemberName> getMembers(Class<?> defc,
        String matchName, Object matchType,
        int matchFlags, Class<?> lookupClass) {
    matchFlags &= ALLOWED_FLAGS;
    String matchSig = null;
    if (matchType != null) {
        matchSig = BytecodeDescriptor.unparse(matchType);
        if (matchSig.startsWith("("))
            matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
        else
            matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
    }
    final int BUF_MAX = 0x2000;
    int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
    MemberName[] buf = newMemberBuffer(len1);
    int totalCount = 0;
    ArrayList<MemberName[]> bufs = null;
    int bufCount = 0;
    for (;;) {
        bufCount = MethodHandleNatives.getMembers(defc,
                matchName, matchSig, matchFlags,
                lookupClass,
                totalCount, buf);
        if (bufCount <= buf.length) {
            if (bufCount < 0)  bufCount = 0;
            totalCount += bufCount;
            break;
        }
        // JVM returned to us with an intentional overflow!
        totalCount += buf.length;
        int excess = bufCount - buf.length;
        if (bufs == null)  bufs = new ArrayList<>(1);
        bufs.add(buf);
        int len2 = buf.length;
        len2 = Math.max(len2, excess);
        len2 = Math.max(len2, totalCount / 4);
        buf = newMemberBuffer(Math.min(BUF_MAX, len2));
    }
    ArrayList<MemberName> result = new ArrayList<>(totalCount);
    if (bufs != null) {
        for (MemberName[] buf0 : bufs) {
            Collections.addAll(result, buf0);
        }
    }
    result.addAll(Arrays.asList(buf).subList(0, bufCount));
    // Signature matching is not the same as type matching, since
    // one signature might correspond to several types.
    // So if matchType is a Class or MethodType, refilter the results.
    if (matchType != null && matchType != matchSig) {
        for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
            MemberName m = it.next();
            if (!matchType.equals(m.getType()))
                it.remove();
        }
    }
    return result;
}
 
Example 11
Source File: MethodType.java    From jdk-1.7-annotated with Apache License 2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 12
Source File: MemberName.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
List<MemberName> getMembers(Class<?> defc,
        String matchName, Object matchType,
        int matchFlags, Class<?> lookupClass) {
    matchFlags &= ALLOWED_FLAGS;
    String matchSig = null;
    if (matchType != null) {
        matchSig = BytecodeDescriptor.unparse(matchType);
        if (matchSig.startsWith("("))
            matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
        else
            matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
    }
    final int BUF_MAX = 0x2000;
    int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
    MemberName[] buf = newMemberBuffer(len1);
    int totalCount = 0;
    ArrayList<MemberName[]> bufs = null;
    int bufCount = 0;
    for (;;) {
        bufCount = MethodHandleNatives.getMembers(defc,
                matchName, matchSig, matchFlags,
                lookupClass,
                totalCount, buf);
        if (bufCount <= buf.length) {
            if (bufCount < 0)  bufCount = 0;
            totalCount += bufCount;
            break;
        }
        // JVM returned to us with an intentional overflow!
        totalCount += buf.length;
        int excess = bufCount - buf.length;
        if (bufs == null)  bufs = new ArrayList<>(1);
        bufs.add(buf);
        int len2 = buf.length;
        len2 = Math.max(len2, excess);
        len2 = Math.max(len2, totalCount / 4);
        buf = newMemberBuffer(Math.min(BUF_MAX, len2));
    }
    ArrayList<MemberName> result = new ArrayList<>(totalCount);
    if (bufs != null) {
        for (MemberName[] buf0 : bufs) {
            Collections.addAll(result, buf0);
        }
    }
    result.addAll(Arrays.asList(buf).subList(0, bufCount));
    // Signature matching is not the same as type matching, since
    // one signature might correspond to several types.
    // So if matchType is a Class or MethodType, refilter the results.
    if (matchType != null && matchType != matchSig) {
        for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
            MemberName m = it.next();
            if (!matchType.equals(m.getType()))
                it.remove();
        }
    }
    return result;
}
 
Example 13
Source File: MethodType.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static String toFieldDescriptorString(Class<?> cls) {
    return BytecodeDescriptor.unparse(cls);
}
 
Example 14
Source File: MemberName.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
List<MemberName> getMembers(Class<?> defc,
        String matchName, Object matchType,
        int matchFlags, Class<?> lookupClass) {
    matchFlags &= ALLOWED_FLAGS;
    String matchSig = null;
    if (matchType != null) {
        matchSig = BytecodeDescriptor.unparse(matchType);
        if (matchSig.startsWith("("))
            matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
        else
            matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
    }
    final int BUF_MAX = 0x2000;
    int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
    MemberName[] buf = newMemberBuffer(len1);
    int totalCount = 0;
    ArrayList<MemberName[]> bufs = null;
    int bufCount = 0;
    for (;;) {
        bufCount = MethodHandleNatives.getMembers(defc,
                matchName, matchSig, matchFlags,
                lookupClass,
                totalCount, buf);
        if (bufCount <= buf.length) {
            if (bufCount < 0)  bufCount = 0;
            totalCount += bufCount;
            break;
        }
        // JVM returned to us with an intentional overflow!
        totalCount += buf.length;
        int excess = bufCount - buf.length;
        if (bufs == null)  bufs = new ArrayList<>(1);
        bufs.add(buf);
        int len2 = buf.length;
        len2 = Math.max(len2, excess);
        len2 = Math.max(len2, totalCount / 4);
        buf = newMemberBuffer(Math.min(BUF_MAX, len2));
    }
    ArrayList<MemberName> result = new ArrayList<>(totalCount);
    if (bufs != null) {
        for (MemberName[] buf0 : bufs) {
            Collections.addAll(result, buf0);
        }
    }
    result.addAll(Arrays.asList(buf).subList(0, bufCount));
    // Signature matching is not the same as type matching, since
    // one signature might correspond to several types.
    // So if matchType is a Class or MethodType, refilter the results.
    if (matchType != null && matchType != matchSig) {
        for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
            MemberName m = it.next();
            if (!matchType.equals(m.getType()))
                it.remove();
        }
    }
    return result;
}
 
Example 15
Source File: MemberName.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
List<MemberName> getMembers(Class<?> defc,
        String matchName, Object matchType,
        int matchFlags, Class<?> lookupClass) {
    matchFlags &= ALLOWED_FLAGS;
    String matchSig = null;
    if (matchType != null) {
        matchSig = BytecodeDescriptor.unparse(matchType);
        if (matchSig.startsWith("("))
            matchFlags &= ~(ALL_KINDS & ~IS_INVOCABLE);
        else
            matchFlags &= ~(ALL_KINDS & ~IS_FIELD);
    }
    final int BUF_MAX = 0x2000;
    int len1 = matchName == null ? 10 : matchType == null ? 4 : 1;
    MemberName[] buf = newMemberBuffer(len1);
    int totalCount = 0;
    ArrayList<MemberName[]> bufs = null;
    int bufCount = 0;
    for (;;) {
        bufCount = MethodHandleNatives.getMembers(defc,
                matchName, matchSig, matchFlags,
                lookupClass,
                totalCount, buf);
        if (bufCount <= buf.length) {
            if (bufCount < 0)  bufCount = 0;
            totalCount += bufCount;
            break;
        }
        // JVM returned to us with an intentional overflow!
        totalCount += buf.length;
        int excess = bufCount - buf.length;
        if (bufs == null)  bufs = new ArrayList<>(1);
        bufs.add(buf);
        int len2 = buf.length;
        len2 = Math.max(len2, excess);
        len2 = Math.max(len2, totalCount / 4);
        buf = newMemberBuffer(Math.min(BUF_MAX, len2));
    }
    ArrayList<MemberName> result = new ArrayList<>(totalCount);
    if (bufs != null) {
        for (MemberName[] buf0 : bufs) {
            Collections.addAll(result, buf0);
        }
    }
    result.addAll(Arrays.asList(buf).subList(0, bufCount));
    // Signature matching is not the same as type matching, since
    // one signature might correspond to several types.
    // So if matchType is a Class or MethodType, refilter the results.
    if (matchType != null && matchType != matchSig) {
        for (Iterator<MemberName> it = result.iterator(); it.hasNext();) {
            MemberName m = it.next();
            if (!matchType.equals(m.getType()))
                it.remove();
        }
    }
    return result;
}
 
Example 16
Source File: InnerClassLambdaMetafactory.java    From openjdk-jdk8u with GNU General Public License v2.0 3 votes vote down vote up
/**
 * General meta-factory constructor, supporting both standard cases and
 * allowing for uncommon options such as serialization or bridging.
 *
 * @param caller Stacked automatically by VM; represents a lookup context
 *               with the accessibility privileges of the caller.
 * @param invokedType Stacked automatically by VM; the signature of the
 *                    invoked method, which includes the expected static
 *                    type of the returned lambda object, and the static
 *                    types of the captured arguments for the lambda.  In
 *                    the event that the implementation method is an
 *                    instance method, the first argument in the invocation
 *                    signature will correspond to the receiver.
 * @param samMethodName Name of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a String.
 * @param samMethodType Type of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a MethodType.
 * @param implMethod The implementation method which should be called (with
 *                   suitable adaptation of argument types, return types,
 *                   and adjustment for captured arguments) when methods of
 *                   the resulting functional interface instance are invoked.
 * @param instantiatedMethodType The signature of the primary functional
 *                               interface method after type variables are
 *                               substituted with their instantiation from
 *                               the capture site
 * @param isSerializable Should the lambda be made serializable?  If set,
 *                       either the target type or one of the additional SAM
 *                       types must extend {@code Serializable}.
 * @param markerInterfaces Additional interfaces which the lambda object
 *                       should implement.
 * @param additionalBridges Method types for additional signatures to be
 *                          bridged to the implementation method
 * @throws LambdaConversionException If any of the meta-factory protocol
 * invariants are violated
 */
public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
                                   MethodType invokedType,
                                   String samMethodName,
                                   MethodType samMethodType,
                                   MethodHandle implMethod,
                                   MethodType instantiatedMethodType,
                                   boolean isSerializable,
                                   Class<?>[] markerInterfaces,
                                   MethodType[] additionalBridges)
        throws LambdaConversionException {
    super(caller, invokedType, samMethodName, samMethodType,
          implMethod, instantiatedMethodType,
          isSerializable, markerInterfaces, additionalBridges);
    implMethodClassName = implDefiningClass.getName().replace('.', '/');
    implMethodName = implInfo.getName();
    implMethodDesc = implMethodType.toMethodDescriptorString();
    implMethodReturnClass = (implKind == MethodHandleInfo.REF_newInvokeSpecial)
            ? implDefiningClass
            : implMethodType.returnType();
    constructorType = invokedType.changeReturnType(Void.TYPE);
    lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
    cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    int parameterCount = invokedType.parameterCount();
    if (parameterCount > 0) {
        argNames = new String[parameterCount];
        argDescs = new String[parameterCount];
        for (int i = 0; i < parameterCount; i++) {
            argNames[i] = "arg$" + (i + 1);
            argDescs[i] = BytecodeDescriptor.unparse(invokedType.parameterType(i));
        }
    } else {
        argNames = argDescs = EMPTY_STRING_ARRAY;
    }
}
 
Example 17
Source File: InnerClassLambdaMetafactory.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * General meta-factory constructor, supporting both standard cases and
 * allowing for uncommon options such as serialization or bridging.
 *
 * @param caller Stacked automatically by VM; represents a lookup context
 *               with the accessibility privileges of the caller.
 * @param invokedType Stacked automatically by VM; the signature of the
 *                    invoked method, which includes the expected static
 *                    type of the returned lambda object, and the static
 *                    types of the captured arguments for the lambda.  In
 *                    the event that the implementation method is an
 *                    instance method, the first argument in the invocation
 *                    signature will correspond to the receiver.
 * @param samMethodName Name of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a String.
 * @param samMethodType Type of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a MethodType.
 * @param implMethod The implementation method which should be called (with
 *                   suitable adaptation of argument types, return types,
 *                   and adjustment for captured arguments) when methods of
 *                   the resulting functional interface instance are invoked.
 * @param instantiatedMethodType The signature of the primary functional
 *                               interface method after type variables are
 *                               substituted with their instantiation from
 *                               the capture site
 * @param isSerializable Should the lambda be made serializable?  If set,
 *                       either the target type or one of the additional SAM
 *                       types must extend {@code Serializable}.
 * @param markerInterfaces Additional interfaces which the lambda object
 *                       should implement.
 * @param additionalBridges Method types for additional signatures to be
 *                          bridged to the implementation method
 * @throws LambdaConversionException If any of the meta-factory protocol
 * invariants are violated
 */
public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
                                   MethodType invokedType,
                                   String samMethodName,
                                   MethodType samMethodType,
                                   MethodHandle implMethod,
                                   MethodType instantiatedMethodType,
                                   boolean isSerializable,
                                   Class<?>[] markerInterfaces,
                                   MethodType[] additionalBridges)
        throws LambdaConversionException {
    super(caller, invokedType, samMethodName, samMethodType,
          implMethod, instantiatedMethodType,
          isSerializable, markerInterfaces, additionalBridges);
    implMethodClassName = implClass.getName().replace('.', '/');
    implMethodName = implInfo.getName();
    implMethodDesc = implInfo.getMethodType().toMethodDescriptorString();
    constructorType = invokedType.changeReturnType(Void.TYPE);
    lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
    cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    int parameterCount = invokedType.parameterCount();
    if (parameterCount > 0) {
        argNames = new String[parameterCount];
        argDescs = new String[parameterCount];
        for (int i = 0; i < parameterCount; i++) {
            argNames[i] = "arg$" + (i + 1);
            argDescs[i] = BytecodeDescriptor.unparse(invokedType.parameterType(i));
        }
    } else {
        argNames = argDescs = EMPTY_STRING_ARRAY;
    }
}
 
Example 18
Source File: MethodType.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Produces a bytecode descriptor representation of the method type.
 * <p>
 * Note that this is not a strict inverse of {@link #fromMethodDescriptorString fromMethodDescriptorString}.
 * Two distinct classes which share a common name but have different class loaders
 * will appear identical when viewed within descriptor strings.
 * <p>
 * This method is included for the benefit of applications that must
 * generate bytecodes that process method handles and {@code invokedynamic}.
 * {@link #fromMethodDescriptorString(java.lang.String, java.lang.ClassLoader) fromMethodDescriptorString},
 * because the latter requires a suitable class loader argument.
 * @return the bytecode type descriptor representation
 */
public String toMethodDescriptorString() {
    String desc = methodDescriptor;
    if (desc == null) {
        desc = BytecodeDescriptor.unparse(this);
        methodDescriptor = desc;
    }
    return desc;
}
 
Example 19
Source File: InnerClassLambdaMetafactory.java    From openjdk-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * General meta-factory constructor, supporting both standard cases and
 * allowing for uncommon options such as serialization or bridging.
 *
 * @param caller Stacked automatically by VM; represents a lookup context
 *               with the accessibility privileges of the caller.
 * @param invokedType Stacked automatically by VM; the signature of the
 *                    invoked method, which includes the expected static
 *                    type of the returned lambda object, and the static
 *                    types of the captured arguments for the lambda.  In
 *                    the event that the implementation method is an
 *                    instance method, the first argument in the invocation
 *                    signature will correspond to the receiver.
 * @param samMethodName Name of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a String.
 * @param samMethodType Type of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a MethodType.
 * @param implMethod The implementation method which should be called (with
 *                   suitable adaptation of argument types, return types,
 *                   and adjustment for captured arguments) when methods of
 *                   the resulting functional interface instance are invoked.
 * @param instantiatedMethodType The signature of the primary functional
 *                               interface method after type variables are
 *                               substituted with their instantiation from
 *                               the capture site
 * @param isSerializable Should the lambda be made serializable?  If set,
 *                       either the target type or one of the additional SAM
 *                       types must extend {@code Serializable}.
 * @param markerInterfaces Additional interfaces which the lambda object
 *                       should implement.
 * @param additionalBridges Method types for additional signatures to be
 *                          bridged to the implementation method
 * @throws LambdaConversionException If any of the meta-factory protocol
 * invariants are violated
 */
public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
                                   MethodType invokedType,
                                   String samMethodName,
                                   MethodType samMethodType,
                                   MethodHandle implMethod,
                                   MethodType instantiatedMethodType,
                                   boolean isSerializable,
                                   Class<?>[] markerInterfaces,
                                   MethodType[] additionalBridges)
        throws LambdaConversionException {
    super(caller, invokedType, samMethodName, samMethodType,
          implMethod, instantiatedMethodType,
          isSerializable, markerInterfaces, additionalBridges);
    implMethodClassName = implDefiningClass.getName().replace('.', '/');
    implMethodName = implInfo.getName();
    implMethodDesc = implMethodType.toMethodDescriptorString();
    implMethodReturnClass = (implKind == MethodHandleInfo.REF_newInvokeSpecial)
            ? implDefiningClass
            : implMethodType.returnType();
    constructorType = invokedType.changeReturnType(Void.TYPE);
    lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
    cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    int parameterCount = invokedType.parameterCount();
    if (parameterCount > 0) {
        argNames = new String[parameterCount];
        argDescs = new String[parameterCount];
        for (int i = 0; i < parameterCount; i++) {
            argNames[i] = "arg$" + (i + 1);
            argDescs[i] = BytecodeDescriptor.unparse(invokedType.parameterType(i));
        }
    } else {
        argNames = argDescs = EMPTY_STRING_ARRAY;
    }
}
 
Example 20
Source File: InnerClassLambdaMetafactory.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * General meta-factory constructor, supporting both standard cases and
 * allowing for uncommon options such as serialization or bridging.
 *
 * @param caller Stacked automatically by VM; represents a lookup context
 *               with the accessibility privileges of the caller.
 * @param invokedType Stacked automatically by VM; the signature of the
 *                    invoked method, which includes the expected static
 *                    type of the returned lambda object, and the static
 *                    types of the captured arguments for the lambda.  In
 *                    the event that the implementation method is an
 *                    instance method, the first argument in the invocation
 *                    signature will correspond to the receiver.
 * @param samMethodName Name of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a String.
 * @param samMethodType Type of the method in the functional interface to
 *                      which the lambda or method reference is being
 *                      converted, represented as a MethodType.
 * @param implMethod The implementation method which should be called (with
 *                   suitable adaptation of argument types, return types,
 *                   and adjustment for captured arguments) when methods of
 *                   the resulting functional interface instance are invoked.
 * @param instantiatedMethodType The signature of the primary functional
 *                               interface method after type variables are
 *                               substituted with their instantiation from
 *                               the capture site
 * @param isSerializable Should the lambda be made serializable?  If set,
 *                       either the target type or one of the additional SAM
 *                       types must extend {@code Serializable}.
 * @param markerInterfaces Additional interfaces which the lambda object
 *                       should implement.
 * @param additionalBridges Method types for additional signatures to be
 *                          bridged to the implementation method
 * @throws LambdaConversionException If any of the meta-factory protocol
 * invariants are violated
 */
public InnerClassLambdaMetafactory(MethodHandles.Lookup caller,
                                   MethodType invokedType,
                                   String samMethodName,
                                   MethodType samMethodType,
                                   MethodHandle implMethod,
                                   MethodType instantiatedMethodType,
                                   boolean isSerializable,
                                   Class<?>[] markerInterfaces,
                                   MethodType[] additionalBridges)
        throws LambdaConversionException {
    super(caller, invokedType, samMethodName, samMethodType,
          implMethod, instantiatedMethodType,
          isSerializable, markerInterfaces, additionalBridges);
    implMethodClassName = implDefiningClass.getName().replace('.', '/');
    implMethodName = implInfo.getName();
    implMethodDesc = implMethodType.toMethodDescriptorString();
    implMethodReturnClass = (implKind == MethodHandleInfo.REF_newInvokeSpecial)
            ? implDefiningClass
            : implMethodType.returnType();
    constructorType = invokedType.changeReturnType(Void.TYPE);
    lambdaClassName = targetClass.getName().replace('.', '/') + "$$Lambda$" + counter.incrementAndGet();
    cw = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    int parameterCount = invokedType.parameterCount();
    if (parameterCount > 0) {
        argNames = new String[parameterCount];
        argDescs = new String[parameterCount];
        for (int i = 0; i < parameterCount; i++) {
            argNames[i] = "arg$" + (i + 1);
            argDescs[i] = BytecodeDescriptor.unparse(invokedType.parameterType(i));
        }
    } else {
        argNames = argDescs = EMPTY_STRING_ARRAY;
    }
}