1/*
2 * Copyright (c) 2002, 2013, 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++ -*-
27struct entry;
28struct cpindex;
29struct unpacker;
30
31struct 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() { return getRefCommon(ix, true); }
103 entry* getRef() { 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
127extern band all_bands[];
128
129#define BAND_LOCAL /* \
130 band* band_temp = all_bands; \
131 band* all_bands = band_temp */
132
133// Band schema:
134enum 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_MethodParameters_NB,
216 e_method_MethodParameters_name_RUN,
217 e_method_MethodParameters_flag_FH,
218 e_method_attr_bands,
219
220 e_class_flags_hi,
221 e_class_flags_lo,
222 e_class_attr_count,
223 e_class_attr_indexes,
224 e_class_attr_calls,
225 e_class_SourceFile_RUN,
226 e_class_EnclosingMethod_RC,
227 e_class_EnclosingMethod_RDN,
228 e_class_Signature_RS,
229 e_class_metadata_bands,
230 e_class_InnerClasses_N,
231 e_class_InnerClasses_RC,
232 e_class_InnerClasses_F,
233 e_class_InnerClasses_outer_RCN,
234 e_class_InnerClasses_name_RUN,
235 e_class_ClassFile_version_minor_H,
236 e_class_ClassFile_version_major_H,
237 e_class_attr_bands,
238
239 e_code_headers,
240 e_code_max_stack,
241 e_code_max_na_locals,
242 e_code_handler_count,
243 e_code_handler_start_P,
244 e_code_handler_end_PO,
245 e_code_handler_catch_PO,
246 e_code_handler_class_RCN,
247
248 // code attributes
249 e_code_flags_hi,
250 e_code_flags_lo,
251 e_code_attr_count,
252 e_code_attr_indexes,
253 e_code_attr_calls,
254 e_code_StackMapTable_N,
255 e_code_StackMapTable_frame_T,
256 e_code_StackMapTable_local_N,
257 e_code_StackMapTable_stack_N,
258 e_code_StackMapTable_offset,
259 e_code_StackMapTable_T,
260 e_code_StackMapTable_RC,
261 e_code_StackMapTable_P,
262 e_code_LineNumberTable_N,
263 e_code_LineNumberTable_bci_P,
264 e_code_LineNumberTable_line,
265 e_code_LocalVariableTable_N,
266 e_code_LocalVariableTable_bci_P,
267 e_code_LocalVariableTable_span_O,
268 e_code_LocalVariableTable_name_RU,
269 e_code_LocalVariableTable_type_RS,
270 e_code_LocalVariableTable_slot,
271 e_code_LocalVariableTypeTable_N,
272 e_code_LocalVariableTypeTable_bci_P,
273 e_code_LocalVariableTypeTable_span_O,
274 e_code_LocalVariableTypeTable_name_RU,
275 e_code_LocalVariableTypeTable_type_RS,
276 e_code_LocalVariableTypeTable_slot,
277 e_code_attr_bands,
278
279 // bands for bytecodes
280 e_bc_codes,
281 // remaining bands provide typed opcode fields required by the bc_codes
282
283 e_bc_case_count,
284 e_bc_case_value,
285 e_bc_byte,
286 e_bc_short,
287 e_bc_local,
288 e_bc_label,
289
290 // ldc* operands:
291 e_bc_intref,
292 e_bc_floatref,
293 e_bc_longref,
294 e_bc_doubleref,
295 e_bc_stringref,
296 e_bc_loadablevalueref,
297 e_bc_classref,
298
299 e_bc_fieldref,
300 e_bc_methodref,
301 e_bc_imethodref,
302 e_bc_indyref,
303
304 // _self_linker_op family
305 e_bc_thisfield,
306 e_bc_superfield,
307 e_bc_thismethod,
308 e_bc_supermethod,
309
310 // bc_invokeinit family:
311 e_bc_initref,
312
313 // bytecode escape sequences
314 e_bc_escref,
315 e_bc_escrefsize,
316 e_bc_escsize,
317 e_bc_escbyte,
318
319 // file attributes and contents
320 e_file_name,
321 e_file_size_hi,
322 e_file_size_lo,
323 e_file_modtime,
324 e_file_options,
325 //e_file_bits, // handled specially as an appendix
326
327 BAND_LIMIT
328};
329
330// Symbolic names for bands, as if in a giant global struct:
331//#define archive_magic all_bands[e_archive_magic]
332//#define archive_header all_bands[e_archive_header]
333//#define band_headers all_bands[e_band_headers]
334#define cp_Utf8_prefix all_bands[e_cp_Utf8_prefix]
335#define cp_Utf8_suffix all_bands[e_cp_Utf8_suffix]
336#define cp_Utf8_chars all_bands[e_cp_Utf8_chars]
337#define cp_Utf8_big_suffix all_bands[e_cp_Utf8_big_suffix]
338#define cp_Utf8_big_chars all_bands[e_cp_Utf8_big_chars]
339#define cp_Int all_bands[e_cp_Int]
340#define cp_Float all_bands[e_cp_Float]
341#define cp_Long_hi all_bands[e_cp_Long_hi]
342#define cp_Long_lo all_bands[e_cp_Long_lo]
343#define cp_Double_hi all_bands[e_cp_Double_hi]
344#define cp_Double_lo all_bands[e_cp_Double_lo]
345#define cp_String all_bands[e_cp_String]
346#define cp_Class all_bands[e_cp_Class]
347#define cp_Signature_form all_bands[e_cp_Signature_form]
348#define cp_Signature_classes all_bands[e_cp_Signature_classes]
349#define cp_Descr_name all_bands[e_cp_Descr_name]
350#define cp_Descr_type all_bands[e_cp_Descr_type]
351#define cp_Field_class all_bands[e_cp_Field_class]
352#define cp_Field_desc all_bands[e_cp_Field_desc]
353#define cp_Method_class all_bands[e_cp_Method_class]
354#define cp_Method_desc all_bands[e_cp_Method_desc]
355#define cp_Imethod_class all_bands[e_cp_Imethod_class]
356#define cp_Imethod_desc all_bands[e_cp_Imethod_desc]
357#define cp_MethodHandle_refkind all_bands[e_cp_MethodHandle_refkind]
358#define cp_MethodHandle_member all_bands[e_cp_MethodHandle_member]
359#define cp_MethodType all_bands[e_cp_MethodType]
360#define cp_BootstrapMethod_ref all_bands[e_cp_BootstrapMethod_ref]
361#define cp_BootstrapMethod_arg_count all_bands[e_cp_BootstrapMethod_arg_count]
362#define cp_BootstrapMethod_arg all_bands[e_cp_BootstrapMethod_arg]
363#define cp_InvokeDynamic_spec all_bands[e_cp_InvokeDynamic_spec]
364#define cp_InvokeDynamic_desc all_bands[e_cp_InvokeDynamic_desc]
365#define attr_definition_headers all_bands[e_attr_definition_headers]
366#define attr_definition_name all_bands[e_attr_definition_name]
367#define attr_definition_layout all_bands[e_attr_definition_layout]
368#define ic_this_class all_bands[e_ic_this_class]
369#define ic_flags all_bands[e_ic_flags]
370#define ic_outer_class all_bands[e_ic_outer_class]
371#define ic_name all_bands[e_ic_name]
372#define class_this all_bands[e_class_this]
373#define class_super all_bands[e_class_super]
374#define class_interface_count all_bands[e_class_interface_count]
375#define class_interface all_bands[e_class_interface]
376#define class_field_count all_bands[e_class_field_count]
377#define class_method_count all_bands[e_class_method_count]
378#define field_descr all_bands[e_field_descr]
379#define field_flags_hi all_bands[e_field_flags_hi]
380#define field_flags_lo all_bands[e_field_flags_lo]
381#define field_attr_count all_bands[e_field_attr_count]
382#define field_attr_indexes all_bands[e_field_attr_indexes]
383#define field_ConstantValue_KQ all_bands[e_field_ConstantValue_KQ]
384#define field_Signature_RS all_bands[e_field_Signature_RS]
385#define field_attr_bands all_bands[e_field_attr_bands]
386#define method_descr all_bands[e_method_descr]
387#define method_flags_hi all_bands[e_method_flags_hi]
388#define method_flags_lo all_bands[e_method_flags_lo]
389#define method_attr_count all_bands[e_method_attr_count]
390#define method_attr_indexes all_bands[e_method_attr_indexes]
391#define method_Exceptions_N all_bands[e_method_Exceptions_N]
392#define method_Exceptions_RC all_bands[e_method_Exceptions_RC]
393#define method_Signature_RS all_bands[e_method_Signature_RS]
394#define method_MethodParameters_NB all_bands[e_method_MethodParameters_NB]
395#define method_MethodParameters_name_RUN all_bands[e_method_MethodParameters_name_RUN]
396#define method_MethodParameters_flag_FH all_bands[e_method_MethodParameters_flag_FH]
397#define method_attr_bands all_bands[e_method_attr_bands]
398#define class_flags_hi all_bands[e_class_flags_hi]
399#define class_flags_lo all_bands[e_class_flags_lo]
400#define class_attr_count all_bands[e_class_attr_count]
401#define class_attr_indexes all_bands[e_class_attr_indexes]
402#define class_SourceFile_RUN all_bands[e_class_SourceFile_RUN]
403#define class_EnclosingMethod_RC all_bands[e_class_EnclosingMethod_RC]
404#define class_EnclosingMethod_RDN all_bands[e_class_EnclosingMethod_RDN]
405#define class_Signature_RS all_bands[e_class_Signature_RS]
406#define class_InnerClasses_N all_bands[e_class_InnerClasses_N]
407#define class_InnerClasses_RC all_bands[e_class_InnerClasses_RC]
408#define class_InnerClasses_F all_bands[e_class_InnerClasses_F]
409#define class_InnerClasses_outer_RCN all_bands[e_class_InnerClasses_outer_RCN]
410#define class_InnerClasses_name_RUN all_bands[e_class_InnerClasses_name_RUN]
411#define class_ClassFile_version_minor_H all_bands[e_class_ClassFile_version_minor_H]
412#define class_ClassFile_version_major_H all_bands[e_class_ClassFile_version_major_H]
413#define class_attr_bands all_bands[e_class_attr_bands]
414#define code_headers all_bands[e_code_headers]
415#define code_max_stack all_bands[e_code_max_stack]
416#define code_max_na_locals all_bands[e_code_max_na_locals]
417#define code_handler_count all_bands[e_code_handler_count]
418#define code_handler_start_P all_bands[e_code_handler_start_P]
419#define code_handler_end_PO all_bands[e_code_handler_end_PO]
420#define code_handler_catch_PO all_bands[e_code_handler_catch_PO]
421#define code_handler_class_RCN all_bands[e_code_handler_class_RCN]
422#define code_flags_hi all_bands[e_code_flags_hi]
423#define code_flags_lo all_bands[e_code_flags_lo]
424#define code_attr_count all_bands[e_code_attr_count]
425#define code_attr_indexes all_bands[e_code_attr_indexes]
426#define code_StackMapTable_N all_bands[e_code_StackMapTable_N]
427#define code_StackMapTable_frame_T all_bands[e_code_StackMapTable_frame_T]
428#define code_StackMapTable_local_N all_bands[e_code_StackMapTable_local_N]
429#define code_StackMapTable_stack_N all_bands[e_code_StackMapTable_stack_N]
430#define code_StackMapTable_offset all_bands[e_code_StackMapTable_offset]
431#define code_StackMapTable_T all_bands[e_code_StackMapTable_T]
432#define code_StackMapTable_RC all_bands[e_code_StackMapTable_RC]
433#define code_StackMapTable_P all_bands[e_code_StackMapTable_P]
434#define code_LineNumberTable_N all_bands[e_code_LineNumberTable_N]
435#define code_LineNumberTable_bci_P all_bands[e_code_LineNumberTable_bci_P]
436#define code_LineNumberTable_line all_bands[e_code_LineNumberTable_line]
437#define code_LocalVariableTable_N all_bands[e_code_LocalVariableTable_N]
438#define code_LocalVariableTable_bci_P all_bands[e_code_LocalVariableTable_bci_P]
439#define code_LocalVariableTable_span_O all_bands[e_code_LocalVariableTable_span_O]
440#define code_LocalVariableTable_name_RU all_bands[e_code_LocalVariableTable_name_RU]
441#define code_LocalVariableTable_type_RS all_bands[e_code_LocalVariableTable_type_RS]
442#define code_LocalVariableTable_slot all_bands[e_code_LocalVariableTable_slot]
443#define code_LocalVariableTypeTable_N all_bands[e_code_LocalVariableTypeTable_N]
444#define code_LocalVariableTypeTable_bci_P all_bands[e_code_LocalVariableTypeTable_bci_P]
445#define code_LocalVariableTypeTable_span_O all_bands[e_code_LocalVariableTypeTable_span_O]
446#define code_LocalVariableTypeTable_name_RU all_bands[e_code_LocalVariableTypeTable_name_RU]
447#define code_LocalVariableTypeTable_type_RS all_bands[e_code_LocalVariableTypeTable_type_RS]
448#define code_LocalVariableTypeTable_slot all_bands[e_code_LocalVariableTypeTable_slot]
449#define code_attr_bands all_bands[e_code_attr_bands]
450#define bc_codes all_bands[e_bc_codes]
451#define bc_case_count all_bands[e_bc_case_count]
452#define bc_case_value all_bands[e_bc_case_value]
453#define bc_byte all_bands[e_bc_byte]
454#define bc_short all_bands[e_bc_short]
455#define bc_local all_bands[e_bc_local]
456#define bc_label all_bands[e_bc_label]
457#define bc_intref all_bands[e_bc_intref]
458#define bc_floatref all_bands[e_bc_floatref]
459#define bc_longref all_bands[e_bc_longref]
460#define bc_doubleref all_bands[e_bc_doubleref]
461#define bc_stringref all_bands[e_bc_stringref]
462#define bc_loadablevalueref all_bands[e_bc_loadablevalueref]
463#define bc_classref all_bands[e_bc_classref]
464#define bc_fieldref all_bands[e_bc_fieldref]
465#define bc_methodref all_bands[e_bc_methodref]
466#define bc_imethodref all_bands[e_bc_imethodref]
467#define bc_indyref all_bands[e_bc_indyref]
468#define bc_thisfield all_bands[e_bc_thisfield]
469#define bc_superfield all_bands[e_bc_superfield]
470#define bc_thismethod all_bands[e_bc_thismethod]
471#define bc_supermethod all_bands[e_bc_supermethod]
472#define bc_initref all_bands[e_bc_initref]
473#define bc_escref all_bands[e_bc_escref]
474#define bc_escrefsize all_bands[e_bc_escrefsize]
475#define bc_escsize all_bands[e_bc_escsize]
476#define bc_escbyte all_bands[e_bc_escbyte]
477#define file_name all_bands[e_file_name]
478#define file_size_hi all_bands[e_file_size_hi]
479#define file_size_lo all_bands[e_file_size_lo]
480#define file_modtime all_bands[e_file_modtime]
481#define file_options all_bands[e_file_options]
482