Ejemplo n.º 1
0
        public void L2Cache()
        {
            var callSite = CallSite <Func <CallSite, object, object> > .Create(Binder.GetMember(CSharpBinderFlags.None, "A", typeof(CallSiteCachingTests), new CSharpArgumentInfo[1]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
            }));

            ObjAndRule[] t = new ObjAndRule[200];

            for (int i = 0; i < 100; i++)
            {
                object newExpando = CallSiteCachingTests.GetNewExpando(i);
                callSite.Target(callSite, newExpando);

                t[i].obj  = newExpando;
                t[i].rule = callSite.Target;

                if (i > 0)
                {
                    // must not reuse rules for new expandos
                    Assert.NotEqual((object)t[i].rule, t[i - 1].rule);
                }
            }

            for (int i = 0; i < 100; i++)
            {
                object newExpando = CallSiteCachingTests.GetNewExpando(i);
                callSite.Target(callSite, newExpando);

                // must reuse rules from L2 cache
                Assert.Equal((object)t[i].rule, callSite.Target);
            }
        }
Ejemplo n.º 2
0
        public void InlineCache()
        {
            var callSite = CallSite <Func <CallSite, object, object> > .Create(Binder.GetMember(CSharpBinderFlags.None, "A", typeof(CallSiteCachingTests), new CSharpArgumentInfo[1]
            {
                CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
            }));

            var initialTarget = callSite.Target;

            Assert.Equal((object)initialTarget, callSite.Update);

            object newExpando = CallSiteCachingTests.GetNewExpando(123);

            callSite.Target(callSite, newExpando);

            var newTarget = callSite.Target;

            for (int i = 0; i < 10; i++)
            {
                callSite.Target(callSite, newExpando);

                // rule should not be changing
                Assert.Equal((object)newTarget, callSite.Target);
            }
        }