Beispiel #1
0
        /// <summary>
        /// Create a LF which simply reinvokes a target of the given basic type. </summary>
        internal static LambdaForm MakeReinvokerForm(MethodHandle target, int whichCache, Object constraint, String debugString, bool forceInline, NamedFunction getTargetFn, NamedFunction preActionFn)
        {
            MethodType mtype        = target.Type().BasicType();
            bool       customized   = (whichCache <0 || mtype.ParameterSlotCount()> MethodType.MAX_MH_INVOKER_ARITY);
            bool       hasPreAction = (preActionFn != null);
            LambdaForm form;

            if (!customized)
            {
                form = mtype.Form().CachedLambdaForm(whichCache);
                if (form != null)
                {
                    return(form);
                }
            }
            const int THIS_DMH = 0;
            const int ARG_BASE = 1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int ARG_LIMIT = ARG_BASE + mtype.parameterCount();
            int ARG_LIMIT  = ARG_BASE + mtype.ParameterCount();
            int nameCursor = ARG_LIMIT;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int PRE_ACTION = hasPreAction ? nameCursor++ : -1;
            int PRE_ACTION = hasPreAction ? nameCursor++: -1;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int NEXT_MH = customized ? -1 : nameCursor++;
            int NEXT_MH = customized ? -1 : nameCursor++;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final int REINVOKE = nameCursor++;
            int REINVOKE = nameCursor++;

            LambdaForm.Name[] names = LambdaForm.Arguments(nameCursor - ARG_LIMIT, mtype.InvokerType());
            assert(names.Length == nameCursor);
            names[THIS_DMH] = names[THIS_DMH].WithConstraint(constraint);
            Object[] targetArgs;
            if (hasPreAction)
            {
                names[PRE_ACTION] = new LambdaForm.Name(preActionFn, names[THIS_DMH]);
            }
            if (customized)
            {
                targetArgs      = Arrays.CopyOfRange(names, ARG_BASE, ARG_LIMIT, typeof(Object[]));
                names[REINVOKE] = new LambdaForm.Name(target, targetArgs);                 // the invoker is the target itself
            }
            else
            {
                names[NEXT_MH]  = new LambdaForm.Name(getTargetFn, names[THIS_DMH]);
                targetArgs      = Arrays.CopyOfRange(names, THIS_DMH, ARG_LIMIT, typeof(Object[]));
                targetArgs[0]   = names[NEXT_MH];               // overwrite this MH with next MH
                names[REINVOKE] = new LambdaForm.Name(mtype, targetArgs);
            }
            form = new LambdaForm(debugString, ARG_LIMIT, names, forceInline);
            if (!customized)
            {
                form = mtype.Form().SetCachedLambdaForm(whichCache, form);
            }
            return(form);
        }