Commit 252514ca authored by bak@chromium.org's avatar bak@chromium.org

- 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
parent 0746d930
...@@ -92,8 +92,6 @@ Handle<String> Factory::NewRawTwoByteString(int length, ...@@ -92,8 +92,6 @@ Handle<String> Factory::NewRawTwoByteString(int length,
Handle<String> Factory::NewConsString(Handle<String> first, Handle<String> Factory::NewConsString(Handle<String> first,
Handle<String> second) { Handle<String> second) {
if (first->length() == 0) return second;
if (second->length() == 0) return first;
CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String); CALL_HEAP_FUNCTION(Heap::AllocateConsString(*first, *second), String);
} }
......
...@@ -1536,14 +1536,24 @@ Object* Heap::AllocateSharedFunctionInfo(Object* name) { ...@@ -1536,14 +1536,24 @@ Object* Heap::AllocateSharedFunctionInfo(Object* name) {
} }
Object* Heap::AllocateConsString(String* first, Object* Heap::AllocateConsString(String* first, String* second) {
String* second) {
int first_length = first->length(); int first_length = first->length();
if (first_length == 0) return second;
int second_length = second->length(); int second_length = second->length();
if (second_length == 0) return first;
int length = first_length + second_length; int length = first_length + second_length;
bool is_ascii = first->IsAsciiRepresentation() bool is_ascii = first->IsAsciiRepresentation()
&& second->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 the resulting string is small make a flat string.
if (length < String::kMinNonFlatLength) { if (length < String::kMinNonFlatLength) {
ASSERT(first->IsFlat()); ASSERT(first->IsFlat());
...@@ -1553,8 +1563,12 @@ Object* Heap::AllocateConsString(String* first, ...@@ -1553,8 +1563,12 @@ Object* Heap::AllocateConsString(String* first,
if (result->IsFailure()) return result; if (result->IsFailure()) return result;
// Copy the characters into the new object. // Copy the characters into the new object.
char* dest = SeqAsciiString::cast(result)->GetChars(); char* dest = SeqAsciiString::cast(result)->GetChars();
String::WriteToFlat(first, dest, 0, first_length); // Copy first part.
String::WriteToFlat(second, dest + first_length, 0, second_length); 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; return result;
} else { } else {
Object* result = AllocateRawTwoByteString(length); Object* result = AllocateRawTwoByteString(length);
......
...@@ -507,8 +507,7 @@ class Heap : public AllStatic { ...@@ -507,8 +507,7 @@ class Heap : public AllStatic {
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation // Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
// failed. // failed.
// Please note this does not perform a garbage collection. // Please note this does not perform a garbage collection.
static Object* AllocateConsString(String* first, static Object* AllocateConsString(String* first, String* second);
String* second);
// Allocates a new sliced string object which is a slice of an underlying // Allocates a new sliced string object which is a slice of an underlying
// string buffer stretching from the index start (inclusive) to the index // string buffer stretching from the index start (inclusive) to the index
......
...@@ -50,9 +50,8 @@ namespace v8 { ...@@ -50,9 +50,8 @@ namespace v8 {
namespace internal { namespace internal {
#define RUNTIME_ASSERT(value) do { \ #define RUNTIME_ASSERT(value) \
if (!(value)) return IllegalOperation(); \ if (!(value)) return Top::ThrowIllegalOperation();
} while (false)
// Cast the given object to a value of the specified type and store // 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 // it in a variable with the given name. If the object is not of the
...@@ -97,11 +96,6 @@ namespace internal { ...@@ -97,11 +96,6 @@ namespace internal {
static StaticResource<StringInputBuffer> runtime_string_input_buffer; static StaticResource<StringInputBuffer> runtime_string_input_buffer;
static Object* IllegalOperation() {
return Top::Throw(Heap::illegal_access_symbol());
}
static Object* DeepCopyBoilerplate(JSObject* boilerplate) { static Object* DeepCopyBoilerplate(JSObject* boilerplate) {
StackLimitCheck check; StackLimitCheck check;
if (check.HasOverflowed()) return Top::StackOverflow(); if (check.HasOverflowed()) return Top::StackOverflow();
...@@ -3704,20 +3698,8 @@ static Object* Runtime_NumberMod(Arguments args) { ...@@ -3704,20 +3698,8 @@ static Object* Runtime_NumberMod(Arguments args) {
static Object* Runtime_StringAdd(Arguments args) { static Object* Runtime_StringAdd(Arguments args) {
NoHandleAllocation ha; NoHandleAllocation ha;
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
CONVERT_CHECKED(String, str1, args[0]); CONVERT_CHECKED(String, str1, args[0]);
CONVERT_CHECKED(String, str2, args[1]); 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); return Heap::AllocateConsString(str1, str2);
} }
...@@ -4584,7 +4566,7 @@ static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) { ...@@ -4584,7 +4566,7 @@ static ObjectPair LoadContextSlotHelper(Arguments args, bool throw_error) {
ASSERT(args.length() == 2); ASSERT(args.length() == 2);
if (!args[0]->IsContext() || !args[1]->IsString()) { if (!args[0]->IsContext() || !args[1]->IsString()) {
return MakePair(IllegalOperation(), NULL); return MakePair(Top::ThrowIllegalOperation(), NULL);
} }
Handle<Context> context = args.at<Context>(0); Handle<Context> context = args.at<Context>(0);
Handle<String> name = args.at<String>(1); Handle<String> name = args.at<String>(1);
......
...@@ -611,6 +611,11 @@ Failure* Top::ReThrow(Object* exception, MessageLocation* location) { ...@@ -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) { void Top::ScheduleThrow(Object* exception) {
// When scheduling a throw we first throw the exception to get the // When scheduling a throw we first throw the exception to get the
// error reporting if it is uncaught before rescheduling it. // error reporting if it is uncaught before rescheduling it.
......
...@@ -239,6 +239,7 @@ class Top { ...@@ -239,6 +239,7 @@ class Top {
static Failure* ReThrow(Object* exception, MessageLocation* location = NULL); static Failure* ReThrow(Object* exception, MessageLocation* location = NULL);
static void ScheduleThrow(Object* exception); static void ScheduleThrow(Object* exception);
static void ReportPendingMessages(); static void ReportPendingMessages();
static Failure* ThrowIllegalOperation();
// Promote a scheduled exception to pending. Asserts has_scheduled_exception. // Promote a scheduled exception to pending. Asserts has_scheduled_exception.
static Object* PromoteScheduledException(); static Object* PromoteScheduledException();
......
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