1*055d4590SKeyi Gui<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 2*055d4590SKeyi Gui 3*055d4590SKeyi Gui<html> 4*055d4590SKeyi Gui <head> 5*055d4590SKeyi Gui <title>Dalvik bytecode constraints</title> 6*055d4590SKeyi Gui <link rel=stylesheet href="dalvik-constraints.css"> 7*055d4590SKeyi Gui </head> 8*055d4590SKeyi Gui 9*055d4590SKeyi Gui <body> 10*055d4590SKeyi Gui 11*055d4590SKeyi Gui <h1>Dalvik bytecode constraints</h1> 12*055d4590SKeyi Gui 13*055d4590SKeyi Gui<!-- 14*055d4590SKeyi Gui <h1>General integrity constraints</h1> 15*055d4590SKeyi Gui 16*055d4590SKeyi Gui <table> 17*055d4590SKeyi Gui <tr> 18*055d4590SKeyi Gui <th> 19*055d4590SKeyi Gui Identifier 20*055d4590SKeyi Gui </th> 21*055d4590SKeyi Gui 22*055d4590SKeyi Gui <th> 23*055d4590SKeyi Gui Description 24*055d4590SKeyi Gui </th> 25*055d4590SKeyi Gui </tr> 26*055d4590SKeyi Gui 27*055d4590SKeyi Gui <tr> 28*055d4590SKeyi Gui <td> 29*055d4590SKeyi Gui A1 30*055d4590SKeyi Gui </td> 31*055d4590SKeyi Gui 32*055d4590SKeyi Gui <td> 33*055d4590SKeyi Gui The magic number of the DEX file must be "dex\n035\0". 34*055d4590SKeyi Gui </td> 35*055d4590SKeyi Gui </tr> 36*055d4590SKeyi Gui 37*055d4590SKeyi Gui <tr> 38*055d4590SKeyi Gui <td> 39*055d4590SKeyi Gui A1 40*055d4590SKeyi Gui </td> 41*055d4590SKeyi Gui 42*055d4590SKeyi Gui <td> 43*055d4590SKeyi Gui The checksum must be an Adler-32 checksum of the whole file contents 44*055d4590SKeyi Gui except magic and checksum field. 45*055d4590SKeyi Gui </td> 46*055d4590SKeyi Gui </tr> 47*055d4590SKeyi Gui 48*055d4590SKeyi Gui 49*055d4590SKeyi GuiThe signature must be a SHA-1 hash of the whole file contents except magic, 50*055d4590SKeyi Guichecksum, and signature. 51*055d4590SKeyi Gui 52*055d4590SKeyi GuiThe file_size must match the actual file size in bytes. 53*055d4590SKeyi Gui 54*055d4590SKeyi GuiThe header_size must have the value 0x70. 55*055d4590SKeyi Gui 56*055d4590SKeyi GuiThe endian_tag must have either the value ENDIAN_CONSTANT or 57*055d4590SKeyi GuiREVERSE_ENDIAN_CONSTANT. 58*055d4590SKeyi Gui 59*055d4590SKeyi GuiFor each of the link, string_ids, type_ids, proto_ids, field_ids, method_ids, class_defs 60*055d4590SKeyi Guiand data sections, the offset and size fields must be either both zero or both 61*055d4590SKeyi Guinon-zero. In the latter case, the offset must be four-byte-aligned. 62*055d4590SKeyi Gui 63*055d4590SKeyi GuiAll offset fields in the header except map_off must be four-byte-aligned. 64*055d4590SKeyi Gui 65*055d4590SKeyi GuiThe map_off field must be either zero or point into the data section. In the 66*055d4590SKeyi Guilatter case, the data section must exist. 67*055d4590SKeyi Gui 68*055d4590SKeyi GuiNone of the link, string_ids, type_ids, proto_ids, field_ids, method_ids, class_defs 69*055d4590SKeyi Guiand data sections must overlap each other or the header. 70*055d4590SKeyi Gui 71*055d4590SKeyi GuiIf a map exists, then each map entry must have a valid type. Each type may 72*055d4590SKeyi Guiappear at most once. 73*055d4590SKeyi Gui 74*055d4590SKeyi GuiIf a map exists, then each map entry must have a nonzero offset and size. The 75*055d4590SKeyi Guioffset must point into the corresponding section of the file (i.e. a 76*055d4590SKeyi Guistring_id_item must point into the string_ids section) and the explicit or 77*055d4590SKeyi Guiimplicit size of the item must match the actual contents and size of the 78*055d4590SKeyi Guisection. 79*055d4590SKeyi Gui 80*055d4590SKeyi GuiIf a map exists, then the offset of map entry n+1 must be greater or equal to 81*055d4590SKeyi Guithe offset of map entry n plus then size of map entry n. This implies 82*055d4590SKeyi Guinon-overlapping entries and low-to-high ordering. 83*055d4590SKeyi Gui 84*055d4590SKeyi GuiThe following types of entries must have an offset that is 85*055d4590SKeyi Guifour-byte-aligned: string_id_item, type_id_item, proto_id_item, field_id_item, 86*055d4590SKeyi Guimethod_id_item, class_def_item, type_list, code_item, 87*055d4590SKeyi Guiannotations_directory_item. 88*055d4590SKeyi Gui 89*055d4590SKeyi GuiFor each string_id_item, the string_data_off field must contain a valid 90*055d4590SKeyi Guireference into the data section. For the referenced string_data_item, the data 91*055d4590SKeyi Guifield must contain a valid MUTF-8 string, and the utf16_size must match the 92*055d4590SKeyi Guidecoded length of the string. 93*055d4590SKeyi Gui 94*055d4590SKeyi GuiFor each type_id_item, the desciptor_idx field must contain a valid reference 95*055d4590SKeyi Guiinto the string_ids list. The referenced string must be a valid type descriptor. 96*055d4590SKeyi Gui 97*055d4590SKeyi GuiFor each proto_id_item, the shorty_idx field must contain a valid reference 98*055d4590SKeyi Guiinto the string_ids list. The referenced string must be a valid shorty descriptor. 99*055d4590SKeyi GuiAlso, the return_type_idx field must be a valid index into the type_ids section, 100*055d4590SKeyi Guiand the parameters_off field must be either zero or a valid offset pointing 101*055d4590SKeyi Guiinto the data section. If nonzero, the parameter list must not contain any void 102*055d4590SKeyi Guientries. 103*055d4590SKeyi Gui 104*055d4590SKeyi GuiFor each field_id_item, both the class_idx and type_idx fields must be a valid 105*055d4590SKeyi Gui indices into the 106*055d4590SKeyi Guitype_ids list. The entry referenced by class_idx must be a non-array reference type. 107*055d4590SKeyi GuiIn addition, the name_idx field must be a valid reference into the string_ids 108*055d4590SKeyi Guisection, and the contents of the referenced entry must conform to the MemberName 109*055d4590SKeyi Guispecification. 110*055d4590SKeyi Gui 111*055d4590SKeyi GuiFor each method_id_item, the class_idx field must be a valid index into the 112*055d4590SKeyi Guitype_ids section, and the 113*055d4590SKeyi Guireferenced entry must be a non-array reference type. The proto_id field must 114*055d4590SKeyi Guibe a valid reference into the proto_ids list. The name_idx field must be a 115*055d4590SKeyi Guivalid reference into the string_ids 116*055d4590SKeyi Guisection, and the contents of the referenced entry must conform to the MemberName 117*055d4590SKeyi Guispecification. 118*055d4590SKeyi Gui 119*055d4590SKeyi GuiFor each class_def_item, ... 120*055d4590SKeyi Gui 121*055d4590SKeyi GuiFor each field_id_item, the class_idx field must be a valid index into the 122*055d4590SKeyi Guitype_ids list. The referenced entry must be a non-array reference type. 123*055d4590SKeyi Gui 124*055d4590SKeyi Gui... 125*055d4590SKeyi Gui 126*055d4590SKeyi Gui--> 127*055d4590SKeyi Gui 128*055d4590SKeyi Gui <h2> 129*055d4590SKeyi Gui Static constraints 130*055d4590SKeyi Gui </h2> 131*055d4590SKeyi Gui 132*055d4590SKeyi Gui <p> 133*055d4590SKeyi Gui Static constraints are constraints on individual elements of the bytecode. 134*055d4590SKeyi Gui They usually can be checked without employing control or data-flow analysis 135*055d4590SKeyi Gui techniques. 136*055d4590SKeyi Gui </p> 137*055d4590SKeyi Gui 138*055d4590SKeyi Gui <table> 139*055d4590SKeyi Gui <tr> 140*055d4590SKeyi Gui <th> 141*055d4590SKeyi Gui Identifier 142*055d4590SKeyi Gui </th> 143*055d4590SKeyi Gui 144*055d4590SKeyi Gui <th> 145*055d4590SKeyi Gui Description 146*055d4590SKeyi Gui </th> 147*055d4590SKeyi Gui 148*055d4590SKeyi Gui <th> 149*055d4590SKeyi Gui Spec equivalent 150*055d4590SKeyi Gui </th> 151*055d4590SKeyi Gui </tr> 152*055d4590SKeyi Gui 153*055d4590SKeyi Gui <tr> 154*055d4590SKeyi Gui <td> 155*055d4590SKeyi Gui A1 156*055d4590SKeyi Gui </td> 157*055d4590SKeyi Gui 158*055d4590SKeyi Gui <td> 159*055d4590SKeyi Gui The <code>insns</code> array must not be empty. 160*055d4590SKeyi Gui </td> 161*055d4590SKeyi Gui 162*055d4590SKeyi Gui <td> 163*055d4590SKeyi Gui 4.8.1.1 164*055d4590SKeyi Gui </td> 165*055d4590SKeyi Gui </tr> 166*055d4590SKeyi Gui 167*055d4590SKeyi Gui <tr> 168*055d4590SKeyi Gui <td> 169*055d4590SKeyi Gui A2 170*055d4590SKeyi Gui </td> 171*055d4590SKeyi Gui 172*055d4590SKeyi Gui <td> 173*055d4590SKeyi Gui The first opcode in the <code>insns</code> array must have index zero. 174*055d4590SKeyi Gui </td> 175*055d4590SKeyi Gui 176*055d4590SKeyi Gui <td> 177*055d4590SKeyi Gui 4.8.1.3 178*055d4590SKeyi Gui </td> 179*055d4590SKeyi Gui </tr> 180*055d4590SKeyi Gui 181*055d4590SKeyi Gui <tr> 182*055d4590SKeyi Gui <td> 183*055d4590SKeyi Gui A3 184*055d4590SKeyi Gui </td> 185*055d4590SKeyi Gui 186*055d4590SKeyi Gui <td> 187*055d4590SKeyi Gui The <code>insns</code> array must only contain valid Dalvik opcodes. 188*055d4590SKeyi Gui </td> 189*055d4590SKeyi Gui 190*055d4590SKeyi Gui <td> 191*055d4590SKeyi Gui 4.8.1.4 192*055d4590SKeyi Gui </td> 193*055d4590SKeyi Gui </tr> 194*055d4590SKeyi Gui 195*055d4590SKeyi Gui <tr> 196*055d4590SKeyi Gui <td> 197*055d4590SKeyi Gui A4 198*055d4590SKeyi Gui </td> 199*055d4590SKeyi Gui 200*055d4590SKeyi Gui <td> 201*055d4590SKeyi Gui The index of instruction <code>n+1</code> must equal the index of 202*055d4590SKeyi Gui instruction <code>n</code> plus the length of instruction 203*055d4590SKeyi Gui <code>n</code>, taking into account possible operands. 204*055d4590SKeyi Gui </td> 205*055d4590SKeyi Gui 206*055d4590SKeyi Gui <td> 207*055d4590SKeyi Gui 4.8.1.5 208*055d4590SKeyi Gui </td> 209*055d4590SKeyi Gui </tr> 210*055d4590SKeyi Gui 211*055d4590SKeyi Gui <tr> 212*055d4590SKeyi Gui <td> 213*055d4590SKeyi Gui A5 214*055d4590SKeyi Gui </td> 215*055d4590SKeyi Gui 216*055d4590SKeyi Gui <td> 217*055d4590SKeyi Gui The last instruction in the <code>insns</code> array must end at index 218*055d4590SKeyi Gui <code>insns_size-1</code>. 219*055d4590SKeyi Gui </td> 220*055d4590SKeyi Gui 221*055d4590SKeyi Gui <td> 222*055d4590SKeyi Gui 4.8.1.6 223*055d4590SKeyi Gui </td> 224*055d4590SKeyi Gui </tr> 225*055d4590SKeyi Gui 226*055d4590SKeyi Gui <tr> 227*055d4590SKeyi Gui <td> 228*055d4590SKeyi Gui A6 229*055d4590SKeyi Gui </td> 230*055d4590SKeyi Gui 231*055d4590SKeyi Gui <td> 232*055d4590SKeyi Gui All <code>goto</code> and <code>if-<kind></code> targets must 233*055d4590SKeyi Gui be opcodes within in the same method. 234*055d4590SKeyi Gui </td> 235*055d4590SKeyi Gui 236*055d4590SKeyi Gui <td> 237*055d4590SKeyi Gui 4.8.1.7 238*055d4590SKeyi Gui </td> 239*055d4590SKeyi Gui </tr> 240*055d4590SKeyi Gui 241*055d4590SKeyi Gui <tr> 242*055d4590SKeyi Gui <td> 243*055d4590SKeyi Gui A7 244*055d4590SKeyi Gui </td> 245*055d4590SKeyi Gui 246*055d4590SKeyi Gui <td> 247*055d4590SKeyi Gui All targets of a <code>packed-switch</code> instruction must be 248*055d4590SKeyi Gui opcodes within in the same method. The size and the list of targets 249*055d4590SKeyi Gui must be consistent. 250*055d4590SKeyi Gui </td> 251*055d4590SKeyi Gui 252*055d4590SKeyi Gui <td> 253*055d4590SKeyi Gui 4.8.1.8 254*055d4590SKeyi Gui </td> 255*055d4590SKeyi Gui </tr> 256*055d4590SKeyi Gui 257*055d4590SKeyi Gui <tr> 258*055d4590SKeyi Gui <td> 259*055d4590SKeyi Gui A8 260*055d4590SKeyi Gui </td> 261*055d4590SKeyi Gui 262*055d4590SKeyi Gui <td> 263*055d4590SKeyi Gui All targets of a <code>sparse-switch</code> instruction must be 264*055d4590SKeyi Gui opcodes within in the same method. The corresponding table must be 265*055d4590SKeyi Gui consistent and sorted low-to-high. 266*055d4590SKeyi Gui </td> 267*055d4590SKeyi Gui 268*055d4590SKeyi Gui <td> 269*055d4590SKeyi Gui 4.8.1.9 270*055d4590SKeyi Gui </td> 271*055d4590SKeyi Gui </tr> 272*055d4590SKeyi Gui 273*055d4590SKeyi Gui <tr> 274*055d4590SKeyi Gui <td> 275*055d4590SKeyi Gui A9 276*055d4590SKeyi Gui </td> 277*055d4590SKeyi Gui 278*055d4590SKeyi Gui <td> 279*055d4590SKeyi Gui The <code>B</code> operand of the <code>const-string</code> and 280*055d4590SKeyi Gui <code>const-string/jumbo</code> instructions must be a valid index 281*055d4590SKeyi Gui into the string constant pool. 282*055d4590SKeyi Gui </td> 283*055d4590SKeyi Gui 284*055d4590SKeyi Gui <td> 285*055d4590SKeyi Gui 4.8.1.10 286*055d4590SKeyi Gui </td> 287*055d4590SKeyi Gui </tr> 288*055d4590SKeyi Gui 289*055d4590SKeyi Gui <tr> 290*055d4590SKeyi Gui <td> 291*055d4590SKeyi Gui A10 292*055d4590SKeyi Gui </td> 293*055d4590SKeyi Gui 294*055d4590SKeyi Gui <td> 295*055d4590SKeyi Gui The <code>C</code> operand of the <code>iget<kind></code> and 296*055d4590SKeyi Gui <code>iput<kind></code> instructions must be a valid index into 297*055d4590SKeyi Gui the field constant pool. The referenced entry must represent an 298*055d4590SKeyi Gui instance field. 299*055d4590SKeyi Gui </td> 300*055d4590SKeyi Gui 301*055d4590SKeyi Gui <td> 302*055d4590SKeyi Gui 4.8.1.12 303*055d4590SKeyi Gui </td> 304*055d4590SKeyi Gui </tr> 305*055d4590SKeyi Gui 306*055d4590SKeyi Gui <tr> 307*055d4590SKeyi Gui <td> 308*055d4590SKeyi Gui A11 309*055d4590SKeyi Gui </td> 310*055d4590SKeyi Gui 311*055d4590SKeyi Gui <td> 312*055d4590SKeyi Gui The <code>C</code> operand of the <code>sget<kind></code> and 313*055d4590SKeyi Gui <code>sput<kind></code> instructions must be a valid index into 314*055d4590SKeyi Gui the field constant pool. The referenced entry must represent a static 315*055d4590SKeyi Gui field. 316*055d4590SKeyi Gui </td> 317*055d4590SKeyi Gui 318*055d4590SKeyi Gui <td> 319*055d4590SKeyi Gui 4.8.1.12 320*055d4590SKeyi Gui </td> 321*055d4590SKeyi Gui </tr> 322*055d4590SKeyi Gui 323*055d4590SKeyi Gui <tr> 324*055d4590SKeyi Gui <td> 325*055d4590SKeyi Gui A12 326*055d4590SKeyi Gui </td> 327*055d4590SKeyi Gui 328*055d4590SKeyi Gui <td> 329*055d4590SKeyi Gui The <code>C</code> operand of the <code>invoke-virtual</code>, 330*055d4590SKeyi Gui <code>invoke-super</code>, <code<invoke-direct</code> and 331*055d4590SKeyi Gui <code>invoke-static</code> instructions must be a valid index into the 332*055d4590SKeyi Gui method constant pool. In all cases, the referenced 333*055d4590SKeyi Gui <code>method_id</code> must belong to a class (not an interface). 334*055d4590SKeyi Gui </td> 335*055d4590SKeyi Gui 336*055d4590SKeyi Gui <td> 337*055d4590SKeyi Gui 4.8.1.13 338*055d4590SKeyi Gui </td> 339*055d4590SKeyi Gui </tr> 340*055d4590SKeyi Gui 341*055d4590SKeyi Gui <tr> 342*055d4590SKeyi Gui <td> 343*055d4590SKeyi Gui A13 344*055d4590SKeyi Gui </td> 345*055d4590SKeyi Gui 346*055d4590SKeyi Gui <td> 347*055d4590SKeyi Gui The <code>B</code> operand of the <code>invoke-virtual/range</code>, 348*055d4590SKeyi Gui <code>invoke-super/range</code>, <code>invoke-direct/range</code>, and 349*055d4590SKeyi Gui <code>invoke-static/range</code> instructions must be a valid index 350*055d4590SKeyi Gui into the method constant pool. In all cases, the referenced 351*055d4590SKeyi Gui <code>method_id</code> must belong to a class (not an interface). 352*055d4590SKeyi Gui </td> 353*055d4590SKeyi Gui 354*055d4590SKeyi Gui <td> 355*055d4590SKeyi Gui 4.8.1.13 356*055d4590SKeyi Gui </td> 357*055d4590SKeyi Gui </tr> 358*055d4590SKeyi Gui 359*055d4590SKeyi Gui <tr> 360*055d4590SKeyi Gui <td> 361*055d4590SKeyi Gui A14 362*055d4590SKeyi Gui </td> 363*055d4590SKeyi Gui 364*055d4590SKeyi Gui <td> 365*055d4590SKeyi Gui A method the name of which starts with a '<' must only be invoked 366*055d4590SKeyi Gui implicitly by the VM, not by code originating from a Dex file. The 367*055d4590SKeyi Gui only exception is the instance initializer, which may be invoked by 368*055d4590SKeyi Gui <code>invoke-direct</code>. 369*055d4590SKeyi Gui </td> 370*055d4590SKeyi Gui 371*055d4590SKeyi Gui <td> 372*055d4590SKeyi Gui 4.8.1.14 373*055d4590SKeyi Gui </td> 374*055d4590SKeyi Gui </tr> 375*055d4590SKeyi Gui 376*055d4590SKeyi Gui <tr> 377*055d4590SKeyi Gui <td> 378*055d4590SKeyi Gui A15 379*055d4590SKeyi Gui </td> 380*055d4590SKeyi Gui 381*055d4590SKeyi Gui <td> 382*055d4590SKeyi Gui The <code>C</code> operand of the <code>invoke-interface</code> 383*055d4590SKeyi Gui instruction must be a valid index into the method constant pool. The 384*055d4590SKeyi Gui referenced <code>method_id</code> must belong to an interface (not a 385*055d4590SKeyi Gui class). 386*055d4590SKeyi Gui </td> 387*055d4590SKeyi Gui 388*055d4590SKeyi Gui <td> 389*055d4590SKeyi Gui 4.8.1.15 390*055d4590SKeyi Gui </td> 391*055d4590SKeyi Gui </tr> 392*055d4590SKeyi Gui 393*055d4590SKeyi Gui <tr> 394*055d4590SKeyi Gui <td> 395*055d4590SKeyi Gui A16 396*055d4590SKeyi Gui </td> 397*055d4590SKeyi Gui 398*055d4590SKeyi Gui <td> 399*055d4590SKeyi Gui The <code>B</code> operand of the <code>invoke-interface/range</code> 400*055d4590SKeyi Gui instruction must be a valid index into the method constant pool. 401*055d4590SKeyi Gui The referenced <code>method_id</code> must belong to an interface (not 402*055d4590SKeyi Gui a class). 403*055d4590SKeyi Gui </td> 404*055d4590SKeyi Gui 405*055d4590SKeyi Gui <td> 406*055d4590SKeyi Gui 4.8.1.15 407*055d4590SKeyi Gui </td> 408*055d4590SKeyi Gui </tr> 409*055d4590SKeyi Gui 410*055d4590SKeyi Gui <tr> 411*055d4590SKeyi Gui <td> 412*055d4590SKeyi Gui A17 413*055d4590SKeyi Gui </td> 414*055d4590SKeyi Gui 415*055d4590SKeyi Gui <td> 416*055d4590SKeyi Gui The <code>B</code> operand of the <code>const-class</code>, 417*055d4590SKeyi Gui <code>check-cast</code>, <code>new-instance</code>, and 418*055d4590SKeyi Gui <code>filled-new-array/range</code> instructions must be a valid index 419*055d4590SKeyi Gui into the type constant pool. 420*055d4590SKeyi Gui </td> 421*055d4590SKeyi Gui 422*055d4590SKeyi Gui <td> 423*055d4590SKeyi Gui 4.8.1.16 424*055d4590SKeyi Gui </td> 425*055d4590SKeyi Gui </tr> 426*055d4590SKeyi Gui 427*055d4590SKeyi Gui <tr> 428*055d4590SKeyi Gui <td> 429*055d4590SKeyi Gui A18 430*055d4590SKeyi Gui </td> 431*055d4590SKeyi Gui 432*055d4590SKeyi Gui <td> 433*055d4590SKeyi Gui The <code>C</code> operand of the <code>instance-of</code>, 434*055d4590SKeyi Gui <code>new-array</code>, and <code>filled-new-array</code> 435*055d4590SKeyi Gui instructions must be a valid index into the type constant pool. 436*055d4590SKeyi Gui </td> 437*055d4590SKeyi Gui 438*055d4590SKeyi Gui <td> 439*055d4590SKeyi Gui 4.8.1.16 440*055d4590SKeyi Gui </td> 441*055d4590SKeyi Gui </tr> 442*055d4590SKeyi Gui 443*055d4590SKeyi Gui <tr> 444*055d4590SKeyi Gui <td> 445*055d4590SKeyi Gui A19 446*055d4590SKeyi Gui </td> 447*055d4590SKeyi Gui 448*055d4590SKeyi Gui <td> 449*055d4590SKeyi Gui The dimensions of an array created by a <code>new-array</code> 450*055d4590SKeyi Gui instruction must be less than <code>256</code>. 451*055d4590SKeyi Gui </td> 452*055d4590SKeyi Gui 453*055d4590SKeyi Gui <td> 454*055d4590SKeyi Gui 4.8.1.17 455*055d4590SKeyi Gui </td> 456*055d4590SKeyi Gui </tr> 457*055d4590SKeyi Gui 458*055d4590SKeyi Gui <tr> 459*055d4590SKeyi Gui <td> 460*055d4590SKeyi Gui A20 461*055d4590SKeyi Gui </td> 462*055d4590SKeyi Gui 463*055d4590SKeyi Gui <td> 464*055d4590SKeyi Gui The <code>new</code> instruction must not refer to array classes, 465*055d4590SKeyi Gui interfaces, or abstract classes. 466*055d4590SKeyi Gui </td> 467*055d4590SKeyi Gui 468*055d4590SKeyi Gui <td> 469*055d4590SKeyi Gui 4.8.1.18 470*055d4590SKeyi Gui </td> 471*055d4590SKeyi Gui </tr> 472*055d4590SKeyi Gui 473*055d4590SKeyi Gui <tr> 474*055d4590SKeyi Gui <td> 475*055d4590SKeyi Gui A21 476*055d4590SKeyi Gui </td> 477*055d4590SKeyi Gui 478*055d4590SKeyi Gui <td> 479*055d4590SKeyi Gui The type referred to by a <code>new-array</code> instruction must be 480*055d4590SKeyi Gui a valid, non-reference type. 481*055d4590SKeyi Gui </td> 482*055d4590SKeyi Gui 483*055d4590SKeyi Gui <td> 484*055d4590SKeyi Gui 4.8.1.20 485*055d4590SKeyi Gui </td> 486*055d4590SKeyi Gui </tr> 487*055d4590SKeyi Gui 488*055d4590SKeyi Gui <tr> 489*055d4590SKeyi Gui <td> 490*055d4590SKeyi Gui A22 491*055d4590SKeyi Gui </td> 492*055d4590SKeyi Gui 493*055d4590SKeyi Gui <td> 494*055d4590SKeyi Gui All registers referred to by an instruction in a single-width 495*055d4590SKeyi Gui (non-pair) fashion must be valid for the current method. That is, 496*055d4590SKeyi Gui their indices must be non-negative and smaller than 497*055d4590SKeyi Gui <code>registers_size</code>. 498*055d4590SKeyi Gui </td> 499*055d4590SKeyi Gui 500*055d4590SKeyi Gui <td> 501*055d4590SKeyi Gui 4.8.1.21 502*055d4590SKeyi Gui </td> 503*055d4590SKeyi Gui </tr> 504*055d4590SKeyi Gui 505*055d4590SKeyi Gui <tr> 506*055d4590SKeyi Gui <td> 507*055d4590SKeyi Gui A23 508*055d4590SKeyi Gui </td> 509*055d4590SKeyi Gui 510*055d4590SKeyi Gui <td> 511*055d4590SKeyi Gui All registers referred to by an instruction in a double-width (pair) 512*055d4590SKeyi Gui fashion must be valid for the current method. That is, their indices 513*055d4590SKeyi Gui must be non-negative and smaller than <code>registers_size-1</code>. 514*055d4590SKeyi Gui </td> 515*055d4590SKeyi Gui 516*055d4590SKeyi Gui <td> 517*055d4590SKeyi Gui 4.8.1.23 518*055d4590SKeyi Gui </td> 519*055d4590SKeyi Gui </tr> 520*055d4590SKeyi Gui </table> 521*055d4590SKeyi Gui 522*055d4590SKeyi Gui <h2> 523*055d4590SKeyi Gui Structural constraints 524*055d4590SKeyi Gui </h2> 525*055d4590SKeyi Gui 526*055d4590SKeyi Gui <p> 527*055d4590SKeyi Gui Structural constraints are constraints on relationships between several 528*055d4590SKeyi Gui elements of the bytecode. They usually can't be checked without employing 529*055d4590SKeyi Gui control or data-flow analysis techniques. 530*055d4590SKeyi Gui </p> 531*055d4590SKeyi Gui 532*055d4590SKeyi Gui <table> 533*055d4590SKeyi Gui <tr> 534*055d4590SKeyi Gui <th> 535*055d4590SKeyi Gui Identifier 536*055d4590SKeyi Gui </th> 537*055d4590SKeyi Gui 538*055d4590SKeyi Gui <th> 539*055d4590SKeyi Gui Description 540*055d4590SKeyi Gui </th> 541*055d4590SKeyi Gui 542*055d4590SKeyi Gui <th> 543*055d4590SKeyi Gui Spec equivalent 544*055d4590SKeyi Gui </th> 545*055d4590SKeyi Gui </tr> 546*055d4590SKeyi Gui 547*055d4590SKeyi Gui <tr> 548*055d4590SKeyi Gui <td> 549*055d4590SKeyi Gui B1 550*055d4590SKeyi Gui </td> 551*055d4590SKeyi Gui 552*055d4590SKeyi Gui <td> 553*055d4590SKeyi Gui The number and types of arguments (registers and immediate values) 554*055d4590SKeyi Gui must always match the instruction. 555*055d4590SKeyi Gui </td> 556*055d4590SKeyi Gui 557*055d4590SKeyi Gui <td> 558*055d4590SKeyi Gui 4.8.2.1 559*055d4590SKeyi Gui </td> 560*055d4590SKeyi Gui </tr> 561*055d4590SKeyi Gui 562*055d4590SKeyi Gui <tr> 563*055d4590SKeyi Gui <td> 564*055d4590SKeyi Gui B2 565*055d4590SKeyi Gui </td> 566*055d4590SKeyi Gui 567*055d4590SKeyi Gui <td> 568*055d4590SKeyi Gui Register pairs must never be broken up. 569*055d4590SKeyi Gui </td> 570*055d4590SKeyi Gui 571*055d4590SKeyi Gui <td> 572*055d4590SKeyi Gui 4.8.2.3 573*055d4590SKeyi Gui </td> 574*055d4590SKeyi Gui </tr> 575*055d4590SKeyi Gui 576*055d4590SKeyi Gui <tr> 577*055d4590SKeyi Gui <td> 578*055d4590SKeyi Gui B3 579*055d4590SKeyi Gui </td> 580*055d4590SKeyi Gui 581*055d4590SKeyi Gui <td> 582*055d4590SKeyi Gui A register (or pair) has to be assigned first before it can be 583*055d4590SKeyi Gui read. 584*055d4590SKeyi Gui </td> 585*055d4590SKeyi Gui 586*055d4590SKeyi Gui <td> 587*055d4590SKeyi Gui 4.8.2.4 588*055d4590SKeyi Gui </td> 589*055d4590SKeyi Gui </tr> 590*055d4590SKeyi Gui 591*055d4590SKeyi Gui <tr> 592*055d4590SKeyi Gui <td> 593*055d4590SKeyi Gui B4 594*055d4590SKeyi Gui </td> 595*055d4590SKeyi Gui 596*055d4590SKeyi Gui <td> 597*055d4590SKeyi Gui An <code>invoke-direct</code> instruction must only invoke an instance 598*055d4590SKeyi Gui initializer or a method in the current class or one of its 599*055d4590SKeyi Gui superclasses. 600*055d4590SKeyi Gui </td> 601*055d4590SKeyi Gui 602*055d4590SKeyi Gui <td> 603*055d4590SKeyi Gui 4.8.2.7 604*055d4590SKeyi Gui </td> 605*055d4590SKeyi Gui </tr> 606*055d4590SKeyi Gui 607*055d4590SKeyi Gui <tr> 608*055d4590SKeyi Gui <td> 609*055d4590SKeyi Gui B5 610*055d4590SKeyi Gui </td> 611*055d4590SKeyi Gui 612*055d4590SKeyi Gui <td> 613*055d4590SKeyi Gui An instance initializer must only be invoked on an uninitialized 614*055d4590SKeyi Gui instance. 615*055d4590SKeyi Gui </td> 616*055d4590SKeyi Gui 617*055d4590SKeyi Gui <td> 618*055d4590SKeyi Gui 4.8.2.8 619*055d4590SKeyi Gui </td> 620*055d4590SKeyi Gui </tr> 621*055d4590SKeyi Gui 622*055d4590SKeyi Gui <tr> 623*055d4590SKeyi Gui <td> 624*055d4590SKeyi Gui B6 625*055d4590SKeyi Gui </td> 626*055d4590SKeyi Gui 627*055d4590SKeyi Gui <td> 628*055d4590SKeyi Gui Instance methods may only be invoked on and instance fields may only 629*055d4590SKeyi Gui be accessed on already initialized instances. 630*055d4590SKeyi Gui </td> 631*055d4590SKeyi Gui 632*055d4590SKeyi Gui <td> 633*055d4590SKeyi Gui 4.8.2.9 634*055d4590SKeyi Gui </td> 635*055d4590SKeyi Gui </tr> 636*055d4590SKeyi Gui 637*055d4590SKeyi Gui <tr> 638*055d4590SKeyi Gui <td> 639*055d4590SKeyi Gui B7 640*055d4590SKeyi Gui </td> 641*055d4590SKeyi Gui 642*055d4590SKeyi Gui <td> 643*055d4590SKeyi Gui A register which holds the result of a <code>new-instance</code> 644*055d4590SKeyi Gui instruction must not be used if the same 645*055d4590SKeyi Gui <code>new-instance</code> instruction is again executed before 646*055d4590SKeyi Gui the instance is initialized. 647*055d4590SKeyi Gui </td> 648*055d4590SKeyi Gui 649*055d4590SKeyi Gui <td> 650*055d4590SKeyi Gui 4.8.2.10 651*055d4590SKeyi Gui </td> 652*055d4590SKeyi Gui </tr> 653*055d4590SKeyi Gui 654*055d4590SKeyi Gui <tr> 655*055d4590SKeyi Gui <td> 656*055d4590SKeyi Gui B8 657*055d4590SKeyi Gui </td> 658*055d4590SKeyi Gui 659*055d4590SKeyi Gui <td> 660*055d4590SKeyi Gui An instance initializer must call another instance initializer (same 661*055d4590SKeyi Gui class or superclass) before any instance members can be accessed. 662*055d4590SKeyi Gui Exceptions are non-inherited instance fields, which can be assigned 663*055d4590SKeyi Gui before calling another initializer, and the <code>Object</code> class 664*055d4590SKeyi Gui in general. 665*055d4590SKeyi Gui </td> 666*055d4590SKeyi Gui 667*055d4590SKeyi Gui <td> 668*055d4590SKeyi Gui 4.8.2.11 669*055d4590SKeyi Gui </td> 670*055d4590SKeyi Gui </tr> 671*055d4590SKeyi Gui 672*055d4590SKeyi Gui <tr> 673*055d4590SKeyi Gui <td> 674*055d4590SKeyi Gui B9 675*055d4590SKeyi Gui </td> 676*055d4590SKeyi Gui 677*055d4590SKeyi Gui <td> 678*055d4590SKeyi Gui All actual method arguments must be assignment-compatible with their 679*055d4590SKeyi Gui respective formal arguments. 680*055d4590SKeyi Gui </td> 681*055d4590SKeyi Gui 682*055d4590SKeyi Gui <td> 683*055d4590SKeyi Gui 4.8.2.12 684*055d4590SKeyi Gui </td> 685*055d4590SKeyi Gui </tr> 686*055d4590SKeyi Gui 687*055d4590SKeyi Gui <tr> 688*055d4590SKeyi Gui <td> 689*055d4590SKeyi Gui B10 690*055d4590SKeyi Gui </td> 691*055d4590SKeyi Gui 692*055d4590SKeyi Gui <td> 693*055d4590SKeyi Gui For each instance method invocation, the actual instance must be 694*055d4590SKeyi Gui assignment-compatible with the class or interface specified in the 695*055d4590SKeyi Gui instruction. 696*055d4590SKeyi Gui </td> 697*055d4590SKeyi Gui 698*055d4590SKeyi Gui <td> 699*055d4590SKeyi Gui 4.8.2.13 700*055d4590SKeyi Gui </td> 701*055d4590SKeyi Gui </tr> 702*055d4590SKeyi Gui 703*055d4590SKeyi Gui <tr> 704*055d4590SKeyi Gui <td> 705*055d4590SKeyi Gui B11 706*055d4590SKeyi Gui </td> 707*055d4590SKeyi Gui 708*055d4590SKeyi Gui <td> 709*055d4590SKeyi Gui A <code>return<kind></code> instruction must match its 710*055d4590SKeyi Gui method's return type. 711*055d4590SKeyi Gui </td> 712*055d4590SKeyi Gui 713*055d4590SKeyi Gui <td> 714*055d4590SKeyi Gui 4.8.2.14 715*055d4590SKeyi Gui </td> 716*055d4590SKeyi Gui </tr> 717*055d4590SKeyi Gui 718*055d4590SKeyi Gui <tr> 719*055d4590SKeyi Gui <td> 720*055d4590SKeyi Gui B12 721*055d4590SKeyi Gui </td> 722*055d4590SKeyi Gui 723*055d4590SKeyi Gui <td> 724*055d4590SKeyi Gui When accessing protected members of a superclass, the actual type of 725*055d4590SKeyi Gui the instance being accessed must be either the current class or one 726*055d4590SKeyi Gui of its subclasses. 727*055d4590SKeyi Gui </td> 728*055d4590SKeyi Gui 729*055d4590SKeyi Gui <td> 730*055d4590SKeyi Gui 4.8.2.15 731*055d4590SKeyi Gui </td> 732*055d4590SKeyi Gui </tr> 733*055d4590SKeyi Gui 734*055d4590SKeyi Gui <tr> 735*055d4590SKeyi Gui <td> 736*055d4590SKeyi Gui B13 737*055d4590SKeyi Gui </td> 738*055d4590SKeyi Gui 739*055d4590SKeyi Gui <td> 740*055d4590SKeyi Gui The type of a value stored into a static field must be 741*055d4590SKeyi Gui assignment-compatible with or convertible to the field's type. 742*055d4590SKeyi Gui </td> 743*055d4590SKeyi Gui 744*055d4590SKeyi Gui <td> 745*055d4590SKeyi Gui 4.8.2.16 746*055d4590SKeyi Gui </td> 747*055d4590SKeyi Gui </tr> 748*055d4590SKeyi Gui 749*055d4590SKeyi Gui <tr> 750*055d4590SKeyi Gui <td> 751*055d4590SKeyi Gui B14 752*055d4590SKeyi Gui </td> 753*055d4590SKeyi Gui 754*055d4590SKeyi Gui <td> 755*055d4590SKeyi Gui The type of a value stored into a field must be assignment-compatible 756*055d4590SKeyi Gui with or convertible to the field's type. 757*055d4590SKeyi Gui </td> 758*055d4590SKeyi Gui 759*055d4590SKeyi Gui <td> 760*055d4590SKeyi Gui 4.8.2.17 761*055d4590SKeyi Gui </td> 762*055d4590SKeyi Gui </tr> 763*055d4590SKeyi Gui 764*055d4590SKeyi Gui <tr> 765*055d4590SKeyi Gui <td> 766*055d4590SKeyi Gui B15 767*055d4590SKeyi Gui </td> 768*055d4590SKeyi Gui 769*055d4590SKeyi Gui <td> 770*055d4590SKeyi Gui The type of every value stored into an array must be 771*055d4590SKeyi Gui assignment-compatible with the array's component type. 772*055d4590SKeyi Gui </td> 773*055d4590SKeyi Gui 774*055d4590SKeyi Gui <td> 775*055d4590SKeyi Gui 4.8.2.18 776*055d4590SKeyi Gui </td> 777*055d4590SKeyi Gui </tr> 778*055d4590SKeyi Gui 779*055d4590SKeyi Gui <tr> 780*055d4590SKeyi Gui <td> 781*055d4590SKeyi Gui B16 782*055d4590SKeyi Gui </td> 783*055d4590SKeyi Gui 784*055d4590SKeyi Gui <td> 785*055d4590SKeyi Gui The <code>A</code> operand of a <code>throw</code> instruction must 786*055d4590SKeyi Gui be assignment-compatible with <code>java.lang.Throwable</code>. 787*055d4590SKeyi Gui </td> 788*055d4590SKeyi Gui 789*055d4590SKeyi Gui <td> 790*055d4590SKeyi Gui 4.8.2.19 791*055d4590SKeyi Gui </td> 792*055d4590SKeyi Gui </tr> 793*055d4590SKeyi Gui 794*055d4590SKeyi Gui <tr> 795*055d4590SKeyi Gui <td> 796*055d4590SKeyi Gui B17 797*055d4590SKeyi Gui </td> 798*055d4590SKeyi Gui 799*055d4590SKeyi Gui <td> 800*055d4590SKeyi Gui The last reachable instruction of a method must either be a backwards 801*055d4590SKeyi Gui <code>goto</code> or branch, a <code>return</code>, or a 802*055d4590SKeyi Gui <code>throw</code> instruction. It must not be possible to leave the 803*055d4590SKeyi Gui <code>insns</code> array at the bottom. 804*055d4590SKeyi Gui </td> 805*055d4590SKeyi Gui 806*055d4590SKeyi Gui <td> 807*055d4590SKeyi Gui 4.8.2.20 808*055d4590SKeyi Gui </td> 809*055d4590SKeyi Gui </tr> 810*055d4590SKeyi Gui 811*055d4590SKeyi Gui <tr> 812*055d4590SKeyi Gui <td> 813*055d4590SKeyi Gui B18 814*055d4590SKeyi Gui </td> 815*055d4590SKeyi Gui 816*055d4590SKeyi Gui <td> 817*055d4590SKeyi Gui The unassigned half of a former register pair may not be read (is 818*055d4590SKeyi Gui considered invalid) until it has been re-assigned by some other 819*055d4590SKeyi Gui instruction. 820*055d4590SKeyi Gui </td> 821*055d4590SKeyi Gui 822*055d4590SKeyi Gui <td> 823*055d4590SKeyi Gui 4.8.2.3, 4.8.2.4 824*055d4590SKeyi Gui </td> 825*055d4590SKeyi Gui </tr> 826*055d4590SKeyi Gui 827*055d4590SKeyi Gui <tr> 828*055d4590SKeyi Gui <td> 829*055d4590SKeyi Gui B19 830*055d4590SKeyi Gui </td> 831*055d4590SKeyi Gui 832*055d4590SKeyi Gui <td> 833*055d4590SKeyi Gui A <code>move-result<kind></code> instruction must be immediately 834*055d4590SKeyi Gui preceded (in the <code>insns</code> array) by an 835*055d4590SKeyi Gui <code>invoke-<kind></code> instruction. The only exception is 836*055d4590SKeyi Gui the <code>move-result-object</code> instruction, which may also be 837*055d4590SKeyi Gui preceded by a <code>filled-new-array</code> instruction. 838*055d4590SKeyi Gui </td> 839*055d4590SKeyi Gui 840*055d4590SKeyi Gui <td> 841*055d4590SKeyi Gui - 842*055d4590SKeyi Gui </td> 843*055d4590SKeyi Gui </tr> 844*055d4590SKeyi Gui 845*055d4590SKeyi Gui <tr> 846*055d4590SKeyi Gui <td> 847*055d4590SKeyi Gui B20 848*055d4590SKeyi Gui </td> 849*055d4590SKeyi Gui 850*055d4590SKeyi Gui <td> 851*055d4590SKeyi Gui A <code>move-result<kind></code> instruction must be immediately 852*055d4590SKeyi Gui preceded (in actual control flow) by a matching 853*055d4590SKeyi Gui <code>return-<kind></code> instruction (it must not be jumped 854*055d4590SKeyi Gui to). The only exception is the <code>move-result-object</code> 855*055d4590SKeyi Gui instruction, which may also be preceded by a 856*055d4590SKeyi Gui <code>filled-new-array</code> instruction. 857*055d4590SKeyi Gui </td> 858*055d4590SKeyi Gui 859*055d4590SKeyi Gui <td> 860*055d4590SKeyi Gui - 861*055d4590SKeyi Gui </td> 862*055d4590SKeyi Gui </tr> 863*055d4590SKeyi Gui 864*055d4590SKeyi Gui <tr> 865*055d4590SKeyi Gui <td> 866*055d4590SKeyi Gui B21 867*055d4590SKeyi Gui </td> 868*055d4590SKeyi Gui 869*055d4590SKeyi Gui <td> 870*055d4590SKeyi Gui A <code>move-exception</code> instruction must only appear as the 871*055d4590SKeyi Gui first instruction in an exception handler. 872*055d4590SKeyi Gui </td> 873*055d4590SKeyi Gui 874*055d4590SKeyi Gui <td> 875*055d4590SKeyi Gui - 876*055d4590SKeyi Gui </td> 877*055d4590SKeyi Gui </tr> 878*055d4590SKeyi Gui 879*055d4590SKeyi Gui <tr> 880*055d4590SKeyi Gui <td> 881*055d4590SKeyi Gui B22 882*055d4590SKeyi Gui </td> 883*055d4590SKeyi Gui 884*055d4590SKeyi Gui <td> 885*055d4590SKeyi Gui The <code>packed-switch-data</code>, <code>sparse-switch-data</code>, 886*055d4590SKeyi Gui and <code>fill-array-data</code> pseudo-instructions must not be 887*055d4590SKeyi Gui reachable by control flow. 888*055d4590SKeyi Gui </td> 889*055d4590SKeyi Gui 890*055d4590SKeyi Gui <td> 891*055d4590SKeyi Gui - 892*055d4590SKeyi Gui </td> 893*055d4590SKeyi Gui </tr> 894*055d4590SKeyi Gui </table> 895*055d4590SKeyi Gui 896*055d4590SKeyi Gui </body> 897*055d4590SKeyi Gui</html> 898