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

Avoid copying in StringTable::intern(oop, TRAPS)

XMLWordPrintable

    • master

      https://github.com/openjdk/jdk/blob/7f02f07f754c942735ba15d70858cd1661a658c0/src/hotspot/share/classfile/stringTable.cpp#L332-L342

      oop StringTable::intern(oop string, TRAPS) {
        if (string == nullptr) return nullptr;
        ResourceMark rm(THREAD);
        int length;
        Handle h_string (THREAD, string);
        jchar* chars = java_lang_String::as_unicode_string(string, length,
                                                           CHECK_NULL);
        oop result = intern(h_string, chars, length, CHECK_NULL);
        return result;
      }

      The "chars" are used for computing the hashcode. However, we can just call java_lang_String::hash_code(oop), which will compute the hashcode for us without making the extra allocation.

      ==========================
      Fixing this will help improve start-up time, as the following one-liner today causes about 4400 calls to String::intern().

      import java.text.*;
      class DateFormatTest {
        public static void main(String args[]) {
          SimpleDateFormat t = new SimpleDateFormat();
        }
      }

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

              Created:
              Updated:
              Resolved: