Observation-based approximate dependency modeling and its use for program slicing

https://doi.org/10.1016/j.jss.2021.110988Get rights and content

Highlights

  • Approximation of program dependence modeling using observations of behavior.

  • Evaluation of the approximated dependence model via program slices.

  • Comparisons to slices generated by the well known static slicer, CodeSurfer.

  • Quantitative and qualitative analysis of generated slices.

Abstract

While dependency analysis is foundational to much program analysis, many techniques have limited scalability and handle only monolingual systems. We present a novel dependency analysis technique that aims to approximate program dependency from a relatively small number of perturbed executions. Our technique, MOAD (Modeling Observation-based Approximate Dependency), reformulates program dependency as the likelihood that one program element is dependent on another (instead of a Boolean relationship). MOAD generates program variants by deleting parts of the source code and executing them while observing the impact. MOAD thus infers a model of program dependency that captures the relationship between the modification and observation points. We evaluate MOAD using program slices obtained from the resulting probabilistic dependency models. Compared to the existing observation-based backward slicing technique, ORBS, MOAD requires only 18.6% of the observations, while the resulting slices are only 12% larger on average. Furthermore, we introduce the notion of the observation-based forward slices. Unlike ORBS, which inherently computes backward slices, MOAD’s model’s dependences can be traversed in either direction allowing us to easily compute forward slices. In comparison to the static forward slice, MOAD only misses deleting 0–6 lines (median 0), while excessively deleting 0–37 lines (median 8) from the slice.

Introduction

Understanding dependency between program elements is a fundamental task in software engineering (Livadas and Roy, 1992, Baah et al., 2010). It provides a basis for many software engineering tasks including program comprehension (Zhifeng Yu and Rajlich, 2001), software testing (Binkley, 1997), maintenance (Gallagher, 1989, Hajnal and Forgács, 2012), refactoring (Ettinger and Verbaere, 2004), security (Karim et al., 2019), and debugging (Jiang et al., 2017). The traditional static approach based on dependence graphs (Horwitz et al., 1990) has been widely adopted but suffers from issues such as its inability to easily handle multi-lingual systems (combining analyses for multiple languages can be quite complex) and limited scalability (partial analysis of a large system is not viable using static approaches that require whole-program analyses).

Observation Based Slicing (ORBS) (Binkley et al., 2014, Binkley et al., 2015, Gold et al., 2017, Binkley et al., 2019) was designed to overcome these issues. ORBS applies speculative deletions iteratively to the program under analysis, and observes whether the latest applied deletion is viable (i.e., the code compiles after deletion) and is unrelated to the slicing criteria (i.e., the variable of interest shows the same behavior after deletion with respect to a test suite). When deletions are made at the line-of-text level, ORBS is entirely language agnostic (Binkley et al., 2014, Gold et al., 2017, Binkley et al., 2019, Lee et al., 2020) and can analyze files for which the grammar is unavailable/unknown, and analyze languages with unconventional semantics such as Picture Description Languages (PDLs) (Yoo et al., 2017). Despite its benefits along with a lightweight implementation it needs, ORBS has one clear drawback: the cost of analysis. Being a purely dynamic approach, it iteratively attempts to validate its speculative deletion of every program element via compilations and test executions. As such, it can incur significant cost.

This paper investigates the feasibility of approximate dependency analysis at a greatly reduced cost. A precise dependency analysis aims to report whether program element A depends on program element B or not: the outcome is Boolean. An approximate dependency analysis instead reports the likelihood that A depends on B: the outcome is a real number. While probabilistic program dependency analysis techniques have been proposed before (Baah et al., 2010) they require an initial static analysis which is then extended with probabilistic information based on test executions. We conjecture that a more general analysis, based solely on dynamic observations can still be useful in many program analysis contexts while being significantly less costly.

