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 CodeGen for executable jar #41449

Closed
Show file tree
Hide file tree
Changes from 185 commits
Commits
Show all changes
186 commits
Select commit Hold shift + click to select a range
4446deb
Add DeadCodeAnalyzer
Thushara-Piyasekara Aug 6, 2023
8f59baa
Add dead code detection for functions and anonymous functions
Thushara-Piyasekara Aug 9, 2023
fe80423
Add comments and optimizations
Thushara-Piyasekara Aug 9, 2023
69ab405
Add Dead Code Detection for multiple modules
Thushara-Piyasekara Aug 17, 2023
4b81d66
Merge branch 'ballerina-platform:master' into dce-project
Thushara-Piyasekara Aug 17, 2023
c6f2f37
Merge branch 'ballerina-platform:master' into dce-project
Thushara-Piyasekara Aug 17, 2023
48c8eff
Add function invocation persistence through modifying BIR
Thushara-Piyasekara Sep 13, 2023
22b7f5c
Add deletion of unused top level functions from thin jars
Thushara-Piyasekara Sep 22, 2023
c470d66
Remove ModuleData class. Optimize DeadCodeAnalyzer
Thushara-Piyasekara Sep 26, 2023
a595764
Add comments. Fix certain langlib children not being updated
Thushara-Piyasekara Sep 26, 2023
e0dd9f1
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Sep 26, 2023
a20f735
Add file license signatures and optimizations
Thushara-Piyasekara Sep 26, 2023
5608d22
Minor optimizations
Thushara-Piyasekara Sep 27, 2023
95628fa
Fix certain child functions not being added to parent symbol
Thushara-Piyasekara Sep 27, 2023
defaf7a
Fix certain child functions not being added to parent symbol
Thushara-Piyasekara Sep 27, 2023
a0abba1
Optimize code according to best practices and suggestions
Thushara-Piyasekara Oct 2, 2023
18b3939
Refactor CompilerPhaseRunner
Thushara-Piyasekara Oct 3, 2023
0709ffd
Improve Resource function handling logic
Thushara-Piyasekara Oct 3, 2023
70012d7
Refactor licence and variable declarations
Thushara-Piyasekara Oct 5, 2023
5554b7e
Refactor file separator
Thushara-Piyasekara Oct 5, 2023
e5beb48
Add BIRDeadNodeAnalyzer
Thushara-Piyasekara Oct 12, 2023
b9f9136
Add detection and deletion of unused Type Definitions
Thushara-Piyasekara Oct 18, 2023
5c20bdb
Add optimized Thin JAR object generation
Thushara-Piyasekara Oct 27, 2023
188ca81
Add BIR TypeDefAnalyzer
Thushara-Piyasekara Oct 31, 2023
a9c077a
Add documentation for TypeDefAnalyzer
Thushara-Piyasekara Oct 31, 2023
e00b11b
Add analyzer support for cyclic typeDefs and typeDef function calls
Thushara-Piyasekara Nov 1, 2023
d7c9b67
Refactor the analyzer algorithm
Thushara-Piyasekara Nov 15, 2023
b0fb559
Add interop dependencies white listing
Thushara-Piyasekara Nov 20, 2023
01a3cd3
Merge with master
Thushara-Piyasekara Nov 20, 2023
42f882c
Fix TypeDefAnalyzer bugs and refactor code
Thushara-Piyasekara Dec 1, 2023
bec52b3
Handle null pointer exceptions in BIRNode.getPackageID
Thushara-Piyasekara Dec 1, 2023
f7c5625
Add new entries for interop-dependencies
Thushara-Piyasekara Dec 1, 2023
925203e
Refactor DeadBIRNodeAnalyzer
Thushara-Piyasekara Dec 1, 2023
e4e21f8
Add unused module elimination
Thushara-Piyasekara Dec 20, 2023
e727315
Add compilation support for langlibs
Thushara-Piyasekara Dec 20, 2023
51920be
Sync with master
Thushara-Piyasekara Dec 20, 2023
d34b75c
Add RecordDefaultFPLoad instruction optimization support
Thushara-Piyasekara Jan 8, 2024
9e72e0e
Merge branch 'ballerina-platform:master' into dce-project
Thushara-Piyasekara Jan 12, 2024
8c5ae60
Add native bytecode optimizer
Thushara-Piyasekara Jan 22, 2024
8ff9437
Revert langlib compilation
Thushara-Piyasekara Jan 23, 2024
edb1d5d
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Jan 24, 2024
5c6a813
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Feb 1, 2024
42e2b5c
Revert to original PackageID assignment
Thushara-Piyasekara Feb 1, 2024
23bf5c9
Add interop dependencies for ballerina/sql library
Thushara-Piyasekara Feb 2, 2024
a05d921
Add new CLI output for optimized build
Thushara-Piyasekara Feb 2, 2024
468f227
Add condition check for optimized build
Thushara-Piyasekara Feb 2, 2024
da7f9cb
Refactor deprecated analyzer names
Thushara-Piyasekara Feb 2, 2024
005e464
Refactor license signatures for newly added files
Thushara-Piyasekara Feb 2, 2024
1ad3fbd
Add null check for markSelfAndChildrenAsUsed function
Thushara-Piyasekara Feb 6, 2024
cf98615
Add logic for handling whitelisted packages
Thushara-Piyasekara Feb 6, 2024
2c59bcb
Refactor LargeMethodOptimizer
Thushara-Piyasekara Feb 6, 2024
13361ff
Add missed attribute analyzing for BStreamType
Thushara-Piyasekara Feb 6, 2024
010e323
Update interop-dependency version
Thushara-Piyasekara Feb 6, 2024
3362cc3
Add duration reports for codegen optimization
Thushara-Piyasekara Feb 6, 2024
8ef8c03
Refactor JBallerinaBackend
Thushara-Piyasekara Feb 6, 2024
c1dae94
Add reflection and driver class whitelisting
Thushara-Piyasekara Feb 6, 2024
1268c79
Add reflection handling for NativeDependencyOptimizer
Thushara-Piyasekara Feb 6, 2024
70dd025
Improve logic for function pointer handling
Thushara-Piyasekara Feb 6, 2024
e6303fd
Whitelist bal files with interop dependency types
Thushara-Piyasekara Feb 6, 2024
64060b3
Refactor UsedTypeDefAnalyzer function names
Thushara-Piyasekara Feb 6, 2024
7ea07cd
Refactor UsedTypeDefAnalyzer function names
Thushara-Piyasekara Feb 6, 2024
6b6c0f4
Merge branch 'dce-project' of https://github.com/Thushara-Piyasekara/…
Thushara-Piyasekara Feb 6, 2024
7028325
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Feb 6, 2024
d42be9b
Remove deprecated DCE algorithms
Thushara-Piyasekara Feb 6, 2024
d8dca7e
Refactor JBallerinaBackend
Thushara-Piyasekara Feb 7, 2024
66a4db4
Update interop-dependencies.properties
Thushara-Piyasekara Feb 7, 2024
1c55fce
Refactor NativeDependencyOptimizer
Thushara-Piyasekara Feb 8, 2024
f466f7c
Remove unused code in JBallerinaBackend
Thushara-Piyasekara Feb 8, 2024
8bc6b29
Remove unused code
Thushara-Piyasekara Feb 8, 2024
45c1b82
Remove unused code
Thushara-Piyasekara Feb 8, 2024
83d9fc1
Remove unused code and files
Thushara-Piyasekara Feb 8, 2024
7dd2615
Refactor logic for UsedBIRNodeAnalyzer and UsedTypeDefAnalyzer
Thushara-Piyasekara Feb 9, 2024
2d32ad0
Refactor high level logic for CodeGen optimization
Thushara-Piyasekara Feb 14, 2024
55027fb
Update interop-dependencies for latest http package
Thushara-Piyasekara Feb 16, 2024
aad44a0
Change builtin PackageID with parent PackageId
Thushara-Piyasekara Feb 16, 2024
565728c
Update TypeModelTest compatibility for Table types
Thushara-Piyasekara Feb 16, 2024
5a130dc
Add analyzer support for table type
Thushara-Piyasekara Feb 17, 2024
19310df
Add fix for handling multiple reference types for the same parent type
Thushara-Piyasekara Feb 17, 2024
21a02ef
Refactor duplicate code into single functions
Thushara-Piyasekara Feb 20, 2024
ca4f440
Fix review suggestions
Thushara-Piyasekara Feb 20, 2024
f8abff6
Refactor ClassNodeVisitor
Thushara-Piyasekara Feb 20, 2024
8685780
Change bir optimized jar file name
Thushara-Piyasekara Feb 20, 2024
fcf88bc
Fix record default fields containing function pointers not being dete…
Thushara-Piyasekara Feb 20, 2024
0918c07
Restore max memory heap size to original
Thushara-Piyasekara Feb 22, 2024
7578783
Refactor according to review suggestions
Thushara-Piyasekara Feb 26, 2024
a968f3e
Add optimization support for testablePkgs
Thushara-Piyasekara Feb 27, 2024
189fb92
Add bir optimization support for test command
Thushara-Piyasekara Mar 4, 2024
c13b0d8
Fix testablePkg birFunctions not being analyzed
Thushara-Piyasekara Mar 5, 2024
878c50c
Refactor optimized test CLI messages
Thushara-Piyasekara Mar 5, 2024
441e85a
Fix mock functions being labeled as UNUSED
Thushara-Piyasekara Mar 6, 2024
4862435
Add duplicate thin jar generation for testing
Thushara-Piyasekara Mar 14, 2024
74ac27d
Resolve merge conflicts
Thushara-Piyasekara Apr 3, 2024
ee5878c
Add working version of the duplicate codegen
Thushara-Piyasekara Apr 3, 2024
819c694
Add support for $moduleInit() chain invocation
Thushara-Piyasekara Apr 4, 2024
e9e76b2
Refactor _DUPLICATE prefix with _OPTIMIZED
Thushara-Piyasekara Apr 9, 2024
ea13e22
Refactor logic for adding optimized library paths
Thushara-Piyasekara Apr 9, 2024
cbdbf22
Resolve merge conflicts
Thushara-Piyasekara Apr 10, 2024
9fdd241
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Apr 10, 2024
bcf932a
Refactor immutable type optimization
Thushara-Piyasekara Apr 11, 2024
771d601
Merge branch 'dce-project' of https://github.com/Thushara-Piyasekara/…
Thushara-Piyasekara Apr 13, 2024
4644530
Fix checkStyle violations
Thushara-Piyasekara Apr 13, 2024
6f8ad58
Add json report generation for testing
Thushara-Piyasekara Apr 16, 2024
1573406
Fix function pointer types not being analyzed
Thushara-Piyasekara Apr 17, 2024
b26b426
Add bytecode optimization for single file projects
Thushara-Piyasekara Apr 17, 2024
b2fb96d
Fix error types being marked as unused
Thushara-Piyasekara Apr 17, 2024
79a220a
Add SingleFileProject tests
Thushara-Piyasekara Apr 19, 2024
f3ff3e7
Fix FPs not being marked as used in different bbs
Thushara-Piyasekara Apr 22, 2024
5f72553
Fix unused submodules not being optimized
Thushara-Piyasekara Apr 24, 2024
f393348
Add new SingleFileProject test cases
Thushara-Piyasekara Apr 24, 2024
81cd78f
Add initial build project tests
Thushara-Piyasekara May 6, 2024
1d2d0c0
Refactor test resources directory structure
Thushara-Piyasekara May 7, 2024
2fcfa82
Add verbose flag for report generation
Thushara-Piyasekara May 7, 2024
3dce8f0
Add NativeDependencyOptimizationReport generation
Thushara-Piyasekara May 7, 2024
04cee13
Add build project test cases
Thushara-Piyasekara May 8, 2024
8d364fa
Add initial tests for bytecode optimizer
Thushara-Piyasekara May 10, 2024
1069269
Add class compilation for test project native libs
Thushara-Piyasekara May 13, 2024
3ba106d
Add new tests
Thushara-Piyasekara May 13, 2024
71a4c50
Add worker related unit tests
Thushara-Piyasekara May 14, 2024
b2939cf
Add client and listener related unit tests
Thushara-Piyasekara May 15, 2024
37f6180
Add anonymous function usage tests
Thushara-Piyasekara May 15, 2024
dd1e18d
Add licencing headers for tests
Thushara-Piyasekara May 16, 2024
a0ec8d8
Fix wrong package name in unit test expected json
Thushara-Piyasekara May 22, 2024
09a7cbe
Add ExternalDependency white listing
Thushara-Piyasekara May 22, 2024
586711a
Add null check for annotation check
Thushara-Piyasekara May 27, 2024
2f3da76
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara May 27, 2024
0c82b8e
Fix merge conflicts
Thushara-Piyasekara May 27, 2024
e5a6144
Add version independent typedef whitelisting
Thushara-Piyasekara May 27, 2024
d399873
Fix checkstyle violations
Thushara-Piyasekara May 28, 2024
e14fa37
Fix getJarFilePathsRequiredForExecution() overload
Thushara-Piyasekara May 28, 2024
6160a5d
Fix spotbugs violations
Thushara-Piyasekara May 28, 2024
79828e4
Fix spotbugs violations
Thushara-Piyasekara May 28, 2024
fa2644d
Add temporary fix for static field value retention
Thushara-Piyasekara May 29, 2024
62e1173
Add string constants for optimized jar identifier
Thushara-Piyasekara May 31, 2024
042adab
Refactor common dependency identification logic
Thushara-Piyasekara May 31, 2024
c4d9c98
Fix CNF error for optimized testing
Thushara-Piyasekara Jun 2, 2024
bcb7b14
Fix testable pkg dependencies being optimized
Thushara-Piyasekara Jun 2, 2024
7a6aba7
Fix optimized jars not being added to classpath
Thushara-Piyasekara Jun 3, 2024
e4e0670
Add temporary fix for test imports being optimized
Thushara-Piyasekara Jun 3, 2024
c3ed36e
Fix checkstyle violations
Thushara-Piyasekara Jun 3, 2024
0443dc3
Fix spotbugs violations
Thushara-Piyasekara Jun 3, 2024
591d916
Fix spotbugs violations
Thushara-Piyasekara Jun 3, 2024
c812e40
Add missing headers and javadoc comments
Thushara-Piyasekara Jun 3, 2024
244389f
Refactor according to review suggestions
Thushara-Piyasekara Jun 4, 2024
63f94e5
Update licensing and javadocs
Thushara-Piyasekara Jun 4, 2024
e7341c1
Fix testable pkg analysis affecting optimized JAR
Thushara-Piyasekara Jun 5, 2024
7ac189d
Add constants for String references
Thushara-Piyasekara Jun 5, 2024
48b2df1
Fix review suggestions
Thushara-Piyasekara Jun 6, 2024
aa8254a
Fix review suggestions
Thushara-Piyasekara Jun 6, 2024
b8e47f2
Fix review suggestions
Thushara-Piyasekara Jun 6, 2024
199a5c1
Fix imported global vars not being marked as used
Thushara-Piyasekara Jun 7, 2024
93679cf
Fix review suggestions
Thushara-Piyasekara Jun 7, 2024
348d281
Merge branch 'fix-42367' of https://github.com/Thushara-Piyasekara/ba…
Thushara-Piyasekara Jun 7, 2024
f1253d2
Fix merge conflicts
Thushara-Piyasekara Jun 7, 2024
ad9bfc4
Fix CheckStyle violations
Thushara-Piyasekara Jun 7, 2024
d8e6c2c
Fix NativeDependencyOptimizationTests failure
Thushara-Piyasekara Jun 10, 2024
da8a75f
Fix NativeDependencyOptimizationTests failure
Thushara-Piyasekara Jun 11, 2024
dcdf514
Fix checkstyle violations
Thushara-Piyasekara Jun 11, 2024
9996ad2
Fix review suggestions
Thushara-Piyasekara Jun 11, 2024
a944fe9
Add --verbose flag usage validation
Thushara-Piyasekara Jun 12, 2024
d5b3c1a
Add jacoco for NativeDependencyOptimizationTests
Thushara-Piyasekara Jun 12, 2024
1404541
Remove CLI optimization report emitter
Thushara-Piyasekara Jun 13, 2024
75a2ccc
Add tests for optimized test suite execution
Thushara-Piyasekara Jun 13, 2024
f2db0cb
Add unix output for OptimizedExecutableTestingTest
Thushara-Piyasekara Jun 14, 2024
1a166f6
Refactor "verbose" flag to "optimize-report"
Thushara-Piyasekara Jun 14, 2024
0090712
Fix review suggestions
Thushara-Piyasekara Jun 14, 2024
c4d7a21
Add conditional init for optimizer related fields
Thushara-Piyasekara Jun 14, 2024
39e2712
Add optimize flag validation for JarResolver
Thushara-Piyasekara Jun 14, 2024
6613f81
Add optimize flag validation for jar packing
Thushara-Piyasekara Jun 14, 2024
6c2a0bb
Refactor common dependency marking logic for tests
Thushara-Piyasekara Jun 17, 2024
52e8654
Refactor unusedPackageID variable names
Thushara-Piyasekara Jun 17, 2024
39f77f3
Make CodeGenOptimizationReportEmitter singleton
Thushara-Piyasekara Jun 17, 2024
c2811f5
Refactor optimization report path resolving logic
Thushara-Piyasekara Jun 19, 2024
faf3d74
Fix merge conflicts
Thushara-Piyasekara Jun 19, 2024
f1840d7
Fix review suggestions
Thushara-Piyasekara Jun 20, 2024
7a9bcba
Fix review suggestions
Thushara-Piyasekara Jun 24, 2024
b77a625
Fix review suggestions
Thushara-Piyasekara Jun 24, 2024
305ac9a
Merge branch 'master' of https://github.com/ballerina-platform/baller…
Thushara-Piyasekara Jun 24, 2024
4dd18cd
Move static compilation options to the builder
Thushara-Piyasekara Jun 25, 2024
808143a
Fix review suggestions
Thushara-Piyasekara Jun 25, 2024
ca52755
Use reflection to reset static fields in unit test
Thushara-Piyasekara Jun 25, 2024
4adf6aa
Fix review suggestions
Thushara-Piyasekara Jun 26, 2024
1c1deb1
Fix CheckStyle violations
Thushara-Piyasekara Jun 26, 2024
35878b7
Fix used submodules being marked as unused
Thushara-Piyasekara Jun 26, 2024
c8c56ff
Fix review suggestions
Thushara-Piyasekara Jun 26, 2024
4135956
Fix checkStyle violations
Thushara-Piyasekara Jun 27, 2024
eb164e9
Fix review suggestions
Thushara-Piyasekara Jun 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ public BuildCommand() {
"generation")
private String graalVMBuildOptions;

