Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use String.intern() for Class reading [SPR-14886] #19452

spring-projects-issues opened this issue Nov 8, 2016 · 0 comments

Use String.intern() for Class reading [SPR-14886] #19452

spring-projects-issues opened this issue Nov 8, 2016 · 0 comments


Copy link

@spring-projects-issues spring-projects-issues commented Nov 8, 2016

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


  • Reads a class constant pool item in {@link #b b}. <i>This method is

  • intended for {@link Attribute} sub classes, and is normally not needed by

  • class generators or adapters.</i>

  • @param index

  the start index of an unsigned short value in {@link #b b},
  whose value is the index of a class constant pool item.
  • @param buf

  buffer to be used to read the item. This buffer must be
  sufficiently large. It is not automatically resized.
  • @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);

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:

  • #19428 Use String.intern() for Annotation and Class scanning
  • #19637 Upgrade to ASM 5.2

Referenced from: commits 3a29daa, 7ffed85

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.