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

Agent cannot instrument Scala classes #17

Open
plokhotnyuk opened this issue May 21, 2023 · 1 comment
Open

Agent cannot instrument Scala classes #17

plokhotnyuk opened this issue May 21, 2023 · 1 comment

Comments

@plokhotnyuk
Copy link

plokhotnyuk commented May 21, 2023

I've tried to run the agent with jsoniter-scala benchmark on JDK-17 using the following command:

sbt -batch -java-home /usr/lib/jvm/zulu-17 clean 'jsoniter-scala-benchmarkJVM/jmh:run -jvmArgs -javaagent:<full path to local copy of type-pollution-agent repo>/agent/target/type-pollution-agent-0.1-SNAPSHOT.jar -p size=128 .*'

Here is a couple of stack traces:

[info] [Byte Buddy] ERROR scala.math.Integral$ [jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7, unnamed module @3ada9e37, Thread[com.github.plokhotnyuk.jsoniter_scala.benchmark.BigIntWriting.jacksonScala-jmh-worker-1,5,main], loaded=false]
[info] java.lang.IllegalStateException: Illegal parameter name of final scala.math.Integral int for public scala.math.Integral scala.math.Integral$.apply(scala.math.Integral)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1766)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:520)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.inline.RebaseDynamicTypeBuilder.make(RebaseDynamicTypeBuilder.java:221)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:11903)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:11838)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1700(AgentBuilder.java:11555)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:12318)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:12250)
[info] 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doPrivileged(AgentBuilder.java)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:11781)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$ByteBuddy$ModuleSupport.transform(Unknown Source)
[info] 	at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[info] 	at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
[info] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[info] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
[info] 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
[info] 	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
[info] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
[info] 	at scala.package$.<clinit>(package.scala:124)
[info] 	at scala.Predef$.<clinit>(Predef.scala:151)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.BigIntBenchmark.setup(BigIntBenchmark.scala:15)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.jmh_generated.BigIntWriting_jacksonScala_jmhTest._jmh_tryInit_f_bigintwriting0_0(BigIntWriting_jacksonScala_jmhTest.java:338)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.jmh_generated.BigIntWriting_jacksonScala_jmhTest.jacksonScala_Throughput(BigIntWriting_jacksonScala_jmhTest.java:71)
[info] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[info] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info] 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[info] 	at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:475)
[info] 	at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:458)
[info] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[info] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[info] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[info] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[info] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[info] 	at java.base/java.lang.Thread.run(Thread.java:833)
[info] [Byte Buddy] ERROR scala.collection.AbstractSeq [jdk.internal.loader.ClassLoaders$AppClassLoader@251a69d7, unnamed module @3ada9e37, Thread[com.github.plokhotnyuk.jsoniter_scala.benchmark.BigIntWriting.jacksonScala-jmh-worker-1,5,main], loaded=false]
[info] java.lang.IllegalStateException: Illegal parameter name of final scala.Function1 default for public java.lang.Object scala.collection.AbstractSeq.applyOrElse(java.lang.Object,scala.Function1)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.InstrumentedType$Default.validated(InstrumentedType.java:1766)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.MethodRegistry$Default.prepare(MethodRegistry.java:520)
[info] 	at agent.net.bytebuddy.dynamic.scaffold.inline.RebaseDynamicTypeBuilder.make(RebaseDynamicTypeBuilder.java:221)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doTransform(AgentBuilder.java:11903)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:11838)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.access$1700(AgentBuilder.java:11555)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:12318)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$Java9CapableVmDispatcher.run(AgentBuilder.java:12250)
[info] 	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.doPrivileged(AgentBuilder.java)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer.transform(AgentBuilder.java:11781)
[info] 	at agent.net.bytebuddy.agent.builder.AgentBuilder$Default$ExecutingTransformer$ByteBuddy$ModuleSupport.transform(Unknown Source)
[info] 	at java.instrument/sun.instrument.TransformerManager.transform(TransformerManager.java:188)
[info] 	at java.instrument/sun.instrument.InstrumentationImpl.transform(InstrumentationImpl.java:541)
[info] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[info] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
[info] 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
[info] 	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
[info] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
[info] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[info] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
[info] 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
[info] 	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
[info] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
[info] 	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
[info] 	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
[info] 	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
[info] 	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
[info] 	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
[info] 	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.BigIntBenchmark.setup(BigIntBenchmark.scala:15)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.jmh_generated.BigIntWriting_jacksonScala_jmhTest._jmh_tryInit_f_bigintwriting0_0(BigIntWriting_jacksonScala_jmhTest.java:338)
[info] 	at com.github.plokhotnyuk.jsoniter_scala.benchmark.jmh_generated.BigIntWriting_jacksonScala_jmhTest.jacksonScala_Throughput(BigIntWriting_jacksonScala_jmhTest.java:71)
[info] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[info] 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
[info] 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[info] 	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
[info] 	at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:475)
[info] 	at org.openjdk.jmh.runner.BenchmarkHandler$BenchmarkTask.call(BenchmarkHandler.java:458)
[info] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[info] 	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
[info] 	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
[info] 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
[info] 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
[info] 	at java.base/java.lang.Thread.run(Thread.java:833)
@franz1981
Copy link
Contributor

@plokhotnyuk sorry to read it just now, I'm not a Scala user myself, but it seems something related ByteBuddy itself and the issue could be redirected there.

What you can try, instead, is to narrow the scope of the agent vs the packages you want it to validate, check https://github.com/RedHatPerf/type-pollution-agent#but-what-about-openjdk-jit-optimizations-that-could-save-any-check-to-be-performed

which means adding a comma separated list of packages prefixes which will be instrumented, leaving out the rest.
Remember that JMH is not very gentle while stopping its forks, and I suggest to configure a reporting intervals (in seconds? depends by your test duration) -> https://github.com/RedHatPerf/type-pollution-agent/blob/master/agent/src/main/java/io/type/pollution/agent/Agent.java#L40 specifying this system property ie via -D

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