Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize clearing reloadable flag #26716

Merged
merged 1 commit into from
Jul 14, 2022
Merged
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 @@ -3,7 +3,6 @@
import io.quarkus.bootstrap.BootstrapConstants;
import io.quarkus.bootstrap.resolver.AppModelResolverException;
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.GACTV;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -77,21 +76,19 @@ void addPlatformRelease(String propertyName, String propertyValue) {
}

public void addPlatformDescriptor(String groupId, String artifactId, String classifier, String type, String version) {
final ArtifactCoords bomCoords = new GACTV(groupId,
final ArtifactCoords bomCoords = ArtifactCoords.pom(groupId,
artifactId.substring(0,
artifactId.length() - BootstrapConstants.PLATFORM_DESCRIPTOR_ARTIFACT_ID_SUFFIX.length()),
null, "pom",
version);
platformImports.computeIfAbsent(bomCoords, c -> new PlatformImport()).descriptorFound = true;
platformBoms.add(bomCoords);
}

public void addPlatformProperties(String groupId, String artifactId, String classifier, String type, String version,
Path propsPath) throws AppModelResolverException {
final ArtifactCoords bomCoords = new GACTV(groupId,
final ArtifactCoords bomCoords = ArtifactCoords.pom(groupId,
artifactId.substring(0,
artifactId.length() - BootstrapConstants.PLATFORM_PROPERTIES_ARTIFACT_ID_SUFFIX.length()),
null, "pom",
version);
platformImports.computeIfAbsent(bomCoords, c -> new PlatformImport());
importedPlatformBoms.computeIfAbsent(groupId, g -> new ArrayList<>()).add(bomCoords);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,6 @@ public int getFlags() {
return flags;
}

public void setFlag(int flag) {
flags |= flag;
}

public void clearFlag(int flag) {
if ((flags & flag) > 0) {
flags ^= flag;
}
}

@Override
public int hashCode() {
final int prime = 31;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,25 @@
public interface DependencyFlags {

/* @formatter:off */
public static final int OPTIONAL = 0b00000000001;
public static final int DIRECT = 0b00000000010;
public static final int RUNTIME_CP = 0b00000000100;
public static final int DEPLOYMENT_CP = 0b00000001000;
public static final int RUNTIME_EXTENSION_ARTIFACT = 0b00000010000;
public static final int WORKSPACE_MODULE = 0b00000100000;
public static final int RELOADABLE = 0b00001000000;
public static final int OPTIONAL = 0b000000000001;
public static final int DIRECT = 0b000000000010;
public static final int RUNTIME_CP = 0b000000000100;
public static final int DEPLOYMENT_CP = 0b000000001000;
public static final int RUNTIME_EXTENSION_ARTIFACT = 0b000000010000;
public static final int WORKSPACE_MODULE = 0b000000100000;
public static final int RELOADABLE = 0b000001000000;
// A top-level runtime extension artifact is either a direct
// dependency or a first extension dependency on the branch
// navigating from the root to leaves
public static final int TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT = 0b00010000000;
public static final int CLASSLOADER_PARENT_FIRST = 0b00100000000;
public static final int CLASSLOADER_RUNNER_PARENT_FIRST = 0b01000000000;
public static final int CLASSLOADER_LESSER_PRIORITY = 0b10000000000;
public static final int TOP_LEVEL_RUNTIME_EXTENSION_ARTIFACT = 0b000010000000;
public static final int CLASSLOADER_PARENT_FIRST = 0b000100000000;
public static final int CLASSLOADER_RUNNER_PARENT_FIRST = 0b001000000000;
public static final int CLASSLOADER_LESSER_PRIORITY = 0b010000000000;
// General purpose flag that could be re-used for various
// kinds of processing indicating that a dependency has been
// visited. This flag is meant to be cleared for all the nodes
// once the processing of the whole tree has completed.
public static final int VISITED = 0b100000000000;
/* @formatter:on */

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public static ResolvedDependencyBuilder newInstance() {

PathCollection resolvedPaths;
WorkspaceModule workspaceModule;
private volatile ArtifactCoords coords;

public PathCollection getResolvedPaths() {
return resolvedPaths;
Expand Down Expand Up @@ -40,6 +41,10 @@ public ResolvedDependencyBuilder setWorkspaceModule(WorkspaceModule projectModul
return this;
}

public ArtifactCoords getArtifactCoords() {
return coords == null ? coords = ArtifactCoords.of(groupId, artifactId, classifier, type, version) : coords;
}

@Override
public ResolvedDependency build() {
return new ResolvedArtifactDependency(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import io.quarkus.maven.dependency.ArtifactCoords;
import io.quarkus.maven.dependency.ArtifactKey;
import io.quarkus.maven.dependency.DependencyFlags;
import io.quarkus.maven.dependency.GACTV;
import io.quarkus.maven.dependency.ResolvedDependencyBuilder;
import io.quarkus.paths.PathList;
import io.quarkus.paths.PathTree;
Expand All @@ -25,7 +24,6 @@
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -160,7 +158,7 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver

visitRuntimeDependencies(root.getChildren());

List<ConditionalDependency> activatedConditionalDeps = Collections.emptyList();
List<ConditionalDependency> activatedConditionalDeps = List.of();

if (!conditionalDepsToProcess.isEmpty()) {
activatedConditionalDeps = new ArrayList<>();
Expand Down Expand Up @@ -209,15 +207,16 @@ public void resolve(CollectRequest collectRtDepsRequest) throws AppModelResolver
buildDepsVisitor.visit(root);

if (!CONVERGED_TREE_ONLY && collectReloadableModules) {
final Set<ArtifactKey> visited = new HashSet<>();
for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
if (!db.isFlagSet(DependencyFlags.RELOADABLE)) {
clearReloadableFlag(db, visited);
if (db.isFlagSet(DependencyFlags.RELOADABLE | DependencyFlags.VISITED)) {
continue;
}
clearReloadableFlag(db);
}
}

for (ResolvedDependencyBuilder db : appBuilder.getDependencies()) {
db.clearFlag(DependencyFlags.VISITED);
appBuilder.addDependency(db);
}

Expand All @@ -243,20 +242,19 @@ private void collectPlatformProperties() throws AppModelResolverException {
appBuilder.setPlatformImports(platformReleases);
}

private void clearReloadableFlag(ResolvedDependencyBuilder db, Set<ArtifactKey> visited) {
final GACTV coords = new GACTV(db.getGroupId(), db.getArtifactId(), db.getClassifier(), db.getType(), db.getVersion());
final Set<ArtifactKey> deps = artifactDeps.get(coords);
private void clearReloadableFlag(ResolvedDependencyBuilder db) {
final Set<ArtifactKey> deps = artifactDeps.get(db.getArtifactCoords());
if (deps == null || deps.isEmpty()) {
return;
}
for (ArtifactKey key : deps) {
final ResolvedDependencyBuilder dep = appBuilder.getDependency(key);
if (dep == null || !visited.add(key)) {
if (dep == null || dep.isFlagSet(DependencyFlags.VISITED)) {
continue;
}
dep.setFlags(DependencyFlags.VISITED);
dep.clearFlag(DependencyFlags.RELOADABLE);
clearReloadableFlag(dep, visited);
visited.remove(key);
clearReloadableFlag(dep);
}
}

Expand Down Expand Up @@ -418,7 +416,7 @@ private ExtensionDependency getExtensionDependencyOrNull(DependencyNode node, Ar
}
}
} else {
exclusions = Collections.emptyList();
exclusions = List.of();
}
return new ExtensionDependency(extInfo, node, exclusions);
}
Expand Down