Use String.intern() for Class reading [SPR-14886] #19452
Labels
in: core
Issues in core modules (aop, beans, core, context, expression)
type: enhancement
A general enhancement
Milestone
Renier Roth opened SPR-14886 and commented
Another place where String.intern() can be used as described in issue #19428
is in
file: org.springframework.asm.ClassReader
line: 3463
{CODE}
/**
Reads a class constant pool item in {
@link
#b b}. <i>This method isintended for {
@link
Attribute} sub classes, and is normally not needed byclass generators or adapters.</i>
@param
index@param
buf@return
the String corresponding to the specified class item.*/
public String readClass(final int index, final char[] buf) {
// computes the start index of the CONSTANT_Class item in b
// and reads the CONSTANT_Utf8 item designated by
// the first two bytes of this CONSTANT_Class item
return readUTF8(items[readUnsignedShort(index)], buf);
}
{CODE}
This is the most inner class i could find that create the String. So the return of this method can use ....intern()
This method is used internally inside the class for super / interface and other classnames.
Spring uses this ClassReader via an Visitor "AnnotationMetadataReadingVisitor" more precise the extend "ClassMetadataReadingVisitor".
This visitor is returned as an implementation for the Interface "AnnotationMetadata" inside "SimpleMetadataReader" which is the only implementation for an metadata reader in the "ScannedGenericBeanDefinition" definition which will be hold inside memory.
Complicated enough, if you read backwards the ScannedGenericBeanDefinition stores the metadata as a field. This is the Visitor described above, which uses the ASM ClassReader to generate the Strings. The Strings are stored multiple times in Memory, this can be avoided to intern the String inside this chain of classes - most inner one is ClassReader (see source above).
Affects: 4.3.4
Issue Links:
Referenced from: commits 3a29daa, 7ffed85
The text was updated successfully, but these errors were encountered: