You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by cs...@apache.org on 2022/04/12 16:44:20 UTC
[maven-resolver] branch MRESOLVER-250-weakref-descriptors created (now a614d46d)
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a change to branch MRESOLVER-250-weakref-descriptors
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
at a614d46d [MRESOLVER-250] Wrap descriptors into weak refs
This branch includes the following new commits:
new a614d46d [MRESOLVER-250] Wrap descriptors into weak refs
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[maven-resolver] 01/01: [MRESOLVER-250] Wrap descriptors into weak refs
Posted by cs...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
cstamas pushed a commit to branch MRESOLVER-250-weakref-descriptors
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git
commit a614d46d0320cd02c2d1b22b72658fe6d2689070
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Tue Apr 12 18:43:37 2022 +0200
[MRESOLVER-250] Wrap descriptors into weak refs
Yet to be proven the memory usage change.
---
.../org/eclipse/aether/internal/impl/collect/DataPool.java | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
index 04ebdf41..a9f5aa86 100644
--- a/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
+++ b/maven-resolver-impl/src/main/java/org/eclipse/aether/internal/impl/collect/DataPool.java
@@ -19,6 +19,7 @@ package org.eclipse.aether.internal.impl.collect;
* under the License.
*/
+import java.lang.ref.WeakReference;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
@@ -66,7 +67,7 @@ public final class DataPool
private ObjectPool<Dependency> dependencies;
- private Map<Object, Descriptor> descriptors;
+ private Map<Object, WeakReference<Descriptor>> descriptors;
private final Map<Object, Constraint> constraints = new HashMap<>();
@@ -81,7 +82,7 @@ public final class DataPool
{
artifacts = (ObjectPool<Artifact>) cache.get( session, ARTIFACT_POOL );
dependencies = (ObjectPool<Dependency>) cache.get( session, DEPENDENCY_POOL );
- descriptors = (Map<Object, Descriptor>) cache.get( session, DESCRIPTORS );
+ descriptors = (Map<Object, WeakReference<Descriptor>>) cache.get( session, DESCRIPTORS );
}
if ( artifacts == null )
@@ -129,7 +130,8 @@ public final class DataPool
public ArtifactDescriptorResult getDescriptor( Object key, ArtifactDescriptorRequest request )
{
- Descriptor descriptor = descriptors.get( key );
+ WeakReference<Descriptor> descriptorRef = descriptors.get( key );
+ Descriptor descriptor = descriptorRef != null ? descriptorRef.get() : null;
if ( descriptor != null )
{
return descriptor.toResult( request );
@@ -139,12 +141,12 @@ public final class DataPool
public void putDescriptor( Object key, ArtifactDescriptorResult result )
{
- descriptors.put( key, new GoodDescriptor( result ) );
+ descriptors.put( key, new WeakReference<>( new GoodDescriptor( result ) ) );
}
public void putDescriptor( Object key, ArtifactDescriptorException e )
{
- descriptors.put( key, BadDescriptor.INSTANCE );
+ descriptors.put( key, new WeakReference<>( BadDescriptor.INSTANCE ) );
}
public Object toKey( VersionRangeRequest request )