I am trying to develop a javaagent
. It also provides support for annotations.
In the preMain
method I am trying to scan the classpath for annotations. Then adding the transformer using instrumentatino.addTransformer()
method.
Because the classes are already loaded during the annotation processing, the transformation does not happen (if I remove the annotation processing code and retransformation code {see below}, things work fine).
To overcome this, I am now trying to retransform the classes. All the necessary setup related to manifest entry and enabling canRetransform
flag in addTransformer
method is done.
My code roughly looks like this:
annotationProcessor.processAnnotation();
instrumentation.addTransformer(new DummyTransformer(), true);
try {
instrumentation.retransformClasses(instrumentation.getAllLoadedClasses());
} catch (UnmodifiableClassException e) {
e.printStackTrace();
}
The DummyTransformer
does not do anything. It simply returns the classBytes as it is (also I tried it returning null on every call)
What happens here is that I am getting this error
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x000000010c5254dd, pid=5912, tid=0x0000000000001603
#
# JRE version: OpenJDK Runtime Environment (8.0_282) (build 1.8.0_282-bre_2021_01_20_16_06-b00)
# Java VM: OpenJDK 64-Bit Server VM (25.282-b00 mixed mode bsd-amd64 compressed oops)
# Problematic frame:
# V [libjvm.dylib+0x5254dd] Symbol::as_C_string() const+0xd
#
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
#
# An error report file with more information is saved as:
# /some/obfuscated/path/hs_err_pid5912.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
#
zsh: abort java -cp build/libs/jvm-agent-0.1-all.jar
Initially I thought the transformer is misbehaving, but as I experimented with DummyTransformer
, returning null
or the same bytes
produces similar results.