Evaluating Code Duplication Evaluating Code Duplication Detection - - PowerPoint PPT Presentation

evaluating code duplication evaluating code duplication
SMART_READER_LITE
LIVE PREVIEW

Evaluating Code Duplication Evaluating Code Duplication Detection - - PowerPoint PPT Presentation

Evaluating Code Duplication Evaluating Code Duplication Detection Techniques Detection Techniques Filip Van Van Rysselberghe Rysselberghe and Serge and Serge Demeyer Demeyer Filip Lab On Re-Engineering Lab On Re-Engineering University Of


slide-1
SLIDE 1

1

Evaluating Code Duplication Evaluating Code Duplication Detection Techniques Detection Techniques

Filip Filip Van Van Rysselberghe Rysselberghe and Serge and Serge Demeyer Demeyer Lab On Re-Engineering Lab On Re-Engineering University Of Antwerp University Of Antwerp

Towards a Taxonomy of Towards a Taxonomy of Clones in Source Code: A Clones in Source Code: A Case Study Case Study

Cory J. Cory J. Kapser Kapser and Michael W. Godfrey and Michael W. Godfrey Software Architecture Group Software Architecture Group University of Waterloo University of Waterloo

slide-2
SLIDE 2

2

Duplicated Code (a.k.a. code clone)

n Code duplication occurs when

developers systematically copy previously existing code which solved a problem similar to the one they are currently trying to solve.

n Typically 5% to 10% of code, up to

50%.

n Variety of reasons duplication occurs.

slide-3
SLIDE 3

3

Associated Problems

n Errors can be difficult to fix. n Change in requirements may be difficult

to implement.

n Code size unnecessarily increased. n Can lead to unused, dead code. n Can be indicative of design problems. n Bugs may be copied as well.

slide-4
SLIDE 4

4

Evaluating Duplicated Code Detection Techniques

n Authors set out to evaluate the qualities

  • f several clone detection techniques

and determine where they fit best into the software maintenance process.

n Compares 3 representative techniques

  • n 5 small to medium size cases.
slide-5
SLIDE 5

5

Duplication Detection Techniques

n Authors suggest there are three groups

  • f methods of detecting duplicated

code:

– String based – Token based – Parse-tree based

slide-6
SLIDE 6

6

Research Structure

n Goal n Questions n Experimental Setup

slide-7
SLIDE 7

7

Selected Cases

n ScoreMaster n TextEdit n Brahms n Jmocha n JavaParser of JMetric

slide-8
SLIDE 8

8

Results: Portability

n Simple line matching most portable. n Parameterized line matching and suffix

tree matching are fairly portable.

n Metric based matching least portable.

slide-9
SLIDE 9

9

Results: What Kind of Matches Found?

n Metrics based approach find function

block duplication.

n Simple string matching finds equal lines. n Parameterized line matching finds

duplicated lines.

n Suffix tree matching finds duplicated

series of tokens.

slide-10
SLIDE 10

10

Results: Accuracy

n Number of false matches:

– Parameterized suffix tree matching and simple line matching find no false matches. – Parameterized line matching finds few false matches. – Metrics based matching finds many false positives when applying metrics to block fragments, only a few when applying to methods.

slide-11
SLIDE 11

11

Results: Accuracy

n Number of useless matches:

– Both parameterized methods returned low amounts of useless matches. – Metrics found more useless matches, 133

  • ut of 138 in TextEdit when applying

metrics to methods. – Simple line matching finds many, 229 useless matches in TextEdit.

slide-12
SLIDE 12

12

Results: Accuracy

n Number of recognizable matches

– Metric fingerprints is very high. – Parameterized matching techniques return less recognizable matches. – Simple string match returns the lowest.

slide-13
SLIDE 13

13

Results: Performance

slide-14
SLIDE 14

14

Conclusions

n Based on comparing the 3 representative duplication detection

techniques, the following conclusions were drawn: – Simple line matching is suitable for problem detection and assessment. – Parameterized matching will work well with fine-grained refactoring tools. – Metric Fingerprints will work well with method level refactoring techniques.

n Have shown that each technique has specific advantages and

disadvantages.

n Have laid the ground work for a systemic approach to detecting

and removing clones.

slide-15
SLIDE 15

15

Toward a Taxonomy of Clones

n Aim to profile cloning as it occurs in the

real world and generate a taxonomy of types of code duplications.

n This will give us insight into how and

why developers duplicate code, and aid the effort in developing clone detection techniques and tools.

slide-16
SLIDE 16

16

The Study

n Performed on the Linux kernel file-

system subsystem.

– Consists of 538 .c and .h files, 279,118 LOC. – 42 file system implementations. – Layered design.

ext2 coda jffs vfs kernel

slide-17
SLIDE 17

17

Study Methods

n Used parameterized string matching and

metrics based detection to gather clones.

n Manually inspected clones returned from the

detection tools and created the current taxonomy.

n Generated scripts to classify each clone into

  • ne of clone types, and again manually

inspected these results.

slide-18
SLIDE 18

18

Taxonomy of Clones

n Duplicated blocks within the same function. n Cloned blocks across functions, files and

directories.

n Similar functions, same file. n Functions cloned between files in the same

directory.

n Functions cloned across directories. n Cloned files. n Initialization and finalization clones.

slide-19
SLIDE 19

19

Results

n 12% of the Linux kernel file-system

code is involved in code duplication.

n Detected 3116 clone pairs, with an

average length is 13.5 lines.

n 78% of cloning occurs in the same

directory.

slide-20
SLIDE 20

20

Locality of Clone Pairs

slide-21
SLIDE 21

21

Frequency of Clone Types

slide-22
SLIDE 22

22

Families of File Systems

n ext2 and ext3 highly related. n Intermezzo cloned much from the main

file-system code and Coda.

n Jffs has cloned much from inflate_fs,

most of the clones were put into 1 file.

slide-23
SLIDE 23

23

Visualization of Cloning Without Showing Same Directory Clones

slide-24
SLIDE 24

24

Metrics Vs. String Matching

slide-25
SLIDE 25

25

Conclusions

n We have begun to build a taxonomy of code

clones in software.

n Cloning activity in the Linux kernel file-system

subsystem is at a non-trivial rate.

n Cloning most commonly occurs within a

subsystem.

n Parameterized string matching provides an

interesting and powerful method for function duplication detection.

n 3D visualization provided an interesting

method of viewing clones amongst subsystems.

slide-26
SLIDE 26

26

Importance of this Work

n Lots of clone detection methods out

there, few comparisons.

n What we catch and what we miss is

unclear.