Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8326865

Avoid copying in StringTable::intern(Symbol*, TRAPS)

XMLWordPrintable

    • b25

      https://github.com/openjdk/jdk/blob/9f0e7da64e21237322e55ca4f0e3639fa5d1c4ed/src/hotspot/share/classfile/stringTable.cpp#L322-L330

      oop StringTable::intern(Symbol* symbol, TRAPS) {
        if (symbol == nullptr) return nullptr;
        ResourceMark rm(THREAD);
        int length;
        jchar* chars = symbol->as_unicode(length);
        Handle string;
        oop result = intern(string, chars, length, CHECK_NULL);
        return result;
      }

      "chars" is copied just to compute the hashcode. We should try to compute the hashcode using the UTF8 characters in the Symbol.

      This is called quite often when loading classes from classfiles (but not when CDS is used):

      java -Xshare:off -cp . HelloWorld
      - called 1600 times

      java -Xshare:on -cp . HelloWorld
      - called 17 times

      Important: we need to be 100% sure that we get the hashcode computation correct!

            cnorrbin Casper Norrbin
            iklam Ioi Lam
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: