The following is moved from JDK-8207381 for tracking the subgraph validation/guard work:
We need a mechanism to validate that the new sub-graph for archiving is 'preservable'. There are following starter approaches:
Approach 1)
Author driven approach. The author who's adding a new sub-graph archiving need to specify all classes included in the graph are 'preservable'. Method for how to specify 'preservable' state is not determined yet currently.
Approach 2)
Add guards to the archived sub-graph during dump time. When archiving a sub-graph, checks can be done for the objects within the sub-graph to make sure they are not the ones with known issues (such as Thread, etc).
Approach 3)
This is suggested by Ioi. Dump time can consult a list of classes maintained internally by the sub-graph archiving mechanism. Only instances of classes on the list can be included in the archived sub-graph. When new sub-graphs are archived, new classes may be added to the list. Only classes with no runtime dependencies should be added to the list.
I'm in favor of the third option, augmented with the following optimization to limit the size of the list:
If an object's class is a sub-type of Serializable, the object is allowed to be part of an archived sub-graph, otherwise the list is consulted at dump time. Only classes that are not Serializable and have no dependencies on runtime context need to be maintained in the list (when their instances are part of archived sub-graphs).
In the future, when any of the classes in the list become sub-types of Serializable, they can be removed from the list.