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

Fix thin jar caching when testing the optimized executable #43582

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 @@ -161,12 +161,20 @@ private void addCodeGeneratedLibraryPaths(PackageContext packageContext, Platfor
}
ModuleContext moduleContext = packageContext.moduleContext(moduleId);
PackageID pkgID = moduleContext.descriptor().moduleCompilationId();
// DuplicatePkgs are pkgs which are imported by both testable and build projects.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// DuplicatePkgs are pkgs which are imported by both testable and build projects.
// Duplicate pkgs are pkgs which are imported by both testable and build projects.

// We need a different category for those to avoid false positive test passes.
boolean isDuplicatePkg = JvmCodeGenUtil.duplicatePkgsMap.containsKey(pkgID.orgName +
pkgID.getNameComps().toString());

// TODO: extract this condition out
if (packageContext.project().buildOptions().eliminateDeadCode() &&
!this.rootPackageContext.project().buildOptions().skipTests() &&
this.jBalBackend.getOptimizedPackageIDs().contains(pkgID)) {
addOptimizedLibraryPaths(packageContext, scope, libraryPaths, moduleContext, pkgID);
addOptimizedLibraryPaths(packageContext, scope, libraryPaths, moduleContext, isDuplicatePkg);
if (!isDuplicatePkg) {
// If the pkg is not an duplicate pkg, we only need the optimized thin JAR.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// If the pkg is not an duplicate pkg, we only need the optimized thin JAR.
// If the pkg is not a duplicate pkg, we only need the optimized thin JAR.

continue;
}
}

PlatformLibrary generatedJarLibrary = jBalBackend.codeGeneratedLibrary(
Expand All @@ -177,14 +185,12 @@ private void addCodeGeneratedLibraryPaths(PackageContext packageContext, Platfor

private void addOptimizedLibraryPaths(PackageContext packageContext, PlatformLibraryScope scope,
Set<JarLibrary> libraryPaths, ModuleContext moduleContext,
PackageID pkgID) {
boolean isDuplicatePkg) {
PlatformLibrary generatedOptimizedLibrary = jBalBackend.codeGeneratedOptimizedLibrary(
packageContext.packageId(), moduleContext.moduleName());
Path optimizedJarLibraryPath = generatedOptimizedLibrary.path().toAbsolutePath();

if (JvmCodeGenUtil.duplicatePkgsMap.containsKey(pkgID.orgName + pkgID.getNameComps().toString())) {
// Package is an optimized duplicated pkg.
// This means the package is a common dependency of both testable and build projects.
if (isDuplicatePkg) {
optimizedJarLibraryPath =
Path.of(optimizedJarLibraryPath.toString().replace(ProjectConstants.BLANG_COMPILED_JAR_EXT,
ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,22 @@ public void cacheBir(ModuleName moduleName, ByteArrayOutputStream birContent) {
public Optional<Path> getPlatformSpecificLibrary(CompilerBackend compilerBackend, String libraryName,
boolean isOptimizedLibrary) {
String libraryFileName = libraryName + compilerBackend.libraryFileExtension();
Path targetPlatformCacheDirPath = isOptimizedLibrary ? getOptimizedTargetPlatformCacheDirPath(compilerBackend) :
getTargetPlatformCacheDirPath(compilerBackend);
Path jarFilePath = targetPlatformCacheDirPath.resolve(libraryFileName);
return Files.exists(jarFilePath) ? Optional.of(jarFilePath) : Optional.empty();
Path optimizedJarFilePath = getOptimizedTargetPlatformCacheDirPath(compilerBackend).resolve(libraryFileName);
if (isOptimizedLibrary) {
return Optional.of(optimizedJarFilePath);
}

Path jarFilePath = getTargetPlatformCacheDirPath(compilerBackend).resolve(libraryFileName);
// getPlatformSpecificLibrary gets invoked from TestUtils class and there is no proper way to check whether a
// given module is `optimized`, `unoptimized` or `duplicated optimized`. Maybe we can lift the logic to
// JarResolver somehow.
// TODO Find a cleaner way to handle JarPaths for bal test with dead code elimination.
Copy link
Member

Choose a reason for hiding this comment

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

Let's create an issue for this.

if (Files.exists(jarFilePath)) {
return Optional.of(jarFilePath);
} else if (Files.exists(optimizedJarFilePath)) {
Copy link
Member

Choose a reason for hiding this comment

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

Can be just an if.

return Optional.of(optimizedJarFilePath);
}
Thushara-Piyasekara marked this conversation as resolved.
Show resolved Hide resolved
return Optional.empty();
}

@Override
Expand Down