月经期喝什么汤好| 吃什么保养皮肤| 百合有什么功效和作用| 空蝶鞍是什么意思| 石斛有什么功效和作用| 懒觉什么意思| 喝酒为什么会脸红| 风生水起是什么生肖| 佛手瓜什么时候结果| 办银行卡需要什么条件| 脂溢性皮炎是什么引起的| 可逆是什么意思| 七月十二是什么星座| 拿到offer是什么意思| 上颚起泡是什么原因| 小孩为什么会得手足口病| 降三高喝什么茶最好| 丰衣足食是什么生肖| 世界大战是什么意思| 梅菜是什么菜| 女孩月经不规律是什么原因| 扫墓是什么意思| 九月三号是什么日子| 猫砂是干什么用的| 碳酸氢钠有什么作用| 什么牌子护肤品好| 阿贝数是什么意思| 36属什么| 7点至9点是什么时辰| 煜什么意思| 小朋友流鼻血是什么原因| 茶不能和什么一起吃| 宫颈肥大是什么原因造成的| 口腔发粘是什么原因| 213什么星座| 思量是什么意思| 右眼皮跳是什么原因| 药食同源什么意思| 老睡不着觉是什么原因| 2015年属什么| 百香果什么时候吃最好| 什么东西不能一起吃| vivian是什么意思| 智齿长什么样子| 人生格言是什么| 射手座属于什么象星座| 独一味是什么药| 狮子座上升星座是什么| hpv感染后有什么症状| 鲜为人知什么意思| 胃窦炎吃什么药效果最好| cefiro是什么品牌| 学习机什么牌子好| 非虫念什么| 脸红是什么大病的前兆| 男孩过生日送什么礼物好| 兵马未动粮草先行是什么意思| 胃胀胃不消化吃什么药| 夏季吃桃子有什么好处| 看甲状腺去医院挂什么科| 五心烦热失眠手脚心发热吃什么药| 腰疼吃什么药最有效| 生姜什么时候种| 宠物医院需要什么资质| 喝酒后肚子疼什么原因| 左肋骨下方隐隐疼痛是什么原因| co2是什么意思| ct查什么| 龙鱼吃什么| 什么颜色加什么颜色等于紫色| barry是什么意思| 幽门螺旋杆菌感染有什么症状| 舌头上有红点点是什么原因| 煮粥用什么锅最好| 经常耳鸣是什么原因引起的| 荨麻疹是什么引起的| 在家做什么小生意| 龟苓膏有什么作用| 四月初八是什么日子| 艾滋病是什么病毒| 四川有什么好大学| 月经期间不能吃什么水果| 紫茉莉什么时候开花| 老年人腿无力是什么原因导致的| 璟字五行属什么| 膝盖不舒服挂什么科| 福报是什么| lady是什么意思| 抗药性是什么意思| 得水痘不能吃什么| 用什么可以解开所有的谜| 状物是什么意思| 什么是力量训练| 严重贫血吃什么补的快| 十指连心是什么意思| mickey是什么牌子| 突然尿多是什么原因| 内衣什么品牌最好| 吃榴莲不能和什么一起吃| 秦皇岛有什么特色美食| 胃炎吃什么药| 髂胫束在什么位置| 屁股上的骨头叫什么骨| 分泌物过氧化氢阳性是什么意思| 梦见进监狱是什么兆头| 为什么每次同房后都会尿路感染| 莴笋不能和什么一起吃| 巨蟹座是什么星象| 喝啤酒头疼是什么原因| 减脂吃什么主食| 什么是形而上学| 脾虚气滞吃什么中成药| 尿颜色很黄是什么原因| 翡翠是什么意思| 猩红热是什么症状| 小狗什么时候断奶| 加拿大属于什么洲| 肺结节吃什么药| 阿僧只劫是什么意思| 乳头大是什么原因| 老鼠为什么会飞| 芈月和嬴政什么关系| 称心如意是什么意思| 脑电图是什么| 儿童腹泻吃什么药| 投射效应是什么意思| aa是什么| 养狗人容易得什么病| 彩金是什么材质| 做梦梦见钓鱼是什么意思| 气血两虚吃什么中成药| 梦见蝉是什么意思| 苏轼是什么居士| 腱鞘炎吃什么药好使| 望惠存是什么意思| 梦见牛是什么意思| 什么是扁平疣| 桂圆和龙眼有什么区别| 关节炎用什么药最好| 牛肉饺子馅配什么蔬菜好吃| 绝经后吃什么能来月经| 猪古代叫什么| 血糖高的人吃什么| 生抽和酱油有什么区别| 阴道痒是什么原因| 女性胆固醇高吃什么好| classic什么意思| 带鱼为什么是扁的| 四岁属什么生肖| 脂肪酸是什么| 治痛风吃什么药| 什么叫资本运作| 类风湿关节炎吃什么好| 书的五行属性是什么| 耳石症是什么引起的| 生粉是什么| 孕妇晚上饿了吃什么好| 绞股蓝有什么作用| 马为什么不怕蛇毒| 美味佳肴是什么意思| 高姓和什么姓是世仇| 肾湿热吃什么中成药| 口交是什么| 蓝莓和什么不能一起吃| 光盘是什么| 糖衣炮弹什么意思| 喝红枣水有什么好处和坏处| 指甲长得快说明什么| 蚊子咬了涂什么| 37岁属什么的生肖| 什么魏什么赵| 男性前列腺炎有什么症状| 早上的太阳叫什么| 扬州有什么好玩的| 堆肥是什么意思| 朱元璋属什么生肖| 黄金有什么作用与功效| pangchi是什么牌子的手表| 虾仁炒什么好吃| 芥子是什么意思| 看演唱会需要准备什么| 南京市徽为什么是貔貅| 心脏早搏是什么症状| 什么地爬| 阴道瘙痒什么原因| TOYOTA是什么车| 撕漫男是什么意思| 医生停诊是什么意思| 现在干什么挣钱| 非甾体抗炎药是什么意思| 斜视是什么意思| 炎症是什么病| 中标是什么意思| 蕾字五行属什么| 冬日暖阳是什么意思| 鸟为什么会飞| 一月二十号是什么星座| 葛根粉有什么功效和作用| 湖北有什么好吃的| 永垂不朽什么意思| 横批是什么意思| 手指缝痒是什么原因| 开塞露用多了有什么副作用| 香菜什么时候种最合适| 做梦捡钱是什么预兆| 肛门瘙痒是什么问题| 三朵花代表什么意思| 梅子是什么| 保卡是什么意思| 心功能不全是什么意思| 不思量 自难忘什么意思| 酸儿辣女什么意思| 乳突炎是什么病| 张学友和张家辉什么关系| 忽然流鼻血是什么原因引起的| 三公是什么意思| 幽门杆菌有什么症状| h1v是什么病| 95年属什么生肖婚配表| 梦见和妈妈吵架是什么意思| 宝宝肋骨外翻是什么原因| 麻雀为什么跳着走| 丝光棉是什么材质| 大盘是什么意思| 甲状腺结节吃什么药好| 什么是酮体| 白色糠疹用什么药膏| 男生适合养什么小型犬| 北属于五行的什么| bm是什么意思| 晚上吃什么有助于睡眠| 角是什么意思| ntr是什么意思| 黑天天的学名叫什么| 脊椎炎有什么症状| 梦见滑雪是什么意思| 补体c1q偏低说明什么| 大拇指指甲凹陷是什么原因| 为什么会低钾| 什么是中位数| 脂肪是什么| 胃酸恶心想吐什么原因| 十一月四日是什么星座| m什么意思| 坐围是什么| 热得直什么| 婴儿拉肚子是什么原因造成的| 囊性包块是什么| 王羲之兰亭序是什么字体| 鲸属于什么类动物| 干什么呢| 淼念什么| 十二月十二日是什么星座| 不能吃油腻的是什么病| 它是什么用英语怎么说| 缺锌容易得什么病| 心可舒治什么病| 苏菲是什么| fda是什么| 什么叫天干| 经期吃什么补气血| 七月六号是什么星座| 碎花裙配什么鞋子| 拔罐后要注意什么| 百度Jump to content

