-
Notifications
You must be signed in to change notification settings - Fork 754
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
// 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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
continue; | ||||||
} | ||||||
} | ||||||
|
||||||
PlatformLibrary generatedJarLibrary = jBalBackend.codeGeneratedLibrary( | ||||||
|
@@ -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)); | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.