Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 保守支援を目的とした コードクローン情報検索ツール.

Similar presentations


Presentation on theme: "Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 保守支援を目的とした コードクローン情報検索ツール."— Presentation transcript:

1 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 保守支援を目的とした コードクローン情報検索ツール の試作 泉田 聡介 †, 植田 泰士 †, 神谷 年洋 ‡, 楠本 真二 †, 井上克郎 † † 大阪大学大学院情報科学研究科 ‡ 科学技術振興事業団 さきがけ研究 21

2 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 2 研究 の 背景 (1/2) コードクローン ソースコード中に含まれる同一もしくは類 似したコードのこと, いわゆる “ 重複した コード ” クローン

3 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 3 研究 の 背景 (2/2) コードクローンはソフトウェア保守を困難にす る コードクローンにバグがあった場合、全てのコード クローンについて修正を考慮しなければならない 機能追加の場合も同様 コードクローン検出ツール CCFinder ソースコードをトークン単位で直接比較することに よりクローンを検出 数百万行規模のシステムにも実用時間で解析可能 実用的に意味のないクローンを検出しない 様々な企業のソフトウェアにも適用している

4 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 4 コードクローン検出手順 (1) ソースコードを入力し,トークンの列にす る (2) 変形ルールにより,トークン列を変形する (3) パラメータ置換を行う (4) マッチングアルゴリズムによりコードク ローンを検出する (5) コードクローンの位置 ( ファイル,行, カラ ム ) を出力する

