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

Off-by-one error in allocation

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2
    • Resolution: Fixed
    • Affects Version/s: 18
    • Fix Version/s: 18
    • Component/s: hotspot
    • Labels:
    • Subcomponent:
      jfr
    • Resolved In Build:
      b20
    • Verification:
      Not verified

      Description

      Copy-paste error in JDK-8275445 trying to resolve original issue JDK-8266936

      Moving from the JFR abstraction:

      static char* allocate_string(bool c_heap, int length, JavaThread* jt) {
        return c_heap ? NEW_C_HEAP_ARRAY(char, length, mtTracing) :
                        NEW_RESOURCE_ARRAY_IN_THREAD(jt, char, length);
      }

      const char* JfrJavaSupport::c_str(oop string, JavaThread* t, bool c_heap /* false */) {
        DEBUG_ONLY(check_java_thread_in_vm(t));
        char* str = NULL;
        const typeArrayOop value = java_lang_String::value(string);
        if (value != NULL) {
          const int length = java_lang_String::utf8_length(string, value);
          str = allocate_string(c_heap, length + 1, t);
          if (str == NULL) {
            JfrJavaSupport::throw_out_of_memory_error("Unable to allocate native memory", t);
            return NULL;
          }
          java_lang_String::as_utf8_string(string, value, str, length + 1);
        }
        return str;
      }

      To the non-JFR code:

      static const char* allocate(oop string) {
        char* str = nullptr;
        const typeArrayOop value = java_lang_String::value(string);
        if (value != nullptr) {
          const int length = java_lang_String::utf8_length(string, value);
          str = NEW_C_HEAP_ARRAY(char, length, mtServiceability);
          java_lang_String::as_utf8_string(string, value, str, length + 1);
        }
        return str;
      }

      allocate_string() takes the length+1 to the NEW_C_HEAP_ARRAY, but the new code lost the +1

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mgronlun Markus Grönlund
              Reporter:
              mgronlun Markus Grönlund
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: