author | mchung |
Mon, 23 Nov 2015 12:44:43 -0800 | |
changeset 34253 | ba3946143842 |
parent 29591 | 51244d1ddffc |
child 41572 | 0b3abcb3879a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23920 | 2 |
* Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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 |
* |
|
5506 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
// -*- C++ -*- |
|
27 |
// Program for unpacking specially compressed Java packages. |
|
28 |
// John R. Rose |
|
29 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
30 |
/* |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
31 |
* When compiling for a 64bit LP64 system (longs and pointers being 64bits), |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
32 |
* the printf format %ld is correct and use of %lld will cause warning |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
33 |
* errors from some compilers (gcc/g++). |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
34 |
* _LP64 can be explicitly set (used on Linux). |
26457
1c341086cc51
8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents:
25859
diff
changeset
|
35 |
* Should be checking for the Visual C++ since the _LP64 is set on the 64-bit |
1c341086cc51
8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents:
25859
diff
changeset
|
36 |
* systems but the correct format prefix for 64-bit integers is ll. |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
37 |
* Solaris compilers will define __sparcv9 or __x86_64 on 64bit compilations. |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
38 |
*/ |
26457
1c341086cc51
8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents:
25859
diff
changeset
|
39 |
#if !defined (_MSC_VER) && \ |
1c341086cc51
8051989: Unportable format string argument mismatch in jdk/src/share/native/com/sun/java/util/jar/pack/unpack.cpp
kizune
parents:
25859
diff
changeset
|
40 |
(defined(_LP64) || defined(__sparcv9) || defined(__x86_64)) |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
41 |
#define LONG_LONG_FORMAT "%ld" |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
42 |
#define LONG_LONG_HEX_FORMAT "%lx" |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
43 |
#else |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
44 |
#define LONG_LONG_FORMAT "%lld" |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
45 |
#define LONG_LONG_HEX_FORMAT "%016llx" |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
46 |
#endif |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
47 |
|
2 | 48 |
#include <sys/types.h> |
49 |
||
50 |
#include <stdio.h> |
|
51 |
#include <string.h> |
|
52 |
#include <stdlib.h> |
|
53 |
#include <stdarg.h> |
|
54 |
||
55 |
#include <limits.h> |
|
56 |
#include <time.h> |
|
57 |
||
58 |
||
59 |
||
60 |
||
61 |
#include "defines.h" |
|
62 |
#include "bytes.h" |
|
63 |
#include "utils.h" |
|
64 |
#include "coding.h" |
|
65 |
#include "bands.h" |
|
66 |
||
67 |
#include "constants.h" |
|
68 |
||
69 |
#include "zip.h" |
|
70 |
||
71 |
#include "unpack.h" |
|
72 |
||
73 |
||
74 |
// tags, in canonical order: |
|
75 |
static const byte TAGS_IN_ORDER[] = { |
|
76 |
CONSTANT_Utf8, |
|
77 |
CONSTANT_Integer, |
|
78 |
CONSTANT_Float, |
|
79 |
CONSTANT_Long, |
|
80 |
CONSTANT_Double, |
|
81 |
CONSTANT_String, |
|
82 |
CONSTANT_Class, |
|
83 |
CONSTANT_Signature, |
|
84 |
CONSTANT_NameandType, |
|
85 |
CONSTANT_Fieldref, |
|
86 |
CONSTANT_Methodref, |
|
12544 | 87 |
CONSTANT_InterfaceMethodref, |
88 |
// constants defined as of JDK 7 |
|
89 |
CONSTANT_MethodHandle, |
|
90 |
CONSTANT_MethodType, |
|
91 |
CONSTANT_BootstrapMethod, |
|
92 |
CONSTANT_InvokeDynamic |
|
2 | 93 |
}; |
94 |
#define N_TAGS_IN_ORDER (sizeof TAGS_IN_ORDER) |
|
95 |
||
96 |
#ifndef PRODUCT |
|
97 |
static const char* TAG_NAME[] = { |
|
98 |
"*None", |
|
99 |
"Utf8", |
|
100 |
"*Unicode", |
|
101 |
"Integer", |
|
102 |
"Float", |
|
103 |
"Long", |
|
104 |
"Double", |
|
105 |
"Class", |
|
106 |
"String", |
|
107 |
"Fieldref", |
|
108 |
"Methodref", |
|
109 |
"InterfaceMethodref", |
|
110 |
"NameandType", |
|
111 |
"*Signature", |
|
12544 | 112 |
"unused14", |
113 |
"MethodHandle", |
|
114 |
"MethodType", |
|
115 |
"*BootstrapMethod", |
|
116 |
"InvokeDynamic", |
|
2 | 117 |
0 |
118 |
}; |
|
119 |
||
120 |
static const char* ATTR_CONTEXT_NAME[] = { // match ATTR_CONTEXT_NAME, etc. |
|
121 |
"class", "field", "method", "code" |
|
122 |
}; |
|
123 |
||
124 |
#else |
|
125 |
||
126 |
#define ATTR_CONTEXT_NAME ((const char**)null) |
|
127 |
||
128 |
#endif |
|
129 |
||
12544 | 130 |
// Note that REQUESTED_LDC comes first, then the normal REQUESTED, |
131 |
// in the regular constant pool. |
|
132 |
enum { REQUESTED_NONE = -1, |
|
133 |
// The codes below REQUESTED_NONE are in constant pool output order, |
|
134 |
// for the sake of outputEntry_cmp: |
|
135 |
REQUESTED_LDC = -99, REQUESTED |
|
136 |
}; |
|
2 | 137 |
|
138 |
#define NO_INORD ((uint)-1) |
|
139 |
||
140 |
struct entry { |
|
141 |
byte tag; |
|
142 |
||
143 |
#if 0 |
|
144 |
byte bits; |
|
145 |
enum { |
|
146 |
//EB_EXTRA = 1, |
|
147 |
EB_SUPER = 2 |
|
148 |
}; |
|
149 |
#endif |
|
150 |
unsigned short nrefs; // pack w/ tag |
|
151 |
||
152 |
int outputIndex; |
|
153 |
uint inord; // &cp.entries[cp.tag_base[this->tag]+this->inord] == this |
|
154 |
||
155 |
entry* *refs; |
|
156 |
||
157 |
// put last to pack best |
|
158 |
union { |
|
159 |
bytes b; |
|
160 |
int i; |
|
161 |
jlong l; |
|
162 |
} value; |
|
163 |
||
164 |
void requestOutputIndex(cpool& cp, int req = REQUESTED); |
|
165 |
int getOutputIndex() { |
|
12544 | 166 |
assert(outputIndex > REQUESTED_NONE); |
2 | 167 |
return outputIndex; |
168 |
} |
|
169 |
||
170 |
entry* ref(int refnum) { |
|
171 |
assert((uint)refnum < nrefs); |
|
172 |
return refs[refnum]; |
|
173 |
} |
|
174 |
||
175 |
const char* utf8String() { |
|
176 |
assert(tagMatches(CONSTANT_Utf8)); |
|
177 |
assert(value.b.len == strlen((const char*)value.b.ptr)); |
|
178 |
return (const char*)value.b.ptr; |
|
179 |
} |
|
180 |
||
181 |
entry* className() { |
|
182 |
assert(tagMatches(CONSTANT_Class)); |
|
183 |
return ref(0); |
|
184 |
} |
|
185 |
||
186 |
entry* memberClass() { |
|
12544 | 187 |
assert(tagMatches(CONSTANT_AnyMember)); |
2 | 188 |
return ref(0); |
189 |
} |
|
190 |
||
191 |
entry* memberDescr() { |
|
12544 | 192 |
assert(tagMatches(CONSTANT_AnyMember)); |
2 | 193 |
return ref(1); |
194 |
} |
|
195 |
||
196 |
entry* descrName() { |
|
197 |
assert(tagMatches(CONSTANT_NameandType)); |
|
198 |
return ref(0); |
|
199 |
} |
|
200 |
||
201 |
entry* descrType() { |
|
202 |
assert(tagMatches(CONSTANT_NameandType)); |
|
203 |
return ref(1); |
|
204 |
} |
|
205 |
||
206 |
int typeSize(); |
|
207 |
||
208 |
bytes& asUtf8(); |
|
209 |
int asInteger() { assert(tag == CONSTANT_Integer); return value.i; } |
|
210 |
||
211 |
bool isUtf8(bytes& b) { return tagMatches(CONSTANT_Utf8) && value.b.equals(b); } |
|
212 |
||
213 |
bool isDoubleWord() { return tag == CONSTANT_Double || tag == CONSTANT_Long; } |
|
214 |
||
215 |
bool tagMatches(byte tag2) { |
|
216 |
return (tag2 == tag) |
|
217 |
|| (tag2 == CONSTANT_Utf8 && tag == CONSTANT_Signature) |
|
218 |
#ifndef PRODUCT |
|
12544 | 219 |
|| (tag2 == CONSTANT_FieldSpecific |
2 | 220 |
&& tag >= CONSTANT_Integer && tag <= CONSTANT_String && tag != CONSTANT_Class) |
12544 | 221 |
|| (tag2 == CONSTANT_AnyMember |
2 | 222 |
&& tag >= CONSTANT_Fieldref && tag <= CONSTANT_InterfaceMethodref) |
223 |
#endif |
|
224 |
; |
|
225 |
} |
|
226 |
||
227 |
#ifdef PRODUCT |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
228 |
const char* string() { return NULL; } |
2 | 229 |
#else |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
230 |
const char* string(); // see far below |
2 | 231 |
#endif |
232 |
}; |
|
233 |
||
234 |
entry* cpindex::get(uint i) { |
|
235 |
if (i >= len) |
|
236 |
return null; |
|
237 |
else if (base1 != null) |
|
238 |
// primary index |
|
239 |
return &base1[i]; |
|
240 |
else |
|
241 |
// secondary index |
|
242 |
return base2[i]; |
|
243 |
} |
|
244 |
||
245 |
inline bytes& entry::asUtf8() { |
|
246 |
assert(tagMatches(CONSTANT_Utf8)); |
|
247 |
return value.b; |
|
248 |
} |
|
249 |
||
250 |
int entry::typeSize() { |
|
251 |
assert(tagMatches(CONSTANT_Utf8)); |
|
252 |
const char* sigp = (char*) value.b.ptr; |
|
253 |
switch (*sigp) { |
|
254 |
case '(': sigp++; break; // skip opening '(' |
|
255 |
case 'D': |
|
256 |
case 'J': return 2; // double field |
|
257 |
default: return 1; // field |
|
258 |
} |
|
259 |
int siglen = 0; |
|
260 |
for (;;) { |
|
261 |
int ch = *sigp++; |
|
262 |
switch (ch) { |
|
263 |
case 'D': case 'J': |
|
264 |
siglen += 1; |
|
265 |
break; |
|
266 |
case '[': |
|
267 |
// Skip rest of array info. |
|
268 |
while (ch == '[') { ch = *sigp++; } |
|
269 |
if (ch != 'L') break; |
|
270 |
// else fall through |
|
271 |
case 'L': |
|
272 |
sigp = strchr(sigp, ';'); |
|
273 |
if (sigp == null) { |
|
274 |
unpack_abort("bad data"); |
|
275 |
return 0; |
|
276 |
} |
|
277 |
sigp += 1; |
|
278 |
break; |
|
279 |
case ')': // closing ')' |
|
280 |
return siglen; |
|
281 |
} |
|
282 |
siglen += 1; |
|
283 |
} |
|
284 |
} |
|
285 |
||
286 |
inline cpindex* cpool::getFieldIndex(entry* classRef) { |
|
16075 | 287 |
if (classRef == NULL) { abort("missing class reference"); return NULL; } |
2 | 288 |
assert(classRef->tagMatches(CONSTANT_Class)); |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
289 |
assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]); |
2 | 290 |
return &member_indexes[classRef->inord*2+0]; |
291 |
} |
|
292 |
inline cpindex* cpool::getMethodIndex(entry* classRef) { |
|
16075 | 293 |
if (classRef == NULL) { abort("missing class reference"); return NULL; } |
2 | 294 |
assert(classRef->tagMatches(CONSTANT_Class)); |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
295 |
assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]); |
2 | 296 |
return &member_indexes[classRef->inord*2+1]; |
297 |
} |
|
298 |
||
299 |
struct inner_class { |
|
300 |
entry* inner; |
|
301 |
entry* outer; |
|
302 |
entry* name; |
|
303 |
int flags; |
|
304 |
inner_class* next_sibling; |
|
305 |
bool requested; |
|
306 |
}; |
|
307 |
||
308 |
// Here is where everything gets deallocated: |
|
309 |
void unpacker::free() { |
|
310 |
int i; |
|
311 |
assert(jniobj == null); // caller resp. |
|
312 |
assert(infileptr == null); // caller resp. |
|
313 |
if (jarout != null) jarout->reset(); |
|
314 |
if (gzin != null) { gzin->free(); gzin = null; } |
|
315 |
if (free_input) input.free(); |
|
316 |
// free everybody ever allocated with U_NEW or (recently) with T_NEW |
|
317 |
assert(smallbuf.base() == null || mallocs.contains(smallbuf.base())); |
|
318 |
assert(tsmallbuf.base() == null || tmallocs.contains(tsmallbuf.base())); |
|
319 |
mallocs.freeAll(); |
|
320 |
tmallocs.freeAll(); |
|
321 |
smallbuf.init(); |
|
322 |
tsmallbuf.init(); |
|
323 |
bcimap.free(); |
|
324 |
class_fixup_type.free(); |
|
325 |
class_fixup_offset.free(); |
|
326 |
class_fixup_ref.free(); |
|
327 |
code_fixup_type.free(); |
|
328 |
code_fixup_offset.free(); |
|
329 |
code_fixup_source.free(); |
|
330 |
requested_ics.free(); |
|
12544 | 331 |
cp.requested_bsms.free(); |
2 | 332 |
cur_classfile_head.free(); |
333 |
cur_classfile_tail.free(); |
|
334 |
for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) |
|
335 |
attr_defs[i].free(); |
|
336 |
||
337 |
// free CP state |
|
338 |
cp.outputEntries.free(); |
|
339 |
for (i = 0; i < CONSTANT_Limit; i++) |
|
340 |
cp.tag_extras[i].free(); |
|
341 |
} |
|
342 |
||
343 |
// input handling |
|
344 |
// Attempts to advance rplimit so that (rplimit-rp) is at least 'more'. |
|
345 |
// Will eagerly read ahead by larger chunks, if possible. |
|
346 |
// Returns false if (rplimit-rp) is not at least 'more', |
|
347 |
// unless rplimit hits input.limit(). |
|
348 |
bool unpacker::ensure_input(jlong more) { |
|
349 |
julong want = more - input_remaining(); |
|
350 |
if ((jlong)want <= 0) return true; // it's already in the buffer |
|
351 |
if (rplimit == input.limit()) return true; // not expecting any more |
|
352 |
||
353 |
if (read_input_fn == null) { |
|
354 |
// assume it is already all there |
|
355 |
bytes_read += input.limit() - rplimit; |
|
356 |
rplimit = input.limit(); |
|
357 |
return true; |
|
358 |
} |
|
359 |
CHECK_0; |
|
360 |
||
361 |
julong remaining = (input.limit() - rplimit); // how much left to read? |
|
362 |
byte* rpgoal = (want >= remaining)? input.limit(): rplimit + (size_t)want; |
|
363 |
enum { CHUNK_SIZE = (1<<14) }; |
|
364 |
julong fetch = want; |
|
365 |
if (fetch < CHUNK_SIZE) |
|
366 |
fetch = CHUNK_SIZE; |
|
367 |
if (fetch > remaining*3/4) |
|
368 |
fetch = remaining; |
|
369 |
// Try to fetch at least "more" bytes. |
|
370 |
while ((jlong)fetch > 0) { |
|
371 |
jlong nr = (*read_input_fn)(this, rplimit, fetch, remaining); |
|
372 |
if (nr <= 0) { |
|
373 |
return (rplimit >= rpgoal); |
|
374 |
} |
|
375 |
remaining -= nr; |
|
376 |
rplimit += nr; |
|
377 |
fetch -= nr; |
|
378 |
bytes_read += nr; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
379 |
assert(remaining == (julong)(input.limit() - rplimit)); |
2 | 380 |
} |
381 |
return true; |
|
382 |
} |
|
383 |
||
384 |
// output handling |
|
385 |
||
386 |
fillbytes* unpacker::close_output(fillbytes* which) { |
|
387 |
assert(wp != null); |
|
388 |
if (which == null) { |
|
389 |
if (wpbase == cur_classfile_head.base()) { |
|
390 |
which = &cur_classfile_head; |
|
391 |
} else { |
|
392 |
which = &cur_classfile_tail; |
|
393 |
} |
|
394 |
} |
|
395 |
assert(wpbase == which->base()); |
|
396 |
assert(wplimit == which->end()); |
|
397 |
which->setLimit(wp); |
|
398 |
wp = null; |
|
399 |
wplimit = null; |
|
400 |
//wpbase = null; |
|
401 |
return which; |
|
402 |
} |
|
403 |
||
404 |
//maybe_inline |
|
405 |
void unpacker::ensure_put_space(size_t size) { |
|
406 |
if (wp + size <= wplimit) return; |
|
407 |
// Determine which segment needs expanding. |
|
408 |
fillbytes* which = close_output(); |
|
409 |
byte* wp0 = which->grow(size); |
|
410 |
wpbase = which->base(); |
|
411 |
wplimit = which->end(); |
|
412 |
wp = wp0; |
|
413 |
} |
|
414 |
||
415 |
maybe_inline |
|
416 |
byte* unpacker::put_space(size_t size) { |
|
417 |
byte* wp0 = wp; |
|
418 |
byte* wp1 = wp0 + size; |
|
419 |
if (wp1 > wplimit) { |
|
420 |
ensure_put_space(size); |
|
421 |
wp0 = wp; |
|
422 |
wp1 = wp0 + size; |
|
423 |
} |
|
424 |
wp = wp1; |
|
425 |
return wp0; |
|
426 |
} |
|
427 |
||
428 |
maybe_inline |
|
429 |
void unpacker::putu2_at(byte* wp, int n) { |
|
430 |
if (n != (unsigned short)n) { |
|
431 |
unpack_abort(ERROR_OVERFLOW); |
|
432 |
return; |
|
433 |
} |
|
434 |
wp[0] = (n) >> 8; |
|
435 |
wp[1] = (n) >> 0; |
|
436 |
} |
|
437 |
||
438 |
maybe_inline |
|
439 |
void unpacker::putu4_at(byte* wp, int n) { |
|
440 |
wp[0] = (n) >> 24; |
|
441 |
wp[1] = (n) >> 16; |
|
442 |
wp[2] = (n) >> 8; |
|
443 |
wp[3] = (n) >> 0; |
|
444 |
} |
|
445 |
||
446 |
maybe_inline |
|
447 |
void unpacker::putu8_at(byte* wp, jlong n) { |
|
448 |
putu4_at(wp+0, (int)((julong)n >> 32)); |
|
449 |
putu4_at(wp+4, (int)((julong)n >> 0)); |
|
450 |
} |
|
451 |
||
452 |
maybe_inline |
|
453 |
void unpacker::putu2(int n) { |
|
454 |
putu2_at(put_space(2), n); |
|
455 |
} |
|
456 |
||
457 |
maybe_inline |
|
458 |
void unpacker::putu4(int n) { |
|
459 |
putu4_at(put_space(4), n); |
|
460 |
} |
|
461 |
||
462 |
maybe_inline |
|
463 |
void unpacker::putu8(jlong n) { |
|
464 |
putu8_at(put_space(8), n); |
|
465 |
} |
|
466 |
||
467 |
maybe_inline |
|
468 |
int unpacker::putref_index(entry* e, int size) { |
|
469 |
if (e == null) |
|
470 |
return 0; |
|
12544 | 471 |
else if (e->outputIndex > REQUESTED_NONE) |
2 | 472 |
return e->outputIndex; |
473 |
else if (e->tag == CONSTANT_Signature) |
|
474 |
return putref_index(e->ref(0), size); |
|
475 |
else { |
|
12544 | 476 |
e->requestOutputIndex(cp, (size == 1 ? REQUESTED_LDC : REQUESTED)); |
2 | 477 |
// Later on we'll fix the bits. |
478 |
class_fixup_type.addByte(size); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
479 |
class_fixup_offset.add((int)wpoffset()); |
2 | 480 |
class_fixup_ref.add(e); |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
481 |
#ifdef PRODUCT |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
482 |
return 0; |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
483 |
#else |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
484 |
return 0x20+size; // 0x22 is easy to eyeball |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
485 |
#endif |
2 | 486 |
} |
487 |
} |
|
488 |
||
489 |
maybe_inline |
|
490 |
void unpacker::putref(entry* e) { |
|
491 |
int oidx = putref_index(e, 2); |
|
492 |
putu2_at(put_space(2), oidx); |
|
493 |
} |
|
494 |
||
495 |
maybe_inline |
|
496 |
void unpacker::putu1ref(entry* e) { |
|
497 |
int oidx = putref_index(e, 1); |
|
498 |
putu1_at(put_space(1), oidx); |
|
499 |
} |
|
500 |
||
501 |
||
502 |
static int total_cp_size[] = {0, 0}; |
|
503 |
static int largest_cp_ref[] = {0, 0}; |
|
504 |
static int hash_probes[] = {0, 0}; |
|
505 |
||
506 |
// Allocation of small and large blocks. |
|
507 |
||
508 |
enum { CHUNK = (1 << 14), SMALL = (1 << 9) }; |
|
509 |
||
510 |
// Call malloc. Try to combine small blocks and free much later. |
|
511 |
void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) { |
|
512 |
if (!smallOK || size > SMALL) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
513 |
void* res = must_malloc((int)size); |
2 | 514 |
(temp ? &tmallocs : &mallocs)->add(res); |
515 |
return res; |
|
516 |
} |
|
517 |
fillbytes& xsmallbuf = *(temp ? &tsmallbuf : &smallbuf); |
|
518 |
if (!xsmallbuf.canAppend(size+1)) { |
|
519 |
xsmallbuf.init(CHUNK); |
|
520 |
(temp ? &tmallocs : &mallocs)->add(xsmallbuf.base()); |
|
521 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
522 |
int growBy = (int)size; |
2 | 523 |
growBy += -growBy & 7; // round up mod 8 |
524 |
return xsmallbuf.grow(growBy); |
|
525 |
} |
|
526 |
||
527 |
maybe_inline |
|
528 |
void unpacker::saveTo(bytes& b, byte* ptr, size_t len) { |
|
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
529 |
b.ptr = U_NEW(byte, add_size(len,1)); |
2 | 530 |
if (aborting()) { |
531 |
b.len = 0; |
|
532 |
return; |
|
533 |
} |
|
534 |
b.len = len; |
|
535 |
b.copyFrom(ptr, len); |
|
536 |
} |
|
537 |
||
12544 | 538 |
bool testBit(int archive_options, int bitMask) { |
539 |
return (archive_options & bitMask) != 0; |
|
540 |
} |
|
541 |
||
2 | 542 |
// Read up through band_headers. |
543 |
// Do the archive_size dance to set the size of the input mega-buffer. |
|
544 |
void unpacker::read_file_header() { |
|
545 |
// Read file header to determine file type and total size. |
|
546 |
enum { |
|
547 |
MAGIC_BYTES = 4, |
|
12544 | 548 |
AH_LENGTH_0 = 3, // archive_header_0 = {minver, majver, options} |
549 |
AH_LENGTH_MIN = 15, // observed in spec {header_0[3], cp_counts[8], class_counts[4]} |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
550 |
AH_LENGTH_0_MAX = AH_LENGTH_0 + 1, // options might have 2 bytes |
12544 | 551 |
AH_LENGTH = 30, //maximum archive header length (w/ all fields) |
2 | 552 |
// Length contributions from optional header fields: |
12544 | 553 |
AH_LENGTH_S = 2, // archive_header_S = optional {size_hi, size_lo} |
554 |
AH_ARCHIVE_SIZE_HI = 0, // offset in archive_header_S |
|
555 |
AH_ARCHIVE_SIZE_LO = 1, // offset in archive_header_S |
|
556 |
AH_FILE_HEADER_LEN = 5, // file_counts = {{size_hi, size_lo), next, modtile, files} |
|
557 |
AH_SPECIAL_FORMAT_LEN = 2, // special_count = {layouts, band_headers} |
|
558 |
AH_CP_NUMBER_LEN = 4, // cp_number_counts = {int, float, long, double} |
|
559 |
AH_CP_EXTRA_LEN = 4, // cp_attr_counts = {MH, MT, InDy, BSM} |
|
560 |
ARCHIVE_SIZE_MIN = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S, |
|
2 | 561 |
FIRST_READ = MAGIC_BYTES + AH_LENGTH_MIN |
562 |
}; |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
563 |
|
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
564 |
assert(AH_LENGTH_MIN == 15); // # of UNSIGNED5 fields required after archive_magic |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
565 |
// An absolute minimum null archive is magic[4], {minver,majver,options}[3], |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
566 |
// archive_size[0], cp_counts[8], class_counts[4], for a total of 19 bytes. |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
567 |
// (Note that archive_size is optional; it may be 0..10 bytes in length.) |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
568 |
// The first read must capture everything up through the options field. |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
569 |
// This happens to work even if {minver,majver,options} is a pathological |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
570 |
// 15 bytes long. Legal pack files limit those three fields to 1+1+2 bytes. |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
571 |
assert(FIRST_READ >= MAGIC_BYTES + AH_LENGTH_0 * B_MAX); |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
572 |
|
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
573 |
// Up through archive_size, the largest possible archive header is |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
574 |
// magic[4], {minver,majver,options}[4], archive_size[10]. |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
575 |
// (Note only the low 12 bits of options are allowed to be non-zero.) |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
576 |
// In order to parse archive_size, we need at least this many bytes |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
577 |
// in the first read. Of course, if archive_size_hi is more than |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
578 |
// a byte, we probably will fail to allocate the buffer, since it |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
579 |
// will be many gigabytes long. This is a practical, not an |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
580 |
// architectural limit to Pack200 archive sizes. |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
581 |
assert(FIRST_READ >= MAGIC_BYTES + AH_LENGTH_0_MAX + 2*B_MAX); |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
582 |
|
2 | 583 |
bool foreign_buf = (read_input_fn == null); |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
584 |
byte initbuf[(int)FIRST_READ + (int)C_SLOP + 200]; // 200 is for JAR I/O |
2 | 585 |
if (foreign_buf) { |
586 |
// inbytes is all there is |
|
587 |
input.set(inbytes); |
|
588 |
rp = input.base(); |
|
589 |
rplimit = input.limit(); |
|
590 |
} else { |
|
591 |
// inbytes, if not empty, contains some read-ahead we must use first |
|
592 |
// ensure_input will take care of copying it into initbuf, |
|
593 |
// then querying read_input_fn for any additional data needed. |
|
594 |
// However, the caller must assume that we use up all of inbytes. |
|
595 |
// There is no way to tell the caller that we used only part of them. |
|
596 |
// Therefore, the caller must use only a bare minimum of read-ahead. |
|
597 |
if (inbytes.len > FIRST_READ) { |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
598 |
abort("too much read-ahead"); |
2 | 599 |
return; |
600 |
} |
|
601 |
input.set(initbuf, sizeof(initbuf)); |
|
602 |
input.b.clear(); |
|
603 |
input.b.copyFrom(inbytes); |
|
604 |
rplimit = rp = input.base(); |
|
605 |
rplimit += inbytes.len; |
|
606 |
bytes_read += inbytes.len; |
|
607 |
} |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
608 |
// Read only 19 bytes, which is certain to contain #archive_options fields, |
2 | 609 |
// but is certain not to overflow past the archive_header. |
610 |
input.b.len = FIRST_READ; |
|
611 |
if (!ensure_input(FIRST_READ)) |
|
612 |
abort("EOF reading archive magic number"); |
|
613 |
||
614 |
if (rp[0] == 'P' && rp[1] == 'K') { |
|
615 |
#ifdef UNPACK_JNI |
|
616 |
// Java driver must handle this case before we get this far. |
|
617 |
abort("encountered a JAR header in unpacker"); |
|
618 |
#else |
|
619 |
// In the Unix-style program, we simply simulate a copy command. |
|
620 |
// Copy until EOF; assume the JAR file is the last segment. |
|
621 |
fprintf(errstrm, "Copy-mode.\n"); |
|
622 |
for (;;) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
623 |
jarout->write_data(rp, (int)input_remaining()); |
2 | 624 |
if (foreign_buf) |
625 |
break; // one-time use of a passed in buffer |
|
626 |
if (input.size() < CHUNK) { |
|
627 |
// Get some breathing room. |
|
628 |
input.set(U_NEW(byte, (size_t) CHUNK + C_SLOP), (size_t) CHUNK); |
|
629 |
CHECK; |
|
630 |
} |
|
631 |
rp = rplimit = input.base(); |
|
632 |
if (!ensure_input(1)) |
|
633 |
break; |
|
634 |
} |
|
635 |
jarout->closeJarFile(false); |
|
636 |
#endif |
|
637 |
return; |
|
638 |
} |
|
639 |
||
640 |
// Read the magic number. |
|
641 |
magic = 0; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
642 |
for (int i1 = 0; i1 < (int)sizeof(magic); i1++) { |
2 | 643 |
magic <<= 8; |
644 |
magic += (*rp++ & 0xFF); |
|
645 |
} |
|
646 |
||
647 |
// Read the first 3 values from the header. |
|
648 |
value_stream hdr; |
|
649 |
int hdrVals = 0; |
|
12544 | 650 |
int hdrValsSkipped = 0; // for assert |
2 | 651 |
hdr.init(rp, rplimit, UNSIGNED5_spec); |
652 |
minver = hdr.getInt(); |
|
653 |
majver = hdr.getInt(); |
|
654 |
hdrVals += 2; |
|
655 |
||
15261 | 656 |
int majmin[4][2] = { |
12544 | 657 |
{JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION}, |
658 |
{JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION}, |
|
15261 | 659 |
{JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION}, |
660 |
{JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION} |
|
12544 | 661 |
}; |
662 |
int majminfound = false; |
|
15261 | 663 |
for (int i = 0 ; i < 4 ; i++) { |
12544 | 664 |
if (majver == majmin[i][0] && minver == majmin[i][1]) { |
665 |
majminfound = true; |
|
666 |
break; |
|
667 |
} |
|
668 |
} |
|
669 |
if (majminfound == null) { |
|
2 | 670 |
char message[200]; |
671 |
sprintf(message, "@" ERROR_FORMAT ": magic/ver = " |
|
15261 | 672 |
"%08X/%d.%d should be %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d OR %08X/%d.%d\n", |
2 | 673 |
magic, majver, minver, |
674 |
JAVA_PACKAGE_MAGIC, JAVA5_PACKAGE_MAJOR_VERSION, JAVA5_PACKAGE_MINOR_VERSION, |
|
12544 | 675 |
JAVA_PACKAGE_MAGIC, JAVA6_PACKAGE_MAJOR_VERSION, JAVA6_PACKAGE_MINOR_VERSION, |
15261 | 676 |
JAVA_PACKAGE_MAGIC, JAVA7_PACKAGE_MAJOR_VERSION, JAVA7_PACKAGE_MINOR_VERSION, |
677 |
JAVA_PACKAGE_MAGIC, JAVA8_PACKAGE_MAJOR_VERSION, JAVA8_PACKAGE_MINOR_VERSION); |
|
2 | 678 |
abort(message); |
679 |
} |
|
680 |
CHECK; |
|
681 |
||
682 |
archive_options = hdr.getInt(); |
|
683 |
hdrVals += 1; |
|
684 |
assert(hdrVals == AH_LENGTH_0); // first three fields only |
|
12544 | 685 |
bool haveSizeHi = testBit(archive_options, AO_HAVE_FILE_SIZE_HI); |
686 |
bool haveModTime = testBit(archive_options, AO_HAVE_FILE_MODTIME); |
|
687 |
bool haveFileOpt = testBit(archive_options, AO_HAVE_FILE_OPTIONS); |
|
688 |
||
689 |
bool haveSpecial = testBit(archive_options, AO_HAVE_SPECIAL_FORMATS); |
|
690 |
bool haveFiles = testBit(archive_options, AO_HAVE_FILE_HEADERS); |
|
691 |
bool haveNumbers = testBit(archive_options, AO_HAVE_CP_NUMBERS); |
|
692 |
bool haveCPExtra = testBit(archive_options, AO_HAVE_CP_EXTRAS); |
|
693 |
||
694 |
if (majver < JAVA7_PACKAGE_MAJOR_VERSION) { |
|
695 |
if (haveCPExtra) { |
|
696 |
abort("Format bits for Java 7 must be zero in previous releases"); |
|
697 |
return; |
|
698 |
} |
|
699 |
} |
|
700 |
if (testBit(archive_options, AO_UNUSED_MBZ)) { |
|
701 |
abort("High archive option bits are reserved and must be zero"); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
702 |
return; |
2 | 703 |
} |
12544 | 704 |
if (haveFiles) { |
2 | 705 |
uint hi = hdr.getInt(); |
706 |
uint lo = hdr.getInt(); |
|
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
707 |
julong x = band::makeLong(hi, lo); |
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
708 |
archive_size = (size_t) x; |
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
709 |
if (archive_size != x) { |
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
710 |
// Silly size specified; force overflow. |
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
711 |
archive_size = PSIZE_MAX+1; |
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
712 |
} |
2 | 713 |
hdrVals += 2; |
714 |
} else { |
|
715 |
hdrValsSkipped += 2; |
|
716 |
} |
|
717 |
||
718 |
// Now we can size the whole archive. |
|
719 |
// Read everything else into a mega-buffer. |
|
720 |
rp = hdr.rp; |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
721 |
size_t header_size_0 = (rp - input.base()); // used-up header (4byte + 3int) |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
722 |
size_t header_size_1 = (rplimit - rp); // buffered unused initial fragment |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
723 |
size_t header_size = header_size_0 + header_size_1; |
2 | 724 |
unsized_bytes_read = header_size_0; |
725 |
CHECK; |
|
726 |
if (foreign_buf) { |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
727 |
if (archive_size > header_size_1) { |
2 | 728 |
abort("EOF reading fixed input buffer"); |
729 |
return; |
|
730 |
} |
|
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
731 |
} else if (archive_size != 0) { |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
732 |
if (archive_size < ARCHIVE_SIZE_MIN) { |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
733 |
abort("impossible archive size"); // bad input data |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
734 |
return; |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
735 |
} |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
736 |
if (archive_size < header_size_1) { |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
737 |
abort("too much read-ahead"); // somehow we pre-fetched too much? |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
738 |
return; |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
739 |
} |
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
740 |
input.set(U_NEW(byte, add_size(header_size_0, archive_size, C_SLOP)), |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
741 |
header_size_0 + archive_size); |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
742 |
CHECK; |
2 | 743 |
assert(input.limit()[0] == 0); |
744 |
// Move all the bytes we read initially into the real buffer. |
|
745 |
input.b.copyFrom(initbuf, header_size); |
|
746 |
rp = input.b.ptr + header_size_0; |
|
747 |
rplimit = input.b.ptr + header_size; |
|
748 |
} else { |
|
749 |
// It's more complicated and painful. |
|
750 |
// A zero archive_size means that we must read until EOF. |
|
751 |
input.init(CHUNK*2); |
|
752 |
CHECK; |
|
753 |
input.b.len = input.allocated; |
|
754 |
rp = rplimit = input.base(); |
|
755 |
// Set up input buffer as if we already read the header: |
|
756 |
input.b.copyFrom(initbuf, header_size); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
757 |
CHECK; |
2 | 758 |
rplimit += header_size; |
759 |
while (ensure_input(input.limit() - rp)) { |
|
760 |
size_t dataSoFar = input_remaining(); |
|
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
761 |
size_t nextSize = add_size(dataSoFar, CHUNK); |
2 | 762 |
input.ensureSize(nextSize); |
763 |
CHECK; |
|
764 |
input.b.len = input.allocated; |
|
765 |
rp = rplimit = input.base(); |
|
766 |
rplimit += dataSoFar; |
|
767 |
} |
|
768 |
size_t dataSize = (rplimit - input.base()); |
|
769 |
input.b.len = dataSize; |
|
770 |
input.grow(C_SLOP); |
|
771 |
CHECK; |
|
772 |
free_input = true; // free it later |
|
773 |
input.b.len = dataSize; |
|
774 |
assert(input.limit()[0] == 0); |
|
775 |
rp = rplimit = input.base(); |
|
776 |
rplimit += dataSize; |
|
777 |
rp += header_size_0; // already scanned these bytes... |
|
778 |
} |
|
779 |
live_input = true; // mark as "do not reuse" |
|
780 |
if (aborting()) { |
|
781 |
abort("cannot allocate large input buffer for package file"); |
|
782 |
return; |
|
783 |
} |
|
784 |
||
12544 | 785 |
// read the rest of the header fields int assertSkipped = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S; |
786 |
int remainingHeaders = AH_LENGTH_MIN - AH_LENGTH_0 - AH_LENGTH_S; |
|
787 |
if (haveSpecial) |
|
788 |
remainingHeaders += AH_SPECIAL_FORMAT_LEN; |
|
789 |
if (haveFiles) |
|
790 |
remainingHeaders += AH_FILE_HEADER_LEN; |
|
791 |
if (haveNumbers) |
|
792 |
remainingHeaders += AH_CP_NUMBER_LEN; |
|
793 |
if (haveCPExtra) |
|
794 |
remainingHeaders += AH_CP_EXTRA_LEN; |
|
795 |
||
796 |
ensure_input(remainingHeaders * B_MAX); |
|
2 | 797 |
CHECK; |
798 |
hdr.rp = rp; |
|
799 |
hdr.rplimit = rplimit; |
|
800 |
||
12544 | 801 |
if (haveFiles) { |
2 | 802 |
archive_next_count = hdr.getInt(); |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
803 |
CHECK_COUNT(archive_next_count); |
2 | 804 |
archive_modtime = hdr.getInt(); |
805 |
file_count = hdr.getInt(); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
806 |
CHECK_COUNT(file_count); |
2 | 807 |
hdrVals += 3; |
808 |
} else { |
|
809 |
hdrValsSkipped += 3; |
|
810 |
} |
|
811 |
||
12544 | 812 |
if (haveSpecial) { |
2 | 813 |
band_headers_size = hdr.getInt(); |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
814 |
CHECK_COUNT(band_headers_size); |
2 | 815 |
attr_definition_count = hdr.getInt(); |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
816 |
CHECK_COUNT(attr_definition_count); |
2 | 817 |
hdrVals += 2; |
818 |
} else { |
|
819 |
hdrValsSkipped += 2; |
|
820 |
} |
|
821 |
||
822 |
int cp_counts[N_TAGS_IN_ORDER]; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
823 |
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { |
12544 | 824 |
if (!haveNumbers) { |
2 | 825 |
switch (TAGS_IN_ORDER[k]) { |
826 |
case CONSTANT_Integer: |
|
827 |
case CONSTANT_Float: |
|
828 |
case CONSTANT_Long: |
|
829 |
case CONSTANT_Double: |
|
830 |
cp_counts[k] = 0; |
|
831 |
hdrValsSkipped += 1; |
|
832 |
continue; |
|
833 |
} |
|
834 |
} |
|
12544 | 835 |
if (!haveCPExtra) { |
836 |
switch(TAGS_IN_ORDER[k]) { |
|
837 |
case CONSTANT_MethodHandle: |
|
838 |
case CONSTANT_MethodType: |
|
839 |
case CONSTANT_InvokeDynamic: |
|
840 |
case CONSTANT_BootstrapMethod: |
|
841 |
cp_counts[k] = 0; |
|
842 |
hdrValsSkipped += 1; |
|
843 |
continue; |
|
844 |
} |
|
845 |
} |
|
2 | 846 |
cp_counts[k] = hdr.getInt(); |
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
847 |
CHECK_COUNT(cp_counts[k]); |
2 | 848 |
hdrVals += 1; |
849 |
} |
|
850 |
||
851 |
ic_count = hdr.getInt(); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
852 |
CHECK_COUNT(ic_count); |
2 | 853 |
default_class_minver = hdr.getInt(); |
854 |
default_class_majver = hdr.getInt(); |
|
855 |
class_count = hdr.getInt(); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
856 |
CHECK_COUNT(class_count); |
2 | 857 |
hdrVals += 4; |
858 |
||
12544 | 859 |
// done with archive_header, time to reconcile to ensure |
860 |
// we have read everything correctly |
|
2 | 861 |
hdrVals += hdrValsSkipped; |
862 |
assert(hdrVals == AH_LENGTH); |
|
863 |
rp = hdr.rp; |
|
864 |
if (rp > rplimit) |
|
865 |
abort("EOF reading archive header"); |
|
866 |
||
867 |
// Now size the CP. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
868 |
#ifndef PRODUCT |
12544 | 869 |
// bool x = (N_TAGS_IN_ORDER == CONSTANT_Limit); |
870 |
// assert(x); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
871 |
#endif //PRODUCT |
2 | 872 |
cp.init(this, cp_counts); |
873 |
CHECK; |
|
874 |
||
875 |
default_file_modtime = archive_modtime; |
|
12544 | 876 |
if (default_file_modtime == 0 && haveModTime) |
2 | 877 |
default_file_modtime = DEFAULT_ARCHIVE_MODTIME; // taken from driver |
12544 | 878 |
if (testBit(archive_options, AO_DEFLATE_HINT)) |
2 | 879 |
default_file_options |= FO_DEFLATE_HINT; |
880 |
||
881 |
// meta-bytes, if any, immediately follow archive header |
|
882 |
//band_headers.readData(band_headers_size); |
|
883 |
ensure_input(band_headers_size); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
884 |
if (input_remaining() < (size_t)band_headers_size) { |
2 | 885 |
abort("EOF reading band headers"); |
886 |
return; |
|
887 |
} |
|
888 |
bytes band_headers; |
|
889 |
// The "1+" allows an initial byte to be pushed on the front. |
|
890 |
band_headers.set(1+U_NEW(byte, 1+band_headers_size+C_SLOP), |
|
891 |
band_headers_size); |
|
892 |
CHECK; |
|
893 |
// Start scanning band headers here: |
|
894 |
band_headers.copyFrom(rp, band_headers.len); |
|
895 |
rp += band_headers.len; |
|
896 |
assert(rp <= rplimit); |
|
897 |
meta_rp = band_headers.ptr; |
|
898 |
// Put evil meta-codes at the end of the band headers, |
|
899 |
// so we are sure to throw an error if we run off the end. |
|
900 |
bytes::of(band_headers.limit(), C_SLOP).clear(_meta_error); |
|
901 |
} |
|
902 |
||
903 |
void unpacker::finish() { |
|
904 |
if (verbose >= 1) { |
|
905 |
fprintf(errstrm, |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
906 |
"A total of " |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
907 |
LONG_LONG_FORMAT " bytes were read in %d segment(s).\n", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
908 |
(bytes_read_before_reset+bytes_read), |
2 | 909 |
segments_read_before_reset+1); |
910 |
fprintf(errstrm, |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
911 |
"A total of " |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
912 |
LONG_LONG_FORMAT " file content bytes were written.\n", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
913 |
(bytes_written_before_reset+bytes_written)); |
2 | 914 |
fprintf(errstrm, |
915 |
"A total of %d files (of which %d are classes) were written to output.\n", |
|
916 |
files_written_before_reset+files_written, |
|
917 |
classes_written_before_reset+classes_written); |
|
918 |
} |
|
919 |
if (jarout != null) |
|
920 |
jarout->closeJarFile(true); |
|
921 |
if (errstrm != null) { |
|
922 |
if (errstrm == stdout || errstrm == stderr) { |
|
923 |
fflush(errstrm); |
|
924 |
} else { |
|
925 |
fclose(errstrm); |
|
926 |
} |
|
927 |
errstrm = null; |
|
928 |
errstrm_name = null; |
|
929 |
} |
|
930 |
} |
|
931 |
||
932 |
||
933 |
// Cf. PackageReader.readConstantPoolCounts |
|
12544 | 934 |
void cpool::init(unpacker* u_, int counts[CONSTANT_Limit]) { |
2 | 935 |
this->u = u_; |
936 |
||
937 |
// Fill-pointer for CP. |
|
938 |
int next_entry = 0; |
|
939 |
||
940 |
// Size the constant pool: |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
941 |
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { |
2 | 942 |
byte tag = TAGS_IN_ORDER[k]; |
943 |
int len = counts[k]; |
|
944 |
tag_count[tag] = len; |
|
945 |
tag_base[tag] = next_entry; |
|
946 |
next_entry += len; |
|
947 |
// Detect and defend against constant pool size overflow. |
|
948 |
// (Pack200 forbids the sum of CP counts to exceed 2^29-1.) |
|
949 |
enum { |
|
950 |
CP_SIZE_LIMIT = (1<<29), |
|
951 |
IMPLICIT_ENTRY_COUNT = 1 // empty Utf8 string |
|
952 |
}; |
|
953 |
if (len >= (1<<29) || len < 0 |
|
954 |
|| next_entry >= CP_SIZE_LIMIT+IMPLICIT_ENTRY_COUNT) { |
|
955 |
abort("archive too large: constant pool limit exceeded"); |
|
956 |
return; |
|
957 |
} |
|
958 |
} |
|
959 |
||
960 |
// Close off the end of the CP: |
|
961 |
nentries = next_entry; |
|
962 |
||
963 |
// place a limit on future CP growth: |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
964 |
size_t generous = 0; |
3463
054c9c1f9fd9
6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents:
2624
diff
changeset
|
965 |
generous = add_size(generous, u->ic_count); // implicit name |
054c9c1f9fd9
6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents:
2624
diff
changeset
|
966 |
generous = add_size(generous, u->ic_count); // outer |
054c9c1f9fd9
6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents:
2624
diff
changeset
|
967 |
generous = add_size(generous, u->ic_count); // outer.utf8 |
054c9c1f9fd9
6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents:
2624
diff
changeset
|
968 |
generous = add_size(generous, 40); // WKUs, misc |
054c9c1f9fd9
6830335: Java JAR Pack200 Decompression Integer Overflow Vulnerability
ksrini
parents:
2624
diff
changeset
|
969 |
generous = add_size(generous, u->class_count); // implicit SourceFile strings |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
970 |
maxentries = (uint)add_size(nentries, generous); |
2 | 971 |
|
972 |
// Note that this CP does not include "empty" entries |
|
973 |
// for longs and doubles. Those are introduced when |
|
974 |
// the entries are renumbered for classfile output. |
|
975 |
||
976 |
entries = U_NEW(entry, maxentries); |
|
977 |
CHECK; |
|
978 |
||
979 |
first_extra_entry = &entries[nentries]; |
|
980 |
||
981 |
// Initialize the standard indexes. |
|
982 |
for (int tag = 0; tag < CONSTANT_Limit; tag++) { |
|
983 |
entry* cpMap = &entries[tag_base[tag]]; |
|
984 |
tag_index[tag].init(tag_count[tag], cpMap, tag); |
|
985 |
} |
|
986 |
||
12544 | 987 |
// Initialize *all* our entries once |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
988 |
for (uint i = 0 ; i < maxentries ; i++) { |
12544 | 989 |
entries[i].outputIndex = REQUESTED_NONE; |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
990 |
} |
12544 | 991 |
|
992 |
initGroupIndexes(); |
|
2 | 993 |
// Initialize hashTab to a generous power-of-two size. |
994 |
uint pow2 = 1; |
|
995 |
uint target = maxentries + maxentries/2; // 60% full |
|
996 |
while (pow2 < target) pow2 <<= 1; |
|
997 |
hashTab = U_NEW(entry*, hashTabLength = pow2); |
|
998 |
} |
|
999 |
||
1000 |
static byte* store_Utf8_char(byte* cp, unsigned short ch) { |
|
1001 |
if (ch >= 0x001 && ch <= 0x007F) { |
|
1002 |
*cp++ = (byte) ch; |
|
1003 |
} else if (ch <= 0x07FF) { |
|
1004 |
*cp++ = (byte) (0xC0 | ((ch >> 6) & 0x1F)); |
|
1005 |
*cp++ = (byte) (0x80 | ((ch >> 0) & 0x3F)); |
|
1006 |
} else { |
|
1007 |
*cp++ = (byte) (0xE0 | ((ch >> 12) & 0x0F)); |
|
1008 |
*cp++ = (byte) (0x80 | ((ch >> 6) & 0x3F)); |
|
1009 |
*cp++ = (byte) (0x80 | ((ch >> 0) & 0x3F)); |
|
1010 |
} |
|
1011 |
return cp; |
|
1012 |
} |
|
1013 |
||
1014 |
static byte* skip_Utf8_chars(byte* cp, int len) { |
|
1015 |
for (;; cp++) { |
|
1016 |
int ch = *cp & 0xFF; |
|
1017 |
if ((ch & 0xC0) != 0x80) { |
|
1018 |
if (len-- == 0) |
|
1019 |
return cp; |
|
1020 |
if (ch < 0x80 && len == 0) |
|
1021 |
return cp+1; |
|
1022 |
} |
|
1023 |
} |
|
1024 |
} |
|
1025 |
||
1026 |
static int compare_Utf8_chars(bytes& b1, bytes& b2) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1027 |
int l1 = (int)b1.len; |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1028 |
int l2 = (int)b2.len; |
2 | 1029 |
int l0 = (l1 < l2) ? l1 : l2; |
1030 |
byte* p1 = b1.ptr; |
|
1031 |
byte* p2 = b2.ptr; |
|
1032 |
int c0 = 0; |
|
1033 |
for (int i = 0; i < l0; i++) { |
|
1034 |
int c1 = p1[i] & 0xFF; |
|
1035 |
int c2 = p2[i] & 0xFF; |
|
1036 |
if (c1 != c2) { |
|
1037 |
// Before returning the obvious answer, |
|
1038 |
// check to see if c1 or c2 is part of a 0x0000, |
|
1039 |
// which encodes as {0xC0,0x80}. The 0x0000 is the |
|
1040 |
// lowest-sorting Java char value, and yet it encodes |
|
1041 |
// as if it were the first char after 0x7F, which causes |
|
1042 |
// strings containing nulls to sort too high. All other |
|
1043 |
// comparisons are consistent between Utf8 and Java chars. |
|
1044 |
if (c1 == 0xC0 && (p1[i+1] & 0xFF) == 0x80) c1 = 0; |
|
1045 |
if (c2 == 0xC0 && (p2[i+1] & 0xFF) == 0x80) c2 = 0; |
|
1046 |
if (c0 == 0xC0) { |
|
1047 |
assert(((c1|c2) & 0xC0) == 0x80); // c1 & c2 are extension chars |
|
1048 |
if (c1 == 0x80) c1 = 0; // will sort below c2 |
|
1049 |
if (c2 == 0x80) c2 = 0; // will sort below c1 |
|
1050 |
} |
|
1051 |
return c1 - c2; |
|
1052 |
} |
|
1053 |
c0 = c1; // save away previous char |
|
1054 |
} |
|
1055 |
// common prefix is identical; return length difference if any |
|
1056 |
return l1 - l2; |
|
1057 |
} |
|
1058 |
||
1059 |
// Cf. PackageReader.readUtf8Bands |
|
1060 |
local_inline |
|
1061 |
void unpacker::read_Utf8_values(entry* cpMap, int len) { |
|
1062 |
// Implicit first Utf8 string is the empty string. |
|
1063 |
enum { |
|
1064 |
// certain bands begin with implicit zeroes |
|
1065 |
PREFIX_SKIP_2 = 2, |
|
1066 |
SUFFIX_SKIP_1 = 1 |
|
1067 |
}; |
|
1068 |
||
1069 |
int i; |
|
1070 |
||
1071 |
// First band: Read lengths of shared prefixes. |
|
1072 |
if (len > PREFIX_SKIP_2) |
|
1073 |
cp_Utf8_prefix.readData(len - PREFIX_SKIP_2); |
|
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
1074 |
NOT_PRODUCT(else cp_Utf8_prefix.readData(0)); // for asserts |
2 | 1075 |
|
1076 |
// Second band: Read lengths of unshared suffixes: |
|
1077 |
if (len > SUFFIX_SKIP_1) |
|
1078 |
cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1); |
|
2602
5b394a4b6ce1
6755943: Java JAR Pack200 Decompression should enforce stricter header checks
ksrini
parents:
2
diff
changeset
|
1079 |
NOT_PRODUCT(else cp_Utf8_suffix.readData(0)); // for asserts |
2 | 1080 |
|
1081 |
bytes* allsuffixes = T_NEW(bytes, len); |
|
1082 |
CHECK; |
|
1083 |
||
1084 |
int nbigsuf = 0; |
|
1085 |
fillbytes charbuf; // buffer to allocate small strings |
|
1086 |
charbuf.init(); |
|
1087 |
||
1088 |
// Third band: Read the char values in the unshared suffixes: |
|
1089 |
cp_Utf8_chars.readData(cp_Utf8_suffix.getIntTotal()); |
|
1090 |
for (i = 0; i < len; i++) { |
|
1091 |
int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt(); |
|
1092 |
if (suffix < 0) { |
|
1093 |
abort("bad utf8 suffix"); |
|
1094 |
return; |
|
1095 |
} |
|
1096 |
if (suffix == 0 && i >= SUFFIX_SKIP_1) { |
|
1097 |
// chars are packed in cp_Utf8_big_chars |
|
1098 |
nbigsuf += 1; |
|
1099 |
continue; |
|
1100 |
} |
|
1101 |
bytes& chars = allsuffixes[i]; |
|
1102 |
uint size3 = suffix * 3; // max Utf8 length |
|
1103 |
bool isMalloc = (suffix > SMALL); |
|
1104 |
if (isMalloc) { |
|
1105 |
chars.malloc(size3); |
|
1106 |
} else { |
|
1107 |
if (!charbuf.canAppend(size3+1)) { |
|
1108 |
assert(charbuf.allocated == 0 || tmallocs.contains(charbuf.base())); |
|
1109 |
charbuf.init(CHUNK); // Reset to new buffer. |
|
1110 |
tmallocs.add(charbuf.base()); |
|
1111 |
} |
|
1112 |
chars.set(charbuf.grow(size3+1), size3); |
|
1113 |
} |
|
1114 |
CHECK; |
|
1115 |
byte* chp = chars.ptr; |
|
1116 |
for (int j = 0; j < suffix; j++) { |
|
1117 |
unsigned short ch = cp_Utf8_chars.getInt(); |
|
1118 |
chp = store_Utf8_char(chp, ch); |
|
1119 |
} |
|
1120 |
// shrink to fit: |
|
1121 |
if (isMalloc) { |
|
1122 |
chars.realloc(chp - chars.ptr); |
|
1123 |
CHECK; |
|
1124 |
tmallocs.add(chars.ptr); // free it later |
|
1125 |
} else { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1126 |
int shrink = (int)(chars.limit() - chp); |
2 | 1127 |
chars.len -= shrink; |
1128 |
charbuf.b.len -= shrink; // ungrow to reclaim buffer space |
|
1129 |
// Note that we did not reclaim the final '\0'. |
|
1130 |
assert(chars.limit() == charbuf.limit()-1); |
|
1131 |
assert(strlen((char*)chars.ptr) == chars.len); |
|
1132 |
} |
|
1133 |
} |
|
1134 |
//cp_Utf8_chars.done(); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1135 |
#ifndef PRODUCT |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1136 |
charbuf.b.set(null, 0); // tidy |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1137 |
#endif |
2 | 1138 |
|
1139 |
// Fourth band: Go back and size the specially packed strings. |
|
1140 |
int maxlen = 0; |
|
1141 |
cp_Utf8_big_suffix.readData(nbigsuf); |
|
1142 |
cp_Utf8_suffix.rewind(); |
|
1143 |
for (i = 0; i < len; i++) { |
|
1144 |
int suffix = (i < SUFFIX_SKIP_1)? 0: cp_Utf8_suffix.getInt(); |
|
1145 |
int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt(); |
|
1146 |
if (prefix < 0 || prefix+suffix < 0) { |
|
1147 |
abort("bad utf8 prefix"); |
|
1148 |
return; |
|
1149 |
} |
|
1150 |
bytes& chars = allsuffixes[i]; |
|
1151 |
if (suffix == 0 && i >= SUFFIX_SKIP_1) { |
|
1152 |
suffix = cp_Utf8_big_suffix.getInt(); |
|
1153 |
assert(chars.ptr == null); |
|
1154 |
chars.len = suffix; // just a momentary hack |
|
1155 |
} else { |
|
1156 |
assert(chars.ptr != null); |
|
1157 |
} |
|
1158 |
if (maxlen < prefix + suffix) { |
|
1159 |
maxlen = prefix + suffix; |
|
1160 |
} |
|
1161 |
} |
|
1162 |
//cp_Utf8_suffix.done(); // will use allsuffixes[i].len (ptr!=null) |
|
1163 |
//cp_Utf8_big_suffix.done(); // will use allsuffixes[i].len |
|
1164 |
||
1165 |
// Fifth band(s): Get the specially packed characters. |
|
1166 |
cp_Utf8_big_suffix.rewind(); |
|
1167 |
for (i = 0; i < len; i++) { |
|
1168 |
bytes& chars = allsuffixes[i]; |
|
1169 |
if (chars.ptr != null) continue; // already input |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1170 |
int suffix = (int)chars.len; // pick up the hack |
2 | 1171 |
uint size3 = suffix * 3; |
1172 |
if (suffix == 0) continue; // done with empty string |
|
1173 |
chars.malloc(size3); |
|
10907
ea32ea5b72d7
7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents:
9035
diff
changeset
|
1174 |
CHECK; |
2 | 1175 |
byte* chp = chars.ptr; |
1176 |
band saved_band = cp_Utf8_big_chars; |
|
1177 |
cp_Utf8_big_chars.readData(suffix); |
|
10907
ea32ea5b72d7
7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents:
9035
diff
changeset
|
1178 |
CHECK; |
2 | 1179 |
for (int j = 0; j < suffix; j++) { |
1180 |
unsigned short ch = cp_Utf8_big_chars.getInt(); |
|
10907
ea32ea5b72d7
7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents:
9035
diff
changeset
|
1181 |
CHECK; |
2 | 1182 |
chp = store_Utf8_char(chp, ch); |
1183 |
} |
|
1184 |
chars.realloc(chp - chars.ptr); |
|
1185 |
CHECK; |
|
1186 |
tmallocs.add(chars.ptr); // free it later |
|
1187 |
//cp_Utf8_big_chars.done(); |
|
1188 |
cp_Utf8_big_chars = saved_band; // reset the band for the next string |
|
1189 |
} |
|
1190 |
cp_Utf8_big_chars.readData(0); // zero chars |
|
1191 |
//cp_Utf8_big_chars.done(); |
|
1192 |
||
1193 |
// Finally, sew together all the prefixes and suffixes. |
|
1194 |
bytes bigbuf; |
|
1195 |
bigbuf.malloc(maxlen * 3 + 1); // max Utf8 length, plus slop for null |
|
1196 |
CHECK; |
|
1197 |
int prevlen = 0; // previous string length (in chars) |
|
1198 |
tmallocs.add(bigbuf.ptr); // free after this block |
|
10907
ea32ea5b72d7
7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents:
9035
diff
changeset
|
1199 |
CHECK; |
2 | 1200 |
cp_Utf8_prefix.rewind(); |
1201 |
for (i = 0; i < len; i++) { |
|
1202 |
bytes& chars = allsuffixes[i]; |
|
1203 |
int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt(); |
|
10907
ea32ea5b72d7
7057857: SIGSEGV [libunpack.so] store_Utf8_char(signed char*, unsigned short) in java.util.jar.pack200
ksrini
parents:
9035
diff
changeset
|
1204 |
CHECK; |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1205 |
int suffix = (int)chars.len; |
2 | 1206 |
byte* fillp; |
1207 |
// by induction, the buffer is already filled with the prefix |
|
1208 |
// make sure the prefix value is not corrupted, though: |
|
1209 |
if (prefix > prevlen) { |
|
1210 |
abort("utf8 prefix overflow"); |
|
1211 |
return; |
|
1212 |
} |
|
1213 |
fillp = skip_Utf8_chars(bigbuf.ptr, prefix); |
|
1214 |
// copy the suffix into the same buffer: |
|
1215 |
fillp = chars.writeTo(fillp); |
|
1216 |
assert(bigbuf.inBounds(fillp)); |
|
1217 |
*fillp = 0; // bigbuf must contain a well-formed Utf8 string |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1218 |
int length = (int)(fillp - bigbuf.ptr); |
2 | 1219 |
bytes& value = cpMap[i].value.b; |
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
1220 |
value.set(U_NEW(byte, add_size(length,1)), length); |
2 | 1221 |
value.copyFrom(bigbuf.ptr, length); |
1222 |
CHECK; |
|
1223 |
// Index all Utf8 strings |
|
1224 |
entry* &htref = cp.hashTabRef(CONSTANT_Utf8, value); |
|
1225 |
if (htref == null) { |
|
1226 |
// Note that if two identical strings are transmitted, |
|
1227 |
// the first is taken to be the canonical one. |
|
1228 |
htref = &cpMap[i]; |
|
1229 |
} |
|
1230 |
prevlen = prefix + suffix; |
|
1231 |
} |
|
1232 |
//cp_Utf8_prefix.done(); |
|
1233 |
||
1234 |
// Free intermediate buffers. |
|
1235 |
free_temps(); |
|
1236 |
} |
|
1237 |
||
1238 |
local_inline |
|
1239 |
void unpacker::read_single_words(band& cp_band, entry* cpMap, int len) { |
|
1240 |
cp_band.readData(len); |
|
1241 |
for (int i = 0; i < len; i++) { |
|
1242 |
cpMap[i].value.i = cp_band.getInt(); // coding handles signs OK |
|
1243 |
} |
|
1244 |
} |
|
1245 |
||
1246 |
maybe_inline |
|
1247 |
void unpacker::read_double_words(band& cp_bands, entry* cpMap, int len) { |
|
1248 |
band& cp_band_hi = cp_bands; |
|
1249 |
band& cp_band_lo = cp_bands.nextBand(); |
|
1250 |
cp_band_hi.readData(len); |
|
1251 |
cp_band_lo.readData(len); |
|
1252 |
for (int i = 0; i < len; i++) { |
|
1253 |
cpMap[i].value.l = cp_band_hi.getLong(cp_band_lo, true); |
|
1254 |
} |
|
1255 |
//cp_band_hi.done(); |
|
1256 |
//cp_band_lo.done(); |
|
1257 |
} |
|
1258 |
||
1259 |
maybe_inline |
|
1260 |
void unpacker::read_single_refs(band& cp_band, byte refTag, entry* cpMap, int len) { |
|
1261 |
assert(refTag == CONSTANT_Utf8); |
|
1262 |
cp_band.setIndexByTag(refTag); |
|
1263 |
cp_band.readData(len); |
|
1264 |
CHECK; |
|
1265 |
int indexTag = (cp_band.bn == e_cp_Class) ? CONSTANT_Class : 0; |
|
1266 |
for (int i = 0; i < len; i++) { |
|
1267 |
entry& e = cpMap[i]; |
|
1268 |
e.refs = U_NEW(entry*, e.nrefs = 1); |
|
1269 |
entry* utf = cp_band.getRef(); |
|
1270 |
CHECK; |
|
1271 |
e.refs[0] = utf; |
|
1272 |
e.value.b = utf->value.b; // copy value of Utf8 string to self |
|
1273 |
if (indexTag != 0) { |
|
1274 |
// Maintain cross-reference: |
|
1275 |
entry* &htref = cp.hashTabRef(indexTag, e.value.b); |
|
1276 |
if (htref == null) { |
|
1277 |
// Note that if two identical classes are transmitted, |
|
1278 |
// the first is taken to be the canonical one. |
|
1279 |
htref = &e; |
|
1280 |
} |
|
1281 |
} |
|
1282 |
} |
|
1283 |
//cp_band.done(); |
|
1284 |
} |
|
1285 |
||
1286 |
maybe_inline |
|
1287 |
void unpacker::read_double_refs(band& cp_band, byte ref1Tag, byte ref2Tag, |
|
1288 |
entry* cpMap, int len) { |
|
1289 |
band& cp_band1 = cp_band; |
|
1290 |
band& cp_band2 = cp_band.nextBand(); |
|
1291 |
cp_band1.setIndexByTag(ref1Tag); |
|
1292 |
cp_band2.setIndexByTag(ref2Tag); |
|
1293 |
cp_band1.readData(len); |
|
1294 |
cp_band2.readData(len); |
|
1295 |
CHECK; |
|
1296 |
for (int i = 0; i < len; i++) { |
|
1297 |
entry& e = cpMap[i]; |
|
1298 |
e.refs = U_NEW(entry*, e.nrefs = 2); |
|
1299 |
e.refs[0] = cp_band1.getRef(); |
|
16075 | 1300 |
CHECK; |
2 | 1301 |
e.refs[1] = cp_band2.getRef(); |
1302 |
CHECK; |
|
1303 |
} |
|
1304 |
//cp_band1.done(); |
|
1305 |
//cp_band2.done(); |
|
1306 |
} |
|
1307 |
||
1308 |
// Cf. PackageReader.readSignatureBands |
|
1309 |
maybe_inline |
|
1310 |
void unpacker::read_signature_values(entry* cpMap, int len) { |
|
1311 |
cp_Signature_form.setIndexByTag(CONSTANT_Utf8); |
|
1312 |
cp_Signature_form.readData(len); |
|
1313 |
CHECK; |
|
1314 |
int ncTotal = 0; |
|
1315 |
int i; |
|
1316 |
for (i = 0; i < len; i++) { |
|
1317 |
entry& e = cpMap[i]; |
|
1318 |
entry& form = *cp_Signature_form.getRef(); |
|
1319 |
CHECK; |
|
1320 |
int nc = 0; |
|
1321 |
||
1322 |
for ( const char* ncp = form.utf8String() ; *ncp; ncp++) { |
|
1323 |
if (*ncp == 'L') nc++; |
|
1324 |
} |
|
1325 |
||
1326 |
ncTotal += nc; |
|
1327 |
e.refs = U_NEW(entry*, cpMap[i].nrefs = 1 + nc); |
|
1328 |
CHECK; |
|
1329 |
e.refs[0] = &form; |
|
1330 |
} |
|
1331 |
//cp_Signature_form.done(); |
|
1332 |
cp_Signature_classes.setIndexByTag(CONSTANT_Class); |
|
1333 |
cp_Signature_classes.readData(ncTotal); |
|
1334 |
for (i = 0; i < len; i++) { |
|
1335 |
entry& e = cpMap[i]; |
|
1336 |
for (int j = 1; j < e.nrefs; j++) { |
|
1337 |
e.refs[j] = cp_Signature_classes.getRef(); |
|
1338 |
CHECK; |
|
1339 |
} |
|
1340 |
} |
|
1341 |
//cp_Signature_classes.done(); |
|
1342 |
} |
|
1343 |
||
12544 | 1344 |
maybe_inline |
1345 |
void unpacker::checkLegacy(const char* name) { |
|
1346 |
if (u->majver < JAVA7_PACKAGE_MAJOR_VERSION) { |
|
1347 |
char message[100]; |
|
1348 |
snprintf(message, 99, "unexpected band %s\n", name); |
|
1349 |
abort(message); |
|
1350 |
} |
|
1351 |
} |
|
1352 |
||
1353 |
maybe_inline |
|
1354 |
void unpacker::read_method_handle(entry* cpMap, int len) { |
|
1355 |
if (len > 0) { |
|
1356 |
checkLegacy(cp_MethodHandle_refkind.name); |
|
1357 |
} |
|
1358 |
cp_MethodHandle_refkind.readData(len); |
|
1359 |
cp_MethodHandle_member.setIndexByTag(CONSTANT_AnyMember); |
|
1360 |
cp_MethodHandle_member.readData(len); |
|
1361 |
for (int i = 0 ; i < len ; i++) { |
|
1362 |
entry& e = cpMap[i]; |
|
1363 |
e.value.i = cp_MethodHandle_refkind.getInt(); |
|
1364 |
e.refs = U_NEW(entry*, e.nrefs = 1); |
|
1365 |
e.refs[0] = cp_MethodHandle_member.getRef(); |
|
1366 |
CHECK; |
|
1367 |
} |
|
1368 |
} |
|
1369 |
||
1370 |
maybe_inline |
|
1371 |
void unpacker::read_method_type(entry* cpMap, int len) { |
|
1372 |
if (len > 0) { |
|
1373 |
checkLegacy(cp_MethodType.name); |
|
1374 |
} |
|
1375 |
cp_MethodType.setIndexByTag(CONSTANT_Signature); |
|
1376 |
cp_MethodType.readData(len); |
|
1377 |
for (int i = 0 ; i < len ; i++) { |
|
1378 |
entry& e = cpMap[i]; |
|
1379 |
e.refs = U_NEW(entry*, e.nrefs = 1); |
|
1380 |
e.refs[0] = cp_MethodType.getRef(); |
|
16075 | 1381 |
CHECK; |
12544 | 1382 |
} |
1383 |
} |
|
1384 |
||
1385 |
maybe_inline |
|
1386 |
void unpacker::read_bootstrap_methods(entry* cpMap, int len) { |
|
1387 |
if (len > 0) { |
|
1388 |
checkLegacy(cp_BootstrapMethod_ref.name); |
|
1389 |
} |
|
1390 |
cp_BootstrapMethod_ref.setIndexByTag(CONSTANT_MethodHandle); |
|
1391 |
cp_BootstrapMethod_ref.readData(len); |
|
1392 |
||
1393 |
cp_BootstrapMethod_arg_count.readData(len); |
|
1394 |
int totalArgCount = cp_BootstrapMethod_arg_count.getIntTotal(); |
|
1395 |
cp_BootstrapMethod_arg.setIndexByTag(CONSTANT_LoadableValue); |
|
1396 |
cp_BootstrapMethod_arg.readData(totalArgCount); |
|
1397 |
for (int i = 0; i < len; i++) { |
|
1398 |
entry& e = cpMap[i]; |
|
1399 |
int argc = cp_BootstrapMethod_arg_count.getInt(); |
|
1400 |
e.value.i = argc; |
|
1401 |
e.refs = U_NEW(entry*, e.nrefs = argc + 1); |
|
1402 |
e.refs[0] = cp_BootstrapMethod_ref.getRef(); |
|
1403 |
for (int j = 1 ; j < e.nrefs ; j++) { |
|
1404 |
e.refs[j] = cp_BootstrapMethod_arg.getRef(); |
|
1405 |
CHECK; |
|
1406 |
} |
|
1407 |
} |
|
1408 |
} |
|
2 | 1409 |
// Cf. PackageReader.readConstantPool |
1410 |
void unpacker::read_cp() { |
|
1411 |
byte* rp0 = rp; |
|
1412 |
||
1413 |
int i; |
|
1414 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1415 |
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) { |
2 | 1416 |
byte tag = TAGS_IN_ORDER[k]; |
1417 |
int len = cp.tag_count[tag]; |
|
1418 |
int base = cp.tag_base[tag]; |
|
1419 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1420 |
PRINTCR((1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0)); |
2 | 1421 |
entry* cpMap = &cp.entries[base]; |
1422 |
for (i = 0; i < len; i++) { |
|
1423 |
cpMap[i].tag = tag; |
|
1424 |
cpMap[i].inord = i; |
|
1425 |
} |
|
12544 | 1426 |
// Initialize the tag's CP index right away, since it might be needed |
1427 |
// in the next pass to initialize the CP for another tag. |
|
1428 |
#ifndef PRODUCT |
|
1429 |
cpindex* ix = &cp.tag_index[tag]; |
|
1430 |
assert(ix->ixTag == tag); |
|
1431 |
assert((int)ix->len == len); |
|
1432 |
assert(ix->base1 == cpMap); |
|
1433 |
#endif |
|
2 | 1434 |
|
1435 |
switch (tag) { |
|
1436 |
case CONSTANT_Utf8: |
|
1437 |
read_Utf8_values(cpMap, len); |
|
1438 |
break; |
|
1439 |
case CONSTANT_Integer: |
|
1440 |
read_single_words(cp_Int, cpMap, len); |
|
1441 |
break; |
|
1442 |
case CONSTANT_Float: |
|
1443 |
read_single_words(cp_Float, cpMap, len); |
|
1444 |
break; |
|
1445 |
case CONSTANT_Long: |
|
1446 |
read_double_words(cp_Long_hi /*& cp_Long_lo*/, cpMap, len); |
|
1447 |
break; |
|
1448 |
case CONSTANT_Double: |
|
1449 |
read_double_words(cp_Double_hi /*& cp_Double_lo*/, cpMap, len); |
|
1450 |
break; |
|
1451 |
case CONSTANT_String: |
|
1452 |
read_single_refs(cp_String, CONSTANT_Utf8, cpMap, len); |
|
1453 |
break; |
|
1454 |
case CONSTANT_Class: |
|
1455 |
read_single_refs(cp_Class, CONSTANT_Utf8, cpMap, len); |
|
1456 |
break; |
|
1457 |
case CONSTANT_Signature: |
|
1458 |
read_signature_values(cpMap, len); |
|
1459 |
break; |
|
1460 |
case CONSTANT_NameandType: |
|
1461 |
read_double_refs(cp_Descr_name /*& cp_Descr_type*/, |
|
1462 |
CONSTANT_Utf8, CONSTANT_Signature, |
|
1463 |
cpMap, len); |
|
1464 |
break; |
|
1465 |
case CONSTANT_Fieldref: |
|
1466 |
read_double_refs(cp_Field_class /*& cp_Field_desc*/, |
|
1467 |
CONSTANT_Class, CONSTANT_NameandType, |
|
1468 |
cpMap, len); |
|
1469 |
break; |
|
1470 |
case CONSTANT_Methodref: |
|
1471 |
read_double_refs(cp_Method_class /*& cp_Method_desc*/, |
|
1472 |
CONSTANT_Class, CONSTANT_NameandType, |
|
1473 |
cpMap, len); |
|
1474 |
break; |
|
1475 |
case CONSTANT_InterfaceMethodref: |
|
1476 |
read_double_refs(cp_Imethod_class /*& cp_Imethod_desc*/, |
|
1477 |
CONSTANT_Class, CONSTANT_NameandType, |
|
1478 |
cpMap, len); |
|
1479 |
break; |
|
12544 | 1480 |
case CONSTANT_MethodHandle: |
1481 |
// consumes cp_MethodHandle_refkind and cp_MethodHandle_member |
|
1482 |
read_method_handle(cpMap, len); |
|
1483 |
break; |
|
1484 |
case CONSTANT_MethodType: |
|
1485 |
// consumes cp_MethodType |
|
1486 |
read_method_type(cpMap, len); |
|
1487 |
break; |
|
1488 |
case CONSTANT_InvokeDynamic: |
|
1489 |
read_double_refs(cp_InvokeDynamic_spec, CONSTANT_BootstrapMethod, |
|
1490 |
CONSTANT_NameandType, |
|
1491 |
cpMap, len); |
|
1492 |
break; |
|
1493 |
case CONSTANT_BootstrapMethod: |
|
1494 |
// consumes cp_BootstrapMethod_ref, cp_BootstrapMethod_arg_count and cp_BootstrapMethod_arg |
|
1495 |
read_bootstrap_methods(cpMap, len); |
|
1496 |
break; |
|
2 | 1497 |
default: |
1498 |
assert(false); |
|
1499 |
break; |
|
1500 |
} |
|
1501 |
CHECK; |
|
1502 |
} |
|
1503 |
||
1504 |
cp.expandSignatures(); |
|
1505 |
CHECK; |
|
1506 |
cp.initMemberIndexes(); |
|
1507 |
CHECK; |
|
1508 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1509 |
PRINTCR((1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0))); |
2 | 1510 |
|
1511 |
#define SNAME(n,s) #s "\0" |
|
1512 |
const char* symNames = ( |
|
1513 |
ALL_ATTR_DO(SNAME) |
|
1514 |
"<init>" |
|
1515 |
); |
|
1516 |
#undef SNAME |
|
1517 |
||
1518 |
for (int sn = 0; sn < cpool::s_LIMIT; sn++) { |
|
1519 |
assert(symNames[0] >= '0' && symNames[0] <= 'Z'); // sanity |
|
1520 |
bytes name; name.set(symNames); |
|
1521 |
if (name.len > 0 && name.ptr[0] != '0') { |
|
1522 |
cp.sym[sn] = cp.ensureUtf8(name); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1523 |
PRINTCR((4, "well-known sym %d=%s", sn, cp.sym[sn]->string())); |
2 | 1524 |
} |
1525 |
symNames += name.len + 1; // skip trailing null to next name |
|
1526 |
} |
|
1527 |
||
1528 |
band::initIndexes(this); |
|
1529 |
} |
|
1530 |
||
1531 |
static band* no_bands[] = { null }; // shared empty body |
|
1532 |
||
1533 |
inline |
|
1534 |
band& unpacker::attr_definitions::fixed_band(int e_class_xxx) { |
|
1535 |
return u->all_bands[xxx_flags_hi_bn + (e_class_xxx-e_class_flags_hi)]; |
|
1536 |
} |
|
1537 |
inline band& unpacker::attr_definitions::xxx_flags_hi() |
|
1538 |
{ return fixed_band(e_class_flags_hi); } |
|
1539 |
inline band& unpacker::attr_definitions::xxx_flags_lo() |
|
1540 |
{ return fixed_band(e_class_flags_lo); } |
|
1541 |
inline band& unpacker::attr_definitions::xxx_attr_count() |
|
1542 |
{ return fixed_band(e_class_attr_count); } |
|
1543 |
inline band& unpacker::attr_definitions::xxx_attr_indexes() |
|
1544 |
{ return fixed_band(e_class_attr_indexes); } |
|
1545 |
inline band& unpacker::attr_definitions::xxx_attr_calls() |
|
1546 |
{ return fixed_band(e_class_attr_calls); } |
|
1547 |
||
1548 |
||
1549 |
inline |
|
1550 |
unpacker::layout_definition* |
|
1551 |
unpacker::attr_definitions::defineLayout(int idx, |
|
1552 |
entry* nameEntry, |
|
1553 |
const char* layout) { |
|
1554 |
const char* name = nameEntry->value.b.strval(); |
|
1555 |
layout_definition* lo = defineLayout(idx, name, layout); |
|
1556 |
CHECK_0; |
|
1557 |
lo->nameEntry = nameEntry; |
|
1558 |
return lo; |
|
1559 |
} |
|
1560 |
||
1561 |
unpacker::layout_definition* |
|
1562 |
unpacker::attr_definitions::defineLayout(int idx, |
|
1563 |
const char* name, |
|
1564 |
const char* layout) { |
|
1565 |
assert(flag_limit != 0); // must be set up already |
|
1566 |
if (idx >= 0) { |
|
1567 |
// Fixed attr. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1568 |
if (idx >= (int)flag_limit) |
2 | 1569 |
abort("attribute index too large"); |
1570 |
if (isRedefined(idx)) |
|
1571 |
abort("redefined attribute index"); |
|
1572 |
redef |= ((julong)1<<idx); |
|
1573 |
} else { |
|
1574 |
idx = flag_limit + overflow_count.length(); |
|
1575 |
overflow_count.add(0); // make a new counter |
|
1576 |
} |
|
1577 |
layout_definition* lo = U_NEW(layout_definition, 1); |
|
1578 |
CHECK_0; |
|
1579 |
lo->idx = idx; |
|
1580 |
lo->name = name; |
|
1581 |
lo->layout = layout; |
|
1582 |
for (int adds = (idx+1) - layouts.length(); adds > 0; adds--) { |
|
1583 |
layouts.add(null); |
|
1584 |
} |
|
1585 |
CHECK_0; |
|
1586 |
layouts.get(idx) = lo; |
|
1587 |
return lo; |
|
1588 |
} |
|
1589 |
||
1590 |
band** |
|
1591 |
unpacker::attr_definitions::buildBands(unpacker::layout_definition* lo) { |
|
1592 |
int i; |
|
1593 |
if (lo->elems != null) |
|
1594 |
return lo->bands(); |
|
1595 |
if (lo->layout[0] == '\0') { |
|
1596 |
lo->elems = no_bands; |
|
1597 |
} else { |
|
1598 |
// Create bands for this attribute by parsing the layout. |
|
1599 |
bool hasCallables = lo->hasCallables(); |
|
1600 |
bands_made = 0x10000; // base number for bands made |
|
1601 |
const char* lp = lo->layout; |
|
1602 |
lp = parseLayout(lp, lo->elems, -1); |
|
1603 |
CHECK_0; |
|
1604 |
if (lp[0] != '\0' || band_stack.length() > 0) { |
|
1605 |
abort("garbage at end of layout"); |
|
1606 |
} |
|
1607 |
band_stack.popTo(0); |
|
1608 |
CHECK_0; |
|
1609 |
||
1610 |
// Fix up callables to point at their callees. |
|
1611 |
band** bands = lo->elems; |
|
1612 |
assert(bands == lo->bands()); |
|
1613 |
int num_callables = 0; |
|
1614 |
if (hasCallables) { |
|
1615 |
while (bands[num_callables] != null) { |
|
1616 |
if (bands[num_callables]->le_kind != EK_CBLE) { |
|
1617 |
abort("garbage mixed with callables"); |
|
1618 |
break; |
|
1619 |
} |
|
1620 |
num_callables += 1; |
|
1621 |
} |
|
1622 |
} |
|
1623 |
for (i = 0; i < calls_to_link.length(); i++) { |
|
1624 |
band& call = *(band*) calls_to_link.get(i); |
|
1625 |
assert(call.le_kind == EK_CALL); |
|
1626 |
// Determine the callee. |
|
1627 |
int call_num = call.le_len; |
|
1628 |
if (call_num < 0 || call_num >= num_callables) { |
|
1629 |
abort("bad call in layout"); |
|
1630 |
break; |
|
1631 |
} |
|
1632 |
band& cble = *bands[call_num]; |
|
1633 |
// Link the call to it. |
|
1634 |
call.le_body[0] = &cble; |
|
1635 |
// Distinguish backward calls and callables: |
|
1636 |
assert(cble.le_kind == EK_CBLE); |
|
1637 |
assert(cble.le_len == call_num); |
|
1638 |
cble.le_back |= call.le_back; |
|
1639 |
} |
|
1640 |
calls_to_link.popTo(0); |
|
1641 |
} |
|
1642 |
return lo->elems; |
|
1643 |
} |
|
1644 |
||
1645 |
/* attribute layout language parser |
|
1646 |
||
1647 |
attribute_layout: |
|
1648 |
( layout_element )* | ( callable )+ |
|
1649 |
layout_element: |
|
1650 |
( integral | replication | union | call | reference ) |
|
1651 |
||
1652 |
callable: |
|
1653 |
'[' body ']' |
|
1654 |
body: |
|
1655 |
( layout_element )+ |
|
1656 |
||
1657 |
integral: |
|
1658 |
( unsigned_int | signed_int | bc_index | bc_offset | flag ) |
|
1659 |
unsigned_int: |
|
1660 |
uint_type |
|
1661 |
signed_int: |
|
1662 |
'S' uint_type |
|
1663 |
any_int: |
|
1664 |
( unsigned_int | signed_int ) |
|
1665 |
bc_index: |
|
1666 |
( 'P' uint_type | 'PO' uint_type ) |
|
1667 |
bc_offset: |
|
1668 |
'O' any_int |
|
1669 |
flag: |
|
1670 |
'F' uint_type |
|
1671 |
uint_type: |
|
1672 |
( 'B' | 'H' | 'I' | 'V' ) |
|
1673 |
||
1674 |
replication: |
|
1675 |
'N' uint_type '[' body ']' |
|
1676 |
||
1677 |
union: |
|
1678 |
'T' any_int (union_case)* '(' ')' '[' (body)? ']' |
|
1679 |
union_case: |
|
1680 |
'(' union_case_tag (',' union_case_tag)* ')' '[' (body)? ']' |
|
1681 |
union_case_tag: |
|
1682 |
( numeral | numeral '-' numeral ) |
|
1683 |
call: |
|
1684 |
'(' numeral ')' |
|
1685 |
||
1686 |
reference: |
|
1687 |
reference_type ( 'N' )? uint_type |
|
1688 |
reference_type: |
|
1689 |
( constant_ref | schema_ref | utf8_ref | untyped_ref ) |
|
1690 |
constant_ref: |
|
1691 |
( 'KI' | 'KJ' | 'KF' | 'KD' | 'KS' | 'KQ' ) |
|
1692 |
schema_ref: |
|
1693 |
( 'RC' | 'RS' | 'RD' | 'RF' | 'RM' | 'RI' ) |
|
1694 |
utf8_ref: |
|
1695 |
'RU' |
|
1696 |
untyped_ref: |
|
1697 |
'RQ' |
|
1698 |
||
1699 |
numeral: |
|
1700 |
'(' ('-')? (digit)+ ')' |
|
1701 |
digit: |
|
1702 |
( '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' ) |
|
1703 |
||
1704 |
*/ |
|
1705 |
||
1706 |
const char* |
|
1707 |
unpacker::attr_definitions::parseIntLayout(const char* lp, band* &res, |
|
1708 |
byte le_kind, bool can_be_signed) { |
|
1709 |
const char* lp0 = lp; |
|
1710 |
band* b = U_NEW(band, 1); |
|
1711 |
CHECK_(lp); |
|
1712 |
char le = *lp++; |
|
1713 |
int spec = UNSIGNED5_spec; |
|
1714 |
if (le == 'S' && can_be_signed) { |
|
1715 |
// Note: This is the last use of sign. There is no 'EF_SIGN'. |
|
1716 |
spec = SIGNED5_spec; |
|
1717 |
le = *lp++; |
|
1718 |
} else if (le == 'B') { |
|
1719 |
spec = BYTE1_spec; // unsigned byte |
|
1720 |
} |
|
1721 |
b->init(u, bands_made++, spec); |
|
1722 |
b->le_kind = le_kind; |
|
1723 |
int le_len = 0; |
|
1724 |
switch (le) { |
|
1725 |
case 'B': le_len = 1; break; |
|
1726 |
case 'H': le_len = 2; break; |
|
1727 |
case 'I': le_len = 4; break; |
|
1728 |
case 'V': le_len = 0; break; |
|
1729 |
default: abort("bad layout element"); |
|
1730 |
} |
|
1731 |
b->le_len = le_len; |
|
1732 |
band_stack.add(b); |
|
1733 |
res = b; |
|
1734 |
return lp; |
|
1735 |
} |
|
1736 |
||
1737 |
const char* |
|
1738 |
unpacker::attr_definitions::parseNumeral(const char* lp, int &res) { |
|
1739 |
const char* lp0 = lp; |
|
1740 |
bool sgn = false; |
|
1741 |
if (*lp == '0') { res = 0; return lp+1; } // special case '0' |
|
1742 |
if (*lp == '-') { sgn = true; lp++; } |
|
1743 |
const char* dp = lp; |
|
1744 |
int con = 0; |
|
1745 |
while (*dp >= '0' && *dp <= '9') { |
|
1746 |
int con0 = con; |
|
1747 |
con *= 10; |
|
1748 |
con += (*dp++) - '0'; |
|
1749 |
if (con <= con0) { con = -1; break; } // numeral overflow |
|
1750 |
} |
|
1751 |
if (lp == dp) { |
|
1752 |
abort("missing numeral in layout"); |
|
1753 |
return ""; |
|
1754 |
} |
|
1755 |
lp = dp; |
|
1756 |
if (con < 0 && !(sgn && con == -con)) { |
|
1757 |
// (Portability note: Misses the error if int is not 32 bits.) |
|
1758 |
abort("numeral overflow"); |
|
1759 |
return "" ; |
|
1760 |
} |
|
1761 |
if (sgn) con = -con; |
|
1762 |
res = con; |
|
1763 |
return lp; |
|
1764 |
} |
|
1765 |
||
1766 |
band** |
|
1767 |
unpacker::attr_definitions::popBody(int bs_base) { |
|
1768 |
// Return everything that was pushed, as a null-terminated pointer array. |
|
1769 |
int bs_limit = band_stack.length(); |
|
1770 |
if (bs_base == bs_limit) { |
|
1771 |
return no_bands; |
|
1772 |
} else { |
|
1773 |
int nb = bs_limit - bs_base; |
|
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
1774 |
band** res = U_NEW(band*, add_size(nb, 1)); |
2 | 1775 |
CHECK_(no_bands); |
1776 |
for (int i = 0; i < nb; i++) { |
|
1777 |
band* b = (band*) band_stack.get(bs_base + i); |
|
1778 |
res[i] = b; |
|
1779 |
} |
|
1780 |
band_stack.popTo(bs_base); |
|
1781 |
return res; |
|
1782 |
} |
|
1783 |
} |
|
1784 |
||
1785 |
const char* |
|
1786 |
unpacker::attr_definitions::parseLayout(const char* lp, band** &res, |
|
1787 |
int curCble) { |
|
1788 |
const char* lp0 = lp; |
|
1789 |
int bs_base = band_stack.length(); |
|
1790 |
bool top_level = (bs_base == 0); |
|
1791 |
band* b; |
|
1792 |
enum { can_be_signed = true }; // optional arg to parseIntLayout |
|
1793 |
||
1794 |
for (bool done = false; !done; ) { |
|
1795 |
switch (*lp++) { |
|
1796 |
case 'B': case 'H': case 'I': case 'V': // unsigned_int |
|
1797 |
case 'S': // signed_int |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
1798 |
--lp; // reparse |
2 | 1799 |
case 'F': |
1800 |
lp = parseIntLayout(lp, b, EK_INT); |
|
1801 |
break; |
|
1802 |
case 'P': |
|
1803 |
{ |
|
1804 |
int le_bci = EK_BCI; |
|
1805 |
if (*lp == 'O') { |
|
1806 |
++lp; |
|
1807 |
le_bci = EK_BCID; |
|
1808 |
} |
|
1809 |
assert(*lp != 'S'); // no PSH, etc. |
|
1810 |
lp = parseIntLayout(lp, b, EK_INT); |
|
1811 |
b->le_bci = le_bci; |
|
1812 |
if (le_bci == EK_BCI) |
|
1813 |
b->defc = coding::findBySpec(BCI5_spec); |
|
1814 |
else |
|
1815 |
b->defc = coding::findBySpec(BRANCH5_spec); |
|
1816 |
} |
|
1817 |
break; |
|
1818 |
case 'O': |
|
1819 |
lp = parseIntLayout(lp, b, EK_INT, can_be_signed); |
|
1820 |
b->le_bci = EK_BCO; |
|
1821 |
b->defc = coding::findBySpec(BRANCH5_spec); |
|
1822 |
break; |
|
1823 |
case 'N': // replication: 'N' uint '[' elem ... ']' |
|
1824 |
lp = parseIntLayout(lp, b, EK_REPL); |
|
1825 |
assert(*lp == '['); |
|
1826 |
++lp; |
|
1827 |
lp = parseLayout(lp, b->le_body, curCble); |
|
1828 |
CHECK_(lp); |
|
1829 |
break; |
|
1830 |
case 'T': // union: 'T' any_int union_case* '(' ')' '[' body ']' |
|
1831 |
lp = parseIntLayout(lp, b, EK_UN, can_be_signed); |
|
1832 |
{ |
|
1833 |
int union_base = band_stack.length(); |
|
1834 |
for (;;) { // for each case |
|
1835 |
band& k_case = *U_NEW(band, 1); |
|
1836 |
CHECK_(lp); |
|
1837 |
band_stack.add(&k_case); |
|
1838 |
k_case.le_kind = EK_CASE; |
|
1839 |
k_case.bn = bands_made++; |
|
1840 |
if (*lp++ != '(') { |
|
1841 |
abort("bad union case"); |
|
1842 |
return ""; |
|
1843 |
} |
|
1844 |
if (*lp++ != ')') { |
|
1845 |
--lp; // reparse |
|
1846 |
// Read some case values. (Use band_stack for temp. storage.) |
|
1847 |
int case_base = band_stack.length(); |
|
1848 |
for (;;) { |
|
1849 |
int caseval = 0; |
|
1850 |
lp = parseNumeral(lp, caseval); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1851 |
band_stack.add((void*)(size_t)caseval); |
2 | 1852 |
if (*lp == '-') { |
1853 |
// new in version 160, allow (1-5) for (1,2,3,4,5) |
|
1854 |
if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) { |
|
1855 |
abort("bad range in union case label (old archive format)"); |
|
1856 |
return ""; |
|
1857 |
} |
|
1858 |
int caselimit = caseval; |
|
1859 |
lp++; |
|
1860 |
lp = parseNumeral(lp, caselimit); |
|
1861 |
if (caseval >= caselimit |
|
1862 |
|| (uint)(caselimit - caseval) > 0x10000) { |
|
1863 |
// Note: 0x10000 is arbitrary implementation restriction. |
|
1864 |
// We can remove it later if it's important to. |
|
1865 |
abort("bad range in union case label"); |
|
1866 |
return ""; |
|
1867 |
} |
|
1868 |
for (;;) { |
|
1869 |
++caseval; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
1870 |
band_stack.add((void*)(size_t)caseval); |
2 | 1871 |
if (caseval == caselimit) break; |
1872 |
} |
|
1873 |
} |
|
1874 |
if (*lp != ',') break; |
|
1875 |
lp++; |
|
1876 |
} |
|
1877 |
if (*lp++ != ')') { |
|
1878 |
abort("bad case label"); |
|
1879 |
return ""; |
|
1880 |
} |
|
1881 |
// save away the case labels |
|
1882 |
int ntags = band_stack.length() - case_base; |
|
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
1883 |
int* tags = U_NEW(int, add_size(ntags, 1)); |
2 | 1884 |
CHECK_(lp); |
1885 |
k_case.le_casetags = tags; |
|
1886 |
*tags++ = ntags; |
|
1887 |
for (int i = 0; i < ntags; i++) { |
|
1888 |
*tags++ = ptrlowbits(band_stack.get(case_base+i)); |
|
1889 |
} |
|
1890 |
band_stack.popTo(case_base); |
|
1891 |
CHECK_(lp); |
|
1892 |
} |
|
1893 |
// Got le_casetags. Now grab the body. |
|
1894 |
assert(*lp == '['); |
|
1895 |
++lp; |
|
1896 |
lp = parseLayout(lp, k_case.le_body, curCble); |
|
1897 |
CHECK_(lp); |
|
1898 |
if (k_case.le_casetags == null) break; // done |
|
1899 |
} |
|
1900 |
b->le_body = popBody(union_base); |
|
1901 |
} |
|
1902 |
break; |
|
1903 |
case '(': // call: '(' -?NN* ')' |
|
1904 |
{ |
|
1905 |
band& call = *U_NEW(band, 1); |
|
1906 |
CHECK_(lp); |
|
1907 |
band_stack.add(&call); |
|
1908 |
call.le_kind = EK_CALL; |
|
1909 |
call.bn = bands_made++; |
|
1910 |
call.le_body = U_NEW(band*, 2); // fill in later |
|
1911 |
int call_num = 0; |
|
1912 |
lp = parseNumeral(lp, call_num); |
|
1913 |
call.le_back = (call_num <= 0); |
|
1914 |
call_num += curCble; // numeral is self-relative offset |
|
1915 |
call.le_len = call_num; //use le_len as scratch |
|
1916 |
calls_to_link.add(&call); |
|
1917 |
CHECK_(lp); |
|
1918 |
if (*lp++ != ')') { |
|
1919 |
abort("bad call label"); |
|
1920 |
return ""; |
|
1921 |
} |
|
1922 |
} |
|
1923 |
break; |
|
1924 |
case 'K': // reference_type: constant_ref |
|
1925 |
case 'R': // reference_type: schema_ref |
|
1926 |
{ |
|
1927 |
int ixTag = CONSTANT_None; |
|
1928 |
if (lp[-1] == 'K') { |
|
1929 |
switch (*lp++) { |
|
1930 |
case 'I': ixTag = CONSTANT_Integer; break; |
|
1931 |
case 'J': ixTag = CONSTANT_Long; break; |
|
1932 |
case 'F': ixTag = CONSTANT_Float; break; |
|
1933 |
case 'D': ixTag = CONSTANT_Double; break; |
|
1934 |
case 'S': ixTag = CONSTANT_String; break; |
|
12544 | 1935 |
case 'Q': ixTag = CONSTANT_FieldSpecific; break; |
1936 |
||
1937 |
// new in 1.7 |
|
1938 |
case 'M': ixTag = CONSTANT_MethodHandle; break; |
|
1939 |
case 'T': ixTag = CONSTANT_MethodType; break; |
|
1940 |
case 'L': ixTag = CONSTANT_LoadableValue; break; |
|
2 | 1941 |
} |
1942 |
} else { |
|
1943 |
switch (*lp++) { |
|
1944 |
case 'C': ixTag = CONSTANT_Class; break; |
|
1945 |
case 'S': ixTag = CONSTANT_Signature; break; |
|
1946 |
case 'D': ixTag = CONSTANT_NameandType; break; |
|
1947 |
case 'F': ixTag = CONSTANT_Fieldref; break; |
|
1948 |
case 'M': ixTag = CONSTANT_Methodref; break; |
|
1949 |
case 'I': ixTag = CONSTANT_InterfaceMethodref; break; |
|
1950 |
case 'U': ixTag = CONSTANT_Utf8; break; //utf8_ref |
|
1951 |
case 'Q': ixTag = CONSTANT_All; break; //untyped_ref |
|
12544 | 1952 |
|
1953 |
// new in 1.7 |
|
1954 |
case 'Y': ixTag = CONSTANT_InvokeDynamic; break; |
|
1955 |
case 'B': ixTag = CONSTANT_BootstrapMethod; break; |
|
1956 |
case 'N': ixTag = CONSTANT_AnyMember; break; |
|
2 | 1957 |
} |
1958 |
} |
|
1959 |
if (ixTag == CONSTANT_None) { |
|
1960 |
abort("bad reference layout"); |
|
1961 |
break; |
|
1962 |
} |
|
1963 |
bool nullOK = false; |
|
1964 |
if (*lp == 'N') { |
|
1965 |
nullOK = true; |
|
1966 |
lp++; |
|
1967 |
} |
|
1968 |
lp = parseIntLayout(lp, b, EK_REF); |
|
1969 |
b->defc = coding::findBySpec(UNSIGNED5_spec); |
|
1970 |
b->initRef(ixTag, nullOK); |
|
1971 |
} |
|
1972 |
break; |
|
1973 |
case '[': |
|
1974 |
{ |
|
1975 |
// [callable1][callable2]... |
|
1976 |
if (!top_level) { |
|
1977 |
abort("bad nested callable"); |
|
1978 |
break; |
|
1979 |
} |
|
1980 |
curCble += 1; |
|
1981 |
NOT_PRODUCT(int call_num = band_stack.length() - bs_base); |
|
1982 |
band& cble = *U_NEW(band, 1); |
|
1983 |
CHECK_(lp); |
|
1984 |
band_stack.add(&cble); |
|
1985 |
cble.le_kind = EK_CBLE; |
|
1986 |
NOT_PRODUCT(cble.le_len = call_num); |
|
1987 |
cble.bn = bands_made++; |
|
1988 |
lp = parseLayout(lp, cble.le_body, curCble); |
|
1989 |
} |
|
1990 |
break; |
|
1991 |
case ']': |
|
1992 |
// Hit a closing brace. This ends whatever body we were in. |
|
1993 |
done = true; |
|
1994 |
break; |
|
1995 |
case '\0': |
|
1996 |
// Hit a null. Also ends the (top-level) body. |
|
1997 |
--lp; // back up, so caller can see the null also |
|
1998 |
done = true; |
|
1999 |
break; |
|
2000 |
default: |
|
2001 |
abort("bad layout"); |
|
2002 |
break; |
|
2003 |
} |
|
2004 |
CHECK_(lp); |
|
2005 |
} |
|
2006 |
||
2007 |
// Return the accumulated bands: |
|
2008 |
res = popBody(bs_base); |
|
2009 |
return lp; |
|
2010 |
} |
|
2011 |
||
2012 |
void unpacker::read_attr_defs() { |
|
2013 |
int i; |
|
2014 |
||
2015 |
// Tell each AD which attrc it is and where its fixed flags are: |
|
2016 |
attr_defs[ATTR_CONTEXT_CLASS].attrc = ATTR_CONTEXT_CLASS; |
|
2017 |
attr_defs[ATTR_CONTEXT_CLASS].xxx_flags_hi_bn = e_class_flags_hi; |
|
2018 |
attr_defs[ATTR_CONTEXT_FIELD].attrc = ATTR_CONTEXT_FIELD; |
|
2019 |
attr_defs[ATTR_CONTEXT_FIELD].xxx_flags_hi_bn = e_field_flags_hi; |
|
2020 |
attr_defs[ATTR_CONTEXT_METHOD].attrc = ATTR_CONTEXT_METHOD; |
|
2021 |
attr_defs[ATTR_CONTEXT_METHOD].xxx_flags_hi_bn = e_method_flags_hi; |
|
2022 |
attr_defs[ATTR_CONTEXT_CODE].attrc = ATTR_CONTEXT_CODE; |
|
2023 |
attr_defs[ATTR_CONTEXT_CODE].xxx_flags_hi_bn = e_code_flags_hi; |
|
2024 |
||
2025 |
// Decide whether bands for the optional high flag words are present. |
|
2026 |
attr_defs[ATTR_CONTEXT_CLASS] |
|
12544 | 2027 |
.setHaveLongFlags(testBit(archive_options, AO_HAVE_CLASS_FLAGS_HI)); |
2 | 2028 |
attr_defs[ATTR_CONTEXT_FIELD] |
12544 | 2029 |
.setHaveLongFlags(testBit(archive_options, AO_HAVE_FIELD_FLAGS_HI)); |
2 | 2030 |
attr_defs[ATTR_CONTEXT_METHOD] |
12544 | 2031 |
.setHaveLongFlags(testBit(archive_options, AO_HAVE_METHOD_FLAGS_HI)); |
2 | 2032 |
attr_defs[ATTR_CONTEXT_CODE] |
12544 | 2033 |
.setHaveLongFlags(testBit(archive_options, AO_HAVE_CODE_FLAGS_HI)); |
2 | 2034 |
|
2035 |
// Set up built-in attrs. |
|
2036 |
// (The simple ones are hard-coded. The metadata layouts are not.) |
|
2037 |
const char* md_layout = ( |
|
2038 |
// parameter annotations: |
|
2039 |
#define MDL0 \ |
|
2040 |
"[NB[(1)]]" |
|
2041 |
MDL0 |
|
2042 |
// annotations: |
|
2043 |
#define MDL1 \ |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2044 |
"[NH[(1)]]" |
2 | 2045 |
MDL1 |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2046 |
#define MDL2 \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2047 |
"[RSHNH[RUH(1)]]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2048 |
MDL2 |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2049 |
// element_value: |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2050 |
#define MDL3 \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2051 |
"[TB" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2052 |
"(66,67,73,83,90)[KIH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2053 |
"(68)[KDH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2054 |
"(70)[KFH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2055 |
"(74)[KJH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2056 |
"(99)[RSH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2057 |
"(101)[RSHRUH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2058 |
"(115)[RUH]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2059 |
"(91)[NH[(0)]]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2060 |
"(64)[" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2061 |
/* nested annotation: */ \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2062 |
"RSH" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2063 |
"NH[RUH(0)]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2064 |
"]" \ |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2065 |
"()[]" \ |
2 | 2066 |
"]" |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2067 |
MDL3 |
2 | 2068 |
); |
2069 |
||
2070 |
const char* md_layout_P = md_layout; |
|
2071 |
const char* md_layout_A = md_layout+strlen(MDL0); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2072 |
const char* md_layout_V = md_layout+strlen(MDL0 MDL1 MDL2); |
2 | 2073 |
assert(0 == strncmp(&md_layout_A[-3], ")]][", 4)); |
2074 |
assert(0 == strncmp(&md_layout_V[-3], ")]][", 4)); |
|
2075 |
||
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2076 |
const char* type_md_layout( |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2077 |
"[NH[(1)(2)(3)]]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2078 |
// target-type + target_info |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2079 |
"[TB" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2080 |
"(0,1)[B]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2081 |
"(16)[FH]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2082 |
"(17,18)[BB]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2083 |
"(19,20,21)[]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2084 |
"(22)[B]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2085 |
"(23)[H]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2086 |
"(64,65)[NH[PHOHH]]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2087 |
"(66)[H]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2088 |
"(67,68,69,70)[PH]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2089 |
"(71,72,73,74,75)[PHB]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2090 |
"()[]]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2091 |
// target-path |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2092 |
"[NB[BB]]" |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2093 |
// annotation + element_value |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2094 |
MDL2 |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2095 |
MDL3 |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2096 |
); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2097 |
|
2 | 2098 |
for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) { |
2099 |
attr_definitions& ad = attr_defs[i]; |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2100 |
if (i != ATTR_CONTEXT_CODE) { |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2101 |
ad.defineLayout(X_ATTR_RuntimeVisibleAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2102 |
"RuntimeVisibleAnnotations", md_layout_A); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2103 |
ad.defineLayout(X_ATTR_RuntimeInvisibleAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2104 |
"RuntimeInvisibleAnnotations", md_layout_A); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2105 |
if (i == ATTR_CONTEXT_METHOD) { |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2106 |
ad.defineLayout(METHOD_ATTR_RuntimeVisibleParameterAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2107 |
"RuntimeVisibleParameterAnnotations", md_layout_P); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2108 |
ad.defineLayout(METHOD_ATTR_RuntimeInvisibleParameterAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2109 |
"RuntimeInvisibleParameterAnnotations", md_layout_P); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2110 |
ad.defineLayout(METHOD_ATTR_AnnotationDefault, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2111 |
"AnnotationDefault", md_layout_V); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2112 |
} |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2113 |
} |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2114 |
ad.defineLayout(X_ATTR_RuntimeVisibleTypeAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2115 |
"RuntimeVisibleTypeAnnotations", type_md_layout); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2116 |
ad.defineLayout(X_ATTR_RuntimeInvisibleTypeAnnotations, |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2117 |
"RuntimeInvisibleTypeAnnotations", type_md_layout); |
2 | 2118 |
} |
2119 |
||
2120 |
attr_definition_headers.readData(attr_definition_count); |
|
2121 |
attr_definition_name.readData(attr_definition_count); |
|
2122 |
attr_definition_layout.readData(attr_definition_count); |
|
2123 |
||
2124 |
CHECK; |
|
2125 |
||
2126 |
// Initialize correct predef bits, to distinguish predefs from new defs. |
|
2127 |
#define ORBIT(n,s) |((julong)1<<n) |
|
2128 |
attr_defs[ATTR_CONTEXT_CLASS].predef |
|
2129 |
= (0 X_ATTR_DO(ORBIT) CLASS_ATTR_DO(ORBIT)); |
|
2130 |
attr_defs[ATTR_CONTEXT_FIELD].predef |
|
2131 |
= (0 X_ATTR_DO(ORBIT) FIELD_ATTR_DO(ORBIT)); |
|
2132 |
attr_defs[ATTR_CONTEXT_METHOD].predef |
|
2133 |
= (0 X_ATTR_DO(ORBIT) METHOD_ATTR_DO(ORBIT)); |
|
2134 |
attr_defs[ATTR_CONTEXT_CODE].predef |
|
2135 |
= (0 O_ATTR_DO(ORBIT) CODE_ATTR_DO(ORBIT)); |
|
2136 |
#undef ORBIT |
|
2137 |
// Clear out the redef bits, folding them back into predef. |
|
2138 |
for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) { |
|
2139 |
attr_defs[i].predef |= attr_defs[i].redef; |
|
2140 |
attr_defs[i].redef = 0; |
|
2141 |
} |
|
2142 |
||
2143 |
// Now read the transmitted locally defined attrs. |
|
2144 |
// This will set redef bits again. |
|
2145 |
for (i = 0; i < attr_definition_count; i++) { |
|
2146 |
int header = attr_definition_headers.getByte(); |
|
2147 |
int attrc = ADH_BYTE_CONTEXT(header); |
|
2148 |
int idx = ADH_BYTE_INDEX(header); |
|
2149 |
entry* name = attr_definition_name.getRef(); |
|
16075 | 2150 |
CHECK; |
2 | 2151 |
entry* layout = attr_definition_layout.getRef(); |
2152 |
CHECK; |
|
2153 |
attr_defs[attrc].defineLayout(idx, name, layout->value.b.strval()); |
|
2154 |
} |
|
2155 |
} |
|
2156 |
||
2157 |
#define NO_ENTRY_YET ((entry*)-1) |
|
2158 |
||
2159 |
static bool isDigitString(bytes& x, int beg, int end) { |
|
2160 |
if (beg == end) return false; // null string |
|
2161 |
byte* xptr = x.ptr; |
|
2162 |
for (int i = beg; i < end; i++) { |
|
2163 |
char ch = xptr[i]; |
|
2164 |
if (!(ch >= '0' && ch <= '9')) return false; |
|
2165 |
} |
|
2166 |
return true; |
|
2167 |
} |
|
2168 |
||
2169 |
enum { // constants for parsing class names |
|
2170 |
SLASH_MIN = '.', |
|
2171 |
SLASH_MAX = '/', |
|
2172 |
DOLLAR_MIN = 0, |
|
2173 |
DOLLAR_MAX = '-' |
|
2174 |
}; |
|
2175 |
||
2176 |
static int lastIndexOf(int chmin, int chmax, bytes& x, int pos) { |
|
2177 |
byte* ptr = x.ptr; |
|
2178 |
for (byte* cp = ptr + pos; --cp >= ptr; ) { |
|
2179 |
assert(x.inBounds(cp)); |
|
2180 |
if (*cp >= chmin && *cp <= chmax) |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2181 |
return (int)(cp - ptr); |
2 | 2182 |
} |
2183 |
return -1; |
|
2184 |
} |
|
2185 |
||
2186 |
maybe_inline |
|
2187 |
inner_class* cpool::getIC(entry* inner) { |
|
2188 |
if (inner == null) return null; |
|
2189 |
assert(inner->tag == CONSTANT_Class); |
|
2190 |
if (inner->inord == NO_INORD) return null; |
|
2191 |
inner_class* ic = ic_index[inner->inord]; |
|
2192 |
assert(ic == null || ic->inner == inner); |
|
2193 |
return ic; |
|
2194 |
} |
|
2195 |
||
2196 |
maybe_inline |
|
2197 |
inner_class* cpool::getFirstChildIC(entry* outer) { |
|
2198 |
if (outer == null) return null; |
|
2199 |
assert(outer->tag == CONSTANT_Class); |
|
2200 |
if (outer->inord == NO_INORD) return null; |
|
2201 |
inner_class* ic = ic_child_index[outer->inord]; |
|
2202 |
assert(ic == null || ic->outer == outer); |
|
2203 |
return ic; |
|
2204 |
} |
|
2205 |
||
2206 |
maybe_inline |
|
2207 |
inner_class* cpool::getNextChildIC(inner_class* child) { |
|
2208 |
inner_class* ic = child->next_sibling; |
|
2209 |
assert(ic == null || ic->outer == child->outer); |
|
2210 |
return ic; |
|
2211 |
} |
|
2212 |
||
2213 |
void unpacker::read_ics() { |
|
2214 |
int i; |
|
2215 |
int index_size = cp.tag_count[CONSTANT_Class]; |
|
2216 |
inner_class** ic_index = U_NEW(inner_class*, index_size); |
|
2217 |
inner_class** ic_child_index = U_NEW(inner_class*, index_size); |
|
2218 |
cp.ic_index = ic_index; |
|
2219 |
cp.ic_child_index = ic_child_index; |
|
2220 |
ics = U_NEW(inner_class, ic_count); |
|
2221 |
ic_this_class.readData(ic_count); |
|
2222 |
ic_flags.readData(ic_count); |
|
2223 |
CHECK; |
|
2224 |
// Scan flags to get count of long-form bands. |
|
2225 |
int long_forms = 0; |
|
2226 |
for (i = 0; i < ic_count; i++) { |
|
2227 |
int flags = ic_flags.getInt(); // may be long form! |
|
2228 |
if ((flags & ACC_IC_LONG_FORM) != 0) { |
|
2229 |
long_forms += 1; |
|
2230 |
ics[i].name = NO_ENTRY_YET; |
|
2231 |
} |
|
2232 |
flags &= ~ACC_IC_LONG_FORM; |
|
2233 |
entry* inner = ic_this_class.getRef(); |
|
2234 |
CHECK; |
|
2235 |
uint inord = inner->inord; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2236 |
assert(inord < (uint)cp.tag_count[CONSTANT_Class]); |
2 | 2237 |
if (ic_index[inord] != null) { |
2238 |
abort("identical inner class"); |
|
2239 |
break; |
|
2240 |
} |
|
2241 |
ic_index[inord] = &ics[i]; |
|
2242 |
ics[i].inner = inner; |
|
2243 |
ics[i].flags = flags; |
|
2244 |
assert(cp.getIC(inner) == &ics[i]); |
|
2245 |
} |
|
2246 |
CHECK; |
|
2247 |
//ic_this_class.done(); |
|
2248 |
//ic_flags.done(); |
|
2249 |
ic_outer_class.readData(long_forms); |
|
2250 |
ic_name.readData(long_forms); |
|
2251 |
for (i = 0; i < ic_count; i++) { |
|
2252 |
if (ics[i].name == NO_ENTRY_YET) { |
|
2253 |
// Long form. |
|
2254 |
ics[i].outer = ic_outer_class.getRefN(); |
|
16075 | 2255 |
CHECK; |
2 | 2256 |
ics[i].name = ic_name.getRefN(); |
16075 | 2257 |
CHECK; |
2 | 2258 |
} else { |
2259 |
// Fill in outer and name based on inner. |
|
2260 |
bytes& n = ics[i].inner->value.b; |
|
2261 |
bytes pkgOuter; |
|
2262 |
bytes number; |
|
2263 |
bytes name; |
|
2264 |
// Parse n into pkgOuter and name (and number). |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2265 |
PRINTCR((5, "parse short IC name %s", n.ptr)); |
2 | 2266 |
int dollar1, dollar2; // pointers to $ in the pattern |
2267 |
// parse n = (<pkg>/)*<outer>($<number>)?($<name>)? |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2268 |
int nlen = (int)n.len; |
2 | 2269 |
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1; |
2270 |
dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen); |
|
2271 |
if (dollar2 < 0) { |
|
2272 |
abort(); |
|
2273 |
return; |
|
2274 |
} |
|
2275 |
assert(dollar2 >= pkglen); |
|
2276 |
if (isDigitString(n, dollar2+1, nlen)) { |
|
2277 |
// n = (<pkg>/)*<outer>$<number> |
|
2278 |
number = n.slice(dollar2+1, nlen); |
|
2279 |
name.set(null,0); |
|
2280 |
dollar1 = dollar2; |
|
2281 |
} else if (pkglen < (dollar1 |
|
2282 |
= lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, dollar2-1)) |
|
2283 |
&& isDigitString(n, dollar1+1, dollar2)) { |
|
2284 |
// n = (<pkg>/)*<outer>$<number>$<name> |
|
2285 |
number = n.slice(dollar1+1, dollar2); |
|
2286 |
name = n.slice(dollar2+1, nlen); |
|
2287 |
} else { |
|
2288 |
// n = (<pkg>/)*<outer>$<name> |
|
2289 |
dollar1 = dollar2; |
|
2290 |
number.set(null,0); |
|
2291 |
name = n.slice(dollar2+1, nlen); |
|
2292 |
} |
|
2293 |
if (number.ptr == null) |
|
2294 |
pkgOuter = n.slice(0, dollar1); |
|
2295 |
else |
|
2296 |
pkgOuter.set(null,0); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2297 |
PRINTCR((5,"=> %s$ 0%s $%s", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2298 |
pkgOuter.string(), number.string(), name.string())); |
2 | 2299 |
|
2300 |
if (pkgOuter.ptr != null) |
|
2301 |
ics[i].outer = cp.ensureClass(pkgOuter); |
|
2302 |
||
2303 |
if (name.ptr != null) |
|
2304 |
ics[i].name = cp.ensureUtf8(name); |
|
2305 |
} |
|
2306 |
||
2307 |
// update child/sibling list |
|
2308 |
if (ics[i].outer != null) { |
|
2309 |
uint outord = ics[i].outer->inord; |
|
2310 |
if (outord != NO_INORD) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2311 |
assert(outord < (uint)cp.tag_count[CONSTANT_Class]); |
2 | 2312 |
ics[i].next_sibling = ic_child_index[outord]; |
2313 |
ic_child_index[outord] = &ics[i]; |
|
2314 |
} |
|
2315 |
} |
|
2316 |
} |
|
2317 |
//ic_outer_class.done(); |
|
2318 |
//ic_name.done(); |
|
2319 |
} |
|
2320 |
||
2321 |
void unpacker::read_classes() { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2322 |
PRINTCR((1," ...scanning %d classes...", class_count)); |
2 | 2323 |
class_this.readData(class_count); |
2324 |
class_super.readData(class_count); |
|
2325 |
class_interface_count.readData(class_count); |
|
2326 |
class_interface.readData(class_interface_count.getIntTotal()); |
|
2327 |
||
2328 |
CHECK; |
|
2329 |
||
2330 |
#if 0 |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2331 |
int i; |
2 | 2332 |
// Make a little mark on super-classes. |
2333 |
for (i = 0; i < class_count; i++) { |
|
2334 |
entry* e = class_super.getRefN(); |
|
2335 |
if (e != null) e->bits |= entry::EB_SUPER; |
|
2336 |
} |
|
2337 |
class_super.rewind(); |
|
2338 |
#endif |
|
2339 |
||
2340 |
// Members. |
|
2341 |
class_field_count.readData(class_count); |
|
2342 |
class_method_count.readData(class_count); |
|
2343 |
||
2344 |
CHECK; |
|
2345 |
||
2346 |
int field_count = class_field_count.getIntTotal(); |
|
2347 |
int method_count = class_method_count.getIntTotal(); |
|
2348 |
||
2349 |
field_descr.readData(field_count); |
|
2350 |
read_attrs(ATTR_CONTEXT_FIELD, field_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2351 |
CHECK; |
2 | 2352 |
|
2353 |
method_descr.readData(method_count); |
|
2354 |
read_attrs(ATTR_CONTEXT_METHOD, method_count); |
|
2355 |
||
2356 |
CHECK; |
|
2357 |
||
2358 |
read_attrs(ATTR_CONTEXT_CLASS, class_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2359 |
CHECK; |
2 | 2360 |
|
2361 |
read_code_headers(); |
|
2362 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2363 |
PRINTCR((1,"scanned %d classes, %d fields, %d methods, %d code headers", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2364 |
class_count, field_count, method_count, code_count)); |
2 | 2365 |
} |
2366 |
||
2367 |
maybe_inline |
|
2368 |
int unpacker::attr_definitions::predefCount(uint idx) { |
|
2369 |
return isPredefined(idx) ? flag_count[idx] : 0; |
|
2370 |
} |
|
2371 |
||
2372 |
void unpacker::read_attrs(int attrc, int obj_count) { |
|
2373 |
attr_definitions& ad = attr_defs[attrc]; |
|
2374 |
assert(ad.attrc == attrc); |
|
2375 |
||
2376 |
int i, idx, count; |
|
2377 |
||
2378 |
CHECK; |
|
2379 |
||
2380 |
bool haveLongFlags = ad.haveLongFlags(); |
|
2381 |
||
2382 |
band& xxx_flags_hi = ad.xxx_flags_hi(); |
|
2383 |
assert(endsWith(xxx_flags_hi.name, "_flags_hi")); |
|
2384 |
if (haveLongFlags) |
|
2385 |
xxx_flags_hi.readData(obj_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2386 |
CHECK; |
2 | 2387 |
|
2388 |
band& xxx_flags_lo = ad.xxx_flags_lo(); |
|
2389 |
assert(endsWith(xxx_flags_lo.name, "_flags_lo")); |
|
2390 |
xxx_flags_lo.readData(obj_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2391 |
CHECK; |
2 | 2392 |
|
2393 |
// pre-scan flags, counting occurrences of each index bit |
|
2394 |
julong indexMask = ad.flagIndexMask(); // which flag bits are index bits? |
|
2395 |
for (i = 0; i < obj_count; i++) { |
|
2396 |
julong indexBits = xxx_flags_hi.getLong(xxx_flags_lo, haveLongFlags); |
|
2397 |
if ((indexBits & ~indexMask) > (ushort)-1) { |
|
2398 |
abort("undefined attribute flag bit"); |
|
2399 |
return; |
|
2400 |
} |
|
2401 |
indexBits &= indexMask; // ignore classfile flag bits |
|
2402 |
for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2403 |
ad.flag_count[idx] += (int)(indexBits & 1); |
2 | 2404 |
} |
2405 |
} |
|
2406 |
// we'll scan these again later for output: |
|
2407 |
xxx_flags_lo.rewind(); |
|
2408 |
xxx_flags_hi.rewind(); |
|
2409 |
||
2410 |
band& xxx_attr_count = ad.xxx_attr_count(); |
|
2411 |
assert(endsWith(xxx_attr_count.name, "_attr_count")); |
|
2412 |
// There is one count element for each 1<<16 bit set in flags: |
|
2413 |
xxx_attr_count.readData(ad.predefCount(X_ATTR_OVERFLOW)); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2414 |
CHECK; |
2 | 2415 |
|
2416 |
band& xxx_attr_indexes = ad.xxx_attr_indexes(); |
|
2417 |
assert(endsWith(xxx_attr_indexes.name, "_attr_indexes")); |
|
2418 |
int overflowIndexCount = xxx_attr_count.getIntTotal(); |
|
2419 |
xxx_attr_indexes.readData(overflowIndexCount); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2420 |
CHECK; |
2 | 2421 |
// pre-scan attr indexes, counting occurrences of each value |
2422 |
for (i = 0; i < overflowIndexCount; i++) { |
|
2423 |
idx = xxx_attr_indexes.getInt(); |
|
2424 |
if (!ad.isIndex(idx)) { |
|
2425 |
abort("attribute index out of bounds"); |
|
2426 |
return; |
|
2427 |
} |
|
2428 |
ad.getCount(idx) += 1; |
|
2429 |
} |
|
2430 |
xxx_attr_indexes.rewind(); // we'll scan it again later for output |
|
2431 |
||
2432 |
// We will need a backward call count for each used backward callable. |
|
2433 |
int backwardCounts = 0; |
|
2434 |
for (idx = 0; idx < ad.layouts.length(); idx++) { |
|
2435 |
layout_definition* lo = ad.getLayout(idx); |
|
2436 |
if (lo != null && ad.getCount(idx) != 0) { |
|
2437 |
// Build the bands lazily, only when they are used. |
|
2438 |
band** bands = ad.buildBands(lo); |
|
2439 |
CHECK; |
|
2440 |
if (lo->hasCallables()) { |
|
2441 |
for (i = 0; bands[i] != null; i++) { |
|
2442 |
if (bands[i]->le_back) { |
|
2443 |
assert(bands[i]->le_kind == EK_CBLE); |
|
2444 |
backwardCounts += 1; |
|
2445 |
} |
|
2446 |
} |
|
2447 |
} |
|
2448 |
} |
|
2449 |
} |
|
2450 |
ad.xxx_attr_calls().readData(backwardCounts); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2451 |
CHECK; |
2 | 2452 |
|
2453 |
// Read built-in bands. |
|
2454 |
// Mostly, these are hand-coded equivalents to readBandData(). |
|
2455 |
switch (attrc) { |
|
2456 |
case ATTR_CONTEXT_CLASS: |
|
2457 |
||
2458 |
count = ad.predefCount(CLASS_ATTR_SourceFile); |
|
2459 |
class_SourceFile_RUN.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2460 |
CHECK; |
2 | 2461 |
|
2462 |
count = ad.predefCount(CLASS_ATTR_EnclosingMethod); |
|
2463 |
class_EnclosingMethod_RC.readData(count); |
|
2464 |
class_EnclosingMethod_RDN.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2465 |
CHECK; |
2 | 2466 |
|
2467 |
count = ad.predefCount(X_ATTR_Signature); |
|
2468 |
class_Signature_RS.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2469 |
CHECK; |
2 | 2470 |
|
2471 |
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations); |
|
2472 |
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2473 |
CHECK; |
2 | 2474 |
|
2475 |
count = ad.predefCount(CLASS_ATTR_InnerClasses); |
|
2476 |
class_InnerClasses_N.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2477 |
CHECK; |
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2478 |
|
2 | 2479 |
count = class_InnerClasses_N.getIntTotal(); |
2480 |
class_InnerClasses_RC.readData(count); |
|
2481 |
class_InnerClasses_F.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2482 |
CHECK; |
2 | 2483 |
// Drop remaining columns wherever flags are zero: |
2484 |
count -= class_InnerClasses_F.getIntCount(0); |
|
2485 |
class_InnerClasses_outer_RCN.readData(count); |
|
2486 |
class_InnerClasses_name_RUN.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2487 |
CHECK; |
2 | 2488 |
|
2489 |
count = ad.predefCount(CLASS_ATTR_ClassFile_version); |
|
2490 |
class_ClassFile_version_minor_H.readData(count); |
|
2491 |
class_ClassFile_version_major_H.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2492 |
CHECK; |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2493 |
|
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2494 |
ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2495 |
ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2496 |
CHECK; |
2 | 2497 |
break; |
2498 |
||
2499 |
case ATTR_CONTEXT_FIELD: |
|
2500 |
||
2501 |
count = ad.predefCount(FIELD_ATTR_ConstantValue); |
|
2502 |
field_ConstantValue_KQ.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2503 |
CHECK; |
2 | 2504 |
|
2505 |
count = ad.predefCount(X_ATTR_Signature); |
|
2506 |
field_Signature_RS.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2507 |
CHECK; |
2 | 2508 |
|
2509 |
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations); |
|
2510 |
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2511 |
CHECK; |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2512 |
|
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2513 |
ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2514 |
ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2515 |
CHECK; |
2 | 2516 |
break; |
2517 |
||
2518 |
case ATTR_CONTEXT_METHOD: |
|
2519 |
||
2520 |
code_count = ad.predefCount(METHOD_ATTR_Code); |
|
2521 |
// Code attrs are handled very specially below... |
|
2522 |
||
2523 |
count = ad.predefCount(METHOD_ATTR_Exceptions); |
|
2524 |
method_Exceptions_N.readData(count); |
|
2525 |
count = method_Exceptions_N.getIntTotal(); |
|
2526 |
method_Exceptions_RC.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2527 |
CHECK; |
2 | 2528 |
|
2529 |
count = ad.predefCount(X_ATTR_Signature); |
|
2530 |
method_Signature_RS.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2531 |
CHECK; |
2 | 2532 |
|
2533 |
ad.readBandData(X_ATTR_RuntimeVisibleAnnotations); |
|
2534 |
ad.readBandData(X_ATTR_RuntimeInvisibleAnnotations); |
|
2535 |
ad.readBandData(METHOD_ATTR_RuntimeVisibleParameterAnnotations); |
|
2536 |
ad.readBandData(METHOD_ATTR_RuntimeInvisibleParameterAnnotations); |
|
2537 |
ad.readBandData(METHOD_ATTR_AnnotationDefault); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2538 |
CHECK; |
15261 | 2539 |
|
2540 |
count = ad.predefCount(METHOD_ATTR_MethodParameters); |
|
2541 |
method_MethodParameters_NB.readData(count); |
|
2542 |
count = method_MethodParameters_NB.getIntTotal(); |
|
2543 |
method_MethodParameters_name_RUN.readData(count); |
|
16013
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
15652
diff
changeset
|
2544 |
method_MethodParameters_flag_FH.readData(count); |
15261 | 2545 |
CHECK; |
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2546 |
|
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2547 |
ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2548 |
ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2549 |
CHECK; |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2550 |
|
2 | 2551 |
break; |
2552 |
||
2553 |
case ATTR_CONTEXT_CODE: |
|
2554 |
// (keep this code aligned with its brother in unpacker::write_attrs) |
|
2555 |
count = ad.predefCount(CODE_ATTR_StackMapTable); |
|
2556 |
// disable this feature in old archives! |
|
2557 |
if (count != 0 && majver < JAVA6_PACKAGE_MAJOR_VERSION) { |
|
2558 |
abort("undefined StackMapTable attribute (old archive format)"); |
|
2559 |
return; |
|
2560 |
} |
|
2561 |
code_StackMapTable_N.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2562 |
CHECK; |
2 | 2563 |
count = code_StackMapTable_N.getIntTotal(); |
2564 |
code_StackMapTable_frame_T.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2565 |
CHECK; |
2 | 2566 |
// the rest of it depends in a complicated way on frame tags |
2567 |
{ |
|
2568 |
int fat_frame_count = 0; |
|
2569 |
int offset_count = 0; |
|
2570 |
int type_count = 0; |
|
2571 |
for (int k = 0; k < count; k++) { |
|
2572 |
int tag = code_StackMapTable_frame_T.getByte(); |
|
2573 |
if (tag <= 127) { |
|
2574 |
// (64-127) [(2)] |
|
2575 |
if (tag >= 64) type_count++; |
|
2576 |
} else if (tag <= 251) { |
|
2577 |
// (247) [(1)(2)] |
|
2578 |
// (248-251) [(1)] |
|
2579 |
if (tag >= 247) offset_count++; |
|
2580 |
if (tag == 247) type_count++; |
|
2581 |
} else if (tag <= 254) { |
|
2582 |
// (252) [(1)(2)] |
|
2583 |
// (253) [(1)(2)(2)] |
|
2584 |
// (254) [(1)(2)(2)(2)] |
|
2585 |
offset_count++; |
|
2586 |
type_count += (tag - 251); |
|
2587 |
} else { |
|
2588 |
// (255) [(1)NH[(2)]NH[(2)]] |
|
2589 |
fat_frame_count++; |
|
2590 |
} |
|
2591 |
} |
|
2592 |
||
2593 |
// done pre-scanning frame tags: |
|
2594 |
code_StackMapTable_frame_T.rewind(); |
|
2595 |
||
2596 |
// deal completely with fat frames: |
|
2597 |
offset_count += fat_frame_count; |
|
2598 |
code_StackMapTable_local_N.readData(fat_frame_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2599 |
CHECK; |
2 | 2600 |
type_count += code_StackMapTable_local_N.getIntTotal(); |
2601 |
code_StackMapTable_stack_N.readData(fat_frame_count); |
|
2602 |
type_count += code_StackMapTable_stack_N.getIntTotal(); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2603 |
CHECK; |
2 | 2604 |
// read the rest: |
2605 |
code_StackMapTable_offset.readData(offset_count); |
|
2606 |
code_StackMapTable_T.readData(type_count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2607 |
CHECK; |
2 | 2608 |
// (7) [RCH] |
2609 |
count = code_StackMapTable_T.getIntCount(7); |
|
2610 |
code_StackMapTable_RC.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2611 |
CHECK; |
2 | 2612 |
// (8) [PH] |
2613 |
count = code_StackMapTable_T.getIntCount(8); |
|
2614 |
code_StackMapTable_P.readData(count); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2615 |
CHECK; |
2 | 2616 |
} |
2617 |
||
2618 |
count = ad.predefCount(CODE_ATTR_LineNumberTable); |
|
2619 |
code_LineNumberTable_N.readData(count); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2620 |
CHECK; |
2 | 2621 |
count = code_LineNumberTable_N.getIntTotal(); |
2622 |
code_LineNumberTable_bci_P.readData(count); |
|
2623 |
code_LineNumberTable_line.readData(count); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2624 |
CHECK; |
2 | 2625 |
|
2626 |
count = ad.predefCount(CODE_ATTR_LocalVariableTable); |
|
2627 |
code_LocalVariableTable_N.readData(count); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2628 |
CHECK; |
2 | 2629 |
count = code_LocalVariableTable_N.getIntTotal(); |
2630 |
code_LocalVariableTable_bci_P.readData(count); |
|
2631 |
code_LocalVariableTable_span_O.readData(count); |
|
2632 |
code_LocalVariableTable_name_RU.readData(count); |
|
2633 |
code_LocalVariableTable_type_RS.readData(count); |
|
2634 |
code_LocalVariableTable_slot.readData(count); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2635 |
CHECK; |
2 | 2636 |
|
2637 |
count = ad.predefCount(CODE_ATTR_LocalVariableTypeTable); |
|
2638 |
code_LocalVariableTypeTable_N.readData(count); |
|
2639 |
count = code_LocalVariableTypeTable_N.getIntTotal(); |
|
2640 |
code_LocalVariableTypeTable_bci_P.readData(count); |
|
2641 |
code_LocalVariableTypeTable_span_O.readData(count); |
|
2642 |
code_LocalVariableTypeTable_name_RU.readData(count); |
|
2643 |
code_LocalVariableTypeTable_type_RS.readData(count); |
|
2644 |
code_LocalVariableTypeTable_slot.readData(count); |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2645 |
CHECK; |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2646 |
|
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2647 |
ad.readBandData(X_ATTR_RuntimeVisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2648 |
ad.readBandData(X_ATTR_RuntimeInvisibleTypeAnnotations); |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2649 |
CHECK; |
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
2650 |
|
2 | 2651 |
break; |
2652 |
} |
|
2653 |
||
2654 |
// Read compressor-defined bands. |
|
2655 |
for (idx = 0; idx < ad.layouts.length(); idx++) { |
|
2656 |
if (ad.getLayout(idx) == null) |
|
2657 |
continue; // none at this fixed index <32 |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2658 |
if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) |
2 | 2659 |
continue; // already handled |
2660 |
if (ad.getCount(idx) == 0) |
|
2661 |
continue; // no attributes of this type (then why transmit layouts?) |
|
2662 |
ad.readBandData(idx); |
|
2663 |
} |
|
2664 |
} |
|
2665 |
||
2666 |
void unpacker::attr_definitions::readBandData(int idx) { |
|
2667 |
int j; |
|
2668 |
uint count = getCount(idx); |
|
2669 |
if (count == 0) return; |
|
2670 |
layout_definition* lo = getLayout(idx); |
|
2671 |
if (lo != null) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2672 |
PRINTCR((1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s", |
2 | 2673 |
count, isRedefined(idx), isPredefined(idx), |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2674 |
ATTR_CONTEXT_NAME[attrc], lo->name)); |
2 | 2675 |
} |
2676 |
bool hasCallables = lo->hasCallables(); |
|
2677 |
band** bands = lo->bands(); |
|
2678 |
if (!hasCallables) { |
|
2679 |
// Read through the rest of the bands in a regular way. |
|
2680 |
readBandData(bands, count); |
|
2681 |
} else { |
|
2682 |
// Deal with the callables. |
|
2683 |
// First set up the forward entry count for each callable. |
|
2684 |
// This is stored on band::length of the callable. |
|
2685 |
bands[0]->expectMoreLength(count); |
|
2686 |
for (j = 0; bands[j] != null; j++) { |
|
2687 |
band& j_cble = *bands[j]; |
|
2688 |
assert(j_cble.le_kind == EK_CBLE); |
|
2689 |
if (j_cble.le_back) { |
|
2690 |
// Add in the predicted effects of backward calls, too. |
|
2691 |
int back_calls = xxx_attr_calls().getInt(); |
|
2692 |
j_cble.expectMoreLength(back_calls); |
|
2693 |
// In a moment, more forward calls may increment j_cble.length. |
|
2694 |
} |
|
2695 |
} |
|
2696 |
// Now consult whichever callables have non-zero entry counts. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2697 |
readBandData(bands, (uint)-1); |
2 | 2698 |
} |
2699 |
} |
|
2700 |
||
2701 |
// Recursive helper to the previous function: |
|
2702 |
void unpacker::attr_definitions::readBandData(band** body, uint count) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2703 |
int j, k; |
2 | 2704 |
for (j = 0; body[j] != null; j++) { |
2705 |
band& b = *body[j]; |
|
2706 |
if (b.defc != null) { |
|
2707 |
// It has data, so read it. |
|
2708 |
b.readData(count); |
|
2709 |
} |
|
2710 |
switch (b.le_kind) { |
|
2711 |
case EK_REPL: |
|
2712 |
{ |
|
2713 |
int reps = b.getIntTotal(); |
|
2714 |
readBandData(b.le_body, reps); |
|
2715 |
} |
|
2716 |
break; |
|
2717 |
case EK_UN: |
|
2718 |
{ |
|
2719 |
int remaining = count; |
|
2720 |
for (k = 0; b.le_body[k] != null; k++) { |
|
2721 |
band& k_case = *b.le_body[k]; |
|
2722 |
int k_count = 0; |
|
2723 |
if (k_case.le_casetags == null) { |
|
2724 |
k_count = remaining; // last (empty) case |
|
2725 |
} else { |
|
2726 |
int* tags = k_case.le_casetags; |
|
2727 |
int ntags = *tags++; // 1st element is length (why not?) |
|
2728 |
while (ntags-- > 0) { |
|
2729 |
int tag = *tags++; |
|
2730 |
k_count += b.getIntCount(tag); |
|
2731 |
} |
|
2732 |
} |
|
2733 |
readBandData(k_case.le_body, k_count); |
|
2734 |
remaining -= k_count; |
|
2735 |
} |
|
2736 |
assert(remaining == 0); |
|
2737 |
} |
|
2738 |
break; |
|
2739 |
case EK_CALL: |
|
2740 |
// Push the count forward, if it is not a backward call. |
|
2741 |
if (!b.le_back) { |
|
2742 |
band& cble = *b.le_body[0]; |
|
2743 |
assert(cble.le_kind == EK_CBLE); |
|
2744 |
cble.expectMoreLength(count); |
|
2745 |
} |
|
2746 |
break; |
|
2747 |
case EK_CBLE: |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2748 |
assert((int)count == -1); // incoming count is meaningless |
2 | 2749 |
k = b.length; |
2750 |
assert(k >= 0); |
|
2751 |
// This is intended and required for non production mode. |
|
2752 |
assert((b.length = -1)); // make it unable to accept more calls now. |
|
2753 |
readBandData(b.le_body, k); |
|
2754 |
break; |
|
2755 |
} |
|
2756 |
} |
|
2757 |
} |
|
2758 |
||
2759 |
static inline |
|
2760 |
band** findMatchingCase(int matchTag, band** cases) { |
|
2761 |
for (int k = 0; cases[k] != null; k++) { |
|
2762 |
band& k_case = *cases[k]; |
|
2763 |
if (k_case.le_casetags != null) { |
|
2764 |
// If it has tags, it must match a tag. |
|
2765 |
int* tags = k_case.le_casetags; |
|
2766 |
int ntags = *tags++; // 1st element is length |
|
2767 |
for (; ntags > 0; ntags--) { |
|
2768 |
int tag = *tags++; |
|
2769 |
if (tag == matchTag) |
|
2770 |
break; |
|
2771 |
} |
|
2772 |
if (ntags == 0) |
|
2773 |
continue; // does not match |
|
2774 |
} |
|
2775 |
return k_case.le_body; |
|
2776 |
} |
|
2777 |
return null; |
|
2778 |
} |
|
2779 |
||
2780 |
// write attribute band data: |
|
2781 |
void unpacker::putlayout(band** body) { |
|
2782 |
int i; |
|
2783 |
int prevBII = -1; |
|
2784 |
int prevBCI = -1; |
|
8779 | 2785 |
if (body == NULL) { |
2786 |
abort("putlayout: unexpected NULL for body"); |
|
2787 |
return; |
|
2788 |
} |
|
2 | 2789 |
for (i = 0; body[i] != null; i++) { |
2790 |
band& b = *body[i]; |
|
2791 |
byte le_kind = b.le_kind; |
|
2792 |
||
2793 |
// Handle scalar part, if any. |
|
2794 |
int x = 0; |
|
2795 |
entry* e = null; |
|
2796 |
if (b.defc != null) { |
|
2797 |
// It has data, so unparse an element. |
|
2798 |
if (b.ixTag != CONSTANT_None) { |
|
2799 |
assert(le_kind == EK_REF); |
|
12544 | 2800 |
if (b.ixTag == CONSTANT_FieldSpecific) |
2 | 2801 |
e = b.getRefUsing(cp.getKQIndex()); |
2802 |
else |
|
2803 |
e = b.getRefN(); |
|
16075 | 2804 |
CHECK; |
2 | 2805 |
switch (b.le_len) { |
2806 |
case 0: break; |
|
2807 |
case 1: putu1ref(e); break; |
|
2808 |
case 2: putref(e); break; |
|
2809 |
case 4: putu2(0); putref(e); break; |
|
2810 |
default: assert(false); |
|
2811 |
} |
|
2812 |
} else { |
|
2813 |
assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN); |
|
2814 |
x = b.getInt(); |
|
2815 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2816 |
assert(!b.le_bci || prevBCI == (int)to_bci(prevBII)); |
2 | 2817 |
switch (b.le_bci) { |
2818 |
case EK_BCI: // PH: transmit R(bci), store bci |
|
2819 |
x = to_bci(prevBII = x); |
|
2820 |
prevBCI = x; |
|
2821 |
break; |
|
2822 |
case EK_BCID: // POH: transmit D(R(bci)), store bci |
|
2823 |
x = to_bci(prevBII += x); |
|
2824 |
prevBCI = x; |
|
2825 |
break; |
|
2826 |
case EK_BCO: // OH: transmit D(R(bci)), store D(bci) |
|
2827 |
x = to_bci(prevBII += x) - prevBCI; |
|
2828 |
prevBCI += x; |
|
2829 |
break; |
|
2830 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
2831 |
assert(!b.le_bci || prevBCI == (int)to_bci(prevBII)); |
2 | 2832 |
|
2833 |
switch (b.le_len) { |
|
2834 |
case 0: break; |
|
2835 |
case 1: putu1(x); break; |
|
2836 |
case 2: putu2(x); break; |
|
2837 |
case 4: putu4(x); break; |
|
2838 |
default: assert(false); |
|
2839 |
} |
|
2840 |
} |
|
2841 |
} |
|
2842 |
||
2843 |
// Handle subparts, if any. |
|
2844 |
switch (le_kind) { |
|
2845 |
case EK_REPL: |
|
2846 |
// x is the repeat count |
|
2847 |
while (x-- > 0) { |
|
2848 |
putlayout(b.le_body); |
|
2849 |
} |
|
2850 |
break; |
|
2851 |
case EK_UN: |
|
2852 |
// x is the tag |
|
2853 |
putlayout(findMatchingCase(x, b.le_body)); |
|
2854 |
break; |
|
2855 |
case EK_CALL: |
|
2856 |
{ |
|
2857 |
band& cble = *b.le_body[0]; |
|
2858 |
assert(cble.le_kind == EK_CBLE); |
|
2859 |
assert(cble.le_len == b.le_len); |
|
2860 |
putlayout(cble.le_body); |
|
2861 |
} |
|
2862 |
break; |
|
2863 |
||
2864 |
#ifndef PRODUCT |
|
2865 |
case EK_CBLE: |
|
2866 |
case EK_CASE: |
|
2867 |
assert(false); // should not reach here |
|
2868 |
#endif |
|
2869 |
} |
|
2870 |
} |
|
2871 |
} |
|
2872 |
||
2873 |
void unpacker::read_files() { |
|
2874 |
file_name.readData(file_count); |
|
12544 | 2875 |
if (testBit(archive_options, AO_HAVE_FILE_SIZE_HI)) |
2 | 2876 |
file_size_hi.readData(file_count); |
2877 |
file_size_lo.readData(file_count); |
|
12544 | 2878 |
if (testBit(archive_options, AO_HAVE_FILE_MODTIME)) |
2 | 2879 |
file_modtime.readData(file_count); |
2880 |
int allFiles = file_count + class_count; |
|
12544 | 2881 |
if (testBit(archive_options, AO_HAVE_FILE_OPTIONS)) { |
2 | 2882 |
file_options.readData(file_count); |
2883 |
// FO_IS_CLASS_STUB might be set, causing overlap between classes and files |
|
2884 |
for (int i = 0; i < file_count; i++) { |
|
2885 |
if ((file_options.getInt() & FO_IS_CLASS_STUB) != 0) { |
|
2886 |
allFiles -= 1; // this one counts as both class and file |
|
2887 |
} |
|
2888 |
} |
|
2889 |
file_options.rewind(); |
|
2890 |
} |
|
2891 |
assert((default_file_options & FO_IS_CLASS_STUB) == 0); |
|
2892 |
files_remaining = allFiles; |
|
2893 |
} |
|
2894 |
||
2895 |
maybe_inline |
|
2896 |
void unpacker::get_code_header(int& max_stack, |
|
2897 |
int& max_na_locals, |
|
2898 |
int& handler_count, |
|
2899 |
int& cflags) { |
|
2900 |
int sc = code_headers.getByte(); |
|
2901 |
if (sc == 0) { |
|
2902 |
max_stack = max_na_locals = handler_count = cflags = -1; |
|
2903 |
return; |
|
2904 |
} |
|
2905 |
// Short code header is the usual case: |
|
2906 |
int nh; |
|
2907 |
int mod; |
|
2908 |
if (sc < 1 + 12*12) { |
|
2909 |
sc -= 1; |
|
2910 |
nh = 0; |
|
2911 |
mod = 12; |
|
2912 |
} else if (sc < 1 + 12*12 + 8*8) { |
|
2913 |
sc -= 1 + 12*12; |
|
2914 |
nh = 1; |
|
2915 |
mod = 8; |
|
2916 |
} else { |
|
2917 |
assert(sc < 1 + 12*12 + 8*8 + 7*7); |
|
2918 |
sc -= 1 + 12*12 + 8*8; |
|
2919 |
nh = 2; |
|
2920 |
mod = 7; |
|
2921 |
} |
|
2922 |
max_stack = sc % mod; |
|
2923 |
max_na_locals = sc / mod; // caller must add static, siglen |
|
2924 |
handler_count = nh; |
|
12544 | 2925 |
if (testBit(archive_options, AO_HAVE_ALL_CODE_FLAGS)) |
2 | 2926 |
cflags = -1; |
2927 |
else |
|
2928 |
cflags = 0; // this one has no attributes |
|
2929 |
} |
|
2930 |
||
2931 |
// Cf. PackageReader.readCodeHeaders |
|
2932 |
void unpacker::read_code_headers() { |
|
2933 |
code_headers.readData(code_count); |
|
2934 |
CHECK; |
|
2935 |
int totalHandlerCount = 0; |
|
2936 |
int totalFlagsCount = 0; |
|
2937 |
for (int i = 0; i < code_count; i++) { |
|
2938 |
int max_stack, max_locals, handler_count, cflags; |
|
2939 |
get_code_header(max_stack, max_locals, handler_count, cflags); |
|
2940 |
if (max_stack < 0) code_max_stack.expectMoreLength(1); |
|
2941 |
if (max_locals < 0) code_max_na_locals.expectMoreLength(1); |
|
2942 |
if (handler_count < 0) code_handler_count.expectMoreLength(1); |
|
2943 |
else totalHandlerCount += handler_count; |
|
2944 |
if (cflags < 0) totalFlagsCount += 1; |
|
2945 |
} |
|
2946 |
code_headers.rewind(); // replay later during writing |
|
2947 |
||
2948 |
code_max_stack.readData(); |
|
2949 |
code_max_na_locals.readData(); |
|
2950 |
code_handler_count.readData(); |
|
2951 |
totalHandlerCount += code_handler_count.getIntTotal(); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2952 |
CHECK; |
2 | 2953 |
|
2954 |
// Read handler specifications. |
|
2955 |
// Cf. PackageReader.readCodeHandlers. |
|
2956 |
code_handler_start_P.readData(totalHandlerCount); |
|
2957 |
code_handler_end_PO.readData(totalHandlerCount); |
|
2958 |
code_handler_catch_PO.readData(totalHandlerCount); |
|
2959 |
code_handler_class_RCN.readData(totalHandlerCount); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2960 |
CHECK; |
2 | 2961 |
|
2962 |
read_attrs(ATTR_CONTEXT_CODE, totalFlagsCount); |
|
2607
7a11e5916dda
6792554: Java JAR Pack200 header checks are insufficent
ksrini
parents:
2602
diff
changeset
|
2963 |
CHECK; |
2 | 2964 |
} |
2965 |
||
2966 |
static inline bool is_in_range(uint n, uint min, uint max) { |
|
2967 |
return n - min <= max - min; // unsigned arithmetic! |
|
2968 |
} |
|
2969 |
static inline bool is_field_op(int bc) { |
|
2970 |
return is_in_range(bc, bc_getstatic, bc_putfield); |
|
2971 |
} |
|
2972 |
static inline bool is_invoke_init_op(int bc) { |
|
2973 |
return is_in_range(bc, _invokeinit_op, _invokeinit_limit-1); |
|
2974 |
} |
|
2975 |
static inline bool is_self_linker_op(int bc) { |
|
2976 |
return is_in_range(bc, _self_linker_op, _self_linker_limit-1); |
|
2977 |
} |
|
2978 |
static bool is_branch_op(int bc) { |
|
2979 |
return is_in_range(bc, bc_ifeq, bc_jsr) |
|
2980 |
|| is_in_range(bc, bc_ifnull, bc_jsr_w); |
|
2981 |
} |
|
2982 |
static bool is_local_slot_op(int bc) { |
|
2983 |
return is_in_range(bc, bc_iload, bc_aload) |
|
2984 |
|| is_in_range(bc, bc_istore, bc_astore) |
|
2985 |
|| bc == bc_iinc || bc == bc_ret; |
|
2986 |
} |
|
2987 |
band* unpacker::ref_band_for_op(int bc) { |
|
2988 |
switch (bc) { |
|
2989 |
case bc_ildc: |
|
2990 |
case bc_ildc_w: |
|
2991 |
return &bc_intref; |
|
2992 |
case bc_fldc: |
|
2993 |
case bc_fldc_w: |
|
2994 |
return &bc_floatref; |
|
2995 |
case bc_lldc2_w: |
|
2996 |
return &bc_longref; |
|
2997 |
case bc_dldc2_w: |
|
2998 |
return &bc_doubleref; |
|
12544 | 2999 |
case bc_sldc: |
3000 |
case bc_sldc_w: |
|
2 | 3001 |
return &bc_stringref; |
3002 |
case bc_cldc: |
|
3003 |
case bc_cldc_w: |
|
3004 |
return &bc_classref; |
|
12544 | 3005 |
case bc_qldc: case bc_qldc_w: |
3006 |
return &bc_loadablevalueref; |
|
2 | 3007 |
|
3008 |
case bc_getstatic: |
|
3009 |
case bc_putstatic: |
|
3010 |
case bc_getfield: |
|
3011 |
case bc_putfield: |
|
3012 |
return &bc_fieldref; |
|
3013 |
||
16050
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
3014 |
case _invokespecial_int: |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
3015 |
case _invokestatic_int: |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
3016 |
return &bc_imethodref; |
2 | 3017 |
case bc_invokevirtual: |
3018 |
case bc_invokespecial: |
|
3019 |
case bc_invokestatic: |
|
3020 |
return &bc_methodref; |
|
3021 |
case bc_invokeinterface: |
|
3022 |
return &bc_imethodref; |
|
12544 | 3023 |
case bc_invokedynamic: |
3024 |
return &bc_indyref; |
|
2 | 3025 |
|
3026 |
case bc_new: |
|
3027 |
case bc_anewarray: |
|
3028 |
case bc_checkcast: |
|
3029 |
case bc_instanceof: |
|
3030 |
case bc_multianewarray: |
|
3031 |
return &bc_classref; |
|
3032 |
} |
|
3033 |
return null; |
|
3034 |
} |
|
3035 |
||
3036 |
maybe_inline |
|
3037 |
band* unpacker::ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar) { |
|
3038 |
if (!is_self_linker_op(bc)) return null; |
|
3039 |
int idx = (bc - _self_linker_op); |
|
3040 |
bool isSuper = (idx >= _self_linker_super_flag); |
|
3041 |
if (isSuper) idx -= _self_linker_super_flag; |
|
3042 |
bool isAload = (idx >= _self_linker_aload_flag); |
|
3043 |
if (isAload) idx -= _self_linker_aload_flag; |
|
3044 |
int origBC = _first_linker_op + idx; |
|
3045 |
bool isField = is_field_op(origBC); |
|
3046 |
isAloadVar = isAload; |
|
3047 |
origBCVar = _first_linker_op + idx; |
|
3048 |
if (!isSuper) |
|
3049 |
return isField? &bc_thisfield: &bc_thismethod; |
|
3050 |
else |
|
3051 |
return isField? &bc_superfield: &bc_supermethod; |
|
3052 |
} |
|
3053 |
||
3054 |
// Cf. PackageReader.readByteCodes |
|
3055 |
inline // called exactly once => inline |
|
3056 |
void unpacker::read_bcs() { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3057 |
PRINTCR((3, "reading compressed bytecodes and operands for %d codes...", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3058 |
code_count)); |
2 | 3059 |
|
3060 |
// read from bc_codes and bc_case_count |
|
3061 |
fillbytes all_switch_ops; |
|
3062 |
all_switch_ops.init(); |
|
3063 |
CHECK; |
|
3064 |
||
3065 |
// Read directly from rp/rplimit. |
|
3066 |
//Do this later: bc_codes.readData(...) |
|
3067 |
byte* rp0 = rp; |
|
3068 |
||
3069 |
band* bc_which; |
|
3070 |
byte* opptr = rp; |
|
3071 |
byte* oplimit = rplimit; |
|
3072 |
||
3073 |
bool isAload; // passed by ref and then ignored |
|
3074 |
int junkBC; // passed by ref and then ignored |
|
3075 |
for (int k = 0; k < code_count; k++) { |
|
3076 |
// Scan one method: |
|
3077 |
for (;;) { |
|
3078 |
if (opptr+2 > oplimit) { |
|
3079 |
rp = opptr; |
|
3080 |
ensure_input(2); |
|
3081 |
oplimit = rplimit; |
|
3082 |
rp = rp0; // back up |
|
3083 |
} |
|
3084 |
if (opptr == oplimit) { abort(); break; } |
|
3085 |
int bc = *opptr++ & 0xFF; |
|
3086 |
bool isWide = false; |
|
3087 |
if (bc == bc_wide) { |
|
3088 |
if (opptr == oplimit) { abort(); break; } |
|
3089 |
bc = *opptr++ & 0xFF; |
|
3090 |
isWide = true; |
|
3091 |
} |
|
3092 |
// Adjust expectations of various band sizes. |
|
3093 |
switch (bc) { |
|
3094 |
case bc_tableswitch: |
|
3095 |
case bc_lookupswitch: |
|
3096 |
all_switch_ops.addByte(bc); |
|
3097 |
break; |
|
3098 |
case bc_iinc: |
|
3099 |
bc_local.expectMoreLength(1); |
|
3100 |
bc_which = isWide ? &bc_short : &bc_byte; |
|
3101 |
bc_which->expectMoreLength(1); |
|
3102 |
break; |
|
3103 |
case bc_sipush: |
|
3104 |
bc_short.expectMoreLength(1); |
|
3105 |
break; |
|
3106 |
case bc_bipush: |
|
3107 |
bc_byte.expectMoreLength(1); |
|
3108 |
break; |
|
3109 |
case bc_newarray: |
|
3110 |
bc_byte.expectMoreLength(1); |
|
3111 |
break; |
|
3112 |
case bc_multianewarray: |
|
3113 |
assert(ref_band_for_op(bc) == &bc_classref); |
|
3114 |
bc_classref.expectMoreLength(1); |
|
3115 |
bc_byte.expectMoreLength(1); |
|
3116 |
break; |
|
3117 |
case bc_ref_escape: |
|
3118 |
bc_escrefsize.expectMoreLength(1); |
|
3119 |
bc_escref.expectMoreLength(1); |
|
3120 |
break; |
|
3121 |
case bc_byte_escape: |
|
3122 |
bc_escsize.expectMoreLength(1); |
|
3123 |
// bc_escbyte will have to be counted too |
|
3124 |
break; |
|
3125 |
default: |
|
3126 |
if (is_invoke_init_op(bc)) { |
|
3127 |
bc_initref.expectMoreLength(1); |
|
3128 |
break; |
|
3129 |
} |
|
3130 |
bc_which = ref_band_for_self_op(bc, isAload, junkBC); |
|
3131 |
if (bc_which != null) { |
|
3132 |
bc_which->expectMoreLength(1); |
|
3133 |
break; |
|
3134 |
} |
|
3135 |
if (is_branch_op(bc)) { |
|
3136 |
bc_label.expectMoreLength(1); |
|
3137 |
break; |
|
3138 |
} |
|
3139 |
bc_which = ref_band_for_op(bc); |
|
3140 |
if (bc_which != null) { |
|
3141 |
bc_which->expectMoreLength(1); |
|
3142 |
assert(bc != bc_multianewarray); // handled elsewhere |
|
3143 |
break; |
|
3144 |
} |
|
3145 |
if (is_local_slot_op(bc)) { |
|
3146 |
bc_local.expectMoreLength(1); |
|
3147 |
break; |
|
3148 |
} |
|
3149 |
break; |
|
3150 |
case bc_end_marker: |
|
3151 |
// Increment k and test against code_count. |
|
3152 |
goto doneScanningMethod; |
|
3153 |
} |
|
3154 |
} |
|
3155 |
doneScanningMethod:{} |
|
3156 |
if (aborting()) break; |
|
3157 |
} |
|
3158 |
||
3159 |
// Go through the formality, so we can use it in a regular fashion later: |
|
3160 |
assert(rp == rp0); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3161 |
bc_codes.readData((int)(opptr - rp)); |
2 | 3162 |
|
3163 |
int i = 0; |
|
3164 |
||
3165 |
// To size instruction bands correctly, we need info on switches: |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3166 |
bc_case_count.readData((int)all_switch_ops.size()); |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3167 |
for (i = 0; i < (int)all_switch_ops.size(); i++) { |
2 | 3168 |
int caseCount = bc_case_count.getInt(); |
3169 |
int bc = all_switch_ops.getByte(i); |
|
3170 |
bc_label.expectMoreLength(1+caseCount); // default label + cases |
|
3171 |
bc_case_value.expectMoreLength(bc == bc_tableswitch ? 1 : caseCount); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3172 |
PRINTCR((2, "switch bc=%d caseCount=%d", bc, caseCount)); |
2 | 3173 |
} |
3174 |
bc_case_count.rewind(); // uses again for output |
|
3175 |
||
3176 |
all_switch_ops.free(); |
|
3177 |
||
3178 |
for (i = e_bc_case_value; i <= e_bc_escsize; i++) { |
|
3179 |
all_bands[i].readData(); |
|
3180 |
} |
|
3181 |
||
3182 |
// The bc_escbyte band is counted by the immediately previous band. |
|
3183 |
bc_escbyte.readData(bc_escsize.getIntTotal()); |
|
3184 |
||
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3185 |
PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...", |
2 | 3186 |
(int)(bc_codes.size()), |
3187 |
(int)(bc_escsize.maxRP() - bc_case_value.minRP()), |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3188 |
code_count)); |
2 | 3189 |
} |
3190 |
||
3191 |
void unpacker::read_bands() { |
|
3192 |
byte* rp0 = rp; |
|
16076 | 3193 |
CHECK; |
2 | 3194 |
read_file_header(); |
3195 |
CHECK; |
|
3196 |
||
3197 |
if (cp.nentries == 0) { |
|
3198 |
// read_file_header failed to read a CP, because it copied a JAR. |
|
3199 |
return; |
|
3200 |
} |
|
3201 |
||
3202 |
// Do this after the file header has been read: |
|
3203 |
check_options(); |
|
3204 |
||
3205 |
read_cp(); |
|
3206 |
CHECK; |
|
3207 |
read_attr_defs(); |
|
3208 |
CHECK; |
|
3209 |
read_ics(); |
|
3210 |
CHECK; |
|
3211 |
read_classes(); |
|
3212 |
CHECK; |
|
3213 |
read_bcs(); |
|
3214 |
CHECK; |
|
3215 |
read_files(); |
|
3216 |
} |
|
3217 |
||
3218 |
/// CP routines |
|
3219 |
||
3220 |
entry*& cpool::hashTabRef(byte tag, bytes& b) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3221 |
PRINTCR((5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len)); |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3222 |
uint hash = tag + (int)b.len; |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3223 |
for (int i = 0; i < (int)b.len; i++) { |
2 | 3224 |
hash = hash * 31 + (0xFF & b.ptr[i]); |
3225 |
} |
|
3226 |
entry** ht = hashTab; |
|
3227 |
int hlen = hashTabLength; |
|
3228 |
assert((hlen & (hlen-1)) == 0); // must be power of 2 |
|
3229 |
uint hash1 = hash & (hlen-1); // == hash % hlen |
|
3230 |
uint hash2 = 0; // lazily computed (requires mod op.) |
|
3231 |
int probes = 0; |
|
3232 |
while (ht[hash1] != null) { |
|
3233 |
entry& e = *ht[hash1]; |
|
3234 |
if (e.value.b.equals(b) && e.tag == tag) |
|
3235 |
break; |
|
3236 |
if (hash2 == 0) |
|
3237 |
// Note: hash2 must be relatively prime to hlen, hence the "|1". |
|
3238 |
hash2 = (((hash % 499) & (hlen-1)) | 1); |
|
3239 |
hash1 += hash2; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3240 |
if (hash1 >= (uint)hlen) hash1 -= hlen; |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3241 |
assert(hash1 < (uint)hlen); |
2 | 3242 |
assert(++probes < hlen); |
3243 |
} |
|
3244 |
#ifndef PRODUCT |
|
3245 |
hash_probes[0] += 1; |
|
3246 |
hash_probes[1] += probes; |
|
3247 |
#endif |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3248 |
PRINTCR((5, " => @%d %p", hash1, ht[hash1])); |
2 | 3249 |
return ht[hash1]; |
3250 |
} |
|
3251 |
||
3252 |
maybe_inline |
|
3253 |
static void insert_extra(entry* e, ptrlist& extras) { |
|
3254 |
// This ordering helps implement the Pack200 requirement |
|
3255 |
// of a predictable CP order in the class files produced. |
|
3256 |
e->inord = NO_INORD; // mark as an "extra" |
|
3257 |
extras.add(e); |
|
3258 |
// Note: We will sort the list (by string-name) later. |
|
3259 |
} |
|
3260 |
||
3261 |
entry* cpool::ensureUtf8(bytes& b) { |
|
3262 |
entry*& ix = hashTabRef(CONSTANT_Utf8, b); |
|
3263 |
if (ix != null) return ix; |
|
3264 |
// Make one. |
|
3265 |
if (nentries == maxentries) { |
|
3266 |
abort("cp utf8 overflow"); |
|
3267 |
return &entries[tag_base[CONSTANT_Utf8]]; // return something |
|
3268 |
} |
|
3269 |
entry& e = entries[nentries++]; |
|
3270 |
e.tag = CONSTANT_Utf8; |
|
3271 |
u->saveTo(e.value.b, b); |
|
3272 |
assert(&e >= first_extra_entry); |
|
3273 |
insert_extra(&e, tag_extras[CONSTANT_Utf8]); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3274 |
PRINTCR((4,"ensureUtf8 miss %s", e.string())); |
2 | 3275 |
return ix = &e; |
3276 |
} |
|
3277 |
||
3278 |
entry* cpool::ensureClass(bytes& b) { |
|
3279 |
entry*& ix = hashTabRef(CONSTANT_Class, b); |
|
3280 |
if (ix != null) return ix; |
|
3281 |
// Make one. |
|
3282 |
if (nentries == maxentries) { |
|
3283 |
abort("cp class overflow"); |
|
3284 |
return &entries[tag_base[CONSTANT_Class]]; // return something |
|
3285 |
} |
|
3286 |
entry& e = entries[nentries++]; |
|
3287 |
e.tag = CONSTANT_Class; |
|
3288 |
e.nrefs = 1; |
|
3289 |
e.refs = U_NEW(entry*, 1); |
|
3290 |
ix = &e; // hold my spot in the index |
|
3291 |
entry* utf = ensureUtf8(b); |
|
3292 |
e.refs[0] = utf; |
|
3293 |
e.value.b = utf->value.b; |
|
3294 |
assert(&e >= first_extra_entry); |
|
3295 |
insert_extra(&e, tag_extras[CONSTANT_Class]); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3296 |
PRINTCR((4,"ensureClass miss %s", e.string())); |
2 | 3297 |
return &e; |
3298 |
} |
|
3299 |
||
3300 |
void cpool::expandSignatures() { |
|
3301 |
int i; |
|
3302 |
int nsigs = 0; |
|
3303 |
int nreused = 0; |
|
3304 |
int first_sig = tag_base[CONSTANT_Signature]; |
|
3305 |
int sig_limit = tag_count[CONSTANT_Signature] + first_sig; |
|
3306 |
fillbytes buf; |
|
3307 |
buf.init(1<<10); |
|
3308 |
CHECK; |
|
3309 |
for (i = first_sig; i < sig_limit; i++) { |
|
3310 |
entry& e = entries[i]; |
|
3311 |
assert(e.tag == CONSTANT_Signature); |
|
3312 |
int refnum = 0; |
|
3313 |
bytes form = e.refs[refnum++]->asUtf8(); |
|
3314 |
buf.empty(); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3315 |
for (int j = 0; j < (int)form.len; j++) { |
2 | 3316 |
int c = form.ptr[j]; |
3317 |
buf.addByte(c); |
|
3318 |
if (c == 'L') { |
|
3319 |
entry* cls = e.refs[refnum++]; |
|
3320 |
buf.append(cls->className()->asUtf8()); |
|
3321 |
} |
|
3322 |
} |
|
3323 |
assert(refnum == e.nrefs); |
|
3324 |
bytes& sig = buf.b; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3325 |
PRINTCR((5,"signature %d %s -> %s", i, form.ptr, sig.ptr)); |
2 | 3326 |
|
3327 |
// try to find a pre-existing Utf8: |
|
3328 |
entry* &e2 = hashTabRef(CONSTANT_Utf8, sig); |
|
3329 |
if (e2 != null) { |
|
3330 |
assert(e2->isUtf8(sig)); |
|
3331 |
e.value.b = e2->value.b; |
|
3332 |
e.refs[0] = e2; |
|
3333 |
e.nrefs = 1; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3334 |
PRINTCR((5,"signature replaced %d => %s", i, e.string())); |
2 | 3335 |
nreused++; |
3336 |
} else { |
|
3337 |
// there is no other replacement; reuse this CP entry as a Utf8 |
|
3338 |
u->saveTo(e.value.b, sig); |
|
3339 |
e.tag = CONSTANT_Utf8; |
|
3340 |
e.nrefs = 0; |
|
3341 |
e2 = &e; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3342 |
PRINTCR((5,"signature changed %d => %s", e.inord, e.string())); |
2 | 3343 |
} |
3344 |
nsigs++; |
|
3345 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3346 |
PRINTCR((1,"expanded %d signatures (reused %d utfs)", nsigs, nreused)); |
2 | 3347 |
buf.free(); |
3348 |
||
3349 |
// go expunge all references to remaining signatures: |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3350 |
for (i = 0; i < (int)nentries; i++) { |
2 | 3351 |
entry& e = entries[i]; |
3352 |
for (int j = 0; j < e.nrefs; j++) { |
|
3353 |
entry*& e2 = e.refs[j]; |
|
3354 |
if (e2 != null && e2->tag == CONSTANT_Signature) |
|
3355 |
e2 = e2->refs[0]; |
|
3356 |
} |
|
3357 |
} |
|
3358 |
} |
|
3359 |
||
12544 | 3360 |
bool isLoadableValue(int tag) { |
3361 |
switch(tag) { |
|
3362 |
case CONSTANT_Integer: |
|
3363 |
case CONSTANT_Float: |
|
3364 |
case CONSTANT_Long: |
|
3365 |
case CONSTANT_Double: |
|
3366 |
case CONSTANT_String: |
|
3367 |
case CONSTANT_Class: |
|
3368 |
case CONSTANT_MethodHandle: |
|
3369 |
case CONSTANT_MethodType: |
|
3370 |
return true; |
|
3371 |
default: |
|
3372 |
return false; |
|
3373 |
} |
|
3374 |
} |
|
3375 |
/* |
|
3376 |
* this method can be used to size an array using null as the parameter, |
|
3377 |
* thereafter can be reused to initialize the array using a valid pointer |
|
3378 |
* as a parameter. |
|
3379 |
*/ |
|
3380 |
int cpool::initLoadableValues(entry** loadable_entries) { |
|
3381 |
int loadable_count = 0; |
|
3382 |
for (int i = 0; i < (int)N_TAGS_IN_ORDER; i++) { |
|
3383 |
int tag = TAGS_IN_ORDER[i]; |
|
3384 |
if (!isLoadableValue(tag)) |
|
3385 |
continue; |
|
3386 |
if (loadable_entries != NULL) { |
|
3387 |
for (int n = 0 ; n < tag_count[tag] ; n++) { |
|
3388 |
loadable_entries[loadable_count + n] = &entries[tag_base[tag] + n]; |
|
3389 |
} |
|
3390 |
} |
|
3391 |
loadable_count += tag_count[tag]; |
|
3392 |
} |
|
3393 |
return loadable_count; |
|
3394 |
} |
|
3395 |
||
3396 |
// Initialize various views into the constant pool. |
|
3397 |
void cpool::initGroupIndexes() { |
|
3398 |
// Initialize All |
|
3399 |
int all_count = 0; |
|
3400 |
for (int tag = CONSTANT_None ; tag < CONSTANT_Limit ; tag++) { |
|
3401 |
all_count += tag_count[tag]; |
|
3402 |
} |
|
3403 |
entry* all_entries = &entries[tag_base[CONSTANT_None]]; |
|
3404 |
tag_group_count[CONSTANT_All - CONSTANT_All] = all_count; |
|
3405 |
tag_group_index[CONSTANT_All - CONSTANT_All].init(all_count, all_entries, CONSTANT_All); |
|
3406 |
||
3407 |
// Initialize LoadableValues |
|
3408 |
int loadable_count = initLoadableValues(NULL); |
|
3409 |
entry** loadable_entries = U_NEW(entry*, loadable_count); |
|
3410 |
initLoadableValues(loadable_entries); |
|
3411 |
tag_group_count[CONSTANT_LoadableValue - CONSTANT_All] = loadable_count; |
|
3412 |
tag_group_index[CONSTANT_LoadableValue - CONSTANT_All].init(loadable_count, |
|
3413 |
loadable_entries, CONSTANT_LoadableValue); |
|
3414 |
||
3415 |
// Initialize AnyMembers |
|
3416 |
int any_count = tag_count[CONSTANT_Fieldref] + |
|
3417 |
tag_count[CONSTANT_Methodref] + |
|
3418 |
tag_count[CONSTANT_InterfaceMethodref]; |
|
3419 |
entry *any_entries = &entries[tag_base[CONSTANT_Fieldref]]; |
|
3420 |
tag_group_count[CONSTANT_AnyMember - CONSTANT_All] = any_count; |
|
3421 |
tag_group_index[CONSTANT_AnyMember - CONSTANT_All].init(any_count, |
|
3422 |
any_entries, CONSTANT_AnyMember); |
|
3423 |
} |
|
3424 |
||
2 | 3425 |
void cpool::initMemberIndexes() { |
3426 |
// This function does NOT refer to any class schema. |
|
3427 |
// It is totally internal to the cpool. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3428 |
int i, j; |
2 | 3429 |
|
3430 |
// Get the pre-existing indexes: |
|
3431 |
int nclasses = tag_count[CONSTANT_Class]; |
|
3432 |
entry* classes = tag_base[CONSTANT_Class] + entries; |
|
3433 |
int nfields = tag_count[CONSTANT_Fieldref]; |
|
3434 |
entry* fields = tag_base[CONSTANT_Fieldref] + entries; |
|
3435 |
int nmethods = tag_count[CONSTANT_Methodref]; |
|
3436 |
entry* methods = tag_base[CONSTANT_Methodref] + entries; |
|
3437 |
||
3438 |
int* field_counts = T_NEW(int, nclasses); |
|
3439 |
int* method_counts = T_NEW(int, nclasses); |
|
3440 |
cpindex* all_indexes = U_NEW(cpindex, nclasses*2); |
|
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
3441 |
entry** field_ix = U_NEW(entry*, add_size(nfields, nclasses)); |
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
3442 |
entry** method_ix = U_NEW(entry*, add_size(nmethods, nclasses)); |
2 | 3443 |
|
3444 |
for (j = 0; j < nfields; j++) { |
|
3445 |
entry& f = fields[j]; |
|
3446 |
i = f.memberClass()->inord; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3447 |
assert(i < nclasses); |
2 | 3448 |
field_counts[i]++; |
3449 |
} |
|
3450 |
for (j = 0; j < nmethods; j++) { |
|
3451 |
entry& m = methods[j]; |
|
3452 |
i = m.memberClass()->inord; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3453 |
assert(i < nclasses); |
2 | 3454 |
method_counts[i]++; |
3455 |
} |
|
3456 |
||
3457 |
int fbase = 0, mbase = 0; |
|
3458 |
for (i = 0; i < nclasses; i++) { |
|
3459 |
int fc = field_counts[i]; |
|
3460 |
int mc = method_counts[i]; |
|
3461 |
all_indexes[i*2+0].init(fc, field_ix+fbase, |
|
3462 |
CONSTANT_Fieldref + SUBINDEX_BIT); |
|
3463 |
all_indexes[i*2+1].init(mc, method_ix+mbase, |
|
3464 |
CONSTANT_Methodref + SUBINDEX_BIT); |
|
3465 |
// reuse field_counts and member_counts as fill pointers: |
|
3466 |
field_counts[i] = fbase; |
|
3467 |
method_counts[i] = mbase; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3468 |
PRINTCR((3, "class %d fields @%d[%d] methods @%d[%d]", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3469 |
i, fbase, fc, mbase, mc)); |
2 | 3470 |
fbase += fc+1; |
3471 |
mbase += mc+1; |
|
3472 |
// (the +1 leaves a space between every subarray) |
|
3473 |
} |
|
3474 |
assert(fbase == nfields+nclasses); |
|
3475 |
assert(mbase == nmethods+nclasses); |
|
3476 |
||
3477 |
for (j = 0; j < nfields; j++) { |
|
3478 |
entry& f = fields[j]; |
|
3479 |
i = f.memberClass()->inord; |
|
3480 |
field_ix[field_counts[i]++] = &f; |
|
3481 |
} |
|
3482 |
for (j = 0; j < nmethods; j++) { |
|
3483 |
entry& m = methods[j]; |
|
3484 |
i = m.memberClass()->inord; |
|
3485 |
method_ix[method_counts[i]++] = &m; |
|
3486 |
} |
|
3487 |
||
3488 |
member_indexes = all_indexes; |
|
3489 |
||
3490 |
#ifndef PRODUCT |
|
3491 |
// Test the result immediately on every class and field. |
|
3492 |
int fvisited = 0, mvisited = 0; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3493 |
int prevord, len; |
2 | 3494 |
for (i = 0; i < nclasses; i++) { |
3495 |
entry* cls = &classes[i]; |
|
3496 |
cpindex* fix = getFieldIndex(cls); |
|
3497 |
cpindex* mix = getMethodIndex(cls); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3498 |
PRINTCR((2, "field and method index for %s [%d] [%d]", |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3499 |
cls->string(), mix->len, fix->len)); |
2 | 3500 |
prevord = -1; |
3501 |
for (j = 0, len = fix->len; j < len; j++) { |
|
3502 |
entry* f = fix->get(j); |
|
3503 |
assert(f != null); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3504 |
PRINTCR((3, "- field %s", f->string())); |
2 | 3505 |
assert(f->memberClass() == cls); |
3506 |
assert(prevord < (int)f->inord); |
|
3507 |
prevord = f->inord; |
|
3508 |
fvisited++; |
|
3509 |
} |
|
3510 |
assert(fix->base2[j] == null); |
|
3511 |
prevord = -1; |
|
3512 |
for (j = 0, len = mix->len; j < len; j++) { |
|
3513 |
entry* m = mix->get(j); |
|
3514 |
assert(m != null); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3515 |
PRINTCR((3, "- method %s", m->string())); |
2 | 3516 |
assert(m->memberClass() == cls); |
3517 |
assert(prevord < (int)m->inord); |
|
3518 |
prevord = m->inord; |
|
3519 |
mvisited++; |
|
3520 |
} |
|
3521 |
assert(mix->base2[j] == null); |
|
3522 |
} |
|
3523 |
assert(fvisited == nfields); |
|
3524 |
assert(mvisited == nmethods); |
|
3525 |
#endif |
|
3526 |
||
3527 |
// Free intermediate buffers. |
|
3528 |
u->free_temps(); |
|
3529 |
} |
|
3530 |
||
3531 |
void entry::requestOutputIndex(cpool& cp, int req) { |
|
12544 | 3532 |
assert(outputIndex <= REQUESTED_NONE); // must not have assigned indexes yet |
2 | 3533 |
if (tag == CONSTANT_Signature) { |
3534 |
ref(0)->requestOutputIndex(cp, req); |
|
3535 |
return; |
|
3536 |
} |
|
3537 |
assert(req == REQUESTED || req == REQUESTED_LDC); |
|
12544 | 3538 |
if (outputIndex != REQUESTED_NONE) { |
2 | 3539 |
if (req == REQUESTED_LDC) |
3540 |
outputIndex = req; // this kind has precedence |
|
3541 |
return; |
|
3542 |
} |
|
3543 |
outputIndex = req; |
|
3544 |
//assert(!cp.outputEntries.contains(this)); |
|
3545 |
assert(tag != CONSTANT_Signature); |
|
12544 | 3546 |
// The BSMs are jetisoned to a side table, however all references |
3547 |
// that the BSMs refer to, need to be considered. |
|
3548 |
if (tag == CONSTANT_BootstrapMethod) { |
|
3549 |
// this is a a pseudo-op entry; an attribute will be generated later on |
|
3550 |
cp.requested_bsms.add(this); |
|
3551 |
} else { |
|
3552 |
// all other tag types go into real output file CP: |
|
3553 |
cp.outputEntries.add(this); |
|
3554 |
} |
|
2 | 3555 |
for (int j = 0; j < nrefs; j++) { |
3556 |
ref(j)->requestOutputIndex(cp); |
|
3557 |
} |
|
3558 |
} |
|
3559 |
||
3560 |
void cpool::resetOutputIndexes() { |
|
12544 | 3561 |
/* |
3562 |
* reset those few entries that are being used in the current class |
|
3563 |
* (Caution since this method is called after every class written, a loop |
|
3564 |
* over every global constant pool entry would be a quadratic cost.) |
|
3565 |
*/ |
|
3566 |
||
3567 |
int noes = outputEntries.length(); |
|
2 | 3568 |
entry** oes = (entry**) outputEntries.base(); |
12544 | 3569 |
for (int i = 0 ; i < noes ; i++) { |
2 | 3570 |
entry& e = *oes[i]; |
12544 | 3571 |
e.outputIndex = REQUESTED_NONE; |
3572 |
} |
|
3573 |
||
3574 |
// do the same for bsms and reset them if required |
|
3575 |
int nbsms = requested_bsms.length(); |
|
3576 |
entry** boes = (entry**) requested_bsms.base(); |
|
3577 |
for (int i = 0 ; i < nbsms ; i++) { |
|
3578 |
entry& e = *boes[i]; |
|
3579 |
e.outputIndex = REQUESTED_NONE; |
|
2 | 3580 |
} |
3581 |
outputIndexLimit = 0; |
|
3582 |
outputEntries.empty(); |
|
3583 |
#ifndef PRODUCT |
|
12544 | 3584 |
// ensure things are cleared out |
3585 |
for (int i = 0; i < (int)maxentries; i++) |
|
3586 |
assert(entries[i].outputIndex == REQUESTED_NONE); |
|
2 | 3587 |
#endif |
3588 |
} |
|
3589 |
||
3590 |
static const byte TAG_ORDER[CONSTANT_Limit] = { |
|
12544 | 3591 |
0, 1, 0, 2, 3, 4, 5, 7, 6, 10, 11, 12, 9, 8, 0, 13, 14, 15, 16 |
2 | 3592 |
}; |
3593 |
||
3594 |
extern "C" |
|
3595 |
int outputEntry_cmp(const void* e1p, const void* e2p) { |
|
3596 |
// Sort entries according to the Pack200 rules for deterministic |
|
3597 |
// constant pool ordering. |
|
3598 |
// |
|
3599 |
// The four sort keys as follows, in order of decreasing importance: |
|
3600 |
// 1. ldc first, then non-ldc guys |
|
3601 |
// 2. normal cp_All entries by input order (i.e., address order) |
|
3602 |
// 3. after that, extra entries by lexical order (as in tag_extras[*]) |
|
3603 |
entry& e1 = *(entry*) *(void**) e1p; |
|
3604 |
entry& e2 = *(entry*) *(void**) e2p; |
|
3605 |
int oi1 = e1.outputIndex; |
|
3606 |
int oi2 = e2.outputIndex; |
|
3607 |
assert(oi1 == REQUESTED || oi1 == REQUESTED_LDC); |
|
3608 |
assert(oi2 == REQUESTED || oi2 == REQUESTED_LDC); |
|
3609 |
if (oi1 != oi2) { |
|
3610 |
if (oi1 == REQUESTED_LDC) return 0-1; |
|
3611 |
if (oi2 == REQUESTED_LDC) return 1-0; |
|
3612 |
// Else fall through; neither is an ldc request. |
|
3613 |
} |
|
3614 |
if (e1.inord != NO_INORD || e2.inord != NO_INORD) { |
|
3615 |
// One or both is normal. Use input order. |
|
3616 |
if (&e1 > &e2) return 1-0; |
|
3617 |
if (&e1 < &e2) return 0-1; |
|
3618 |
return 0; // equal pointers |
|
3619 |
} |
|
3620 |
// Both are extras. Sort by tag and then by value. |
|
3621 |
if (e1.tag != e2.tag) { |
|
3622 |
return TAG_ORDER[e1.tag] - TAG_ORDER[e2.tag]; |
|
3623 |
} |
|
3624 |
// If the tags are the same, use string comparison. |
|
3625 |
return compare_Utf8_chars(e1.value.b, e2.value.b); |
|
3626 |
} |
|
3627 |
||
3628 |
void cpool::computeOutputIndexes() { |
|
3629 |
int i; |
|
3630 |
||
3631 |
#ifndef PRODUCT |
|
3632 |
// outputEntries must be a complete list of those requested: |
|
3633 |
static uint checkStart = 0; |
|
3634 |
int checkStep = 1; |
|
3635 |
if (nentries > 100) checkStep = nentries / 100; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3636 |
for (i = (int)(checkStart++ % checkStep); i < (int)nentries; i += checkStep) { |
2 | 3637 |
entry& e = entries[i]; |
12544 | 3638 |
if (e.tag == CONSTANT_BootstrapMethod) { |
3639 |
if (e.outputIndex != REQUESTED_NONE) { |
|
3640 |
assert(requested_bsms.contains(&e)); |
|
3641 |
} else { |
|
3642 |
assert(!requested_bsms.contains(&e)); |
|
3643 |
} |
|
2 | 3644 |
} else { |
12544 | 3645 |
if (e.outputIndex != REQUESTED_NONE) { |
3646 |
assert(outputEntries.contains(&e)); |
|
3647 |
} else { |
|
3648 |
assert(!outputEntries.contains(&e)); |
|
3649 |
} |
|
2 | 3650 |
} |
3651 |
} |
|
3652 |
||
3653 |
// check hand-initialization of TAG_ORDER |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3654 |
for (i = 0; i < (int)N_TAGS_IN_ORDER; i++) { |
2 | 3655 |
byte tag = TAGS_IN_ORDER[i]; |
3656 |
assert(TAG_ORDER[tag] == i+1); |
|
3657 |
} |
|
3658 |
#endif |
|
3659 |
||
3660 |
int noes = outputEntries.length(); |
|
3661 |
entry** oes = (entry**) outputEntries.base(); |
|
3662 |
||
3663 |
// Sort the output constant pool into the order required by Pack200. |
|
3664 |
PTRLIST_QSORT(outputEntries, outputEntry_cmp); |
|
3665 |
||
3666 |
// Allocate a new index for each entry that needs one. |
|
3667 |
// We do this in two passes, one for LDC entries and one for the rest. |
|
3668 |
int nextIndex = 1; // always skip index #0 in output cpool |
|
3669 |
for (i = 0; i < noes; i++) { |
|
3670 |
entry& e = *oes[i]; |
|
12544 | 3671 |
assert(e.outputIndex >= REQUESTED_LDC); |
2 | 3672 |
e.outputIndex = nextIndex++; |
3673 |
if (e.isDoubleWord()) nextIndex++; // do not use the next index |
|
3674 |
} |
|
3675 |
outputIndexLimit = nextIndex; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3676 |
PRINTCR((3,"renumbering CP to %d entries", outputIndexLimit)); |
2 | 3677 |
} |
3678 |
||
3679 |
#ifndef PRODUCT |
|
3680 |
// debugging goo |
|
3681 |
||
3682 |
unpacker* debug_u; |
|
3683 |
||
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3684 |
static bytes& getbuf(size_t len) { // for debugging only! |
2 | 3685 |
static int bn = 0; |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3686 |
static bytes bufs[8]; |
2 | 3687 |
bytes& buf = bufs[bn++ & 7]; |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3688 |
while (buf.len < len + 10) { |
2 | 3689 |
buf.realloc(buf.len ? buf.len * 2 : 1000); |
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3690 |
} |
2 | 3691 |
buf.ptr[0] = 0; // for the sake of strcat |
3692 |
return buf; |
|
3693 |
} |
|
3694 |
||
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3695 |
const char* entry::string() { |
2 | 3696 |
bytes buf; |
3697 |
switch (tag) { |
|
3698 |
case CONSTANT_None: |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3699 |
return "<empty>"; |
2 | 3700 |
case CONSTANT_Signature: |
3701 |
if (value.b.ptr == null) |
|
3702 |
return ref(0)->string(); |
|
3703 |
// else fall through: |
|
3704 |
case CONSTANT_Utf8: |
|
3705 |
buf = value.b; |
|
3706 |
break; |
|
3707 |
case CONSTANT_Integer: |
|
3708 |
case CONSTANT_Float: |
|
3709 |
buf = getbuf(12); |
|
3710 |
sprintf((char*)buf.ptr, "0x%08x", value.i); |
|
3711 |
break; |
|
3712 |
case CONSTANT_Long: |
|
3713 |
case CONSTANT_Double: |
|
3714 |
buf = getbuf(24); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3715 |
sprintf((char*)buf.ptr, "0x" LONG_LONG_HEX_FORMAT, value.l); |
2 | 3716 |
break; |
3717 |
default: |
|
3718 |
if (nrefs == 0) { |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3719 |
return TAG_NAME[tag]; |
2 | 3720 |
} else if (nrefs == 1) { |
3721 |
return refs[0]->string(); |
|
3722 |
} else { |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3723 |
const char* s1 = refs[0]->string(); |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3724 |
const char* s2 = refs[1]->string(); |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3725 |
buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1); |
2 | 3726 |
buf.strcat(s1).strcat(" ").strcat(s2); |
3727 |
if (nrefs > 2) buf.strcat(" ..."); |
|
3728 |
} |
|
3729 |
} |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3730 |
return (const char*)buf.ptr; |
2 | 3731 |
} |
3732 |
||
3733 |
void print_cp_entry(int i) { |
|
3734 |
entry& e = debug_u->cp.entries[i]; |
|
29591
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3735 |
|
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3736 |
if ((uint)e.tag < CONSTANT_Limit) { |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3737 |
printf(" %d\t%s %s\n", i, TAG_NAME[e.tag], e.string()); |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3738 |
} else { |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3739 |
printf(" %d\t%d %s\n", i, e.tag, e.string()); |
51244d1ddffc
8074839: Resolve disabled warnings for libunpack and the unpack200 binary
mikael
parents:
29368
diff
changeset
|
3740 |
} |
2 | 3741 |
} |
3742 |
||
3743 |
void print_cp_entries(int beg, int end) { |
|
3744 |
for (int i = beg; i < end; i++) |
|
3745 |
print_cp_entry(i); |
|
3746 |
} |
|
3747 |
||
3748 |
void print_cp() { |
|
3749 |
print_cp_entries(0, debug_u->cp.nentries); |
|
3750 |
} |
|
3751 |
||
3752 |
#endif |
|
3753 |
||
3754 |
// Unpacker Start |
|
3755 |
||
3756 |
const char str_tf[] = "true\0false"; |
|
3757 |
#undef STR_TRUE |
|
3758 |
#undef STR_FALSE |
|
3759 |
#define STR_TRUE (&str_tf[0]) |
|
3760 |
#define STR_FALSE (&str_tf[5]) |
|
3761 |
||
3762 |
const char* unpacker::get_option(const char* prop) { |
|
3763 |
if (prop == null ) return null; |
|
3764 |
if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) { |
|
3765 |
return deflate_hint_or_zero == 0? null : STR_TF(deflate_hint_or_zero > 0); |
|
3766 |
#ifdef HAVE_STRIP |
|
3767 |
} else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) { |
|
3768 |
return STR_TF(strip_compile); |
|
3769 |
} else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) { |
|
3770 |
return STR_TF(strip_debug); |
|
3771 |
} else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) { |
|
3772 |
return STR_TF(strip_jcov); |
|
3773 |
#endif /*HAVE_STRIP*/ |
|
3774 |
} else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) { |
|
3775 |
return STR_TF(remove_packfile); |
|
3776 |
} else if (strcmp(prop, DEBUG_VERBOSE) == 0) { |
|
3777 |
return saveIntStr(verbose); |
|
3778 |
} else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) { |
|
3779 |
return (modification_time_or_zero == 0)? null: |
|
3780 |
saveIntStr(modification_time_or_zero); |
|
3781 |
} else if (strcmp(prop, UNPACK_LOG_FILE) == 0) { |
|
3782 |
return log_file; |
|
3783 |
} else { |
|
3784 |
return NULL; // unknown option ignore |
|
3785 |
} |
|
3786 |
} |
|
3787 |
||
3788 |
bool unpacker::set_option(const char* prop, const char* value) { |
|
3789 |
if (prop == NULL) return false; |
|
3790 |
if (strcmp(prop, UNPACK_DEFLATE_HINT) == 0) { |
|
3791 |
deflate_hint_or_zero = ( (value == null || strcmp(value, "keep") == 0) |
|
3792 |
? 0: BOOL_TF(value) ? +1: -1); |
|
3793 |
#ifdef HAVE_STRIP |
|
3794 |
} else if (strcmp(prop, UNPACK_STRIP_COMPILE) == 0) { |
|
3795 |
strip_compile = STR_TF(value); |
|
3796 |
} else if (strcmp(prop, UNPACK_STRIP_DEBUG) == 0) { |
|
3797 |
strip_debug = STR_TF(value); |
|
3798 |
} else if (strcmp(prop, UNPACK_STRIP_JCOV) == 0) { |
|
3799 |
strip_jcov = STR_TF(value); |
|
3800 |
#endif /*HAVE_STRIP*/ |
|
3801 |
} else if (strcmp(prop, UNPACK_REMOVE_PACKFILE) == 0) { |
|
3802 |
remove_packfile = STR_TF(value); |
|
3803 |
} else if (strcmp(prop, DEBUG_VERBOSE) == 0) { |
|
3804 |
verbose = (value == null)? 0: atoi(value); |
|
3805 |
} else if (strcmp(prop, DEBUG_VERBOSE ".bands") == 0) { |
|
3806 |
#ifndef PRODUCT |
|
3807 |
verbose_bands = (value == null)? 0: atoi(value); |
|
3808 |
#endif |
|
3809 |
} else if (strcmp(prop, UNPACK_MODIFICATION_TIME) == 0) { |
|
3810 |
if (value == null || (strcmp(value, "keep") == 0)) { |
|
3811 |
modification_time_or_zero = 0; |
|
3812 |
} else if (strcmp(value, "now") == 0) { |
|
3813 |
time_t now; |
|
3814 |
time(&now); |
|
3815 |
modification_time_or_zero = (int) now; |
|
3816 |
} else { |
|
3817 |
modification_time_or_zero = atoi(value); |
|
3818 |
if (modification_time_or_zero == 0) |
|
3819 |
modification_time_or_zero = 1; // make non-zero |
|
3820 |
} |
|
3821 |
} else if (strcmp(prop, UNPACK_LOG_FILE) == 0) { |
|
3822 |
log_file = (value == null)? value: saveStr(value); |
|
3823 |
} else { |
|
3824 |
return false; // unknown option ignore |
|
3825 |
} |
|
3826 |
return true; |
|
3827 |
} |
|
3828 |
||
3829 |
// Deallocate all internal storage and reset to a clean state. |
|
3830 |
// Do not disturb any input or output connections, including |
|
3831 |
// infileptr, infileno, inbytes, read_input_fn, jarout, or errstrm. |
|
3832 |
// Do not reset any unpack options. |
|
3833 |
void unpacker::reset() { |
|
3834 |
bytes_read_before_reset += bytes_read; |
|
3835 |
bytes_written_before_reset += bytes_written; |
|
3836 |
files_written_before_reset += files_written; |
|
3837 |
classes_written_before_reset += classes_written; |
|
3838 |
segments_read_before_reset += 1; |
|
3839 |
if (verbose >= 2) { |
|
3840 |
fprintf(errstrm, |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3841 |
"After segment %d, " |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3842 |
LONG_LONG_FORMAT " bytes read and " |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3843 |
LONG_LONG_FORMAT " bytes written.\n", |
2 | 3844 |
segments_read_before_reset-1, |
3845 |
bytes_read_before_reset, bytes_written_before_reset); |
|
3846 |
fprintf(errstrm, |
|
3847 |
"After segment %d, %d files (of which %d are classes) written to output.\n", |
|
3848 |
segments_read_before_reset-1, |
|
3849 |
files_written_before_reset, classes_written_before_reset); |
|
3850 |
if (archive_next_count != 0) { |
|
3851 |
fprintf(errstrm, |
|
3852 |
"After segment %d, %d segment%s remaining (estimated).\n", |
|
3853 |
segments_read_before_reset-1, |
|
3854 |
archive_next_count, archive_next_count==1?"":"s"); |
|
3855 |
} |
|
3856 |
} |
|
3857 |
||
3858 |
unpacker save_u = (*this); // save bytewise image |
|
3859 |
infileptr = null; // make asserts happy |
|
3860 |
jniobj = null; // make asserts happy |
|
3861 |
jarout = null; // do not close the output jar |
|
3862 |
gzin = null; // do not close the input gzip stream |
|
3863 |
bytes esn; |
|
3864 |
if (errstrm_name != null) { |
|
3865 |
esn.saveFrom(errstrm_name); |
|
3866 |
} else { |
|
3867 |
esn.set(null, 0); |
|
3868 |
} |
|
3869 |
this->free(); |
|
3870 |
mtrace('s', 0, 0); // note the boundary between segments |
|
3871 |
this->init(read_input_fn); |
|
3872 |
||
3873 |
// restore selected interface state: |
|
3874 |
#define SAVE(x) this->x = save_u.x |
|
3875 |
SAVE(jniobj); |
|
3876 |
SAVE(jnienv); |
|
3877 |
SAVE(infileptr); // buffered |
|
3878 |
SAVE(infileno); // unbuffered |
|
3879 |
SAVE(inbytes); // direct |
|
3880 |
SAVE(jarout); |
|
3881 |
SAVE(gzin); |
|
3882 |
//SAVE(read_input_fn); |
|
3883 |
SAVE(errstrm); |
|
3884 |
SAVE(verbose); // verbose level, 0 means no output |
|
3885 |
SAVE(strip_compile); |
|
3886 |
SAVE(strip_debug); |
|
3887 |
SAVE(strip_jcov); |
|
3888 |
SAVE(remove_packfile); |
|
3889 |
SAVE(deflate_hint_or_zero); // ==0 means not set, otherwise -1 or 1 |
|
3890 |
SAVE(modification_time_or_zero); |
|
3891 |
SAVE(bytes_read_before_reset); |
|
3892 |
SAVE(bytes_written_before_reset); |
|
3893 |
SAVE(files_written_before_reset); |
|
3894 |
SAVE(classes_written_before_reset); |
|
3895 |
SAVE(segments_read_before_reset); |
|
3896 |
#undef SAVE |
|
3897 |
if (esn.len > 0) { |
|
3898 |
errstrm_name = saveStr(esn.strval()); |
|
3899 |
esn.free(); |
|
3900 |
} |
|
3901 |
log_file = errstrm_name; |
|
3902 |
// Note: If we use strip_names, watch out: They get nuked here. |
|
3903 |
} |
|
3904 |
||
3905 |
void unpacker::init(read_input_fn_t input_fn) { |
|
3906 |
int i; |
|
3907 |
NOT_PRODUCT(debug_u = this); |
|
3908 |
BYTES_OF(*this).clear(); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3909 |
#ifndef PRODUCT |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3910 |
free(); // just to make sure freeing is idempotent |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
3911 |
#endif |
2 | 3912 |
this->u = this; // self-reference for U_NEW macro |
3913 |
errstrm = stdout; // default error-output |
|
3914 |
log_file = LOGFILE_STDOUT; |
|
3915 |
read_input_fn = input_fn; |
|
3916 |
all_bands = band::makeBands(this); |
|
3917 |
// Make a default jar buffer; caller may safely overwrite it. |
|
3918 |
jarout = U_NEW(jar, 1); |
|
3919 |
jarout->init(this); |
|
3920 |
for (i = 0; i < ATTR_CONTEXT_LIMIT; i++) |
|
3921 |
attr_defs[i].u = u; // set up outer ptr |
|
3922 |
} |
|
3923 |
||
3924 |
const char* unpacker::get_abort_message() { |
|
3925 |
return abort_message; |
|
3926 |
} |
|
3927 |
||
3928 |
void unpacker::dump_options() { |
|
3929 |
static const char* opts[] = { |
|
3930 |
UNPACK_LOG_FILE, |
|
3931 |
UNPACK_DEFLATE_HINT, |
|
3932 |
#ifdef HAVE_STRIP |
|
3933 |
UNPACK_STRIP_COMPILE, |
|
3934 |
UNPACK_STRIP_DEBUG, |
|
3935 |
UNPACK_STRIP_JCOV, |
|
3936 |
#endif /*HAVE_STRIP*/ |
|
3937 |
UNPACK_REMOVE_PACKFILE, |
|
3938 |
DEBUG_VERBOSE, |
|
3939 |
UNPACK_MODIFICATION_TIME, |
|
3940 |
null |
|
3941 |
}; |
|
3942 |
for (int i = 0; opts[i] != null; i++) { |
|
3943 |
const char* str = get_option(opts[i]); |
|
3944 |
if (str == null) { |
|
3945 |
if (verbose == 0) continue; |
|
3946 |
str = "(not set)"; |
|
3947 |
} |
|
3948 |
fprintf(errstrm, "%s=%s\n", opts[i], str); |
|
3949 |
} |
|
3950 |
} |
|
3951 |
||
3952 |
||
3953 |
// Usage: unpack a byte buffer |
|
3954 |
// packptr is a reference to byte buffer containing a |
|
3955 |
// packed file and len is the length of the buffer. |
|
3956 |
// If null, the callback is used to fill an internal buffer. |
|
3957 |
void unpacker::start(void* packptr, size_t len) { |
|
16076 | 3958 |
CHECK; |
2 | 3959 |
NOT_PRODUCT(debug_u = this); |
3960 |
if (packptr != null && len != 0) { |
|
3961 |
inbytes.set((byte*) packptr, len); |
|
3962 |
} |
|
16076 | 3963 |
CHECK; |
2 | 3964 |
read_bands(); |
3965 |
} |
|
3966 |
||
3967 |
void unpacker::check_options() { |
|
3968 |
const char* strue = "true"; |
|
3969 |
const char* sfalse = "false"; |
|
3970 |
if (deflate_hint_or_zero != 0) { |
|
3971 |
bool force_deflate_hint = (deflate_hint_or_zero > 0); |
|
3972 |
if (force_deflate_hint) |
|
3973 |
default_file_options |= FO_DEFLATE_HINT; |
|
3974 |
else |
|
3975 |
default_file_options &= ~FO_DEFLATE_HINT; |
|
3976 |
// Turn off per-file deflate hint by force. |
|
3977 |
suppress_file_options |= FO_DEFLATE_HINT; |
|
3978 |
} |
|
3979 |
if (modification_time_or_zero != 0) { |
|
3980 |
default_file_modtime = modification_time_or_zero; |
|
3981 |
// Turn off per-file modtime by force. |
|
3982 |
archive_options &= ~AO_HAVE_FILE_MODTIME; |
|
3983 |
} |
|
3984 |
// %%% strip_compile, etc... |
|
3985 |
} |
|
3986 |
||
3987 |
// classfile writing |
|
3988 |
||
3989 |
void unpacker::reset_cur_classfile() { |
|
3990 |
// set defaults |
|
3991 |
cur_class_minver = default_class_minver; |
|
3992 |
cur_class_majver = default_class_majver; |
|
3993 |
||
3994 |
// reset constant pool state |
|
3995 |
cp.resetOutputIndexes(); |
|
3996 |
||
3997 |
// reset fixups |
|
3998 |
class_fixup_type.empty(); |
|
3999 |
class_fixup_offset.empty(); |
|
4000 |
class_fixup_ref.empty(); |
|
4001 |
requested_ics.empty(); |
|
12544 | 4002 |
cp.requested_bsms.empty(); |
2 | 4003 |
} |
4004 |
||
4005 |
cpindex* cpool::getKQIndex() { |
|
4006 |
char ch = '?'; |
|
4007 |
if (u->cur_descr != null) { |
|
4008 |
entry* type = u->cur_descr->descrType(); |
|
4009 |
ch = type->value.b.ptr[0]; |
|
4010 |
} |
|
4011 |
byte tag = CONSTANT_Integer; |
|
4012 |
switch (ch) { |
|
4013 |
case 'L': tag = CONSTANT_String; break; |
|
4014 |
case 'I': tag = CONSTANT_Integer; break; |
|
4015 |
case 'J': tag = CONSTANT_Long; break; |
|
4016 |
case 'F': tag = CONSTANT_Float; break; |
|
4017 |
case 'D': tag = CONSTANT_Double; break; |
|
4018 |
case 'B': case 'S': case 'C': |
|
4019 |
case 'Z': tag = CONSTANT_Integer; break; |
|
4020 |
default: abort("bad KQ reference"); break; |
|
4021 |
} |
|
4022 |
return getIndex(tag); |
|
4023 |
} |
|
4024 |
||
4025 |
uint unpacker::to_bci(uint bii) { |
|
4026 |
uint len = bcimap.length(); |
|
4027 |
uint* map = (uint*) bcimap.base(); |
|
4028 |
assert(len > 0); // must be initialized before using to_bci |
|
4029 |
if (bii < len) |
|
4030 |
return map[bii]; |
|
4031 |
// Else it's a fractional or out-of-range BCI. |
|
4032 |
uint key = bii-len; |
|
4033 |
for (int i = len; ; i--) { |
|
4034 |
if (map[i-1]-(i-1) <= key) |
|
4035 |
break; |
|
4036 |
else |
|
4037 |
--bii; |
|
4038 |
} |
|
4039 |
return bii; |
|
4040 |
} |
|
4041 |
||
4042 |
void unpacker::put_stackmap_type() { |
|
4043 |
int tag = code_StackMapTable_T.getByte(); |
|
4044 |
putu1(tag); |
|
4045 |
switch (tag) { |
|
4046 |
case 7: // (7) [RCH] |
|
4047 |
putref(code_StackMapTable_RC.getRef()); |
|
4048 |
break; |
|
4049 |
case 8: // (8) [PH] |
|
4050 |
putu2(to_bci(code_StackMapTable_P.getInt())); |
|
4051 |
break; |
|
4052 |
} |
|
4053 |
} |
|
4054 |
||
4055 |
// Functions for writing code. |
|
4056 |
||
4057 |
maybe_inline |
|
4058 |
void unpacker::put_label(int curIP, int size) { |
|
4059 |
code_fixup_type.addByte(size); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4060 |
code_fixup_offset.add((int)put_empty(size)); |
2 | 4061 |
code_fixup_source.add(curIP); |
4062 |
} |
|
4063 |
||
4064 |
inline // called exactly once => inline |
|
4065 |
void unpacker::write_bc_ops() { |
|
4066 |
bcimap.empty(); |
|
4067 |
code_fixup_type.empty(); |
|
4068 |
code_fixup_offset.empty(); |
|
4069 |
code_fixup_source.empty(); |
|
4070 |
||
4071 |
band* bc_which; |
|
4072 |
||
4073 |
byte* opptr = bc_codes.curRP(); |
|
4074 |
// No need for oplimit, since the codes are pre-counted. |
|
4075 |
||
4076 |
size_t codeBase = wpoffset(); |
|
4077 |
||
4078 |
bool isAload; // copy-out result |
|
4079 |
int origBC; |
|
4080 |
||
4081 |
entry* thisClass = cur_class; |
|
4082 |
entry* superClass = cur_super; |
|
4083 |
entry* newClass = null; // class of last _new opcode |
|
4084 |
||
4085 |
// overwrite any prior index on these bands; it changes w/ current class: |
|
4086 |
bc_thisfield.setIndex( cp.getFieldIndex( thisClass)); |
|
4087 |
bc_thismethod.setIndex( cp.getMethodIndex(thisClass)); |
|
4088 |
if (superClass != null) { |
|
4089 |
bc_superfield.setIndex( cp.getFieldIndex( superClass)); |
|
4090 |
bc_supermethod.setIndex(cp.getMethodIndex(superClass)); |
|
4091 |
} else { |
|
4092 |
NOT_PRODUCT(bc_superfield.setIndex(null)); |
|
4093 |
NOT_PRODUCT(bc_supermethod.setIndex(null)); |
|
4094 |
} |
|
16075 | 4095 |
CHECK; |
2 | 4096 |
|
4097 |
for (int curIP = 0; ; curIP++) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4098 |
int curPC = (int)(wpoffset() - codeBase); |
2 | 4099 |
bcimap.add(curPC); |
4100 |
ensure_put_space(10); // covers most instrs w/o further bounds check |
|
4101 |
int bc = *opptr++ & 0xFF; |
|
4102 |
||
4103 |
putu1_fast(bc); |
|
4104 |
// Note: See '--wp' below for pseudo-bytecodes like bc_end_marker. |
|
4105 |
||
4106 |
bool isWide = false; |
|
4107 |
if (bc == bc_wide) { |
|
4108 |
bc = *opptr++ & 0xFF; |
|
4109 |
putu1_fast(bc); |
|
4110 |
isWide = true; |
|
4111 |
} |
|
4112 |
switch (bc) { |
|
4113 |
case bc_end_marker: |
|
4114 |
--wp; // not really part of the code |
|
4115 |
assert(opptr <= bc_codes.maxRP()); |
|
4116 |
bc_codes.curRP() = opptr; // advance over this in bc_codes |
|
4117 |
goto doneScanningMethod; |
|
4118 |
case bc_tableswitch: // apc: (df, lo, hi, (hi-lo+1)*(label)) |
|
4119 |
case bc_lookupswitch: // apc: (df, nc, nc*(case, label)) |
|
4120 |
{ |
|
4121 |
int caseCount = bc_case_count.getInt(); |
|
4122 |
while (((wpoffset() - codeBase) % 4) != 0) putu1_fast(0); |
|
4123 |
ensure_put_space(30 + caseCount*8); |
|
4124 |
put_label(curIP, 4); //int df = bc_label.getInt(); |
|
4125 |
if (bc == bc_tableswitch) { |
|
4126 |
int lo = bc_case_value.getInt(); |
|
4127 |
int hi = lo + caseCount-1; |
|
4128 |
putu4(lo); |
|
4129 |
putu4(hi); |
|
4130 |
for (int j = 0; j < caseCount; j++) { |
|
4131 |
put_label(curIP, 4); //int lVal = bc_label.getInt(); |
|
4132 |
//int cVal = lo + j; |
|
4133 |
} |
|
4134 |
} else { |
|
4135 |
putu4(caseCount); |
|
4136 |
for (int j = 0; j < caseCount; j++) { |
|
4137 |
int cVal = bc_case_value.getInt(); |
|
4138 |
putu4(cVal); |
|
4139 |
put_label(curIP, 4); //int lVal = bc_label.getInt(); |
|
4140 |
} |
|
4141 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4142 |
assert((int)to_bci(curIP) == curPC); |
2 | 4143 |
continue; |
4144 |
} |
|
4145 |
case bc_iinc: |
|
4146 |
{ |
|
4147 |
int local = bc_local.getInt(); |
|
4148 |
int delta = (isWide ? bc_short : bc_byte).getInt(); |
|
4149 |
if (isWide) { |
|
4150 |
putu2(local); |
|
4151 |
putu2(delta); |
|
4152 |
} else { |
|
4153 |
putu1_fast(local); |
|
4154 |
putu1_fast(delta); |
|
4155 |
} |
|
4156 |
continue; |
|
4157 |
} |
|
4158 |
case bc_sipush: |
|
4159 |
{ |
|
4160 |
int val = bc_short.getInt(); |
|
4161 |
putu2(val); |
|
4162 |
continue; |
|
4163 |
} |
|
4164 |
case bc_bipush: |
|
4165 |
case bc_newarray: |
|
4166 |
{ |
|
4167 |
int val = bc_byte.getByte(); |
|
4168 |
putu1_fast(val); |
|
4169 |
continue; |
|
4170 |
} |
|
4171 |
case bc_ref_escape: |
|
4172 |
{ |
|
4173 |
// Note that insnMap has one entry for this. |
|
4174 |
--wp; // not really part of the code |
|
4175 |
int size = bc_escrefsize.getInt(); |
|
4176 |
entry* ref = bc_escref.getRefN(); |
|
4177 |
CHECK; |
|
4178 |
switch (size) { |
|
4179 |
case 1: putu1ref(ref); break; |
|
4180 |
case 2: putref(ref); break; |
|
4181 |
default: assert(false); |
|
4182 |
} |
|
4183 |
continue; |
|
4184 |
} |
|
4185 |
case bc_byte_escape: |
|
4186 |
{ |
|
4187 |
// Note that insnMap has one entry for all these bytes. |
|
4188 |
--wp; // not really part of the code |
|
4189 |
int size = bc_escsize.getInt(); |
|
4190 |
ensure_put_space(size); |
|
4191 |
for (int j = 0; j < size; j++) |
|
4192 |
putu1_fast(bc_escbyte.getByte()); |
|
4193 |
continue; |
|
4194 |
} |
|
4195 |
default: |
|
4196 |
if (is_invoke_init_op(bc)) { |
|
4197 |
origBC = bc_invokespecial; |
|
4198 |
entry* classRef; |
|
4199 |
switch (bc - _invokeinit_op) { |
|
4200 |
case _invokeinit_self_option: classRef = thisClass; break; |
|
4201 |
case _invokeinit_super_option: classRef = superClass; break; |
|
4202 |
default: assert(bc == _invokeinit_op+_invokeinit_new_option); |
|
4203 |
case _invokeinit_new_option: classRef = newClass; break; |
|
4204 |
} |
|
4205 |
wp[-1] = origBC; // overwrite with origBC |
|
4206 |
int coding = bc_initref.getInt(); |
|
4207 |
// Find the nth overloading of <init> in classRef. |
|
4208 |
entry* ref = null; |
|
16075 | 4209 |
cpindex* ix = cp.getMethodIndex(classRef); |
4210 |
CHECK; |
|
2 | 4211 |
for (int j = 0, which_init = 0; ; j++) { |
4212 |
ref = (ix == null)? null: ix->get(j); |
|
4213 |
if (ref == null) break; // oops, bad input |
|
4214 |
assert(ref->tag == CONSTANT_Methodref); |
|
4215 |
if (ref->memberDescr()->descrName() == cp.sym[cpool::s_lt_init_gt]) { |
|
4216 |
if (which_init++ == coding) break; |
|
4217 |
} |
|
4218 |
} |
|
4219 |
putref(ref); |
|
4220 |
continue; |
|
4221 |
} |
|
4222 |
bc_which = ref_band_for_self_op(bc, isAload, origBC); |
|
4223 |
if (bc_which != null) { |
|
4224 |
if (!isAload) { |
|
4225 |
wp[-1] = origBC; // overwrite with origBC |
|
4226 |
} else { |
|
4227 |
wp[-1] = bc_aload_0; // overwrite with _aload_0 |
|
4228 |
// Note: insnMap keeps the _aload_0 separate. |
|
4229 |
bcimap.add(++curPC); |
|
4230 |
++curIP; |
|
4231 |
putu1_fast(origBC); |
|
4232 |
} |
|
4233 |
entry* ref = bc_which->getRef(); |
|
4234 |
CHECK; |
|
4235 |
putref(ref); |
|
4236 |
continue; |
|
4237 |
} |
|
4238 |
if (is_branch_op(bc)) { |
|
4239 |
//int lVal = bc_label.getInt(); |
|
4240 |
if (bc < bc_goto_w) { |
|
4241 |
put_label(curIP, 2); //putu2(lVal & 0xFFFF); |
|
4242 |
} else { |
|
4243 |
assert(bc <= bc_jsr_w); |
|
4244 |
put_label(curIP, 4); //putu4(lVal); |
|
4245 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4246 |
assert((int)to_bci(curIP) == curPC); |
2 | 4247 |
continue; |
4248 |
} |
|
4249 |
bc_which = ref_band_for_op(bc); |
|
4250 |
if (bc_which != null) { |
|
4251 |
entry* ref = bc_which->getRefCommon(bc_which->ix, bc_which->nullOK); |
|
4252 |
CHECK; |
|
4253 |
if (ref == null && bc_which == &bc_classref) { |
|
4254 |
// Shorthand for class self-references. |
|
4255 |
ref = thisClass; |
|
4256 |
} |
|
4257 |
origBC = bc; |
|
4258 |
switch (bc) { |
|
16050
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4259 |
case _invokestatic_int: |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4260 |
origBC = bc_invokestatic; |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4261 |
break; |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4262 |
case _invokespecial_int: |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4263 |
origBC = bc_invokespecial; |
1eee624cddb3
8007297: [pack200] allow opcodes with InterfaceMethodRefs
ksrini
parents:
16013
diff
changeset
|
4264 |
break; |
2 | 4265 |
case bc_ildc: |
4266 |
case bc_cldc: |
|
4267 |
case bc_fldc: |
|
12544 | 4268 |
case bc_sldc: |
4269 |
case bc_qldc: |
|
2 | 4270 |
origBC = bc_ldc; |
4271 |
break; |
|
4272 |
case bc_ildc_w: |
|
4273 |
case bc_cldc_w: |
|
4274 |
case bc_fldc_w: |
|
12544 | 4275 |
case bc_sldc_w: |
4276 |
case bc_qldc_w: |
|
2 | 4277 |
origBC = bc_ldc_w; |
4278 |
break; |
|
4279 |
case bc_lldc2_w: |
|
4280 |
case bc_dldc2_w: |
|
4281 |
origBC = bc_ldc2_w; |
|
4282 |
break; |
|
4283 |
case bc_new: |
|
4284 |
newClass = ref; |
|
4285 |
break; |
|
4286 |
} |
|
4287 |
wp[-1] = origBC; // overwrite with origBC |
|
4288 |
if (origBC == bc_ldc) { |
|
4289 |
putu1ref(ref); |
|
4290 |
} else { |
|
4291 |
putref(ref); |
|
4292 |
} |
|
4293 |
if (origBC == bc_multianewarray) { |
|
4294 |
// Copy the trailing byte also. |
|
4295 |
int val = bc_byte.getByte(); |
|
4296 |
putu1_fast(val); |
|
4297 |
} else if (origBC == bc_invokeinterface) { |
|
4298 |
int argSize = ref->memberDescr()->descrType()->typeSize(); |
|
4299 |
putu1_fast(1 + argSize); |
|
4300 |
putu1_fast(0); |
|
12544 | 4301 |
} else if (origBC == bc_invokedynamic) { |
4302 |
// pad the next two byte |
|
4303 |
putu1_fast(0); |
|
4304 |
putu1_fast(0); |
|
2 | 4305 |
} |
4306 |
continue; |
|
4307 |
} |
|
4308 |
if (is_local_slot_op(bc)) { |
|
4309 |
int local = bc_local.getInt(); |
|
4310 |
if (isWide) { |
|
4311 |
putu2(local); |
|
4312 |
if (bc == bc_iinc) { |
|
4313 |
int iVal = bc_short.getInt(); |
|
4314 |
putu2(iVal); |
|
4315 |
} |
|
4316 |
} else { |
|
4317 |
putu1_fast(local); |
|
4318 |
if (bc == bc_iinc) { |
|
4319 |
int iVal = bc_byte.getByte(); |
|
4320 |
putu1_fast(iVal); |
|
4321 |
} |
|
4322 |
} |
|
4323 |
continue; |
|
4324 |
} |
|
4325 |
// Random bytecode. Just copy it. |
|
4326 |
assert(bc < bc_bytecode_limit); |
|
4327 |
} |
|
4328 |
} |
|
4329 |
doneScanningMethod:{} |
|
4330 |
//bcimap.add(curPC); // PC limit is already also in map, from bc_end_marker |
|
4331 |
||
4332 |
// Armed with a bcimap, we can now fix up all the labels. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4333 |
for (int i = 0; i < (int)code_fixup_type.size(); i++) { |
2 | 4334 |
int type = code_fixup_type.getByte(i); |
4335 |
byte* bp = wp_at(code_fixup_offset.get(i)); |
|
4336 |
int curIP = code_fixup_source.get(i); |
|
4337 |
int destIP = curIP + bc_label.getInt(); |
|
4338 |
int span = to_bci(destIP) - to_bci(curIP); |
|
4339 |
switch (type) { |
|
4340 |
case 2: putu2_at(bp, (ushort)span); break; |
|
4341 |
case 4: putu4_at(bp, span); break; |
|
4342 |
default: assert(false); |
|
4343 |
} |
|
4344 |
} |
|
4345 |
} |
|
4346 |
||
4347 |
inline // called exactly once => inline |
|
4348 |
void unpacker::write_code() { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4349 |
int j; |
2 | 4350 |
|
4351 |
int max_stack, max_locals, handler_count, cflags; |
|
4352 |
get_code_header(max_stack, max_locals, handler_count, cflags); |
|
4353 |
||
4354 |
if (max_stack < 0) max_stack = code_max_stack.getInt(); |
|
4355 |
if (max_locals < 0) max_locals = code_max_na_locals.getInt(); |
|
4356 |
if (handler_count < 0) handler_count = code_handler_count.getInt(); |
|
4357 |
||
4358 |
int siglen = cur_descr->descrType()->typeSize(); |
|
4359 |
CHECK; |
|
4360 |
if ((cur_descr_flags & ACC_STATIC) == 0) siglen++; |
|
4361 |
max_locals += siglen; |
|
4362 |
||
4363 |
putu2(max_stack); |
|
4364 |
putu2(max_locals); |
|
4365 |
size_t bcbase = put_empty(4); |
|
4366 |
||
4367 |
// Write the bytecodes themselves. |
|
4368 |
write_bc_ops(); |
|
4369 |
CHECK; |
|
4370 |
||
4371 |
byte* bcbasewp = wp_at(bcbase); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4372 |
putu4_at(bcbasewp, (int)(wp - (bcbasewp+4))); // size of code attr |
2 | 4373 |
|
4374 |
putu2(handler_count); |
|
4375 |
for (j = 0; j < handler_count; j++) { |
|
4376 |
int bii = code_handler_start_P.getInt(); |
|
4377 |
putu2(to_bci(bii)); |
|
4378 |
bii += code_handler_end_PO.getInt(); |
|
4379 |
putu2(to_bci(bii)); |
|
4380 |
bii += code_handler_catch_PO.getInt(); |
|
4381 |
putu2(to_bci(bii)); |
|
4382 |
putref(code_handler_class_RCN.getRefN()); |
|
4383 |
CHECK; |
|
4384 |
} |
|
4385 |
||
4386 |
julong indexBits = cflags; |
|
4387 |
if (cflags < 0) { |
|
4388 |
bool haveLongFlags = attr_defs[ATTR_CONTEXT_CODE].haveLongFlags(); |
|
4389 |
indexBits = code_flags_hi.getLong(code_flags_lo, haveLongFlags); |
|
4390 |
} |
|
4391 |
write_attrs(ATTR_CONTEXT_CODE, indexBits); |
|
4392 |
} |
|
4393 |
||
4394 |
int unpacker::write_attrs(int attrc, julong indexBits) { |
|
4395 |
CHECK_0; |
|
4396 |
if (indexBits == 0) { |
|
4397 |
// Quick short-circuit. |
|
4398 |
putu2(0); |
|
4399 |
return 0; |
|
4400 |
} |
|
4401 |
||
4402 |
attr_definitions& ad = attr_defs[attrc]; |
|
4403 |
||
4404 |
int i, j, j2, idx, count; |
|
4405 |
||
4406 |
int oiCount = 0; |
|
4407 |
if (ad.isPredefined(X_ATTR_OVERFLOW) |
|
4408 |
&& (indexBits & ((julong)1<<X_ATTR_OVERFLOW)) != 0) { |
|
4409 |
indexBits -= ((julong)1<<X_ATTR_OVERFLOW); |
|
4410 |
oiCount = ad.xxx_attr_count().getInt(); |
|
4411 |
} |
|
4412 |
||
4413 |
int bitIndexes[X_ATTR_LIMIT_FLAGS_HI]; |
|
4414 |
int biCount = 0; |
|
4415 |
||
4416 |
// Fill bitIndexes with index bits, in order. |
|
4417 |
for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) { |
|
4418 |
if ((indexBits & 1) != 0) |
|
4419 |
bitIndexes[biCount++] = idx; |
|
4420 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4421 |
assert(biCount <= (int)lengthof(bitIndexes)); |
2 | 4422 |
|
4423 |
// Write a provisional attribute count, perhaps to be corrected later. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4424 |
int naOffset = (int)wpoffset(); |
2 | 4425 |
int na0 = biCount + oiCount; |
4426 |
putu2(na0); |
|
4427 |
||
4428 |
int na = 0; |
|
4429 |
for (i = 0; i < na0; i++) { |
|
4430 |
if (i < biCount) |
|
4431 |
idx = bitIndexes[i]; |
|
4432 |
else |
|
4433 |
idx = ad.xxx_attr_indexes().getInt(); |
|
4434 |
assert(ad.isIndex(idx)); |
|
4435 |
entry* aname = null; |
|
4436 |
entry* ref; // scratch |
|
4437 |
size_t abase = put_empty(2+4); |
|
4438 |
CHECK_0; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4439 |
if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) { |
2 | 4440 |
// Switch on the attrc and idx simultaneously. |
4441 |
switch (ADH_BYTE(attrc, idx)) { |
|
4442 |
||
4443 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_OVERFLOW): |
|
4444 |
case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_OVERFLOW): |
|
4445 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_OVERFLOW): |
|
4446 |
case ADH_BYTE(ATTR_CONTEXT_CODE, X_ATTR_OVERFLOW): |
|
4447 |
// no attribute at all, so back up on this one |
|
4448 |
wp = wp_at(abase); |
|
4449 |
continue; |
|
4450 |
||
4451 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_ClassFile_version): |
|
4452 |
cur_class_minver = class_ClassFile_version_minor_H.getInt(); |
|
4453 |
cur_class_majver = class_ClassFile_version_major_H.getInt(); |
|
4454 |
// back up; not a real attribute |
|
4455 |
wp = wp_at(abase); |
|
4456 |
continue; |
|
4457 |
||
4458 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_InnerClasses): |
|
4459 |
// note the existence of this attr, but save for later |
|
4460 |
if (cur_class_has_local_ics) |
|
4461 |
abort("too many InnerClasses attrs"); |
|
4462 |
cur_class_has_local_ics = true; |
|
4463 |
wp = wp_at(abase); |
|
4464 |
continue; |
|
4465 |
||
4466 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_SourceFile): |
|
4467 |
aname = cp.sym[cpool::s_SourceFile]; |
|
4468 |
ref = class_SourceFile_RUN.getRefN(); |
|
4469 |
CHECK_0; |
|
4470 |
if (ref == null) { |
|
4471 |
bytes& n = cur_class->ref(0)->value.b; |
|
4472 |
// parse n = (<pkg>/)*<outer>?($<id>)* |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4473 |
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, (int)n.len)+1; |
2 | 4474 |
bytes prefix = n.slice(pkglen, n.len); |
4475 |
for (;;) { |
|
4476 |
// Work backwards, finding all '$', '#', etc. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4477 |
int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len); |
2 | 4478 |
if (dollar < 0) break; |
4479 |
prefix = prefix.slice(0, dollar); |
|
4480 |
} |
|
4481 |
const char* suffix = ".java"; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4482 |
int len = (int)(prefix.len + strlen(suffix)); |
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
4483 |
bytes name; name.set(T_NEW(byte, add_size(len, 1)), len); |
2 | 4484 |
name.strcat(prefix).strcat(suffix); |
4485 |
ref = cp.ensureUtf8(name); |
|
4486 |
} |
|
4487 |
putref(ref); |
|
4488 |
break; |
|
4489 |
||
4490 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, CLASS_ATTR_EnclosingMethod): |
|
4491 |
aname = cp.sym[cpool::s_EnclosingMethod]; |
|
4492 |
putref(class_EnclosingMethod_RC.getRefN()); |
|
16075 | 4493 |
CHECK_0; |
2 | 4494 |
putref(class_EnclosingMethod_RDN.getRefN()); |
4495 |
break; |
|
4496 |
||
4497 |
case ADH_BYTE(ATTR_CONTEXT_FIELD, FIELD_ATTR_ConstantValue): |
|
4498 |
aname = cp.sym[cpool::s_ConstantValue]; |
|
4499 |
putref(field_ConstantValue_KQ.getRefUsing(cp.getKQIndex())); |
|
4500 |
break; |
|
4501 |
||
4502 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Code): |
|
4503 |
aname = cp.sym[cpool::s_Code]; |
|
4504 |
write_code(); |
|
4505 |
break; |
|
4506 |
||
4507 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_Exceptions): |
|
4508 |
aname = cp.sym[cpool::s_Exceptions]; |
|
4509 |
putu2(count = method_Exceptions_N.getInt()); |
|
4510 |
for (j = 0; j < count; j++) { |
|
4511 |
putref(method_Exceptions_RC.getRefN()); |
|
16075 | 4512 |
CHECK_0; |
2 | 4513 |
} |
4514 |
break; |
|
4515 |
||
15261 | 4516 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, METHOD_ATTR_MethodParameters): |
4517 |
aname = cp.sym[cpool::s_MethodParameters]; |
|
4518 |
putu1(count = method_MethodParameters_NB.getByte()); |
|
4519 |
for (j = 0; j < count; j++) { |
|
4520 |
putref(method_MethodParameters_name_RUN.getRefN()); |
|
16013
3569e84e7429
8008262: pack200 should support MethodParameters - part 2
ksrini
parents:
15652
diff
changeset
|
4521 |
putu2(method_MethodParameters_flag_FH.getInt()); |
15261 | 4522 |
} |
4523 |
break; |
|
4524 |
||
2 | 4525 |
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_StackMapTable): |
4526 |
aname = cp.sym[cpool::s_StackMapTable]; |
|
4527 |
// (keep this code aligned with its brother in unpacker::read_attrs) |
|
4528 |
putu2(count = code_StackMapTable_N.getInt()); |
|
4529 |
for (j = 0; j < count; j++) { |
|
4530 |
int tag = code_StackMapTable_frame_T.getByte(); |
|
4531 |
putu1(tag); |
|
4532 |
if (tag <= 127) { |
|
4533 |
// (64-127) [(2)] |
|
4534 |
if (tag >= 64) put_stackmap_type(); |
|
4535 |
} else if (tag <= 251) { |
|
4536 |
// (247) [(1)(2)] |
|
4537 |
// (248-251) [(1)] |
|
4538 |
if (tag >= 247) putu2(code_StackMapTable_offset.getInt()); |
|
4539 |
if (tag == 247) put_stackmap_type(); |
|
4540 |
} else if (tag <= 254) { |
|
4541 |
// (252) [(1)(2)] |
|
4542 |
// (253) [(1)(2)(2)] |
|
4543 |
// (254) [(1)(2)(2)(2)] |
|
4544 |
putu2(code_StackMapTable_offset.getInt()); |
|
16075 | 4545 |
CHECK_0; |
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4546 |
for (int k = (tag - 251); k > 0; k--) { |
2 | 4547 |
put_stackmap_type(); |
16075 | 4548 |
CHECK_0; |
2 | 4549 |
} |
4550 |
} else { |
|
4551 |
// (255) [(1)NH[(2)]NH[(2)]] |
|
4552 |
putu2(code_StackMapTable_offset.getInt()); |
|
4553 |
putu2(j2 = code_StackMapTable_local_N.getInt()); |
|
16075 | 4554 |
while (j2-- > 0) {put_stackmap_type(); CHECK_0;} |
2 | 4555 |
putu2(j2 = code_StackMapTable_stack_N.getInt()); |
16075 | 4556 |
while (j2-- > 0) {put_stackmap_type(); CHECK_0;} |
2 | 4557 |
} |
4558 |
} |
|
4559 |
break; |
|
4560 |
||
4561 |
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LineNumberTable): |
|
4562 |
aname = cp.sym[cpool::s_LineNumberTable]; |
|
4563 |
putu2(count = code_LineNumberTable_N.getInt()); |
|
4564 |
for (j = 0; j < count; j++) { |
|
4565 |
putu2(to_bci(code_LineNumberTable_bci_P.getInt())); |
|
4566 |
putu2(code_LineNumberTable_line.getInt()); |
|
4567 |
} |
|
4568 |
break; |
|
4569 |
||
4570 |
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTable): |
|
4571 |
aname = cp.sym[cpool::s_LocalVariableTable]; |
|
4572 |
putu2(count = code_LocalVariableTable_N.getInt()); |
|
4573 |
for (j = 0; j < count; j++) { |
|
4574 |
int bii = code_LocalVariableTable_bci_P.getInt(); |
|
4575 |
int bci = to_bci(bii); |
|
4576 |
putu2(bci); |
|
4577 |
bii += code_LocalVariableTable_span_O.getInt(); |
|
4578 |
putu2(to_bci(bii) - bci); |
|
4579 |
putref(code_LocalVariableTable_name_RU.getRefN()); |
|
16075 | 4580 |
CHECK_0; |
2 | 4581 |
putref(code_LocalVariableTable_type_RS.getRefN()); |
16075 | 4582 |
CHECK_0; |
2 | 4583 |
putu2(code_LocalVariableTable_slot.getInt()); |
4584 |
} |
|
4585 |
break; |
|
4586 |
||
4587 |
case ADH_BYTE(ATTR_CONTEXT_CODE, CODE_ATTR_LocalVariableTypeTable): |
|
4588 |
aname = cp.sym[cpool::s_LocalVariableTypeTable]; |
|
4589 |
putu2(count = code_LocalVariableTypeTable_N.getInt()); |
|
4590 |
for (j = 0; j < count; j++) { |
|
4591 |
int bii = code_LocalVariableTypeTable_bci_P.getInt(); |
|
4592 |
int bci = to_bci(bii); |
|
4593 |
putu2(bci); |
|
4594 |
bii += code_LocalVariableTypeTable_span_O.getInt(); |
|
4595 |
putu2(to_bci(bii) - bci); |
|
4596 |
putref(code_LocalVariableTypeTable_name_RU.getRefN()); |
|
16075 | 4597 |
CHECK_0; |
2 | 4598 |
putref(code_LocalVariableTypeTable_type_RS.getRefN()); |
16075 | 4599 |
CHECK_0; |
2 | 4600 |
putu2(code_LocalVariableTypeTable_slot.getInt()); |
4601 |
} |
|
4602 |
break; |
|
4603 |
||
4604 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Signature): |
|
4605 |
aname = cp.sym[cpool::s_Signature]; |
|
4606 |
putref(class_Signature_RS.getRefN()); |
|
4607 |
break; |
|
4608 |
||
4609 |
case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Signature): |
|
4610 |
aname = cp.sym[cpool::s_Signature]; |
|
4611 |
putref(field_Signature_RS.getRefN()); |
|
4612 |
break; |
|
4613 |
||
4614 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Signature): |
|
4615 |
aname = cp.sym[cpool::s_Signature]; |
|
4616 |
putref(method_Signature_RS.getRefN()); |
|
4617 |
break; |
|
4618 |
||
4619 |
case ADH_BYTE(ATTR_CONTEXT_CLASS, X_ATTR_Deprecated): |
|
4620 |
case ADH_BYTE(ATTR_CONTEXT_FIELD, X_ATTR_Deprecated): |
|
4621 |
case ADH_BYTE(ATTR_CONTEXT_METHOD, X_ATTR_Deprecated): |
|
4622 |
aname = cp.sym[cpool::s_Deprecated]; |
|
4623 |
// no data |
|
4624 |
break; |
|
4625 |
} |
|
4626 |
} |
|
16075 | 4627 |
CHECK_0; |
2 | 4628 |
if (aname == null) { |
4629 |
// Unparse a compressor-defined attribute. |
|
4630 |
layout_definition* lo = ad.getLayout(idx); |
|
4631 |
if (lo == null) { |
|
4632 |
abort("bad layout index"); |
|
4633 |
break; |
|
4634 |
} |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4635 |
assert((int)lo->idx == idx); |
2 | 4636 |
aname = lo->nameEntry; |
4637 |
if (aname == null) { |
|
4638 |
bytes nameb; nameb.set(lo->name); |
|
4639 |
aname = cp.ensureUtf8(nameb); |
|
4640 |
// Cache the name entry for next time. |
|
4641 |
lo->nameEntry = aname; |
|
4642 |
} |
|
4643 |
// Execute all the layout elements. |
|
4644 |
band** bands = lo->bands(); |
|
4645 |
if (lo->hasCallables()) { |
|
4646 |
band& cble = *bands[0]; |
|
4647 |
assert(cble.le_kind == EK_CBLE); |
|
4648 |
bands = cble.le_body; |
|
4649 |
} |
|
4650 |
putlayout(bands); |
|
4651 |
} |
|
4652 |
||
4653 |
if (aname == null) |
|
4654 |
abort("bad attribute index"); |
|
4655 |
CHECK_0; |
|
4656 |
||
4657 |
byte* wp1 = wp; |
|
4658 |
wp = wp_at(abase); |
|
4659 |
||
4660 |
// DTRT if this attr is on the strip-list. |
|
4661 |
// (Note that we emptied the data out of the band first.) |
|
4662 |
if (ad.strip_names.contains(aname)) { |
|
4663 |
continue; |
|
4664 |
} |
|
4665 |
||
4666 |
// patch the name and length |
|
4667 |
putref(aname); |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4668 |
putu4((int)(wp1 - (wp+4))); // put the attr size |
2 | 4669 |
wp = wp1; |
4670 |
na++; // count the attrs actually written |
|
4671 |
} |
|
4672 |
||
4673 |
if (na != na0) |
|
4674 |
// Refresh changed count. |
|
4675 |
putu2_at(wp_at(naOffset), na); |
|
4676 |
return na; |
|
4677 |
} |
|
4678 |
||
4679 |
void unpacker::write_members(int num, int attrc) { |
|
4680 |
CHECK; |
|
4681 |
attr_definitions& ad = attr_defs[attrc]; |
|
4682 |
band& member_flags_hi = ad.xxx_flags_hi(); |
|
4683 |
band& member_flags_lo = ad.xxx_flags_lo(); |
|
4684 |
band& member_descr = (&member_flags_hi)[e_field_descr-e_field_flags_hi]; |
|
4685 |
assert(endsWith(member_descr.name, "_descr")); |
|
4686 |
assert(endsWith(member_flags_lo.name, "_flags_lo")); |
|
4687 |
assert(endsWith(member_flags_lo.name, "_flags_lo")); |
|
4688 |
bool haveLongFlags = ad.haveLongFlags(); |
|
4689 |
||
4690 |
putu2(num); |
|
4691 |
julong indexMask = attr_defs[attrc].flagIndexMask(); |
|
4692 |
for (int i = 0; i < num; i++) { |
|
4693 |
julong mflags = member_flags_hi.getLong(member_flags_lo, haveLongFlags); |
|
4694 |
entry* mdescr = member_descr.getRef(); |
|
4695 |
cur_descr = mdescr; |
|
4696 |
putu2(cur_descr_flags = (ushort)(mflags & ~indexMask)); |
|
4697 |
CHECK; |
|
4698 |
putref(mdescr->descrName()); |
|
4699 |
putref(mdescr->descrType()); |
|
4700 |
write_attrs(attrc, (mflags & indexMask)); |
|
4701 |
CHECK; |
|
4702 |
} |
|
4703 |
cur_descr = null; |
|
4704 |
} |
|
4705 |
||
4706 |
extern "C" |
|
4707 |
int raw_address_cmp(const void* p1p, const void* p2p) { |
|
4708 |
void* p1 = *(void**) p1p; |
|
4709 |
void* p2 = *(void**) p2p; |
|
4710 |
return (p1 > p2)? 1: (p1 < p2)? -1: 0; |
|
4711 |
} |
|
4712 |
||
12544 | 4713 |
/* |
4714 |
* writes the InnerClass attributes and returns the updated attribute |
|
4715 |
*/ |
|
4716 |
int unpacker::write_ics(int naOffset, int na) { |
|
2 | 4717 |
#ifdef ASSERT |
12544 | 4718 |
for (int i = 0; i < ic_count; i++) { |
2 | 4719 |
assert(!ics[i].requested); |
4720 |
} |
|
4721 |
#endif |
|
4722 |
// First, consult the global table and the local constant pool, |
|
4723 |
// and decide on the globally implied inner classes. |
|
4724 |
// (Note that we read the cpool's outputIndex fields, but we |
|
4725 |
// do not yet write them, since the local IC attribute might |
|
4726 |
// reverse a global decision to declare an IC.) |
|
4727 |
assert(requested_ics.length() == 0); // must start out empty |
|
4728 |
// Always include all members of the current class. |
|
4729 |
for (inner_class* child = cp.getFirstChildIC(cur_class); |
|
4730 |
child != null; |
|
4731 |
child = cp.getNextChildIC(child)) { |
|
4732 |
child->requested = true; |
|
4733 |
requested_ics.add(child); |
|
4734 |
} |
|
4735 |
// And, for each inner class mentioned in the constant pool, |
|
4736 |
// include it and all its outers. |
|
4737 |
int noes = cp.outputEntries.length(); |
|
4738 |
entry** oes = (entry**) cp.outputEntries.base(); |
|
12544 | 4739 |
for (int i = 0; i < noes; i++) { |
2 | 4740 |
entry& e = *oes[i]; |
4741 |
if (e.tag != CONSTANT_Class) continue; // wrong sort |
|
4742 |
for (inner_class* ic = cp.getIC(&e); |
|
4743 |
ic != null; |
|
4744 |
ic = cp.getIC(ic->outer)) { |
|
4745 |
if (ic->requested) break; // already processed |
|
4746 |
ic->requested = true; |
|
4747 |
requested_ics.add(ic); |
|
4748 |
} |
|
4749 |
} |
|
4750 |
int local_ics = requested_ics.length(); |
|
4751 |
// Second, consult a local attribute (if any) and adjust the global set. |
|
4752 |
inner_class* extra_ics = null; |
|
4753 |
int num_extra_ics = 0; |
|
4754 |
if (cur_class_has_local_ics) { |
|
4755 |
// adjust the set of ICs by symmetric set difference w/ the locals |
|
4756 |
num_extra_ics = class_InnerClasses_N.getInt(); |
|
4757 |
if (num_extra_ics == 0) { |
|
4758 |
// Explicit zero count has an irregular meaning: It deletes the attr. |
|
4759 |
local_ics = 0; // (short-circuit all tests of requested bits) |
|
4760 |
} else { |
|
4761 |
extra_ics = T_NEW(inner_class, num_extra_ics); |
|
4762 |
// Note: extra_ics will be freed up by next call to get_next_file(). |
|
4763 |
} |
|
4764 |
} |
|
12544 | 4765 |
for (int i = 0; i < num_extra_ics; i++) { |
2 | 4766 |
inner_class& extra_ic = extra_ics[i]; |
4767 |
extra_ic.inner = class_InnerClasses_RC.getRef(); |
|
12544 | 4768 |
CHECK_0; |
2 | 4769 |
// Find the corresponding equivalent global IC: |
4770 |
inner_class* global_ic = cp.getIC(extra_ic.inner); |
|
4771 |
int flags = class_InnerClasses_F.getInt(); |
|
4772 |
if (flags == 0) { |
|
4773 |
// The extra IC is simply a copy of a global IC. |
|
4774 |
if (global_ic == null) { |
|
4775 |
abort("bad reference to inner class"); |
|
4776 |
break; |
|
4777 |
} |
|
4778 |
extra_ic = (*global_ic); // fill in rest of fields |
|
4779 |
} else { |
|
4780 |
flags &= ~ACC_IC_LONG_FORM; // clear high bit if set to get clean zero |
|
4781 |
extra_ic.flags = flags; |
|
4782 |
extra_ic.outer = class_InnerClasses_outer_RCN.getRefN(); |
|
16075 | 4783 |
CHECK_0; |
2 | 4784 |
extra_ic.name = class_InnerClasses_name_RUN.getRefN(); |
16075 | 4785 |
CHECK_0; |
2 | 4786 |
// Detect if this is an exact copy of the global tuple. |
4787 |
if (global_ic != null) { |
|
4788 |
if (global_ic->flags != extra_ic.flags || |
|
4789 |
global_ic->outer != extra_ic.outer || |
|
4790 |
global_ic->name != extra_ic.name) { |
|
4791 |
global_ic = null; // not really the same, so break the link |
|
4792 |
} |
|
4793 |
} |
|
4794 |
} |
|
4795 |
if (global_ic != null && global_ic->requested) { |
|
4796 |
// This local repetition reverses the globally implied request. |
|
4797 |
global_ic->requested = false; |
|
4798 |
extra_ic.requested = false; |
|
4799 |
local_ics -= 1; |
|
4800 |
} else { |
|
4801 |
// The global either does not exist, or is not yet requested. |
|
4802 |
extra_ic.requested = true; |
|
4803 |
local_ics += 1; |
|
4804 |
} |
|
4805 |
} |
|
4806 |
// Finally, if there are any that survived, put them into an attribute. |
|
4807 |
// (Note that a zero-count attribute is always deleted.) |
|
4808 |
// The putref calls below will tell the constant pool to add any |
|
4809 |
// necessary local CP references to support the InnerClasses attribute. |
|
4810 |
// This step must be the last round of additions to the local CP. |
|
4811 |
if (local_ics > 0) { |
|
4812 |
// append the new attribute: |
|
4813 |
putref(cp.sym[cpool::s_InnerClasses]); |
|
4814 |
putu4(2 + 2*4*local_ics); |
|
4815 |
putu2(local_ics); |
|
4816 |
PTRLIST_QSORT(requested_ics, raw_address_cmp); |
|
4817 |
int num_global_ics = requested_ics.length(); |
|
12544 | 4818 |
for (int i = -num_global_ics; i < num_extra_ics; i++) { |
2 | 4819 |
inner_class* ic; |
4820 |
if (i < 0) |
|
4821 |
ic = (inner_class*) requested_ics.get(num_global_ics+i); |
|
4822 |
else |
|
4823 |
ic = &extra_ics[i]; |
|
4824 |
if (ic->requested) { |
|
4825 |
putref(ic->inner); |
|
4826 |
putref(ic->outer); |
|
4827 |
putref(ic->name); |
|
4828 |
putu2(ic->flags); |
|
4829 |
NOT_PRODUCT(local_ics--); |
|
4830 |
} |
|
4831 |
} |
|
4832 |
assert(local_ics == 0); // must balance |
|
4833 |
putu2_at(wp_at(naOffset), ++na); // increment class attr count |
|
4834 |
} |
|
4835 |
||
4836 |
// Tidy up global 'requested' bits: |
|
12544 | 4837 |
for (int i = requested_ics.length(); --i >= 0; ) { |
2 | 4838 |
inner_class* ic = (inner_class*) requested_ics.get(i); |
4839 |
ic->requested = false; |
|
4840 |
} |
|
4841 |
requested_ics.empty(); |
|
12544 | 4842 |
return na; |
4843 |
} |
|
4844 |
||
4845 |
/* |
|
4846 |
* Writes the BootstrapMethods attribute and returns the updated attribute count |
|
4847 |
*/ |
|
4848 |
int unpacker::write_bsms(int naOffset, int na) { |
|
4849 |
cur_class_local_bsm_count = cp.requested_bsms.length(); |
|
4850 |
if (cur_class_local_bsm_count > 0) { |
|
4851 |
int noes = cp.outputEntries.length(); |
|
4852 |
entry** oes = (entry**) cp.outputEntries.base(); |
|
4853 |
PTRLIST_QSORT(cp.requested_bsms, outputEntry_cmp); |
|
4854 |
// append the BootstrapMethods attribute (after the InnerClasses attr): |
|
4855 |
putref(cp.sym[cpool::s_BootstrapMethods]); |
|
15652
edc2e7c83709
8007902: [unpack200] incorrect BootstrapMethods attribute
ksrini
parents:
15261
diff
changeset
|
4856 |
// make a note of the offset, for lazy patching |
12544 | 4857 |
int sizeOffset = (int)wpoffset(); |
4858 |
putu4(-99); // attr size will be patched |
|
4859 |
putu2(cur_class_local_bsm_count); |
|
4860 |
int written_bsms = 0; |
|
4861 |
for (int i = 0 ; i < cur_class_local_bsm_count ; i++) { |
|
4862 |
entry* e = (entry*)cp.requested_bsms.get(i); |
|
4863 |
assert(e->outputIndex != REQUESTED_NONE); |
|
4864 |
// output index is the index within the array |
|
4865 |
e->outputIndex = i; |
|
4866 |
putref(e->refs[0]); // bsm |
|
4867 |
putu2(e->nrefs-1); // number of args after bsm |
|
4868 |
for (int j = 1; j < e->nrefs; j++) { |
|
4869 |
putref(e->refs[j]); |
|
4870 |
} |
|
4871 |
written_bsms += 1; |
|
4872 |
} |
|
4873 |
assert(written_bsms == cur_class_local_bsm_count); // else insane |
|
15652
edc2e7c83709
8007902: [unpack200] incorrect BootstrapMethods attribute
ksrini
parents:
15261
diff
changeset
|
4874 |
byte* sizewp = wp_at(sizeOffset); |
12544 | 4875 |
putu4_at(sizewp, (int)(wp - (sizewp+4))); // size of code attr |
4876 |
putu2_at(wp_at(naOffset), ++na); // increment class attr count |
|
4877 |
} |
|
4878 |
return na; |
|
4879 |
} |
|
4880 |
||
4881 |
void unpacker::write_classfile_tail() { |
|
4882 |
||
4883 |
cur_classfile_tail.empty(); |
|
4884 |
set_output(&cur_classfile_tail); |
|
4885 |
||
4886 |
int i, num; |
|
4887 |
||
4888 |
attr_definitions& ad = attr_defs[ATTR_CONTEXT_CLASS]; |
|
4889 |
||
4890 |
bool haveLongFlags = ad.haveLongFlags(); |
|
4891 |
julong kflags = class_flags_hi.getLong(class_flags_lo, haveLongFlags); |
|
4892 |
julong indexMask = ad.flagIndexMask(); |
|
4893 |
||
4894 |
cur_class = class_this.getRef(); |
|
16075 | 4895 |
CHECK; |
12544 | 4896 |
cur_super = class_super.getRef(); |
2 | 4897 |
CHECK; |
12544 | 4898 |
|
4899 |
if (cur_super == cur_class) cur_super = null; |
|
4900 |
// special representation for java/lang/Object |
|
4901 |
||
4902 |
putu2((ushort)(kflags & ~indexMask)); |
|
4903 |
putref(cur_class); |
|
4904 |
putref(cur_super); |
|
4905 |
||
4906 |
putu2(num = class_interface_count.getInt()); |
|
4907 |
for (i = 0; i < num; i++) { |
|
4908 |
putref(class_interface.getRef()); |
|
16075 | 4909 |
CHECK; |
12544 | 4910 |
} |
4911 |
||
4912 |
write_members(class_field_count.getInt(), ATTR_CONTEXT_FIELD); |
|
4913 |
write_members(class_method_count.getInt(), ATTR_CONTEXT_METHOD); |
|
4914 |
CHECK; |
|
4915 |
||
4916 |
cur_class_has_local_ics = false; // may be set true by write_attrs |
|
4917 |
||
4918 |
int naOffset = (int)wpoffset(); // note the attr count location |
|
4919 |
int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask)); |
|
4920 |
CHECK; |
|
4921 |
||
4922 |
na = write_bsms(naOffset, na); |
|
4923 |
CHECK; |
|
4924 |
||
4925 |
// choose which inner classes (if any) pertain to k: |
|
4926 |
na = write_ics(naOffset, na); |
|
4927 |
CHECK; |
|
4928 |
||
2 | 4929 |
close_output(); |
12544 | 4930 |
cp.computeOutputIndexes(); |
2 | 4931 |
|
4932 |
// rewrite CP references in the tail |
|
4933 |
int nextref = 0; |
|
4934 |
for (i = 0; i < (int)class_fixup_type.size(); i++) { |
|
4935 |
int type = class_fixup_type.getByte(i); |
|
4936 |
byte* fixp = wp_at(class_fixup_offset.get(i)); |
|
4937 |
entry* e = (entry*)class_fixup_ref.get(nextref++); |
|
4938 |
int idx = e->getOutputIndex(); |
|
4939 |
switch (type) { |
|
4940 |
case 1: putu1_at(fixp, idx); break; |
|
4941 |
case 2: putu2_at(fixp, idx); break; |
|
4942 |
default: assert(false); // should not reach here |
|
4943 |
} |
|
4944 |
} |
|
4945 |
CHECK; |
|
4946 |
} |
|
4947 |
||
4948 |
void unpacker::write_classfile_head() { |
|
4949 |
cur_classfile_head.empty(); |
|
4950 |
set_output(&cur_classfile_head); |
|
4951 |
||
4952 |
putu4(JAVA_MAGIC); |
|
4953 |
putu2(cur_class_minver); |
|
4954 |
putu2(cur_class_majver); |
|
4955 |
putu2(cp.outputIndexLimit); |
|
4956 |
||
4957 |
int checkIndex = 1; |
|
4958 |
int noes = cp.outputEntries.length(); |
|
4959 |
entry** oes = (entry**) cp.outputEntries.base(); |
|
4960 |
for (int i = 0; i < noes; i++) { |
|
4961 |
entry& e = *oes[i]; |
|
4962 |
assert(e.getOutputIndex() == checkIndex++); |
|
4963 |
byte tag = e.tag; |
|
4964 |
assert(tag != CONSTANT_Signature); |
|
4965 |
putu1(tag); |
|
4966 |
switch (tag) { |
|
4967 |
case CONSTANT_Utf8: |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
4968 |
putu2((int)e.value.b.len); |
2 | 4969 |
put_bytes(e.value.b); |
4970 |
break; |
|
4971 |
case CONSTANT_Integer: |
|
4972 |
case CONSTANT_Float: |
|
4973 |
putu4(e.value.i); |
|
4974 |
break; |
|
4975 |
case CONSTANT_Long: |
|
4976 |
case CONSTANT_Double: |
|
4977 |
putu8(e.value.l); |
|
4978 |
assert(checkIndex++); |
|
4979 |
break; |
|
4980 |
case CONSTANT_Class: |
|
4981 |
case CONSTANT_String: |
|
4982 |
// just write the ref |
|
4983 |
putu2(e.refs[0]->getOutputIndex()); |
|
4984 |
break; |
|
4985 |
case CONSTANT_Fieldref: |
|
4986 |
case CONSTANT_Methodref: |
|
4987 |
case CONSTANT_InterfaceMethodref: |
|
4988 |
case CONSTANT_NameandType: |
|
12544 | 4989 |
case CONSTANT_InvokeDynamic: |
2 | 4990 |
putu2(e.refs[0]->getOutputIndex()); |
4991 |
putu2(e.refs[1]->getOutputIndex()); |
|
4992 |
break; |
|
12544 | 4993 |
case CONSTANT_MethodHandle: |
4994 |
putu1(e.value.i); |
|
4995 |
putu2(e.refs[0]->getOutputIndex()); |
|
4996 |
break; |
|
4997 |
case CONSTANT_MethodType: |
|
4998 |
putu2(e.refs[0]->getOutputIndex()); |
|
4999 |
break; |
|
5000 |
case CONSTANT_BootstrapMethod: // should not happen |
|
2 | 5001 |
default: |
5002 |
abort(ERROR_INTERNAL); |
|
5003 |
} |
|
5004 |
} |
|
5005 |
||
5006 |
#ifndef PRODUCT |
|
5007 |
total_cp_size[0] += cp.outputIndexLimit; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5008 |
total_cp_size[1] += (int)cur_classfile_head.size(); |
2 | 5009 |
#endif |
5010 |
close_output(); |
|
5011 |
} |
|
5012 |
||
5013 |
unpacker::file* unpacker::get_next_file() { |
|
5014 |
CHECK_0; |
|
5015 |
free_temps(); |
|
5016 |
if (files_remaining == 0) { |
|
5017 |
// Leave a clue that we're exhausted. |
|
5018 |
cur_file.name = null; |
|
5019 |
cur_file.size = null; |
|
5020 |
if (archive_size != 0) { |
|
5021 |
julong predicted_size = unsized_bytes_read + archive_size; |
|
5022 |
if (predicted_size != bytes_read) |
|
5023 |
abort("archive header had incorrect size"); |
|
5024 |
} |
|
5025 |
return null; |
|
5026 |
} |
|
5027 |
files_remaining -= 1; |
|
5028 |
assert(files_written < file_count || classes_written < class_count); |
|
5029 |
cur_file.name = ""; |
|
5030 |
cur_file.size = 0; |
|
5031 |
cur_file.modtime = default_file_modtime; |
|
5032 |
cur_file.options = default_file_options; |
|
5033 |
cur_file.data[0].set(null, 0); |
|
5034 |
cur_file.data[1].set(null, 0); |
|
5035 |
if (files_written < file_count) { |
|
5036 |
entry* e = file_name.getRef(); |
|
5037 |
CHECK_0; |
|
5038 |
cur_file.name = e->utf8String(); |
|
12544 | 5039 |
bool haveLongSize = (testBit(archive_options, AO_HAVE_FILE_SIZE_HI)); |
2 | 5040 |
cur_file.size = file_size_hi.getLong(file_size_lo, haveLongSize); |
12544 | 5041 |
if (testBit(archive_options, AO_HAVE_FILE_MODTIME)) |
2 | 5042 |
cur_file.modtime += file_modtime.getInt(); //relative to archive modtime |
12544 | 5043 |
if (testBit(archive_options, AO_HAVE_FILE_OPTIONS)) |
2 | 5044 |
cur_file.options |= file_options.getInt() & ~suppress_file_options; |
5045 |
} else if (classes_written < class_count) { |
|
5046 |
// there is a class for a missing file record |
|
5047 |
cur_file.options |= FO_IS_CLASS_STUB; |
|
5048 |
} |
|
5049 |
if ((cur_file.options & FO_IS_CLASS_STUB) != 0) { |
|
5050 |
assert(classes_written < class_count); |
|
5051 |
classes_written += 1; |
|
5052 |
if (cur_file.size != 0) { |
|
5053 |
abort("class file size transmitted"); |
|
5054 |
return null; |
|
5055 |
} |
|
5056 |
reset_cur_classfile(); |
|
5057 |
||
5058 |
// write the meat of the classfile: |
|
5059 |
write_classfile_tail(); |
|
5060 |
cur_file.data[1] = cur_classfile_tail.b; |
|
5061 |
CHECK_0; |
|
5062 |
||
5063 |
// write the CP of the classfile, second: |
|
5064 |
write_classfile_head(); |
|
5065 |
cur_file.data[0] = cur_classfile_head.b; |
|
5066 |
CHECK_0; |
|
5067 |
||
5068 |
cur_file.size += cur_file.data[0].len; |
|
5069 |
cur_file.size += cur_file.data[1].len; |
|
5070 |
if (cur_file.name[0] == '\0') { |
|
5071 |
bytes& prefix = cur_class->ref(0)->value.b; |
|
5072 |
const char* suffix = ".class"; |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5073 |
int len = (int)(prefix.len + strlen(suffix)); |
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
5074 |
bytes name; name.set(T_NEW(byte, add_size(len, 1)), len); |
2 | 5075 |
cur_file.name = name.strcat(prefix).strcat(suffix).strval(); |
5076 |
} |
|
5077 |
} else { |
|
5078 |
// If there is buffered file data, produce a pointer to it. |
|
5079 |
if (cur_file.size != (size_t) cur_file.size) { |
|
5080 |
// Silly size specified. |
|
5081 |
abort("resource file too large"); |
|
5082 |
return null; |
|
5083 |
} |
|
5084 |
size_t rpleft = input_remaining(); |
|
5085 |
if (rpleft > 0) { |
|
5086 |
if (rpleft > cur_file.size) |
|
5087 |
rpleft = (size_t) cur_file.size; |
|
5088 |
cur_file.data[0].set(rp, rpleft); |
|
5089 |
rp += rpleft; |
|
5090 |
} |
|
5091 |
if (rpleft < cur_file.size) { |
|
5092 |
// Caller must read the rest. |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5093 |
size_t fleft = (size_t)cur_file.size - rpleft; |
2 | 5094 |
bytes_read += fleft; // Credit it to the overall archive size. |
5095 |
} |
|
5096 |
} |
|
5097 |
CHECK_0; |
|
5098 |
bytes_written += cur_file.size; |
|
5099 |
files_written += 1; |
|
5100 |
return &cur_file; |
|
5101 |
} |
|
5102 |
||
5103 |
// Write a file to jarout. |
|
5104 |
void unpacker::write_file_to_jar(unpacker::file* f) { |
|
5105 |
size_t htsize = f->data[0].len + f->data[1].len; |
|
5106 |
julong fsize = f->size; |
|
5107 |
#ifndef PRODUCT |
|
5108 |
if (nowrite NOT_PRODUCT(|| skipfiles-- > 0)) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5109 |
PRINTCR((2,"would write %d bytes to %s", (int) fsize, f->name)); |
2 | 5110 |
return; |
5111 |
} |
|
5112 |
#endif |
|
5113 |
if (htsize == fsize) { |
|
5114 |
jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime, |
|
5115 |
f->data[0], f->data[1]); |
|
5116 |
} else { |
|
5117 |
assert(input_remaining() == 0); |
|
5118 |
bytes part1, part2; |
|
5119 |
part1.len = f->data[0].len; |
|
5120 |
part1.set(T_NEW(byte, part1.len), part1.len); |
|
5121 |
part1.copyFrom(f->data[0]); |
|
5122 |
assert(f->data[1].len == 0); |
|
5123 |
part2.set(null, 0); |
|
5124 |
size_t fleft = (size_t) fsize - part1.len; |
|
5125 |
assert(bytes_read > fleft); // part2 already credited by get_next_file |
|
5126 |
bytes_read -= fleft; |
|
5127 |
if (fleft > 0) { |
|
5128 |
// Must read some more. |
|
5129 |
if (live_input) { |
|
5130 |
// Stop using the input buffer. Make a new one: |
|
5131 |
if (free_input) input.free(); |
|
5132 |
input.init(fleft > (1<<12) ? fleft : (1<<12)); |
|
5133 |
free_input = true; |
|
5134 |
live_input = false; |
|
5135 |
} else { |
|
5136 |
// Make it large enough. |
|
5137 |
assert(free_input); // must be reallocable |
|
5138 |
input.ensureSize(fleft); |
|
5139 |
} |
|
5140 |
rplimit = rp = input.base(); |
|
5191
79b41f733e33
6902299: Java JAR "unpack200" must verify input parameters
ksrini
parents:
3463
diff
changeset
|
5141 |
CHECK; |
2 | 5142 |
input.setLimit(rp + fleft); |
5143 |
if (!ensure_input(fleft)) |
|
5144 |
abort("EOF reading resource file"); |
|
5145 |
part2.ptr = input_scan(); |
|
5146 |
part2.len = input_remaining(); |
|
5147 |
rplimit = rp = input.base(); |
|
5148 |
} |
|
5149 |
jarout->addJarEntry(f->name, f->deflate_hint(), f->modtime, |
|
5150 |
part1, part2); |
|
5151 |
} |
|
5152 |
if (verbose >= 3) { |
|
1082
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5153 |
fprintf(errstrm, "Wrote " |
53833ff90c45
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents:
2
diff
changeset
|
5154 |
LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name); |
2 | 5155 |
} |
5156 |
} |
|
5157 |
||
5158 |
// Redirect the stdio to the specified file in the unpack.log.file option |
|
5159 |
void unpacker::redirect_stdio() { |
|
5160 |
if (log_file == null) { |
|
5161 |
log_file = LOGFILE_STDOUT; |
|
5162 |
} |
|
5163 |
if (log_file == errstrm_name) |
|
5164 |
// Nothing more to be done. |
|
5165 |
return; |
|
5166 |
errstrm_name = log_file; |
|
5167 |
if (strcmp(log_file, LOGFILE_STDERR) == 0) { |
|
5168 |
errstrm = stderr; |
|
5169 |
return; |
|
5170 |
} else if (strcmp(log_file, LOGFILE_STDOUT) == 0) { |
|
5171 |
errstrm = stdout; |
|
5172 |
return; |
|
5173 |
} else if (log_file[0] != '\0' && (errstrm = fopen(log_file,"a+")) != NULL) { |
|
5174 |
return; |
|
5175 |
} else { |
|
23920 | 5176 |
fprintf(stderr, "Can not open log file %s\n", log_file); |
2 | 5177 |
// Last resort |
5178 |
// (Do not use stdout, since it might be jarout->jarfp.) |
|
5179 |
errstrm = stderr; |
|
5180 |
log_file = errstrm_name = LOGFILE_STDERR; |
|
5181 |
} |
|
5182 |
} |
|
5183 |
||
5184 |
#ifndef PRODUCT |
|
5185 |
int unpacker::printcr_if_verbose(int level, const char* fmt ...) { |
|
17490
46864558d068
8001163: [pack200] should support attributes introduced by JSR-308
ksrini
parents:
16126
diff
changeset
|
5186 |
if (verbose < level) return 0; |
2 | 5187 |
va_list vl; |
5188 |
va_start(vl, fmt); |
|
5189 |
char fmtbuf[300]; |
|
5190 |
strcpy(fmtbuf+100, fmt); |
|
5191 |
strcat(fmtbuf+100, "\n"); |
|
5192 |
char* fmt2 = fmtbuf+100; |
|
5193 |
while (level-- > 0) *--fmt2 = ' '; |
|
5194 |
vfprintf(errstrm, fmt2, vl); |
|
5195 |
return 1; // for ?: usage |
|
5196 |
} |
|
5197 |
#endif |
|
5198 |
||
5199 |
void unpacker::abort(const char* message) { |
|
5200 |
if (message == null) message = "error unpacking archive"; |
|
5201 |
#ifdef UNPACK_JNI |
|
5202 |
if (message[0] == '@') { // secret convention for sprintf |
|
5203 |
bytes saved; |
|
5204 |
saved.saveFrom(message+1); |
|
5205 |
mallocs.add(message = saved.strval()); |
|
5206 |
} |
|
5207 |
abort_message = message; |
|
5208 |
return; |
|
5209 |
#else |
|
5210 |
if (message[0] == '@') ++message; |
|
5211 |
fprintf(errstrm, "%s\n", message); |
|
5212 |
#ifndef PRODUCT |
|
5213 |
fflush(errstrm); |
|
5214 |
::abort(); |
|
5215 |
#else |
|
5216 |
exit(-1); |
|
5217 |
#endif |
|
5218 |
#endif // JNI |
|
5219 |
} |