| 摘要: |
| 关键类是理解复杂软件的极佳起点, 不仅有助于优化软件的文档化过程, 也有助于压缩逆向工程得到的类图. 尽管目前已经提出了很多有效的关键类识别方法, 但普遍存在3点不足: 1)现有工作所依赖的软件网络(由软件元素及其依赖构建的图)不可避免地会包含软件运行时永远不会(或极少)被执行到的软件元素; 2)基于动态分析构建的软件网络往往不够完整, 会遗漏真正的关键类; 3)现有工作通常只考虑类之间的直接耦合对类重要性的影响, 而忽视类之间的间接(非接触)耦合及邻居节点度分布的多样性对类重要性的影响. 鉴于此, 提出一种融合动态分析和引力公式的关键类识别方法. 首先, 使用静态分析技术构建面向对象软件的类依赖网络CCN (class coupling network), 用以抽象类及类之间的耦合关系. 其次, 综合考虑CCN中类之间“直接和间接的耦合”“邻居节点度分布的多样性”等对类重要性的影响, 构建引力熵GEN (gravitational entropy)度量指标以量化类的重要性. 然后, 按照类的GEN值对所有类进行降序排列, 从而得到初步的排序结果. 最后, 通过动态分析技术收集运行时类之间真实的交互关系, 进而对初步排序的结果进行优化, 并通过设定阈值来过滤非关键类, 从而得到候选的关键类. 8个开源Java软件上的实验结果表明: 1) 在检查不超过前15% (或top-25)的节点时, 该方法从整体上而言均显著优于其他11种对比方法; 2)使用动态分析对结果进行优化, 有助于显著提升该方法的性能; 3)耦合类型的不同赋权方式对该方法的性能没有显著影响; 4)该方法在运行效率上是可以接受的. |
| 关键词: 关键类识别 软件网络 引力公式 熵 软件度量 |
| DOI:10.13328/j.cnki.jos.007453 |
| 分类号:TP311 |
| 基金项目:国家自然科学基金 (62272412, 62232008, 62032010); 浙江省自然科学基金 (LY22F020007); 桐乡市通用人工智能研究院项目(TAGI2-A-2024-0003); 浙江工商大学“数字+学科建设”项目(SZJ2022B015) |
|
| Key Class Identification Based on Dynamic Analysis and Gravitational Formula |
|
PAN Wei-Feng1, YANG Yan-Wei1, YANG Zi-Jiang2, JIANG Bo1, WANG Jia-Le1, YANG Bai-Lin1
|
|
1.School of Computer Science and Technology, Zhejiang Gongshang University, Hangzhou 310018, China;2.School of Computer Science and Technology, University of Science and Technology of China, Hefei 230026, China
|
| Abstract: |
| Key classes are a crucial starting point for understanding complex software, contributing to the optimization of documentation and the compression of reverse-engineered class diagrams. Although many effective key class identification methods have been proposed, three major limitations remain: 1) software networks, which are graphs representing software elements and their dependencies, often include elements that are never or rarely executed at runtime; 2) networks constructed through dynamic analysis are frequently incomplete, potentially omitting truly key classes; and 3) most existing approaches consider only the effect of direct coupling between classes, while ignoring the influence of indirect (non-contact) coupling and the diversity of degree distribution among neighboring nodes. To address these issues, a key class identification approach is proposed that integrates dynamic analysis with a gravitational formula. First, a class coupling network (CCN) is constructed using static analysis to represent classes and their coupling relationships. Second, a gravitational entropy (GEN) metric is introduced to quantify class importance by jointly considering direct and indirect couplings in the CCN and the degree-distribution diversity of neighboring nodes. Third, classes are ranked in descending order based on their GEN values to obtain a preliminary ranking. Finally, dynamic analysis is performed to capture actual runtime interactions between classes, which are used to refine the preliminary results. A threshold is applied to filter out non-key classes, producing a final set of candidate key classes. Experimental results on eight open-source Java projects demonstrate that the proposed method significantly outperforms eleven baseline approaches when considering no more than the top 15% (or top 25) of nodes. The integration of dynamic analysis notably improves the performance of the proposed method. Moreover, the choice of weighting schemes for coupling types has a minimal impact on performance, and the overall computational efficiency is acceptable. |
| Key words: key class identification software network gravitational formula entropy software measurement |