/* Ċ Ġ* ĠL 2 _ JUMP _ IF _ OBJECTS _ EQUAL . kt Ċ Ġ* ĠCopyright ĠÂ© Ġ 1 9 9 3 - 2 0 2 0 , ĠThe ĠAv ail ĠFoundation , ĠLLC . Ċ Ġ* ĠAll Ġrights Ġreserved . Ċ Ġ* Ċ Ġ* ĠRedistribution Ġand Ġuse Ġin Ġsource Ġand Ġbinary Ġforms , Ġwith Ġor Ġwithout Ċ Ġ* Ġmodification , Ġare Ġpermitted Ġprovided Ġthat Ġthe Ġfollowing Ġconditions Ġare Ġmet : Ċ Ġ* Ċ Ġ* Ġ* ĠRedistributions Ġof Ġsource Ġcode Ġmust Ġretain Ġthe Ġabove Ġcopyright Ġnotice , Ġthis Ċ Ġ* ĠĠ Ġlist Ġof Ġconditions Ġand Ġthe Ġfollowing Ġdisclaimer . Ċ Ġ* Ċ Ġ* Ġ* ĠRedistributions Ġin Ġbinary Ġform Ġmust Ġreproduce Ġthe Ġabove Ġcopyright Ġnotice , Ċ Ġ* ĠĠ Ġthis Ġlist Ġof Ġconditions Ġand Ġthe Ġfollowing Ġdisclaimer Ġin Ġthe Ġdocumentation Ċ Ġ* ĠĠ Ġand / or Ġother Ġmaterials Ġprovided Ġwith Ġthe Ġdistribution . Ċ Ġ* Ċ Ġ* Ġ* ĠNeither Ġthe Ġname Ġof Ġthe Ġcopyright Ġholder Ġnor Ġthe Ġnames Ġof Ġthe Ġcontributors Ċ Ġ* ĠĠ Ġmay Ġbe Ġused Ġto Ġendorse Ġor Ġpromote Ġproducts Ġderived Ġfrom Ġthis Ġsoftware Ċ Ġ* ĠĠ Ġwithout Ġspecific Ġprior Ġwritten Ġpermission . Ċ Ġ* Ċ Ġ* ĠTHIS ĠSOFTWARE ĠIS ĠPROVIDED ĠBY ĠTHE ĠCOPYRIGHT ĠHOLDERS ĠAND ĠCONTRIBUTORS Ġ" AS ĠIS " Ċ Ġ* ĠAND ĠANY ĠEXPRESS ĠOR ĠIMPLIED ĠWARRANTIES , ĠINCLUDING , ĠBUT ĠNOT ĠLIMITED ĠTO , ĠTHE Ċ Ġ* ĠIMPLIED ĠWARRANTIES ĠOF ĠMERCHANTABILITY ĠAND ĠFITNESS ĠFOR ĠA ĠPARTICULAR ĠPURPOSE Ċ Ġ* ĠARE ĠDISCLAIMED . ĠIN ĠNO ĠEVENT ĠSHALL ĠTHE ĠCOPYRIGHT ĠHOLDER ĠOR ĠCONTRIBUTORS ĠBE Ċ Ġ* ĠLIABLE ĠFOR ĠANY ĠDIRECT , ĠINDIRECT , ĠINCIDENTAL , ĠSPECIAL , ĠEXEMPLARY , ĠOR Ċ Ġ* ĠCONSEQUENTIAL ĠDAMAGES Ġ( INCLUDING , ĠBUT ĠNOT ĠLIMITED ĠTO , ĠPROCUREMENT ĠOF Ċ Ġ* ĠSUBSTITUTE ĠGOODS ĠOR ĠSERVICES ; ĠLOSS ĠOF ĠUSE , ĠDATA , ĠOR ĠPROFITS ; ĠOR ĠBUSINESS Ċ Ġ* ĠINTERRUPTION ) ĠHOWEVER ĠCAUSED ĠAND ĠON ĠANY ĠTHEORY ĠOF ĠLIABILITY , ĠWHETHER ĠIN Ċ Ġ* ĠCONTRACT , ĠSTRICT ĠLIABILITY , ĠOR ĠTORT Ġ( INCLUDING ĠNEGLIGENCE ĠOR ĠOTHERWISE ) Ċ Ġ* ĠARISING ĠIN ĠANY ĠWAY ĠOUT ĠOF ĠTHE ĠUSE ĠOF ĠTHIS ĠSOFTWARE , ĠEVEN ĠIF ĠADVISED ĠOF ĠTHE Ċ Ġ* ĠPOSSIBILITY ĠOF ĠSUCH ĠDAMAGE . Ċ Ġ*/ Ċ package Ġcom . avail . interpreter . level Two . operation Ċ Ċ import Ġcom . avail . descriptor . representation . A _ Basic Object Ċ import Ġcom . avail . descriptor . types . A _ Type . Companion . type Intersection Ċ import Ġcom . avail . interpreter . level Two . L 2 Instruction Ċ import Ġcom . avail . interpreter . level Two . L 2 Named Operand Type Ċ import Ġcom . avail . interpreter . level Two . L 2 Operand Type Ċ import Ġcom . avail . interpreter . level Two . operand . L 2 Pc Operand Ċ import Ġcom . avail . interpreter . level Two . operand . L 2 Read Boxed Operand Ċ import Ġcom . avail . optimizer . L 2 Generator Ċ import Ġcom . avail . optimizer . L 2 Value Manifest Ċ import Ġcom . avail . optimizer . Register Set Ċ import Ġcom . avail . optimizer . jvm . JVM Translator Ċ import Ġorg . object web . asm . Method Visitor Ċ import Ġorg . object web . asm . Op codes Ċ Ċ /** Ċ Ġ* ĠBranch Ġbased Ġon Ġwhether Ġthe Ġtwo Ġvalues Ġare Ġequal Ġto Ġeach Ġother . Ċ Ġ* Ċ Ġ* Ġ@ author ĠMark Ġvan ĠG ul ik Ġ& lt ; mark @ avail lang . org & gt ; Ċ Ġ* Ġ@ author ĠT odd ĠL ĠSmith Ġ& lt ; tod d @ avail lang . org & gt ; Ċ Ġ*/ Ċ object ĠL 2 _ JUMP _ IF _ OBJECTS _ EQUAL Ġ: ĠL 2 Conditional Jump ( Ċ ĉ L 2 Operand Type . READ _ BOX ED . named (" first Ġvalue "), Ċ ĉ L 2 Operand Type . READ _ BOX ED . named (" second Ġvalue "), Ċ ĉ L 2 Operand Type . PC . named (" is Ġequal ", ĠL 2 Named Operand Type . Purpose . SUCCESS ), Ċ ĉ L 2 Operand Type . PC . named (" is Ġnot Ġequal ", ĠL 2 Named Operand Type . Purpose . FAILURE )) Ċ { Ċ ĉ override Ġfun Ġinstruction Was Added ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ manifest : ĠL 2 Value Manifest ) Ċ ĉ { Ċĉ ĉ assert ( this Ġ== Ġinstruction . operation ()) Ċĉ ĉ val Ġfirst Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġsecond Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 1 ) Ċĉ ĉ val Ġif Equal Ġ= Ġinstruction . operand < L 2 Pc Operand >( 2 ) Ċ // ĉ ĉ val Ġif NotEqual Ġ= Ġinstruction . operand < L 2 Pc Operand >( 3 ) ĊĊĉ ĉ super . instruction Was Added ( instruction , Ġmanifest ) ĊĊĉ ĉ // ĠMerge Ġthe Ġsource Ġand Ġdestination Ġonly Ġalong Ġthe Ġif Equal Ġbranch . Ċĉ ĉ if Equal . manifest (). merge Existing Semantic Values ( Ċĉĉ ĉ first . semantic Value (), Ġsecond . semantic Value ()) Ċ ĉ } ĊĊ ĉ override Ġfun Ġbranch Reduction ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ register Set : ĠRegister Set , Ċĉ ĉ generator : ĠL 2 Generator ): ĠBranch Reduction Ċ ĉ { Ċĉ ĉ val Ġfirst Reg Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġsecond Reg Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 1 ) Ċĉ ĉ // ĉ ĉ final ĠL 2 Pc Operand Ġif Equal Ġ= Ġinstruction . operand ( 2 ); Ċ // ĉ ĉ final ĠL 2 Pc Operand Ġnot Equal Ġ= Ġinstruction . operand ( 3 ); Ċĉ ĉ val Ġconstant 1 : ĠA _ Basic Object ? Ġ= Ġfirst Reg . constant OrNull () Ċĉ ĉ val Ġconstant 2 : ĠA _ Basic Object ? Ġ= Ġsecond Reg . constant OrNull () Ċĉ ĉ return Ġwhen Ċĉ ĉ { Ċĉĉ ĉ constant 1 Ġ!== Ġnull Ċĉĉĉĉ ĉ && Ġconstant 2 Ġ!== Ġnull Ċĉĉĉĉ ĉ && Ġconstant 1 . equals ( constant 2 ) Ġ-> Ċĉĉĉ ĉ Branch Reduction . Always Taken Ċĉĉ ĉ constant 1 Ġ!== Ġnull Ġ&& Ġconstant 2 Ġ!== Ġnull Ġ-> Ċĉĉĉ ĉ Branch Reduction . Never Taken Ċĉĉ ĉ // ĠThey Ġcan 't Ġbe Ġequal . Ċĉĉ ĉ first Reg . type (). type Intersection ( second Reg . type ()). is Bottom Ġ-> Ċĉĉĉ ĉ Branch Reduction . Never Taken Ċĉĉ ĉ // ĠOtherwise Ġit 's Ġstill Ġcont ing ent . Ċĉĉ ĉ else Ġ-> ĠBranch Reduction . Some times Taken Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġpropagate Types ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ register Sets : ĠList < Register Set >, Ċĉ ĉ generator : ĠL 2 Generator ) Ċ ĉ { Ċĉ ĉ val Ġfirst Reg Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġsecond Reg Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 1 ) Ċĉ ĉ assert ( register Sets . size Ġ== Ġ 2 ) Ċĉ ĉ // ĉ ĉ final ĠRegister Set Ġfall Through Set Ġ= Ġregister Sets . get ( 0 ); Ċĉ ĉ val Ġpost Jump Set Ġ= Ġregister Sets [ 1 ] ĊĊĉ ĉ // ĠIn Ġthe Ġpath Ġwhere Ġthe Ġregisters Ġcompared Ġequal , Ġwe Ġcan Ġde duce Ġthat Ċĉ ĉ // Ġboth Ġregisters ' Ġorigin Ġregisters Ġmust Ġbe Ġconstr ained Ġto Ġthe Ġtype Ċĉ ĉ // Ġintersection Ġof Ġthe Ġtwo Ġregisters . Ċĉ ĉ val Ġintersection Ġ= Ċĉĉ ĉ post Jump Set . type At ( first Reg . register ()). type Intersection ( Ċĉĉĉ ĉ post Jump Set . type At ( second Reg . register ())) Ċĉ ĉ post Jump Set . st reng then Tested Type At Put ( Ċĉĉ ĉ first Reg . register (), Ġintersection ) Ċĉ ĉ post Jump Set . st reng then Tested Type At Put ( Ċĉĉ ĉ second Reg . register (), Ġintersection ) ĊĊĉ ĉ // ĠFurthermore , Ġif Ġone Ġregister Ġis Ġa Ġconstant , Ġthen Ġin Ġthe Ġpath Ġwhere Ċĉ ĉ // Ġthe Ġregisters Ġcompared Ġequal Ġwe Ġcan Ġde duce Ġthat Ġboth Ġregisters ' Ċĉ ĉ // Ġorigin Ġregisters Ġhold Ġthat Ġsame Ġconstant . Ċĉ ĉ if Ġ( post Jump Set . has Constant At ( first Reg . register ())) Ċĉ ĉ { Ċĉĉ ĉ post Jump Set . st reng then Tested Value At Put ( Ċĉĉĉ ĉ second Reg . register (), Ċĉĉĉ ĉ post Jump Set . constant At ( first Reg . register ())) Ċĉ ĉ } Ċĉ ĉ else Ġif Ġ( post Jump Set . has Constant At ( second Reg . register ())) Ċĉ ĉ { Ċĉĉ ĉ post Jump Set . st reng then Tested Value At Put ( Ċĉĉĉ ĉ first Reg . register (), Ċĉĉĉ ĉ post Jump Set . constant At ( second Reg . register ())) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġappend To With Warnings ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ desired Types : ĠSet < L 2 Operand Type >, Ċĉ ĉ builder : ĠStringBuilder , Ċĉ ĉ warning Style Change : Ġ( Boolean ) Ġ-> ĠUnit ) Ċ ĉ { Ċĉ ĉ assert ( this Ġ== Ġinstruction . operation ()) Ċĉ ĉ val Ġfirst Ġ= Ċĉĉ ĉ instruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġsecond Ġ= Ċĉĉ ĉ instruction . operand < L 2 Read Boxed Operand >( 1 ) Ċĉ ĉ // ĉ ĉ final ĠL 2 Pc Operand Ġif Equal Ġ= Ġinstruction . operand ( 2 ); Ċ // ĉ ĉ final ĠL 2 Pc Operand Ġif NotEqual Ġ= Ġinstruction . operand ( 3 ); Ċĉ ĉ render P reamble ( instruction , Ġbuilder ) Ċĉ ĉ builder . append (' Ġ') Ċĉ ĉ builder . append ( first . register String ()) Ċĉ ĉ builder . append (" Ġ= Ġ") Ċĉ ĉ builder . append ( second . register String ()) Ċĉ ĉ render Oper ands Starting At ( instruction , Ġ 2 , Ġdesired Types , Ġbuilder ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġtranslate To JVM ( Ċĉ ĉ translator : ĠJVM Translator , Ċĉ ĉ method : ĠMethod Visitor , Ċĉ ĉ instruction : ĠL 2 Instruction ) Ċ ĉ { Ċĉ ĉ val Ġfirst Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġsecond Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 1 ) Ċĉ ĉ val Ġif Equal Ġ= Ġinstruction . operand < L 2 Pc Operand >( 2 ) Ċĉ ĉ val Ġif NotEqual Ġ= Ġinstruction . operand < L 2 Pc Operand >( 3 ) ĊĊĉ ĉ // Ġ:: Ġif Ġ( first . equals ( second )) Ġgoto Ġif Equal ; Ċĉ ĉ // Ġ:: Ġelse Ġgoto Ġnot Equal ; Ċĉ ĉ translator . load ( method , Ġfirst . register ()) Ċĉ ĉ translator . load ( method , Ġsecond . register ()) Ċĉ ĉ A _ Basic Object . equals Method . generate Call ( method ) Ċĉ ĉ emit Branch ( translator , Ġmethod , Ġinstruction , ĠOp codes . IF NE , Ġif Equal , Ġif NotEqual ) Ċ ĉ } Ċ } Ċ