一种虚拟机无关且向后兼容的动态类型语言受保护修饰符
A VM-Agnostic and Backwards Compatible Protected Modifier for Dynamically-Typed Languages
AI总结:
本文提出ProtDyn,一种虚拟机无关且向后兼容的受保护修饰符模型,通过名称改编和自发送区分,在动态类型语言中实现低性能开销的封装与子类扩展。
摘要:
在面向对象语言中,方法可见性修饰符在将内部方法与公共API分离方面起着关键作用。受保护可见性修饰符提供了一种将方法对外部对象隐藏,同时允许在子类中内部使用和重写的方法。虽然可见性修饰符存在于主要的静态类型语言中,但在动态类型语言中并不常见或成熟。在本文中,我们提出了ProtDyn,一种在编译时为动态类型语言计算的基于自发送的可见性模型,该模型依赖于名称改编和自发送与非自发送的语法区分。我们介绍了#Pharo,该模型的一种实现,它与现有程序向后兼容,以及其向Python的移植。利用这些实现,我们研究了ProtDyn在存在全局查找缓存和多态内联缓存的情况下对方法查找性能的影响。我们表明,我们的名称改编和双重方法注册技术对性能影响非常低,并保留了全局查找缓存和多态内联缓存的好处。我们还表明,在真实用例中,内存开销在最坏情况下介于2%到13%之间。受保护修饰符语义强制封装(如私有),但仍允许开发者在子类中扩展类。ProtDyn提供了一种虚拟机无关且向后兼容的设计,以在动态类型语言中引入受保护语义。
英文摘要:
In object-oriented languages, method visibility modifiers hold a key role in separating internal methods from the public API. Protected visibility modifiers offer a way to hide methods from external objects while authorizing internal use and overriding in subclasses. While present in main statically-typed languages, visibility modifiers are not as common or mature in dynamically-typed languages. In this article, we present ProtDyn, a self-send-based visibility model calculated at compile time for dynamically-typed languages relying on name-mangling and syntactic differentiation of self vs non self sends. We present #Pharo, a ProtDyn implementation of this model that is backwards compatible with existing programs, and its port to Python. Using these implementations we study the performance impact of ProtDyn on the method lookup, in the presence of global lookup caches and polymorphic inline caches. We show that our name mangling and double method registration technique has a very low impact on performance and keeps the benefits from the global lookup cache and polymorphic inline cache. We also show that the memory overhead on a real use case is between 2% and 13% in the worst-case scenario. Protected modifier semantics enforces encapsulation such as private but allow developers to still extend the class in subclasses. ProtDyn offers a VM-agnostic and backwards-compatible design to introduce protected semantics in dynamically-typed languages.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。