@CommandLine.Option(names = "--optimize", description = "generate optimized executable jar", defaultValue = "false")
private Boolean optimizeCodegen;

@CommandLine.Option(names = "--optimize-report", description = "generate code generation optimization reports",
defaultValue = "false")
private Boolean optimizeReport;

@Override
public void execute() {
long start = 0;
Expand Down Expand Up @@ -283,8 +290,8 @@ public void execute() {
// resolve maven dependencies in Ballerina.toml
.addTask(new ResolveMavenDependenciesTask(outStream))
// compile the modules
.addTask(new CompileTask(outStream, errStream, false, true,
isPackageModified, buildOptions.enableCache()))
.addTask(new CompileTask(outStream, errStream, false, true, false, isPackageModified,
buildOptions.enableCache()))
.addTask(new CreateExecutableTask(outStream, this.output, null, false))
.addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime())
.build();
Expand Down Expand Up @@ -317,7 +324,9 @@ private BuildOptions constructBuildOptions() {
.setNativeImage(nativeImage)
.disableSyntaxTreeCaching(disableSyntaxTreeCaching)
.setGraalVMBuildOptions(graalVMBuildOptions)
.setShowDependencyDiagnostics(showDependencyDiagnostics);
.setShowDependencyDiagnostics(showDependencyDiagnostics)
.setOptimizeCodegen(optimizeCodegen)
.setOptimizeReport(optimizeReport);

if (targetDir != null) {
buildOptionsBuilder.targetDir(targetDir.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ public void execute() {
.addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild)
.addTask(new RunBuildToolsTask(outStream), isSingleFileBuild)
.addTask(new ResolveMavenDependenciesTask(outStream))
.addTask(new CompileTask(outStream, errStream, true, false,
isPackageModified, buildOptions.enableCache()))
.addTask(new CompileTask(outStream, errStream, true, false, false, isPackageModified,
buildOptions.enableCache()))
.addTask(new CreateBalaTask(outStream))
.addTask(new DumpBuildTimeTask(outStream), !project.buildOptions().dumpBuildTime())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ private TaskExecutor createTaskExecutor(boolean isPackageModified, String[] args
.addTask(new CleanTargetDirTask(isPackageModified, buildOptions.enableCache()), isSingleFileBuild)
.addTask(new RunBuildToolsTask(outStream), isSingleFileBuild)
.addTask(new ResolveMavenDependenciesTask(outStream))
.addTask(new CompileTask(outStream, errStream, false, false, isPackageModified,
.addTask(new CompileTask(outStream, errStream, false, false, false, isPackageModified,
buildOptions.enableCache()))
.addTask(new CreateExecutableTask(outStream, null, null, false), false)
.addTask(new DumpBuildTimeTask(outStream), false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ public void execute() {
// resolve maven dependencies in Ballerina.toml
.addTask(new ResolveMavenDependenciesTask(outStream))
// compile the modules
.addTask(new CompileTask(outStream, errStream, false, false,
isPackageModified, buildOptions.enableCache()))
.addTask(new CompileTask(outStream, errStream, false, false, false, isPackageModified,
buildOptions.enableCache()))
// .addTask(new CopyResourcesTask(), isSingleFileBuild)
.addTask(new CreateExecutableTask(outStream, null, target, true))
.addTask(new RunExecutableTask(args, outStream, errStream, target))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@ public TestCommand() {
@CommandLine.Option(names = "--cloud", description = "Enable cloud artifact generation")
private String cloud;

@CommandLine.Option(names = "--optimize", description = "generate optimized executable jar", defaultValue = "false")
private Boolean optimizeCodegen;

@CommandLine.Option(names = "--optimize-report", description = "generate code generation optimization reports",
defaultValue = "false")
private Boolean optimizeReport;

private static final String testCmd = "bal test [--OPTIONS]\n" +
" [<ballerina-file> | <package-path>] [(-Ckey=value)...]";
Expand Down Expand Up @@ -374,8 +380,8 @@ public void execute() {
TaskExecutor taskExecutor = new TaskExecutor.TaskBuilder()
.addTask(new ResolveMavenDependenciesTask(outStream)) // resolve maven dependencies in Ballerina.toml
// compile the modules
.addTask(new CompileTask(outStream, errStream, false, false,
isPackageModified, buildOptions.enableCache()))
.addTask(new CompileTask(outStream, errStream, false, false, true, isPackageModified,
buildOptions.enableCache()))
// .addTask(new CopyResourcesTask(), listGroups) // merged with CreateJarTask
.addTask(new CreateTestExecutableTask(outStream, groupList, disableGroupList, testList, listGroups,
cliArgs, isParallelExecution),
Expand Down Expand Up @@ -415,7 +421,9 @@ private BuildOptions constructBuildOptions() {
.setEnableCache(enableCache)
.disableSyntaxTreeCaching(disableSyntaxTreeCaching)
.setGraalVMBuildOptions(graalVMBuildOptions)
.setShowDependencyDiagnostics(showDependencyDiagnostics);
.setShowDependencyDiagnostics(showDependencyDiagnostics)
.setOptimizeCodegen(optimizeCodegen)
.setOptimizeReport(optimizeReport);

if (targetDir != null) {
buildOptionsBuilder.targetDir(targetDir.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package io.ballerina.cli.task;

import io.ballerina.cli.utils.BuildTime;
import io.ballerina.projects.BuildOptions;
import io.ballerina.projects.CodeGeneratorResult;
import io.ballerina.projects.CodeModifierResult;
import io.ballerina.projects.JBallerinaBackend;
Expand Down Expand Up @@ -64,23 +65,26 @@ public class CompileTask implements Task {
private final transient PrintStream err;
private final boolean compileForBalPack;
private final boolean compileForBalBuild;
private final boolean compileForBalTest;
private final boolean isPackageModified;
private final boolean cachesEnabled;

public CompileTask(PrintStream out, PrintStream err) {
this(out, err, false, false, true, false);
this(out, err, false, false, false, true, false);
}

public CompileTask(PrintStream out,
PrintStream err,
boolean compileForBalPack,
boolean compileForBalBuild,
boolean compileForBalTest,
boolean isPackageModified,
boolean cachesEnabled) {
this.out = out;
this.err = err;
this.compileForBalPack = compileForBalPack;
this.compileForBalBuild = compileForBalBuild;
this.compileForBalTest = compileForBalTest;
this.isPackageModified = isPackageModified;
this.cachesEnabled = cachesEnabled;
}
Expand Down Expand Up @@ -112,6 +116,10 @@ public void execute(Project project) {
if (this.compileForBalBuild) {
addDiagnosticForProvidedPlatformLibs(project, diagnostics);
}
if (this.compileForBalBuild || this.compileForBalTest) {
addDiagnosticForInvalidOptimizeReportFlagUsage(project, diagnostics);
}

long start = 0;

if (project.currentPackage().compilationOptions().dumpGraph()
Expand Down Expand Up @@ -329,6 +337,17 @@ private void addDiagnosticForProvidedPlatformLibs(Project project, List<Diagnost
}
}

private void addDiagnosticForInvalidOptimizeReportFlagUsage(Project project, List<Diagnostic> diagnostics) {
BuildOptions buildOptions = project.buildOptions();
if (buildOptions.optimizeReport() && !buildOptions.optimizeCodegen()) {
DiagnosticInfo diagnosticInfo = new DiagnosticInfo(
ProjectDiagnosticErrorCode.INVALID_VERBOSE_FLAG_USAGE.diagnosticId(),
"--optimize-report flag can only be used with --optimize flag", DiagnosticSeverity.ERROR);
diagnostics.add(new PackageDiagnostic(diagnosticInfo,
project.currentPackage().descriptor().name().toString()));
}
}

/**
* If CompileTask is triggered by `bal pack` command, and project does not have CompilerPlugin.toml or BalTool.toml,
* skip the compilation if project is empty. The project should be evaluated for emptiness before calling this.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import static io.ballerina.cli.launcher.LauncherUtils.createLauncherException;
import static io.ballerina.cli.utils.FileUtils.getFileNameWithoutExtension;
import static io.ballerina.projects.util.ProjectConstants.BLANG_COMPILED_JAR_EXT;
import static io.ballerina.projects.util.ProjectConstants.BYTECODE_OPTIMIZED_JAR_SUFFIX;
import static io.ballerina.projects.util.ProjectConstants.USER_DIR;

/**
Expand Down Expand Up @@ -93,6 +94,8 @@ public void execute(Project project) {
out.println(warnings);
}
emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.GRAAL_EXEC, executablePath);
} else if (project.buildOptions().optimizeCodegen()) {
emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.OPTIMIZE_CODEGEN, executablePath);
} else {
emitResult = jBallerinaBackend.emit(JBallerinaBackend.OutputType.EXEC, executablePath);
}
Expand All @@ -119,7 +122,7 @@ public void execute(Project project) {
throw createLauncherException(e.getMessage());
}

if (!project.buildOptions().nativeImage() && !isHideTaskOutput) {
if (!project.buildOptions().nativeImage() && !isHideTaskOutput && !project.buildOptions().optimizeCodegen()) {
Path relativePathToExecutable = currentDir.relativize(executablePath);

if (project.buildOptions().getTargetPath() != null) {
Expand All @@ -134,6 +137,25 @@ public void execute(Project project) {
}
}

if (project.buildOptions().optimizeCodegen()) {
Path relativePathToExecutable = currentDir.relativize(executablePath);
String relativePathToExecutableString =
relativePathToExecutable.toString().replace(BLANG_COMPILED_JAR_EXT, BYTECODE_OPTIMIZED_JAR_SUFFIX);
String executablePathString =
executablePath.toString().replace(BLANG_COMPILED_JAR_EXT, BYTECODE_OPTIMIZED_JAR_SUFFIX);

if (project.buildOptions().getTargetPath() != null) {
this.out.println("\t" + relativePathToExecutableString);
} else {
if (relativePathToExecutableString.contains("..")
|| relativePathToExecutableString.contains("." + File.separator)) {
this.out.println("\t" + executablePathString);
} else {
this.out.println("\t" + relativePathToExecutableString);
}
}
}

// notify plugin
// todo following call has to be refactored after introducing new plugin architecture
BuildUtils.notifyPlugins(project, target);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,3 @@ private void runGeneratedExecutable(Project project) {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public static String getClassPath(JBallerinaBackend jBallerinaBackend, Package c

List<Path> jarList = getModuleJarPaths(jBallerinaBackend, currentPackage);
dependencies.removeAll(jarList);
dependencies.removeAll(jarResolver.optimizedJarLibraryPaths);

StringJoiner classPath = joinClassPaths(dependencies);
return classPath.toString();
Expand Down
2 changes: 2 additions & 0 deletions compiler/ballerina-lang/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ dependencies {
implementation "org.apache.commons:commons-compress:${project.apacheCommonsCompressVersion}"
implementation 'io.netty:netty-buffer'
implementation 'org.ow2.asm:asm'
implementation "org.ow2.asm:asm-tree:${project.ow2AsmTreeVersion}"
implementation 'commons-io:commons-io'
implementation 'com.github.zafarkhaja:java-semver'
testImplementation ("guru.nidi:graphviz-java") {
Expand Down Expand Up @@ -71,6 +72,7 @@ processResources {
include 'ballerina-toml-schema.json'
include 'compiler.properties'
include 'dependencies-toml-schema.json'
include 'interop-dependencies.properties'
include 'old-dependencies-toml-schema.json'
include 'settings-toml-schema.json'
include 'bal-tools-toml-schema.json'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,14 @@ public boolean showDependencyDiagnostics() {
return toBooleanDefaultIfNull(this.showDependencyDiagnostics);
}

public boolean optimizeCodegen() {
return this.compilationOptions.optimizeCodegen();
}

public boolean optimizeReport() {
return this.compilationOptions.optimizeReport();
}

/**
* Merge the given build options by favoring theirs if there are conflicts.
*
Expand Down Expand Up @@ -211,6 +219,8 @@ public BuildOptions acceptTheirs(BuildOptions theirOptions) {
buildOptionsBuilder.setExportOpenAPI(compilationOptions.exportOpenAPI);
buildOptionsBuilder.setExportComponentModel(compilationOptions.exportComponentModel);
buildOptionsBuilder.setEnableCache(compilationOptions.enableCache);
buildOptionsBuilder.setOptimizeCodegen(compilationOptions.optimizeCodegen);
buildOptionsBuilder.setOptimizeReport(compilationOptions.optimizeReport);
Thushara-Piyasekara marked this conversation as resolved.
Show resolved Hide resolved
buildOptionsBuilder.setRemoteManagement(compilationOptions.remoteManagement);

return buildOptionsBuilder.build();
Expand Down Expand Up @@ -250,7 +260,9 @@ public enum OptionName {
NATIVE_IMAGE("graalvm"),
EXPORT_COMPONENT_MODEL("exportComponentModel"),
GRAAL_VM_BUILD_OPTIONS("graalvmBuildOptions"),
SHOW_DEPENDENCY_DIAGNOSTICS("showDependencyDiagnostics");
SHOW_DEPENDENCY_DIAGNOSTICS("showDependencyDiagnostics"),
OPTIMIZE_CODEGEN("optimizeCodegen"),
OPTIMIZE_REPORT("optimizeReport");

private final String name;

Expand Down Expand Up @@ -406,11 +418,21 @@ public BuildOptionsBuilder setNativeImage(Boolean value) {
return this;
}

public BuildOptionsBuilder setOptimizeCodegen(Boolean value) {
compilationOptionsBuilder.setOptimizeCodegen(value);
return this;
}

public BuildOptionsBuilder setRemoteManagement(Boolean value) {
compilationOptionsBuilder.setRemoteManagement(value);
return this;
}

public BuildOptionsBuilder setOptimizeReport(Boolean value) {
compilationOptionsBuilder.setOptimizeReport(value);
return this;
}

public BuildOptionsBuilder setShowDependencyDiagnostics(Boolean value) {
showDependencyDiagnostics = value;
return this;
Expand Down
Loading
Loading