<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://jogamp.org/bugzilla/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.2"
          urlbase="https://jogamp.org/bugzilla/"
          
          maintainer="sgothel@jausoft.com"
>

    <bug>
          <bug_id>1393</bug_id>
          
          <creation_ts>2019-09-09 08:54:44 +0200</creation_ts>
          <short_desc>MacOS 10.14.6 + OpenJDK11U produces occasional freezes on AppKit Main Thread</short_desc>
          <delta_ts>2020-02-07 07:07:51 +0100</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>3</classification_id>
          <classification>JogAmp</classification>
          <product>Newt</product>
          <component>macosx</component>
          <version>2.4.0</version>
          <rep_platform>All</rep_platform>
          <op_sys>macosx</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P4</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          <dependson>1370</dependson>
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sven Gothel">sgothel</reporter>
          <assigned_to name="Sven Gothel">sgothel</assigned_to>
          <cc>askinner</cc>
    
    <cc>jani</cc>
          
          <cf_type>DEFECT</cf_type>
          <cf_scm_refs>b12a80e386b12d9d8fa63cf07124f8da989dcd04
e33aa16904d8abddaeceb1374ffa45bd45a96210
7e76df3a05b7eb2404cb4584ee0b34ea287eb9bf
b8db98376069a72ad40b7ef2fe2d9003aea2b091
ecc6794670b31d859763eb363ed3ead15d757977
b0a222100ce8425485bea201adf28dc6509333ad
4a072cd1c09d3f2ba5fd04033091836d195c9409
2e59792eba285d7cd3c2f4f4c78838b8cc8918f7
12eed5d38616d23b6e8e2e5b497dfc2f54d90c90
999e1ca3ec1a406d3dba65f0bae79054580fb287</cf_scm_refs>
          <cf_workaround>---</cf_workaround>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>6317</commentid>
    <comment_count>0</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-09-09 08:54:44 +0200</bug_when>
    <thetext>Latest manual tests after resolving Bug 1389
disclosed a few occasional freezes using NEWT + Java11.

These are related to probable AWT changes since Java8.

MacOS 10.14.6 freezes 4 / 273
====================================
com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext01VSyncAnimNEWT test07ExclPre_4Win
com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext11VSyncAnimNEWT
com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext02FPSAnimNEWT
com.jogamp.opengl.test.junit.jogl.acore.ect.TestExclusiveContext12FPSAnimNEWT

Inspection of proper utilization of NSWindow/NSView etc 
on AppKit Main-Thread is required. 

May utilize &apos;Main Thread Checker&apos;, see
&lt;https://developer.apple.com/documentation/code_diagnostics/main_thread_checker?language=objc&gt;

Further we should align the Main-Thread usage in the macosx implementation
with our new ios implementation.
See commit 004c67c73a0309158c30929cd0d6513e23f34803 
which already simplifies the createWindow code.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6318</commentid>
    <comment_count>1</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-09-09 09:11:12 +0200</bug_when>
    <thetext>Just for the sake of a little documentation:

We have to ensure avoiding deadlocks the likes of:

Threads: USR, EDT, AppKit
(USR the user thread, any ..)
(EDT the NEWT EDT thread for lifecycle and events/tasks)
(AppKit MacOS APPKit Main-Thread)

USR -- cmd --&gt; EDT (blocking pending action)

from here on:

EDT -- osx --&gt; APK (one of those cocoa/NS actions)

EDT &lt;-- blocking -- APK (we issue a deferred-and-wait NEWT command on EDT)

Result ** DEADLOCK **

The only critical synchronous action w/ NEWT are
lifecycle operations, where we demand handles to be realized.
E.g. createWindow(..) up until the native handles exist,
however, the actual &apos;setVisible&apos; can be spun off-thread on the APK.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6319</commentid>
    <comment_count>2</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-09-09 09:39:49 +0200</bug_when>
    <thetext>resolved as described:

commit b12a80e386b12d9d8fa63cf07124f8da989dcd04
Author: Sven Gothel &lt;sgothel@jausoft.com&gt;
Date:   Mon Sep 9 09:29:43 2019 +0200

    Bug 1393: Run orderFront0(=setVisible) async off-thread on AppKit after sync AppKit NSWindow creation
    
    MacOS 10.14.6 + OpenJDK11U produces occasional freezes on AppKit Main Thread
    
    Latest manual tests after resolving Bug 1389
    disclosed a few occasional freezes using NEWT + Java11.
    
    These are related to probable AWT changes since Java8,
    as these do not occur with Java8.
    
    Fix: Spun off orderFront0(=setVisible) async off-thread on AppKit after sync AppKit NSWindow creation.
    
    This fix also aligns the macos createWindow code with the new simplified ios implementation,
    see commit 004c67c73a0309158c30929cd0d6513e23f34803


commit e33aa16904d8abddaeceb1374ffa45bd45a96210
Author: Sven Gothel &lt;sgothel@jausoft.com&gt;
Date:   Mon Sep 9 09:33:23 2019 +0200

    Bug 1393: MacOS/iOS: Issue updateSizePosInsets0 async to AppKit Main-Thread
    
    Additionally, setPointerIcon0 must also be made async on AppKit (instead of wait),
    we have to assume/hope the user won&apos;t pull the PointerIconImpl instance in-between ;-)
    Hence removing the comment regarding the lifecycle.


