JDK-8261547 : Minor memory leak reported for Metal Rendering pipeline
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: internal
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: x86_64
  • Submitted: 2021-02-11
  • Updated: 2021-02-12
  • Resolved: 2021-02-12
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
internalFixed
Related Reports
Relates :  
Description
This came up as a review comment on https://github.com/openjdk/jdk/pull/2403.

Please check the validity and fix if it's a valid leak.

According to Xcode Instruments leak profile, there are 2 minor memory leaks in the Metal rendering pipeline:

#1 Malloc 80 Bytes 1 0x7fde0d4247b0 80 Bytes libjava.dylib getStringUTF8

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 libjava.dylib getStringUTF8 /Volumes/Work/review/2403/jdk/src/java.base/share/native/libjava/jni_util.c:888
   3 libjava.dylib JNU_GetStringPlatformChars /Volumes/Work/review/2403/jdk/src/java.base/share/native/libjava/jni_util.c:917
   4 libawt_lwawt.dylib Java_sun_java2d_metal_MTLGraphicsConfig_getMTLConfigInfo /Volumes/Work/review/2403/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m:151
   5  0x11ab08d48
   6  0x11ab0250d

#2 Malloc 80 Bytes 1 0x7fde0d4325a0 80 Bytes libjava.dylib getStringUTF8

   0 libsystem_malloc.dylib malloc_zone_malloc
   1 libsystem_malloc.dylib malloc
   2 libjava.dylib getStringUTF8 /Volumes/Work/review/2403/jdk/src/java.base/share/native/libjava/jni_util.c:888
   3 libjava.dylib JNU_GetStringPlatformChars /Volumes/Work/review/2403/jdk/src/java.base/share/native/libjava/jni_util.c:917
   4 libawt_lwawt.dylib Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary /Volumes/Work/review/2403/jdk/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m:120
   5  0x11ab08d48
   6  0x11ab024c8
Comments
I am still facing some configure issue in lanai repo(did not work on lanai repo after upgrading to 10.15.7), so if somebody could check PR github.com/openjdk/lanai/pull/182 it will be good. PRSADHUK-Mac:lanai PRSADHUK$ bash ./jib.sh configure -p macosx-x64-debug -- --enable-debug ............ checking for extra path... /var/tmp/jib-PRSADHUK/install/jpg/infra/builddeps/devkit-macosx_x64/Xcode11.3.1-MacOSX10.15+1.1/devkit-macosx_x64-Xcode11.3.1-MacOSX10.15+1.1.tar.gz/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin:/var/tmp/jib-PRSADHUK/install/jpg/infra/builddeps/devkit-macosx_x64/Xcode11.3.1-MacOSX10.15+1.1/devkit-macosx_x64-Xcode11.3.1-MacOSX10.15+1.1.tar.gz/Xcode.app/Contents/Developer/usr/bin checking where to store configuration... in current directory configure: Current directory is /Users/PRSADHUK/export/lanai. configure: Since this is not the source root, configure will output the configuration here configure: (as opposed to creating a configuration in <src_root>/build/<conf-name>). configure: However, this directory is not empty. This is not allowed, since it could configure: seriously mess up just about everything. configure: Try 'cd /export/lanai/open' and restart configure configure: (or create a new empty directory and cd to it). configure: error: Will not continue creating configuration in /Users/PRSADHUK/export/lanai /Users/PRSADHUK/export/lanai/configure-support/generated-configure.sh: line 82: 5: Bad file descriptor configure exiting with result code 1
11-02-2021