亚马逊要砸10亿美元拍《三体》?游族称以开放态度推进开发

From Wikipedia, the free encyclopedia
(Redirected from Polymorphic inline cache)
百度 所有的奢侈,皆因匠心再度登临巴塞尔钟表展,除了展现中国奢侈品的独特魅力,8848还宣布,将赞助全球独立制表人顶级组织AHCI。

Inline caching is an optimization technique employed by some language runtimes, and first developed for Smalltalk.[1] The goal of inline caching is to speed up runtime method binding by remembering the results of a previous method lookup directly at the call site. Inline caching is especially useful for dynamically typed languages where most if not all method binding happens at runtime and where virtual method tables often cannot be used.

Runtime method binding

[edit]

The following ECMAScript function receives an object, invokes its toString-method and displays the results on the page the script is embedded in.

function dump(obj) {
    document.write(obj.toString());
}

Since the type of the object is not specified and because of potential method overloading, it is impossible to decide ahead of time which concrete implementation of the toString-method is going to be invoked. Instead, a dynamic lookup has to be performed at runtime. In language runtimes that do not employ some form of caching, this lookup is performed every time a method is invoked. Because methods may be defined several steps down the inheritance chain, a dynamic lookup can be an expensive operation.

To achieve better performance, many language runtimes employ some form of non-inline caching where the results of a limited number of method lookups are stored in an associative data structure. This can greatly increase performance, provided that the programs executed are "cache friendly" (i.e., there is a limited set of methods that are invoked frequently). This data structure is typically called the first-level method lookup cache.[1]

