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