动态调度实现
我目前正在寻找各种方法来实现动态调度。
据我所知,有两种“简单”的方法来实现这一点:
- 虚拟函数表,就像在 C++
- 消息调度程序中一样,就像在 SmallTalk 中一样(这有点类似于 Python 将方法作为属性存储在
__dict__)
我要指出的是,据我所知,选择 VFT 是因为它们性能合理且易于实现(也因为它们非常适合 C++ 单独编译模型),而不是因为它们是最快的可能的方法。
我已经读过几篇文章和出版物,但大多数都是“旧的”(我读到的最后一篇文章(*)提到使用 Pentium 200MHz ... 嗯),所以我怀疑它们是否代表了最先进的技术除非研究陷入停滞。
我感兴趣的是:
- 动态调度策略,如果它们支持多种方法就更好了。
- 各种策略的基准
我对最近的文章和非常规策略特别感兴趣(即使它们没有被证明有效)。
欢迎发表出版物,如果可以免费提供就更好了,否则提供技术摘要,结果会很棒。
真实编译器实现的技术文章也受到欢迎。
(*) 这篇关于 Eiffel 的文章说明了整个程序如何分析可以帮助消除虚拟呼叫站点。
I am currently looking for various ways to implement dynamic dispatch.
As far as I know, there are two "easy" ways to implement this:
- Virtual Function Tables, like in C++
- Message Dispatcher, like in SmallTalk (which is somewhat akin to Python's idea of storing methods as attributes in
__dict__
)
I would note that as far as I know VFT have been chosen because they were performing reasonably and easy to implement (and also because they were well-suited with C++ separate compilation model), not because they were the fastest possible methods.
I have read a couple of articles and publications already, however most are "old" (the last I read(*) mentioned using a Pentium 200MHz ... hum), so I doubt that they represent the state-of-the-art unless research came to a stall.
I am interested in:
- Dynamic Dispatch strategies, the better if they support multi-methods.
- Benchmarks of the various strategies
I am particularly interested in recent articles and out-of-the-ordinary strategies (even if they did not prove efficient).
Publications are welcome, it would be better if they were freely available, and otherwise a summary of the technic presented and the result would be great.
Technical articles of real compiler implementations are also welcome.
(*) This article about Eiffel illustrates how whole program analysis can help remove virtual call sites.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在阅读基于原型的对象系统的实现时遇到了以下多方法策略。它是根据该领域编写的,但适应更传统的基于类的语言并不困难。
第 3 节详细介绍了它,图 5 是一个有用的图表。这个想法是每个可以分派的对象(或者类,也许)都有它自己的方法表。 (从这个意义上来说,它与 C++ 相当。)在该对象(或类)上分派的每个方法都放入表中。巧妙的部分是该表被分成几个小节,这些小节对应于参数位置。
澄清一下:假设您有一个专门针对第一个参数的类“Foo”和第二个参数的类“Quux”的方法。类 Foo 的调度表的第 1 部分将包含指向该方法的指针。并且,类 Quux 的调度表的第 two 部分也将有一个指向该方法的指针。为了进行调度,需要查阅参数的类的调度表。如果方法指针匹配(就像我们的示例一样),那就是要调用的方法。
该论文名为“Prototypes with Multiple Dispatch”。
http://lee.fov120.com/ecoop.pdf
I came across the following multi-method strategy while reading about the implementation of prototype-based object systems. It is written with that domain in mind, but it would not be difficult to adapt to a more traditional class-based language.
Section 3 details it, and figure 5 is a useful diagram. The idea is that each object (or class, perhaps) that can be dispatched on has its own method table. (In that sense, it is comparable to C++.) Each method that dispatches on that object (or class) is put into the table. The clever part is that the table is separated into subsections, which correspond to parameter positions.
To clarify: imagine that you have a method that specializes on class "Foo" for the first argument, and class "Quux" for the second argument. Section 1 of class Foo's dispatch table would contain a pointer to the method. And, section two for class Quux's dispatch table would also have a pointer to the method. To do dispatch, then, the arguments' classes' dispatch tables are consulted. If the method pointers match (like in our example), that is the method to call.
The paper is called "Prototypes with Multiple Dispatch".
http://lee.fov120.com/ecoop.pdf