Pretenure JSON graph if the input string is larger than 100*1024 chars.

Review URL: https://chromiumcodereview.appspot.com/11238031

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12795 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
verwaest@chromium.org 2012-10-23 08:06:28 +00:00
parent b882786349
commit 362e8cb02a

View File

@ -154,6 +154,7 @@ class JsonParser BASE_EMBEDDED {
inline Zone* zone() const { return zone_; } inline Zone* zone() const { return zone_; }
static const int kInitialSpecialStringLength = 1024; static const int kInitialSpecialStringLength = 1024;
static const int kPretenureTreshold = 100 * 1024;
private: private:
@ -161,6 +162,7 @@ class JsonParser BASE_EMBEDDED {
int source_length_; int source_length_;
Handle<SeqAsciiString> seq_source_; Handle<SeqAsciiString> seq_source_;
PretenureFlag pretenure_;
Isolate* isolate_; Isolate* isolate_;
Factory* factory_; Factory* factory_;
Handle<JSFunction> object_constructor_; Handle<JSFunction> object_constructor_;
@ -180,6 +182,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJson(Handle<String> source,
FlattenString(source); FlattenString(source);
source_ = source; source_ = source;
source_length_ = source_->length(); source_length_ = source_->length();
pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED;
// Optimized fast case where we only have ASCII characters. // Optimized fast case where we only have ASCII characters.
if (seq_ascii) { if (seq_ascii) {
@ -281,7 +284,7 @@ template <bool seq_ascii>
Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() { Handle<Object> JsonParser<seq_ascii>::ParseJsonObject() {
Handle<Object> prototype; Handle<Object> prototype;
Handle<JSObject> json_object = Handle<JSObject> json_object =
factory()->NewJSObject(object_constructor()); factory()->NewJSObject(object_constructor(), pretenure_);
ASSERT_EQ(c0_, '{'); ASSERT_EQ(c0_, '{');
AdvanceSkipWhitespace(); AdvanceSkipWhitespace();
@ -365,11 +368,12 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonArray() {
AdvanceSkipWhitespace(); AdvanceSkipWhitespace();
// Allocate a fixed array with all the elements. // Allocate a fixed array with all the elements.
Handle<FixedArray> fast_elements = Handle<FixedArray> fast_elements =
factory()->NewFixedArray(elements.length()); factory()->NewFixedArray(elements.length(), pretenure_);
for (int i = 0, n = elements.length(); i < n; i++) { for (int i = 0, n = elements.length(); i < n; i++) {
fast_elements->set(i, *elements[i]); fast_elements->set(i, *elements[i]);
} }
return factory()->NewJSArrayWithElements(fast_elements); return factory()->NewJSArrayWithElements(
fast_elements, FAST_ELEMENTS, pretenure_);
} }
@ -436,7 +440,7 @@ Handle<Object> JsonParser<seq_ascii>::ParseJsonNumber() {
buffer.Dispose(); buffer.Dispose();
} }
SkipWhitespace(); SkipWhitespace();
return factory()->NewNumber(number); return factory()->NewNumber(number, pretenure_);
} }
@ -454,16 +458,22 @@ inline void SeqStringSet(Handle<SeqAsciiString> seq_str, int i, uc32 c) {
} }
template <typename StringType> template <typename StringType>
inline Handle<StringType> NewRawString(Factory* factory, int length); inline Handle<StringType> NewRawString(Factory* factory,
int length,
PretenureFlag pretenure);
template <> template <>
inline Handle<SeqTwoByteString> NewRawString(Factory* factory, int length) { inline Handle<SeqTwoByteString> NewRawString(Factory* factory,
return factory->NewRawTwoByteString(length, NOT_TENURED); int length,
PretenureFlag pretenure) {
return factory->NewRawTwoByteString(length, pretenure);
} }
template <> template <>
inline Handle<SeqAsciiString> NewRawString(Factory* factory, int length) { inline Handle<SeqAsciiString> NewRawString(Factory* factory,
return factory->NewRawAsciiString(length, NOT_TENURED); int length,
PretenureFlag pretenure) {
return factory->NewRawAsciiString(length, pretenure);
} }
@ -477,7 +487,8 @@ Handle<String> JsonParser<seq_ascii>::SlowScanJsonString(
int count = end - start; int count = end - start;
int max_length = count + source_length_ - position_; int max_length = count + source_length_ - position_;
int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count));
Handle<StringType> seq_str = NewRawString<StringType>(factory(), length); Handle<StringType> seq_str =
NewRawString<StringType>(factory(), length, pretenure_);
// Copy prefix into seq_str. // Copy prefix into seq_str.
SinkChar* dest = seq_str->GetChars(); SinkChar* dest = seq_str->GetChars();
String::WriteToFlat(*prefix, dest, start, end); String::WriteToFlat(*prefix, dest, start, end);
@ -659,7 +670,7 @@ Handle<String> JsonParser<seq_ascii>::ScanJsonString() {
beg_pos, beg_pos,
length); length);
} else { } else {
result = factory()->NewRawAsciiString(length); result = factory()->NewRawAsciiString(length, pretenure_);
char* dest = SeqAsciiString::cast(*result)->GetChars(); char* dest = SeqAsciiString::cast(*result)->GetChars();
String::WriteToFlat(*source_, dest, beg_pos, position_); String::WriteToFlat(*source_, dest, beg_pos, position_);
} }