多态内联缓存如何与可变类型一起工作?
多态内联缓存(PIC)的工作原理是根据对象的类型缓存实际方法,以避免昂贵的查找过程(通常是哈希表查找)。
如果类型对象是可变的(即该方法可能在运行时被猴子修补成不同的东西),那么如何处理类型比较?
我提出的一个想法是一个“类计数器”,每次调整一个方法时它都会增加,但是这在一个经过大量猴子修补的环境中似乎会非常昂贵,因为它会杀死所有的 PIC那个类,即使它们的方法没有改变。
我确信一定有一个好的解决方案,因为这个问题直接适用于 JavaScript,并且 AFAIK 所有三个大型 JavaScript 虚拟机都有 PIC。
A polymorphic inline cache(PIC) works by caching the actual method by the type of the object, in order to avoid the expensive lookup procedures (usually a hashtable lookup).
How does one handle the type comparison if the type objects are mutable (i.e. the method might be monkey patched into something different at run time)?
The one idea I've come up with would be a "class counter" that gets incremented each time a method is adjusted, however this seems like it would be exceptionally expensive in a heavily monkey patched environment, since it would kill all the PICs for that class, even if the methods for them weren't altered.
I'm sure there must be a good solution to this, as this issue is directly applicable to JavaScript, and AFAIK all three of the big JavaScript virtual machines have PICs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在V8中,我假设monkeypatching会改变对象的“隐藏类”(“map”是SELF术语)。 这对于你修补对象本身的猴子来说是有效的。
如果你猴子修补这个类(你能用 JS 来做吗?),我猜它会使所有 PIC 失效,因为这可能很少见。 或者,它可能会重新编译旧方法以直接分派到新方法(我猜是在类型检查之后)
顺便说一句,我认为其他“三大”实际上并不使用 PIC。 我猜你指的是松鼠鱼和踪迹猴。 前者是口译员,后者专注于追踪方法,我不记得听说过任何有关 PIC 的事情。 事实上,我不认为tracemonkey 对对象有任何酷的作用,但我可能是错的。
In V8, I would assume that monkeypatching would change the "hidden class" ("map" is SELF terminology) of the object. That would work in you monkey patched the object itself.
If you monkey patched the class (can you do that is JS?), I would guess it invalidates all PICs, since this is probably rare. Alternatively, it might recompile the old method to dispatch straight to the new method (after a type check I guess)
As an aside, I don't think the other "big 3" use PICs, actually. I presume you mean squirrelfish and tracemonkey. The former is an interpreter, and the latter focusses on the tracing approach, and I don't recall hearing anything about PICs. In fact, I don't think tracemonkey does anything cool at all for objects, but I could be wrong.
使用类型推断:
反优化是类型推断失败时发生的过程的名称:
为此,需要多个编译器:
调试是通过动态去优化完成的:
参考
不要对我进行优化,v8
V8 中的 Javascript 隐藏类和内联缓存
及时调试JIT 数量
IonMonkey:邪恶代表您| JavaScript
优化杀手·petkaantonov/bluebird Wiki< /p>
使用多态内联缓存优化动态类型面向对象语言 (pdf)
类型化、基于堆栈的虚拟机上动态语言 JIT 的去优化 (pdf)
Javascript var 与 let v8 和 SpiderMonkey 中的(去)优化/减速问题
chakracore msjunit:内联调用后测试去优化。
chakracore msjunit:测试在严格模式下使用不匹配的参数计数访问和修改参数对象的函数的内联和去优化
JavaScript 的嵌套细化类型 (pdf)
Type inference is used:
De-optimization is the name of the process that happens when type inference fails:
Multiple compilers are necessary for this to work:
Debugging is done via dynamic deoptimization:
References
Deoptimize me not, v8
Javascript Hidden Classes and Inline Caching in V8
Debugging in the Time of JITs
IonMonkey: Evil on your behalf | JavaScript
Optimization killers · petkaantonov/bluebird Wiki
Optimizing Dynamically-Typed Object-Oriented Languages with Polymorphic Inline Caches (pdf)
Deoptimization for Dynamic Language JITs on Typed, Stack-based Virtual Machines (pdf)
Javascript var vs let (de)optimization/slowdown issue in v8 and SpiderMonkey
chakracore msjunit: Test deoptimization after inlined call.
chakracore msjunit: Test inlining and deoptimization of functions accessing and modifying the arguments object in strict mode with mismatched arguments count
Nested Refinement Types for JavaScript (pdf)
Introducing the WebKit FTL JIT | WebKit