The approximate nature of our approach stems from the fact that it infers a stochastic model of program dependences. Unlike ORBS which performs iterative deletions to analyze program dependency with respect to a single program element (i.e., the slicing criterion), our technique, MOAD (Modeling Observation-based Approximate Dependency), learns an approximate model of program dependence from significantly fewer dynamic observations. Intuitively, ORBS makes a single slice increasingly more accurate by iterative deletion. In contrast, MOAD employs a set of deletions that can be treated independently. For each, it observes multiple program elements and can thus, ultimately, learn more from each execution. This approach introduces the following benefits:

  • MOAD requires many fewer observations than ORBS, as it infers the relationships between individual deletions and thus the dependency, instead of uncovering dependence information by iteratively deleting until it arrives at a one-minimal slice (Binkley et al., 2014).

  • The output of MOAD can be used to construct multiple backward and forward slices, whereas a single ORBS run produces a single backward slice.

  • Moreover, since the observations required by MOAD are independent from each other, MOAD is inherently parallel.

To evaluate MOAD, we have implemented it and performed dependency analysis against a benchmark suite of programs that have been widely used in the slicing literature. We evaluate the viability and the accuracy of MOAD by producing slices based on the MOAD produced model: program element A is in the backward slice of program element B iff the reported likelihood of B depending on A is greater than a threshold value. A comparison to a baseline random slicing technique shows that MOAD is indeed learning program dependences; a comparison to ORBS slices shows that MOAD can produce slices that are only 16% larger than ORBS slices, while using only 18.7% of the observations. We also investigate various ways to construct the observation sets, as well as the impact of different inference models.

In earlier work (Lee et al., 2019) we presented the basic technique and empirically evaluated its use for producing backward slices. This paper extends our previous work in three main ways. First, we provide a more extensive comparison of backward slices produced by MOAD and those produced by ORBS. Secondly, we compare MOAD-based forward slices to those of the CodeSurfer static analysis tool from Grammatech Inc. (2002). Finally, we also describe our framework in more depth and provide more extensive experiments to show the relative merits of different deletion schemes as well as inference models when inferring MOAD dependency models. Taken together this extends the use of the underlying modeling technique and provides a richer explanation both of its benefits as well as clarifying its limitations. As hinted at in Section 2, our study of slicing only scratches the surface. Our probabilistic dependency modeling is far more general. It can be applied to a wide range of problems such as Fault Diagnosis (Baah et al., 2010). However, we leave these additional use cases to future work and focus here on slicing as a representative example.

To summarize, the technical contributions of this paper are as follows:

  • We introduce the concept of learning approximate dependency analysis, which transforms the dependency relationship from Boolean to probabilistic.

  • We present MOAD, a technique that models approximate program dependency, and describe its essential steps: how to generate observations and how to infer models from the observations.

  • We conduct an empirical evaluation of MOAD via backward program slices instantiated from the learned models.

  • We show how to instantiate forward program slices from the models learned by MOAD and empirically compare these slices to those of a static analysis tool.

The rest of this paper is organized as follows. Section 2 introduces the concept of approximate dependency analysis, and explains how it relates to the existing slicing technique ORBS. Section 3 introduces MOAD, a technique that aims to model approximate dependency, and how we can use it for slicing by instantiating program slices from the learned dependency models. Section 4 presents the set-up of empirical evaluation, the results of which are reported in Section 5. Section 6 contains discussions of our findings and potential future work. Section 7 presents the related work, and Section 8 concludes.

Section snippets

Approximating program dependency

Program dependency is dependence relations that hold between elements of a program (e.g., statements, expressions, or variables). If the computation of an element a directly or indirectly affects the computation of another element, b, we consider b to be dependent on a. A plethora of techniques have been proposed to capture and model dependence information.

Often these techniques are static and require parsing and detailed analysis of program elements based on the semantics of the programming

MOAD : Modeling observation-based approximate dependency

This section first overviews the key terminology used to describe MOAD, before describing its two phases: the observation phase and the inference phase. The output of the first phase is a set of observations. These observations form the input to the inference phase, which builds an inference model M that aims to capture the dependence within the program. As a case study, we illustrate M by inferring program slices (Weiser, 1979, Weiser, 1984). In the next section we compare the inferred slices

Research questions

