@@ -55,10 +55,36 @@ private byte[] buildDeadCode() {
5555 ClassDesc .of ("DeadCodePattern" ),
5656 List .of (Classfile .Option .generateStackmap (false ), Classfile .Option .patchDeadCode (false )),
5757 clb -> clb .withMethodBody (
58- "twoReturns" ,
59- MethodTypeDesc .of (ConstantDescs .CD_void ),
60- 0 ,
61- cob -> cob .return_ ().return_ ()));
58+ "twoReturns" ,
59+ MethodTypeDesc .of (ConstantDescs .CD_void ),
60+ 0 ,
61+ cob -> cob .return_ ().return_ ())
62+ .withMethodBody (
63+ "deadJumpInExceptionBlocks" ,
64+ MethodTypeDesc .of (ConstantDescs .CD_void ),
65+ 0 ,
66+ cob -> {
67+ var deadEnd = cob .newLabel ();
68+ cob .goto_ (deadEnd );
69+ var deadStart = cob .newBoundLabel ();
70+ cob .return_ (); //dead code
71+ cob .labelBinding (deadEnd );
72+ cob .return_ ();
73+ var handler = cob .newBoundLabel ();
74+ cob .athrow ();
75+ //exception block before dead code to stay untouched
76+ cob .exceptionCatch (cob .startLabel (), deadStart , handler , ConstantDescs .CD_Throwable );
77+ //exception block after dead code to stay untouched
78+ cob .exceptionCatch (deadEnd , handler , handler , ConstantDescs .CD_Throwable );
79+ //exception block overlapping dead code to cut from right
80+ cob .exceptionCatch (cob .startLabel (), deadEnd , handler , ConstantDescs .CD_Throwable );
81+ //exception block overlapping dead code to from left
82+ cob .exceptionCatch (deadStart , handler , handler , ConstantDescs .CD_Throwable );
83+ //exception block matching dead code to remove
84+ cob .exceptionCatch (deadStart , deadEnd , handler , ConstantDescs .CD_Throwable );
85+ //exception block around dead code to split
86+ cob .exceptionCatch (cob .startLabel (), handler , handler , ConstantDescs .CD_Throwable );
87+ }));
6288 }
6389
6490 @ Test
0 commit comments