1 /* 2 * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 // -*- C++ -*- 27 struct entry; 28 struct cpindex; 29 struct unpacker; 30 31 struct band { 32 const char* name; 33 int bn; // band_number of this band 34 coding* defc; // default coding method 35 cpindex* ix; // CP entry mapping, if CPRefBand 36 byte ixTag; // 0 or 1; null is coded as (nullOK?0:-1) 37 byte nullOK; // 0 or 1; null is coded as (nullOK?0:-1) 38 int length; // expected # values 39 unpacker* u; // back pointer 40 41 value_stream vs[2]; // source of values 42 coding_method cm; // method used for initial state of vs[0] 43 byte* rplimit; // end of band (encoded, transmitted) 44 45 int total_memo; // cached value of getIntTotal, or -1 46 int* hist0; // approximate. histogram 47 enum { HIST0_MIN = 0, HIST0_MAX = 255 }; // catches the usual cases 48 49 // properties for attribute layout elements: 50 byte le_kind; // EK_XXX 51 byte le_bci; // 0,EK_BCI,EK_BCD,EK_BCO 52 byte le_back; // ==EF_BACK 53 byte le_len; // 0,1,2,4 (size in classfile), or call addr 54 band** le_body; // body of repl, union, call (null-terminated) 55 // Note: EK_CASE elements use hist0 to record union tags. 56 #define le_casetags hist0 57 58 band& nextBand() { return this[1]; } 59 band& prevBand() { return this[-1]; } 60 61 void init(unpacker* u_, int bn_, coding* defc_) { 62 u = u_; 63 cm.u = u_; 64 bn = bn_; 65 defc = defc_; 66 } 67 void init(unpacker* u_, int bn_, int defcSpec) { 68 init(u_, bn_, coding::findBySpec(defcSpec)); 69 } 70 void initRef(int ixTag_ = 0, bool nullOK_ = false) { 71 ixTag = ixTag_; 72 nullOK = nullOK_; 73 setIndexByTag(ixTag); 74 } 75 76 void expectMoreLength(int l) { 77 assert(length >= 0); // able to accept a length 78 assert((int)l >= 0); // no overflow 79 assert(rplimit == null); // readData not yet called 80 length += l; 81 assert(length >= l); // no overflow 82 } 83 84 void setIndex(cpindex* ix_); 85 void setIndexByTag(byte tag); 86 87 // Parse the band and its meta-coding header. 88 void readData(int expectedLength = 0); 89 90 // Reset the band for another pass (Cf. Java Band.resetForSecondPass.) 91 void rewind() { 92 cm.reset(&vs[0]); 93 } 94 95 byte* &curRP() { return vs[0].rp; } 96 byte* minRP() { return cm.vs0.rp; } 97 byte* maxRP() { return rplimit; } 98 size_t size() { return maxRP() - minRP(); } 99 100 int getByte() { assert(ix == null); return vs[0].getByte(); } 101 int getInt() { assert(ix == null); return vs[0].getInt(); } 102 entry* getRefN() { assert(ix != null); return getRefCommon(ix, true); } 103 entry* getRef() { assert(ix != null); return getRefCommon(ix, false); } 104 entry* getRefUsing(cpindex* ix2) 105 { assert(ix == null); return getRefCommon(ix2, true); } 106 entry* getRefCommon(cpindex* ix, bool nullOK); 107 jlong getLong(band& lo_band, bool have_hi); 108 109 static jlong makeLong(uint hi, uint lo) { 110 return ((julong)hi << 32) + (((julong)lo << 32) >> 32); 111 } 112 113 int getIntTotal(); 114 int getIntCount(int tag); 115 116 static band* makeBands(unpacker* u); 117 static void initIndexes(unpacker* u); 118 119 #ifndef PRODUCT 120 void dump(); 121 #endif 122 123 void abort(const char* msg = null); //{ u->abort(msg); } 124 bool aborting(); //{ return u->aborting(); } 125 }; 126 127 extern band all_bands[]; 128 129 #define BAND_LOCAL /* \ 130 band* band_temp = all_bands; \ 131 band* all_bands = band_temp */ 132 133 // Band schema: 134 enum band_number { 135 //e_archive_magic, 136 //e_archive_header, 137 //e_band_headers, 138 139 // constant pool contents 140 e_cp_Utf8_prefix, 141 e_cp_Utf8_suffix, 142 e_cp_Utf8_chars, 143 e_cp_Utf8_big_suffix, 144 e_cp_Utf8_big_chars, 145 e_cp_Int, 146 e_cp_Float, 147 e_cp_Long_hi, 148 e_cp_Long_lo, 149 e_cp_Double_hi, 150 e_cp_Double_lo, 151 e_cp_String, 152 e_cp_Class, 153 e_cp_Signature_form, 154 e_cp_Signature_classes, 155 e_cp_Descr_name, 156 e_cp_Descr_type, 157 e_cp_Field_class, 158 e_cp_Field_desc, 159 e_cp_Method_class, 160 e_cp_Method_desc, 161 e_cp_Imethod_class, 162 e_cp_Imethod_desc, 163 e_cp_MethodHandle_refkind, 164 e_cp_MethodHandle_member, 165 e_cp_MethodType, 166 e_cp_BootstrapMethod_ref, 167 e_cp_BootstrapMethod_arg_count, 168 e_cp_BootstrapMethod_arg, 169 e_cp_InvokeDynamic_spec, 170 e_cp_InvokeDynamic_desc, 171 172 // bands which define transmission of attributes 173 e_attr_definition_headers, 174 e_attr_definition_name, 175 e_attr_definition_layout, 176 177 // band for hardwired InnerClasses attribute (shared across the package) 178 e_ic_this_class, 179 e_ic_flags, 180 // These bands contain data only where flags sets ACC_IC_LONG_FORM: 181 e_ic_outer_class, 182 e_ic_name, 183 184 // bands for carrying class schema information: 185 e_class_this, 186 e_class_super, 187 e_class_interface_count, 188 e_class_interface, 189 190 // bands for class members 191 e_class_field_count, 192 e_class_method_count, 193 194 e_field_descr, 195 e_field_flags_hi, 196 e_field_flags_lo, 197 e_field_attr_count, 198 e_field_attr_indexes, 199 e_field_attr_calls, 200 e_field_ConstantValue_KQ, 201 e_field_Signature_RS, 202 e_field_metadata_bands, 203 e_field_attr_bands, 204 205 e_method_descr, 206 e_method_flags_hi, 207 e_method_flags_lo, 208 e_method_attr_count, 209 e_method_attr_indexes, 210 e_method_attr_calls, 211 e_method_Exceptions_N, 212 e_method_Exceptions_RC, 213 e_method_Signature_RS, 214 e_method_metadata_bands, 215 e_method_attr_bands, 216 217 e_class_flags_hi, 218 e_class_flags_lo, 219 e_class_attr_count, 220 e_class_attr_indexes, 221 e_class_attr_calls, 222 e_class_SourceFile_RUN, 223 e_class_EnclosingMethod_RC, 224 e_class_EnclosingMethod_RDN, 225 e_class_Signature_RS, 226 e_class_metadata_bands, 227 e_class_InnerClasses_N, 228 e_class_InnerClasses_RC, 229 e_class_InnerClasses_F, 230 e_class_InnerClasses_outer_RCN, 231 e_class_InnerClasses_name_RUN, 232 e_class_ClassFile_version_minor_H, 233 e_class_ClassFile_version_major_H, 234 e_class_attr_bands, 235 236 e_code_headers, 237 e_code_max_stack, 238 e_code_max_na_locals, 239 e_code_handler_count, 240 e_code_handler_start_P, 241 e_code_handler_end_PO, 242 e_code_handler_catch_PO, 243 e_code_handler_class_RCN, 244 245 // code attributes 246 e_code_flags_hi, 247 e_code_flags_lo, 248 e_code_attr_count, 249 e_code_attr_indexes, 250 e_code_attr_calls, 251 e_code_StackMapTable_N, 252 e_code_StackMapTable_frame_T, 253 e_code_StackMapTable_local_N, 254 e_code_StackMapTable_stack_N, 255 e_code_StackMapTable_offset, 256 e_code_StackMapTable_T, 257 e_code_StackMapTable_RC, 258 e_code_StackMapTable_P, 259 e_code_LineNumberTable_N, 260 e_code_LineNumberTable_bci_P, 261 e_code_LineNumberTable_line, 262 e_code_LocalVariableTable_N, 263 e_code_LocalVariableTable_bci_P, 264 e_code_LocalVariableTable_span_O, 265 e_code_LocalVariableTable_name_RU, 266 e_code_LocalVariableTable_type_RS, 267 e_code_LocalVariableTable_slot, 268 e_code_LocalVariableTypeTable_N, 269 e_code_LocalVariableTypeTable_bci_P, 270 e_code_LocalVariableTypeTable_span_O, 271 e_code_LocalVariableTypeTable_name_RU, 272 e_code_LocalVariableTypeTable_type_RS, 273 e_code_LocalVariableTypeTable_slot, 274 e_code_attr_bands, 275 276 // bands for bytecodes 277 e_bc_codes, 278 // remaining bands provide typed opcode fields required by the bc_codes 279 280 e_bc_case_count, 281 e_bc_case_value, 282 e_bc_byte, 283 e_bc_short, 284 e_bc_local, 285 e_bc_label, 286 287 // ldc* operands: 288 e_bc_intref, 289 e_bc_floatref, 290 e_bc_longref, 291 e_bc_doubleref, 292 e_bc_stringref, 293 e_bc_loadablevalueref, 294 e_bc_classref, 295 296 e_bc_fieldref, 297 e_bc_methodref, 298 e_bc_imethodref, 299 e_bc_indyref, 300 301 // _self_linker_op family 302 e_bc_thisfield, 303 e_bc_superfield, 304 e_bc_thismethod, 305 e_bc_supermethod, 306 307 // bc_invokeinit family: 308 e_bc_initref, 309 310 // bytecode escape sequences 311 e_bc_escref, 312 e_bc_escrefsize, 313 e_bc_escsize, 314 e_bc_escbyte, 315 316 // file attributes and contents 317 e_file_name, 318 e_file_size_hi, 319 e_file_size_lo, 320 e_file_modtime, 321 e_file_options, 322 //e_file_bits, // handled specially as an appendix 323 324 BAND_LIMIT 325 }; 326 327 // Symbolic names for bands, as if in a giant global struct: 328 //#define archive_magic all_bands[e_archive_magic] 329 //#define archive_header all_bands[e_archive_header] 330 //#define band_headers all_bands[e_band_headers] 331 #define cp_Utf8_prefix all_bands[e_cp_Utf8_prefix] 332 #define cp_Utf8_suffix all_bands[e_cp_Utf8_suffix] 333 #define cp_Utf8_chars all_bands[e_cp_Utf8_chars] 334 #define cp_Utf8_big_suffix all_bands[e_cp_Utf8_big_suffix] 335 #define cp_Utf8_big_chars all_bands[e_cp_Utf8_big_chars] 336 #define cp_Int all_bands[e_cp_Int] 337 #define cp_Float all_bands[e_cp_Float] 338 #define cp_Long_hi all_bands[e_cp_Long_hi] 339 #define cp_Long_lo all_bands[e_cp_Long_lo] 340 #define cp_Double_hi all_bands[e_cp_Double_hi] 341 #define cp_Double_lo all_bands[e_cp_Double_lo] 342 #define cp_String all_bands[e_cp_String] 343 #define cp_Class all_bands[e_cp_Class] 344 #define cp_Signature_form all_bands[e_cp_Signature_form] 345 #define cp_Signature_classes all_bands[e_cp_Signature_classes] 346 #define cp_Descr_name all_bands[e_cp_Descr_name] 347 #define cp_Descr_type all_bands[e_cp_Descr_type] 348 #define cp_Field_class all_bands[e_cp_Field_class] 349 #define cp_Field_desc all_bands[e_cp_Field_desc] 350 #define cp_Method_class all_bands[e_cp_Method_class] 351 #define cp_Method_desc all_bands[e_cp_Method_desc] 352 #define cp_Imethod_class all_bands[e_cp_Imethod_class] 353 #define cp_Imethod_desc all_bands[e_cp_Imethod_desc] 354 #define cp_MethodHandle_refkind all_bands[e_cp_MethodHandle_refkind] 355 #define cp_MethodHandle_member all_bands[e_cp_MethodHandle_member] 356 #define cp_MethodType all_bands[e_cp_MethodType] 357 #define cp_BootstrapMethod_ref all_bands[e_cp_BootstrapMethod_ref] 358 #define cp_BootstrapMethod_arg_count all_bands[e_cp_BootstrapMethod_arg_count] 359 #define cp_BootstrapMethod_arg all_bands[e_cp_BootstrapMethod_arg] 360 #define cp_InvokeDynamic_spec all_bands[e_cp_InvokeDynamic_spec] 361 #define cp_InvokeDynamic_desc all_bands[e_cp_InvokeDynamic_desc] 362 #define attr_definition_headers all_bands[e_attr_definition_headers] 363 #define attr_definition_name all_bands[e_attr_definition_name] 364 #define attr_definition_layout all_bands[e_attr_definition_layout] 365 #define ic_this_class all_bands[e_ic_this_class] 366 #define ic_flags all_bands[e_ic_flags] 367 #define ic_outer_class all_bands[e_ic_outer_class] 368 #define ic_name all_bands[e_ic_name] 369 #define class_this all_bands[e_class_this] 370 #define class_super all_bands[e_class_super] 371 #define class_interface_count all_bands[e_class_interface_count] 372 #define class_interface all_bands[e_class_interface] 373 #define class_field_count all_bands[e_class_field_count] 374 #define class_method_count all_bands[e_class_method_count] 375 #define field_descr all_bands[e_field_descr] 376 #define field_flags_hi all_bands[e_field_flags_hi] 377 #define field_flags_lo all_bands[e_field_flags_lo] 378 #define field_attr_count all_bands[e_field_attr_count] 379 #define field_attr_indexes all_bands[e_field_attr_indexes] 380 #define field_ConstantValue_KQ all_bands[e_field_ConstantValue_KQ] 381 #define field_Signature_RS all_bands[e_field_Signature_RS] 382 #define field_attr_bands all_bands[e_field_attr_bands] 383 #define method_descr all_bands[e_method_descr] 384 #define method_flags_hi all_bands[e_method_flags_hi] 385 #define method_flags_lo all_bands[e_method_flags_lo] 386 #define method_attr_count all_bands[e_method_attr_count] 387 #define method_attr_indexes all_bands[e_method_attr_indexes] 388 #define method_Exceptions_N all_bands[e_method_Exceptions_N] 389 #define method_Exceptions_RC all_bands[e_method_Exceptions_RC] 390 #define method_Signature_RS all_bands[e_method_Signature_RS] 391 #define method_attr_bands all_bands[e_method_attr_bands] 392 #define class_flags_hi all_bands[e_class_flags_hi] 393 #define class_flags_lo all_bands[e_class_flags_lo] 394 #define class_attr_count all_bands[e_class_attr_count] 395 #define class_attr_indexes all_bands[e_class_attr_indexes] 396 #define class_SourceFile_RUN all_bands[e_class_SourceFile_RUN] 397 #define class_EnclosingMethod_RC all_bands[e_class_EnclosingMethod_RC] 398 #define class_EnclosingMethod_RDN all_bands[e_class_EnclosingMethod_RDN] 399 #define class_Signature_RS all_bands[e_class_Signature_RS] 400 #define class_InnerClasses_N all_bands[e_class_InnerClasses_N] 401 #define class_InnerClasses_RC all_bands[e_class_InnerClasses_RC] 402 #define class_InnerClasses_F all_bands[e_class_InnerClasses_F] 403 #define class_InnerClasses_outer_RCN all_bands[e_class_InnerClasses_outer_RCN] 404 #define class_InnerClasses_name_RUN all_bands[e_class_InnerClasses_name_RUN] 405 #define class_ClassFile_version_minor_H all_bands[e_class_ClassFile_version_minor_H] 406 #define class_ClassFile_version_major_H all_bands[e_class_ClassFile_version_major_H] 407 #define class_attr_bands all_bands[e_class_attr_bands] 408 #define code_headers all_bands[e_code_headers] 409 #define code_max_stack all_bands[e_code_max_stack] 410 #define code_max_na_locals all_bands[e_code_max_na_locals] 411 #define code_handler_count all_bands[e_code_handler_count] 412 #define code_handler_start_P all_bands[e_code_handler_start_P] 413 #define code_handler_end_PO all_bands[e_code_handler_end_PO] 414 #define code_handler_catch_PO all_bands[e_code_handler_catch_PO] 415 #define code_handler_class_RCN all_bands[e_code_handler_class_RCN] 416 #define code_flags_hi all_bands[e_code_flags_hi] 417 #define code_flags_lo all_bands[e_code_flags_lo] 418 #define code_attr_count all_bands[e_code_attr_count] 419 #define code_attr_indexes all_bands[e_code_attr_indexes] 420 #define code_StackMapTable_N all_bands[e_code_StackMapTable_N] 421 #define code_StackMapTable_frame_T all_bands[e_code_StackMapTable_frame_T] 422 #define code_StackMapTable_local_N all_bands[e_code_StackMapTable_local_N] 423 #define code_StackMapTable_stack_N all_bands[e_code_StackMapTable_stack_N] 424 #define code_StackMapTable_offset all_bands[e_code_StackMapTable_offset] 425 #define code_StackMapTable_T all_bands[e_code_StackMapTable_T] 426 #define code_StackMapTable_RC all_bands[e_code_StackMapTable_RC] 427 #define code_StackMapTable_P all_bands[e_code_StackMapTable_P] 428 #define code_LineNumberTable_N all_bands[e_code_LineNumberTable_N] 429 #define code_LineNumberTable_bci_P all_bands[e_code_LineNumberTable_bci_P] 430 #define code_LineNumberTable_line all_bands[e_code_LineNumberTable_line] 431 #define code_LocalVariableTable_N all_bands[e_code_LocalVariableTable_N] 432 #define code_LocalVariableTable_bci_P all_bands[e_code_LocalVariableTable_bci_P] 433 #define code_LocalVariableTable_span_O all_bands[e_code_LocalVariableTable_span_O] 434 #define code_LocalVariableTable_name_RU all_bands[e_code_LocalVariableTable_name_RU] 435 #define code_LocalVariableTable_type_RS all_bands[e_code_LocalVariableTable_type_RS] 436 #define code_LocalVariableTable_slot all_bands[e_code_LocalVariableTable_slot] 437 #define code_LocalVariableTypeTable_N all_bands[e_code_LocalVariableTypeTable_N] 438 #define code_LocalVariableTypeTable_bci_P all_bands[e_code_LocalVariableTypeTable_bci_P] 439 #define code_LocalVariableTypeTable_span_O all_bands[e_code_LocalVariableTypeTable_span_O] 440 #define code_LocalVariableTypeTable_name_RU all_bands[e_code_LocalVariableTypeTable_name_RU] 441 #define code_LocalVariableTypeTable_type_RS all_bands[e_code_LocalVariableTypeTable_type_RS] 442 #define code_LocalVariableTypeTable_slot all_bands[e_code_LocalVariableTypeTable_slot] 443 #define code_attr_bands all_bands[e_code_attr_bands] 444 #define bc_codes all_bands[e_bc_codes] 445 #define bc_case_count all_bands[e_bc_case_count] 446 #define bc_case_value all_bands[e_bc_case_value] 447 #define bc_byte all_bands[e_bc_byte] 448 #define bc_short all_bands[e_bc_short] 449 #define bc_local all_bands[e_bc_local] 450 #define bc_label all_bands[e_bc_label] 451 #define bc_intref all_bands[e_bc_intref] 452 #define bc_floatref all_bands[e_bc_floatref] 453 #define bc_longref all_bands[e_bc_longref] 454 #define bc_doubleref all_bands[e_bc_doubleref] 455 #define bc_stringref all_bands[e_bc_stringref] 456 #define bc_loadablevalueref all_bands[e_bc_loadablevalueref] 457 #define bc_classref all_bands[e_bc_classref] 458 #define bc_fieldref all_bands[e_bc_fieldref] 459 #define bc_methodref all_bands[e_bc_methodref] 460 #define bc_imethodref all_bands[e_bc_imethodref] 461 #define bc_indyref all_bands[e_bc_indyref] 462 #define bc_thisfield all_bands[e_bc_thisfield] 463 #define bc_superfield all_bands[e_bc_superfield] 464 #define bc_thismethod all_bands[e_bc_thismethod] 465 #define bc_supermethod all_bands[e_bc_supermethod] 466 #define bc_initref all_bands[e_bc_initref] 467 #define bc_escref all_bands[e_bc_escref] 468 #define bc_escrefsize all_bands[e_bc_escrefsize] 469 #define bc_escsize all_bands[e_bc_escsize] 470 #define bc_escbyte all_bands[e_bc_escbyte] 471 #define file_name all_bands[e_file_name] 472 #define file_size_hi all_bands[e_file_size_hi] 473 #define file_size_lo all_bands[e_file_size_lo] 474 #define file_modtime all_bands[e_file_modtime] 475 #define file_options all_bands[e_file_options]