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

Improve performance of Symbol::print_value_on()

    XMLWordPrintable

Details

    • b17

    Backports

      Description

        During investigation of performance of class unloading I found that logging the unloading event (UnloadingEventLog::log()) takes 20-40% of total class unloading time.

        The problem seems to be Symbol::print_value_on().

        The code is:

        void Symbol::print_value_on(outputStream* st) const {
          st->print("'");
          for (int i = 0; i < utf8_length(); i++) {
            st->print("%c", char_at(i));
          }
          st->print("'");
        }

        I.e. ultimately uses snprintf for every character of the symbol. The code seems to print the raw utf-8 string (ju)byte by (ju)byte.

        A faster way seems to be just use outputStream::write() since apparently the code wants to print the raw utf8 bytes anyway:

          st->write("'", 1);
          st->write((const char*)base(), utf8_length());
          st->write("'", 1);

        Initial tests showed that this is ~5-10x faster, reducing the overhead of event logging during class unloading significantly.

        Attachments

          Issue Links

            Activity

              People

                tschatzl Thomas Schatzl
                tschatzl Thomas Schatzl
                Votes:
                0 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: