TL;DR
"Software organ transplantation" is an emerging technique for reusing highly specific functional code snippets without the bloat of traditional component reuse. This paper addresses the "organ shortage" in this field by demonstrating that open-source GitHub repositories—specifically commits labeled with the keyword "add"—are a massive, viable source of easily transplantable code organs that can be successfully integrated into new host applications.
What Problem Does This Paper Address?
In software engineering, code reuse traditionally happens at the "component" level (e.g., importing entire libraries or sets of classes). However, this often introduces massive code bloat and potential defects when a developer only needs one specific functionality. In 2015, researchers introduced the concept of "organ transplantation": extracting just the specific lines of code or functions (the "organ") needed for a feature and grafting them into a new host program.
While highly efficient, this technique has faced a major bottleneck: a lack of available organs. Previous research relied on small-scale, highly specific, and pre-prepared datasets. This paper asks whether the vast, chaotic ecosystem of open-source GitHub repositories can be mined to automatically identify, extract, and transplant functional organs into new software.
Methods
The authors propose a strategy to mine and transplant code from GitHub:
- Mining and Classification: They analyzed commit messages across open-source projects, identifying the keyword "add" as a strong signal for new, functional code. They classified these commits into "practical" (actual features) vs. "unpractical" (README updates, comments).
- Transplantability Assessment: Organs were categorized as easy-to-transplant (self-contained, no undefined variables) or difficult-to-transplant (coupled to the original codebase).
- Extraction and Integration: For difficult organs, the authors developed a method to extract the "vein"—the necessary local and global variables required for the organ to function. They use call graphs to trace and capture the latest state of these variables before the organ is executed.
- Transplantation: To find the right place to inject the organ in the host software, they use a lexical fitness function. By comparing the names of the donor class and potential host classes (assuming class names reflect functionality), they identify the most logical insertion point.
Note: While the framework is designed with automation in mind, the extraction and transplantation experiments in this paper were conducted manually to validate the strategy.
Datasets
- Empirical Study Dataset: 12 popular GitHub projects across 6 languages (Java, Go, JavaScript, CSS, Ruby, HTML), including SoundJS, awesome-nlp, and requery.
- Unit Testing Dataset: 30 mathematical organs extracted from three repositories: Apache Commons Math (Java), SymPy (Python), and CML (C).
- Host Platform: MiCode Notes, an open-source Android notepad application, used as the target host for real-world transplantation experiments.
Key Insights and Ideas
- "Add" commits are a goldmine: Developers explicitly document feature additions. Nearly 60% of commits with the word "add" contained practical, reusable code organs.
- Most code is surprisingly modular: A massive 70% of the practical organs identified were "easy-to-transplant." They had weak relevance to their surrounding source code, meaning they could be lifted and shifted with minimal modification.
- Organs come in diverse shapes: The mined organs weren't just single functions. They ranged from simple multi-line statements (26%) and new functions (35%) to entirely new classes (17%).
- Lexical similarity works for placement: Simply matching the vocabulary of the donor's class name with the host's class names proved to be an effective heuristic for finding where a transplanted feature should live.
Key Results
- High Reliability: The 30 extracted mathematical organs were subjected to rigorous unit testing (using tools like EvoSuite, JUnit Test Generator, PyUnit, and LDRA Testbed). Java organs achieved an impressive 97.6% average pass rate, while Python and C organs achieved 81.9% and 80.5%, respectively.
- Successful Real-World Transplants: The authors successfully transplanted three distinct Java organs into the MiCode Notes Android app: a background music player, a welcome screen, and a gesture password system.
- Low Overhead: The transplantation process required very little extra work. The most complex transplant (the gesture password) required only 13 atomic operations (10 additions, 1 deletion, 2 modifications) to integrate perfectly into the host.
Limitations and Future Work
The authors acknowledge several limitations. First, the dataset was relatively small due to the manual effort required to verify the organs. Second, relying solely on the "add" keyword likely misses many viable organs hidden in "fix," "update," or "modify" commits. Finally, the unit tests were restricted to mathematical functions, which are inherently easier to test than complex state-dependent UI or network code.
Future work will focus on fully automating the extraction and transplantation pipeline. The authors also plan to tackle more complex transplantation scenarios, such as organs that span multiple files or require the deletion of existing host code to function properly.
Summary updated