-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Support for AppCDS #5336
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
base: master
Are you sure you want to change the base?
Support for AppCDS #5336
Changes from 1 commit
c815098
6aad554
a8e376f
ef4b437
c55d5c4
6154135
5ed97e1
7599528
7e85ae7
ac1c2e8
34ef580
44330bd
216b85a
9b58449
3f5edad
39abf04
e18e47d
a660def
79437f9
7176c6c
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 |
---|---|---|
@@ -0,0 +1,159 @@ | ||
package org.jetbrains.compose.desktop.application.dsl | ||
|
||
igordmn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import org.jetbrains.compose.internal.utils.packagedAppJarFilesDir | ||
import java.io.File | ||
import java.io.Serializable | ||
|
||
/** | ||
* The configuration of AppCDS for the native distribution. | ||
igordmn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
abstract class AppCdsConfiguration { | ||
/** | ||
* The AppCDS mode to use. | ||
*/ | ||
var mode: AppCdsMode = AppCdsMode.None | ||
|
||
/** | ||
* Whether to ask the JVM to log AppCDS-related actions. | ||
*/ | ||
@Suppress("MemberVisibilityCanBePrivate") | ||
var logging: Boolean = false | ||
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. I would not add it to the DSL. Users are able to add the logging flag by their own if it is needed 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. I wasn't sure as well, but this is a very useful feature, and most developers aren't familiar with AppCDS or its flags. So I think it's worhwhile; it will reduce the amount of questions ("Why doesn't it work for me?", "How do I know whether it works?") asked of us. 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. maybe add it to the javadoc? 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. Nobody reads the javadoc :) 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. I don't agree. We say about the case when user already need to debug something. How will they find the option? 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. 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. When reading the API, without reading the implementation, I had the same questions why we need a separate It also confuses me as an user of the feature, adding more questions than answers: what is the difference with Gradle logging, when I need to set it, etc. I would just add 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. Removed the |
||
|
||
/** | ||
* Returns the AppCDS-related arguments to pass the JVM when running the app. | ||
*/ | ||
internal fun runtimeJvmArgs() = buildList { | ||
m-sasha marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
addAll(mode.runtimeJvmArgs()) | ||
if (logging) add("-Xlog:cds") | ||
} | ||
} | ||
|
||
/** | ||
* The mode of use of AppCDS. | ||
*/ | ||
abstract class AppCdsMode : Serializable { | ||
terrakok marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Whether to generate a classes.jsa archive for the JRE classes. | ||
*/ | ||
internal abstract val generateJreClassesArchive: Boolean | ||
|
||
/** | ||
* Returns whether this mode creates an archive of app classes at build time. | ||
*/ | ||
internal open val generateAppClassesArchive: Boolean get() = false | ||
|
||
/** | ||
* The arguments to pass to the JVM when running the app to create | ||
* the archive for the app's class files. | ||
* | ||
* This will only be called if [generateAppClassesArchive] is `true`. | ||
*/ | ||
internal open fun appClassesArchiveCreationJvmArgs(): List<String> = | ||
error("AppCdsMode '$this' does not create an archive") | ||
|
||
/** | ||
* Returns the app's classes archive file, given the root directory of | ||
* the packaged app. | ||
*/ | ||
internal open fun appClassesArchiveFile(packagedAppRootDir: File): File = | ||
error("AppCdsMode '$this' does not create an archive") | ||
|
||
/** | ||
* The arguments to pass to the JVM when running the final app. | ||
*/ | ||
internal abstract fun runtimeJvmArgs(): List<String> | ||
|
||
/** | ||
* Checks whether this mode is compatible with the given JDK major version. | ||
* Throws an exception if not. | ||
*/ | ||
internal open fun checkJdkCompatibility(jdkMajorVersion: Int) = Unit | ||
|
||
|
||
companion object { | ||
|
||
/** | ||
* The name of the AppCds archive file. | ||
*/ | ||
private const val ARCHIVE_NAME = "app.jsa" | ||
|
||
/** | ||
* AppCDS is not used. | ||
*/ | ||
val None = object : AppCdsMode() { | ||
override val generateJreClassesArchive: Boolean get() = false | ||
override fun runtimeJvmArgs() = emptyList<String>() | ||
override fun toString() = "None" | ||
} | ||
|
||
/** | ||
* AppCDS is used via a dynamic shared archive created automatically | ||
* when the app is run (using `-XX:+AutoCreateSharedArchive`). | ||
* | ||
* Pros: | ||
* - Simplest - no additional step is needed to build the archive. | ||
* - Creates a smaller distributable. | ||
* | ||
* Cons: | ||
* - Requires JDK 19 or later. | ||
* - The archive is not available at the first execution of the app, | ||
* so it is slower. The archive is created when at shutdown time | ||
* of the first execution, which also takes a little longer. | ||
*/ | ||
igordmn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Suppress("unused") | ||
val Auto = object : AppCdsMode() { | ||
private val MIN_JDK_VERSION = 19 | ||
override val generateJreClassesArchive: Boolean get() = true | ||
override fun runtimeJvmArgs() = | ||
listOf( | ||
"-XX:SharedArchiveFile=\$APPDIR/$ARCHIVE_NAME", | ||
"-XX:+AutoCreateSharedArchive" | ||
) | ||
override fun checkJdkCompatibility(jdkMajorVersion: Int) { | ||
if (jdkMajorVersion < MIN_JDK_VERSION) { | ||
error( | ||
"AppCdsMode '$this' is not supported on JDK earlier than" + | ||
" $MIN_JDK_VERSION; current is $jdkMajorVersion" | ||
) | ||
} | ||
} | ||
override fun toString() = "Auto" | ||
} | ||
|
||
/** | ||
* AppCDS is used via a dynamic shared archive created by executing | ||
* the app before packaging (using `-XX:ArchiveClassesAtExit`). | ||
* | ||
* Pros: | ||
* - Can be used with JDKs earlier than 19. | ||
* - The first run of the distributed app is fast too. | ||
* | ||
* Cons: | ||
* - Requires an additional step of running the app when building the | ||
* distributable. | ||
* - The distributable is larger because it includes the archive of | ||
* the app's classes. | ||
*/ | ||
@Suppress("unused") | ||
val Prebuild = object : AppCdsMode() { | ||
override val generateJreClassesArchive: Boolean get() = true | ||
override val generateAppClassesArchive: Boolean get() = true | ||
override fun appClassesArchiveCreationJvmArgs() = | ||
listOf( | ||
"-XX:ArchiveClassesAtExit=\$APPDIR/$ARCHIVE_NAME", | ||
"-Dcompose.cds.create-archive=true" | ||
) | ||
override fun appClassesArchiveFile(packagedAppRootDir: File): File { | ||
val appDir = packagedAppJarFilesDir(packagedAppRootDir) | ||
return appDir.resolve(ARCHIVE_NAME) | ||
} | ||
override fun runtimeJvmArgs() = | ||
listOf( | ||
"-XX:SharedArchiveFile=\$APPDIR/$ARCHIVE_NAME", | ||
) | ||
|
||
override fun toString() = "Prebuild" | ||
} | ||
} | ||
} |
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.
After merging the PR, please close the user PR #2080