Facing some issue in creating branch of lanai repo ====== git push -u origin JDK-8261547 /bin/bash: /usr/biin/nc: No such file or directory /bin/bash: line 0: exec: /usr/biin/nc: cannot execute: No such file or directory kex_exchange_identification: write: Broken pipe fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ==== Also, updating and building repo encountered some issue in my environment ======= In file included from /Users/PRSADHUK/export/lanai/open/src/hotspot/share/utilities/globalDefinitions_gcc.hpp:58: /var/tmp/jib-PRSADHUK/install/jpg/infra/builddeps/devkit-macosx_x64/Xcode11.3.1-MacOSX10.15+1.1/devkit-macosx_x64-Xcode11.3.1-MacOSX10.15+1.1.tar.gz/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk/usr/include/AvailabilityMacros.h:158:6: error: MAC_OS_X_VERSION_MAX_ALLOWED must be >= MAC_OS_X_VERSION_MIN_REQUIRED #error MAC_OS_X_VERSION_MAX_ALLOWED must be >= MAC_OS_X_VERSION_MIN_REQUIRED so I am embedding the patch if somebody is interested in trying it out git diff diff --git a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m index 94966d37143..f55f8c081c9 100644 --- a/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m +++ b/src/java.desktop/macosx/native/libawt_lwawt/java2d/metal/MTLGraphicsConfig.m @@ -117,7 +117,8 @@ JNI_COCOA_ENTER(env); NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3]; [retArray addObject: [NSNumber numberWithInt: (int)displayID]]; - [retArray addObject: [NSString stringWithUTF8String: JNU_GetStringPlatformChars(env, shadersLibName, 0)]]; + NSString *str = JNU_GetStringPlatformChars(env, shadersLibName, 0); + [retArray addObject: [NSString stringWithUTF8String: str]]; if ([NSThread isMainThread]) { [MTLGraphicsConfigUtil _tryLoadMetalLibrary: retArray]; } else { @@ -125,6 +126,7 @@ } NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0]; ret = (jboolean)[num boolValue]; + JNU_ReleaseStringPlatformChars(env, shadersLibName, str); JNI_COCOA_EXIT(env); return ret; } @@ -148,7 +150,8 @@ JNI_COCOA_ENTER(env); NSMutableArray * retArray = [NSMutableArray arrayWithCapacity:3]; [retArray addObject: [NSNumber numberWithInt: (int)displayID]]; - [retArray addObject: [NSString stringWithUTF8String: JNU_GetStringPlatformChars(env, mtlShadersLib, 0)]]; + NSString *str = JNU_GetStringPlatformChars(env, mtlShadersLib, 0); + [retArray addObject: [NSString stringWithUTF8String: str]]; if ([NSThread isMainThread]) { [MTLGraphicsConfigUtil _getMTLConfigInfo: retArray]; } else { @@ -156,6 +159,7 @@ } NSNumber * num = (NSNumber *)[retArray objectAtIndex: 0]; ret = (jlong)[num longValue]; + JNU_ReleaseStringPlatformChars(env, mtlShadersLib, str); JNI_COCOA_EXIT(env); return ret; }
11-02-2021

One needs to call JNU_ReleaseStringPlatformChars((env, shadersLibName, stringWithUTF8String) [in Java_sun_java2d_metal_MTLGraphicsConfig_tryLoadMetalLibrary] if "shadersLibName" need to be released at any point, but am not sure if it is supposed to be released. Same for 2nd one too JNU_ReleaseStringPlatformChars(env, mtlShadersLib, stringWithUTF8String) in Java_sun_java2d_metal_MTLGraphicsConfig_getMTLConfigInfo but again "mtlShadersLib" not sure if it can be released as it is linked to jvm library, if I understand correctly.
11-02-2021

It is a review comment - so test case will not be provided. It is a common initialization path so any test application would do. There is reported trace as well. So - please investigate if it is valid. You can close this only if it is false positive and not due to lack of test case.
11-02-2021

No testcase provided which indicates the leak. As per my testing on SwingSet2, J2DDemo no leaks are reported in Metal pipeline.
11-02-2021

Thanks [~kcr]. Indeed it was...But strangely, it did not create any problem for openjdk/jdk repo when I tried to create a branch.
11-02-2021