Inline caching

[edit]

The concept of inline caching is based on the empirical observation that the objects that occur at a particular call site are often of the same type. In those cases, performance can be increased greatly by storing the result of a method lookup "inline"; i.e., directly at the call site. To facilitate this process, call sites are assigned different states. Initially, a call site is considered to be "uninitialized". Once the language runtime reaches a particular uninitialized call site, it performs the dynamic lookup, stores the result at the call site and changes its state to "monomorphic". If the language runtime reaches the same call site again, it retrieves the callee from it and invokes it directly without performing any more lookups. To account for the possibility that objects of different types may occur at the same call site, the language runtime also has to insert guard conditions into the code. Most commonly, these are inserted into the preamble of the callee rather than at the call site to better exploit branch prediction and to save space due to one copy in the preamble versus multiple copies at each call site. If a call site that is in the "monomorphic" state encounters a type other than the one it expects, it has to change back to the "uninitialized" state and perform a full dynamic lookup again.

The canonical implementation [1] is a register load of a constant followed by a call instruction. The "uninitialized" state is better called "unlinked". The register is loaded with the message selector (typically the address of some object) and the call is to the run-time routine that will look-up the message in the class of the current receiver, using the first-level method lookup cache above. The run-time routine then rewrites the instructions, changing the load instruction to load the register with the type of the current receiver, and the call instruction to call the preamble of the target method, now "linking" the call site to the target method. Execution then continues immediately following the preamble. A subsequent execution will call the preamble directly. The preamble then derives the type of the current receiver and compares it with that in the register; if they agree, the receiver is of the same type and the method continues to execute. If not, the preamble again calls the run-time and various strategies are possible, one being to relink the call-site for the new receiver type.

The performance gains come from having to do one type comparison, instead of at least a type comparison and a selector comparison for the first-level method lookup cache, and from using a direct call (which will benefit from instruction prefetch and pipe-lining) as opposed to the indirect call in a method-lookup or a vtable dispatch.

Monomorphic inline caching

[edit]

If a particular call site frequently sees different types of objects, the performance benefits of inline caching can easily be nullified by the overhead induced by the frequent changes in state of the call site. The following example constitutes a worst-case scenario for monomorphic inline caching:

var values = [1, "a", 2, "b", 3, "c", 4, "d"];
for (var i in values) {
    document.write(values[i].toString());
}

Again, the method toString is invoked on an object whose type is not known in advance. More importantly though, the type of the object changes with every iteration of the surrounding loop. A naive implementation of monomorphic inline caching would therefore constantly cycle through the "uninitialized" and "monomorphic" states. In order to prevent this from happening, most implementations of monomorphic inline caching support a third state often referred to as the "megamorphic" state. This state is entered when a particular call site has seen a predetermined number of different types. Once a call site has entered the "megamorphic" state, it will behave just as it did in the "uninitialized" state with the exception that it will not enter the "monomorphic" state ever again (some implementations of monomorphic inline caching will change "megamorphic" call sites back to being "uninitialized" after a certain amount of time has passed or once a full garbage collection cycle is performed).

Polymorphic inline caching

[edit]

To better deal with call sites that frequently see a limited number of different types, some language runtimes employ a technique called polymorphic inline caching.[2] With polymorphic inline caching, once a call site that is in its "monomorphic" state sees its second type, rather than reverting to the "uninitialized" state, it switches to a new state called "polymorphic". A "polymorphic" call site decides which of a limited set of known methods to invoke based on the type that it is currently presented with. In other words, with polymorphic inline caching, multiple method lookup results can be recorded at the same call site. Because every call site in a program can potentially see every type in the system, there usually is an upper bound to how many lookup results are recorded at each call site. Once that upper bound is reached, call sites become "megamorphic" and no more inline caching is performed.

The canonical implementation [2] is a jump table which consists of a preamble that derives the type of the receiver and a series of constant compares and conditional jumps that jump to the code following the preamble in the relevant method for each receiver type. The jump table is typically allocated for a particular call-site when a monomorphic call-site encounters a different type. The jump-table will have a fixed size and be able to grow, adding cases as new types are encountered up to some small maximum number of cases such as 4, 6 or 8. Once it reaches its maximum size, execution for a new receiver type will "fall-off" the end and enter the run-time, typically to perform a method lookup starting with the first-level method cache.

The observation that together, monomorphic and polymorphic inline caches collect per-call-site receiver type information as a side-effect of optimizing program execution[2] led to the development of adaptive optimization in Self, where the run-time optimizes "hot spots" in the program using the type information in inline caches to guide speculative inlining decisions.

Megamorphic inline caching

[edit]

If a run-time uses both monomorphic and polymorphic inline caching, then in the steady state, the only unlinked sends occurring will be those from sends falling off the ends of polymorphic inline caches. Since such sends are slow, it can now be profitable to optimize these sites. A megamorphic inline cache can be implemented by creating code to perform a first-level method lookup for a particular call-site. In this scheme, once a send falls off the end of a polymorphic inline cache, a megamorphic cache specific to the call site's selector is created (or shared if one already exists), and the send site is relinked to call it. The code can be significantly more efficient than a normal first-level method lookup probe since the selector is now a constant, which decreases register pressure, the code for the lookup and dispatch is executed without calling into the run-time, and the dispatch can benefit from branch prediction.

Empirical measurements [3] show that in large Smalltalk programs, about 1/3 of all send sites in active methods remain unlinked, and of the remaining 2/3, 90% are monomorphic, 9% polymorphic and 1% (0.9%) are megamorphic.

See also

[edit]

References

[edit]
  1. ^ a b c L. Peter Deutsch, Allan M. Schiffman, "Efficient implementation of the smalltalk-80 system", POPL '84: Proceedings of the 11th ACM SIGACT-SIGPLAN symposium on Principles of programming languages, January 1984
  2. ^ a b c H?lzle, U., Chambers, C., AND Ungar, D. 1991. Optimizing dynamically-typed object-oriented languages with polymorphic inline caches. In Proceedings of the ECOOP ’91 Conference. Lecture Notes in Computer Science, vol. 512. Springer-Verlag, Berlin.
  3. ^ PICs [was v8 first impressions] on the Strongtalk mailing list[permanent dead link]
[edit]
胸闷是什么原因引起的 眼压高是什么原因造成的 甲状腺功能亢进是什么意思 蚊子长什么样 活着的意义是什么
羊内腰和外腰分别是什么 吃黄芪有什么好处 姓彭的女孩子取什么名字好 四叶草是什么牌子 毅五行属什么
天蝎配什么星座 小心眼是什么意思 颠覆三观是什么意思 扁平比是什么意思 高血压能喝什么饮料
哀莫大于心死什么意思 伤口出水是什么原因 性格内敛是什么意思 感染科主要看什么病 手脚脱皮是什么原因
乌龟死了是什么样子hcv8jop4ns9r.cn 烧头七有什么讲究hcv7jop9ns2r.cn 路征和景甜什么关系hcv7jop5ns3r.cn imf是什么意思hcv9jop2ns4r.cn 原则上是什么意思hcv9jop0ns8r.cn
五什么四什么hcv7jop9ns3r.cn 一个山一个见读什么hcv8jop8ns0r.cn 888是什么意思hcv8jop1ns0r.cn cs和cf有什么区别hcv8jop7ns6r.cn 虎头蜂泡酒有什么功效hcv7jop9ns3r.cn
olp是什么意思hcv8jop0ns8r.cn 食少便溏是什么意思hcv8jop6ns9r.cn 内分泌失调挂什么科jasonfriends.com 台湾以前叫什么名字hcv8jop7ns6r.cn 鱼油有什么作用wmyky.com
长寿菜是什么菜hcv9jop4ns8r.cn 校长是什么级别hcv9jop5ns5r.cn 午时是什么时间hcv8jop6ns3r.cn 炖鸡放什么材料hcv9jop3ns5r.cn 黄水疮用什么药膏最快hcv9jop3ns1r.cn
百度