From 252514ca23cc53a22687a87d16385c2f7962486b Mon Sep 17 00:00:00 2001 From: "bak@chromium.org" Date: Fri, 26 Jun 2009 13:09:50 +0000 Subject: [PATCH] - Inlined the code for make simple cons strings. - Simplify generated code for Runtime_** functions. Review URL: http://codereview.chromium.org/149068 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2283 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/factory.cc | 2 -- src/heap.cc | 22 ++++++++++++++++++---- src/heap.h | 3 +-- src/runtime.cc | 24 +++--------------------- src/top.cc | 5 +++++ src/top.h | 1 + 6 files changed, 28 insertions(+), 29 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index fad3e9c281..fe19873ab3 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -92,8 +92,6 @@ Handle Factory::NewRawTwoByteString(int length, Handle Factory::NewConsString(Handle first, Handle second) { - if (first->length() == 0) return second; - if (second->length() == 0) return first; CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String); } diff --git a/src/heap.cc b/src/heap.cc index 2573be8f2b..bf6fccd9f4 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -1536,14 +1536,24 @@ Object* Heap::AllocateSharedFunctionInfo(Object* name) { } -Object* Heap::AllocateConsString(String* first, - String* second) { +Object* Heap::AllocateConsString(String* first, String* second) { int first_length = first->length(); + if (first_length == 0) return second; + int second_length = second->length(); + if (second_length == 0) return first; + int length = first_length + second_length; bool is_ascii = first->IsAsciiRepresentation() && second->IsAsciiRepresentation(); + // Make sure that an out of memory exception is thrown if the length + // of the new cons string is too large to fit in a Smi. + if (length > Smi::kMaxValue || length < -0) { + Top::context()->mark_out_of_memory(); + return Failure::OutOfMemoryException(); + } + // If the resulting string is small make a flat string. if (length < String::kMinNonFlatLength) { ASSERT(first->IsFlat()); @@ -1553,8 +1563,12 @@ Object* Heap::AllocateConsString(String* first, if (result->IsFailure()) return result; // Copy the characters into the new object. char* dest = SeqAsciiString::cast(result)->GetChars(); - String::WriteToFlat(first, dest, 0, first_length); - String::WriteToFlat(second, dest + first_length, 0, second_length); + // Copy first part. + char* src = SeqAsciiString::cast(first)->GetChars(); + for (int i = 0; i < first_length; i++) *dest++ = src[i]; + // Copy second part. + src = SeqAsciiString::cast(second)->GetChars(); + for (int i = 0; i < second_length; i++) *dest++ = src[i]; return result; } else { Object* result = AllocateRawTwoByteString(length); diff --git a/src/heap.h b/src/heap.h index 9c19ec878b..31adcbdba8 100644 --- a/src/heap.h +++ b/src/heap.h @@ -507,8 +507,7 @@ class Heap : public AllStatic { // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // failed. // Please note this does not perform a garbage collection. - static Object* AllocateConsString(String* first, - String* second); + static Object* AllocateConsString(String* first, String* second); // Allocates a new sliced string object which is a slice of an underlying // string buffer stretching from the index start (inclusive) to the index diff --git a/src/runtime.cc b/src/runtime.cc index ad02f5d5b4..dcff28bc36 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -50,9 +50,8 @@ namespace v8 { namespace internal { -#define RUNTIME_ASSERT(value) do { \ - if (!(value)) return IllegalOperation(); \ -} while (false) +#define RUNTIME_ASSERT(value) \ + if (!(value)) return Top::ThrowIllegalOperation(); // Cast the given object to a value of the specified type and store // it in a variable with the given name. If the object is not of the @@ -97,11 +96,6 @@ namespace internal { static StaticResource runtime_string_input_buffer; -static Object* IllegalOperation() { - return Top::Throw(Heap::illegal_access_symbol()); -} - - static Object* DeepCopyBoilerplate(JSObject* boilerplate) { StackLimitCheck check; if (check.HasOverflowed()) return Top::StackOverflow(); @@ -3704,20 +3698,8 @@ static Object* Runtime_NumberMod(Arguments args) { static Object* Runtime_StringAdd(Arguments args) { NoHandleAllocation ha; ASSERT(args.length() == 2); - CONVERT_CHECKED(String, str1, args[0]); CONVERT_CHECKED(String, str2, args[1]); - int len1 = str1->length(); - int len2 = str2->length(); - if (len1 == 0) return str2; - if (len2 == 0) return str1; - int length_sum = len1 + len2; - // Make sure that an out of memory exception is thrown if the length - // of the new cons string is too large to fit in a Smi. - if (length_sum > Smi::kMaxValue || length_sum < 0) { - Top::context()->mark_out_of_memory(); - return Failure::OutOfMemoryException(); - } return Heap::AllocateConsString(str1, str2); } @@ -4584,7 +4566,7 @@ static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) { ASSERT(args.length() == 2); if (!args[0]->IsContext() || !args[1]->IsString()) { - return MakePair(IllegalOperation(), NULL); + return MakePair(Top::ThrowIllegalOperation(), NULL); } Handle context = args.at(0); Handle name = args.at(1); diff --git a/src/top.cc b/src/top.cc index 42a2b7edfb..96d4a01e71 100644 --- a/src/top.cc +++ b/src/top.cc @@ -611,6 +611,11 @@ Failure* Top::ReThrow(Object* exception, MessageLocation* location) { } +Failure* Top::ThrowIllegalOperation() { + return Throw(Heap::illegal_access_symbol()); +} + + void Top::ScheduleThrow(Object* exception) { // When scheduling a throw we first throw the exception to get the // error reporting if it is uncaught before rescheduling it. diff --git a/src/top.h b/src/top.h index 53d67e555f..25242f7ccf 100644 --- a/src/top.h +++ b/src/top.h @@ -239,6 +239,7 @@ class Top { static Failure* ReThrow(Object* exception, MessageLocation* location = NULL); static void ScheduleThrow(Object* exception); static void ReportPendingMessages(); + static Failure* ThrowIllegalOperation(); // Promote a scheduled exception to pending. Asserts has_scheduled_exception. static Object* PromoteScheduledException();