From 362e8cb02a07d7abf8ac5daf6376bd8c3b97ddb0 Mon Sep 17 00:00:00 2001 From: "verwaest@chromium.org" Date: Tue, 23 Oct 2012 08:06:28 +0000 Subject: [PATCH] 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 --- src/json-parser.h | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/src/json-parser.h b/src/json-parser.h index 40116fa59a..0c26c184ee 100644 --- a/src/json-parser.h +++ b/src/json-parser.h @@ -154,6 +154,7 @@ class JsonParser BASE_EMBEDDED { inline Zone* zone() const { return zone_; } static const int kInitialSpecialStringLength = 1024; + static const int kPretenureTreshold = 100 * 1024; private: @@ -161,6 +162,7 @@ class JsonParser BASE_EMBEDDED { int source_length_; Handle seq_source_; + PretenureFlag pretenure_; Isolate* isolate_; Factory* factory_; Handle object_constructor_; @@ -180,6 +182,7 @@ Handle JsonParser::ParseJson(Handle source, FlattenString(source); source_ = source; source_length_ = source_->length(); + pretenure_ = (source_length_ >= kPretenureTreshold) ? TENURED : NOT_TENURED; // Optimized fast case where we only have ASCII characters. if (seq_ascii) { @@ -281,7 +284,7 @@ template Handle JsonParser::ParseJsonObject() { Handle prototype; Handle json_object = - factory()->NewJSObject(object_constructor()); + factory()->NewJSObject(object_constructor(), pretenure_); ASSERT_EQ(c0_, '{'); AdvanceSkipWhitespace(); @@ -365,11 +368,12 @@ Handle JsonParser::ParseJsonArray() { AdvanceSkipWhitespace(); // Allocate a fixed array with all the elements. Handle fast_elements = - factory()->NewFixedArray(elements.length()); + factory()->NewFixedArray(elements.length(), pretenure_); for (int i = 0, n = elements.length(); i < n; 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 JsonParser::ParseJsonNumber() { buffer.Dispose(); } SkipWhitespace(); - return factory()->NewNumber(number); + return factory()->NewNumber(number, pretenure_); } @@ -454,16 +458,22 @@ inline void SeqStringSet(Handle seq_str, int i, uc32 c) { } template -inline Handle NewRawString(Factory* factory, int length); +inline Handle NewRawString(Factory* factory, + int length, + PretenureFlag pretenure); template <> -inline Handle NewRawString(Factory* factory, int length) { - return factory->NewRawTwoByteString(length, NOT_TENURED); +inline Handle NewRawString(Factory* factory, + int length, + PretenureFlag pretenure) { + return factory->NewRawTwoByteString(length, pretenure); } template <> -inline Handle NewRawString(Factory* factory, int length) { - return factory->NewRawAsciiString(length, NOT_TENURED); +inline Handle NewRawString(Factory* factory, + int length, + PretenureFlag pretenure) { + return factory->NewRawAsciiString(length, pretenure); } @@ -477,7 +487,8 @@ Handle JsonParser::SlowScanJsonString( int count = end - start; int max_length = count + source_length_ - position_; int length = Min(max_length, Max(kInitialSpecialStringLength, 2 * count)); - Handle seq_str = NewRawString(factory(), length); + Handle seq_str = + NewRawString(factory(), length, pretenure_); // Copy prefix into seq_str. SinkChar* dest = seq_str->GetChars(); String::WriteToFlat(*prefix, dest, start, end); @@ -656,10 +667,10 @@ Handle JsonParser::ScanJsonString() { Handle result; if (seq_ascii && is_symbol) { result = factory()->LookupAsciiSymbol(seq_source_, - beg_pos, - length); + beg_pos, + length); } else { - result = factory()->NewRawAsciiString(length); + result = factory()->NewRawAsciiString(length, pretenure_); char* dest = SeqAsciiString::cast(*result)->GetChars(); String::WriteToFlat(*source_, dest, beg_pos, position_); }