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

Eliminate redundant memcpy operation in jni_GetStringUTFRegion

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P3
    • 9
    • 7
    • hotspot
    • b13
    • generic
    • generic

    Description

      ###@###.### wrote:
      > I also found that a memory allocation and a memory copying can be
      > removed from the following function defined in
      > hotspot/src/share/vm/prims/jni.cpp. The function was a source of the
      > MISALIGN.MEM.REF events and the events could not be decreased with the
      > above macro:
      >
      > JNI_ENTRY(void, jni_GetStringUTFRegion(JNIEnv *env, jstring string,
      > jsize start, jsize len, char *buf))
      > JNIWrapper("GetStringUTFRegion");
      > DTRACE_PROBE5(hotspot_jni, GetStringUTFRegion__entry, env, string,
      > start, len, buf);
      > DT_VOID_RETURN_MARK(GetStringUTFRegion);
      > oop s = JNIHandles::resolve_non_null(string);
      > int s_len = java_lang_String::length(s);
      > if (start < 0 || len < 0 || start + len > s_len) {
      > THROW(vmSymbols::java_lang_StringIndexOutOfBoundsException());
      > } else {
      > //%note jni_7
      > if (len > 0) {
      > ResourceMark rm(THREAD);
      > char *utf_region = java_lang_String::as_utf8_string(s, start,
      > len);
      > int utf_len = (int)strlen(utf_region);
      > memcpy(buf, utf_region, utf_len);
      > buf[utf_len] = 0;
      > } else {
      > // JDK null-terminates the buffer even in len is zero
      > if (buf != NULL) {
      > buf[0] = 0;
      > }
      > }
      > }
      > JNI_END
      >
      > The java_lang_String::as_utf8_string function allocates a temporary
      > buffer in which result of utf8 encoding is put. The function returns the
      > allocated buffer. The data from the temporary buffer is copied into the
      > specified buffer. After all the temporary buffer is freed. I wrote the
      > java_lang_String::copy_as_utf8_string function which writes results of
      > encoding directly into the specified buffer. This optimization reduces a
      > number of CPU_CLK/JOP from 3883 to 1540, a path length/JOP - from 1580
      > to 793.

      Sample source is attached.

      Attachments

        Activity

          People

            dsimms David Simms
            sbohne Steve Bohne (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: