Closed Bug 103042 Opened 24 years ago Closed 24 years ago

O(n**2) arena allocation in jsscan.c on long string literals

Categories

(Core :: JavaScript Engine, defect, P1)

defect

Tracking

()

VERIFIED FIXED
mozilla0.9.6

People

(Reporter: brendan, Assigned: brendan)

References

()

Details

(Keywords: js1.5)

Attachments

(1 file)

See the URL. Fix coming up. /be
Status: NEW → ASSIGNED
Keywords: js1.5, mozilla0.9.6
Priority: -- → P1
Target Milestone: --- → mozilla0.9.6
Comment on attachment 51994 [details] [diff] [review] proposed fix, please review > if (!base) { >- JS_ARENA_ALLOCATE_CAST(base, jschar *, pool, tbincr); >+ tbsize = TBMIN * sizeof(jschar); >+ length = TBMIN; >+ JS_ARENA_ALLOCATE_CAST(base, jschar *, pool, tbsize); > } else { >- tbsize = (size_t)(length * sizeof(jschar)); >- JS_ARENA_GROW_CAST(base, jschar *, pool, tbsize, tbincr); >+ length = PTRDIFF(tb->limit, base, jschar); >+ tbsize = length * sizeof(jschar); >+ length <<= 1; >+ JS_ARENA_GROW_CAST(base, jschar *, pool, tbsize, tbsize); > } > if (!base) { > JS_ReportOutOfMemory(cx); > return JS_FALSE; > } > tb->base = base; >- tb->limit = base + length + length + TBINCR; >+ tb->limit = base + length; So based on my reading of this, we never really grow, and we might well crash, since limit overstates the allocation. Shouldn't we be shifting length before we use it to compute tbsize for reallocation?
shaver, give me some credit here! Note that the patch passes tbsize and the size and incr parameters (final two) to JS_ARENA_GROW_CAST, which has the direct effect of doubling the current allocation size. We update length after computing tbsize for this reason. Both tbsize+tbsize and length<<=1 double the byte- and jschar-reckoned "sizes", and in the right order. /be
Comment on attachment 51994 [details] [diff] [review] proposed fix, please review I hate being stupid. You're right, of course. sr=shaver
Attachment #51994 - Flags: superreview+
waterson, this was the patch I mentioned, that might help reduce the bloatblame attributed (due to dlsym limitations) to js_MatchToken. Anyone -- I need an r=, I'd like to get this patch in. /be
Comment on attachment 51994 [details] [diff] [review] proposed fix, please review r=jband
Attachment #51994 - Flags: review+
Fix is in. /be
Status: ASSIGNED → RESOLVED
Closed: 24 years ago
Resolution: --- → FIXED
Marking Verified -
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: