[gui][patch] improvements to single threaded event dispatch

graydon hoare graydon@redhat.com
Tue Jan 18 03:51:00 GMT 2005


hi,

this patch, which I've committed to java-gui-branch, improves the event 
dispatch performance of the recent "single threading" patch I put into 
the AWT peers. there are two major changes here:

  - if the java side is full for "sufficiently long", it checks the
    native side in a non-blocking manner to see if there are pending
    native events. this prevents java-generated events (painting, timers)
    from starving the peer event queue.

  - if the peer side is full for "sufficiently long", it transfers
    control back up to the java side for a moment, to give it a chance to
    drain the java queue.

the latter behavior almost existed in the initial patch, but it used an 
ad-hoc "event batch count" to decide when to transfer control back to 
java. now both behaviors are controlled by time: if 100ms worth of 
processing has elapsed on either side (this is the human perceptual 
latency threshold), the transition occurs.

note that this is *not* the same as saying that the two halves of the 
event loop are polling or "busy waiting". the thread still blocks in the 
native side when there is no event traffic. it simply means that time 
measurements govern the transitions between behavior modes *during* the 
time when there is activity. you could think of it somewhat like a 
timeslice in a multi-threaded program in which the threads might do 
blocking i/o.

(indeed, the need for this patch might be a sensible argument that 
having two threads was a better state of affairs; but I still think I 
prefer this organization, since we have more explicit control over 
scheduling).

-graydon

2005-01-17  Graydon Hoare  <graydon@redhat.com>

	* gnu/awt/xlib/XEventLoop.java: Add non-blocking event mode.
	* gnu/awt/xlib/XToolkit.java: Likewise.
	* gnu/gcj/xlib/XAnyEvent.java: Likewise.
	* gnu/gcj/xlib/natXAnyEvent.cc: Likewise.
	* gnu/java/awt/ClasspathToolkit.java: Likewise.
	* gnu/java/awt/peer/gtk/GtkToolkit.java: Likewise.
	* java/awt/EventQueue.java (getNextEvent):
	Adjust event loop to switch to native mode after 100ms.
	* javax/swing/Timer.java (drainEvents): Reuse Runnable.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkGenericPeer.c
	(Java_gnu_java_awt_peer_gtk_GtkGenericPeer_dispose):
	Wake up event thread.
	* jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
	(Java_gnu_java_awt_peer_gtk_GtkToolkit_iterateNativeQueue):
	Adjust event loop to switch to java mode after 100ms.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: java-gui-single-thread-event-improvements.patch
URL: <http://gcc.gnu.org/pipermail/java-patches/attachments/20050118/7aa88bdd/attachment.ksh>


More information about the Java-patches mailing list