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

sun/font/HBShaper - mismatch in return type of FFM upcall function description and native invocation

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 24
    • 23, 24
    • client-libs
    • 2d
    • master

      In the JDK mainline, sun/font/HBShaper uses foreign functions feature of the Java language to invoke native functions.

      One such function is a upcall which gets invoked from the native function into the Java code. That upcall is constructed as follows https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/font/HBShaper.java#L281-L296

          FunctionDescriptor store_layout_fd =
                     FunctionDescriptor.ofVoid(
                      ...);
          MethodHandle store_layout_mh =
              getMethodHandle("store_layout_results", store_layout_fd);
          MemorySegment tmp10 = LINKER.upcallStub(store_layout_mh, store_layout_fd, garena);
          store_layout_results_stub = tmp10;

      So the upcall is declared to return a void type. The corresponding java method (correctly) is defined to return void too https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/classes/sun/font/HBShaper.java#L590

          /* Upcall to receive results of layout */
          private static void store_layout_results(
          ...

      However, the native code for this corresponding function is declared to return int type and infact the upcall invocation from within the native code even expects and assigns an int return value from that invocation:

      https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/native/libfontmanager/hb-jdk-p.h#L59

          typedef int (*store_layoutdata_func_t)
             (int slot, int baseIndex, int offset,
              float startX, float startY, float devScale,
              int charCount, int glyphCount,
              hb_glyph_info_t *glyphInfo, hb_glyph_position_t *glyphPos);

      https://github.com/openjdk/jdk/blob/master/src/java.desktop/share/native/libfontmanager/HBShaper_Panama.c#L135

          ret = (*store_layout_results_fn)
                         (slot, baseIndex, offset, startX, startY, devScale,
                          charCount, glyphCount, glyphInfo, glyphPos);


            prr Philip Race
            jpai Jaikiran Pai
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: