From 2d196e63938e614be71ef34119e2534bf76d93e8 Mon Sep 17 00:00:00 2001 From: "vitalyr@chromium.org" Date: Fri, 18 Mar 2011 23:55:11 +0000 Subject: [PATCH] Avoid TLS accesses in QuoteJsonString. Review URL: http://codereview.chromium.org/6713056 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7275 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/runtime.cc | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/src/runtime.cc b/src/runtime.cc index 9bbca2dbda..93445ec114 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -5071,23 +5071,24 @@ static const byte JsonQuoteLengths[kQuoteTableLength] = { template -MaybeObject* AllocateRawString(int length); +MaybeObject* AllocateRawString(Isolate* isolate, int length); template <> -MaybeObject* AllocateRawString(int length) { - return HEAP->AllocateRawTwoByteString(length); +MaybeObject* AllocateRawString(Isolate* isolate, int length) { + return isolate->heap()->AllocateRawTwoByteString(length); } template <> -MaybeObject* AllocateRawString(int length) { - return HEAP->AllocateRawAsciiString(length); +MaybeObject* AllocateRawString(Isolate* isolate, int length) { + return isolate->heap()->AllocateRawAsciiString(length); } template -static MaybeObject* SlowQuoteJsonString(Vector characters) { +static MaybeObject* SlowQuoteJsonString(Isolate* isolate, + Vector characters) { int length = characters.length(); const Char* read_cursor = characters.start(); const Char* end = read_cursor + length; @@ -5101,7 +5102,8 @@ static MaybeObject* SlowQuoteJsonString(Vector characters) { quoted_length += JsonQuoteLengths[static_cast(c)]; } } - MaybeObject* new_alloc = AllocateRawString(quoted_length); + MaybeObject* new_alloc = AllocateRawString(isolate, + quoted_length); Object* new_object; if (!new_alloc->ToObject(&new_object)) { return new_alloc; @@ -5133,29 +5135,31 @@ static MaybeObject* SlowQuoteJsonString(Vector characters) { template -static MaybeObject* QuoteJsonString(Vector characters) { +static MaybeObject* QuoteJsonString(Isolate* isolate, + Vector characters) { int length = characters.length(); - COUNTERS->quote_json_char_count()->Increment(length); + isolate->counters()->quote_json_char_count()->Increment(length); const int kSpaceForQuotes = 2 + (comma ? 1 :0); int worst_case_length = length * kJsonQuoteWorstCaseBlowup + kSpaceForQuotes; if (worst_case_length > kMaxGuaranteedNewSpaceString) { - return SlowQuoteJsonString(characters); + return SlowQuoteJsonString(isolate, characters); } - MaybeObject* new_alloc = AllocateRawString(worst_case_length); + MaybeObject* new_alloc = AllocateRawString(isolate, + worst_case_length); Object* new_object; if (!new_alloc->ToObject(&new_object)) { return new_alloc; } - if (!HEAP->new_space()->Contains(new_object)) { + if (!isolate->heap()->new_space()->Contains(new_object)) { // Even if our string is small enough to fit in new space we still have to // handle it being allocated in old space as may happen in the third // attempt. See CALL_AND_RETRY in heap-inl.h and similar code in // CEntryStub::GenerateCore. - return SlowQuoteJsonString(characters); + return SlowQuoteJsonString(isolate, characters); } StringType* new_string = StringType::cast(new_object); - ASSERT(HEAP->new_space()->Contains(new_string)); + ASSERT(isolate->heap()->new_space()->Contains(new_string)); STATIC_ASSERT(SeqTwoByteString::kHeaderSize == SeqAsciiString::kHeaderSize); Char* write_cursor = reinterpret_cast( @@ -5192,8 +5196,8 @@ static MaybeObject* QuoteJsonString(Vector characters) { int final_length = static_cast( write_cursor - reinterpret_cast( new_string->address() + SeqAsciiString::kHeaderSize)); - HEAP->new_space()->ShrinkStringAtAllocationBoundary(new_string, - final_length); + isolate->heap()->new_space()->ShrinkStringAtAllocationBoundary( + new_string, final_length); return new_string; } @@ -5212,9 +5216,11 @@ static MaybeObject* Runtime_QuoteJSONString(RUNTIME_CALLING_CONVENTION) { ASSERT(str->IsFlat()); } if (str->IsTwoByteRepresentation()) { - return QuoteJsonString(str->ToUC16Vector()); + return QuoteJsonString(isolate, + str->ToUC16Vector()); } else { - return QuoteJsonString(str->ToAsciiVector()); + return QuoteJsonString(isolate, + str->ToAsciiVector()); } } @@ -5233,9 +5239,11 @@ static MaybeObject* Runtime_QuoteJSONStringComma(RUNTIME_CALLING_CONVENTION) { ASSERT(str->IsFlat()); } if (str->IsTwoByteRepresentation()) { - return QuoteJsonString(str->ToUC16Vector()); + return QuoteJsonString(isolate, + str->ToUC16Vector()); } else { - return QuoteJsonString(str->ToAsciiVector()); + return QuoteJsonString(isolate, + str->ToAsciiVector()); } }