We evaluate MOAD by investigating the following six research questions. The first RQ concerns whether MOAD has the capability to approximate program dependency. With RQ2 to RQ4, we evaluate MOAD by comparing its backward slices to those generated by ORBS and the static slicer of CodeSurfer. With RQ5, we evaluate how the amount of observation affects MOAD’s accuracy. Finally, with RQ6, we compare the forward slices generated by MOAD with those generated by CodeSurfer.

RQ1. Viability: Do the

Viability (RQ1)

To answer RQ1, we first create a random slicer. Our implementation randomly deletes each unit with a probability of 0.5. For every slicing criterion in every subject program, we run the random slicer ten times and check whether the slice generated preserves the trajectory of the slicing criterion. With 900 slicing criteria (see Table 1) spread across the ten subject programs, the random slicer generates 9000 slices in total. Only fifteen of the random slices compile, and none of them preserve

Advanced and adaptive deletion generation scheme

An in-depth analysis of MOAD backward slices compared to static backward slices indicates that a specific set of units should be deleted together or should not be deleted. The category

[Keeping Declarations] describes that MOAD often cannot delete the variable declaration statements since the 2-hot deletion generation scheme does not offer an observation that deletes the declaration statement with all the statements using the declared variable.
[Missing Initialization] and [Missing Return]

Related work

There have been multiple proposals to approximate dependencies by complementing a statically extracted graph with dynamic information (Baah et al., 2010, Feng and Gupta, 2010, Gong et al., 2015). A notable example is Baah et al. (2010) who proposed to annotate traditional program dependence graphs (PDGs) with probabilities that capture dependence relations from dynamic execution of test cases. They extend the PDG with edges having conditional probabilities that relate states of child nodes to

Conclusion

This paper introduces and studies a new technique for modeling program dependence based on dynamic observation. The long term goal of this work is to enable the reformulation of dynamic program dependency analysis into a probabilistic space using statistical inference models. Doing so should lower analysis costs but also allow more several and specific analysis tasks to be supported. Furthermore, the cost is all upfront: once the model is built, inferring results is very inexpensive. A single

Artifact

Our implementation of MOAD is publicly available via zenodo (Lee, 2021).

CRediT authorship contribution statement

Seongmin Lee: Conceptualization, Methodology, Investigation, Software, Data curation, Writing - original draft, Writing - review & editing. David Binkley: Methodology, Investigation, Writing - original draft, Writing - review & editing. Robert Feldt: Conceptualization, Methodology, Writing - original draft, Writing - review & editing. Nicolas Gold: Methodology, Writing - original draft, Writing - review & editing. Shin Yoo: Conceptualization, Methodology, Writing - original draft, Writing -

Declaration of Competing Interest

The authors declare that they have no known competing financial interests or personal relationships that could have appeared to influence the work reported in this paper.

Acknowledgments

Seongmin Lee and Shin Yoo have been supported by Next-Generation Information Computing Development Programthrough the National Research Foundation of Korea (NRF) funded by the Ministry of Science, ICT (2017M3C4A7068179), as well as by National Research Foundation of Korea (NRF), South Korea Grant NRF-2020R1A2C1013629. Robert Feldt has been supported by the Swedish Scientific Council (No. 2015-04913, Basing Software Testing on Information Theory).

Seongmin Lee is a PhD candidate at School of Computing, KAIST, in Republic of Korea. He received BSc with a double major in School of Computing and Department of Mathematical Sciences from KAIST. His research interest includes program analysis, dependency analysis, program slicing, and genetic improvement.

References (37)

  • GongD. et al.

    State dependency probabilistic model for fault localization

    Inf. Softw. Technol.

    (2015)
  • LeeS. et al.

    Evaluating lexical approximation of program dependence

    J. Syst. Softw.

    (2020)
  • YooS. et al.

    Observational slicing based on visual semantics

    J. Syst. Softw.

    (2017)
  • BaahG.K. et al.

    The probabilistic program dependence graph and its application to fault diagnosis

    IEEE Trans. Softw. Eng.

    (2010)
  • BinkleyD.W.

    Precise executable interprocedural slices

    ACM Lett. Program. Lang. Syst.

    (1993)
  • BinkleyD.

    Semantics guided regression test cost reduction

    IEEE Trans. Softw. Eng.

    (1997)
  • Binkley, D., Gold, N., Harman, M., Islam, S., Krinke, J., Yoo, S., 2014. ORBS: Language-independent program slicing....
  • Binkley, D., Gold, N., Harman, M., Islam, S., Krinke, J., Yoo, S., 2015. ORBS and the limits of static slicing. In:...
  • BinkleyD. et al.

    A comparison of tree- and line-oriented observational slicing

    Empir. Softw. Eng.

    (2019)
  • Binkley, D., Harman, M., 2005. Locating dependence clusters and dependence pollution. In: 21St IEEE International...
  • ChalonerK. et al.

    Bayesian experimental design: A review

    Statist. Sci.

    (1995)
  • CollardM.L. et al.

    SrcML: An infrastructure for the exploration, analysis, and manipulation of source code: A tool demonstration

  • DoH. et al.

    Supporting controlled experimentation with testing techniques: An infrastructure and its potential impact

    Empir. Softw. Eng.

    (2005)
  • EttingerR. et al.

    Untangling: A slice extraction refactoring

  • FengM. et al.

    Learning universal probabilistic models for fault localization

  • GallagherK.B.

    Using Program Slicing in Software Maintenance

    (1989)
  • Gold, N., Binkley, D., Harman, M., Islam, S., Krinke, J., Yoo, S., 2017. Generalized observational slicing for...
  • The codesurfer slicing system

    (2002)
  • Cited by (6)

    Seongmin Lee is a PhD candidate at School of Computing, KAIST, in Republic of Korea. He received BSc with a double major in School of Computing and Department of Mathematical Sciences from KAIST. His research interest includes program analysis, dependency analysis, program slicing, and genetic improvement.

    David Binkley is a professor of Computer Science at Loyola University Maryland where he has worked since earning his doctorate from the University of Wisconsin in 1991. He has been a visiting faculty researcher at the National Institute of Standards and Technology (NIST), worked with Grammatech Inc. on CodeSurfer development, and was a member of the Crest Centre at Kings’ College London. Dr. Binkley’s current research, partially funded by NSF, focuses on change recommendation and observational program analysis. He recently completed a sabbatical year working under Fulbright award with the researchers at Simula Research, Oslo Norway.

    Robert Feldt is a professor of Software Engineering at Chalmers University of Technology, Sweden, and at Blekinge Institute of Technology, Sweden. He has broad research interests spanning from human factors to automation, statistics, and applied machine learning, and he works, in particular, on software testing and quality, requirements engineering, as well as human-centered (behavioral) software engineering. Most of his research is empirical and conducted in close collaboration with industry partners in Sweden, Europe and Asia, but he also leads more basic research. Dr Feldt received a PhD in Computer Engineering from the Chalmers University of Technology in 2002, has studied Psychology at Gothenburg University in the ’90s and has also worked as an IT and software consultant for more than 25 years. He is co-Editor in Chief of the Empirical Software Engineering journal and on the editorial board of two other journals (STVR and SQJ).

    Nicolas Gold is an Associate Professor of Computer Science at University College London. He was awarded his doctorate from the University of Durham in 2000 and worked at UMIST and King’s College London before joining UCL in 2010. His current research interests include program analysis, ethics, and applications of computer music in e-health and education.

    Shin Yoo is an associate professor in the School of Computing at Korea Advanced Institute of Science and Technology (KAIST), Republic of Korea. From 2012 to 2015, he was a lecturer of software engineering in Centre for Research on Evolution, Search, and Testing (CREST) at University College London, UK. He received PhD in Computer Science from King’s College London, UK, in 2009. He received MSc and BSc from King’s College London and Seoul National University, Korea, respectively. His main research interest lies in Search Based Software Engineering, i.e. the use of metaheuristics and computational intelligence, such as genetic algorithm, to automatically solve various problems in software engineering, especially those related to testing and debugging.

    Editor: Gabriele Bavota.

    View full text