Replace SoftIdentityMap with modern Cache implementation and add model object pooling #2529
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
This PR replaces the buggy
SoftIdentityMap
with a modern, thread-safe cache implementation and adds model object pooling for better memory efficiency.Note: This is a simplified version of #2506 targeted for Maven 4.0.0, focusing on the core cache replacement and object pooling without complex configuration and statistics.
Problem
The existing
SoftIdentityMap
had bugs and needed replacement with a modern cache implementation. Additionally, Maven 4 model objects could benefit from object pooling to reduce memory allocation overhead.Solution
1. Modern Cache Infrastructure
Replaced
SoftIdentityMap
with a complete new cache infrastructure:Cache<K,V>
interface - Clean, simple API without complex configuration or statisticsDefaultCache<K,V>
- Thread-safe implementation featuring:System.identityHashCode()
for better performanceCacheMapAdapter<K,V>
- Backward compatibility adapter for existing Map-based APIs2. Model Object Pooling
Added object pooling for Maven model objects:
ModelObjectProcessor
interface for processing model objectsDefaultModelObjectPool
implementation providing object poolingKey Features
ConcurrentHashMap
and proper synchronizationFiles Changed
Added
api/maven-api-model/src/main/java/org/apache/maven/api/model/ModelObjectProcessor.java
- Object processor interfaceimpl/maven-impl/src/main/java/org/apache/maven/impl/cache/Cache.java
- New cache interfaceimpl/maven-impl/src/main/java/org/apache/maven/impl/cache/DefaultCache.java
- Thread-safe cache implementationimpl/maven-impl/src/main/java/org/apache/maven/impl/cache/CacheMapAdapter.java
- Backward compatibility adapterimpl/maven-impl/src/main/java/org/apache/maven/impl/model/DefaultModelObjectPool.java
- Object pool implementationimpl/maven-impl/src/main/resources/META-INF/services/org.apache.maven.api.model.ModelObjectProcessor
- Service registrationimpl/maven-impl/src/test/java/org/apache/maven/impl/cache/CacheTest.java
- Comprehensive test suiteModified
src/mdo/model.vm
- Integrated object pooling for model classesimpl/maven-impl/src/main/java/org/apache/maven/impl/cache/DefaultRequestCache.java
- Use new cache implementationRemoved
impl/maven-impl/src/main/java/org/apache/maven/impl/cache/SoftIdentityMap.java
- Buggy old implementationimpl/maven-impl/src/test/java/org/apache/maven/impl/cache/SoftIdentityMapTest.java
- Old testsTesting
Comprehensive Test Coverage
9 new cache tests covering:
Verification
mvn install -DskipTests
)Performance Impact
Before
After
Backward Compatibility
This change is fully backward compatible:
CacheMapAdapter
Relationship to #2506
This PR implements the core functionality from #2506 but simplified for Maven 4.0.0:
Ready for review and merge 🚀