JDK-8323068 : Fix memory leaks in 3D metal code
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: internal
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • CPU: generic
  • Submitted: 2024-01-05
  • Updated: 2024-01-07
  • Resolved: 2024-01-07
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
Blocks :  
Description
I used leaks cmd utility in macOS to check for memory leaks in 3D rendering.
I ran RenderPerfTest and ran leaks utility for RenderPerfTest and i see that we have large memory leaks.

Process:         java [9172]
Path:            /Users/USER/*/java
Load Address:    0x102234000
Identifier:      java
Version:         18.0.2.1 (0)
Code Type:       ARM64
Platform:        macOS
Parent Process:  zsh [2167]

Date/Time:       2024-01-04 17:27:53.679 +0530
Launch Time:     2024-01-04 17:27:43.190 +0530
OS Version:      macOS 13.6.2 (22G320)
Report Version:  7
Analysis Tool:   /usr/bin/leaks

Physical footprint:         918.8M
Physical footprint (peak):  918.8M
Idle exit:                  untracked
----

leaks Report Version: 4.0, multi-line stacks
Process 9172: 6645594 nodes malloced for 457242 KB
Process 9172: 6519181 leaks for 417985408 total leaked bytes.

STACK OF 2151822 INSTANCES OF 'ROOT LEAK: <MetalLight>':
5   ???                                   0x11383c010 0x7fffffffffffffff + 9223372041477144593
4   ???                                   0x10bc858ac 0x7fffffffffffffff + 9223372041347422381
3   libprism_mtl.dylib                    0x102382b98 Java_com_sun_prism_mtl_MTLContext_nSetLight + 288
2   libprism_mtl.dylib                    0x102383ab0 -[MetalMeshView setLight:x:y:z:r:g:b:w:ca:la:qa:isA:range:dirX:dirY:dirZ:inA:outA:falloff:] + 188
1   libobjc.A.dylib                       0x1a7ed62a8 _objc_rootAllocWithZone + 40
0   libsystem_malloc.dylib                0x1a80acf38 _malloc_zone_calloc_instrumented_or_legacy + 228 
====
    2151822 (164M) << TOTAL >>
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018000a0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018000f0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x600001800190> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018001e0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x600001800280> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018002d0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x600001800370> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018003c0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x600001800460> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018004b0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018005a0> [80]
      1 (80 bytes) ROOT LEAK: <MetalLight 0x6000018005f0> [80]



leaks Report Version: 4.0, multi-line stacks
Process 9805: 2827044 nodes malloced for 181750 KB
Process 9805: 2704156 leaks for 130472000 total leaked bytes.

STACK OF 878478 INSTANCES OF 'ROOT LEAK: <MTLDepthStencilDescriptorInternal>':
8   ???                                   0x115b0fdb4 0x7fffffffffffffff + 9223372041513663925
7   ???                                   0x115aae0c8 0x7fffffffffffffff + 9223372041513263305
6   libprism_mtl.dylib                    0x1047068a0 Java_com_sun_prism_mtl_MTLContext_nRenderMeshView + 48
5   libprism_mtl.dylib                    0x1047080c0 -[MetalMeshView render] + 1452
4   libprism_mtl.dylib                    0x1047091a8 -[MetalPipelineManager getDepthStencilState] + 32
3   libobjc.A.dylib                       0x1a7efcad8 objc_opt_new + 112
2   com.apple.Metal                       0x1b16daf68 +[MTLDepthStencilDescriptor allocWithZone:] + 80
1   libobjc.A.dylib                       0x1a7ed62a8 _objc_rootAllocWithZone + 40
0   libsystem_malloc.dylib                0x1a80acf38 _malloc_zone_calloc_instrumented_or_legacy + 228 
====
    2634467 (121M) << TOTAL >>
      ----
      3 (144 bytes) ROOT LEAK: <MTLDepthStencilDescriptorInternal 0x600002c05da0> [48]
         1 (48 bytes) _private + 8 --> <MTLStencilDescriptorInternal 0x600003170000> [48]
         1 (48 bytes) _private --> <MTLStencilDescriptorInternal 0x600002c05d70> [48]
      ----
      3 (144 bytes) ROOT LEAK: <MTLDepthStencilDescriptorInternal 0x600002c2dc80> [48]
         1 (48 bytes) _private + 8 --> <MTLStencilDescriptorInternal 0x600002c60060> [48]
         1 (48 bytes) _private --> <MTLStencilDescriptorInternal 0x600002c312c0> [48]
Comments
Changeset: a2a78c8b Author: Jayathirth Rao D V <jayathirth.d.v@oracle.com> Committer: Kevin Rushforth <kcr@openjdk.org> Date: 2024-01-05 20:22:14 +0000 URL: https://git.openjdk.org/jfx-sandbox/commit/a2a78c8b0ac19b7e08550c965ee4d9691a356ae4
07-01-2024

I was able to fix all memory leaks except the one where we are creating RenderPassDescriptor in setDeviceParametersFor3D. Releasing it with autorelease is causing state issues, i have added TODO to fix the same in future. Verified the patch Metal API and Shader validation and i don't see any issues.
05-01-2024