1
(I)
NSC88 - 2213 - E009 - 087
87 /08 /01 -- 88 /07 /31
Java deadlock monitor !"#$%& '()!* +,-./0123! * 456789:91;!<=> ?"@A$BC789:97!DEF G.89:9 HIJK%&'(DEFL6M NOPQ!RSTUDE/0V1%&! FWOXYZZ=[\!W]^O_S 1=!`!abcd'(* +efg h i j \ k l ^ K m n opqNrK st9suvwx NrK y9wt7wvzs{|{vz !DE}3 * .~`$ 89:9 GK'! n;* +e\ !opDE}3 * L6V!#6X. vz{|vy 6$DEFG}3\! 89:9 HI!DEF63' L6d6(! vz{|vy1;3 \¡¢!N£¤¥$¦§¨©eª«* -¬3 N .¥®¯r°±² 89:9 $DE}3* G#;³Vf!` ! ´b¯µ¶·¸31op! vz{|vy $* 45¹ºGBC 89:9 !DE F;³»¡·¸31%&!¼ ½¾¿ ÀÁ ÃÄ* +eopDE}3* ůr¾Vf! ´RÆ -!Ç È.7 7
(Keywords: distributed shared mem-ory, multi-thread, concurrency control, Java, deadlock, monitor)
There are many synchronized mechanisms an-nounced now, and different platforms or pro-gramming languages have their own suitable solutions. But there are no proper solutions for Java. Java has its own synchronized mechanism, but it is not truly concurrent, it supports a lim-ited form of currency. A programmer must take care of many details when developing concurrent applications. Even there are some solutions are designed for Java, and also let a programmer can develop concurrent applications more conven-iently, but the poor performance is the common problem. Monitor is a technique used in concur-rency control for a long time, Java synchroniza-tion mechanism also take advantages of this
concept a little, but is not enough. This paper will declare the disadvantage of other solutions and will also introduce an approach for enhanc-ing this mechanism in programmenhanc-ing level bye use of our monitors. We will provide libraries and a preprocessor that are helping for concur-rency control. Finally, we will compare our so-lution with others in performance and the com-plexity of coding style.
7 7 $ Java GVHI!DEF$ÉÊGË KÌ(ÍÊ'6”wait”Î'(6”notify”,K· '(Ï! monitoraÌ(ÍÊËO$Ð ÑÒsynchronized ! method © block Ó^; K!ÉÊ.Wait ¾ notify Ì( method 6 ÔÕd Object (Ö×J6»Ø¸'(Ö × Ó ! method © block Ù ;ÚÐÑÒ synchronizedÛK=¬3ÜÖ×Ýg h°ÞSÜÖ×!”lock”^;¬3ßJ r Ú à á â S Ü Ö×!”lock”Nãdظ threadÝ^rÔäÍÊ./0ÜF6(Ï !DEF1;¬3 NX N¥$ å* G©e debug GÙ\æçabèé K!pêrëÒìí!<=î/K ï(ð'ñ(Ö×ËK' condition vari-ableòÊ inter-nested ! synchronized method óôÝ”lock”NrÚõAöËOÊ÷à á! signalïQ$ wait !¤nø ¾ù°ú;³ûü.
7 7 $` Java G! ´ýGuard-based system 6ÇÈþ3S!· CJava CORRELATE ; ³ active object [8,12,13,14,15]Vù#6å* ª «èéNépê6X6Ü !#.Ü1;r6/0 MgK(Í!N! ¾É `! ÜKO6Q$Êû( Ê!©e6;'(ÏÛÊ daemon3 Ü !¯rÚ3 R0'(ÍÊ!Ü Î'(<=!¥"#$d¸Ý R ¾!ÍÊN¤¥63 busy waiting ©e63 wait-notify ! R¾ V1=[! context switch 'rNY1 ;¤¥6'FË=63 guard-based system +!VÙNr\.
2 ì$K!DEFpd monitor 6Vý'(ÉÊ\!FV<= ! #0$D'(Ý!"ËrK'( ;$ monitor "#K=C$ monitor !Ý%KVf!Q$ M!ÊÜÝ(&'C$ monitor ! J=ÚàáâS$ monitor "!õ A monitor lock Å^;C$.Monitor !Î( '( )6MK *+(condition variable) ;³¾V,!Ì(ÍÊ”wait”¾”signal”Û $ monitor "!pì"-! ¤n. Ôä ÝJràá$û( *+ bõAq lock !/K0âSÚVf! ô1( signal ).
7 7 1;r2 monitor 6/0 Java HI! DEFJ63 monitor !aÒ!$ 3G\èé4b$ -V context switch5Ç guard-based system 6=7! 1 ; Ü < = J689 Java HI:; monitor !DEF¬V;K( * +b;R inter-nested !óôaNrK !pê·Ü#; Java op!}3 <¤¥$å* !=éúG©e$>§ -ÙrÇ3 Java î 1%&!F6 ! ?@V -NrÇÈ. A [5] Ó ;BC'(DH! monitor rKïNDù°ú! queue 3 EFGAND!ï queue H0 entry-queuecondition-queuesignaler-queue ; ³ waiting-queueVý! queue Kö H 0 entry-queue signaler-queue ; ³ waiting-queue;Iö queue R qND! monitor60JKLMN (starvation)O !$Ú signal ÅV ;$ monitor NÚPÍS!EF \Q! ;³gO$ monitor " - ! ; R Q ! SaõA monitor lockKÌTUgVW'6ñ( monitor "V queue !!ù°úg=X Î'(6 entry queue !ù°úg61 K queue !Y!1;PQ¬3! monitor ËKÌ'6 blocking monitor Î' 6 non-blocking monitor.
Blocking monitorZ!6$monitor"! $ signal û( *+Å=[GÚ signal ! \=àá$ signaler queueÓ1;ö queue !ù°ú 0 Wp>Sp>Ep(] waiting queue ù°ú^ d signaler queue ^d entry queue).,_! non-blocking monitor6$ signal û( * +Å=`àá$condition queue ÓaS
waiting queueÓbc")a\; Ôä$ monitor V1=!Ê1;Vù °ú0 Sp>Wp>Ep.ÜÌ monitor ÆKÆ! #$ blocking monitor Ó$ monitor "! û( pê!Ý%$û( condition queue ÓbcÜ !;N a[G a$ non-blocking monitor ÓQ$!;'º signal ! *+aN=àáN$bcÜ ! $de")C$ monitor ÝfZg= R!ÍÊ;gÜ monitor 6ßKÚ B*#hK;A@!C$ monitorß Jg")$àá$û( *+. ;i=2'(jÛ! Monitor· context switchÇÈY!abg NrÚBS!J ;2 non-blocking monitor.
7 7 $ nested monitor call -KÌO [2]:
1. Intra-nested monitor call
D'(Ö×! monitor lock ÚD'( =kº
2. Inter-nested monitor call =kND! monitor lock a. Open call Û=loÜmonitor aC$m '( monitor =õA 1ÞS! monitor lock. b. Close call $ÞSND! monitor lock ÅËKgàá$û( *+!Ý%^r¯1ÞS! lockU-õq.
n'!nested callË=¯ lock counter o'J ;Janò nested call $loû( monitorJ=pV counterV6 close callP=pV monitor Ö×bSS nested callqrî ! monitor.`loÜ monitor ! rs.N$qrî°! monitor ÝKOKVf!±Q$Ü monitor "tNO[G_rC$Ü monitorg$ '( queue ÓuGv/Ü$¾!ï queue 'w! monitor xKy queue>J condition queue (Vfï queue Ù6 queue6KÌ monitor 6K3 !N$o$uG! queue ÅVù°ú *Ò·1]:
Signal Characteristics Priority
Blocking
Signal and Urgent Wait Ep < Sp < Rp < Wp Priority Blocking (PB) Non-Blocking
Signal and Continue Ep < Rp < Wp < Sp Priority Non-locking (PNB)
3 Vý Rp ])zo! queue !ù°ú1 ; r{|}VÁ0$S inter nested monitor call ÅÜO~Qr î°! monitor ~L6NO[G¤T×!r Ü monitor;LpêN'! F1;Ü queue!ù°ú Rp '=Yd Wp#O^d Sp!JR^d Sp1;JrOÒÜ! F. H 1Rq !K¾VfÆ! nR(ÇÈV1S!+¢]w q! nùd`!Vf n¤¥6$ -©e* å!=éúG r¯ $'"pd(!,G. ظh= !Vî/N( 6ÏF!V1ì!¤n£¬ 3e1;hKÁ6= ¬3ÇÈ N!FL6`$ Java G! ´ #6=k=K!Vå* !=úr z^>§Né_ #6=kO ! å* Oåqé4!* Vf ZNr\/ÜB` Java 1%&! DEF$* 45!¹ºG%&¼ ½ * +e¬3;_S å;³N§ !>Ü(¬3e;$NB*¬3 ·D¬3î Java 1%&!DEF '{Ôä¬31+! monitor. !
[1].Scott Oaks and Henry Wong, “Java Threads”, O’REILLY & Associates, Inc. 1997
[2]. Andrews, Gregory R. “Concurrent pro-gramming, principles and practice”, New York Benjamin Cummings, 1991
[3].Andrews S. Tanenbaum. “Distributed Oper-ating Systems”, Prentice-Hall, Inc. A Simon & Schuster Company, 1995.
[4]Andrews S. Tanenbaum. “Modern Operating Systems”, Prentice-Hall, Inc. A Simon &
Schuster Company, 1992.
[5].Peter A. Buhr and Michel Fortier. “Monitor Classification,” ACM Computing Surveys, Vol. 27, No. 1, March 1995. pp. 69-73, pp. 89.
[6].Mukesh Singhal. “Deadlock Detection in Distributed Systems,” IEEE Computer, No-vember 1989. pp. 37-40
[7].Young Man Kim; Ten Hwang Lai; Sounda-rajan, N. “Efficient distributed deadlock de-tection and resolution using probes, tokens, and barriers”, IEEE Parallel and Distributed Systems, 1997. Proceedings. pp. 584-590.
[8].Martin Carroll, “Active Objects Made Easy,” PRACTICE AND EXPERIENCE, Vol. 28(1), 1-21, January 1998. pp. 1-5, pp. 13-20.
[9].Jose R. Gonzalez de Mendivil, Federico Fa-rina, Carlos F. Alastruey. “ A safe distributed deadlock resolution algorithm”, Journal of Systems Architecture 1998. pp. 887-891
[10].Miyoshi, A.; Kitayama, T.; Tokuda, H. “Implementation and Evaluation of Real-Time Java Threads”, Real-Time Sys-tems Symposium, 1997. Proceedings., The 18th IEEE, pp. 166-173
[11].Demartini, C.; Sisto, R. “Static analysis of Java multithreaded and distributed applica-tions”, IEEE Software Engineering for Par-allel and Distributed Systems, 1998. Pro-ceedings. pp. 215-221.
4 [12].Carlos A. Varela, Gul A. Agha. “What after
Java? From objects to actors”, Computer Networks and ISDN Systems 1998. pp. 573-576.
[13].Gianpaolo Cugola and Carlo Ghezzi. “Cjava: Introduction concurrent Objects in Java” Dipartimento di Elettronica e Infor-mazione, Politecnico di Milano.
[14].Chao-Hsin Lin; Elrad, T. “An enhanced reflective architecture for adaptation of the object-oriented language/software”, IEEE Software Engineering Conference, 1998. Proceedings. pp. 20-24.
[15].Ciaran McHale “Synchronization in Con-current Object-oriented Languages: Expres-sive Power, Genericity and Inheritance”, A thesis submitted to University of Dublin, Trinity College.
[16].http://java.sun.com/docs/books/jls/html/ind ex.html
[17].C. H. Wu “Enhancing Thread Synchroni-zation Mechanism of Java“ Master Thesis, Institute of Computer and Information Sci-ence, College of Electrical Engineering and Computer Science, National Chiao Tung University, June 1998.