Issue Details (XML | Word | Printable)

Key: MACMULTITOUCH-3
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: raner
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
macmultitouch

AttachCurrentThread/DetachCurrentThread causes high CPU load on Mac OS X

Created: 05/Dec/09 09:15 AM   Updated: 04/Jan/10 09:20 PM   Resolved: 04/Jan/10 09:20 PM
Component/s: None
Affects Version/s: None
Fix Version/s: None

Time Tracking:
Original Estimate: 1 hour
Original Estimate - 1 hour
Remaining Estimate: 1 hour
Remaining Estimate - 1 hour
Time Spent: Not Specified
Time Spent - Not Specified

Environment:

Mac OS X 10.5.8, JDK 1.5.0_16


Tags:


 Description  « Hide

The calls to AttachCurrentThread and DetachCurrentThread cause a large number of threads being created and destroyed at a rapid rate. This is an expensive and resource-intensive way of performing callbacks on Mac OS X, and causes a significant increase of the CPU load while the native code is active.
When run in debug mode from Eclipse, the Eclipse UI can hardly keep up with displaying all the threads that are being created and destroyed as soon as activity from the touchpad is recorded. Also during touchpad movements, the CPU load increases to about 50% of the full capacity of my dual-core system.

Alternative implementations could be:

  • moving the call to DetachCurrentThread somewhere else (maybe to ..._deregisterListener?), so that subsequent class to AttachCurrentThread effectively become no-ops
  • setting aside a specific Java thread that receives the callbacks and statically storing the JNIEnv for that thread


waynekeenan added a comment - 05/Dec/09 10:12 PM

AFAIK because MacOSX is calling the C 'mtcallback' function from its 'own thread' the need to attached (and detach) that native OS thread to the JVM can't be avoided in the callback; all docs and examples of C-> Java callbacks I have seen do this. I am assuming that the threads you see being created are these OS threads, but I have not confirmed this myself.

An alternative approach to invoking Java from C in 'mtcallback' via the JNI API might be to instead communicate via a socket.

Happy to hear your thoughts on the above.


waynekeenan added a comment - 04/Jan/10 09:20 PM

perhaps not a bug, but instead an unfortunate side effect of the JNI architecture.