Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,8 @@ static final class GraphKey {
this.traverser = traverser;
this.filter = filter;

hashCode = Objects.hash(artifact, repositories, selector, manager, traverser, filter);
hashCode =
Objects.hash(artifact, repositories, selector, System.identityHashCode(manager), traverser, filter);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

identityHashCode is wrong here: what we want in fact is "state" of manager (ie. "same conditions for same artifacts gives same siblings").

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If so, then this pr shall be re-designed.
sigh.
If really wanna keep a state of the manager, then we have to analyze if the hashing process can be splited/re-used, which is very complicated then.

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ public class BfDependencyCollector extends DependencyCollectorDelegate {
public static final String CONFIG_PROP_THREADS = CONFIG_PROPS_PREFIX + "threads";

/**
* The default value for {@link #CONFIG_PROP_THREADS}, default value 5.
* The default value for {@link #CONFIG_PROP_THREADS}, default value {@code Runtime.getRuntime().availableProcessors()}.
*
* @since 1.9.0
*/
public static final int DEFAULT_THREADS = 5;
public static final int DEFAULT_THREADS = Runtime.getRuntime().availableProcessors();

@Inject
public BfDependencyCollector(
Expand Down Expand Up @@ -470,19 +470,28 @@ private ArtifactDescriptorResult resolveDescriptorForVersion(
}

static class ParallelDescriptorResolver implements Closeable {
private final ExecutorService executorService;
private static volatile ExecutorService executorService;

/**
* Artifact ID -> Future of DescriptorResolutionResult
*/
private final Map<String, Future<DescriptorResolutionResult>> results = new ConcurrentHashMap<>(256);

ParallelDescriptorResolver(int threads) {
this.executorService = ExecutorUtils.threadPool(threads, getClass().getSimpleName() + "-");
if (executorService == null) {
synchronized (ParallelDescriptorResolver.class) {
if (executorService == null) {
// create only once, so that we can reuse it across multiple instances of this class
// and avoid creating too many threads / recreating it for too many times
executorService = ExecutorUtils.threadPool(
threads, ParallelDescriptorResolver.class.getSimpleName() + "-");
}
}
}
}

void resolveDescriptors(Artifact artifact, Callable<DescriptorResolutionResult> callable) {
results.computeIfAbsent(ArtifactIdUtils.toId(artifact), key -> this.executorService.submit(callable));
results.computeIfAbsent(ArtifactIdUtils.toId(artifact), key -> executorService.submit(callable));
}

void cacheVersionRangeDescriptor(Artifact artifact, DescriptorResolutionResult resolutionResult) {
Expand All @@ -494,9 +503,7 @@ Future<DescriptorResolutionResult> find(Artifact artifact) {
}

@Override
public void close() {
executorService.shutdown();
}
public void close() {}
}

static class DoneFuture<V> implements Future<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public abstract class AbstractDependencyManager implements DependencyManager {

protected final SystemDependencyScope systemDependencyScope;

private final int hashCode;
private volatile long hashCode = Long.MAX_VALUE;

protected AbstractDependencyManager(int deriveUntil, int applyFrom, ScopeManager scopeManager) {
this(
Expand Down Expand Up @@ -112,16 +112,6 @@ protected AbstractDependencyManager(
this.managedExclusions = requireNonNull(managedExclusions);
// nullable: if using scope manager, but there is no system scope defined
this.systemDependencyScope = systemDependencyScope;

this.hashCode = Objects.hash(
depth,
deriveUntil,
applyFrom,
managedVersions,
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
}

protected abstract DependencyManager newInstance(
Expand Down Expand Up @@ -332,7 +322,20 @@ public boolean equals(Object obj) {

@Override
public int hashCode() {
return hashCode;
if (this.hashCode != Long.MAX_VALUE) {
return (int) hashCode;
}
int result = Objects.hash(
depth,
deriveUntil,
applyFrom,
managedVersions,
managedScopes,
managedOptionals,
managedLocalPaths,
managedExclusions);
this.hashCode = result;
return result;
}

protected static class Key {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,10 @@ public boolean equals(Object o) {
}

private static class DoneMMap<K, V> extends MMap<K, V> {
private final int hashCode;
private volatile long hashCode = Long.MAX_VALUE;

private DoneMMap(HashMap<K, V> delegate) {
super(delegate);
this.hashCode = delegate.hashCode();
}

@Override
Expand All @@ -99,7 +98,12 @@ public MMap<K, V> done() {

@Override
public int hashCode() {
return hashCode;
if (this.hashCode != Long.MAX_VALUE) {
return (int) hashCode;
}
int result = delegate.hashCode();
this.hashCode = result;
return result;
}

@Override
Expand Down