Java – What does “Not linked” mean in the Dynamic CDS Archive log?

What does “Not linked” mean in the Dynamic CDS Archive log?… here is a solution to the problem.

What does “Not linked” mean in the Dynamic CDS Archive log?

I’m trying to use JDK 13’s JEP-350 “dynamic CDS file” with real (non-academic) application .
To do this, I added the -XX:ArchiveClassesAtExit=, -Xlog:class+load=debug and -Xlog:cds=debug JVM options for my application startup script. When the application completes and HotSpot starts creating shared archives, the logs are populated with a number of warnings, such as:

[215.210s][warning][cds] Skipping tech/toparvion/analog/remote/agent/si/ContainerTargetFile: Not linked

But there is nothing suspicious about the same class in the class load log:

[121.323s][info ][class,load] tech.toparvion.analog.remote.agent.si.ContainerTargetFile source: file:/E:/Issues/Temp/deploy-v0.12/lib/analog/lib/ analog.slim.jar
[121.323s] [debug] [class,load]  klass: 0x0000000801072ce0 super: 0x00000008002ea5e0 loader: [loader data: 0x000001dc2aba5eb0 for instance a 'jdk/internal/loader/ClassLoaders$AppClassLoader'{ 0x0000000702300000}] bytes: 1305 checksum: 1645a974

The total number of classes used by the application is 10566 (including approximately 500 generated classes), of which 1824 such skip classes (including applications and libraries). I know that far from all classes can be put into a shared archive, but here I get ≈18% of skipped classes, which seems to be grossly lacking in CDS efficiency.

So the question is:

  1. Why skip class?
  2. What should I do to avoid skipping and include them in the archive?

Update
I repeated the same experiment with a static AppCDS archive and it worked, i.e. the ContainerTargetFile class was successfully stored in the shared archive as well as hundreds of other classes. Therefore, the above question seems to only concern Dynamic CDS Archives.

Solution

I had a similar experience when testing this feature. Almost all classes are skipped due to “unlinked” reasons. Further searches of the OpenJDK produced an interesting question with a link to the source code. If you examine the should_be_excluded functions, there are some useful comments explaining the exclusions, their rationale, and limitations. In particular, there seems to be a problem with the link when the JVM exits, i.e. when ArchiveClassesAtExit occurs.

https://bugs.openjdk.java.net/browse/JDK-8232081

http://hg.openjdk.java.net/jdk/jdk/file/23a06a5eeddd/src/hotspot/share/classfile/systemDictionaryShared.cpp#l1081
http://hg.openjdk.java.net/jdk/jdk/file/23a06a5eeddd/src/hotspot/share/classfile/systemDictionaryShared.cpp#l1116

Related Problems and Solutions