|
| 1 | +# Circular Dependency Analysis - README |
| 2 | + |
| 3 | +This directory contains a comprehensive analysis of the circular dependency between the `org.jnode.vm.core` and `rt` plugins in the JNode project. |
| 4 | + |
| 5 | +## Problem Statement |
| 6 | + |
| 7 | +The task was to: |
| 8 | +1. Read documentation in `docs/plugins` |
| 9 | +2. List detailed source-level dependencies between `org.jnode.vm.core` and `rt` |
| 10 | +3. Sort results by classes with fewer dependencies (involved in circular dependency) |
| 11 | +4. Propose solutions to break the circular dependency |
| 12 | + |
| 13 | +## Delivered Artifacts |
| 14 | + |
| 15 | +### 1. Analysis Tool: `analyze_vm_core_rt_cycle.py` |
| 16 | + |
| 17 | +**Purpose:** Automated tool to analyze the circular dependency between org.jnode.vm.core and rt at the Java source code level. |
| 18 | + |
| 19 | +**Usage:** |
| 20 | +```bash |
| 21 | +python3 analyze_vm_core_rt_cycle.py |
| 22 | +``` |
| 23 | + |
| 24 | +**Output:** |
| 25 | +- Generates `VM_CORE_RT_CYCLE_DETAILED_ANALYSIS.md` with complete dependency list |
| 26 | +- Shows all 154 classes involved in the circular dependency |
| 27 | +- Lists classes sorted by number of dependencies (least dependencies first) |
| 28 | +- Separates vm.core → rt dependencies from rt → vm.core dependencies |
| 29 | + |
| 30 | +**What it does:** |
| 31 | +- Parses plugin descriptors to identify which packages belong to which plugins |
| 32 | +- Analyzes Java import statements in all source files |
| 33 | +- Maps dependencies at the class level |
| 34 | +- Generates detailed reports with actionable recommendations |
| 35 | + |
| 36 | +### 2. Detailed Analysis Report: `VM_CORE_RT_CYCLE_DETAILED_ANALYSIS.md` |
| 37 | + |
| 38 | +**Content:** |
| 39 | +- **154 classes** involved in the circular dependency |
| 40 | +- **113 classes** in org.jnode.vm.core that import from rt |
| 41 | +- **41 classes** in rt that import from org.jnode.vm.core |
| 42 | +- Each class listed with: |
| 43 | + - Full qualified class name |
| 44 | + - File path |
| 45 | + - List of imports that create the circular dependency |
| 46 | + - Number of dependencies |
| 47 | +- **Sorted by dependency count** (least dependencies first) |
| 48 | + |
| 49 | +**Key sections:** |
| 50 | +1. Summary statistics |
| 51 | +2. Classes in vm.core importing from rt (sorted) |
| 52 | +3. Classes in rt importing from vm.core (sorted) |
| 53 | +4. Recommendations to break the circular dependency |
| 54 | + |
| 55 | +### 3. Implementation Proposal: `BREAKING_VM_CORE_RT_CYCLE_PROPOSAL.md` |
| 56 | + |
| 57 | +**Content:** |
| 58 | +- **Three-phase approach** to breaking the circular dependency |
| 59 | +- **Phase 1:** Move JNodePermission to rt (quick win, 1 day) |
| 60 | +- **Phase 2:** Create org.jnode.vm.isolate.api plugin (medium effort, 3-5 days) |
| 61 | +- **Phase 3:** Document Native* pattern as intentional design |
| 62 | +- Detailed implementation steps for each phase |
| 63 | +- Risk assessment and testing plan |
| 64 | +- Timeline estimates |
| 65 | + |
| 66 | +**Key insight:** |
| 67 | +Not all circular dependencies should be eliminated. The analysis shows that 31 of 41 rt → vm.core dependencies are in Native* implementation classes, which represent **intentional architectural coupling** between the VM and runtime. |
| 68 | + |
| 69 | +### 4. Executive Summary: `CIRCULAR_DEPENDENCY_SUMMARY.md` |
| 70 | + |
| 71 | +**Purpose:** High-level overview of findings and recommendations |
| 72 | + |
| 73 | +**Content:** |
| 74 | +- Quick reference to all deliverables |
| 75 | +- Key findings and statistics |
| 76 | +- Classes with least dependencies (best refactoring candidates) |
| 77 | +- Architecture insights |
| 78 | +- Next steps and recommendations |
| 79 | + |
| 80 | +## Key Findings |
| 81 | + |
| 82 | +### Statistics |
| 83 | + |
| 84 | +| Metric | Value | |
| 85 | +|--------|-------| |
| 86 | +| Total classes in cycle | 154 | |
| 87 | +| Classes in vm.core importing rt | 113 | |
| 88 | +| Classes in rt importing vm.core | 41 | |
| 89 | +| Native* implementation classes | 31 | |
| 90 | +| javax.isolate wrapper classes | 4 | |
| 91 | +| Classes with 1 dependency | 33 | |
| 92 | +| Classes with 2-5 dependencies | 61 | |
| 93 | +| Classes with >5 dependencies | 60 | |
| 94 | + |
| 95 | +### Top Refactoring Candidates |
| 96 | + |
| 97 | +**From org.jnode.vm.core (classes with 1 dependency):** |
| 98 | +1. `VmSystemSettings` - imports java.util.Properties |
| 99 | +2. `JNodePermission` - imports java.security.BasicPermission ⭐ **Phase 1 target** |
| 100 | +3. `BaseVmArchitecture` - imports java.nio.ByteOrder |
| 101 | +4. `VmReflection` - imports java.lang.reflect.InvocationTargetException |
| 102 | +5. `ResourceManagerImpl` - imports javax.naming.NamingException |
| 103 | + |
| 104 | +**From rt (classes with 1 dependency):** |
| 105 | +1. `javax.isolate.LinkMessage` - imports org.jnode.vm.isolate.LinkMessageFactory ⭐ **Phase 2 target** |
| 106 | +2. `javax.isolate.Isolate` - imports org.jnode.vm.isolate.VmIsolate ⭐ **Phase 2 target** |
| 107 | +3. `javax.isolate.StreamBindings` - imports org.jnode.vm.isolate.VmStreamBindings ⭐ **Phase 2 target** |
| 108 | +4. `javax.isolate.Link` - imports org.jnode.vm.isolate.VmLink ⭐ **Phase 2 target** |
| 109 | +5. `java.lang.VMSecurityManager` - imports org.jnode.vm.VmSystem |
| 110 | + |
| 111 | +### Architecture Insight |
| 112 | + |
| 113 | +The analysis reveals an important architectural pattern: |
| 114 | + |
| 115 | +**Native* Classes Pattern:** |
| 116 | +- 31 out of 41 classes in rt that depend on vm.core are "Native*" implementation classes |
| 117 | +- These classes implement JNode's native method implementations |
| 118 | +- Examples: NativeObject, NativeSystem, NativeThread, NativeRuntime, NativeUnsafe |
| 119 | +- This dependency is **by design** and represents the fundamental coupling between: |
| 120 | + - The Java standard library (rt) |
| 121 | + - The VM implementation (vm.core) |
| 122 | + |
| 123 | +**Conclusion:** This is not a bug - it's the bootstrap architecture. Accept and document it. |
| 124 | + |
| 125 | +## Recommended Actions |
| 126 | + |
| 127 | +### Immediate (Low Risk) |
| 128 | +✅ **Phase 1: Move JNodePermission** |
| 129 | +- Move from org.jnode.vm.core to rt |
| 130 | +- Reduces circular dependency by 1 class |
| 131 | +- Very low risk - simple permission class |
| 132 | +- Estimated time: 1 day including testing |
| 133 | + |
| 134 | +### Short Term (Medium Risk) |
| 135 | +⏭️ **Phase 2: Extract Isolate API** |
| 136 | +- Create org.jnode.vm.isolate.api plugin |
| 137 | +- Move isolate interface definitions |
| 138 | +- Reduces circular dependency by ~9 classes |
| 139 | +- Medium risk - requires interface extraction |
| 140 | +- Estimated time: 3-5 days including testing |
| 141 | + |
| 142 | +### Long Term (Documentation) |
| 143 | +📝 **Phase 3: Document Native* Pattern** |
| 144 | +- Document the Native* → vm.core pattern as intentional |
| 145 | +- Create architectural guidelines |
| 146 | +- Accept ~145 remaining dependencies as fundamental |
| 147 | +- Estimated time: 1 day |
| 148 | + |
| 149 | +## How to Use These Tools |
| 150 | + |
| 151 | +### To Analyze Current State |
| 152 | +```bash |
| 153 | +cd /home/runner/work/jnode/jnode |
| 154 | +python3 analyze_vm_core_rt_cycle.py |
| 155 | +# Review VM_CORE_RT_CYCLE_DETAILED_ANALYSIS.md |
| 156 | +``` |
| 157 | + |
| 158 | +### To Track Progress After Changes |
| 159 | +```bash |
| 160 | +# After making changes to break dependencies |
| 161 | +python3 analyze_vm_core_rt_cycle.py |
| 162 | +# Compare new report with previous one |
| 163 | +diff VM_CORE_RT_CYCLE_DETAILED_ANALYSIS.md.old VM_CORE_RT_CYCLE_DETAILED_ANALYSIS.md |
| 164 | +``` |
| 165 | + |
| 166 | +### To Implement Phase 1 |
| 167 | +```bash |
| 168 | +# Follow steps in BREAKING_VM_CORE_RT_CYCLE_PROPOSAL.md |
| 169 | +# Phase 1 section provides exact commands and changes needed |
| 170 | +``` |
| 171 | + |
| 172 | +## Related Documentation |
| 173 | + |
| 174 | +- **Plugin System:** `docs/plugins/plugin.md` |
| 175 | +- **Plugin Lists:** `docs/plugins/plugin-list.md` |
| 176 | +- **Previous Analysis:** `SOURCE_LEVEL_CYCLES_REPORT.md` |
| 177 | +- **Previous Summary:** `SOURCE_LEVEL_CYCLES_SUMMARY.md` |
| 178 | + |
| 179 | +## Notes |
| 180 | + |
| 181 | +### Why Not Eliminate All Dependencies? |
| 182 | + |
| 183 | +The analysis shows that full elimination of the circular dependency is: |
| 184 | +1. **Not necessary** - Some coupling is by design |
| 185 | +2. **Not beneficial** - Would require major architectural changes |
| 186 | +3. **Not practical** - Native implementations fundamentally need VM access |
| 187 | + |
| 188 | +### Focus Areas |
| 189 | + |
| 190 | +Instead of trying to eliminate all dependencies, focus on: |
| 191 | +1. ✅ Reducing **accidental** coupling (Phases 1 & 2) |
| 192 | +2. ✅ Documenting **intentional** coupling (Phase 3) |
| 193 | +3. ✅ Maintaining clear architectural boundaries |
| 194 | +4. ✅ Tracking dependencies over time |
| 195 | + |
| 196 | +## Contact |
| 197 | + |
| 198 | +For questions about this analysis, refer to: |
| 199 | +- The detailed reports in this directory |
| 200 | +- The plugin documentation in `docs/plugins/` |
| 201 | +- The JNode development team |
| 202 | + |
| 203 | +--- |
| 204 | + |
| 205 | +**Analysis Date:** 2025-11-16 |
| 206 | +**Tool Version:** 1.0 |
| 207 | +**Status:** Analysis Complete, Implementation Proposed |
0 commit comments