/* Ċ Ġ* ĠL 2 _ JUMP _ IF _ SUB TYPE _ OF _ CONSTANT . java Ċ Ġ* Ġ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 Ċ import Ġcom . avail . descriptor . types . A _ Type . Companion . instance Ċ import Ġcom . avail . descriptor . types . A _ Type . Companion . is Subtype Of Ċ import Ġcom . avail . descriptor . types . A _ Type . Companion . type Intersection Ċ import Ġcom . avail . descriptor . types . Instance Meta Descriptor Ċ 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 Constant Operand Ċ 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 . Register Set Ċ import Ġcom . avail . optimizer . jvm . JVM Translator Ċ import Ġorg . object web . asm . Method Visitor Ċ import Ġorg . object web . asm . Op codes Ċ Ċ /** Ċ Ġ* ĠCondition ally Ġjump , Ġdepending Ġon Ġwhether Ġthe Ġtype Ġto Ġcheck Ġis Ġa Ġsubtype Ġof Ċ Ġ* Ġthe Ġconstant Ġtype . Ċ Ġ* Ċ Ġ* Ġ@ 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 _ SUB TYPE _ OF _ CONSTANT Ġ: ĠL 2 Conditional Jump ( Ċ ĉ L 2 Operand Type . READ _ BOX ED . named (" type Ġto Ġcheck "), Ċ ĉ L 2 Operand Type . CONSTANT . named (" constant Ġtype "), Ċ ĉ L 2 Operand Type . PC . named (" is Ġsubtype ", ĠL 2 Named Operand Type . Purpose . SUCCESS ), Ċ ĉ L 2 Operand Type . PC . named (" not Ġsubtype ", ĠL 2 Named Operand Type . Purpose . FAILURE )) Ċ { Ċ ĉ override Ġfun Ġbranch Reduction ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ register Set : ĠRegister Set , Ċĉ ĉ generator : ĠL 2 Generator ): ĠBranch Reduction Ċ ĉ { Ċĉ ĉ // ĠE limin ate Ġtests Ġdue Ġto Ġtype Ġpropagation . Ċĉ ĉ val Ġtype ToCheck Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġconstant Type Ġ= Ġinstruction . operand < L 2 Constant Operand >( 1 ) Ċĉ ĉ // ĉ ĉ final ĠL 2 Pc Operand Ġis Subtype Ġ= Ġinstruction . operand ( 2 ); Ċ // ĉ ĉ final ĠL 2 Pc Operand Ġnot Subtype Ġ= Ġinstruction . operand ( 3 ); Ċĉ ĉ val Ġexact Type : ĠA _ Basic Object ? Ġ= Ġtype ToCheck . constant OrNull () Ċĉ ĉ return Ġwhen Ċĉ ĉ { Ċĉĉ ĉ exact Type Ġ!== Ġnull Ċĉĉĉĉ ĉ && Ġexact Type . isInstanceOf ( constant Type . constant ) Ġ-> Ċĉĉĉ ĉ Branch Reduction . Always Taken Ċĉĉ ĉ exact Type Ġ!== Ġnull Ġ-> ĠBranch Reduction . Never Taken Ċĉĉ ĉ // ĠIt 's Ġa Ġsubtype , Ġso Ġit Ġmust Ġalways Ġpass Ġthe Ġtype Ġtest . Ċĉĉ ĉ type ToCheck . type (). instance (). is Subtype Of ( constant Type . constant ) Ġ-> Ċĉĉĉ ĉ Branch Reduction . Always Taken Ċĉĉ ĉ // ĠThe Ġtypes Ġdon 't Ġintersect , Ġso Ġit Ġcan 't Ġever Ġpass Ġthe Ġtype Ġtest . Ċĉĉ ĉ type ToCheck . type (). instance () Ċĉĉĉĉ ĉ . type Intersection ( constant Type . constant ). is Bottom Ġ-> Ċĉĉĉ ĉ Branch Reduction . Never Taken Ċĉĉ ĉ else Ġ-> ĠBranch Reduction . Some times Taken Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġpropagate Types ( Ċĉ ĉ instruction : ĠL 2 Instruction , Ċĉ ĉ register Sets : ĠList < Register Set >, Ċĉ ĉ generator : ĠL 2 Generator ) Ċ ĉ { Ċĉ ĉ val Ġtype ToCheck Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġconstant Type Ġ= Ġinstruction . operand < L 2 Constant Operand >( 1 ) Ċĉ ĉ assert ( register Sets . size Ġ== Ġ 2 ) Ċĉ ĉ val Ġis Subtype Set Ġ= Ġregister Sets [ 0 ] Ċĉ ĉ assert ( is Subtype Set . has Type At ( type ToCheck . register ())) Ċĉ ĉ if Ġ( is Subtype Set . has Constant At ( type ToCheck . register ())) Ċĉ ĉ { Ċĉĉ ĉ // ĠThe Ġ* exact * Ġtype Ġis Ġalready Ġknown . Ġ ĠDon 't Ġwe aken Ġit Ġby Ġrecording Ċĉĉ ĉ // Ġtype Ġinformation Ġfor Ġit Ġ( a Ġmeta ). Ċĉ ĉ } Ċĉ ĉ else Ċĉ ĉ { Ċĉĉ ĉ val Ġexisting Meta Ġ= Ġis Subtype Set . type At ( type ToCheck . register ()) Ċĉĉ ĉ val Ġexisting Type : ĠA _ Type Ġ= Ġexisting Meta . instance () Ċĉĉ ĉ val Ġintersection Type Ġ= Ċĉĉĉ ĉ existing Type . type Intersection ( constant Type . constant ) Ċĉĉ ĉ val Ġintersection Meta Ġ= Ċĉĉĉ ĉ Instance Meta Descriptor . instance Meta ( intersection Type ) Ċĉĉ ĉ is Subtype Set . st reng then Tested Type At Put ( Ċĉĉĉ ĉ type ToCheck . register (), Ġintersection Meta ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ 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 Ġtype ToCheck Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġconstant Type Ġ= Ġinstruction . operand < L 2 Constant Operand >( 1 ) Ċĉ ĉ // ĉ ĉ final ĠL 2 Pc Operand Ġis Subtype Ġ= Ġinstruction . operand ( 2 ); Ċ // ĉ ĉ final ĠL 2 Pc Operand Ġnot Subtype Ġ= Ġinstruction . operand ( 3 ); Ċĉ ĉ render P reamble ( instruction , Ġbuilder ) Ċĉ ĉ builder . append (' Ġ') Ċĉ ĉ builder . append ( type ToCheck . register String ()) Ċĉ ĉ builder . append (" ĠâĬ Ĩ Ġ") Ċĉ ĉ builder . append ( constant Type . constant ) Ċĉ ĉ 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 Ġtype ToCheck Ġ= Ġinstruction . operand < L 2 Read Boxed Operand >( 0 ) Ċĉ ĉ val Ġconstant Type Ġ= Ġinstruction . operand < L 2 Constant Operand >( 1 ) Ċĉ ĉ val Ġis Subtype Ġ= Ġinstruction . operand < L 2 Pc Operand >( 2 ) Ċĉ ĉ val Ġnot Subtype Ġ= Ġinstruction . operand < L 2 Pc Operand >( 3 ) ĊĊĉ ĉ // Ġ:: Ġif Ġ( type . is Subtype Of ( constant )) Ġgoto Ġis Subtype ; Ċĉ ĉ // Ġ:: Ġelse Ġgoto Ġnot Subtype ; Ċĉ ĉ translator . load ( method , Ġtype ToCheck . register ()) Ċĉ ĉ translator . literal ( method , Ġconstant Type . constant ) Ċĉ ĉ A _ Type . is Subtype Of Method . generate Call ( method ) Ċĉ ĉ emit Branch ( Ċĉĉ ĉ translator , Ġmethod , Ġinstruction , ĠOp codes . IF NE , Ġis Subtype , Ġnot Subtype ) Ċ ĉ } Ċ } Ċ