mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 12:04:39 +02:00
6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
Removal of compiler warnings and fixing of assert logic. Reviewed-by: jrose, ksrini, bristor
This commit is contained in:
parent
1c42f2e0d3
commit
36a04a49a7
14 changed files with 330 additions and 279 deletions
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -126,15 +126,15 @@ void band::readData(int expectedLength) {
|
||||||
(*save_meta_rp) = (byte) XB;
|
(*save_meta_rp) = (byte) XB;
|
||||||
cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null);
|
cm.init(u->rp, u->rplimit, u->meta_rp, 0, defc, length, null);
|
||||||
(*save_meta_rp) = save_meta_xb; // put it back, just to be tidy
|
(*save_meta_rp) = save_meta_xb; // put it back, just to be tidy
|
||||||
NOT_PRODUCT(cp2 = (u->meta_rp - meta_rp0));
|
NOT_PRODUCT(cp2 = (int)(u->meta_rp - meta_rp0));
|
||||||
}
|
}
|
||||||
rplimit = u->rp;
|
rplimit = u->rp;
|
||||||
|
|
||||||
rewind();
|
rewind();
|
||||||
|
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
printcr(3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]",
|
PRINTCR((3,"readFrom %s at %p [%d values, %d bytes, cp=%d/%d]",
|
||||||
(name?name:"(band)"), minRP(), length, size(), cp1, cp2);
|
(name?name:"(band)"), minRP(), length, size(), cp1, cp2));
|
||||||
if (u->verbose_bands || u->verbose >= 4) dump();
|
if (u->verbose_bands || u->verbose >= 4) dump();
|
||||||
|
|
||||||
if (ix != null && u->verbose != 0 && length > 0) {
|
if (ix != null && u->verbose != 0 && length > 0) {
|
||||||
|
@ -421,18 +421,22 @@ const band_init all_band_inits[] = {
|
||||||
BAND_INIT(file_modtime, DELTA5_spec, 0),
|
BAND_INIT(file_modtime, DELTA5_spec, 0),
|
||||||
BAND_INIT(file_options, UNSIGNED5_spec, 0),
|
BAND_INIT(file_options, UNSIGNED5_spec, 0),
|
||||||
//BAND_INIT(file_bits, BYTE1_spec, 0),
|
//BAND_INIT(file_bits, BYTE1_spec, 0),
|
||||||
{0}
|
#ifndef PRODUCT
|
||||||
|
{ 0, 0, 0, 0 }
|
||||||
|
#else
|
||||||
|
{ 0, 0 }
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
#define NUM_BAND_INITS \
|
#define NUM_BAND_INITS \
|
||||||
(sizeof(all_band_inits)/sizeof(all_band_inits[0]))
|
(sizeof(all_band_inits)/sizeof(all_band_inits[0]))
|
||||||
|
|
||||||
band* band::makeBands(unpacker* u) {
|
band* band::makeBands(unpacker* u) {
|
||||||
band* all_bands = U_NEW(band, BAND_LIMIT);
|
band* tmp_all_bands = U_NEW(band, BAND_LIMIT);
|
||||||
for (int i = 0; i < BAND_LIMIT; i++) {
|
for (int i = 0; i < BAND_LIMIT; i++) {
|
||||||
assert((byte*)&all_band_inits[i+1]
|
assert((byte*)&all_band_inits[i+1]
|
||||||
< (byte*)all_band_inits+sizeof(all_band_inits));
|
< (byte*)all_band_inits+sizeof(all_band_inits));
|
||||||
const band_init& bi = all_band_inits[i];
|
const band_init& bi = all_band_inits[i];
|
||||||
band& b = all_bands[i];
|
band& b = tmp_all_bands[i];
|
||||||
coding* defc = coding::findBySpec(bi.defc);
|
coding* defc = coding::findBySpec(bi.defc);
|
||||||
assert((defc == null) == (bi.defc == -1)); // no garbage, please
|
assert((defc == null) == (bi.defc == -1)); // no garbage, please
|
||||||
assert(defc == null || !defc->isMalloc);
|
assert(defc == null || !defc->isMalloc);
|
||||||
|
@ -446,13 +450,13 @@ band* band::makeBands(unpacker* u) {
|
||||||
b.name = bi.name;
|
b.name = bi.name;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return all_bands;
|
return tmp_all_bands;
|
||||||
}
|
}
|
||||||
|
|
||||||
void band::initIndexes(unpacker* u) {
|
void band::initIndexes(unpacker* u) {
|
||||||
band* all_bands = u->all_bands;
|
band* tmp_all_bands = u->all_bands;
|
||||||
for (int i = 0; i < BAND_LIMIT; i++) {
|
for (int i = 0; i < BAND_LIMIT; i++) {
|
||||||
band* scan = &all_bands[i];
|
band* scan = &tmp_all_bands[i];
|
||||||
uint tag = scan->ixTag; // Cf. #define INDEX(tag) above
|
uint tag = scan->ixTag; // Cf. #define INDEX(tag) above
|
||||||
if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) {
|
if (tag != 0 && tag != CONSTANT_Literal && (tag & SUBINDEX_BIT) == 0) {
|
||||||
scan->setIndex(u->cp.getIndex(tag));
|
scan->setIndex(u->cp.getIndex(tag));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -71,15 +71,17 @@ void bytes::realloc(size_t len_) {
|
||||||
|
|
||||||
void bytes::free() {
|
void bytes::free() {
|
||||||
if (ptr == dummy) return; // escaping from an error
|
if (ptr == dummy) return; // escaping from an error
|
||||||
if (ptr != null) mtrace('f', ptr, 0);
|
if (ptr != null) {
|
||||||
if (ptr != null) ::free(ptr);
|
mtrace('f', ptr, 0);
|
||||||
|
::free(ptr);
|
||||||
|
}
|
||||||
len = 0;
|
len = 0;
|
||||||
ptr = 0;
|
ptr = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes::indexOf(byte c) {
|
int bytes::indexOf(byte c) {
|
||||||
byte* p = (byte*) memchr(ptr, c, len);
|
byte* p = (byte*) memchr(ptr, c, len);
|
||||||
return (p == 0) ? -1 : p - ptr;
|
return (p == 0) ? -1 : (int)(p - ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
byte* bytes::writeTo(byte* bp) {
|
byte* bytes::writeTo(byte* bp) {
|
||||||
|
@ -174,8 +176,10 @@ void ptrlist::freeAll() {
|
||||||
int len = length();
|
int len = length();
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
void* p = (void*) get(i);
|
void* p = (void*) get(i);
|
||||||
if (p != null) mtrace('f', p, 0);
|
if (p != null) {
|
||||||
if (p != null) ::free(p);
|
mtrace('f', p, 0);
|
||||||
|
::free(p);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
free();
|
free();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -117,7 +117,7 @@ struct fillbytes {
|
||||||
|
|
||||||
struct ptrlist : fillbytes {
|
struct ptrlist : fillbytes {
|
||||||
typedef const void* cvptr;
|
typedef const void* cvptr;
|
||||||
int length() { return size() / sizeof(cvptr); }
|
int length() { return (int)(size() / sizeof(cvptr)); }
|
||||||
cvptr* base() { return (cvptr*) fillbytes::base(); }
|
cvptr* base() { return (cvptr*) fillbytes::base(); }
|
||||||
cvptr& get(int i) { return *(cvptr*)loc(i * sizeof(cvptr)); }
|
cvptr& get(int i) { return *(cvptr*)loc(i * sizeof(cvptr)); }
|
||||||
cvptr* limit() { return (cvptr*) fillbytes::limit(); }
|
cvptr* limit() { return (cvptr*) fillbytes::limit(); }
|
||||||
|
@ -133,7 +133,7 @@ struct ptrlist : fillbytes {
|
||||||
::qsort((ptrls).base(), (ptrls).length(), sizeof(void*), fn)
|
::qsort((ptrls).base(), (ptrls).length(), sizeof(void*), fn)
|
||||||
|
|
||||||
struct intlist : fillbytes {
|
struct intlist : fillbytes {
|
||||||
int length() { return size() / sizeof(int); }
|
int length() { return (int)(size() / sizeof(int)); }
|
||||||
int* base() { return (int*) fillbytes::base(); }
|
int* base() { return (int*) fillbytes::base(); }
|
||||||
int& get(int i) { return *(int*)loc(i * sizeof(int)); }
|
int& get(int i) { return *(int*)loc(i * sizeof(int)); }
|
||||||
int* limit() { return (int*) fillbytes::limit(); }
|
int* limit() { return (int*) fillbytes::limit(); }
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -113,7 +113,7 @@ coding* coding::init() {
|
||||||
jlong maxNegCode = range-1;
|
jlong maxNegCode = range-1;
|
||||||
while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode;
|
while (IS_NEG_CODE(S, maxPosCode)) --maxPosCode;
|
||||||
while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode;
|
while (!IS_NEG_CODE(S, maxNegCode)) --maxNegCode;
|
||||||
int maxPos = decode_sign(S, maxPosCode);
|
int maxPos = decode_sign(S, (uint)maxPosCode);
|
||||||
if (maxPos < 0)
|
if (maxPos < 0)
|
||||||
this->max = INT_MAX_VALUE; // 32-bit wraparound
|
this->max = INT_MAX_VALUE; // 32-bit wraparound
|
||||||
else
|
else
|
||||||
|
@ -121,7 +121,7 @@ coding* coding::init() {
|
||||||
if (maxNegCode < 0)
|
if (maxNegCode < 0)
|
||||||
this->min = 0; // No negative codings at all.
|
this->min = 0; // No negative codings at all.
|
||||||
else
|
else
|
||||||
this->min = decode_sign(S, maxNegCode);
|
this->min = decode_sign(S, (uint)maxNegCode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,10 +149,10 @@ coding* coding::findBySpec(int spec) {
|
||||||
coding* ptr = NEW(coding, 1);
|
coding* ptr = NEW(coding, 1);
|
||||||
CHECK_NULL_0(ptr);
|
CHECK_NULL_0(ptr);
|
||||||
coding* c = ptr->initFrom(spec);
|
coding* c = ptr->initFrom(spec);
|
||||||
if (c == null) mtrace('f', ptr, 0);
|
if (c == null) {
|
||||||
if (c == null)
|
mtrace('f', ptr, 0);
|
||||||
::free(ptr);
|
::free(ptr);
|
||||||
else
|
} else
|
||||||
// else caller should free it...
|
// else caller should free it...
|
||||||
c->isMalloc = true;
|
c->isMalloc = true;
|
||||||
return c;
|
return c;
|
||||||
|
@ -167,9 +167,10 @@ coding* coding::findBySpec(int B, int H, int S, int D) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void coding::free() {
|
void coding::free() {
|
||||||
if (isMalloc) mtrace('f', this, 0);
|
if (isMalloc) {
|
||||||
if (isMalloc)
|
mtrace('f', this, 0);
|
||||||
::free(this);
|
::free(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void coding_method::reset(value_stream* state) {
|
void coding_method::reset(value_stream* state) {
|
||||||
|
@ -187,7 +188,7 @@ uint coding::parse(byte* &rp, int B, int H) {
|
||||||
byte* ptr = rp;
|
byte* ptr = rp;
|
||||||
// hand peel the i==0 part of the loop:
|
// hand peel the i==0 part of the loop:
|
||||||
uint b_i = *ptr++ & 0xFF;
|
uint b_i = *ptr++ & 0xFF;
|
||||||
if (B == 1 || b_i < L)
|
if (B == 1 || b_i < (uint)L)
|
||||||
{ rp = ptr; return b_i; }
|
{ rp = ptr; return b_i; }
|
||||||
uint sum = b_i;
|
uint sum = b_i;
|
||||||
uint H_i = H;
|
uint H_i = H;
|
||||||
|
@ -195,7 +196,7 @@ uint coding::parse(byte* &rp, int B, int H) {
|
||||||
for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
|
for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
|
||||||
b_i = *ptr++ & 0xFF;
|
b_i = *ptr++ & 0xFF;
|
||||||
sum += b_i * H_i;
|
sum += b_i * H_i;
|
||||||
if (i == B || b_i < L)
|
if (i == B || b_i < (uint)L)
|
||||||
{ rp = ptr; return sum; }
|
{ rp = ptr; return sum; }
|
||||||
H_i *= H;
|
H_i *= H;
|
||||||
}
|
}
|
||||||
|
@ -210,7 +211,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) {
|
||||||
byte* ptr = rp;
|
byte* ptr = rp;
|
||||||
// hand peel the i==0 part of the loop:
|
// hand peel the i==0 part of the loop:
|
||||||
uint b_i = *ptr++ & 0xFF;
|
uint b_i = *ptr++ & 0xFF;
|
||||||
if (B == 1 || b_i < L)
|
if (B == 1 || b_i < (uint)L)
|
||||||
{ rp = ptr; return b_i; }
|
{ rp = ptr; return b_i; }
|
||||||
uint sum = b_i;
|
uint sum = b_i;
|
||||||
uint lg_H_i = lgH;
|
uint lg_H_i = lgH;
|
||||||
|
@ -218,7 +219,7 @@ uint coding::parse_lgH(byte* &rp, int B, int H, int lgH) {
|
||||||
for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
|
for (int i = 2; i <= B_MAX; i++) { // easy for compilers to unroll if desired
|
||||||
b_i = *ptr++ & 0xFF;
|
b_i = *ptr++ & 0xFF;
|
||||||
sum += b_i << lg_H_i;
|
sum += b_i << lg_H_i;
|
||||||
if (i == B || b_i < L)
|
if (i == B || b_i < (uint)L)
|
||||||
{ rp = ptr; return sum; }
|
{ rp = ptr; return sum; }
|
||||||
lg_H_i += lgH;
|
lg_H_i += lgH;
|
||||||
}
|
}
|
||||||
|
@ -237,7 +238,7 @@ void coding::parseMultiple(byte* &rp, int N, byte* limit, int B, int H) {
|
||||||
byte* ptr = rp;
|
byte* ptr = rp;
|
||||||
if (B == 1 || H == 256) {
|
if (B == 1 || H == 256) {
|
||||||
size_t len = (size_t)N*B;
|
size_t len = (size_t)N*B;
|
||||||
if (len / B != N || ptr+len > limit) {
|
if (len / B != (size_t)N || ptr+len > limit) {
|
||||||
abort(ERB);
|
abort(ERB);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -325,7 +326,7 @@ static maybe_inline
|
||||||
int getPopValue(value_stream* self, uint uval) {
|
int getPopValue(value_stream* self, uint uval) {
|
||||||
if (uval > 0) {
|
if (uval > 0) {
|
||||||
// note that the initial parse performed a range check
|
// note that the initial parse performed a range check
|
||||||
assert(uval <= self->cm->fVlength);
|
assert(uval <= (uint)self->cm->fVlength);
|
||||||
return self->cm->fValues[uval-1];
|
return self->cm->fValues[uval-1];
|
||||||
} else {
|
} else {
|
||||||
// take an unfavored value
|
// take an unfavored value
|
||||||
|
@ -368,7 +369,7 @@ int coding::sumInUnsignedRange(int x, int y) {
|
||||||
|
|
||||||
static maybe_inline
|
static maybe_inline
|
||||||
int getDeltaValue(value_stream* self, uint uval, bool isSubrange) {
|
int getDeltaValue(value_stream* self, uint uval, bool isSubrange) {
|
||||||
assert((bool)(self->c.isSubrange) == isSubrange);
|
assert((uint)(self->c.isSubrange) == (uint)isSubrange);
|
||||||
assert(self->c.isSubrange | self->c.isFullRange);
|
assert(self->c.isSubrange | self->c.isFullRange);
|
||||||
if (isSubrange)
|
if (isSubrange)
|
||||||
return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval);
|
return self->sum = self->c.sumInUnsignedRange(self->sum, (int)uval);
|
||||||
|
@ -443,7 +444,7 @@ int value_stream::getInt() {
|
||||||
uval = coding::parse(rp, B, H);
|
uval = coding::parse(rp, B, H);
|
||||||
if (S != 0)
|
if (S != 0)
|
||||||
uval = (uint) decode_sign(S, uval);
|
uval = (uint) decode_sign(S, uval);
|
||||||
return getDeltaValue(this, uval, c.isSubrange);
|
return getDeltaValue(this, uval, (bool)c.isSubrange);
|
||||||
|
|
||||||
case cmk_BHS1D1full:
|
case cmk_BHS1D1full:
|
||||||
assert(S == 1 && D == 1 && c.isFullRange);
|
assert(S == 1 && D == 1 && c.isFullRange);
|
||||||
|
@ -499,6 +500,9 @@ int value_stream::getInt() {
|
||||||
assert(c.spec == BYTE1_spec);
|
assert(c.spec == BYTE1_spec);
|
||||||
assert(B == 1 && H == 256 && S == 0 && D == 0);
|
assert(B == 1 && H == 256 && S == 0 && D == 0);
|
||||||
return getPopValue(this, *rp++ & 0xFF);
|
return getPopValue(this, *rp++ & 0xFF);
|
||||||
|
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
assert(false);
|
assert(false);
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -695,7 +699,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit,
|
||||||
for (int i = 0; i < N; i++) {
|
for (int i = 0; i < N; i++) {
|
||||||
uint val = vs.getInt();
|
uint val = vs.getInt();
|
||||||
if (val == 0) UN += 1;
|
if (val == 0) UN += 1;
|
||||||
if (!(val <= fVlength)) {
|
if (!(val <= (uint)fVlength)) {
|
||||||
abort("pop token out of range");
|
abort("pop token out of range");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -728,6 +732,7 @@ void coding_method::init(byte* &band_rp, byte* band_limit,
|
||||||
switch (self->vs0.cmk) {
|
switch (self->vs0.cmk) {
|
||||||
case cmk_BHS0: cmk2 = cmk_pop_BHS0; break;
|
case cmk_BHS0: cmk2 = cmk_pop_BHS0; break;
|
||||||
case cmk_BYTE1: cmk2 = cmk_pop_BYTE1; break;
|
case cmk_BYTE1: cmk2 = cmk_pop_BYTE1; break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
self->vs0.cmk = cmk2;
|
self->vs0.cmk = cmk2;
|
||||||
if (self != this) {
|
if (self != this) {
|
||||||
|
@ -947,15 +952,17 @@ coding basic_codings[] = {
|
||||||
CODING_INIT(4,240,1,1),
|
CODING_INIT(4,240,1,1),
|
||||||
CODING_INIT(4,248,0,1),
|
CODING_INIT(4,248,0,1),
|
||||||
CODING_INIT(4,248,1,1),
|
CODING_INIT(4,248,1,1),
|
||||||
|
CODING_INIT(0,0,0,0)
|
||||||
0
|
|
||||||
};
|
};
|
||||||
#define BASIC_INDEX_LIMIT \
|
#define BASIC_INDEX_LIMIT \
|
||||||
(sizeof(basic_codings)/sizeof(basic_codings[0])-1)
|
(int)(sizeof(basic_codings)/sizeof(basic_codings[0])-1)
|
||||||
|
|
||||||
coding* coding::findByIndex(int idx) {
|
coding* coding::findByIndex(int idx) {
|
||||||
assert(_meta_canon_min == 1);
|
#ifndef PRODUCT
|
||||||
assert(_meta_canon_max+1 == BASIC_INDEX_LIMIT);
|
/* Tricky assert here, constants and gcc complains about it without local. */
|
||||||
|
int index_limit = BASIC_INDEX_LIMIT;
|
||||||
|
assert(_meta_canon_min == 1 && _meta_canon_max+1 == index_limit);
|
||||||
|
#endif
|
||||||
if (idx >= _meta_canon_min && idx <= _meta_canon_max)
|
if (idx >= _meta_canon_min && idx <= _meta_canon_max)
|
||||||
return basic_codings[idx].init();
|
return basic_codings[idx].init();
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -35,9 +35,11 @@ struct unpacker;
|
||||||
#define CODING_D(x) ((x)>>0 & 0xF)
|
#define CODING_D(x) ((x)>>0 & 0xF)
|
||||||
|
|
||||||
#define CODING_INIT(B, H, S, D) \
|
#define CODING_INIT(B, H, S, D) \
|
||||||
{ CODING_SPEC(B, H, S, D) }
|
{ CODING_SPEC(B, H, S, D) , 0, 0, 0, 0, 0, 0, 0, 0}
|
||||||
|
|
||||||
#define long do_not_use_C_long_types_use_jlong_or_int
|
// For debugging purposes, some compilers do not like this and will complain.
|
||||||
|
// #define long do_not_use_C_long_types_use_jlong_or_int
|
||||||
|
// Use of the type "long" is problematic, do not use it.
|
||||||
|
|
||||||
struct coding {
|
struct coding {
|
||||||
int spec; // B,H,S,D
|
int spec; // B,H,S,D
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -45,15 +45,15 @@
|
||||||
#ifdef PRODUCT
|
#ifdef PRODUCT
|
||||||
#define IF_PRODUCT(xxx) xxx
|
#define IF_PRODUCT(xxx) xxx
|
||||||
#define NOT_PRODUCT(xxx)
|
#define NOT_PRODUCT(xxx)
|
||||||
#define assert(p) (0)
|
#define assert(p)
|
||||||
#define printcr false &&
|
#define PRINTCR(args)
|
||||||
#else
|
#else
|
||||||
#define IF_PRODUCT(xxx)
|
#define IF_PRODUCT(xxx)
|
||||||
#define NOT_PRODUCT(xxx) xxx
|
#define NOT_PRODUCT(xxx) xxx
|
||||||
#define assert(p) ((p) || (assert_failed(#p), 1))
|
#define assert(p) ((p) || assert_failed(#p))
|
||||||
#define printcr u->verbose && u->printcr_if_verbose
|
#define PRINTCR(args) u->verbose && u->printcr_if_verbose args
|
||||||
extern "C" void breakpoint();
|
extern "C" void breakpoint();
|
||||||
extern void assert_failed(const char*);
|
extern int assert_failed(const char*);
|
||||||
#define BREAK (breakpoint())
|
#define BREAK (breakpoint())
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ extern void assert_failed(const char*);
|
||||||
|
|
||||||
#define lengthof(array) (sizeof(array)/sizeof(array[0]))
|
#define lengthof(array) (sizeof(array)/sizeof(array[0]))
|
||||||
|
|
||||||
#define NEW(T, n) (T*) must_malloc(sizeof(T)*(n))
|
#define NEW(T, n) (T*) must_malloc((int)(sizeof(T)*(n)))
|
||||||
#define U_NEW(T, n) (T*) u->alloc(sizeof(T)*(n))
|
#define U_NEW(T, n) (T*) u->alloc(sizeof(T)*(n))
|
||||||
#define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n))
|
#define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n))
|
||||||
|
|
||||||
|
@ -121,12 +121,12 @@ enum { false, true };
|
||||||
|
|
||||||
#define null (0)
|
#define null (0)
|
||||||
|
|
||||||
#ifndef __sparc
|
/* Must cast to void *, then size_t, then int. */
|
||||||
#define intptr_t jlong
|
#define ptrlowbits(x) ((int)(size_t)(void*)(x))
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ptrlowbits(x) ((int) (intptr_t)(x))
|
|
||||||
|
|
||||||
|
/* Back and forth from jlong to pointer */
|
||||||
|
#define ptr2jlong(x) ((jlong)(size_t)(void*)(x))
|
||||||
|
#define jlong2ptr(x) ((void*)(size_t)(x))
|
||||||
|
|
||||||
// Keys used by Java:
|
// Keys used by Java:
|
||||||
#define UNPACK_DEFLATE_HINT "unpack.deflate.hint"
|
#define UNPACK_DEFLATE_HINT "unpack.deflate.hint"
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -59,7 +59,8 @@ static jlong read_input_via_jni(unpacker* self,
|
||||||
void* buf, jlong minlen, jlong maxlen);
|
void* buf, jlong minlen, jlong maxlen);
|
||||||
|
|
||||||
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
|
static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
|
||||||
unpacker* uPtr = (unpacker*) env->GetLongField(pObj, unpackerPtrFID);
|
unpacker* uPtr;
|
||||||
|
uPtr = (unpacker*)jlong2ptr(env->GetLongField(pObj, unpackerPtrFID));
|
||||||
//fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr);
|
//fprintf(stderr, "get_unpacker(%p) uPtr=%p\n", pObj, uPtr);
|
||||||
if (uPtr == null) {
|
if (uPtr == null) {
|
||||||
if (noCreate) return null;
|
if (noCreate) return null;
|
||||||
|
@ -71,7 +72,7 @@ static unpacker* get_unpacker(JNIEnv *env, jobject pObj, bool noCreate=false) {
|
||||||
//fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
|
//fprintf(stderr, "get_unpacker(%p) uPtr=%p initializing\n", pObj, uPtr);
|
||||||
uPtr->init(read_input_via_jni);
|
uPtr->init(read_input_via_jni);
|
||||||
uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
|
uPtr->jniobj = (void*) env->NewGlobalRef(pObj);
|
||||||
env->SetLongField(pObj, unpackerPtrFID, (jlong)uPtr);
|
env->SetLongField(pObj, unpackerPtrFID, ptr2jlong(uPtr));
|
||||||
}
|
}
|
||||||
uPtr->jnienv = env; // keep refreshing this in case of MT access
|
uPtr->jnienv = env; // keep refreshing this in case of MT access
|
||||||
return uPtr;
|
return uPtr;
|
||||||
|
@ -150,7 +151,7 @@ Java_com_sun_java_util_jar_pack_NativeUnpack_start(JNIEnv *env, jobject pObj,
|
||||||
size_t buflen = 0;
|
size_t buflen = 0;
|
||||||
if (pBuf != null) {
|
if (pBuf != null) {
|
||||||
buf = env->GetDirectBufferAddress(pBuf);
|
buf = env->GetDirectBufferAddress(pBuf);
|
||||||
buflen = env->GetDirectBufferCapacity(pBuf);
|
buflen = (size_t)env->GetDirectBufferCapacity(pBuf);
|
||||||
if (buflen == 0) buf = null;
|
if (buflen == 0) buf = null;
|
||||||
if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; }
|
if (buf == null) { THROW_IOE(ERROR_INTERNAL); return 0; }
|
||||||
if ((size_t)offset >= buflen)
|
if ((size_t)offset >= buflen)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2003-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -86,13 +86,13 @@ static jlong read_input_via_stdio(unpacker* u,
|
||||||
readlen = (int)(maxlen - numread);
|
readlen = (int)(maxlen - numread);
|
||||||
int nr = 0;
|
int nr = 0;
|
||||||
if (u->infileptr != null) {
|
if (u->infileptr != null) {
|
||||||
nr = fread(bufptr, 1, readlen, u->infileptr);
|
nr = (int)fread(bufptr, 1, readlen, u->infileptr);
|
||||||
} else {
|
} else {
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
// we prefer unbuffered inputs
|
// we prefer unbuffered inputs
|
||||||
nr = read(u->infileno, bufptr, readlen);
|
nr = (int)read(u->infileno, bufptr, readlen);
|
||||||
#else
|
#else
|
||||||
nr = fread(bufptr, 1, readlen, stdin);
|
nr = (int)fread(bufptr, 1, readlen, stdin);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
if (nr <= 0) {
|
if (nr <= 0) {
|
||||||
|
@ -279,7 +279,6 @@ int unpacker::run(int argc, char **argv) {
|
||||||
char** argbuf = init_args(argc, argv, envargc);
|
char** argbuf = init_args(argc, argv, envargc);
|
||||||
char** arg0 = argbuf+envargc;
|
char** arg0 = argbuf+envargc;
|
||||||
char** argp = argbuf;
|
char** argp = argbuf;
|
||||||
int ach;
|
|
||||||
|
|
||||||
int verbose = 0;
|
int verbose = 0;
|
||||||
char* logfile = null;
|
char* logfile = null;
|
||||||
|
@ -370,7 +369,7 @@ int unpacker::run(int argc, char **argv) {
|
||||||
int magic;
|
int magic;
|
||||||
|
|
||||||
// check for GZIP input
|
// check for GZIP input
|
||||||
magic = read_magic(&u, peek, sizeof(peek));
|
magic = read_magic(&u, peek, (int)sizeof(peek));
|
||||||
if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC) {
|
if ((magic & GZIP_MAGIC_MASK) == GZIP_MAGIC) {
|
||||||
// Oops; must slap an input filter on this data.
|
// Oops; must slap an input filter on this data.
|
||||||
setup_gzin(&u);
|
setup_gzin(&u);
|
||||||
|
@ -397,8 +396,8 @@ int unpacker::run(int argc, char **argv) {
|
||||||
if (u.aborting()) break;
|
if (u.aborting()) break;
|
||||||
|
|
||||||
// Peek ahead for more data.
|
// Peek ahead for more data.
|
||||||
magic = read_magic(&u, peek, sizeof(peek));
|
magic = read_magic(&u, peek, (int)sizeof(peek));
|
||||||
if (magic != JAVA_PACKAGE_MAGIC) {
|
if (magic != (int)JAVA_PACKAGE_MAGIC) {
|
||||||
if (magic != EOF_MAGIC)
|
if (magic != EOF_MAGIC)
|
||||||
u.abort("garbage after end of pack archive");
|
u.abort("garbage after end of pack archive");
|
||||||
break; // all done
|
break; // all done
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -27,6 +27,21 @@
|
||||||
// Program for unpacking specially compressed Java packages.
|
// Program for unpacking specially compressed Java packages.
|
||||||
// John R. Rose
|
// John R. Rose
|
||||||
|
|
||||||
|
/*
|
||||||
|
* When compiling for a 64bit LP64 system (longs and pointers being 64bits),
|
||||||
|
* the printf format %ld is correct and use of %lld will cause warning
|
||||||
|
* errors from some compilers (gcc/g++).
|
||||||
|
* _LP64 can be explicitly set (used on Linux).
|
||||||
|
* Solaris compilers will define __sparcv9 or __x86_64 on 64bit compilations.
|
||||||
|
*/
|
||||||
|
#if defined(_LP64) || defined(__sparcv9) || defined(__x86_64)
|
||||||
|
#define LONG_LONG_FORMAT "%ld"
|
||||||
|
#define LONG_LONG_HEX_FORMAT "%lx"
|
||||||
|
#else
|
||||||
|
#define LONG_LONG_FORMAT "%lld"
|
||||||
|
#define LONG_LONG_HEX_FORMAT "%016llx"
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -253,12 +268,12 @@ int entry::typeSize() {
|
||||||
|
|
||||||
inline cpindex* cpool::getFieldIndex(entry* classRef) {
|
inline cpindex* cpool::getFieldIndex(entry* classRef) {
|
||||||
assert(classRef->tagMatches(CONSTANT_Class));
|
assert(classRef->tagMatches(CONSTANT_Class));
|
||||||
assert((uint)classRef->inord < tag_count[CONSTANT_Class]);
|
assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
|
||||||
return &member_indexes[classRef->inord*2+0];
|
return &member_indexes[classRef->inord*2+0];
|
||||||
}
|
}
|
||||||
inline cpindex* cpool::getMethodIndex(entry* classRef) {
|
inline cpindex* cpool::getMethodIndex(entry* classRef) {
|
||||||
assert(classRef->tagMatches(CONSTANT_Class));
|
assert(classRef->tagMatches(CONSTANT_Class));
|
||||||
assert((uint)classRef->inord < tag_count[CONSTANT_Class]);
|
assert((uint)classRef->inord < (uint)tag_count[CONSTANT_Class]);
|
||||||
return &member_indexes[classRef->inord*2+1];
|
return &member_indexes[classRef->inord*2+1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +356,7 @@ bool unpacker::ensure_input(jlong more) {
|
||||||
rplimit += nr;
|
rplimit += nr;
|
||||||
fetch -= nr;
|
fetch -= nr;
|
||||||
bytes_read += nr;
|
bytes_read += nr;
|
||||||
assert(remaining == (input.limit() - rplimit));
|
assert(remaining == (julong)(input.limit() - rplimit));
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -441,9 +456,13 @@ int unpacker::putref_index(entry* e, int size) {
|
||||||
e->requestOutputIndex(cp, -size);
|
e->requestOutputIndex(cp, -size);
|
||||||
// Later on we'll fix the bits.
|
// Later on we'll fix the bits.
|
||||||
class_fixup_type.addByte(size);
|
class_fixup_type.addByte(size);
|
||||||
class_fixup_offset.add(wpoffset());
|
class_fixup_offset.add((int)wpoffset());
|
||||||
class_fixup_ref.add(e);
|
class_fixup_ref.add(e);
|
||||||
return !assert(1) ? 0 : 0x20+size; // 0x22 is easy to eyeball
|
#ifdef PRODUCT
|
||||||
|
return 0;
|
||||||
|
#else
|
||||||
|
return 0x20+size; // 0x22 is easy to eyeball
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -472,7 +491,7 @@ enum { CHUNK = (1 << 14), SMALL = (1 << 9) };
|
||||||
void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
|
void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
|
||||||
CHECK_0;
|
CHECK_0;
|
||||||
if (!smallOK || size > SMALL) {
|
if (!smallOK || size > SMALL) {
|
||||||
void* res = must_malloc(size);
|
void* res = must_malloc((int)size);
|
||||||
(temp ? &tmallocs : &mallocs)->add(res);
|
(temp ? &tmallocs : &mallocs)->add(res);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
@ -481,7 +500,7 @@ void* unpacker::alloc_heap(size_t size, bool smallOK, bool temp) {
|
||||||
xsmallbuf.init(CHUNK);
|
xsmallbuf.init(CHUNK);
|
||||||
(temp ? &tmallocs : &mallocs)->add(xsmallbuf.base());
|
(temp ? &tmallocs : &mallocs)->add(xsmallbuf.base());
|
||||||
}
|
}
|
||||||
int growBy = size;
|
int growBy = (int)size;
|
||||||
growBy += -growBy & 7; // round up mod 8
|
growBy += -growBy & 7; // round up mod 8
|
||||||
return xsmallbuf.grow(growBy);
|
return xsmallbuf.grow(growBy);
|
||||||
}
|
}
|
||||||
|
@ -514,7 +533,7 @@ void unpacker::read_file_header() {
|
||||||
FIRST_READ = MAGIC_BYTES + AH_LENGTH_MIN
|
FIRST_READ = MAGIC_BYTES + AH_LENGTH_MIN
|
||||||
};
|
};
|
||||||
bool foreign_buf = (read_input_fn == null);
|
bool foreign_buf = (read_input_fn == null);
|
||||||
byte initbuf[FIRST_READ + C_SLOP + 200]; // 200 is for JAR I/O
|
byte initbuf[(int)FIRST_READ + (int)C_SLOP + 200]; // 200 is for JAR I/O
|
||||||
if (foreign_buf) {
|
if (foreign_buf) {
|
||||||
// inbytes is all there is
|
// inbytes is all there is
|
||||||
input.set(inbytes);
|
input.set(inbytes);
|
||||||
|
@ -553,7 +572,7 @@ void unpacker::read_file_header() {
|
||||||
// Copy until EOF; assume the JAR file is the last segment.
|
// Copy until EOF; assume the JAR file is the last segment.
|
||||||
fprintf(errstrm, "Copy-mode.\n");
|
fprintf(errstrm, "Copy-mode.\n");
|
||||||
for (;;) {
|
for (;;) {
|
||||||
jarout->write_data(rp, input_remaining());
|
jarout->write_data(rp, (int)input_remaining());
|
||||||
if (foreign_buf)
|
if (foreign_buf)
|
||||||
break; // one-time use of a passed in buffer
|
break; // one-time use of a passed in buffer
|
||||||
if (input.size() < CHUNK) {
|
if (input.size() < CHUNK) {
|
||||||
|
@ -572,7 +591,7 @@ void unpacker::read_file_header() {
|
||||||
|
|
||||||
// Read the magic number.
|
// Read the magic number.
|
||||||
magic = 0;
|
magic = 0;
|
||||||
for (int i1 = 0; i1 < sizeof(magic); i1++) {
|
for (int i1 = 0; i1 < (int)sizeof(magic); i1++) {
|
||||||
magic <<= 8;
|
magic <<= 8;
|
||||||
magic += (*rp++ & 0xFF);
|
magic += (*rp++ & 0xFF);
|
||||||
}
|
}
|
||||||
|
@ -586,7 +605,7 @@ void unpacker::read_file_header() {
|
||||||
majver = hdr.getInt();
|
majver = hdr.getInt();
|
||||||
hdrVals += 2;
|
hdrVals += 2;
|
||||||
|
|
||||||
if (magic != JAVA_PACKAGE_MAGIC ||
|
if (magic != (int)JAVA_PACKAGE_MAGIC ||
|
||||||
(majver != JAVA5_PACKAGE_MAJOR_VERSION &&
|
(majver != JAVA5_PACKAGE_MAJOR_VERSION &&
|
||||||
majver != JAVA6_PACKAGE_MAJOR_VERSION) ||
|
majver != JAVA6_PACKAGE_MAJOR_VERSION) ||
|
||||||
(minver != JAVA5_PACKAGE_MINOR_VERSION &&
|
(minver != JAVA5_PACKAGE_MINOR_VERSION &&
|
||||||
|
@ -633,19 +652,19 @@ void unpacker::read_file_header() {
|
||||||
// Now we can size the whole archive.
|
// Now we can size the whole archive.
|
||||||
// Read everything else into a mega-buffer.
|
// Read everything else into a mega-buffer.
|
||||||
rp = hdr.rp;
|
rp = hdr.rp;
|
||||||
int header_size_0 = (rp - input.base()); // used-up header (4byte + 3int)
|
int header_size_0 = (int)(rp - input.base()); // used-up header (4byte + 3int)
|
||||||
int header_size_1 = (rplimit - rp); // buffered unused initial fragment
|
int header_size_1 = (int)(rplimit - rp); // buffered unused initial fragment
|
||||||
int header_size = header_size_0+header_size_1;
|
int header_size = header_size_0+header_size_1;
|
||||||
unsized_bytes_read = header_size_0;
|
unsized_bytes_read = header_size_0;
|
||||||
CHECK;
|
CHECK;
|
||||||
if (foreign_buf) {
|
if (foreign_buf) {
|
||||||
if (archive_size > header_size_1) {
|
if (archive_size > (size_t)header_size_1) {
|
||||||
abort("EOF reading fixed input buffer");
|
abort("EOF reading fixed input buffer");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (archive_size > 0) {
|
} else if (archive_size > 0) {
|
||||||
input.set(U_NEW(byte, (size_t) header_size_0 + archive_size + C_SLOP),
|
input.set(U_NEW(byte, (size_t)(header_size_0 + archive_size + C_SLOP)),
|
||||||
(size_t) header_size_0 + archive_size);
|
(size_t) header_size_0 + (size_t)archive_size);
|
||||||
assert(input.limit()[0] == 0);
|
assert(input.limit()[0] == 0);
|
||||||
// Move all the bytes we read initially into the real buffer.
|
// Move all the bytes we read initially into the real buffer.
|
||||||
input.b.copyFrom(initbuf, header_size);
|
input.b.copyFrom(initbuf, header_size);
|
||||||
|
@ -712,7 +731,7 @@ void unpacker::read_file_header() {
|
||||||
}
|
}
|
||||||
|
|
||||||
int cp_counts[N_TAGS_IN_ORDER];
|
int cp_counts[N_TAGS_IN_ORDER];
|
||||||
for (int k = 0; k < N_TAGS_IN_ORDER; k++) {
|
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
|
||||||
if (!(archive_options & AO_HAVE_CP_NUMBERS)) {
|
if (!(archive_options & AO_HAVE_CP_NUMBERS)) {
|
||||||
switch (TAGS_IN_ORDER[k]) {
|
switch (TAGS_IN_ORDER[k]) {
|
||||||
case CONSTANT_Integer:
|
case CONSTANT_Integer:
|
||||||
|
@ -753,7 +772,10 @@ void unpacker::read_file_header() {
|
||||||
abort("EOF reading archive header");
|
abort("EOF reading archive header");
|
||||||
|
|
||||||
// Now size the CP.
|
// Now size the CP.
|
||||||
assert(N_TAGS_IN_ORDER == cpool::NUM_COUNTS);
|
#ifndef PRODUCT
|
||||||
|
bool x = (N_TAGS_IN_ORDER == cpool::NUM_COUNTS);
|
||||||
|
assert(x);
|
||||||
|
#endif //PRODUCT
|
||||||
cp.init(this, cp_counts);
|
cp.init(this, cp_counts);
|
||||||
CHECK;
|
CHECK;
|
||||||
|
|
||||||
|
@ -766,7 +788,7 @@ void unpacker::read_file_header() {
|
||||||
// meta-bytes, if any, immediately follow archive header
|
// meta-bytes, if any, immediately follow archive header
|
||||||
//band_headers.readData(band_headers_size);
|
//band_headers.readData(band_headers_size);
|
||||||
ensure_input(band_headers_size);
|
ensure_input(band_headers_size);
|
||||||
if (input_remaining() < band_headers_size) {
|
if (input_remaining() < (size_t)band_headers_size) {
|
||||||
abort("EOF reading band headers");
|
abort("EOF reading band headers");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -789,12 +811,14 @@ void unpacker::read_file_header() {
|
||||||
void unpacker::finish() {
|
void unpacker::finish() {
|
||||||
if (verbose >= 1) {
|
if (verbose >= 1) {
|
||||||
fprintf(errstrm,
|
fprintf(errstrm,
|
||||||
"A total of %lld bytes were read in %d segment(s).\n",
|
"A total of "
|
||||||
bytes_read_before_reset+bytes_read,
|
LONG_LONG_FORMAT " bytes were read in %d segment(s).\n",
|
||||||
|
(bytes_read_before_reset+bytes_read),
|
||||||
segments_read_before_reset+1);
|
segments_read_before_reset+1);
|
||||||
fprintf(errstrm,
|
fprintf(errstrm,
|
||||||
"A total of %lld file content bytes were written.\n",
|
"A total of "
|
||||||
bytes_written_before_reset+bytes_written);
|
LONG_LONG_FORMAT " file content bytes were written.\n",
|
||||||
|
(bytes_written_before_reset+bytes_written));
|
||||||
fprintf(errstrm,
|
fprintf(errstrm,
|
||||||
"A total of %d files (of which %d are classes) were written to output.\n",
|
"A total of %d files (of which %d are classes) were written to output.\n",
|
||||||
files_written_before_reset+files_written,
|
files_written_before_reset+files_written,
|
||||||
|
@ -822,7 +846,7 @@ void cpool::init(unpacker* u_, int counts[NUM_COUNTS]) {
|
||||||
int next_entry = 0;
|
int next_entry = 0;
|
||||||
|
|
||||||
// Size the constant pool:
|
// Size the constant pool:
|
||||||
for (int k = 0; k < N_TAGS_IN_ORDER; k++) {
|
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
|
||||||
byte tag = TAGS_IN_ORDER[k];
|
byte tag = TAGS_IN_ORDER[k];
|
||||||
int len = counts[k];
|
int len = counts[k];
|
||||||
tag_count[tag] = len;
|
tag_count[tag] = len;
|
||||||
|
@ -902,8 +926,8 @@ static byte* skip_Utf8_chars(byte* cp, int len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int compare_Utf8_chars(bytes& b1, bytes& b2) {
|
static int compare_Utf8_chars(bytes& b1, bytes& b2) {
|
||||||
int l1 = b1.len;
|
int l1 = (int)b1.len;
|
||||||
int l2 = b2.len;
|
int l2 = (int)b2.len;
|
||||||
int l0 = (l1 < l2) ? l1 : l2;
|
int l0 = (l1 < l2) ? l1 : l2;
|
||||||
byte* p1 = b1.ptr;
|
byte* p1 = b1.ptr;
|
||||||
byte* p2 = b2.ptr;
|
byte* p2 = b2.ptr;
|
||||||
|
@ -949,10 +973,12 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
// First band: Read lengths of shared prefixes.
|
// First band: Read lengths of shared prefixes.
|
||||||
if (len > PREFIX_SKIP_2)
|
if (len > PREFIX_SKIP_2)
|
||||||
cp_Utf8_prefix.readData(len - PREFIX_SKIP_2);
|
cp_Utf8_prefix.readData(len - PREFIX_SKIP_2);
|
||||||
|
NOT_PRODUCT(else cp_Utf8_prefix.readData(0)); // for asserts
|
||||||
|
|
||||||
// Second band: Read lengths of unshared suffixes:
|
// Second band: Read lengths of unshared suffixes:
|
||||||
if (len > SUFFIX_SKIP_1)
|
if (len > SUFFIX_SKIP_1)
|
||||||
cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1);
|
cp_Utf8_suffix.readData(len - SUFFIX_SKIP_1);
|
||||||
|
NOT_PRODUCT(else cp_Utf8_suffix.readData(0)); // for asserts
|
||||||
|
|
||||||
bytes* allsuffixes = T_NEW(bytes, len);
|
bytes* allsuffixes = T_NEW(bytes, len);
|
||||||
CHECK;
|
CHECK;
|
||||||
|
@ -999,7 +1025,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
CHECK;
|
CHECK;
|
||||||
tmallocs.add(chars.ptr); // free it later
|
tmallocs.add(chars.ptr); // free it later
|
||||||
} else {
|
} else {
|
||||||
int shrink = chars.limit() - chp;
|
int shrink = (int)(chars.limit() - chp);
|
||||||
chars.len -= shrink;
|
chars.len -= shrink;
|
||||||
charbuf.b.len -= shrink; // ungrow to reclaim buffer space
|
charbuf.b.len -= shrink; // ungrow to reclaim buffer space
|
||||||
// Note that we did not reclaim the final '\0'.
|
// Note that we did not reclaim the final '\0'.
|
||||||
|
@ -1008,7 +1034,9 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//cp_Utf8_chars.done();
|
//cp_Utf8_chars.done();
|
||||||
if (assert(1)) charbuf.b.set(null, 0); // tidy
|
#ifndef PRODUCT
|
||||||
|
charbuf.b.set(null, 0); // tidy
|
||||||
|
#endif
|
||||||
|
|
||||||
// Fourth band: Go back and size the specially packed strings.
|
// Fourth band: Go back and size the specially packed strings.
|
||||||
int maxlen = 0;
|
int maxlen = 0;
|
||||||
|
@ -1041,7 +1069,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
bytes& chars = allsuffixes[i];
|
bytes& chars = allsuffixes[i];
|
||||||
if (chars.ptr != null) continue; // already input
|
if (chars.ptr != null) continue; // already input
|
||||||
int suffix = chars.len; // pick up the hack
|
int suffix = (int)chars.len; // pick up the hack
|
||||||
uint size3 = suffix * 3;
|
uint size3 = suffix * 3;
|
||||||
if (suffix == 0) continue; // done with empty string
|
if (suffix == 0) continue; // done with empty string
|
||||||
chars.malloc(size3);
|
chars.malloc(size3);
|
||||||
|
@ -1071,7 +1099,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
bytes& chars = allsuffixes[i];
|
bytes& chars = allsuffixes[i];
|
||||||
int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
|
int prefix = (i < PREFIX_SKIP_2)? 0: cp_Utf8_prefix.getInt();
|
||||||
int suffix = chars.len;
|
int suffix = (int)chars.len;
|
||||||
byte* fillp;
|
byte* fillp;
|
||||||
// by induction, the buffer is already filled with the prefix
|
// by induction, the buffer is already filled with the prefix
|
||||||
// make sure the prefix value is not corrupted, though:
|
// make sure the prefix value is not corrupted, though:
|
||||||
|
@ -1084,7 +1112,7 @@ void unpacker::read_Utf8_values(entry* cpMap, int len) {
|
||||||
fillp = chars.writeTo(fillp);
|
fillp = chars.writeTo(fillp);
|
||||||
assert(bigbuf.inBounds(fillp));
|
assert(bigbuf.inBounds(fillp));
|
||||||
*fillp = 0; // bigbuf must contain a well-formed Utf8 string
|
*fillp = 0; // bigbuf must contain a well-formed Utf8 string
|
||||||
int length = fillp - bigbuf.ptr;
|
int length = (int)(fillp - bigbuf.ptr);
|
||||||
bytes& value = cpMap[i].value.b;
|
bytes& value = cpMap[i].value.b;
|
||||||
value.set(U_NEW(byte, length+1), length);
|
value.set(U_NEW(byte, length+1), length);
|
||||||
value.copyFrom(bigbuf.ptr, length);
|
value.copyFrom(bigbuf.ptr, length);
|
||||||
|
@ -1215,12 +1243,12 @@ void unpacker::read_cp() {
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (int k = 0; k < N_TAGS_IN_ORDER; k++) {
|
for (int k = 0; k < (int)N_TAGS_IN_ORDER; k++) {
|
||||||
byte tag = TAGS_IN_ORDER[k];
|
byte tag = TAGS_IN_ORDER[k];
|
||||||
int len = cp.tag_count[tag];
|
int len = cp.tag_count[tag];
|
||||||
int base = cp.tag_base[tag];
|
int base = cp.tag_base[tag];
|
||||||
|
|
||||||
printcr(1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0);
|
PRINTCR((1,"Reading %d %s entries...", len, NOT_PRODUCT(TAG_NAME[tag])+0));
|
||||||
entry* cpMap = &cp.entries[base];
|
entry* cpMap = &cp.entries[base];
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
cpMap[i].tag = tag;
|
cpMap[i].tag = tag;
|
||||||
|
@ -1282,7 +1310,7 @@ void unpacker::read_cp() {
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
cpindex* ix = &cp.tag_index[tag];
|
cpindex* ix = &cp.tag_index[tag];
|
||||||
assert(ix->ixTag == tag);
|
assert(ix->ixTag == tag);
|
||||||
assert(ix->len == len);
|
assert((int)ix->len == len);
|
||||||
assert(ix->base1 == cpMap);
|
assert(ix->base1 == cpMap);
|
||||||
#endif
|
#endif
|
||||||
CHECK;
|
CHECK;
|
||||||
|
@ -1293,7 +1321,7 @@ void unpacker::read_cp() {
|
||||||
cp.initMemberIndexes();
|
cp.initMemberIndexes();
|
||||||
CHECK;
|
CHECK;
|
||||||
|
|
||||||
printcr(1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0));
|
PRINTCR((1,"parsed %d constant pool entries in %d bytes", cp.nentries, (rp - rp0)));
|
||||||
|
|
||||||
#define SNAME(n,s) #s "\0"
|
#define SNAME(n,s) #s "\0"
|
||||||
const char* symNames = (
|
const char* symNames = (
|
||||||
|
@ -1307,7 +1335,7 @@ void unpacker::read_cp() {
|
||||||
bytes name; name.set(symNames);
|
bytes name; name.set(symNames);
|
||||||
if (name.len > 0 && name.ptr[0] != '0') {
|
if (name.len > 0 && name.ptr[0] != '0') {
|
||||||
cp.sym[sn] = cp.ensureUtf8(name);
|
cp.sym[sn] = cp.ensureUtf8(name);
|
||||||
printcr(4, "well-known sym %d=%s", sn, cp.sym[sn]->string());
|
PRINTCR((4, "well-known sym %d=%s", sn, cp.sym[sn]->string()));
|
||||||
}
|
}
|
||||||
symNames += name.len + 1; // skip trailing null to next name
|
symNames += name.len + 1; // skip trailing null to next name
|
||||||
}
|
}
|
||||||
|
@ -1352,7 +1380,7 @@ unpacker::attr_definitions::defineLayout(int idx,
|
||||||
assert(flag_limit != 0); // must be set up already
|
assert(flag_limit != 0); // must be set up already
|
||||||
if (idx >= 0) {
|
if (idx >= 0) {
|
||||||
// Fixed attr.
|
// Fixed attr.
|
||||||
if (idx >= flag_limit)
|
if (idx >= (int)flag_limit)
|
||||||
abort("attribute index too large");
|
abort("attribute index too large");
|
||||||
if (isRedefined(idx))
|
if (isRedefined(idx))
|
||||||
abort("redefined attribute index");
|
abort("redefined attribute index");
|
||||||
|
@ -1635,7 +1663,7 @@ unpacker::attr_definitions::parseLayout(const char* lp, band** &res,
|
||||||
for (;;) {
|
for (;;) {
|
||||||
int caseval = 0;
|
int caseval = 0;
|
||||||
lp = parseNumeral(lp, caseval);
|
lp = parseNumeral(lp, caseval);
|
||||||
band_stack.add((void*)caseval);
|
band_stack.add((void*)(size_t)caseval);
|
||||||
if (*lp == '-') {
|
if (*lp == '-') {
|
||||||
// new in version 160, allow (1-5) for (1,2,3,4,5)
|
// new in version 160, allow (1-5) for (1,2,3,4,5)
|
||||||
if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) {
|
if (u->majver < JAVA6_PACKAGE_MAJOR_VERSION) {
|
||||||
|
@ -1654,7 +1682,7 @@ unpacker::attr_definitions::parseLayout(const char* lp, band** &res,
|
||||||
}
|
}
|
||||||
for (;;) {
|
for (;;) {
|
||||||
++caseval;
|
++caseval;
|
||||||
band_stack.add((void*)caseval);
|
band_stack.add((void*)(size_t)caseval);
|
||||||
if (caseval == caselimit) break;
|
if (caseval == caselimit) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1921,7 +1949,7 @@ static int lastIndexOf(int chmin, int chmax, bytes& x, int pos) {
|
||||||
for (byte* cp = ptr + pos; --cp >= ptr; ) {
|
for (byte* cp = ptr + pos; --cp >= ptr; ) {
|
||||||
assert(x.inBounds(cp));
|
assert(x.inBounds(cp));
|
||||||
if (*cp >= chmin && *cp <= chmax)
|
if (*cp >= chmin && *cp <= chmax)
|
||||||
return cp - ptr;
|
return (int)(cp - ptr);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -1976,7 +2004,7 @@ void unpacker::read_ics() {
|
||||||
entry* inner = ic_this_class.getRef();
|
entry* inner = ic_this_class.getRef();
|
||||||
CHECK;
|
CHECK;
|
||||||
uint inord = inner->inord;
|
uint inord = inner->inord;
|
||||||
assert(inord < cp.tag_count[CONSTANT_Class]);
|
assert(inord < (uint)cp.tag_count[CONSTANT_Class]);
|
||||||
if (ic_index[inord] != null) {
|
if (ic_index[inord] != null) {
|
||||||
abort("identical inner class");
|
abort("identical inner class");
|
||||||
break;
|
break;
|
||||||
|
@ -2003,10 +2031,10 @@ void unpacker::read_ics() {
|
||||||
bytes number;
|
bytes number;
|
||||||
bytes name;
|
bytes name;
|
||||||
// Parse n into pkgOuter and name (and number).
|
// Parse n into pkgOuter and name (and number).
|
||||||
printcr(5, "parse short IC name %s", n.ptr);
|
PRINTCR((5, "parse short IC name %s", n.ptr));
|
||||||
int dollar1, dollar2; // pointers to $ in the pattern
|
int dollar1, dollar2; // pointers to $ in the pattern
|
||||||
// parse n = (<pkg>/)*<outer>($<number>)?($<name>)?
|
// parse n = (<pkg>/)*<outer>($<number>)?($<name>)?
|
||||||
int nlen = n.len;
|
int nlen = (int)n.len;
|
||||||
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1;
|
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, nlen) + 1;
|
||||||
dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
|
dollar2 = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, n, nlen);
|
||||||
if (dollar2 < 0) {
|
if (dollar2 < 0) {
|
||||||
|
@ -2035,8 +2063,8 @@ void unpacker::read_ics() {
|
||||||
pkgOuter = n.slice(0, dollar1);
|
pkgOuter = n.slice(0, dollar1);
|
||||||
else
|
else
|
||||||
pkgOuter.set(null,0);
|
pkgOuter.set(null,0);
|
||||||
printcr(5,"=> %s$ 0%s $%s",
|
PRINTCR((5,"=> %s$ 0%s $%s",
|
||||||
pkgOuter.string(), number.string(), name.string());
|
pkgOuter.string(), number.string(), name.string()));
|
||||||
|
|
||||||
if (pkgOuter.ptr != null)
|
if (pkgOuter.ptr != null)
|
||||||
ics[i].outer = cp.ensureClass(pkgOuter);
|
ics[i].outer = cp.ensureClass(pkgOuter);
|
||||||
|
@ -2049,7 +2077,7 @@ void unpacker::read_ics() {
|
||||||
if (ics[i].outer != null) {
|
if (ics[i].outer != null) {
|
||||||
uint outord = ics[i].outer->inord;
|
uint outord = ics[i].outer->inord;
|
||||||
if (outord != NO_INORD) {
|
if (outord != NO_INORD) {
|
||||||
assert(outord < cp.tag_count[CONSTANT_Class]);
|
assert(outord < (uint)cp.tag_count[CONSTANT_Class]);
|
||||||
ics[i].next_sibling = ic_child_index[outord];
|
ics[i].next_sibling = ic_child_index[outord];
|
||||||
ic_child_index[outord] = &ics[i];
|
ic_child_index[outord] = &ics[i];
|
||||||
}
|
}
|
||||||
|
@ -2060,8 +2088,7 @@ void unpacker::read_ics() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpacker::read_classes() {
|
void unpacker::read_classes() {
|
||||||
int i;
|
PRINTCR((1," ...scanning %d classes...", class_count));
|
||||||
printcr(1," ...scanning %d classes...", class_count);
|
|
||||||
class_this.readData(class_count);
|
class_this.readData(class_count);
|
||||||
class_super.readData(class_count);
|
class_super.readData(class_count);
|
||||||
class_interface_count.readData(class_count);
|
class_interface_count.readData(class_count);
|
||||||
|
@ -2070,6 +2097,7 @@ void unpacker::read_classes() {
|
||||||
CHECK;
|
CHECK;
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
int i;
|
||||||
// Make a little mark on super-classes.
|
// Make a little mark on super-classes.
|
||||||
for (i = 0; i < class_count; i++) {
|
for (i = 0; i < class_count; i++) {
|
||||||
entry* e = class_super.getRefN();
|
entry* e = class_super.getRefN();
|
||||||
|
@ -2099,8 +2127,8 @@ void unpacker::read_classes() {
|
||||||
|
|
||||||
read_code_headers();
|
read_code_headers();
|
||||||
|
|
||||||
printcr(1,"scanned %d classes, %d fields, %d methods, %d code headers",
|
PRINTCR((1,"scanned %d classes, %d fields, %d methods, %d code headers",
|
||||||
class_count, field_count, method_count, code_count);
|
class_count, field_count, method_count, code_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
maybe_inline
|
maybe_inline
|
||||||
|
@ -2137,7 +2165,7 @@ void unpacker::read_attrs(int attrc, int obj_count) {
|
||||||
}
|
}
|
||||||
indexBits &= indexMask; // ignore classfile flag bits
|
indexBits &= indexMask; // ignore classfile flag bits
|
||||||
for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) {
|
for (idx = 0; indexBits != 0; idx++, indexBits >>= 1) {
|
||||||
ad.flag_count[idx] += (indexBits & 1);
|
ad.flag_count[idx] += (int)(indexBits & 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// we'll scan these again later for output:
|
// we'll scan these again later for output:
|
||||||
|
@ -2337,7 +2365,7 @@ void unpacker::read_attrs(int attrc, int obj_count) {
|
||||||
for (idx = 0; idx < ad.layouts.length(); idx++) {
|
for (idx = 0; idx < ad.layouts.length(); idx++) {
|
||||||
if (ad.getLayout(idx) == null)
|
if (ad.getLayout(idx) == null)
|
||||||
continue; // none at this fixed index <32
|
continue; // none at this fixed index <32
|
||||||
if (idx < ad.flag_limit && ad.isPredefined(idx))
|
if (idx < (int)ad.flag_limit && ad.isPredefined(idx))
|
||||||
continue; // already handled
|
continue; // already handled
|
||||||
if (ad.getCount(idx) == 0)
|
if (ad.getCount(idx) == 0)
|
||||||
continue; // no attributes of this type (then why transmit layouts?)
|
continue; // no attributes of this type (then why transmit layouts?)
|
||||||
|
@ -2351,9 +2379,9 @@ void unpacker::attr_definitions::readBandData(int idx) {
|
||||||
if (count == 0) return;
|
if (count == 0) return;
|
||||||
layout_definition* lo = getLayout(idx);
|
layout_definition* lo = getLayout(idx);
|
||||||
if (lo != null) {
|
if (lo != null) {
|
||||||
printcr(1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s",
|
PRINTCR((1, "counted %d [redefined = %d predefined = %d] attributes of type %s.%s",
|
||||||
count, isRedefined(idx), isPredefined(idx),
|
count, isRedefined(idx), isPredefined(idx),
|
||||||
ATTR_CONTEXT_NAME[attrc], lo->name);
|
ATTR_CONTEXT_NAME[attrc], lo->name));
|
||||||
}
|
}
|
||||||
bool hasCallables = lo->hasCallables();
|
bool hasCallables = lo->hasCallables();
|
||||||
band** bands = lo->bands();
|
band** bands = lo->bands();
|
||||||
|
@ -2376,13 +2404,13 @@ void unpacker::attr_definitions::readBandData(int idx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Now consult whichever callables have non-zero entry counts.
|
// Now consult whichever callables have non-zero entry counts.
|
||||||
readBandData(bands, -1);
|
readBandData(bands, (uint)-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recursive helper to the previous function:
|
// Recursive helper to the previous function:
|
||||||
void unpacker::attr_definitions::readBandData(band** body, uint count) {
|
void unpacker::attr_definitions::readBandData(band** body, uint count) {
|
||||||
int i, j, k;
|
int j, k;
|
||||||
for (j = 0; body[j] != null; j++) {
|
for (j = 0; body[j] != null; j++) {
|
||||||
band& b = *body[j];
|
band& b = *body[j];
|
||||||
if (b.defc != null) {
|
if (b.defc != null) {
|
||||||
|
@ -2427,7 +2455,7 @@ void unpacker::attr_definitions::readBandData(band** body, uint count) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case EK_CBLE:
|
case EK_CBLE:
|
||||||
assert(count == -1); // incoming count is meaningless
|
assert((int)count == -1); // incoming count is meaningless
|
||||||
k = b.length;
|
k = b.length;
|
||||||
assert(k >= 0);
|
assert(k >= 0);
|
||||||
// This is intended and required for non production mode.
|
// This is intended and required for non production mode.
|
||||||
|
@ -2490,7 +2518,7 @@ void unpacker::putlayout(band** body) {
|
||||||
assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
|
assert(le_kind == EK_INT || le_kind == EK_REPL || le_kind == EK_UN);
|
||||||
x = b.getInt();
|
x = b.getInt();
|
||||||
|
|
||||||
assert(!b.le_bci || prevBCI == to_bci(prevBII));
|
assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
|
||||||
switch (b.le_bci) {
|
switch (b.le_bci) {
|
||||||
case EK_BCI: // PH: transmit R(bci), store bci
|
case EK_BCI: // PH: transmit R(bci), store bci
|
||||||
x = to_bci(prevBII = x);
|
x = to_bci(prevBII = x);
|
||||||
|
@ -2505,7 +2533,7 @@ void unpacker::putlayout(band** body) {
|
||||||
prevBCI += x;
|
prevBCI += x;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assert(!b.le_bci || prevBCI == to_bci(prevBII));
|
assert(!b.le_bci || prevBCI == (int)to_bci(prevBII));
|
||||||
|
|
||||||
switch (b.le_len) {
|
switch (b.le_len) {
|
||||||
case 0: break;
|
case 0: break;
|
||||||
|
@ -2721,8 +2749,8 @@ band* unpacker::ref_band_for_self_op(int bc, bool& isAloadVar, int& origBCVar) {
|
||||||
// Cf. PackageReader.readByteCodes
|
// Cf. PackageReader.readByteCodes
|
||||||
inline // called exactly once => inline
|
inline // called exactly once => inline
|
||||||
void unpacker::read_bcs() {
|
void unpacker::read_bcs() {
|
||||||
printcr(3, "reading compressed bytecodes and operands for %d codes...",
|
PRINTCR((3, "reading compressed bytecodes and operands for %d codes...",
|
||||||
code_count);
|
code_count));
|
||||||
|
|
||||||
// read from bc_codes and bc_case_count
|
// read from bc_codes and bc_case_count
|
||||||
fillbytes all_switch_ops;
|
fillbytes all_switch_ops;
|
||||||
|
@ -2825,18 +2853,18 @@ void unpacker::read_bcs() {
|
||||||
|
|
||||||
// Go through the formality, so we can use it in a regular fashion later:
|
// Go through the formality, so we can use it in a regular fashion later:
|
||||||
assert(rp == rp0);
|
assert(rp == rp0);
|
||||||
bc_codes.readData(opptr - rp);
|
bc_codes.readData((int)(opptr - rp));
|
||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
// To size instruction bands correctly, we need info on switches:
|
// To size instruction bands correctly, we need info on switches:
|
||||||
bc_case_count.readData(all_switch_ops.size());
|
bc_case_count.readData((int)all_switch_ops.size());
|
||||||
for (i = 0; i < all_switch_ops.size(); i++) {
|
for (i = 0; i < (int)all_switch_ops.size(); i++) {
|
||||||
int caseCount = bc_case_count.getInt();
|
int caseCount = bc_case_count.getInt();
|
||||||
int bc = all_switch_ops.getByte(i);
|
int bc = all_switch_ops.getByte(i);
|
||||||
bc_label.expectMoreLength(1+caseCount); // default label + cases
|
bc_label.expectMoreLength(1+caseCount); // default label + cases
|
||||||
bc_case_value.expectMoreLength(bc == bc_tableswitch ? 1 : caseCount);
|
bc_case_value.expectMoreLength(bc == bc_tableswitch ? 1 : caseCount);
|
||||||
printcr(2, "switch bc=%d caseCount=%d", bc, caseCount);
|
PRINTCR((2, "switch bc=%d caseCount=%d", bc, caseCount));
|
||||||
}
|
}
|
||||||
bc_case_count.rewind(); // uses again for output
|
bc_case_count.rewind(); // uses again for output
|
||||||
|
|
||||||
|
@ -2849,15 +2877,14 @@ void unpacker::read_bcs() {
|
||||||
// The bc_escbyte band is counted by the immediately previous band.
|
// The bc_escbyte band is counted by the immediately previous band.
|
||||||
bc_escbyte.readData(bc_escsize.getIntTotal());
|
bc_escbyte.readData(bc_escsize.getIntTotal());
|
||||||
|
|
||||||
printcr(3, "scanned %d opcode and %d operand bytes for %d codes...",
|
PRINTCR((3, "scanned %d opcode and %d operand bytes for %d codes...",
|
||||||
(int)(bc_codes.size()),
|
(int)(bc_codes.size()),
|
||||||
(int)(bc_escsize.maxRP() - bc_case_value.minRP()),
|
(int)(bc_escsize.maxRP() - bc_case_value.minRP()),
|
||||||
code_count);
|
code_count));
|
||||||
}
|
}
|
||||||
|
|
||||||
void unpacker::read_bands() {
|
void unpacker::read_bands() {
|
||||||
byte* rp0 = rp;
|
byte* rp0 = rp;
|
||||||
int i;
|
|
||||||
|
|
||||||
read_file_header();
|
read_file_header();
|
||||||
CHECK;
|
CHECK;
|
||||||
|
@ -2886,9 +2913,9 @@ void unpacker::read_bands() {
|
||||||
/// CP routines
|
/// CP routines
|
||||||
|
|
||||||
entry*& cpool::hashTabRef(byte tag, bytes& b) {
|
entry*& cpool::hashTabRef(byte tag, bytes& b) {
|
||||||
printcr(5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len);
|
PRINTCR((5, "hashTabRef tag=%d %s[%d]", tag, b.string(), b.len));
|
||||||
uint hash = tag + b.len;
|
uint hash = tag + (int)b.len;
|
||||||
for (int i = 0; i < b.len; i++) {
|
for (int i = 0; i < (int)b.len; i++) {
|
||||||
hash = hash * 31 + (0xFF & b.ptr[i]);
|
hash = hash * 31 + (0xFF & b.ptr[i]);
|
||||||
}
|
}
|
||||||
entry** ht = hashTab;
|
entry** ht = hashTab;
|
||||||
|
@ -2905,15 +2932,15 @@ entry*& cpool::hashTabRef(byte tag, bytes& b) {
|
||||||
// Note: hash2 must be relatively prime to hlen, hence the "|1".
|
// Note: hash2 must be relatively prime to hlen, hence the "|1".
|
||||||
hash2 = (((hash % 499) & (hlen-1)) | 1);
|
hash2 = (((hash % 499) & (hlen-1)) | 1);
|
||||||
hash1 += hash2;
|
hash1 += hash2;
|
||||||
if (hash1 >= hlen) hash1 -= hlen;
|
if (hash1 >= (uint)hlen) hash1 -= hlen;
|
||||||
assert(hash1 < hlen);
|
assert(hash1 < (uint)hlen);
|
||||||
assert(++probes < hlen);
|
assert(++probes < hlen);
|
||||||
}
|
}
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
hash_probes[0] += 1;
|
hash_probes[0] += 1;
|
||||||
hash_probes[1] += probes;
|
hash_probes[1] += probes;
|
||||||
#endif
|
#endif
|
||||||
printcr(5, " => @%d %p", hash1, ht[hash1]);
|
PRINTCR((5, " => @%d %p", hash1, ht[hash1]));
|
||||||
return ht[hash1];
|
return ht[hash1];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2939,7 +2966,7 @@ entry* cpool::ensureUtf8(bytes& b) {
|
||||||
u->saveTo(e.value.b, b);
|
u->saveTo(e.value.b, b);
|
||||||
assert(&e >= first_extra_entry);
|
assert(&e >= first_extra_entry);
|
||||||
insert_extra(&e, tag_extras[CONSTANT_Utf8]);
|
insert_extra(&e, tag_extras[CONSTANT_Utf8]);
|
||||||
printcr(4,"ensureUtf8 miss %s", e.string());
|
PRINTCR((4,"ensureUtf8 miss %s", e.string()));
|
||||||
return ix = &e;
|
return ix = &e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2961,7 +2988,7 @@ entry* cpool::ensureClass(bytes& b) {
|
||||||
e.value.b = utf->value.b;
|
e.value.b = utf->value.b;
|
||||||
assert(&e >= first_extra_entry);
|
assert(&e >= first_extra_entry);
|
||||||
insert_extra(&e, tag_extras[CONSTANT_Class]);
|
insert_extra(&e, tag_extras[CONSTANT_Class]);
|
||||||
printcr(4,"ensureClass miss %s", e.string());
|
PRINTCR((4,"ensureClass miss %s", e.string()));
|
||||||
return &e;
|
return &e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2980,7 +3007,7 @@ void cpool::expandSignatures() {
|
||||||
int refnum = 0;
|
int refnum = 0;
|
||||||
bytes form = e.refs[refnum++]->asUtf8();
|
bytes form = e.refs[refnum++]->asUtf8();
|
||||||
buf.empty();
|
buf.empty();
|
||||||
for (int j = 0; j < form.len; j++) {
|
for (int j = 0; j < (int)form.len; j++) {
|
||||||
int c = form.ptr[j];
|
int c = form.ptr[j];
|
||||||
buf.addByte(c);
|
buf.addByte(c);
|
||||||
if (c == 'L') {
|
if (c == 'L') {
|
||||||
|
@ -2990,7 +3017,7 @@ void cpool::expandSignatures() {
|
||||||
}
|
}
|
||||||
assert(refnum == e.nrefs);
|
assert(refnum == e.nrefs);
|
||||||
bytes& sig = buf.b;
|
bytes& sig = buf.b;
|
||||||
printcr(5,"signature %d %s -> %s", i, form.ptr, sig.ptr);
|
PRINTCR((5,"signature %d %s -> %s", i, form.ptr, sig.ptr));
|
||||||
|
|
||||||
// try to find a pre-existing Utf8:
|
// try to find a pre-existing Utf8:
|
||||||
entry* &e2 = hashTabRef(CONSTANT_Utf8, sig);
|
entry* &e2 = hashTabRef(CONSTANT_Utf8, sig);
|
||||||
|
@ -2999,7 +3026,7 @@ void cpool::expandSignatures() {
|
||||||
e.value.b = e2->value.b;
|
e.value.b = e2->value.b;
|
||||||
e.refs[0] = e2;
|
e.refs[0] = e2;
|
||||||
e.nrefs = 1;
|
e.nrefs = 1;
|
||||||
printcr(5,"signature replaced %d => %s", i, e.string());
|
PRINTCR((5,"signature replaced %d => %s", i, e.string()));
|
||||||
nreused++;
|
nreused++;
|
||||||
} else {
|
} else {
|
||||||
// there is no other replacement; reuse this CP entry as a Utf8
|
// there is no other replacement; reuse this CP entry as a Utf8
|
||||||
|
@ -3007,15 +3034,15 @@ void cpool::expandSignatures() {
|
||||||
e.tag = CONSTANT_Utf8;
|
e.tag = CONSTANT_Utf8;
|
||||||
e.nrefs = 0;
|
e.nrefs = 0;
|
||||||
e2 = &e;
|
e2 = &e;
|
||||||
printcr(5,"signature changed %d => %s", e.inord, e.string());
|
PRINTCR((5,"signature changed %d => %s", e.inord, e.string()));
|
||||||
}
|
}
|
||||||
nsigs++;
|
nsigs++;
|
||||||
}
|
}
|
||||||
printcr(1,"expanded %d signatures (reused %d utfs)", nsigs, nreused);
|
PRINTCR((1,"expanded %d signatures (reused %d utfs)", nsigs, nreused));
|
||||||
buf.free();
|
buf.free();
|
||||||
|
|
||||||
// go expunge all references to remaining signatures:
|
// go expunge all references to remaining signatures:
|
||||||
for (i = 0; i < nentries; i++) {
|
for (i = 0; i < (int)nentries; i++) {
|
||||||
entry& e = entries[i];
|
entry& e = entries[i];
|
||||||
for (int j = 0; j < e.nrefs; j++) {
|
for (int j = 0; j < e.nrefs; j++) {
|
||||||
entry*& e2 = e.refs[j];
|
entry*& e2 = e.refs[j];
|
||||||
|
@ -3028,7 +3055,7 @@ void cpool::expandSignatures() {
|
||||||
void cpool::initMemberIndexes() {
|
void cpool::initMemberIndexes() {
|
||||||
// This function does NOT refer to any class schema.
|
// This function does NOT refer to any class schema.
|
||||||
// It is totally internal to the cpool.
|
// It is totally internal to the cpool.
|
||||||
int i, j, len;
|
int i, j;
|
||||||
|
|
||||||
// Get the pre-existing indexes:
|
// Get the pre-existing indexes:
|
||||||
int nclasses = tag_count[CONSTANT_Class];
|
int nclasses = tag_count[CONSTANT_Class];
|
||||||
|
@ -3047,13 +3074,13 @@ void cpool::initMemberIndexes() {
|
||||||
for (j = 0; j < nfields; j++) {
|
for (j = 0; j < nfields; j++) {
|
||||||
entry& f = fields[j];
|
entry& f = fields[j];
|
||||||
i = f.memberClass()->inord;
|
i = f.memberClass()->inord;
|
||||||
assert((uint)i < nclasses);
|
assert(i < nclasses);
|
||||||
field_counts[i]++;
|
field_counts[i]++;
|
||||||
}
|
}
|
||||||
for (j = 0; j < nmethods; j++) {
|
for (j = 0; j < nmethods; j++) {
|
||||||
entry& m = methods[j];
|
entry& m = methods[j];
|
||||||
i = m.memberClass()->inord;
|
i = m.memberClass()->inord;
|
||||||
assert((uint)i < nclasses);
|
assert(i < nclasses);
|
||||||
method_counts[i]++;
|
method_counts[i]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3068,8 +3095,8 @@ void cpool::initMemberIndexes() {
|
||||||
// reuse field_counts and member_counts as fill pointers:
|
// reuse field_counts and member_counts as fill pointers:
|
||||||
field_counts[i] = fbase;
|
field_counts[i] = fbase;
|
||||||
method_counts[i] = mbase;
|
method_counts[i] = mbase;
|
||||||
printcr(3, "class %d fields @%d[%d] methods @%d[%d]",
|
PRINTCR((3, "class %d fields @%d[%d] methods @%d[%d]",
|
||||||
i, fbase, fc, mbase, mc);
|
i, fbase, fc, mbase, mc));
|
||||||
fbase += fc+1;
|
fbase += fc+1;
|
||||||
mbase += mc+1;
|
mbase += mc+1;
|
||||||
// (the +1 leaves a space between every subarray)
|
// (the +1 leaves a space between every subarray)
|
||||||
|
@ -3093,18 +3120,18 @@ void cpool::initMemberIndexes() {
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
// Test the result immediately on every class and field.
|
// Test the result immediately on every class and field.
|
||||||
int fvisited = 0, mvisited = 0;
|
int fvisited = 0, mvisited = 0;
|
||||||
int prevord;
|
int prevord, len;
|
||||||
for (i = 0; i < nclasses; i++) {
|
for (i = 0; i < nclasses; i++) {
|
||||||
entry* cls = &classes[i];
|
entry* cls = &classes[i];
|
||||||
cpindex* fix = getFieldIndex(cls);
|
cpindex* fix = getFieldIndex(cls);
|
||||||
cpindex* mix = getMethodIndex(cls);
|
cpindex* mix = getMethodIndex(cls);
|
||||||
printcr(2, "field and method index for %s [%d] [%d]",
|
PRINTCR((2, "field and method index for %s [%d] [%d]",
|
||||||
cls->string(), mix->len, fix->len);
|
cls->string(), mix->len, fix->len));
|
||||||
prevord = -1;
|
prevord = -1;
|
||||||
for (j = 0, len = fix->len; j < len; j++) {
|
for (j = 0, len = fix->len; j < len; j++) {
|
||||||
entry* f = fix->get(j);
|
entry* f = fix->get(j);
|
||||||
assert(f != null);
|
assert(f != null);
|
||||||
printcr(3, "- field %s", f->string());
|
PRINTCR((3, "- field %s", f->string()));
|
||||||
assert(f->memberClass() == cls);
|
assert(f->memberClass() == cls);
|
||||||
assert(prevord < (int)f->inord);
|
assert(prevord < (int)f->inord);
|
||||||
prevord = f->inord;
|
prevord = f->inord;
|
||||||
|
@ -3115,7 +3142,7 @@ void cpool::initMemberIndexes() {
|
||||||
for (j = 0, len = mix->len; j < len; j++) {
|
for (j = 0, len = mix->len; j < len; j++) {
|
||||||
entry* m = mix->get(j);
|
entry* m = mix->get(j);
|
||||||
assert(m != null);
|
assert(m != null);
|
||||||
printcr(3, "- method %s", m->string());
|
PRINTCR((3, "- method %s", m->string()));
|
||||||
assert(m->memberClass() == cls);
|
assert(m->memberClass() == cls);
|
||||||
assert(prevord < (int)m->inord);
|
assert(prevord < (int)m->inord);
|
||||||
prevord = m->inord;
|
prevord = m->inord;
|
||||||
|
@ -3164,7 +3191,7 @@ void cpool::resetOutputIndexes() {
|
||||||
outputEntries.empty();
|
outputEntries.empty();
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
// they must all be clear now
|
// they must all be clear now
|
||||||
for (i = 0; i < nentries; i++)
|
for (i = 0; i < (int)nentries; i++)
|
||||||
assert(entries[i].outputIndex == NOT_REQUESTED);
|
assert(entries[i].outputIndex == NOT_REQUESTED);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -3215,7 +3242,7 @@ void cpool::computeOutputIndexes() {
|
||||||
static uint checkStart = 0;
|
static uint checkStart = 0;
|
||||||
int checkStep = 1;
|
int checkStep = 1;
|
||||||
if (nentries > 100) checkStep = nentries / 100;
|
if (nentries > 100) checkStep = nentries / 100;
|
||||||
for (i = (checkStart++ % checkStep); i < nentries; i += checkStep) {
|
for (i = (int)(checkStart++ % checkStep); i < (int)nentries; i += checkStep) {
|
||||||
entry& e = entries[i];
|
entry& e = entries[i];
|
||||||
if (e.outputIndex != NOT_REQUESTED) {
|
if (e.outputIndex != NOT_REQUESTED) {
|
||||||
assert(outputEntries.contains(&e));
|
assert(outputEntries.contains(&e));
|
||||||
|
@ -3225,7 +3252,7 @@ void cpool::computeOutputIndexes() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// check hand-initialization of TAG_ORDER
|
// check hand-initialization of TAG_ORDER
|
||||||
for (i = 0; i < N_TAGS_IN_ORDER; i++) {
|
for (i = 0; i < (int)N_TAGS_IN_ORDER; i++) {
|
||||||
byte tag = TAGS_IN_ORDER[i];
|
byte tag = TAGS_IN_ORDER[i];
|
||||||
assert(TAG_ORDER[tag] == i+1);
|
assert(TAG_ORDER[tag] == i+1);
|
||||||
}
|
}
|
||||||
|
@ -3247,7 +3274,7 @@ void cpool::computeOutputIndexes() {
|
||||||
if (e.isDoubleWord()) nextIndex++; // do not use the next index
|
if (e.isDoubleWord()) nextIndex++; // do not use the next index
|
||||||
}
|
}
|
||||||
outputIndexLimit = nextIndex;
|
outputIndexLimit = nextIndex;
|
||||||
printcr(3,"renumbering CP to %d entries", outputIndexLimit);
|
PRINTCR((3,"renumbering CP to %d entries", outputIndexLimit));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
|
@ -3257,9 +3284,9 @@ unpacker* debug_u;
|
||||||
|
|
||||||
static bytes& getbuf(int len) { // for debugging only!
|
static bytes& getbuf(int len) { // for debugging only!
|
||||||
static int bn = 0;
|
static int bn = 0;
|
||||||
static bytes bufs[8] = { 0 };
|
static bytes bufs[8];
|
||||||
bytes& buf = bufs[bn++ & 7];
|
bytes& buf = bufs[bn++ & 7];
|
||||||
while (buf.len < len+10)
|
while ((int)buf.len < len+10)
|
||||||
buf.realloc(buf.len ? buf.len * 2 : 1000);
|
buf.realloc(buf.len ? buf.len * 2 : 1000);
|
||||||
buf.ptr[0] = 0; // for the sake of strcat
|
buf.ptr[0] = 0; // for the sake of strcat
|
||||||
return buf;
|
return buf;
|
||||||
|
@ -3285,7 +3312,7 @@ char* entry::string() {
|
||||||
case CONSTANT_Long:
|
case CONSTANT_Long:
|
||||||
case CONSTANT_Double:
|
case CONSTANT_Double:
|
||||||
buf = getbuf(24);
|
buf = getbuf(24);
|
||||||
sprintf((char*)buf.ptr, "0x%016llx", value.l);
|
sprintf((char*)buf.ptr, "0x" LONG_LONG_HEX_FORMAT, value.l);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (nrefs == 0) {
|
if (nrefs == 0) {
|
||||||
|
@ -3296,7 +3323,7 @@ char* entry::string() {
|
||||||
} else {
|
} else {
|
||||||
char* s1 = refs[0]->string();
|
char* s1 = refs[0]->string();
|
||||||
char* s2 = refs[1]->string();
|
char* s2 = refs[1]->string();
|
||||||
buf = getbuf(strlen(s1) + 1 + strlen(s2) + 4 + 1);
|
buf = getbuf((int)strlen(s1) + 1 + (int)strlen(s2) + 4 + 1);
|
||||||
buf.strcat(s1).strcat(" ").strcat(s2);
|
buf.strcat(s1).strcat(" ").strcat(s2);
|
||||||
if (nrefs > 2) buf.strcat(" ...");
|
if (nrefs > 2) buf.strcat(" ...");
|
||||||
}
|
}
|
||||||
|
@ -3409,7 +3436,9 @@ void unpacker::reset() {
|
||||||
segments_read_before_reset += 1;
|
segments_read_before_reset += 1;
|
||||||
if (verbose >= 2) {
|
if (verbose >= 2) {
|
||||||
fprintf(errstrm,
|
fprintf(errstrm,
|
||||||
"After segment %d, %lld bytes read and %lld bytes written.\n",
|
"After segment %d, "
|
||||||
|
LONG_LONG_FORMAT " bytes read and "
|
||||||
|
LONG_LONG_FORMAT " bytes written.\n",
|
||||||
segments_read_before_reset-1,
|
segments_read_before_reset-1,
|
||||||
bytes_read_before_reset, bytes_written_before_reset);
|
bytes_read_before_reset, bytes_written_before_reset);
|
||||||
fprintf(errstrm,
|
fprintf(errstrm,
|
||||||
|
@ -3475,7 +3504,9 @@ void unpacker::init(read_input_fn_t input_fn) {
|
||||||
int i;
|
int i;
|
||||||
NOT_PRODUCT(debug_u = this);
|
NOT_PRODUCT(debug_u = this);
|
||||||
BYTES_OF(*this).clear();
|
BYTES_OF(*this).clear();
|
||||||
if (assert(1)) free(); // just to make sure freeing is idempotent
|
#ifndef PRODUCT
|
||||||
|
free(); // just to make sure freeing is idempotent
|
||||||
|
#endif
|
||||||
this->u = this; // self-reference for U_NEW macro
|
this->u = this; // self-reference for U_NEW macro
|
||||||
errstrm = stdout; // default error-output
|
errstrm = stdout; // default error-output
|
||||||
log_file = LOGFILE_STDOUT;
|
log_file = LOGFILE_STDOUT;
|
||||||
|
@ -3621,7 +3652,7 @@ void unpacker::put_stackmap_type() {
|
||||||
maybe_inline
|
maybe_inline
|
||||||
void unpacker::put_label(int curIP, int size) {
|
void unpacker::put_label(int curIP, int size) {
|
||||||
code_fixup_type.addByte(size);
|
code_fixup_type.addByte(size);
|
||||||
code_fixup_offset.add(put_empty(size));
|
code_fixup_offset.add((int)put_empty(size));
|
||||||
code_fixup_source.add(curIP);
|
code_fixup_source.add(curIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3658,7 +3689,7 @@ void unpacker::write_bc_ops() {
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int curIP = 0; ; curIP++) {
|
for (int curIP = 0; ; curIP++) {
|
||||||
int curPC = wpoffset() - codeBase;
|
int curPC = (int)(wpoffset() - codeBase);
|
||||||
bcimap.add(curPC);
|
bcimap.add(curPC);
|
||||||
ensure_put_space(10); // covers most instrs w/o further bounds check
|
ensure_put_space(10); // covers most instrs w/o further bounds check
|
||||||
int bc = *opptr++ & 0xFF;
|
int bc = *opptr++ & 0xFF;
|
||||||
|
@ -3702,7 +3733,7 @@ void unpacker::write_bc_ops() {
|
||||||
put_label(curIP, 4); //int lVal = bc_label.getInt();
|
put_label(curIP, 4); //int lVal = bc_label.getInt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert(to_bci(curIP) == curPC);
|
assert((int)to_bci(curIP) == curPC);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
case bc_iinc:
|
case bc_iinc:
|
||||||
|
@ -3805,7 +3836,7 @@ void unpacker::write_bc_ops() {
|
||||||
assert(bc <= bc_jsr_w);
|
assert(bc <= bc_jsr_w);
|
||||||
put_label(curIP, 4); //putu4(lVal);
|
put_label(curIP, 4); //putu4(lVal);
|
||||||
}
|
}
|
||||||
assert(to_bci(curIP) == curPC);
|
assert((int)to_bci(curIP) == curPC);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
bc_which = ref_band_for_op(bc);
|
bc_which = ref_band_for_op(bc);
|
||||||
|
@ -3880,7 +3911,7 @@ void unpacker::write_bc_ops() {
|
||||||
//bcimap.add(curPC); // PC limit is already also in map, from bc_end_marker
|
//bcimap.add(curPC); // PC limit is already also in map, from bc_end_marker
|
||||||
|
|
||||||
// Armed with a bcimap, we can now fix up all the labels.
|
// Armed with a bcimap, we can now fix up all the labels.
|
||||||
for (int i = 0; i < code_fixup_type.size(); i++) {
|
for (int i = 0; i < (int)code_fixup_type.size(); i++) {
|
||||||
int type = code_fixup_type.getByte(i);
|
int type = code_fixup_type.getByte(i);
|
||||||
byte* bp = wp_at(code_fixup_offset.get(i));
|
byte* bp = wp_at(code_fixup_offset.get(i));
|
||||||
int curIP = code_fixup_source.get(i);
|
int curIP = code_fixup_source.get(i);
|
||||||
|
@ -3896,7 +3927,7 @@ void unpacker::write_bc_ops() {
|
||||||
|
|
||||||
inline // called exactly once => inline
|
inline // called exactly once => inline
|
||||||
void unpacker::write_code() {
|
void unpacker::write_code() {
|
||||||
int i, j;
|
int j;
|
||||||
|
|
||||||
int max_stack, max_locals, handler_count, cflags;
|
int max_stack, max_locals, handler_count, cflags;
|
||||||
get_code_header(max_stack, max_locals, handler_count, cflags);
|
get_code_header(max_stack, max_locals, handler_count, cflags);
|
||||||
|
@ -3919,7 +3950,7 @@ void unpacker::write_code() {
|
||||||
CHECK;
|
CHECK;
|
||||||
|
|
||||||
byte* bcbasewp = wp_at(bcbase);
|
byte* bcbasewp = wp_at(bcbase);
|
||||||
putu4_at(bcbasewp, wp - (bcbasewp+4)); // size of code attr
|
putu4_at(bcbasewp, (int)(wp - (bcbasewp+4))); // size of code attr
|
||||||
|
|
||||||
putu2(handler_count);
|
putu2(handler_count);
|
||||||
for (j = 0; j < handler_count; j++) {
|
for (j = 0; j < handler_count; j++) {
|
||||||
|
@ -3968,10 +3999,10 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
if ((indexBits & 1) != 0)
|
if ((indexBits & 1) != 0)
|
||||||
bitIndexes[biCount++] = idx;
|
bitIndexes[biCount++] = idx;
|
||||||
}
|
}
|
||||||
assert(biCount <= lengthof(bitIndexes));
|
assert(biCount <= (int)lengthof(bitIndexes));
|
||||||
|
|
||||||
// Write a provisional attribute count, perhaps to be corrected later.
|
// Write a provisional attribute count, perhaps to be corrected later.
|
||||||
int naOffset = wpoffset();
|
int naOffset = (int)wpoffset();
|
||||||
int na0 = biCount + oiCount;
|
int na0 = biCount + oiCount;
|
||||||
putu2(na0);
|
putu2(na0);
|
||||||
|
|
||||||
|
@ -3986,7 +4017,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
entry* ref; // scratch
|
entry* ref; // scratch
|
||||||
size_t abase = put_empty(2+4);
|
size_t abase = put_empty(2+4);
|
||||||
CHECK_0;
|
CHECK_0;
|
||||||
if (idx < ad.flag_limit && ad.isPredefined(idx)) {
|
if (idx < (int)ad.flag_limit && ad.isPredefined(idx)) {
|
||||||
// Switch on the attrc and idx simultaneously.
|
// Switch on the attrc and idx simultaneously.
|
||||||
switch (ADH_BYTE(attrc, idx)) {
|
switch (ADH_BYTE(attrc, idx)) {
|
||||||
|
|
||||||
|
@ -4020,16 +4051,16 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
bytes& n = cur_class->ref(0)->value.b;
|
bytes& n = cur_class->ref(0)->value.b;
|
||||||
// parse n = (<pkg>/)*<outer>?($<id>)*
|
// parse n = (<pkg>/)*<outer>?($<id>)*
|
||||||
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, n.len)+1;
|
int pkglen = lastIndexOf(SLASH_MIN, SLASH_MAX, n, (int)n.len)+1;
|
||||||
bytes prefix = n.slice(pkglen, n.len);
|
bytes prefix = n.slice(pkglen, n.len);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Work backwards, finding all '$', '#', etc.
|
// Work backwards, finding all '$', '#', etc.
|
||||||
int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, prefix.len);
|
int dollar = lastIndexOf(DOLLAR_MIN, DOLLAR_MAX, prefix, (int)prefix.len);
|
||||||
if (dollar < 0) break;
|
if (dollar < 0) break;
|
||||||
prefix = prefix.slice(0, dollar);
|
prefix = prefix.slice(0, dollar);
|
||||||
}
|
}
|
||||||
const char* suffix = ".java";
|
const char* suffix = ".java";
|
||||||
int len = prefix.len + strlen(suffix);
|
int len = (int)(prefix.len + strlen(suffix));
|
||||||
bytes name; name.set(T_NEW(byte, len + 1), len);
|
bytes name; name.set(T_NEW(byte, len + 1), len);
|
||||||
name.strcat(prefix).strcat(suffix);
|
name.strcat(prefix).strcat(suffix);
|
||||||
ref = cp.ensureUtf8(name);
|
ref = cp.ensureUtf8(name);
|
||||||
|
@ -4081,7 +4112,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
// (253) [(1)(2)(2)]
|
// (253) [(1)(2)(2)]
|
||||||
// (254) [(1)(2)(2)(2)]
|
// (254) [(1)(2)(2)(2)]
|
||||||
putu2(code_StackMapTable_offset.getInt());
|
putu2(code_StackMapTable_offset.getInt());
|
||||||
for (int j2 = (tag - 251); j2 > 0; j2--) {
|
for (int k = (tag - 251); k > 0; k--) {
|
||||||
put_stackmap_type();
|
put_stackmap_type();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -4165,7 +4196,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
abort("bad layout index");
|
abort("bad layout index");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
assert(lo->idx == idx);
|
assert((int)lo->idx == idx);
|
||||||
aname = lo->nameEntry;
|
aname = lo->nameEntry;
|
||||||
if (aname == null) {
|
if (aname == null) {
|
||||||
bytes nameb; nameb.set(lo->name);
|
bytes nameb; nameb.set(lo->name);
|
||||||
|
@ -4198,7 +4229,7 @@ int unpacker::write_attrs(int attrc, julong indexBits) {
|
||||||
|
|
||||||
// patch the name and length
|
// patch the name and length
|
||||||
putref(aname);
|
putref(aname);
|
||||||
putu4(wp1 - (wp+4)); // put the attr size
|
putu4((int)(wp1 - (wp+4))); // put the attr size
|
||||||
wp = wp1;
|
wp = wp1;
|
||||||
na++; // count the attrs actually written
|
na++; // count the attrs actually written
|
||||||
}
|
}
|
||||||
|
@ -4279,7 +4310,7 @@ void unpacker::write_classfile_tail() {
|
||||||
cur_class_has_local_ics = false; // may be set true by write_attrs
|
cur_class_has_local_ics = false; // may be set true by write_attrs
|
||||||
|
|
||||||
|
|
||||||
int naOffset = wpoffset();
|
int naOffset = (int)wpoffset();
|
||||||
int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
|
int na = write_attrs(ATTR_CONTEXT_CLASS, (kflags & indexMask));
|
||||||
|
|
||||||
|
|
||||||
|
@ -4448,7 +4479,7 @@ void unpacker::write_classfile_head() {
|
||||||
putu1(tag);
|
putu1(tag);
|
||||||
switch (tag) {
|
switch (tag) {
|
||||||
case CONSTANT_Utf8:
|
case CONSTANT_Utf8:
|
||||||
putu2(e.value.b.len);
|
putu2((int)e.value.b.len);
|
||||||
put_bytes(e.value.b);
|
put_bytes(e.value.b);
|
||||||
break;
|
break;
|
||||||
case CONSTANT_Integer:
|
case CONSTANT_Integer:
|
||||||
|
@ -4479,7 +4510,7 @@ void unpacker::write_classfile_head() {
|
||||||
|
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
total_cp_size[0] += cp.outputIndexLimit;
|
total_cp_size[0] += cp.outputIndexLimit;
|
||||||
total_cp_size[1] += cur_classfile_head.size();
|
total_cp_size[1] += (int)cur_classfile_head.size();
|
||||||
#endif
|
#endif
|
||||||
close_output();
|
close_output();
|
||||||
}
|
}
|
||||||
|
@ -4544,7 +4575,7 @@ unpacker::file* unpacker::get_next_file() {
|
||||||
if (cur_file.name[0] == '\0') {
|
if (cur_file.name[0] == '\0') {
|
||||||
bytes& prefix = cur_class->ref(0)->value.b;
|
bytes& prefix = cur_class->ref(0)->value.b;
|
||||||
const char* suffix = ".class";
|
const char* suffix = ".class";
|
||||||
int len = prefix.len + strlen(suffix);
|
int len = (int)(prefix.len + strlen(suffix));
|
||||||
bytes name; name.set(T_NEW(byte, len + 1), len);
|
bytes name; name.set(T_NEW(byte, len + 1), len);
|
||||||
cur_file.name = name.strcat(prefix).strcat(suffix).strval();
|
cur_file.name = name.strcat(prefix).strcat(suffix).strval();
|
||||||
}
|
}
|
||||||
|
@ -4564,7 +4595,7 @@ unpacker::file* unpacker::get_next_file() {
|
||||||
}
|
}
|
||||||
if (rpleft < cur_file.size) {
|
if (rpleft < cur_file.size) {
|
||||||
// Caller must read the rest.
|
// Caller must read the rest.
|
||||||
size_t fleft = cur_file.size - rpleft;
|
size_t fleft = (size_t)cur_file.size - rpleft;
|
||||||
bytes_read += fleft; // Credit it to the overall archive size.
|
bytes_read += fleft; // Credit it to the overall archive size.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4580,7 +4611,7 @@ void unpacker::write_file_to_jar(unpacker::file* f) {
|
||||||
julong fsize = f->size;
|
julong fsize = f->size;
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
if (nowrite NOT_PRODUCT(|| skipfiles-- > 0)) {
|
if (nowrite NOT_PRODUCT(|| skipfiles-- > 0)) {
|
||||||
printcr(2,"would write %d bytes to %s", (int) fsize, f->name);
|
PRINTCR((2,"would write %d bytes to %s", (int) fsize, f->name));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -4623,7 +4654,8 @@ void unpacker::write_file_to_jar(unpacker::file* f) {
|
||||||
part1, part2);
|
part1, part2);
|
||||||
}
|
}
|
||||||
if (verbose >= 3) {
|
if (verbose >= 3) {
|
||||||
fprintf(errstrm, "Wrote %lld bytes to: %s\n", fsize, f->name);
|
fprintf(errstrm, "Wrote "
|
||||||
|
LONG_LONG_FORMAT " bytes to: %s\n", fsize, f->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -314,7 +314,7 @@ struct unpacker {
|
||||||
void readBandData(band** body, uint count); // recursive helper
|
void readBandData(band** body, uint count); // recursive helper
|
||||||
|
|
||||||
layout_definition* getLayout(uint idx) {
|
layout_definition* getLayout(uint idx) {
|
||||||
if (idx >= layouts.length()) return null;
|
if (idx >= (uint)layouts.length()) return null;
|
||||||
return (layout_definition*) layouts.get(idx);
|
return (layout_definition*) layouts.get(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,12 +332,12 @@ struct unpacker {
|
||||||
int predefCount(uint idx);
|
int predefCount(uint idx);
|
||||||
|
|
||||||
bool isRedefined(uint idx) {
|
bool isRedefined(uint idx) {
|
||||||
assert(idx < flag_limit);
|
if (idx >= flag_limit) return false;
|
||||||
return ((redef >> idx) & 1);
|
return (bool)((redef >> idx) & 1);
|
||||||
}
|
}
|
||||||
bool isPredefined(uint idx) {
|
bool isPredefined(uint idx) {
|
||||||
assert(idx < flag_limit);
|
if (idx >= flag_limit) return false;
|
||||||
return (((predef & ~redef) >> idx) & 1);
|
return (bool)(((predef & ~redef) >> idx) & 1);
|
||||||
}
|
}
|
||||||
julong flagIndexMask() {
|
julong flagIndexMask() {
|
||||||
return (predef | redef);
|
return (predef | redef);
|
||||||
|
@ -345,9 +345,9 @@ struct unpacker {
|
||||||
bool isIndex(uint idx) {
|
bool isIndex(uint idx) {
|
||||||
assert(flag_limit != 0); // must be set up already
|
assert(flag_limit != 0); // must be set up already
|
||||||
if (idx < flag_limit)
|
if (idx < flag_limit)
|
||||||
return (((predef | redef) >> idx) & 1);
|
return (bool)(((predef | redef) >> idx) & 1);
|
||||||
else
|
else
|
||||||
return (idx - flag_limit < overflow_count.length());
|
return (idx - flag_limit < (uint)overflow_count.length());
|
||||||
}
|
}
|
||||||
int& getCount(uint idx) {
|
int& getCount(uint idx) {
|
||||||
assert(isIndex(idx));
|
assert(isIndex(idx));
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -65,7 +65,7 @@ void* must_malloc(int size) {
|
||||||
|
|
||||||
void mkdirs(int oklen, char* path) {
|
void mkdirs(int oklen, char* path) {
|
||||||
|
|
||||||
if (strlen(path) <= oklen) return;
|
if (strlen(path) <= (size_t)oklen) return;
|
||||||
char dir[PATH_MAX];
|
char dir[PATH_MAX];
|
||||||
|
|
||||||
strcpy(dir, path);
|
strcpy(dir, path);
|
||||||
|
@ -79,12 +79,13 @@ void mkdirs(int oklen, char* path) {
|
||||||
|
|
||||||
#ifndef PRODUCT
|
#ifndef PRODUCT
|
||||||
void breakpoint() { } // hook for debugger
|
void breakpoint() { } // hook for debugger
|
||||||
void assert_failed(const char* p) {
|
int assert_failed(const char* p) {
|
||||||
char message[1<<12];
|
char message[1<<12];
|
||||||
sprintf(message, "@assert failed: %s\n", p);
|
sprintf(message, "@assert failed: %s\n", p);
|
||||||
fprintf(stdout, 1+message);
|
fprintf(stdout, 1+message);
|
||||||
breakpoint();
|
breakpoint();
|
||||||
unpack_abort(message);
|
unpack_abort(message);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2003 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
|
|
||||||
void* must_malloc(int size);
|
void* must_malloc(int size);
|
||||||
#ifndef USE_MTRACE
|
#ifndef USE_MTRACE
|
||||||
#define mtrace(c, ptr, size) (0)
|
#define mtrace(c, ptr, size)
|
||||||
#else
|
#else
|
||||||
void mtrace(char c, void* ptr, size_t size);
|
void mtrace(char c, void* ptr, size_t size);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2005 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -85,7 +85,7 @@ void jar::init(unpacker* u_) {
|
||||||
// Write data to the ZIP output stream.
|
// Write data to the ZIP output stream.
|
||||||
void jar::write_data(void* buff, int len) {
|
void jar::write_data(void* buff, int len) {
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
int rc = fwrite(buff, 1, len, jarfp);
|
int rc = (int)fwrite(buff, 1, len, jarfp);
|
||||||
if (rc <= 0) {
|
if (rc <= 0) {
|
||||||
fprintf(u->errstrm, "Error: write on output file failed err=%d\n",errno);
|
fprintf(u->errstrm, "Error: write on output file failed err=%d\n",errno);
|
||||||
exit(1); // Called only from the native standalone unpacker
|
exit(1); // Called only from the native standalone unpacker
|
||||||
|
@ -98,17 +98,17 @@ void jar::write_data(void* buff, int len) {
|
||||||
|
|
||||||
void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
|
void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
|
||||||
int len, int clen, uLong crc) {
|
int len, int clen, uLong crc) {
|
||||||
uint fname_length = strlen(fname);
|
uint fname_length = (uint)strlen(fname);
|
||||||
ushort header[23];
|
ushort header[23];
|
||||||
if (modtime == 0) modtime = default_modtime;
|
if (modtime == 0) modtime = default_modtime;
|
||||||
uLong dostime = get_dostime(modtime);
|
uLong dostime = get_dostime(modtime);
|
||||||
|
|
||||||
header[0] = SWAP_BYTES(0x4B50);
|
header[0] = (ushort)SWAP_BYTES(0x4B50);
|
||||||
header[1] = SWAP_BYTES(0x0201);
|
header[1] = (ushort)SWAP_BYTES(0x0201);
|
||||||
header[2] = SWAP_BYTES(0xA);
|
header[2] = (ushort)SWAP_BYTES(0xA);
|
||||||
|
|
||||||
// required version
|
// required version
|
||||||
header[3] = SWAP_BYTES(0xA);
|
header[3] = (ushort)SWAP_BYTES(0xA);
|
||||||
|
|
||||||
// flags 02 = maximum sub-compression flag
|
// flags 02 = maximum sub-compression flag
|
||||||
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
|
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
|
||||||
|
@ -117,23 +117,23 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
|
||||||
header[5] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
|
header[5] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
|
||||||
|
|
||||||
// Last modified date and time.
|
// Last modified date and time.
|
||||||
header[6] = GET_INT_LO(dostime);
|
header[6] = (ushort)GET_INT_LO(dostime);
|
||||||
header[7] = GET_INT_HI(dostime);
|
header[7] = (ushort)GET_INT_HI(dostime);
|
||||||
|
|
||||||
// CRC
|
// CRC
|
||||||
header[8] = GET_INT_LO(crc);
|
header[8] = (ushort)GET_INT_LO(crc);
|
||||||
header[9] = GET_INT_HI(crc);
|
header[9] = (ushort)GET_INT_HI(crc);
|
||||||
|
|
||||||
// Compressed length:
|
// Compressed length:
|
||||||
header[10] = GET_INT_LO(clen);
|
header[10] = (ushort)GET_INT_LO(clen);
|
||||||
header[11] = GET_INT_HI(clen);
|
header[11] = (ushort)GET_INT_HI(clen);
|
||||||
|
|
||||||
// Uncompressed length.
|
// Uncompressed length.
|
||||||
header[12] = GET_INT_LO(len);
|
header[12] = (ushort)GET_INT_LO(len);
|
||||||
header[13] = GET_INT_HI(len);
|
header[13] = (ushort)GET_INT_HI(len);
|
||||||
|
|
||||||
// Filename length
|
// Filename length
|
||||||
header[14] = SWAP_BYTES(fname_length);
|
header[14] = (ushort)SWAP_BYTES(fname_length);
|
||||||
// So called "extra field" length.
|
// So called "extra field" length.
|
||||||
header[15] = 0;
|
header[15] = 0;
|
||||||
// So called "comment" length.
|
// So called "comment" length.
|
||||||
|
@ -146,8 +146,8 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
|
||||||
header[19] = 0;
|
header[19] = 0;
|
||||||
header[20] = 0;
|
header[20] = 0;
|
||||||
// Offset within ZIP file.
|
// Offset within ZIP file.
|
||||||
header[21] = GET_INT_LO(output_file_offset);
|
header[21] = (ushort)GET_INT_LO(output_file_offset);
|
||||||
header[22] = GET_INT_HI(output_file_offset);
|
header[22] = (ushort)GET_INT_HI(output_file_offset);
|
||||||
|
|
||||||
// Copy the whole thing into the central directory.
|
// Copy the whole thing into the central directory.
|
||||||
central_directory.append(header, sizeof(header));
|
central_directory.append(header, sizeof(header));
|
||||||
|
@ -160,17 +160,17 @@ void jar::add_to_jar_directory(const char* fname, bool store, int modtime,
|
||||||
|
|
||||||
void jar::write_jar_header(const char* fname, bool store, int modtime,
|
void jar::write_jar_header(const char* fname, bool store, int modtime,
|
||||||
int len, int clen, uint crc) {
|
int len, int clen, uint crc) {
|
||||||
uint fname_length = strlen(fname);
|
uint fname_length = (uint)strlen(fname);
|
||||||
ushort header[15];
|
ushort header[15];
|
||||||
if (modtime == 0) modtime = default_modtime;
|
if (modtime == 0) modtime = default_modtime;
|
||||||
uLong dostime = get_dostime(modtime);
|
uLong dostime = get_dostime(modtime);
|
||||||
|
|
||||||
// ZIP LOC magic.
|
// ZIP LOC magic.
|
||||||
header[0] = SWAP_BYTES(0x4B50);
|
header[0] = (ushort)SWAP_BYTES(0x4B50);
|
||||||
header[1] = SWAP_BYTES(0x0403);
|
header[1] = (ushort)SWAP_BYTES(0x0403);
|
||||||
|
|
||||||
// Version
|
// Version
|
||||||
header[2] = SWAP_BYTES(0xA);
|
header[2] = (ushort)SWAP_BYTES(0xA);
|
||||||
|
|
||||||
// flags 02 = maximum sub-compression flag
|
// flags 02 = maximum sub-compression flag
|
||||||
header[3] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
|
header[3] = ( store ) ? 0x0 : SWAP_BYTES(0x2);
|
||||||
|
@ -179,31 +179,31 @@ void jar::write_jar_header(const char* fname, bool store, int modtime,
|
||||||
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
|
header[4] = ( store ) ? 0x0 : SWAP_BYTES(0x08);
|
||||||
|
|
||||||
// Last modified date and time.
|
// Last modified date and time.
|
||||||
header[5] = GET_INT_LO(dostime);
|
header[5] = (ushort)GET_INT_LO(dostime);
|
||||||
header[6] = GET_INT_HI(dostime);
|
header[6] = (ushort)GET_INT_HI(dostime);
|
||||||
|
|
||||||
// CRC
|
// CRC
|
||||||
header[7] = GET_INT_LO(crc);
|
header[7] = (ushort)GET_INT_LO(crc);
|
||||||
header[8] = GET_INT_HI(crc);
|
header[8] = (ushort)GET_INT_HI(crc);
|
||||||
|
|
||||||
// Compressed length:
|
// Compressed length:
|
||||||
header[9] = GET_INT_LO(clen);
|
header[9] = (ushort)GET_INT_LO(clen);
|
||||||
header[10] = GET_INT_HI(clen);
|
header[10] = (ushort)GET_INT_HI(clen);
|
||||||
|
|
||||||
// Uncompressed length.
|
// Uncompressed length.
|
||||||
header[11] = GET_INT_LO(len);
|
header[11] = (ushort)GET_INT_LO(len);
|
||||||
header[12] = GET_INT_HI(len);
|
header[12] = (ushort)GET_INT_HI(len);
|
||||||
|
|
||||||
// Filename length
|
// Filename length
|
||||||
header[13] = SWAP_BYTES(fname_length);
|
header[13] = (ushort)SWAP_BYTES(fname_length);
|
||||||
// So called "extra field" length.
|
// So called "extra field" length.
|
||||||
header[14] = 0;
|
header[14] = 0;
|
||||||
|
|
||||||
// Write the LOC header to the output file.
|
// Write the LOC header to the output file.
|
||||||
write_data(header, sizeof(header));
|
write_data(header, (int)sizeof(header));
|
||||||
|
|
||||||
// Copy the fname to the header.
|
// Copy the fname to the header.
|
||||||
write_data((char*)fname, fname_length);
|
write_data((char*)fname, (int)fname_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char marker_comment[] = ZIP_ARCHIVE_MARKER_COMMENT;
|
static const char marker_comment[] = ZIP_ARCHIVE_MARKER_COMMENT;
|
||||||
|
@ -214,32 +214,32 @@ void jar::write_central_directory() {
|
||||||
ushort header[11];
|
ushort header[11];
|
||||||
|
|
||||||
// Create the End of Central Directory structure.
|
// Create the End of Central Directory structure.
|
||||||
header[0] = SWAP_BYTES(0x4B50);
|
header[0] = (ushort)SWAP_BYTES(0x4B50);
|
||||||
header[1] = SWAP_BYTES(0x0605);
|
header[1] = (ushort)SWAP_BYTES(0x0605);
|
||||||
// disk numbers
|
// disk numbers
|
||||||
header[2] = 0;
|
header[2] = 0;
|
||||||
header[3] = 0;
|
header[3] = 0;
|
||||||
// Number of entries in central directory.
|
// Number of entries in central directory.
|
||||||
header[4] = SWAP_BYTES(central_directory_count);
|
header[4] = (ushort)SWAP_BYTES(central_directory_count);
|
||||||
header[5] = SWAP_BYTES(central_directory_count);
|
header[5] = (ushort)SWAP_BYTES(central_directory_count);
|
||||||
// Size of the central directory}
|
// Size of the central directory}
|
||||||
header[6] = GET_INT_LO(central_directory.size());
|
header[6] = (ushort)GET_INT_LO((int)central_directory.size());
|
||||||
header[7] = GET_INT_HI(central_directory.size());
|
header[7] = (ushort)GET_INT_HI((int)central_directory.size());
|
||||||
// Offset of central directory within disk.
|
// Offset of central directory within disk.
|
||||||
header[8] = GET_INT_LO(output_file_offset);
|
header[8] = (ushort)GET_INT_LO(output_file_offset);
|
||||||
header[9] = GET_INT_HI(output_file_offset);
|
header[9] = (ushort)GET_INT_HI(output_file_offset);
|
||||||
// zipfile comment length;
|
// zipfile comment length;
|
||||||
header [10] = SWAP_BYTES(mc.len);
|
header [10] = (ushort)SWAP_BYTES((int)mc.len);
|
||||||
|
|
||||||
// Write the central directory.
|
// Write the central directory.
|
||||||
printcr(2, "Central directory at %d\n", output_file_offset);
|
PRINTCR((2, "Central directory at %d\n", output_file_offset));
|
||||||
write_data(central_directory.b);
|
write_data(central_directory.b);
|
||||||
|
|
||||||
// Write the End of Central Directory structure.
|
// Write the End of Central Directory structure.
|
||||||
printcr(2, "end-of-directory at %d\n", output_file_offset);
|
PRINTCR((2, "end-of-directory at %d\n", output_file_offset));
|
||||||
write_data(header, sizeof(header));
|
write_data(header, (int)sizeof(header));
|
||||||
|
|
||||||
printcr(2, "writing zip comment\n");
|
PRINTCR((2, "writing zip comment\n"));
|
||||||
// Write the comment.
|
// Write the comment.
|
||||||
write_data(mc);
|
write_data(mc);
|
||||||
}
|
}
|
||||||
|
@ -249,7 +249,7 @@ void jar::write_central_directory() {
|
||||||
// Open a Jar file and initialize.
|
// Open a Jar file and initialize.
|
||||||
void jar::openJarFile(const char* fname) {
|
void jar::openJarFile(const char* fname) {
|
||||||
if (!jarfp) {
|
if (!jarfp) {
|
||||||
printcr(1, "jar::openJarFile: opening %s\n",fname);
|
PRINTCR((1, "jar::openJarFile: opening %s\n",fname));
|
||||||
jarfp = fopen(fname, "wb");
|
jarfp = fopen(fname, "wb");
|
||||||
if (!jarfp) {
|
if (!jarfp) {
|
||||||
fprintf(u->errstrm, "Error: Could not open jar file: %s\n",fname);
|
fprintf(u->errstrm, "Error: Could not open jar file: %s\n",fname);
|
||||||
|
@ -262,25 +262,25 @@ void jar::openJarFile(const char* fname) {
|
||||||
void jar::addJarEntry(const char* fname,
|
void jar::addJarEntry(const char* fname,
|
||||||
bool deflate_hint, int modtime,
|
bool deflate_hint, int modtime,
|
||||||
bytes& head, bytes& tail) {
|
bytes& head, bytes& tail) {
|
||||||
int len = head.len + tail.len;
|
int len = (int)(head.len + tail.len);
|
||||||
int clen = 0;
|
int clen = 0;
|
||||||
|
|
||||||
uint crc = get_crc32(0L,Z_NULL,0);
|
uint crc = get_crc32(0,Z_NULL,0);
|
||||||
if (head.len != 0)
|
if (head.len != 0)
|
||||||
crc = get_crc32(crc, (uchar *)head.ptr, head.len);
|
crc = get_crc32(crc, (uchar *)head.ptr, (uint)head.len);
|
||||||
if (tail.len != 0)
|
if (tail.len != 0)
|
||||||
crc = get_crc32(crc, (uchar *)tail.ptr, tail.len);
|
crc = get_crc32(crc, (uchar *)tail.ptr, (uint)tail.len);
|
||||||
|
|
||||||
bool deflate = (deflate_hint && len > 0);
|
bool deflate = (deflate_hint && len > 0);
|
||||||
|
|
||||||
if (deflate) {
|
if (deflate) {
|
||||||
if (deflate_bytes(head, tail) == false) {
|
if (deflate_bytes(head, tail) == false) {
|
||||||
printcr(2, "Reverting to store fn=%s\t%d -> %d\n",
|
PRINTCR((2, "Reverting to store fn=%s\t%d -> %d\n",
|
||||||
fname, len, deflated.size());
|
fname, len, deflated.size()));
|
||||||
deflate = false;
|
deflate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
clen = (deflate) ? deflated.size() : len;
|
clen = (int)((deflate) ? deflated.size() : len);
|
||||||
add_to_jar_directory(fname, !deflate, modtime, len, clen, crc);
|
add_to_jar_directory(fname, !deflate, modtime, len, clen, crc);
|
||||||
write_jar_header( fname, !deflate, modtime, len, clen, crc);
|
write_jar_header( fname, !deflate, modtime, len, clen, crc);
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ void jar::closeJarFile(bool central) {
|
||||||
if (central) write_central_directory();
|
if (central) write_central_directory();
|
||||||
fflush(jarfp);
|
fflush(jarfp);
|
||||||
fclose(jarfp);
|
fclose(jarfp);
|
||||||
printcr(2, "jar::closeJarFile:closed jar-file\n");
|
PRINTCR((2, "jar::closeJarFile:closed jar-file\n"));
|
||||||
}
|
}
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
|
@ -338,6 +338,7 @@ uLong jar::get_dostime(int modtime) {
|
||||||
default_modtime = modtime; // catch a reasonable default
|
default_modtime = modtime; // catch a reasonable default
|
||||||
time_t t = modtime;
|
time_t t = modtime;
|
||||||
struct tm sbuf;
|
struct tm sbuf;
|
||||||
|
(void)memset((void*)&sbuf,0, sizeof(sbuf));
|
||||||
struct tm* s = gmtime_r(&t, &sbuf);
|
struct tm* s = gmtime_r(&t, &sbuf);
|
||||||
modtime_cache = modtime;
|
modtime_cache = modtime;
|
||||||
dostime_cache = dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
|
dostime_cache = dostime(s->tm_year + 1900, s->tm_mon + 1, s->tm_mday,
|
||||||
|
@ -355,7 +356,7 @@ uLong jar::get_dostime(int modtime) {
|
||||||
input data
|
input data
|
||||||
*/
|
*/
|
||||||
bool jar::deflate_bytes(bytes& head, bytes& tail) {
|
bool jar::deflate_bytes(bytes& head, bytes& tail) {
|
||||||
int len = head.len + tail.len;
|
int len = (int)(head.len + tail.len);
|
||||||
|
|
||||||
z_stream zs;
|
z_stream zs;
|
||||||
BYTES_OF(zs).clear();
|
BYTES_OF(zs).clear();
|
||||||
|
@ -368,26 +369,26 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) {
|
||||||
if (error != Z_OK) {
|
if (error != Z_OK) {
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case Z_MEM_ERROR:
|
case Z_MEM_ERROR:
|
||||||
printcr(2, "Error: deflate error : Out of memory \n");
|
PRINTCR((2, "Error: deflate error : Out of memory \n"));
|
||||||
break;
|
break;
|
||||||
case Z_STREAM_ERROR:
|
case Z_STREAM_ERROR:
|
||||||
printcr(2,"Error: deflate error : Invalid compression level \n");
|
PRINTCR((2,"Error: deflate error : Invalid compression level \n"));
|
||||||
break;
|
break;
|
||||||
case Z_VERSION_ERROR:
|
case Z_VERSION_ERROR:
|
||||||
printcr(2,"Error: deflate error : Invalid version\n");
|
PRINTCR((2,"Error: deflate error : Invalid version\n"));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
printcr(2,"Error: Internal deflate error error = %d\n", error);
|
PRINTCR((2,"Error: Internal deflate error error = %d\n", error));
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
deflated.empty();
|
deflated.empty();
|
||||||
zs.next_out = (uchar*) deflated.grow(len + (len/2));
|
zs.next_out = (uchar*) deflated.grow(len + (len/2));
|
||||||
zs.avail_out = deflated.size();
|
zs.avail_out = (int)deflated.size();
|
||||||
|
|
||||||
zs.next_in = (uchar*)head.ptr;
|
zs.next_in = (uchar*)head.ptr;
|
||||||
zs.avail_in = head.len;
|
zs.avail_in = (int)head.len;
|
||||||
|
|
||||||
bytes* first = &head;
|
bytes* first = &head;
|
||||||
bytes* last = &tail;
|
bytes* last = &tail;
|
||||||
|
@ -400,28 +401,28 @@ bool jar::deflate_bytes(bytes& head, bytes& tail) {
|
||||||
|
|
||||||
if (first != null && error == Z_OK) {
|
if (first != null && error == Z_OK) {
|
||||||
zs.next_in = (uchar*) first->ptr;
|
zs.next_in = (uchar*) first->ptr;
|
||||||
zs.avail_in = first->len;
|
zs.avail_in = (int)first->len;
|
||||||
error = deflate(&zs, Z_NO_FLUSH);
|
error = deflate(&zs, Z_NO_FLUSH);
|
||||||
}
|
}
|
||||||
if (error == Z_OK) {
|
if (error == Z_OK) {
|
||||||
zs.next_in = (uchar*) last->ptr;
|
zs.next_in = (uchar*) last->ptr;
|
||||||
zs.avail_in = last->len;
|
zs.avail_in = (int)last->len;
|
||||||
error = deflate(&zs, Z_FINISH);
|
error = deflate(&zs, Z_FINISH);
|
||||||
}
|
}
|
||||||
if (error == Z_STREAM_END) {
|
if (error == Z_STREAM_END) {
|
||||||
if (len > zs.total_out ) {
|
if (len > (int)zs.total_out ) {
|
||||||
printcr(2, "deflate compressed data %d -> %d\n", len, zs.total_out);
|
PRINTCR((2, "deflate compressed data %d -> %d\n", len, zs.total_out));
|
||||||
deflated.b.len = zs.total_out;
|
deflated.b.len = zs.total_out;
|
||||||
deflateEnd(&zs);
|
deflateEnd(&zs);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
printcr(2, "deflate expanded data %d -> %d\n", len, zs.total_out);
|
PRINTCR((2, "deflate expanded data %d -> %d\n", len, zs.total_out));
|
||||||
deflateEnd(&zs);
|
deflateEnd(&zs);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
deflateEnd(&zs);
|
deflateEnd(&zs);
|
||||||
printcr(2, "Error: deflate error deflate did not finish error=%d\n",error);
|
PRINTCR((2, "Error: deflate error deflate did not finish error=%d\n",error));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -486,7 +487,7 @@ void gunzip::init(unpacker* u_) {
|
||||||
BYTES_OF(*this).clear();
|
BYTES_OF(*this).clear();
|
||||||
u = u_;
|
u = u_;
|
||||||
assert(u->gzin == null); // once only, please
|
assert(u->gzin == null); // once only, please
|
||||||
read_input_fn = (void*)(intptr_t)u->read_input_fn;
|
read_input_fn = (void*)u->read_input_fn;
|
||||||
zstream = NEW(z_stream, 1);
|
zstream = NEW(z_stream, 1);
|
||||||
u->gzin = this;
|
u->gzin = this;
|
||||||
u->read_input_fn = read_input_via_gzip;
|
u->read_input_fn = read_input_via_gzip;
|
||||||
|
@ -555,7 +556,7 @@ void gunzip::read_fixed_field(char* buf, size_t buflen) {
|
||||||
if (aborting()) return;
|
if (aborting()) return;
|
||||||
jlong nr = ((unpacker::read_input_fn_t)read_input_fn)
|
jlong nr = ((unpacker::read_input_fn_t)read_input_fn)
|
||||||
(u, buf, buflen, buflen);
|
(u, buf, buflen, buflen);
|
||||||
if (nr != buflen)
|
if ((size_t)nr != buflen)
|
||||||
u->abort("short stream header");
|
u->abort("short stream header");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2001-2004 Sun Microsystems, Inc. All Rights Reserved.
|
* Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
|
@ -69,7 +69,7 @@ struct jar {
|
||||||
|
|
||||||
// Private Methods
|
// Private Methods
|
||||||
void write_data(void* ptr, int len);
|
void write_data(void* ptr, int len);
|
||||||
void write_data(bytes& b) { write_data(b.ptr, b.len); }
|
void write_data(bytes& b) { write_data(b.ptr, (int)b.len); }
|
||||||
void add_to_jar_directory(const char* fname, bool store, int modtime,
|
void add_to_jar_directory(const char* fname, bool store, int modtime,
|
||||||
int len, int clen, uLong crc);
|
int len, int clen, uLong crc);
|
||||||
void write_jar_header(const char* fname, bool store, int modtime,
|
void write_jar_header(const char* fname, bool store, int modtime,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue