(Postprint): Efficient Late Bind
Total Page:16
File Type:pdf, Size:1020Kb
Dieses Dokument ist eine Zweitveröffentlichung (Postprint) / This is a self-archiving document (postprint): Lars Schütze, Jeronimo Castrillon Efficient Late Binding of Dynamic Function Compositions Erstveröffentlichung in / First published in: SLE 2019: 12th ACM SIGPLAN International Conference on Software Language Engineering, Athens, 2019. ACM Digital Library, S. 141 – 151. ISBN 978-1-4503-6981-7 DOI: https://doi.org/10.1145/3357766.3359543 Diese Version ist verfügbar / This version is available on: https://nbn-resolving.org/urn:nbn:de:bsz:14-qucosa2-731781 Final edited form was published in "SLE 2019: 12th ACM SIGPLAN International Conference on Software Language Engineering", Athens, 2019. S. 141 – 151. ISBN 978-1-4503-6981-7 https://doi.org/10.1145/3357766.3359543 Efficient Late Binding of Dynamic Function Compositions Lars Schütze Jeronimo Castrillon Chair for Compiler Construction Chair for Compiler Construction Technische Universität Dresden Technische Universität Dresden Dresden, Germany Dresden, Germany [email protected] [email protected] Abstract 1 Introduction Adaptive software becomes more and more important as Ubiquitous computing leads to new challenges where context- computing is increasingly context-dependent. Runtime adapt- dependent software is more and more important. Developing ability can be achieved by dynamically selecting and apply- such software requires approaches that focus on objects, their ing context-specific code. Role-oriented programming has context-dependent behavior and relations. Object-oriented been proposed as a paradigm to enable runtime adaptive soft- programming (OOP) is the de facto standard approach to ware by design. Roles change the objects’ behavior at run- those problems today. This is because of the comprehensi- time and thus allow adapting the software to a given context. bility of object-oriented models and code which enables an However, this increased variability and expressiveness has intuitive representation of aspects of the real world. That is a direct impact on performance and memory consumption. how classes, objects, functions and inheritance originated. We found a high overhead in the steady-state performance of For example, an aspect of the real world is that an object may executing compositions of adaptations. This paper presents appear in different roles at different times (i.e., contexts). To a new approach to use run-time information to construct a reflect the different roles of entities, design patterns have dispatch plan that can be executed efficiently by the JVM. been proposed to achieve separation of concerns [7, 15]. Be- The concept of late binding is extended to dynamic func- cause these approaches can only compose or decompose in a tion compositions. We evaluated the implementation with a single dimension by using delegation or inheritance, context- benchmark for role-oriented programming languages lever- dependent concerns are tangled with the application and aging context-dependent role semantics achieving a mean scattered over it. speedup of 2.79× over the regular implementation. With the advent of aspect-oriented programming (AOP) [33] and context-oriented programming (COP) [28] it was possi- CCS Concepts • Software and its engineering → Soft- ble to separate behavioral concerns in multiple dimensions. ware performance; Compilers; Context specific languages. However, the focus of these multi-dimensional separation of Keywords Role-Oriented Programming, Dispatch Optimiza- concerns (MDSOC) paradigms is on the cross-cutting nature tion, Virtual Machine of concerns and adaptation of classes. Role-oriented programming (ROP) has been proposed as ACM Reference Format: an extension to object-oriented programming to enable adap- Lars Schütze and Jeronimo Castrillon. 2019. Efficient Late Binding tive software by design [43, 47]. Classes represent the struc- of Dynamic Function Compositions. In Proceedings of the 12th ACM tural view of the program while context-dependent behavior SIGPLAN International Conference on Software Language Engineer- is encapsulated in separate entities called roles. To model ing (SLE ’19), October 20–22, 2019, Athens, Greece. ACM, New York, context-dependency compartments encapsulate roles and NY, USA, 11 pages. https://doi.org/10.1145/3357766.3359543 represent the context in which these roles can be active. Adaptation is achieved by attaching roles dynamically to ©2019 Copyright held by the owner/author(s). Publication rights licensed objects to superimpose their behavior. Object Teams [23, 24] to ACM. This is the author’s version of the work. It is posted here for your is one of the most mature role-oriented programming lan- personal use. Not for redistribution. The definitive Version of Record was guages. It allows adapting Java programs available in source published in SSLE ’19, October 20–22, 2019, Athens, Greece code or binary form dynamically at runtime. https://doi.org/10.1145/3357766.3359543 It is common practice to lower MDSOC mechanisms to object-oriented mechanisms, which results in a verbose de- scription that incurs high runtime overhead [3, 40]. The over- head is especially noticeable in the steady-state performance of dynamic role-oriented programming languages as the be- havior of every object may be potentially adapted [46]. We argue that the major cause for the overhead is that current 1 Provided by Sächsische Landesbibliothek - Staats- und Universitätsbibliothek Dresden Final edited form was published in "SLE 2019: 12th ACM SIGPLAN International Conference on Software Language Engineering", Athens, 2019. S. 141 – 151. ISBN 978-1-4503-6981-7 https://doi.org/10.1145/3357766.3359543 SLE ’19, October 20–22, 2019, Athens, Greece Lars Schütze and Jeronimo Castrillon translation approaches have not been able to properly close have code for multiple concerns. This collaboration-scoped the semantic gap between role-oriented mechanisms and usage cannot be directly represented but is scattered over object-oriented machine models preventing many possible the program. While design patterns improve the quality of optimisationz. software architectures, they cannot solve the problem of To close the semantic gap and reduce verbosity the execu- tangling and scattering of concerns satisfactorily. To solve tion environment must understand the enhanced execution the problem, different approaches for separation of concerns semantics. We address this problem by applying the concept have been proposed with varying degree of granularity rang- of late binding of virtually dispatched functions to function ing from adapting single objects or functions to classes and compositions using exact runtime type information. Func- components. tions superimposed by role functions are by default virtual, but may become static until superimposition is released re- Aspect-Oriented Programming AOP decomposes cross- sulting in no subsequent lookups. The runtime provides cutting concerns to encapsulate each concern separately. As- exact instructions to the execution environment about how pects encapsulate such concerns and provide expressions to to find and execute role functions by composing a directed define interceptors, class extensions (inter-type declarations) acyclic graph (DAG) of function calls. This not only allows and its own properties [12]. An aspect can alter the behav- optimizing role dispatch in the sense of Just-in-Time (JIT) ior of non-aspect parts of the program called base classes compilation by the execution environment but also improves by applying advices which define the additional behavior. the runtime and generated code in terms of lookup and reuse. Alternative behavior can be applied at join points in the We demonstrate our approach by extending the static com- base program including function calls and property access. piler, dynamic compiler and the runtime of Object Teams [23, Pointcuts provide predicates that quantify over the set of 24]. We used a typical synthetic benchmark already reported existing join points and choose the set of join points where in the literature to compare different language implementa- the execution of the advice is desired. Aspects are woven tions of the role-oriented concept [46]. The benchmark uses into the application using special compilers called weavers. many demanding role-oriented programming features such Join points where advice invocation code may be woven in as multiple active contexts, deep roles (i.e., roles play roles), are called join point shadows [27]. and exchanged function bodies that are not easily built with A compiler for the aspect-oriented language consists of object-oriented design patterns. Our evaluation features a a module for evaluating pointcuts and the aforementioned mean speedup of 2.79× over the original implementation weaver, beside the elements of a traditional compiler. After when callsites can be reused and a mean slowdown of 9.76× evaluating a pointcut, the join point shadows are forwarded if there is no possible reuse ever. to the weaver. But at weave-time it cannot be decided for all The paper introduces in Section 2 concepts similar to join point shadows whether pointcuts apply or not. Thus, roles that could also benefit from the approach and gives an for some join points advice invocation logic and guards are overview of how Object Teams implements roles. In Section 3 compiled into the application called residuals. late binding for function compositions of role functions is Since virtual machine does not understand aspect seman-