private void decodeGeneration ( CodeAssembler a , LocalVariable encodedVar , int offset , int generation , Label altGenerationHandler ) { if ( offset < 0 ) { throw new IllegalArgumentException ( ) ; } if ( generation < 0 ) { return ; } LocalVariable actualGeneration = a . createLocalVariable ( null , TypeDesc . INT ) ; a . loadLocal ( encodedVar ) ; a . loadConstant ( offset ) ; a . loadFromArray ( TypeDesc . BYTE ) ; a . storeLocal ( actualGeneration ) ; a . loadLocal ( actualGeneration ) ; Label compareGeneration = a . createLabel ( ) ; a . ifZeroComparisonBranch ( compareGeneration , ">=" ) ; // Decode four byte generation format. a . loadLocal ( actualGeneration ) ; a . loadConstant ( 24 ) ; a . math ( Opcode . ISHL ) ; a . loadConstant ( 0x7fffffff ) ; a . math ( Opcode . IAND ) ; for ( int i = 1 ; i < 4 ; i ++ ) { a . loadLocal ( encodedVar ) ; a . loadConstant ( offset + i ) ; a . loadFromArray ( TypeDesc . BYTE ) ; a . loadConstant ( 0xff ) ; a . math ( Opcode . IAND ) ; int shift = 8 * ( 3 - i ) ; if ( shift > 0 ) { a . loadConstant ( shift ) ; a . math ( Opcode . ISHL ) ; } a . math ( Opcode . IOR ) ; } a . storeLocal ( actualGeneration ) ; compareGeneration . setLocation ( ) ; a . loadConstant ( generation ) ; a . loadLocal ( actualGeneration ) ; Label generationMatches = a . createLabel ( ) ; a . ifComparisonBranch ( generationMatches , "==" ) ; if ( altGenerationHandler != null ) { a . loadLocal ( actualGeneration ) ; a . branch ( altGenerationHandler ) ; } else { // Throw CorruptEncodingException. TypeDesc corruptEncodingEx = TypeDesc . forClass ( CorruptEncodingException . class ) ; a . newObject ( corruptEncodingEx ) ; a . dup ( ) ; a . loadConstant ( generation ) ; // expected generation a . loadLocal ( actualGeneration ) ; // actual generation a . invokeConstructor ( corruptEncodingEx , new TypeDesc [ ] { TypeDesc . INT , TypeDesc . INT } ) ; a . throwObject ( ) ; } generationMatches . setLocation ( ) ; }
Generates code that ensures a matching generation value exists in the byte array referenced by the local variable throwing a CorruptEncodingException otherwise .