5 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 5 1. static void foo() throws RESyntaxException { 2. String a[] = new String [] { "123,400", "abc", "orange 100" }; 3. org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+"); 4. int sum = 0; 5. for (int i = 0; i < a.length; ++i) 6. if (pat.match(a[i])) 7. sum += Sample.parseNumber(pat.getParen(0)); 8. System.out.println("sum = " + sum); 9. } 10. static void goo(String [] a) throws RESyntaxException { 11. RE exp = new RE("[0-9,]+"); 12. int sum = 0; 13. for (int i = 0; i < a.length; ++i) 14. if (exp.match(a[i])) 15. sum += parseNumber(exp.getParen(0)); 16. System.out.println("sum = " + sum); 17. } 例題ソースコード

6 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 6 ステップ (1) :ソースコードを入力し,トークンの列にする

7 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 7 ステップ (2) :変形ルールにより,トークン列を変形する

8 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 8 ステップ (3) :パラメータ置換を行う

9 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 9 ステップ (4) : マッチング アルゴリズ ムにより, コードク ローンを検 出

10 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 10 ステップ (4) : マッチング アルゴリズ ムにより, コードク ローンを検 出

11 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 11 ステップ (5) :コードクローンの位置を出力する #version: ccfinder 4.5h #langspec: JAVA #option: -b 30,1 #option: -k: - #option: -r abcdfikmnprsv #option: -c wfg #begin{file description} 0.0 17 92C:\test1.java #end{file description} #begin{syntax error} #end{syntax error} #begin{clone} 0.0 3,3,10 10,1,47 0.011,3,53 17,1,90 37 #end{clone} 対象ファイルの ID (file 0 in group 0) クローンの位置 file 0.0: 3 ~ 9 行 file 0.0: 11 ~ 17 行 がクローンである

12 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 12 1. static void foo() throws RESyntaxException { 2. String a[] = new String [] { "123,400", "abc", "orange 100" }; 3. org.apache.regexp.RE pat = new org.apache.regexp.RE("[0-9,]+"); 4. int sum = 0; 5. for (int i = 0; i < a.length; ++i) 6. if (pat.match(a[i])) 7. sum += Sample.parseNumber(pat.getParen(0)); 8. System.out.println("sum = " + sum); 9. } 10. static void goo(String [] a) throws RESyntaxException { 11. RE exp = new RE("[0-9,]+"); 12. int sum = 0; 13. for (int i = 0; i < a.length; ++i) 14. if (exp.match(a[i])) 15. sum += parseNumber(exp.getParen(0)); 16. System.out.println("sum = " + sum); 17. }

13 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 13 #version: ccfinder 4.5h #langspec: JAVA #option: -b 30,1 #option: -k: - #option: -r abcdfikmnprsv #option: -c wfg #begin{file description} 0.0 17 92C:\test1.java #end{file description} #begin{syntax error} #end{syntax error} #begin{clone} 0.0 3,3,10 10,1,47 0.011,3,53 17,1,90 37 #end{clone} CCFinder の 出力 ユーザの利用目的に応じた ユーザインタフェースが求められて いる 検出結果はクローンの位置情報のみであり、 その結果を直感的に理解することは困難

14 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 14 研究 の 目的 CCFinder を利用したコードクローン情報検索 ツールの試作 ユーザが入力したコード片に対して,そのコード クローンを含むファイルを検索し、提示する

15 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 15 利用状況の想定 修正箇所の特定 デバッグへの適用 機能追加時の使用 発見したクローン全てに 対し、修正コードを適用 を検討 修正箇所に関するクロー ンの検索 機能を追加 追加前のコード片のクロー ン を検索 クローン全てについて 機能追加の是非を検討

16 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 16 クローン情報検索ツール 入力: ユーザが指定するコード片 検索対象ファイル名のリスト 出力: ユーザが指定したコード片のクロー ンを含む ファイルのリスト 特徴 簡単な操作 検索結果のソースコード上での確認 ハイライト表示等 Java で実装.サイズは約 3 千行.

17 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 17 ツールのインターフェース ファイルのリストを入 力 検索したいコード 片を入力 解析対象言語の選択 解析開始ボタン

18 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 18 ツールの使用例 検索項目 の入力 起動画面 検索結果 ソースコー ドの確認

19 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 19 ケーススタディ 擬似デバッグへの適用 SourceForge で開発されている日本語入力 システム「かんな」の修正例へ適用 修正の対象となるコード片を検出できるか 実行にかかる時間はどれくらいか 適用環境 CPU Pentium4 2GHz 、メインメモリ 512MB OS WindowsXP HomeEdition SP1 Java VM JDK1.4 付属のもの

20 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 20 「かんな」の修正例 「かんな」の ver3.6 と ver3.6p1 間の修正 例 セキュリティー問題の修正において、バッ ファ処理の前にオーバーフローを調べる処 理を追加する. ほぼ同じ修正を行っている部分が 21 ヵ所 あった.

21 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 21 評価方法 以下の 2 つの方法の比較を行う. grep を用いた検索 修正箇所で使用されている変数 “ Request.type ” で検索 本ツールを用いた検索 入力コード片として,典型的なバッファ処理を行ってい る 2 行を与えて検索 ir_debug(Dmsg(10, ” ProcWideReq3 start\n ” ) ); buf += HEADER_SIZE; Request.type3.context = S2TOS(buf); 検索対象:かんな ver3.6 の全ソースコード (約 21,000 行)

22 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 22 結果 検索結果 検索時間 grep 243 行( 58 箇所) 約 1 秒 本ツール 17 箇所 約 8 秒 本ツールでの検索では,実際の修正箇所 21 箇所のうち 4 箇所が検出されず 2 行が連続していなかった 検出された 17 箇所は正しい grep での検索結果のうち 134 行( 20 箇 所)が 修正箇所に関連していた

23 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 23 f 値を用いた比較 f 値の定義 完全性 - 必要な情報のうち実際に検索された情報の割合 効率性 - 実際に検索された情報のうち必要な情報の割合 完全性効率性 f値f値 grep95%34%0.50 本ツール 81%100%0.90 本ツールでの検索の方が効率的である

24 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 24 まとめ と 今後 の 課題 ユーザが入力したコード片のクローンを検索 するツールの試作を行った 「かんな」の修正へ適用した 今後の課題 実際の保守作業への適用 出力する結果の表示方法の検討

25 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University H15/09/11FIT2003 25


Download ppt "Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 保守支援を目的とした コードクローン情報検索ツール."

Similar presentations


Ads by Google