@@ -36,10 +36,16 @@ val Project.toolchainVendor
3636val Project .addModules
3737 get() = libs.versions.java.addModules.get()
3838
39+ val Project .githubUser
40+ get() = libs.versions.dev.name.get().lowercase()
41+
42+ val Project .githubRepo
43+ get() = " https://github.com/${githubUser} /${rootProject.name} "
44+
3945/* *
4046 * Retrieves all JVM arguments for running (**java**) and compiling (**javac**) java/kotlin code..
4147 *
42- * @param compile Flag indicating whether or not to include additional JVM arguments for compilation.
48+ * @param compile Flag indicating whether to include additional JVM arguments for compilation.
4349 * Defaults to false.
4450 * @return A list of JVM arguments for the project.
4551 */
@@ -53,6 +59,120 @@ fun Project.jvmArguments(compile: Boolean = false) = buildList {
5359 }
5460}
5561
62+ // $ java -XX:+UnlockExperimentalVMOptions -XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal
63+ // --version
64+ // https://docs.oracle.com/en/java/javase/21/docs/specs/man/java.html
65+ // https://docs.oracle.com/en/java/javase/21/core/java-networking.html#GUID-E6C82625-7C02-4AB3-B15D-0DF8A249CD73
66+ // https://cs.oswego.edu/dl/jsr166/dist/jsr166.jar
67+ // https://chriswhocodes.com/hotspot_options_openjdk21.html
68+ // https://sap.github.io/SapMachine/jfrevents
69+
70+ val Project .cc get() = listOf (
71+ " --show-version" ,
72+ " --enable-preview" ,
73+ " --add-modules=$addModules " ,
74+ " --enable-native-access=ALL-UNNAMED" ,
75+ " -XshowSettings:vm" ,
76+ " -XshowSettings:system" ,
77+ " -XshowSettings:properties" ,
78+ " -Xmx96M" ,
79+ " -XX:+PrintCommandLineFlags" ,
80+ " -XX:+UseZGC" ,
81+ " -XX:+ZGenerational" ,
82+ " -XX:+UseCompressedOops" ,
83+ " -XX:+UnlockExperimentalVMOptions" ,
84+ // os+thread,gc+heap=trace,
85+ """ -Xlog:cds,safepoint,gc*:
86+ |file="$tmp$name -gc-%p-%t.log":
87+ |level,tags,time,uptime,pid,tid:
88+ |filecount=5,
89+ |filesize=10m"""
90+ .joinToConfigString(),
91+ """ -XX:StartFlightRecording=
92+ |filename=$tmp$name .jfr,
93+ |name=$name ,
94+ |maxsize=100M,
95+ |maxage=1d,
96+ |path-to-gc-roots=true,
97+ |dumponexit=true,
98+ |memory-leaks=gc-roots,
99+ |gc=detailed,
100+ |+jdk.VirtualThreadStart#enabled=true,
101+ |+jdk.VirtualThreadEnd#enabled=true,
102+ |jdk.ObjectCount#enabled=true,
103+ |jdk.SecurityPropertyModification#enabled=true,
104+ |jdk.TLSHandshake#enabled=true,
105+ |jdk.X509Certificate#enabled=true,
106+ |jdk.X509Validation#enabled=true,
107+ |settings=profile"""
108+ .joinToConfigString(),
109+ " -XX:FlightRecorderOptions:stackdepth=64" ,
110+ " -XX:+HeapDumpOnOutOfMemoryError" ,
111+ " -XX:HeapDumpPath=$tmp$name -%p.hprof" ,
112+ " -XX:ErrorFile=$tmp$name -hs-err-%p.log" ,
113+ " -XX:OnOutOfMemoryError='kill -9 %p'" ,
114+ " -XX:+ExitOnOutOfMemoryError" ,
115+ " -XX:+UnlockDiagnosticVMOptions" ,
116+ " -XX:NativeMemoryTracking=detail" ,
117+ " -XX:+EnableDynamicAgentLoading" ,
118+ " -XX:+LogVMOutput" ,
119+ " -XX:LogFile=$tmp$name -jvm.log" ,
120+ " -Djava.awt.headless=true" ,
121+ " -Djdk.attach.allowAttachSelf=true" ,
122+ " -Djdk.traceVirtualThreadLocals=false" ,
123+ " -Djdk.tracePinnedThreads=full" ,
124+ " -Djava.security.debug=properties" ,
125+ " -Djava.security.egd=file:/dev/./urandom" ,
126+ " -Djdk.includeInExceptions=hostInfo,jar" ,
127+ " -Dkotlinx.coroutines.debug" ,
128+ " -ea" ,
129+ // "--show-module-resolution",
130+ // "-XX:+ShowHiddenFrames",
131+ // "-XX:+AutoCreateSharedArchive",
132+ // "-XX:SharedArchiveFile=$tmp/$name.jsa"
133+ // "-verbose:module",
134+ // "-XX:ConcGCThreads=2",
135+ // "-XX:ZUncommitDelay=60",
136+ // "-XX:VMOptionsFile=vm_options",
137+ // "-Xlog:gc\*",
138+ // "-Xlog:class+load=info,cds=debug,cds+dynamic=info",
139+ // "-XX:+IgnoreUnrecognizedVMOptions",
140+ // "-XX:MaxRAMPercentage=0.8",
141+ // "-XX:+StartAttachListener", // For jcmd Dynamic Attach Mechanism
142+ // "-XX:+DisableAttachMechanism",
143+ // "-XX:+DebugNonSafepoints",
144+ // "-XX:OnOutOfMemoryError="./restart.sh"",
145+ // "-XX:SelfDestructTimer=0.05",
146+ // "-XX:NativeMemoryTracking=[off|summary|detail]",
147+ // "-XX:+PrintNMTStatistics",
148+ // "-XX:OnError=\"gdb - %p\"", // Attach gdb on segfault
149+ // "-Djava.security.properties=/path/to/custom/java.security", // == to override
150+ // "-Duser.timezone=\"PST8PDT\"",
151+ // "-Djava.net.preferIPv4Stack=true",
152+ // "-Djavax.net.debug=all",
153+ // "-Dhttps.protocols=TLSv1.2",
154+ // "-Dhttps.agent=$name",
155+ // "-Dhttp.keepAlive=true",
156+ // "-Dhttp.maxConnections=5",
157+ // "-Djava.security.manager=allow",
158+ // "-Dfile.encoding=COMPAT", // uses '-Dnative.encoding'
159+ // "-Djdbc.drivers=org.postgresql.Driver",
160+ // "-Djava.io.tmpdir=/var/data/tmp",
161+ // "-Djava.locale.providers=COMPAT,CLDR",
162+ // "-Djdk.lang.Process.launchMechanism=vfork",
163+ // "-Djdk.tls.maxCertificateChainLength=10",
164+ // "-Djdk.tls.maxHandshakeMessageSize=32768",
165+ // "--add-exports=java.management/sun.management=ALL-UNNAMED",
166+ // "--add-exports=jdk.attach/sun.tools.attach=ALL-UNNAMED",
167+ // "--add-opens=java.base/java.net=ALL-UNNAMED",
168+ // "--add-opens=jdk.attach/sun.tools.attach=ALL-UNNAMED",
169+ // "--patch-module java.base="$DIR/jsr166.jar",
170+ // "-javaagent:path/to/glowroot.jar",
171+ // "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:5005",
172+ // "-agentlib:jdwp=transport=dt_socket,server=n,address=host:5005,suspend=y,onthrow=<FQ
173+ // exception class name>,onuncaught=<y/n>"
174+ )
175+
56176/* * Kotlin version properties. */
57177val Project .kotlinVersion
58178 get() = libs.versions.kotlin.asProvider()
@@ -303,6 +423,7 @@ fun KotlinDependencyHandler.kspDependency(
303423 )
304424}
305425
426+
306427/* * Returns the path of the dependency jar in runtime classpath. */
307428context(Project )
308429val ExternalDependency .dependencyPath get() = configurations
@@ -315,6 +436,7 @@ val ExternalDependency.dependencyPath get() = configurations
315436 ?.path
316437 ? : error(" Could not find $name in runtime classpath" )
317438
439+
318440/* * Returns the application `run` command. */
319441context(Project )
320442fun Path.appRunCmd (args : List <String >): String {
0 commit comments