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

Jmh with -jvmArgs --add-modules=jdk.incubator.vector #3576

Open
Quafadas opened this issue Sep 18, 2024 · 1 comment
Open

Jmh with -jvmArgs --add-modules=jdk.incubator.vector #3576

Quafadas opened this issue Sep 18, 2024 · 1 comment
Milestone

Comments

@Quafadas
Copy link
Contributor

I'm trying to benchmark the start of my attempts to play with project Panama's VectorAPI.

I've successfully run JMH like this;

mill benchmark.runJmh -jvmArgs --add-modules=jdk.incubator.vector -rf json vecxt.benchmark.DgemmBenchmark

Which works If I'm depending on a library which uses the VectorAPI. However, it seems that if I try to use it directly myself, Jmh becomes unhappy.

Processing 3 classes from /Users/simon/Code/vecxt/out/benchmark/compile.dest/classes with "reflection" generator
Writing out Java source to /Users/simon/Code/vecxt/out/benchmark/generateBenchmarkSources.dest/jmh_sources and resources to /Users/simon/Code/vecxt/out/benchmark/generateBenchmarkSources.dest/jmh_resources
Annotation generator had thrown the exception.
java.lang.NoClassDefFoundError: jdk/incubator/vector/Vector
        at java.base/java.lang.Class.getDeclaredMethods0(Native Method)
        at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3601)
        at java.base/java.lang.Class.getDeclaredMethods(Class.java:2686)
        at org.openjdk.jmh.generators.reflection.RFClassInfo.getMethods(RFClassInfo.java:99)
        at org.openjdk.jmh.generators.core.BenchmarkGenerator.buildAnnotatedSet(BenchmarkGenerator.java:213)
        at org.openjdk.jmh.generators.core.BenchmarkGenerator.generate(BenchmarkGenerator.java:77)
        at org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator.main(JmhBytecodeGenerator.java:100)
Caused by: java.lang.ClassNotFoundException: jdk.incubator.vector.Vector
        at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
        at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        ... 7 more


1 targets failed
benchmark.generateBenchmarkSources java.lang.Exception: Interactive Subprocess Failed (exit code 1)
    mill.util.Jvm$.runSubprocess(Jvm.scala:188)
    mill.util.Jvm$.runSubprocessWithBackgroundOutputs(Jvm.scala:152)
    mill.util.Jvm$.runSubprocess(Jvm.scala:88)
    mill.contrib.jmh.JmhModule.$anonfun$generateBenchmarkSources$3(JmhModule.scala:73)

I suspect, but am a little lost on how to prove, that this is because Jmh does some source generation, but the plugin doesn't pass javaCOptions to the process which does the codegen?

Does that sound plausible?

@Quafadas Quafadas changed the title Jmh with Jmh with -jvmArgs --add-modules=jdk.incubator.vector Sep 18, 2024
@Quafadas
Copy link
Contributor Author

Yup, this works, PR incoming.

object benchmark extends JmhModule with ScalaModule {
    def scalaVersion = vecxt.jvm.scalaVersion
    def jmhCoreVersion = "1.37"
    override def javacOptions: T[Seq[String]] = super.javacOptions() ++ vecIncubatorFlag
    override def moduleDeps: Seq[JavaModule] = Seq(vecxt.jvm)

    override def generateBenchmarkSources = T{
      val dest = T.ctx().dest

      val javacOpts = javacOptions().toSeq

      val sourcesDir = dest / "jmh_sources"
      val resourcesDir = dest / "jmh_resources"

      os.remove.all(sourcesDir)
      os.makeDir.all(sourcesDir)
      os.remove.all(resourcesDir)
      os.makeDir.all(resourcesDir)

      Jvm.runSubprocess(
        "org.openjdk.jmh.generators.bytecode.JmhBytecodeGenerator",
        (runClasspath() ++ generatorDeps()).map(_.path),
        mainArgs = Seq(
          compile().classes.path.toString,
          sourcesDir.toString,
          resourcesDir.toString,
          "default"
        ),
        jvmArgs = javacOpts
      )


      (sourcesDir, resourcesDir)
    }
}

lihaoyi pushed a commit that referenced this issue Sep 19, 2024
I believe this to be a solution for #3576 . However, I'm unclear how I
could effectively test it. Feedback welcomed.
@lefou lefou added this to the 0.12.0 milestone Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants