Skip to content

Commit

Permalink
Fix to match master
Browse files Browse the repository at this point in the history
  • Loading branch information
heshanpadmasiri committed Oct 6, 2024
1 parent e8f9410 commit 518e6bd
Show file tree
Hide file tree
Showing 23 changed files with 162 additions and 236 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public void execute(Project project) {
}
}

// TODO: this has lot of common code with default case, refactor to common method
if (project.buildOptions().optimizeCodegen()) {
Path relativePathToExecutable = currentDir.relativize(executablePath);
String relativePathToExecutableString =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public enum OptionName {
EXPORT_COMPONENT_MODEL("exportComponentModel"),
GRAAL_VM_BUILD_OPTIONS("graalvmBuildOptions"),
SHOW_DEPENDENCY_DIAGNOSTICS("showDependencyDiagnostics"),
OPTIMIZE_DEPENDENCY_COMPILATION("optimizeDependencyCompilation");
OPTIMIZE_DEPENDENCY_COMPILATION("optimizeDependencyCompilation"),
OPTIMIZE_CODEGEN("optimizeCodegen"),
OPTIMIZE_REPORT("optimizeReport");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/**
* Emits time durations and optimized node details for codegen optimization.
*
* @since 2201.10.0
* @since 2201.11.0
*/
public final class CodeGenOptimizationReportEmitter {

Expand All @@ -70,7 +70,7 @@ public static CodeGenOptimizationReportEmitter getInstance(CompilerContext compi
return codegenOptimizationReportEmitter;
}

protected void flipBirOptimizationTimer(PackageID pkgId) {
void flipBirOptimizationTimer(PackageID pkgId) {
long currentTime = System.currentTimeMillis();
if (this.birOptimizationDurations.containsKey(pkgId)) {
long totalDuration = currentTime - this.birOptimizationDurations.get(pkgId);
Expand All @@ -80,46 +80,47 @@ protected void flipBirOptimizationTimer(PackageID pkgId) {
}
}

protected void flipNativeOptimizationTimer() {
void flipNativeOptimizationTimer() {
if (this.nativeOptimizationDuration == 0) {
this.nativeOptimizationDuration = System.currentTimeMillis();
} else {
this.nativeOptimizationDuration = System.currentTimeMillis() - this.nativeOptimizationDuration;
}
}

protected void emitBirOptimizationDuration() {
void emitBirOptimizationDuration() {
long totalDuration = this.birOptimizationDurations.values().stream().mapToLong(Long::longValue).sum();
this.out.printf("Duration for unused BIR node analysis : %dms%n", totalDuration);
this.birOptimizationDurations.forEach((key, value) -> this.out.printf(" %s : %dms%n", key, value));
this.out.println();
}

protected void emitNativeOptimizationDuration() {
void emitNativeOptimizationDuration() {
this.out.println(
"Duration for Bytecode optimization (analysis + deletion) : " + this.nativeOptimizationDuration + "ms");
this.nativeOptimizationDuration = 0;
}

protected void emitOptimizedExecutableSize(Path executableFilePath) {
void emitOptimizedExecutableSize(Path executableFilePath) {
float optimizedJarSize;
try {
float optimizedJarSize = Files.size(executableFilePath) / (1024f * 1024f);
System.out.printf("Optimized file size : %f MB%n", optimizedJarSize);
optimizedJarSize = Files.size(executableFilePath) / (1024f * 1024f);
} catch (IOException e) {
throw new ProjectException("Failed to emit optimized executable size ", e);
}
System.out.printf("Optimized file size : %f MB%n", optimizedJarSize);
}

protected void emitCodegenOptimizationReport(Map<PackageID, UsedBIRNodeAnalyzer.InvocationData> invocationDataMap,
Path targetDirectoryPath) {
void emitCodegenOptimizationReport(Map<PackageID, UsedBIRNodeAnalyzer.InvocationData> invocationDataMap,
Path targetDirectoryPath) {
if (!Files.exists(targetDirectoryPath)) {
try {
Files.createDirectories(targetDirectoryPath);
} catch (IOException e) {
throw new ProjectException("Failed to create optimization report directory ", e);
}
}

// We are need to preserve the insertion order here since we use reports in tests.
Map<String, CodegenOptimizationReport> reports = new LinkedHashMap<>(invocationDataMap.size());
invocationDataMap.forEach((key, value) -> reports.put(key.toString(), getCodegenOptimizationReport(value)));
Path jsonFilePath = targetDirectoryPath.resolve(CODEGEN_OPTIMIZATION_REPORT);
Expand All @@ -134,8 +135,7 @@ protected void emitCodegenOptimizationReport(Map<PackageID, UsedBIRNodeAnalyzer.
}
}

private CodegenOptimizationReport getCodegenOptimizationReport(
UsedBIRNodeAnalyzer.InvocationData invocationData) {
private CodegenOptimizationReport getCodegenOptimizationReport(UsedBIRNodeAnalyzer.InvocationData invocationData) {
return new CodegenOptimizationReport(getFunctionNames(invocationData.usedFunctions),
getFunctionNames(invocationData.unusedFunctions), getTypeDefNames(invocationData.usedTypeDefs),
getTypeDefNames(invocationData.unusedTypeDefs), invocationData.usedNativeClassPaths);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,16 @@
/**
* Java record used to store codegen optimization report data to JSON.
*
* @param usedFunctionNames used BIR functions identified by the UsedBIRNodeAnalyzer
* @param unusedFunctionNames unused BIR functions identified by the UsedBIRNodeAnalyzer
* @param usedTypeDefNames used BIR type definitions identified by the UsedBIRNodeAnalyzer
* @param unusedTypeDefNames unused BIR type definitions identified by the UsedBIRNodeAnalyzer
* @param usedFunctionNames used BIR functions identified by the UsedBIRNodeAnalyzer
* @param unusedFunctionNames unused BIR functions identified by the UsedBIRNodeAnalyzer
* @param usedTypeDefNames used BIR type definitions identified by the UsedBIRNodeAnalyzer
* @param unusedTypeDefNames unused BIR type definitions identified by the UsedBIRNodeAnalyzer
* @param usedNativeClassPaths native class paths used by external functions
*
* @since 2201.10.0
* @since 2201.11.0
*/
record CodegenOptimizationReport(FunctionNames usedFunctionNames, FunctionNames unusedFunctionNames,
TypeDefinitions usedTypeDefNames, TypeDefinitions unusedTypeDefNames,
Set<String> usedNativeClassPaths) {
TypeDefinitions usedTypeDefNames, TypeDefinitions unusedTypeDefNames,
Set<String> usedNativeClassPaths) {

/**
* @param sourceFunctions BIR functions directly derived from source
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,22 @@ public class CompilationOptions {
Boolean optimizeDependencyCompilation;
Boolean optimizeCodegen;
Boolean optimizeReport;

private CompilationOptions(Boolean offlineBuild, Boolean observabilityIncluded, Boolean dumpBir,
Boolean dumpBirFile, String cloud, Boolean listConflictedClasses, Boolean sticky,
Boolean dumpGraph, Boolean dumpRawGraphs, Boolean withCodeGenerators,
Boolean withCodeModifiers, Boolean configSchemaGen, Boolean exportOpenAPI,
Boolean exportComponentModel, Boolean enableCache, Boolean disableSyntaxTree,
Boolean remoteManagement, Boolean optimizeDependencyCompilation,
Boolean optimizeCodegen, Boolean optimizeReport) {
this.offlineBuild = offlineBuild;
this.observabilityIncluded = observabilityIncluded;
this.dumpBir = dumpBir;
this.dumpBirFile = dumpBirFile;
this.cloud = cloud;
this.listConflictedClasses = listConflictedClasses;
this.sticky = sticky;
this.dumpGraph = dumpGraph;
this.dumpRawGraphs = dumpRawGraphs;
this.withCodeGenerators = withCodeGenerators;
this.withCodeModifiers = withCodeModifiers;
this.configSchemaGen = configSchemaGen;
Expand Down
Loading

0 comments on commit 518e6bd

Please sign in to comment.