Commit 3f8a1917 authored by ricow@chromium.org's avatar ricow@chromium.org

Double allocation size for special json strings on every resize (fixes

crbug 83877)

The issue was that with the relatively small start and increment size of the string we created a ton of string handles when scanning a large string with special characters (500k+ in this case).

In addition, since we can not be sure the the newly allocated string
is in newspace a check is introduced and if not a filler object is
inserted instead of shrinking.
Review URL: http://codereview.chromium.org/7075009

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8082 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 331e6102
......@@ -380,7 +380,7 @@ Token::Value JsonParser::SlowScanJsonString() {
while (c0_ != '"') {
// Create new seq string
if (count >= kInitialSpecialStringSize * allocation_count) {
allocation_count++;
allocation_count = allocation_count * 2;
int new_size = allocation_count * kInitialSpecialStringSize;
Handle<String> new_two_byte =
isolate()->factory()->NewRawTwoByteString(new_size,
......@@ -443,10 +443,18 @@ Token::Value JsonParser::SlowScanJsonString() {
Advance();
// Shrink the the string to our length.
isolate()->heap()->
new_space()->
ShrinkStringAtAllocationBoundary<SeqTwoByteString>(*seq_two_byte,
count);
if (isolate()->heap()->InNewSpace(*seq_two_byte)) {
isolate()->heap()->new_space()->
ShrinkStringAtAllocationBoundary<SeqTwoByteString>(*seq_two_byte,
count);
} else {
int string_size = SeqTwoByteString::SizeFor(count);
int allocated_string_size =
SeqTwoByteString::SizeFor(kInitialSpecialStringSize * allocation_count);
int delta = allocated_string_size - string_size;
Address start_filler_object = seq_two_byte->address() + string_size;
isolate()->heap()->CreateFillerObjectAt(start_filler_object, delta);
}
string_val_ = isolate()->factory()->NewConsString(ascii, seq_two_byte);
return Token::STRING;
}
......
......@@ -135,7 +135,7 @@ class JsonParser BASE_EMBEDDED {
int end_pos;
};
static const int kInitialSpecialStringSize = 100;
static const int kInitialSpecialStringSize = 1024;
private:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment