250 // Skip rest of array info.
251 while (ch == '[') { ch = *sigp++; }
252 if (ch != 'L') break;
253 // else fall through
254 case 'L':
255 sigp = strchr(sigp, ';');
256 if (sigp == null) {
257 unpack_abort("bad data");
258 return 0;
259 }
260 sigp += 1;
261 break;
262 case ')': // closing ')'
263 return siglen;
264 }
265 siglen += 1;
266 }
267 }
268
269 inline cpindex* cpool::getFieldIndex(entry* classRef) {
270 assert(classRef->tagMatches(CONSTANT_Class));
271 assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
272 return &member_indexes[classRef->inord*2+0];
273 }
274 inline cpindex* cpool::getMethodIndex(entry* classRef) {
275 assert(classRef->tagMatches(CONSTANT_Class));
276 assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
277 return &member_indexes[classRef->inord*2+1];
278 }
279
280 struct inner_class {
281 entry* inner;
282 entry* outer;
283 entry* name;
284 int flags;
285 inner_class* next_sibling;
286 bool requested;
287 };
288
289 // Here is where everything gets deallocated:
290 void unpacker::free() {
291 int i;
292 assert(jniobj == null); // caller resp.
293 assert(infileptr == null); // caller resp.
294 if (jarout != null) jarout->reset();
1221 }
1222 }
1223 }
1224 //cp_band.done();
1225 }
1226
1227 maybe_inline
1228 void unpacker::read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag,
1229 entry* cpMap, int len) {
1230 band& cp_band1 = cp_band;
1231 band& cp_band2 = cp_band.nextBand();
1232 cp_band1.setIndexByTag(ref1Tag);
1233 cp_band2.setIndexByTag(ref2Tag);
1234 cp_band1.readData(len);
1235 cp_band2.readData(len);
1236 CHECK;
1237 for (int i = 0; i < len; i++) {
1238 entry& e = cpMap[i];
1239 e.refs = U_NEW(entry*, e.nrefs = 2);
1240 e.refs[0] = cp_band1.getRef();
1241 e.refs[1] = cp_band2.getRef();
1242 CHECK;
1243 }
1244 //cp_band1.done();
1245 //cp_band2.done();
1246 }
1247
1248 // Cf. PackageReader.readSignatureBands
1249 maybe_inline
1250 void unpacker::read_signature_values(entry* cpMap, int len) {
1251 cp_Signature_form.setIndexByTag(CONSTANT_Utf8);
1252 cp_Signature_form.readData(len);
1253 CHECK;
1254 int ncTotal = 0;
1255 int i;
1256 for (i = 0; i < len; i++) {
1257 entry& e = cpMap[i];
1258 entry& form = *cp_Signature_form.getRef();
1259 CHECK;
1260 int nc = 0;
1946 attr_defs[ATTR_CONTEXT_FIELD].predef
1947 = (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT));
1948 attr_defs[ATTR_CONTEXT_METHOD].predef
1949 = (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT));
1950 attr_defs[ATTR_CONTEXT_CODE].predef
1951 = (0 O_ATTR_DO(ORBIT) CODE_ATTR_DO(ORBIT));
1952 #undef ORBIT
1953 // Clear out the redef bits, folding them back into predef.
1954 for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
1955 attr_defs[i].predef |= attr_defs[i].redef;
1956 attr_defs[i].redef = 0;
1957 }
1958
1959 // Now read the transmitted locally defined attrs.
1960 // This will set redef bits again.
1961 for (i = 0; i < attr_definition_count; i++) {
1962 int header = attr_definition_headers.getByte();
1963 int attrc = ADH_BYTE_CONTEXT(header);
1964 int idx = ADH_BYTE_INDEX(header);
1965 entry* name = attr_definition_name.getRef();
1966 entry* layout = attr_definition_layout.getRef();
1967 CHECK;
1968 attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval());
1969 }
1970 }
1971
1972 #define NO_ENTRY_YET ((entry*)-1)
1973
1974 static bool isDigitString(bytes& x, int beg, int end) {
1975 if (beg == end) return false; // null string
1976 byte* xptr = x.ptr;
1977 for (int i = beg; i < end; i++) {
1978 char ch = xptr[i];
1979 if (!(ch >= '0' && ch <= '9')) return false;
1980 }
1981 return true;
1982 }
1983
1984 enum { // constants for parsing class names
1985 SLASH_MIN = '.',
2050 uint inord = inner->inord;
2051 assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
2052 if (ic_index[inord] != null) {
2053 abort("identical inner class");
2054 break;
2055 }
2056 ic_index[inord] = &ics[i];
2057 ics[i].inner = inner;
2058 ics[i].flags = flags;
2059 assert(cp.getIC(inner) == &ics[i]);
2060 }
2061 CHECK;
2062 //ic_this_class.done();
2063 //ic_flags.done();
2064 ic_outer_class.readData(long_forms);
2065 ic_name.readData(long_forms);
2066 for (i = 0; i < ic_count; i++) {
2067 if (ics[i].name == NO_ENTRY_YET) {
2068 // Long form.
2069 ics[i].outer = ic_outer_class.getRefN();
2070 ics[i].name = ic_name.getRefN();
2071 } else {
2072 // Fill in outer and name based on inner.
2073 bytes& n = ics[i].inner->value.b;
2074 bytes pkgOuter;
2075 bytes number;
2076 bytes name;
2077 // Parse n into pkgOuter and name (and number).
2078 PRINTCR((5, "parse short IC name %s", n.ptr));
2079 int dollar1, dollar2; // pointers to $ in the pattern
2080 // parse n = (<pkg>/)*<outer>($<number>)?($<name>)?
2081 int nlen = (int)n.len;
2082 int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1;
2083 dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
2084 if (dollar2 < 0) {
2085 abort();
2086 return;
2087 }
2088 assert(dollar2 >= pkglen);
2089 if (isDigitString(n, dollar2+1, nlen)) {
2090 // n = (<pkg>/)*<outer>$<number>
2566 int prevBCI = -1;
2567 if (body == NULL) {
2568 abort("putlayout: unexpected NULL for body");
2569 return;
2570 }
2571 for (i = 0; body[i] != null; i++) {
2572 band& b = *body[i];
2573 byte le_kind = b.le_kind;
2574
2575 // Handle scalar part, if any.
2576 int x = 0;
2577 entry* e = null;
2578 if (b.defc != null) {
2579 // It has data, so unparse an element.
2580 if (b.ixTag != CONSTANT_None) {
2581 assert(le_kind == EK_REF);
2582 if (b.ixTag == CONSTANT_Literal)
2583 e = b.getRefUsing(cp.getKQIndex());
2584 else
2585 e = b.getRefN();
2586 switch (b.le_len) {
2587 case 0: break;
2588 case 1: putu1ref(e); break;
2589 case 2: putref(e); break;
2590 case 4: putu2(0); putref(e); break;
2591 default: assert(false);
2592 }
2593 } else {
2594 assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
2595 x = b.getInt();
2596
2597 assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2598 switch (b.le_bci) {
2599 case EK_BCI: // PH: transmit R(bci), store bci
2600 x = to_bci(prevBII = x);
2601 prevBCI = x;
2602 break;
2603 case EK_BCID: // POH: transmit D(R(bci)), store bci
2604 x = to_bci(prevBII += x);
2605 prevBCI = x;
2947 }
2948 bc_case_count.rewind(); // uses again for output
2949
2950 all_switch_ops.free();
2951
2952 for (i = e_bc_case_value; i <= e_bc_escsize; i++) {
2953 all_bands[i].readData();
2954 }
2955
2956 // The bc_escbyte band is counted by the immediately previous band.
2957 bc_escbyte.readData(bc_escsize.getIntTotal());
2958
2959 PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...",
2960 (int)(bc_codes.size()),
2961 (int)(bc_escsize.maxRP() - bc_case_value.minRP()),
2962 code_count));
2963 }
2964
2965 void unpacker::read_bands() {
2966 byte* rp0 = rp;
2967
2968 read_file_header();
2969 CHECK;
2970
2971 if (cp.nentries == 0) {
2972 // read_file_header failed to read a CP, because it copied a JAR.
2973 return;
2974 }
2975
2976 // Do this after the file header has been read:
2977 check_options();
2978
2979 read_cp();
2980 CHECK;
2981 read_attr_defs();
2982 CHECK;
2983 read_ics();
2984 CHECK;
2985 read_classes();
2986 CHECK;
2987 read_bcs();
3615 DEBUG_VERBOSE,
3616 UNPACK_MODIFICATION_TIME,
3617 null
3618 };
3619 for (int i = 0; opts[i] != null; i++) {
3620 const char* str = get_option(opts[i]);
3621 if (str == null) {
3622 if (verbose == 0) continue;
3623 str = "(not set)";
3624 }
3625 fprintf(errstrm, "%s=%s\n", opts[i], str);
3626 }
3627 }
3628
3629
3630 // Usage: unpack a byte buffer
3631 // packptr is a reference to byte buffer containing a
3632 // packed file and len is the length of the buffer.
3633 // If null, the callback is used to fill an internal buffer.
3634 void unpacker::start(void* packptr, size_t len) {
3635 NOT_PRODUCT(debug_u = this);
3636 if (packptr != null && len != 0) {
3637 inbytes.set((byte*) packptr, len);
3638 }
3639 read_bands();
3640 }
3641
3642 void unpacker::check_options() {
3643 const char* strue = "true";
3644 const char* sfalse = "false";
3645 if (deflate_hint_or_zero != 0) {
3646 bool force_deflate_hint = (deflate_hint_or_zero > 0);
3647 if (force_deflate_hint)
3648 default_file_options |= FO_DEFLATE_HINT;
3649 else
3650 default_file_options &= ~FO_DEFLATE_HINT;
3651 // Turn off per-file deflate hint by force.
3652 suppress_file_options |= FO_DEFLATE_HINT;
3653 }
3654 if (modification_time_or_zero != 0) {
3655 default_file_modtime = modification_time_or_zero;
3656 // Turn off per-file modtime by force.
3657 archive_options &= ~AO_HAVE_FILE_MODTIME;
3658 }
3749
3750 size_t codeBase = wpoffset();
3751
3752 bool isAload; // copy-out result
3753 int origBC;
3754
3755 entry* thisClass = cur_class;
3756 entry* superClass = cur_super;
3757 entry* newClass = null; // class of last _new opcode
3758
3759 // overwrite any prior index on these bands; it changes w/ current class:
3760 bc_thisfield.setIndex( cp.getFieldIndex( thisClass));
3761 bc_thismethod.setIndex( cp.getMethodIndex(thisClass));
3762 if (superClass != null) {
3763 bc_superfield.setIndex( cp.getFieldIndex( superClass));
3764 bc_supermethod.setIndex(cp.getMethodIndex(superClass));
3765 } else {
3766 NOT_PRODUCT(bc_superfield.setIndex(null));
3767 NOT_PRODUCT(bc_supermethod.setIndex(null));
3768 }
3769
3770 for (int curIP = 0; ; curIP++) {
3771 int curPC = (int)(wpoffset() - codeBase);
3772 bcimap.add(curPC);
3773 ensure_put_space(10); // covers most instrs w/o further bounds check
3774 int bc = *opptr++ & 0xFF;
3775
3776 putu1_fast(bc);
3777 // Note: See '--wp' below for pseudo-bytecodes like bc_end_marker.
3778
3779 bool isWide = false;
3780 if (bc == bc_wide) {
3781 bc = *opptr++ & 0xFF;
3782 putu1_fast(bc);
3783 isWide = true;
3784 }
3785 switch (bc) {
3786 case bc_end_marker:
3787 --wp; // not really part of the code
3788 assert(opptr <= bc_codes.maxRP());
3862 int size = bc_escsize.getInt();
3863 ensure_put_space(size);
3864 for (int j = 0; j < size; j++)
3865 putu1_fast(bc_escbyte.getByte());
3866 continue;
3867 }
3868 default:
3869 if (is_invoke_init_op(bc)) {
3870 origBC = bc_invokespecial;
3871 entry* classRef;
3872 switch (bc - _invokeinit_op) {
3873 case _invokeinit_self_option: classRef = thisClass; break;
3874 case _invokeinit_super_option: classRef = superClass; break;
3875 default: assert(bc == _invokeinit_op+_invokeinit_new_option);
3876 case _invokeinit_new_option: classRef = newClass; break;
3877 }
3878 wp[-1] = origBC; // overwrite with origBC
3879 int coding = bc_initref.getInt();
3880 // Find the nth overloading of <init> in classRef.
3881 entry* ref = null;
3882 cpindex* ix = (classRef == null)? null: cp.getMethodIndex(classRef);
3883 for (int j = 0, which_init = 0; ; j++) {
3884 ref = (ix == null)? null: ix->get(j);
3885 if (ref == null) break; // oops, bad input
3886 assert(ref->tag == CONSTANT_Methodref);
3887 if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt]) {
3888 if (which_init++ == coding) break;
3889 }
3890 }
3891 putref(ref);
3892 continue;
3893 }
3894 bc_which = ref_band_for_self_op(bc, isAload, origBC);
3895 if (bc_which != null) {
3896 if (!isAload) {
3897 wp[-1] = origBC; // overwrite with origBC
3898 } else {
3899 wp[-1] = bc_aload_0; // overwrite with _aload_0
3900 // Note: insnMap keeps the _aload_0 separate.
3901 bcimap.add(++curPC);
3902 ++curIP;
4133 int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, (int)n.len)+1;
4134 bytes prefix = n.slice(pkglen, n.len);
4135 for (;;) {
4136 // Work backwards, finding all '$', '#', etc.
4137 int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len);
4138 if (dollar < 0) break;
4139 prefix = prefix.slice(0, dollar);
4140 }
4141 const char* suffix = ".java";
4142 int len = (int)(prefix.len + strlen(suffix));
4143 bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
4144 name.strcat(prefix).strcat(suffix);
4145 ref = cp.ensureUtf8(name);
4146 }
4147 putref(ref);
4148 break;
4149
4150 case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod):
4151 aname = cp.sym[cpool::s_EnclosingMethod];
4152 putref(class_EnclosingMethod_RC.getRefN());
4153 putref(class_EnclosingMethod_RDN.getRefN());
4154 break;
4155
4156 case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
4157 aname = cp.sym[cpool::s_ConstantValue];
4158 putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
4159 break;
4160
4161 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
4162 aname = cp.sym[cpool::s_Code];
4163 write_code();
4164 break;
4165
4166 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
4167 aname = cp.sym[cpool::s_Exceptions];
4168 putu2(count = method_Exceptions_N.getInt());
4169 for (j = 0; j < count; j++) {
4170 putref(method_Exceptions_RC.getRefN());
4171 }
4172 break;
4173
4174 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
4175 aname = cp.sym[cpool::s_StackMapTable];
4176 // (keep this code aligned with its brother in unpacker::read_attrs)
4177 putu2(count = code_StackMapTable_N.getInt());
4178 for (j = 0; j < count; j++) {
4179 int tag = code_StackMapTable_frame_T.getByte();
4180 putu1(tag);
4181 if (tag <= 127) {
4182 // (64-127) [(2)]
4183 if (tag >= 64) put_stackmap_type();
4184 } else if (tag <= 251) {
4185 // (247) [(1)(2)]
4186 // (248-251) [(1)]
4187 if (tag >= 247) putu2(code_StackMapTable_offset.getInt());
4188 if (tag == 247) put_stackmap_type();
4189 } else if (tag <= 254) {
4190 // (252) [(1)(2)]
4191 // (253) [(1)(2)(2)]
4192 // (254) [(1)(2)(2)(2)]
4193 putu2(code_StackMapTable_offset.getInt());
4194 for (int k = (tag - 251); k > 0; k--) {
4195 put_stackmap_type();
4196 }
4197 } else {
4198 // (255) [(1)NH[(2)]NH[(2)]]
4199 putu2(code_StackMapTable_offset.getInt());
4200 putu2(j2 = code_StackMapTable_local_N.getInt());
4201 while (j2-- > 0) put_stackmap_type();
4202 putu2(j2 = code_StackMapTable_stack_N.getInt());
4203 while (j2-- > 0) put_stackmap_type();
4204 }
4205 }
4206 break;
4207
4208 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable):
4209 aname = cp.sym[cpool::s_LineNumberTable];
4210 putu2(count = code_LineNumberTable_N.getInt());
4211 for (j = 0; j < count; j++) {
4212 putu2(to_bci(code_LineNumberTable_bci_P.getInt()));
4213 putu2(code_LineNumberTable_line.getInt());
4214 }
4215 break;
4216
4217 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable):
4218 aname = cp.sym[cpool::s_LocalVariableTable];
4219 putu2(count = code_LocalVariableTable_N.getInt());
4220 for (j = 0; j < count; j++) {
4221 int bii = code_LocalVariableTable_bci_P.getInt();
4222 int bci = to_bci(bii);
4223 putu2(bci);
4224 bii += code_LocalVariableTable_span_O.getInt();
4225 putu2(to_bci(bii) - bci);
4226 putref(code_LocalVariableTable_name_RU.getRefN());
4227 putref(code_LocalVariableTable_type_RS.getRefN());
4228 putu2(code_LocalVariableTable_slot.getInt());
4229 }
4230 break;
4231
4232 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable):
4233 aname = cp.sym[cpool::s_LocalVariableTypeTable];
4234 putu2(count = code_LocalVariableTypeTable_N.getInt());
4235 for (j = 0; j < count; j++) {
4236 int bii = code_LocalVariableTypeTable_bci_P.getInt();
4237 int bci = to_bci(bii);
4238 putu2(bci);
4239 bii += code_LocalVariableTypeTable_span_O.getInt();
4240 putu2(to_bci(bii) - bci);
4241 putref(code_LocalVariableTypeTable_name_RU.getRefN());
4242 putref(code_LocalVariableTypeTable_type_RS.getRefN());
4243 putu2(code_LocalVariableTypeTable_slot.getInt());
4244 }
4245 break;
4246
4247 case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature):
4248 aname = cp.sym[cpool::s_Signature];
4249 putref(class_Signature_RS.getRefN());
4250 break;
4251
4252 case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature):
4253 aname = cp.sym[cpool::s_Signature];
4254 putref(field_Signature_RS.getRefN());
4255 break;
4256
4257 case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature):
4258 aname = cp.sym[cpool::s_Signature];
4259 putref(method_Signature_RS.getRefN());
4260 break;
4261
4262 case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Deprecated):
4263 case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Deprecated):
4264 case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated):
4265 aname = cp.sym[cpool::s_Deprecated];
4266 // no data
4267 break;
4268 }
4269 }
4270
4271 if (aname == null) {
4272 // Unparse a compressor-defined attribute.
4273 layout_definition* lo = ad.getLayout(idx);
4274 if (lo == null) {
4275 abort("bad layout index");
4276 break;
4277 }
4278 assert((int)lo->idx == idx);
4279 aname = lo->nameEntry;
4280 if (aname == null) {
4281 bytes nameb; nameb.set(lo->name);
4282 aname = cp.ensureUtf8(nameb);
4283 // Cache the name entry for next time.
4284 lo->nameEntry = aname;
4285 }
4286 // Execute all the layout elements.
4287 band** bands = lo->bands();
4288 if (lo->hasCallables()) {
4289 band& cble = *bands[0];
4290 assert(cble.le_kind == EK_CBLE);
4349 extern "C"
4350 int raw_address_cmp(const void* p1p, const void* p2p) {
4351 void* p1 = *(void**) p1p;
4352 void* p2 = *(void**) p2p;
4353 return (p1 > p2)? 1: (p1 < p2)? -1: 0;
4354 }
4355
4356 void unpacker::write_classfile_tail() {
4357 cur_classfile_tail.empty();
4358 set_output(&cur_classfile_tail);
4359
4360 int i, num;
4361
4362 attr_definitions& ad = attr_defs[ATTR_CONTEXT_CLASS];
4363
4364 bool haveLongFlags = ad.haveLongFlags();
4365 julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
4366 julong indexMask = ad.flagIndexMask();
4367
4368 cur_class = class_this.getRef();
4369 cur_super = class_super.getRef();
4370
4371 CHECK;
4372
4373 if (cur_super == cur_class) cur_super = null;
4374 // special representation for java/lang/Object
4375
4376 putu2((ushort)(kflags & ~indexMask));
4377 putref(cur_class);
4378 putref(cur_super);
4379
4380 putu2(num = class_interface_count.getInt());
4381 for (i = 0; i < num; i++) {
4382 putref(class_interface.getRef());
4383 }
4384
4385 write_members(class_field_count.getInt(), ATTR_CONTEXT_FIELD);
4386 write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD);
4387 CHECK;
4388
4389 cur_class_has_local_ics = false; // may be set true by write_attrs
4390
4391
4392 int naOffset = (int)wpoffset();
4393 int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
4394
4395
4396 // at the very last, choose which inner classes (if any) pertain to k:
4397 #ifdef ASSERT
4398 for (i = 0; i < ic_count; i++) {
4399 assert(!ics[i].requested);
4400 }
4401 #endif
4402 // First, consult the global table and the local constant pool,
4443 }
4444 }
4445 for (i = 0; i < num_extra_ics; i++) {
4446 inner_class& extra_ic = extra_ics[i];
4447 extra_ic.inner = class_InnerClasses_RC.getRef();
4448 CHECK;
4449 // Find the corresponding equivalent global IC:
4450 inner_class* global_ic = cp.getIC(extra_ic.inner);
4451 int flags = class_InnerClasses_F.getInt();
4452 if (flags == 0) {
4453 // The extra IC is simply a copy of a global IC.
4454 if (global_ic == null) {
4455 abort("bad reference to inner class");
4456 break;
4457 }
4458 extra_ic = (*global_ic); // fill in rest of fields
4459 } else {
4460 flags &= ~ACC_IC_LONG_FORM; // clear high bit if set to get clean zero
4461 extra_ic.flags = flags;
4462 extra_ic.outer = class_InnerClasses_outer_RCN.getRefN();
4463 extra_ic.name = class_InnerClasses_name_RUN.getRefN();
4464 // Detect if this is an exact copy of the global tuple.
4465 if (global_ic != null) {
4466 if (global_ic->flags != extra_ic.flags ||
4467 global_ic->outer != extra_ic.outer ||
4468 global_ic->name != extra_ic.name) {
4469 global_ic = null; // not really the same, so break the link
4470 }
4471 }
4472 }
4473 if (global_ic != null && global_ic->requested) {
4474 // This local repetition reverses the globally implied request.
4475 global_ic->requested = false;
4476 extra_ic.requested = false;
4477 local_ics -= 1;
4478 } else {
4479 // The global either does not exist, or is not yet requested.
4480 extra_ic.requested = true;
4481 local_ics += 1;
4482 }
4483 }
|
250 // Skip rest of array info.
251 while (ch == '[') { ch = *sigp++; }
252 if (ch != 'L') break;
253 // else fall through
254 case 'L':
255 sigp = strchr(sigp, ';');
256 if (sigp == null) {
257 unpack_abort("bad data");
258 return 0;
259 }
260 sigp += 1;
261 break;
262 case ')': // closing ')'
263 return siglen;
264 }
265 siglen += 1;
266 }
267 }
268
269 inline cpindex* cpool::getFieldIndex(entry* classRef) {
270 if (classRef == NULL) { abort("missing class reference"); return NULL; }
271 assert(classRef->tagMatches(CONSTANT_Class));
272 assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
273 return &member_indexes[classRef->inord*2+0];
274 }
275 inline cpindex* cpool::getMethodIndex(entry* classRef) {
276 if (classRef == NULL) { abort("missing class reference"); return NULL; }
277 assert(classRef->tagMatches(CONSTANT_Class));
278 assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
279 return &member_indexes[classRef->inord*2+1];
280 }
281
282 struct inner_class {
283 entry* inner;
284 entry* outer;
285 entry* name;
286 int flags;
287 inner_class* next_sibling;
288 bool requested;
289 };
290
291 // Here is where everything gets deallocated:
292 void unpacker::free() {
293 int i;
294 assert(jniobj == null); // caller resp.
295 assert(infileptr == null); // caller resp.
296 if (jarout != null) jarout->reset();
1223 }
1224 }
1225 }
1226 //cp_band.done();
1227 }
1228
1229 maybe_inline
1230 void unpacker::read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag,
1231 entry* cpMap, int len) {
1232 band& cp_band1 = cp_band;
1233 band& cp_band2 = cp_band.nextBand();
1234 cp_band1.setIndexByTag(ref1Tag);
1235 cp_band2.setIndexByTag(ref2Tag);
1236 cp_band1.readData(len);
1237 cp_band2.readData(len);
1238 CHECK;
1239 for (int i = 0; i < len; i++) {
1240 entry& e = cpMap[i];
1241 e.refs = U_NEW(entry*, e.nrefs = 2);
1242 e.refs[0] = cp_band1.getRef();
1243 CHECK;
1244 e.refs[1] = cp_band2.getRef();
1245 CHECK;
1246 }
1247 //cp_band1.done();
1248 //cp_band2.done();
1249 }
1250
1251 // Cf. PackageReader.readSignatureBands
1252 maybe_inline
1253 void unpacker::read_signature_values(entry* cpMap, int len) {
1254 cp_Signature_form.setIndexByTag(CONSTANT_Utf8);
1255 cp_Signature_form.readData(len);
1256 CHECK;
1257 int ncTotal = 0;
1258 int i;
1259 for (i = 0; i < len; i++) {
1260 entry& e = cpMap[i];
1261 entry& form = *cp_Signature_form.getRef();
1262 CHECK;
1263 int nc = 0;
1949 attr_defs[ATTR_CONTEXT_FIELD].predef
1950 = (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT));
1951 attr_defs[ATTR_CONTEXT_METHOD].predef
1952 = (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT));
1953 attr_defs[ATTR_CONTEXT_CODE].predef
1954 = (0 O_ATTR_DO(ORBIT) CODE_ATTR_DO(ORBIT));
1955 #undef ORBIT
1956 // Clear out the redef bits, folding them back into predef.
1957 for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) {
1958 attr_defs[i].predef |= attr_defs[i].redef;
1959 attr_defs[i].redef = 0;
1960 }
1961
1962 // Now read the transmitted locally defined attrs.
1963 // This will set redef bits again.
1964 for (i = 0; i < attr_definition_count; i++) {
1965 int header = attr_definition_headers.getByte();
1966 int attrc = ADH_BYTE_CONTEXT(header);
1967 int idx = ADH_BYTE_INDEX(header);
1968 entry* name = attr_definition_name.getRef();
1969 CHECK;
1970 entry* layout = attr_definition_layout.getRef();
1971 CHECK;
1972 attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval());
1973 }
1974 }
1975
1976 #define NO_ENTRY_YET ((entry*)-1)
1977
1978 static bool isDigitString(bytes& x, int beg, int end) {
1979 if (beg == end) return false; // null string
1980 byte* xptr = x.ptr;
1981 for (int i = beg; i < end; i++) {
1982 char ch = xptr[i];
1983 if (!(ch >= '0' && ch <= '9')) return false;
1984 }
1985 return true;
1986 }
1987
1988 enum { // constants for parsing class names
1989 SLASH_MIN = '.',
2054 uint inord = inner->inord;
2055 assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
2056 if (ic_index[inord] != null) {
2057 abort("identical inner class");
2058 break;
2059 }
2060 ic_index[inord] = &ics[i];
2061 ics[i].inner = inner;
2062 ics[i].flags = flags;
2063 assert(cp.getIC(inner) == &ics[i]);
2064 }
2065 CHECK;
2066 //ic_this_class.done();
2067 //ic_flags.done();
2068 ic_outer_class.readData(long_forms);
2069 ic_name.readData(long_forms);
2070 for (i = 0; i < ic_count; i++) {
2071 if (ics[i].name == NO_ENTRY_YET) {
2072 // Long form.
2073 ics[i].outer = ic_outer_class.getRefN();
2074 CHECK;
2075 ics[i].name = ic_name.getRefN();
2076 CHECK;
2077 } else {
2078 // Fill in outer and name based on inner.
2079 bytes& n = ics[i].inner->value.b;
2080 bytes pkgOuter;
2081 bytes number;
2082 bytes name;
2083 // Parse n into pkgOuter and name (and number).
2084 PRINTCR((5, "parse short IC name %s", n.ptr));
2085 int dollar1, dollar2; // pointers to $ in the pattern
2086 // parse n = (<pkg>/)*<outer>($<number>)?($<name>)?
2087 int nlen = (int)n.len;
2088 int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1;
2089 dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
2090 if (dollar2 < 0) {
2091 abort();
2092 return;
2093 }
2094 assert(dollar2 >= pkglen);
2095 if (isDigitString(n, dollar2+1, nlen)) {
2096 // n = (<pkg>/)*<outer>$<number>
2572 int prevBCI = -1;
2573 if (body == NULL) {
2574 abort("putlayout: unexpected NULL for body");
2575 return;
2576 }
2577 for (i = 0; body[i] != null; i++) {
2578 band& b = *body[i];
2579 byte le_kind = b.le_kind;
2580
2581 // Handle scalar part, if any.
2582 int x = 0;
2583 entry* e = null;
2584 if (b.defc != null) {
2585 // It has data, so unparse an element.
2586 if (b.ixTag != CONSTANT_None) {
2587 assert(le_kind == EK_REF);
2588 if (b.ixTag == CONSTANT_Literal)
2589 e = b.getRefUsing(cp.getKQIndex());
2590 else
2591 e = b.getRefN();
2592 CHECK;
2593 switch (b.le_len) {
2594 case 0: break;
2595 case 1: putu1ref(e); break;
2596 case 2: putref(e); break;
2597 case 4: putu2(0); putref(e); break;
2598 default: assert(false);
2599 }
2600 } else {
2601 assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
2602 x = b.getInt();
2603
2604 assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
2605 switch (b.le_bci) {
2606 case EK_BCI: // PH: transmit R(bci), store bci
2607 x = to_bci(prevBII = x);
2608 prevBCI = x;
2609 break;
2610 case EK_BCID: // POH: transmit D(R(bci)), store bci
2611 x = to_bci(prevBII += x);
2612 prevBCI = x;
2954 }
2955 bc_case_count.rewind(); // uses again for output
2956
2957 all_switch_ops.free();
2958
2959 for (i = e_bc_case_value; i <= e_bc_escsize; i++) {
2960 all_bands[i].readData();
2961 }
2962
2963 // The bc_escbyte band is counted by the immediately previous band.
2964 bc_escbyte.readData(bc_escsize.getIntTotal());
2965
2966 PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...",
2967 (int)(bc_codes.size()),
2968 (int)(bc_escsize.maxRP() - bc_case_value.minRP()),
2969 code_count));
2970 }
2971
2972 void unpacker::read_bands() {
2973 byte* rp0 = rp;
2974 CHECK;
2975 read_file_header();
2976 CHECK;
2977
2978 if (cp.nentries == 0) {
2979 // read_file_header failed to read a CP, because it copied a JAR.
2980 return;
2981 }
2982
2983 // Do this after the file header has been read:
2984 check_options();
2985
2986 read_cp();
2987 CHECK;
2988 read_attr_defs();
2989 CHECK;
2990 read_ics();
2991 CHECK;
2992 read_classes();
2993 CHECK;
2994 read_bcs();
3622 DEBUG_VERBOSE,
3623 UNPACK_MODIFICATION_TIME,
3624 null
3625 };
3626 for (int i = 0; opts[i] != null; i++) {
3627 const char* str = get_option(opts[i]);
3628 if (str == null) {
3629 if (verbose == 0) continue;
3630 str = "(not set)";
3631 }
3632 fprintf(errstrm, "%s=%s\n", opts[i], str);
3633 }
3634 }
3635
3636
3637 // Usage: unpack a byte buffer
3638 // packptr is a reference to byte buffer containing a
3639 // packed file and len is the length of the buffer.
3640 // If null, the callback is used to fill an internal buffer.
3641 void unpacker::start(void* packptr, size_t len) {
3642 CHECK;
3643 NOT_PRODUCT(debug_u = this);
3644 if (packptr != null && len != 0) {
3645 inbytes.set((byte*) packptr, len);
3646 }
3647 CHECK;
3648 read_bands();
3649 }
3650
3651 void unpacker::check_options() {
3652 const char* strue = "true";
3653 const char* sfalse = "false";
3654 if (deflate_hint_or_zero != 0) {
3655 bool force_deflate_hint = (deflate_hint_or_zero > 0);
3656 if (force_deflate_hint)
3657 default_file_options |= FO_DEFLATE_HINT;
3658 else
3659 default_file_options &= ~FO_DEFLATE_HINT;
3660 // Turn off per-file deflate hint by force.
3661 suppress_file_options |= FO_DEFLATE_HINT;
3662 }
3663 if (modification_time_or_zero != 0) {
3664 default_file_modtime = modification_time_or_zero;
3665 // Turn off per-file modtime by force.
3666 archive_options &= ~AO_HAVE_FILE_MODTIME;
3667 }
3758
3759 size_t codeBase = wpoffset();
3760
3761 bool isAload; // copy-out result
3762 int origBC;
3763
3764 entry* thisClass = cur_class;
3765 entry* superClass = cur_super;
3766 entry* newClass = null; // class of last _new opcode
3767
3768 // overwrite any prior index on these bands; it changes w/ current class:
3769 bc_thisfield.setIndex( cp.getFieldIndex( thisClass));
3770 bc_thismethod.setIndex( cp.getMethodIndex(thisClass));
3771 if (superClass != null) {
3772 bc_superfield.setIndex( cp.getFieldIndex( superClass));
3773 bc_supermethod.setIndex(cp.getMethodIndex(superClass));
3774 } else {
3775 NOT_PRODUCT(bc_superfield.setIndex(null));
3776 NOT_PRODUCT(bc_supermethod.setIndex(null));
3777 }
3778 CHECK;
3779
3780 for (int curIP = 0; ; curIP++) {
3781 int curPC = (int)(wpoffset() - codeBase);
3782 bcimap.add(curPC);
3783 ensure_put_space(10); // covers most instrs w/o further bounds check
3784 int bc = *opptr++ & 0xFF;
3785
3786 putu1_fast(bc);
3787 // Note: See '--wp' below for pseudo-bytecodes like bc_end_marker.
3788
3789 bool isWide = false;
3790 if (bc == bc_wide) {
3791 bc = *opptr++ & 0xFF;
3792 putu1_fast(bc);
3793 isWide = true;
3794 }
3795 switch (bc) {
3796 case bc_end_marker:
3797 --wp; // not really part of the code
3798 assert(opptr <= bc_codes.maxRP());
3872 int size = bc_escsize.getInt();
3873 ensure_put_space(size);
3874 for (int j = 0; j < size; j++)
3875 putu1_fast(bc_escbyte.getByte());
3876 continue;
3877 }
3878 default:
3879 if (is_invoke_init_op(bc)) {
3880 origBC = bc_invokespecial;
3881 entry* classRef;
3882 switch (bc - _invokeinit_op) {
3883 case _invokeinit_self_option: classRef = thisClass; break;
3884 case _invokeinit_super_option: classRef = superClass; break;
3885 default: assert(bc == _invokeinit_op+_invokeinit_new_option);
3886 case _invokeinit_new_option: classRef = newClass; break;
3887 }
3888 wp[-1] = origBC; // overwrite with origBC
3889 int coding = bc_initref.getInt();
3890 // Find the nth overloading of <init> in classRef.
3891 entry* ref = null;
3892 cpindex* ix = cp.getMethodIndex(classRef);
3893 CHECK;
3894 for (int j = 0, which_init = 0; ; j++) {
3895 ref = (ix == null)? null: ix->get(j);
3896 if (ref == null) break; // oops, bad input
3897 assert(ref->tag == CONSTANT_Methodref);
3898 if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt]) {
3899 if (which_init++ == coding) break;
3900 }
3901 }
3902 putref(ref);
3903 continue;
3904 }
3905 bc_which = ref_band_for_self_op(bc, isAload, origBC);
3906 if (bc_which != null) {
3907 if (!isAload) {
3908 wp[-1] = origBC; // overwrite with origBC
3909 } else {
3910 wp[-1] = bc_aload_0; // overwrite with _aload_0
3911 // Note: insnMap keeps the _aload_0 separate.
3912 bcimap.add(++curPC);
3913 ++curIP;
4144 int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, (int)n.len)+1;
4145 bytes prefix = n.slice(pkglen, n.len);
4146 for (;;) {
4147 // Work backwards, finding all '$', '#', etc.
4148 int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len);
4149 if (dollar < 0) break;
4150 prefix = prefix.slice(0, dollar);
4151 }
4152 const char* suffix = ".java";
4153 int len = (int)(prefix.len + strlen(suffix));
4154 bytes name; name.set(T_NEW(byte, add_size(len, 1)), len);
4155 name.strcat(prefix).strcat(suffix);
4156 ref = cp.ensureUtf8(name);
4157 }
4158 putref(ref);
4159 break;
4160
4161 case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod):
4162 aname = cp.sym[cpool::s_EnclosingMethod];
4163 putref(class_EnclosingMethod_RC.getRefN());
4164 CHECK_0;
4165 putref(class_EnclosingMethod_RDN.getRefN());
4166 break;
4167
4168 case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue):
4169 aname = cp.sym[cpool::s_ConstantValue];
4170 putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex()));
4171 break;
4172
4173 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code):
4174 aname = cp.sym[cpool::s_Code];
4175 write_code();
4176 break;
4177
4178 case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions):
4179 aname = cp.sym[cpool::s_Exceptions];
4180 putu2(count = method_Exceptions_N.getInt());
4181 for (j = 0; j < count; j++) {
4182 putref(method_Exceptions_RC.getRefN());
4183 CHECK_0;
4184 }
4185 break;
4186
4187 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable):
4188 aname = cp.sym[cpool::s_StackMapTable];
4189 // (keep this code aligned with its brother in unpacker::read_attrs)
4190 putu2(count = code_StackMapTable_N.getInt());
4191 for (j = 0; j < count; j++) {
4192 int tag = code_StackMapTable_frame_T.getByte();
4193 putu1(tag);
4194 if (tag <= 127) {
4195 // (64-127) [(2)]
4196 if (tag >= 64) put_stackmap_type();
4197 } else if (tag <= 251) {
4198 // (247) [(1)(2)]
4199 // (248-251) [(1)]
4200 if (tag >= 247) putu2(code_StackMapTable_offset.getInt());
4201 if (tag == 247) put_stackmap_type();
4202 } else if (tag <= 254) {
4203 // (252) [(1)(2)]
4204 // (253) [(1)(2)(2)]
4205 // (254) [(1)(2)(2)(2)]
4206 putu2(code_StackMapTable_offset.getInt());
4207 CHECK_0;
4208 for (int k = (tag - 251); k > 0; k--) {
4209 put_stackmap_type();
4210 CHECK_0;
4211 }
4212 } else {
4213 // (255) [(1)NH[(2)]NH[(2)]]
4214 putu2(code_StackMapTable_offset.getInt());
4215 putu2(j2 = code_StackMapTable_local_N.getInt());
4216 while (j2-- > 0) {put_stackmap_type(); CHECK_0;}
4217 putu2(j2 = code_StackMapTable_stack_N.getInt());
4218 while (j2-- > 0) {put_stackmap_type(); CHECK_0;}
4219 }
4220 }
4221 break;
4222
4223 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable):
4224 aname = cp.sym[cpool::s_LineNumberTable];
4225 putu2(count = code_LineNumberTable_N.getInt());
4226 for (j = 0; j < count; j++) {
4227 putu2(to_bci(code_LineNumberTable_bci_P.getInt()));
4228 putu2(code_LineNumberTable_line.getInt());
4229 }
4230 break;
4231
4232 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable):
4233 aname = cp.sym[cpool::s_LocalVariableTable];
4234 putu2(count = code_LocalVariableTable_N.getInt());
4235 for (j = 0; j < count; j++) {
4236 int bii = code_LocalVariableTable_bci_P.getInt();
4237 int bci = to_bci(bii);
4238 putu2(bci);
4239 bii += code_LocalVariableTable_span_O.getInt();
4240 putu2(to_bci(bii) - bci);
4241 putref(code_LocalVariableTable_name_RU.getRefN());
4242 CHECK_0;
4243 putref(code_LocalVariableTable_type_RS.getRefN());
4244 CHECK_0;
4245 putu2(code_LocalVariableTable_slot.getInt());
4246 }
4247 break;
4248
4249 case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable):
4250 aname = cp.sym[cpool::s_LocalVariableTypeTable];
4251 putu2(count = code_LocalVariableTypeTable_N.getInt());
4252 for (j = 0; j < count; j++) {
4253 int bii = code_LocalVariableTypeTable_bci_P.getInt();
4254 int bci = to_bci(bii);
4255 putu2(bci);
4256 bii += code_LocalVariableTypeTable_span_O.getInt();
4257 putu2(to_bci(bii) - bci);
4258 putref(code_LocalVariableTypeTable_name_RU.getRefN());
4259 CHECK_0;
4260 putref(code_LocalVariableTypeTable_type_RS.getRefN());
4261 CHECK_0;
4262 putu2(code_LocalVariableTypeTable_slot.getInt());
4263 }
4264 break;
4265
4266 case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature):
4267 aname = cp.sym[cpool::s_Signature];
4268 putref(class_Signature_RS.getRefN());
4269 break;
4270
4271 case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature):
4272 aname = cp.sym[cpool::s_Signature];
4273 putref(field_Signature_RS.getRefN());
4274 break;
4275
4276 case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature):
4277 aname = cp.sym[cpool::s_Signature];
4278 putref(method_Signature_RS.getRefN());
4279 break;
4280
4281 case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Deprecated):
4282 case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Deprecated):
4283 case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated):
4284 aname = cp.sym[cpool::s_Deprecated];
4285 // no data
4286 break;
4287 }
4288 }
4289 CHECK_0;
4290 if (aname == null) {
4291 // Unparse a compressor-defined attribute.
4292 layout_definition* lo = ad.getLayout(idx);
4293 if (lo == null) {
4294 abort("bad layout index");
4295 break;
4296 }
4297 assert((int)lo->idx == idx);
4298 aname = lo->nameEntry;
4299 if (aname == null) {
4300 bytes nameb; nameb.set(lo->name);
4301 aname = cp.ensureUtf8(nameb);
4302 // Cache the name entry for next time.
4303 lo->nameEntry = aname;
4304 }
4305 // Execute all the layout elements.
4306 band** bands = lo->bands();
4307 if (lo->hasCallables()) {
4308 band& cble = *bands[0];
4309 assert(cble.le_kind == EK_CBLE);
4368 extern "C"
4369 int raw_address_cmp(const void* p1p, const void* p2p) {
4370 void* p1 = *(void**) p1p;
4371 void* p2 = *(void**) p2p;
4372 return (p1 > p2)? 1: (p1 < p2)? -1: 0;
4373 }
4374
4375 void unpacker::write_classfile_tail() {
4376 cur_classfile_tail.empty();
4377 set_output(&cur_classfile_tail);
4378
4379 int i, num;
4380
4381 attr_definitions& ad = attr_defs[ATTR_CONTEXT_CLASS];
4382
4383 bool haveLongFlags = ad.haveLongFlags();
4384 julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags);
4385 julong indexMask = ad.flagIndexMask();
4386
4387 cur_class = class_this.getRef();
4388 CHECK;
4389 cur_super = class_super.getRef();
4390
4391 CHECK;
4392
4393 if (cur_super == cur_class) cur_super = null;
4394 // special representation for java/lang/Object
4395
4396 putu2((ushort)(kflags & ~indexMask));
4397 putref(cur_class);
4398 putref(cur_super);
4399
4400 putu2(num = class_interface_count.getInt());
4401 for (i = 0; i < num; i++) {
4402 putref(class_interface.getRef());
4403 CHECK;
4404 }
4405
4406 write_members(class_field_count.getInt(), ATTR_CONTEXT_FIELD);
4407 write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD);
4408 CHECK;
4409
4410 cur_class_has_local_ics = false; // may be set true by write_attrs
4411
4412
4413 int naOffset = (int)wpoffset();
4414 int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
4415
4416
4417 // at the very last, choose which inner classes (if any) pertain to k:
4418 #ifdef ASSERT
4419 for (i = 0; i < ic_count; i++) {
4420 assert(!ics[i].requested);
4421 }
4422 #endif
4423 // First, consult the global table and the local constant pool,
4464 }
4465 }
4466 for (i = 0; i < num_extra_ics; i++) {
4467 inner_class& extra_ic = extra_ics[i];
4468 extra_ic.inner = class_InnerClasses_RC.getRef();
4469 CHECK;
4470 // Find the corresponding equivalent global IC:
4471 inner_class* global_ic = cp.getIC(extra_ic.inner);
4472 int flags = class_InnerClasses_F.getInt();
4473 if (flags == 0) {
4474 // The extra IC is simply a copy of a global IC.
4475 if (global_ic == null) {
4476 abort("bad reference to inner class");
4477 break;
4478 }
4479 extra_ic = (*global_ic); // fill in rest of fields
4480 } else {
4481 flags &= ~ACC_IC_LONG_FORM; // clear high bit if set to get clean zero
4482 extra_ic.flags = flags;
4483 extra_ic.outer = class_InnerClasses_outer_RCN.getRefN();
4484 CHECK;
4485 extra_ic.name = class_InnerClasses_name_RUN.getRefN();
4486 CHECK;
4487 // Detect if this is an exact copy of the global tuple.
4488 if (global_ic != null) {
4489 if (global_ic->flags != extra_ic.flags ||
4490 global_ic->outer != extra_ic.outer ||
4491 global_ic->name != extra_ic.name) {
4492 global_ic = null; // not really the same, so break the link
4493 }
4494 }
4495 }
4496 if (global_ic != null && global_ic->requested) {
4497 // This local repetition reverses the globally implied request.
4498 global_ic->requested = false;
4499 extra_ic.requested = false;
4500 local_ics -= 1;
4501 } else {
4502 // The global either does not exist, or is not yet requested.
4503 extra_ic.requested = true;
4504 local_ics += 1;
4505 }
4506 }
|