commit 7e76df3a05b7eb2404cb4584ee0b34ea287eb9bf (HEAD -&gt; master)
Author: Sven Gothel &lt;sgothel@jausoft.com&gt;
Date:   Mon Sep 9 09:36:50 2019 +0200

    Bug 1393: OSXUtil: Optionally inject Apple&apos;s &apos;Main Thread Checker&apos;
    
    To allow proper testing of whether all AppKit calls are performed on its Main-Thread where required,
    we inject the libMainThreadChecker.dylib when property &apos;nativewindow.debug.OSXUtil.MainThreadChecker&apos; is set.
    
    See &lt;https://developer.apple.com/documentation/code_diagnostics/main_thread_checker?language=objc&gt;
    Lib-Name: /Applications/Xcode.app/Contents/Developer/usr/lib/libMainThreadChecker.dylib</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6324</commentid>
    <comment_count>3</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-09-11 04:18:16 +0200</bug_when>
    <thetext>commit b8db98376069a72ad40b7ef2fe2d9003aea2b091

    Bug 1393: Add window position validation in TestDisplayLifecycle*NEWT
    
    The OSX fixes for bug 1393 spun off certain tasks like position/size gathering async to AppKit,
    hence we should validate whether both are valid.
    
    Further the TestDisplayLifecycle02NEWT had one bug,
    it retrieved &apos;screen.getViewportInWindowUnits()&apos; while it was not yet initialized.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6325</commentid>
    <comment_count>4</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-09-11 07:41:51 +0200</bug_when>
    <thetext>reopening: further investigation shows that subsequent &apos;run on main-thread&apos; task has been spun off to the app-kit thread, but not processed.

however, the app-kit thread has not being locked within our EDT
as shown in comment 1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6344</commentid>
    <comment_count>5</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-11-28 02:23:55 +0100</bug_when>
    <thetext>ecc6794670b31d859763eb363ed3ead15d757977

    Bug 1393: Adding test cases setting visibility before enabling exclusive context thread animator
    
    MacOS Java11 freezes occur on 3rd NEWT window creation (orderFront) after enabling exclusive context thread animator.
    Here we add set visibility upfront which does not trigger the freeze on the AppKit main thread.
    Note: OpenJDK8 works flawlessly.
    For some reason, the exclusive context thread enabled animator interferes when &apos;orderFront&apos; is issued.

+++

b0a222100ce8425485bea201adf28dc6509333ad

    Bug 1393: MacOS: Implement AppKit EDTUtil operating solely on main-thread
    
    Introducing boolean property &apos;newt.macos.useAppKitEDTUtil&apos;, which defaults to &apos;false&apos;.
    If enabled, the new AppKitEDTUtil is being used, operating on the AppKit main thread.
    This is used to ease debugging Bug 1393, minimizing thread context switches.

+++

4a072cd1c09d3f2ba5fd04033091836d195c9409

    Bug 1393: MacOS: Wait for window position setting on main-thread (blocking)
    
    Also issue the orderFront0 call within createWindow1 (aligned with IOS code)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6438</commentid>
    <comment_count>6</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-08 04:56:37 +0100</bug_when>
    <thetext>2e59792eba285d7cd3c2f4f4c78838b8cc8918f7
Make window position check more tolerant (2x insets or 64 pixels, whichever is greater)
    
    Certain WM&apos;s may modify the windowing position &apos;a little&apos;, which has been experienced on one X11 server
    during invisible setting. The insets were removed and its value added to the position!
    
    We could argue that this is an issue in our windowing code, however, the WM is free to reposition a window.
    
    Refines commit b8db98376069a72ad40b7ef2fe2d9003aea2b091</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6445</commentid>
    <comment_count>7</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-08 08:37:17 +0100</bug_when>
    <thetext>*** Bug 1398 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6446</commentid>
    <comment_count>8</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2019-12-08 09:46:19 +0100</bug_when>
    <thetext>12eed5d38616d23b6e8e2e5b497dfc2f54d90c90
Resolve EDT + AppKit Deadlock with native parenting: Fetch parent screen position directly w/o locking.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6486</commentid>
    <comment_count>9</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-01 00:00:24 +0100</bug_when>
    <thetext>passed unit tests ..</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>6495</commentid>
    <comment_count>10</comment_count>
    <who name="Sven Gothel">sgothel</who>
    <bug_when>2020-01-02 04:45:35 +0100</bug_when>
    <thetext>(In reply to Sven Gothel from comment #8)

jogl commit 999e1ca3ec1a406d3dba65f0bae79054580fb287

    Bug 1393: MacOS: getLocationOnScreen w/ JAWT Parent: Use parent&apos;s unblocking specialization
    
    On MacOS, commit 12eed5d38616d23b6e8e2e5b497dfc2f54d90c90 replaced all
    parent.getLocationOnScreen(..) calls with OSXUtil.GetLocationOnScreen(parentHandle, ..)
    avoiding the EDT + Appkit Deadlock with native parenting.
    
    On MacOS AWT and JAWT are using offscreen CALayer since Java &gt;= 1.7.0,
    therefor the MacOSXJAWTWindow&apos;s native window handle can&apos;t be used to gather
    the screen position via OSXUtil.
    
    However, the JAWT Window specialization MacOSXJAWTWindow implements a non-locking code-path
    and we can decide to use it by querying the general interface OffscreenLayerOption.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>