Currently the G1 evacuation-time test for string deduplication first tests the enable flag. If enabled, it collects some arguments and calls into the dedup handling code. One of the first things done by the dedup handling code is to test whether the object is actually a string, doing nothing if it isn't.
This is done for every (beforeJDK-8158045, every non-array after) object. As a result, enabling dedup has a pretty significant cost, since most objects are not strings.
A better approach is to add a member to G1ParScanThreadState whose value is SystemDictionary::String_klass if dedup is enabled, else nullptr.
Change the test for dedup to compare the already available klass of the object with the value in that new state member. If not equal then either not a string or dedup is disabled. Otherwise, call into the dedup handling.
With this change, enabling dedup only imposes a cost on evacuation of strings.
This is done for every (before
A better approach is to add a member to G1ParScanThreadState whose value is SystemDictionary::String_klass if dedup is enabled, else nullptr.
Change the test for dedup to compare the already available klass of the object with the value in that new state member. If not equal then either not a string or dedup is disabled. Otherwise, call into the dedup handling.
With this change, enabling dedup only imposes a cost on evacuation of strings.