Skip to content

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

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

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

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

spring-projects-issues opened this issue Nov 8, 2016 · 0 comments
Assignees
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

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

{CODE}
/**

  • 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);
    }
    {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

@spring-projects-issues spring-projects-issues added type: enhancement A general enhancement in: core Issues in core modules (aop, beans, core, context, expression) labels Jan 11, 2019
@spring-projects-issues spring-projects-issues added this to the 4.3.5 milestone Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants