A Mutation / Injection-based Automatic Framework for Evaluating Code Clone Detection Tools Chanchal Roy University of Saskatchewan The 9th CREST Open Workshop.

Slides:



Advertisements
Similar presentations
Duplicate code detection using Clone Digger Peter Bulychev Lomonosov Moscow State University CS department.
Advertisements

Privacy-Enhancing Models and Mechanisms for Securing Provenance and its Use October 2010 Lead PI: Ravi Sandhu (UT San Antonio) PIs: Elisa Bertino (Purdue),
Chapter 24 Quality Management.
Chao Liu, Chen Chen, Jiawei Han, Philip S. Yu
Context-Sensitive Query Auto-Completion AUTHORS:NAAMA KRAUS AND ZIV BAR-YOSSEF DATE OF PUBLICATION:NOVEMBER 2010 SPEAKER:RISHU GUPTA 1.
Software Testing Technique. Introduction Software Testing is the process of executing a program or system with the intent of finding errors. It involves.
Kiri Wagstaff Jet Propulsion Laboratory, California Institute of Technology July 25, 2012 Association for the Advancement of Artificial Intelligence CHALLENGES.
Building Bug-Free O-O Software: An Introduction to Design By Contract A presentation about Design By Contract and the Eiffel software development tool.
Runtime Techniques for Efficient and Reliable Program Execution Harry Xu CS 295 Winter 2012.
Provenance-Aware Storage Systems Margo Seltzer April 29, 2005.
1 A Systematic Review of Cross- vs. Within-Company Cost Estimation Studies Barbara Kitchenham Emilia Mendes Guilherme Travassos.
DATA TRACKING AND EVALUATION 1. Goal of the STEP program: To increase the number of STEM graduates within the five-year period of the grant. You have.
ANTLR in SSP Xingzhong Xu Hong Man Aug Outline ANTLR Abstract Syntax Tree Code Equivalence (Code Re-hosting) Future Work.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Extraction of.
Eugene Syriani Jeff Gray University of Alabama Software Engineering Group Department of Computer Science College of Engineering.
Automated Software Maintainability through Machine Learning by Eric Mudge.
Reverse Engineering © SERG Code Cloning: Detection, Classification, and Refactoring.
Prediction of fault-proneness at early phase in object-oriented development Toshihiro Kamiya †, Shinji Kusumoto † and Katsuro Inoue †‡ † Osaka University.
Code recognition & CL modeling through AST Xingzhong Xu Hong Man.
© S. Demeyer, S. Ducasse, O. Nierstrasz Duplication.1 7. Problem Detection Metrics  Software quality  Analyzing trends Duplicated Code  Detection techniques.
Analyzing Software Code and Execution – Plagiarism and Bug Detection Shoaib Jameel.
7. Duplicated Code Metrics Duplicated Code Software quality
Parameterizing Random Test Data According to Equivalence Classes Chris Murphy, Gail Kaiser, Marta Arias Columbia University.
1 Program Comprehension through Dynamic Analysis Visualization, evaluation, and a survey Bas Cornelissen (et al.) Delft University of Technology IPA Herfstdagen,
Refactoring Support Tool: Cancer Yoshiki Higo Osaka University.
05-899D: Human Aspects of Software Development Spring 2011, Lecture 20 YoungSeok Yoon Institute for Software.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Industrial Application.
Reverse Engineering State Machines by Interactive Grammar Inference Neil Walkinshaw, Kirill Bogdanov, Mike Holcombe, Sarah Salahuddin.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Finding Similar.
Detecting software clones in binaries Zaharije Radivojević, Saša Stojanović, Miloš Cvetanović School of Electrical Engineering, Belgrade University 14th.
CD in Natural Language Software Artifacts 1 Clone Detection in Natural Language Software Artifacts: Techniques and Applications Elmar Juergens November.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University A Criterion for.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A clone detection approach for a collection of similar.
Supervisor:Mr. Sayed Morteza Zaker Presentor:Fateme hadinezhad.
The CoNLL-2013 Shared Task on Grammatical Error Correction Hwee Tou Ng, Yuanbin Wu, and Christian Hadiwinoto 1 Siew.
How to write a successful EU funded project proposal? Fred de Vries Brussels 21 April 2004 Seminar Networking eLearning Practitioners.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University A Method to Detect License Inconsistencies for Large-
Mining and Analysis of Control Structure Variant Clones Guo Qiao.
CS Fall 2007 Dr. Barbara Boucher Owens. CS 2 Text –Main, Michael. Data Structures & Other Objects in Java Third Edition Objectives –Master building.
2002/12/11PROFES20021 On software maintenance process improvement based on code clone analysis Yoshiki Higo* , Yasushi Ueda* , Toshihiro Kamiya** , Shinji.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Detection and evolution analysis of code clones for.
CMCD: Count Matrix based Code Clone Detection Yang Yuan and Yao Guo Key Laboratory of High-Confidence Software Technologies (Ministry of Education) Peking.
1 Gemini: Maintenance Support Environment Based on Code Clone Analysis *Graduate School of Engineering Science, Osaka Univ. **PRESTO, Japan Science and.
Debug Concern Navigator Masaru Shiozuka(Kyushu Institute of Technology, Japan) Naoyasu Ubayashi(Kyushu University, Japan) Yasutaka Kamei(Kyushu University,
1 Evaluating Code Duplication Detection Techniques Filip Van Rysselberghe and Serge Demeyer Lab On Re-Engineering University Of Antwerp Towards a Taxonomy.
GECCO Papers Same research group, different lead authors Same conference Paper 1: Embodied Distributed Evolutionary Algorithm (EDEA) for on-line, on-board.
THE IRISH SOFTWARE ENGINEERING RESEARCH CENTRELERO© What we currently know about software fault prediction: A systematic review of the fault prediction.
Duplicate code detection using anti-unification Peter Bulychev Moscow State University Marius Minea Institute eAustria, Timisoara.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University Cage: A Keyword.
Week 14 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Classification.
1 Experience from Studies of Software Maintenance and Evolution Parastoo Mohagheghi Post doc, NTNU-IDI SEVO Seminar, 16 March 2006.
 Software Clones:( Definitions from Wikipedia) ◦ Duplicate code: a sequence of source code that occurs more than once, either within a program or across.
What kind of and how clones are refactored? A case study of three OSS projects WRT2012 June 1, Eunjong Choi†, Norihiro Yoshida‡, Katsuro Inoue†
Concepts and Realization of a Diagram Editor Generator Based on Hypergraph Transformation Author: Mark Minas Presenter: Song Gu.
1 Gemini: Code Clone Analysis Tool †Graduate School of Engineering Science, Osaka Univ., Japan ‡ Graduate School of Information Science and Technology,
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Aries: Refactoring.
(6) Estimating Computer’s efficiency Software Estimation The objective of Software Estimation is to provide the skills needed to accurately predict the.
NPQ Instructor II. Introduction  The NPQ Instructor II program is designed for individuals that are interested in the Fire and Emergency Services Training.
Department of Computer Science, Graduate School of Information Science & Technology, Osaka University Detection of License Inconsistencies in Free and.
Software Engineering Lab (LabSoft) 1/29 On The Detection of Code Clone With Concern Analysis Paiva, Alexandre; Alves, Johnatan;
Software Metrics 1.
CBCD: Cloned Buggy Code Detector
A Refactoring Technique for Large Groups of Software Clones
CCLearner: A Deep Learning-Based Clone Detection Approach
○Yuichi Semura1, Norihiro Yoshida2, Eunjong Choi3, Katsuro Inoue1
: Clone Refactoring Davood Mazinanian Nikolaos Tsantalis Raphael Stein
Refactoring Support Tool: Cancer
On Refactoring Support Based on Code Clone Dependency Relation
George Mason University
Presentation transcript:

A Mutation / Injection-based Automatic Framework for Evaluating Code Clone Detection Tools Chanchal Roy University of Saskatchewan The 9th CREST Open Workshop Code Provenance and clone Detection Nov 23, 2010

2 Introduction Clone Pair Clone Class What are Code Clones? A code fragment which has identical or similar code fragment (s) in source code

3 Introduction Intentional copy/paste is a common reuse technique in software development Previous studies report 7% - 30% cloned code software systems [Baker WCRE95, Roy and Cordy WCRE08] Unfortunately, clones are harmful in software maintenance and evolution [Juergens et al. ICSE09]

4 Introduction: Existing Methods In response, many methods proposed: Text-based: Duploc [Ducasse et al. ICSM99], NICAD [Roy and Cordy, ICPC08] Token-based: Dup [Baker, WCRE95], CCFinder [Kamiya et al., TSE02], CP-Miner [Li et al., TSE06] Tree-Based: CloneDr [Baxter et al. ICSM98], Asta [Evans et al. WCRE07], Deckard [Jiang et al. ICSE07], cpdetector [Falke et al. ESE08] Metrics-based: Kontogiannis WCRE97, Mayrand et al. ICSM96 Graph-based: Gabel et al. ICSE08, Komondoor and Horwitz SAS01, Dublix [Krinke WCRE01]

5 Introduction: Lack of Evaluation Marked lack of in-depth evaluation of the methods in terms of precision and recall Existing tool comparison experiments (e.g., Bellon et al. TSE07) or individual evaluations have faced serious challenges [Baker TSE07, Roy and Cordy ICPC08, SCP09]

6 Introduction: Precision and Recall Software System A: Actual clones? C: Candidate clones detected by T False negatives False positives D: Detected actual clones Recall= Precision = | A | | D | | C | | D |

7 Primary Challenge: Lack of a Reliable Reference Set We DONT have this Software System A :Actual clones? C : Candidate clones. We still dont have this actual/reliable clone set for any system

8 Challenges in Oracling a System No crisp definition of code clones Huge manual effort May be possible for small system What about for large systems? Even the relatively small cook system yields nearly a million function pairs to sort through Not possible for human to do error-free

9 Challenges in Evaluation Union of results from different tools can give good relative results but no guarantee that the subject tools indeed detect all the clones Manual validation of the large candidate clone set is difficult Bellon [TSE07] took 77 hours for only 2% of clones No studies report the reliability of judges

10 Lack of Evaluation for Individual Types of Clones No work reports precision and recall values for different types of clones except, Bellon et al. [TSE07]: Types I, II and III Falke et al. [ESE08]: Types I and II Limitations reported Baker [TSE07] Roy and Cordy ICPC08, Roy et al. SCP09

11 In this talk… A mutation-based framework that automatically and efficiently measures and compares precision and recall of the tools for different fine-grained types of clones. A taxonomy of clones => Mutation operators for cloning => Framework for tool comparison

12 An Editing Taxonomy of Clones Definition of clone is inherently vague Most cases detection dependent and task-oriented Some taxonomies proposed but limited to function clones and still contain the vague terms, similar and long differences [Roy and Cordy SCP09, ICPC08] We derived the taxonomy from the literature and validated with empirical studies [Roy and Cordy WCRE08] Applicable to any granularity of clones

13 Exact Software Clones Changes in layout and formatting Reuse by copy and paste void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Changes in whitespace void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Changes in comments Changes in formatting void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 { void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 { Type I

14 void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Reuse by copy and paste Renaming of identifiersRenaming of Literals and Types void addTimes(int n) { //s0 int add=0; //s1 int times =1; //s2 for (int i=1; i<=n; i++) { //s3 add=add + i; //s4 times = times * i; //s5 fun(add, times); }} //s6 sumProd =>addTimes sum => add product => times Near-Miss Software Clone Renaming Identifiers and Literal Values Type II void sumProd(int n) { //s0 double sum=0.0; //s1 double product =1.0; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 0=>0.0 1=>1.0 int=>double

15 Near-Miss Software Clone Statements added/deleted/modified in copied fragments void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Reuse by copy and paste Addition of new of lines Deletions of lines void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) //s3 if (i % 2 == 0){ //s3b sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 //s5 line deleted fun(sum, product); }} //s6 void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 if (i % 2 == 0) sum+= i; //s4m product = product * i; //s5 fun(sum, product); }} //s6 Modification of lines Type III

16 void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Reordering of Statements void sumProd(int n) { //s0 int product =1; //s2 int sum=0; //s1 for (int i=1; i<=n; i++) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); }} //s6 Near-Miss Software Clone Statements reordering/control replacements Type IV void sumProd(int n) { //s0 int sum=0; //s1 int product =1; //s2 int i = 0; //s7 while (i<=n) { //s3 sum=sum + i; //s4 product = product * i; //s5 fun(sum, product); //s6 i =i + 1; }} //s8 Reuse by copy and paste Control Replacements

17 Mutation Operators for Cloning For each of the fine-grained clone types of the clone taxonomy, We built mutation operators for cloning We use TXL [Cordy SCP06] in implementing the operators Tested with C, C# and Java

18 Mutation Operators for Cloning NameRandom Editing Activities mCWChanges in whitespace mCCChanges in comments mCFChanges in formatting For Type I Clones

19 mCC: Changes in Comments if (x==5) { a=1; } else { a=0; } mCC Line Original Mutated Line if (x==5) { a=1; } else //C { a=0; }

20 mCF: Changes in formatting if (x==5) { a=1; } else { a=0; } if (x==5) { a=1; } else { a=0; } mCF Line Original Mutated Line

21 mCF: Changes in formatting if (x==5) { a=1; } else { a=0; } if (x==5) { a=1; } else { a=0; } mCF Line Original Mutated Line One or more changes can be made at a time

22 Mutation Operators for Cloning NameRandom Editing Activities mSRISystematic renaming of identifiers mARIArbitrary renaming of identifiers mRPEReplacement of identifiers with expressions (systematically/non- systematically) For Type II Clones

23 mSRI: Systematic renaming of identifiers if (x==5) { a=1; } else { a=0; } Line Original Mutated Line if (x==5) { b=1; } else { b=0; } mSRI

24 mSRI: Systematic renaming of identifiers if (x==5) { a=1; } else { a=0; } mSRI Line Original Mutated Line if (x==5) { b=1; } else { b=0; }

25 mARI: Arbitrary renaming of identifiers if (x==5) { a=1; } else { a=0; } mARI Line Original Mutated Line if (x==5) { b=1; } else { c=0; }

26 Mutation Operators for Cloning NameRandom Editing Activities mSILSmall insertions within a line mSDLSmall deletions within a line mILsInsertions of one or more lines mDLsDeletions of one or more lines mMLsModifications of whole line(s) For Type III Clones

27 mSIL: Small Insertion within a Line if (x==5) { a=1; } else { a=0; } mSIL Line Original Mutated Line if (x==5) { a=1 + x; } else { a=0; }

28 mILs: Insertions of One or More Lines if (x==5) { a=1; } else { a=0; } mILs Line Original Mutated Line if (x==5) { a=1; } else { a=0; y=y + c; }

29 Mutation Operators for Cloning NameRandom Editing Activities mRDsReordering of declaration statements mROSReordering of other statements (Data- dependent and/or in-dependent statements) mCRReplacing one type of control by another For Type IV Clones

30 Mutation Operators for Cloning Combinations of mutation operators if (x==5) { a=1; } else { a=0; } if (x==5) { a=1; } else //c { a=0; } if (x==5) { b=1; } else //c { b=0; } if (x==5) { b=1+x; } else //c { b=0; } Original Final Mutated mCC mSRI mSIL mCC + mSRI + mSIL

31 The Evaluation Framework Generation Phase Create artificial clone pairs (using mutation analysis) Inject to the code base Evaluation Phase How well and how efficiently the known clone pairs are detected by the tool(s)

32 Generation Phase: Base Case Code Base oCF(f3, 10, 20) Database Mutation Operators Pick an operator (say mCC) and apply Mutated Fragment Randomly injects into the code base Randomly picks a fragment Original Fragment mOCF(f1, 2, 12) OP/Type: mCC CP: (oCF, moCF)

33 Evaluation Phase: Base Case Mutated Code Base oCF(f3, 10, 20) Database mOCF(f1, 2, 12) OP/Type: mCC CP: (oCF, moCF) Clone Report Tool Evaluation Subject Tool: T

34 Unit Recall = 1, if (oCF, moCF) is killed by T in the mutated code base 0, otherwise For known clone pair, (oCF, moCF), of type mCC, the unit recall is: UR T (oCF, moCF)

35 Definition of killed(oCF, moCF) (oCF, moCF) has been detected by the subject tool, T That is a clone pair, (CF1, CF2) detected by T matches or subsumes (oCF, moCF) We use source coordinates of the fragments to determine this First match the full file names of the fragments, then check for begin-end line numbers of the fragments within the files

36 Unit Precision = v: Total no of valid clone pairs with moCF k:Total no of clone pairs with moCF Say, for moCF, T reports k clone pairs, (moCF, CF1), (moCF, CF2),…, (moCF, CFk) Also let, v of them are valid clone pairs, then For known clone pair, (oCF, moCF), of type mCC, the unit precision is: UP T (oCF, moCF)

37 Automatic Validation of Known Clone Pairs Built a clone pair validator based on NICAD (Roy and Cordy ICPC08) Unlike NICAD, it is not a clone detector It only works with a specific given clone pair It is aware of the mutation operator applied Depending on the inserted clone, detection parameters are automatically tuned

38 Generation Phase: General Case Random Fragment Selection Mutator 1 Mutator 2 Mutator N Injected Mutant Source Coordinate Database Random Fragment Injection Random Fragments Original Code Base Randomly Mutated Fragments Randomly InjectedMutant Code Bases

39 Evaluation Phase: General Case Injected Mutant Source Coordinate Database Randomly InjectedMutant Code Bases Tool 1 Tool 2 Tool K 2 1 M Tool 1 Mutant 1 Report Tool 2 Mutant 1 Report Tool K Mutant 1 Report Mutant 1 Tool Eval Mutant 2 Tool Eval Mutant M Tool Eval Statistical Analysis and Reporting Evaluation Database

40 Recall = With mCC, m fragments are mutated and each injected n times to the code base R T mCC UR T (oCF i, moCF i ) i=1 m * n = R T Type I UR T (oCF i, moCF i ) i=1 (m * n) * (3 + 4)

41 Overall Recall l clone mutation operators and c of their combinations applied n times to m selected code fragments, so = R T overall UR T (oCF i, moCF i ) i=1 (m * n) * (l + c)

42 Precision With mCC, m fragments are mutated and each injected n times to the code base = P T mCC i=1 vivi m * n i=1 kiki m * n = P T Type I i=1 vivi m * n * (3 + 4) i=1 kiki m * n * (3 + 4)

43 Overall Precision l clone mutation operators and c of their combinations applied n times to m selected code fragments, so = P T Overall i=1 m * n * (l + c) i=1 m * n * (l + c) vivi kiki

44 Example Use of the Framework Select one or more subject systems Case one: Evaluate single tool We evaluate NICAD [Roy and Cordy ICPC08 ] Case two: Compare a set of tools Basic NICAD [Roy and Cordy WCRE08] Flexible Pretty-Printed NICAD [Roy and Cordy ICPC08 ] and Full NICAD [Roy and Cordy ICPC08 ]

45 Subject Systems LanguageCode BaseLOC#Methods C GZip K117 Apache-httpd K4301 Weltab11K123 Java Netbeans-Javadoc114K972 Eclipse-jdtcore148K7383 JHotdraw 5.4b40K2399

46 Recall Measurement Clone Type Standard Pt-Printing Flexible Pt-Printing Full NICAD Type I100% Type II29%27%100% Type III80%85%100% Type IV67% 77% Overall84%87%96%

47 Precision Measurement Clone Type Standard Pt-Printing Flexible Pt-Printing Full NICAD Type I100% Type II94% 97% Type III85%81%96% Type IV81%79%89% Overall90%89%95%

48 Other Issues Time and memory requirements Can report fine-grained comparative timing and memory requirements for subject tools Scalability of the framework Can work subject system of any size, depending on the scalability of the subject tools Uses multi-processing to balance the load Adapting tools to the framework The subject tool should run in command line Should provide textual reports of the found clones

49 Related Work: Tool Comparison Experiments Baily and Burd SCAM02 3 CDs + 2 PDs Bellon et al. TSE07 Extensive to-date 6 CDs, C and Java systems Koschke et al. WCRE06 Rysselberge and Demeyer ASE04

50 Related Work: Single Tool Evaluation Strategies Text-based Only example-based evaluation, no precision and recall evaluations except NICAD Token-based CP-Miner, for precision by examining 100 randomly selected fragments AST-based Cpdetector, in terms of both precision and recall (Type I & II). Deckard, for precision with examing 100 segments Metrics-based Kontogianis evaluated with IR-approach, system was oracled manually. Graph-based Gabel et al., precision examined 30 fragments per experiment.

51 Conclusion and Future Work Existing evaluation studies have several limitations Baker TSE07, Roy and Cordy SCP09/ICPC08 We provided a mutation/injection-based automatic evaluation framework Evaluates precision and recall single tool Compare tools for precision and recall Effectiveness of this framework has been shown comparing NICAD variants We are planning to conduct a mega tool comparison experiment with the framework

52 Acknowledgements Inspirations Rainer Koschke for Dagstuhl seminar 2006 Stefan Bellon et al., for beginning the road to meaningful evaluation & comparison Tool & method authors For useful answers to our questions and worries Anonymous referees & colleagues For help in presenting, tuning and clarifying several of the papers of this work.

53 Questions?

54 References Roy, C.K., and Cordy, J.R. A Mutation / Injection- based Automatic Framework for Evaluating Code Clone Detection Tools. In Mutation 2009, pp , IEEE Press, Denver, Colorado, USA, April 2009.A Mutation / Injection- based Automatic Framework for Evaluating Code Clone Detection Tools