@@ -28,11 +28,11 @@ dependencies {
2828 implementation(libs. securemodules)
2929 implementation(libs. modlauncher)
3030 implementation(libs. unsafe)
31- implementation(project( ' :eventbus-test-jar ' ) )
31+ implementation(projects . eventbusTestJar )
3232
33- implementation( ' org.openjdk. jmh:jmh-core:1.37 ' )
34- runtimeOnly( ' org.openjdk. jmh:jmh-generator-annprocess:1.37 ' )
35- annotationProcessor( ' org.openjdk. jmh:jmh-generator-annprocess:1.37 ' )
33+ implementation libs . jmh. core
34+ runtimeOnly libs . jmh. annotationProcessor
35+ annotationProcessor libs . jmh. annotationProcessor
3636}
3737
3838extraJavaModuleInfo {
@@ -57,15 +57,16 @@ tasks.register('archiveJfr', ArchiveJfr) {
5757 output = file(' build/jmh_profile_results/archive/' )
5858}
5959
60- tasks. register(' jmh' ). configure {
61- dependsOn( ' aggregateJmh' , ' archiveJfr ' )
60+ tasks. register(' jmh' ) {
61+ dependsOn ' aggregateJmh'
6262}
6363
64- VALID_VMS . each { javaVendor, javaVersions ->
65- javaVersions. each { int javaVersion ->
66- def output = file(" build/jmh_results/jmh-${ javaVendor} -${ javaVersion} .json" )
67- def outputJfr = file(" build/jmh_profile_results/last_run/${ javaVendor} -${ javaVersion} /" )
68- def task = tasks. register(" jmh${ javaVendor}${ javaVersion} " , JavaExec ) {
64+ ((Map<String , List<Integer > > ) ext. VALID_VMS ). forEach { javaVendor, javaVersions ->
65+ for (Integer javaVersion in javaVersions) {
66+ var output = file(" build/jmh_results/jmh-${ javaVendor} -${ javaVersion} .json" )
67+ var outputJfr = file(" build/jmh_profile_results/last_run/${ javaVendor} -${ javaVersion} /" )
68+ outputJfr. mkdirs()
69+ var task = tasks. register(" jmh${ javaVendor}${ javaVersion} " , JavaExec ) {
6970 classpath = sourceSets. main. runtimeClasspath
7071 mainModule = ' net.minecraftforge.eventbus.jmh'
7172 mainClass = ' net.minecraftforge.eventbus.benchmarks.Main'
@@ -81,32 +82,44 @@ VALID_VMS.each { javaVendor, javaVersions ->
8182 ' -tu' , ' ns' , // Time unit: [m, s, ms, us, ns]
8283 ' -f' , ' 1' , // Forks per benchmark
8384 ' -rf' , ' json' , // Results File Format
84- ' -prof' , ' stack' , // Profiler: Simple and naive Java stack profiler
85- ' -prof' , " jfr:dir=${ outputJfr} " , // Profiler: Java Flight Recorder profiler
85+
86+ // Todo: Conditionally enable these when given a debug flag. Log a warning if they are enabled
87+ // saying that they should only be used for identifying hotspots and to not trust the
88+ // results of the benchmarks when they are enabled.
89+ // '-prof', 'stack', // Profiler: Simple and naive Java stack profiler
90+ // '-prof', "jfr:dir=${outputJfr}", // Profiler: Java Flight Recorder profiler
91+
92+ // Comment out the line below to enable BenchmarkClassLoader. This sets up a transformed environment
93+ // with ModLauncher but *doesn't* call useModLauncher() in BusBuilder.
94+ ' -e' , ' BenchmarkClassLoader.*' ,
95+
8696 ' -v' , ' EXTRA' , // Verbosity [SILENT, NORMAL, EXTRA]
8797 ' -foe' , ' true' , // Fail on error
8898 ' -rff' , output,
8999 ]
90100 if (project. hasProperty(' bench' ))
91101 args + = project. property(' bench' )
92-
102+
93103 doFirst {
94- if (outputJfr. exists())
95- outputJfr. deleteDir()
104+ outputJfr. deleteDir()
96105 if (! output. parentFile. exists())
97- output. parentFile. mkdirs()
106+ output. parentFile. mkdirs()
98107 if (output. exists())
99108 output. delete()
100109 }
101- javaLauncher. set(javaToolchains. launcherFor {
102- it. vendor. set(JvmVendorSpec . " ${ javaVendor.toUpperCase(Locale.ROOT)} " as JvmVendorSpec )
103- it. languageVersion. set(JavaLanguageVersion . of(javaVersion))
104- it. implementation. set(JvmImplementation . VENDOR_SPECIFIC )
105- })
110+ javaLauncher = javaToolchains. launcherFor {
111+ vendor = JvmVendorSpec . " ${ javaVendor.toUpperCase(Locale.ROOT)} " as JvmVendorSpec
112+ languageVersion = JavaLanguageVersion . of(javaVersion)
113+ implementation = JvmImplementation . VENDOR_SPECIFIC
114+ }
115+ }
116+ tasks. named(' aggregateJmh' ) {
117+ dependsOn task
118+ inputs. file output
119+ }
120+ tasks. named(' archiveJfr' ) {
121+ dependsOn task
122+ inputs. dir outputJfr
106123 }
107- aggregateJmh. dependsOn(task)
108- aggregateJmh. inputs. file(output)
109- archiveJfr. dependsOn(task)
110- archiveJfr. inputs. dir(outputJfr)
111124 }
112125}
0 commit comments