Commit 4766a592 authored by bak@chromium.org's avatar bak@chromium.org

- Pushed source code for functions into old space.

- Renamed TryFlattenIfNotFlat to TryFlatten.

Review URL: http://codereview.chromium.org/661181

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3976 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1d330492
...@@ -2615,7 +2615,7 @@ int String::WriteAscii(char* buffer, int start, int length) const { ...@@ -2615,7 +2615,7 @@ int String::WriteAscii(char* buffer, int start, int length) const {
StringTracker::RecordWrite(str); StringTracker::RecordWrite(str);
// Flatten the string for efficiency. This applies whether we are // Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters. // using StringInputBuffer or Get(i) to access the characters.
str->TryFlattenIfNotFlat(); str->TryFlatten();
int end = length; int end = length;
if ( (length == -1) || (length > str->length() - start) ) if ( (length == -1) || (length > str->length() - start) )
end = str->length() - start; end = str->length() - start;
......
...@@ -203,7 +203,7 @@ void TransformToFastProperties(Handle<JSObject> object, ...@@ -203,7 +203,7 @@ void TransformToFastProperties(Handle<JSObject> object,
void FlattenString(Handle<String> string) { void FlattenString(Handle<String> string) {
CALL_HEAP_FUNCTION_VOID(string->TryFlattenIfNotFlat()); CALL_HEAP_FUNCTION_VOID(string->TryFlatten());
ASSERT(string->IsFlat()); ASSERT(string->IsFlat());
} }
...@@ -362,8 +362,11 @@ Handle<Object> LookupSingleCharacterStringFromCode(uint32_t index) { ...@@ -362,8 +362,11 @@ Handle<Object> LookupSingleCharacterStringFromCode(uint32_t index) {
} }
Handle<String> SubString(Handle<String> str, int start, int end) { Handle<String> SubString(Handle<String> str,
CALL_HEAP_FUNCTION(str->SubString(start, end), String); int start,
int end,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(str->SubString(start, end, pretenure), String);
} }
......
...@@ -287,7 +287,10 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object, ...@@ -287,7 +287,10 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first, Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
Handle<FixedArray> second); Handle<FixedArray> second);
Handle<String> SubString(Handle<String> str, int start, int end); Handle<String> SubString(Handle<String> str,
int start,
int end,
PretenureFlag pretenure = NOT_TENURED);
// Sets the expected number of properties for the function's instances. // Sets the expected number of properties for the function's instances.
......
...@@ -2012,7 +2012,8 @@ Object* Heap::AllocateConsString(String* first, String* second) { ...@@ -2012,7 +2012,8 @@ Object* Heap::AllocateConsString(String* first, String* second) {
Object* Heap::AllocateSubString(String* buffer, Object* Heap::AllocateSubString(String* buffer,
int start, int start,
int end) { int end,
PretenureFlag pretenure) {
int length = end - start; int length = end - start;
if (length == 1) { if (length == 1) {
...@@ -2028,16 +2029,13 @@ Object* Heap::AllocateSubString(String* buffer, ...@@ -2028,16 +2029,13 @@ Object* Heap::AllocateSubString(String* buffer,
} }
// Make an attempt to flatten the buffer to reduce access time. // Make an attempt to flatten the buffer to reduce access time.
if (!buffer->IsFlat()) { buffer->TryFlatten();
buffer->TryFlatten();
}
Object* result = buffer->IsAsciiRepresentation() Object* result = buffer->IsAsciiRepresentation()
? AllocateRawAsciiString(length) ? AllocateRawAsciiString(length, pretenure )
: AllocateRawTwoByteString(length); : AllocateRawTwoByteString(length, pretenure);
if (result->IsFailure()) return result; if (result->IsFailure()) return result;
String* string_result = String::cast(result); String* string_result = String::cast(result);
// Copy the characters into the new object. // Copy the characters into the new object.
if (buffer->IsAsciiRepresentation()) { if (buffer->IsAsciiRepresentation()) {
ASSERT(string_result->IsAsciiRepresentation()); ASSERT(string_result->IsAsciiRepresentation());
......
...@@ -556,7 +556,8 @@ class Heap : public AllStatic { ...@@ -556,7 +556,8 @@ class Heap : public AllStatic {
// Please note this does not perform a garbage collection. // Please note this does not perform a garbage collection.
static Object* AllocateSubString(String* buffer, static Object* AllocateSubString(String* buffer,
int start, int start,
int end); int end,
PretenureFlag pretenure = NOT_TENURED);
// Allocate a new external string object, which is backed by a string // Allocate a new external string object, which is backed by a string
// resource that resides outside the V8 heap. // resource that resides outside the V8 heap.
......
...@@ -1640,13 +1640,11 @@ bool String::Equals(String* other) { ...@@ -1640,13 +1640,11 @@ bool String::Equals(String* other) {
} }
Object* String::TryFlattenIfNotFlat() { Object* String::TryFlatten(PretenureFlag pretenure) {
// We don't need to flatten strings that are already flat. Since this code // We don't need to flatten strings that are already flat. Since this code
// is inlined, it can be helpful in the flat case to not call out to Flatten. // is inlined, it can be helpful in the flat case to not call out to Flatten.
if (!IsFlat()) { if (IsFlat()) return this;
return TryFlatten(); return SlowTryFlatten(pretenure);
}
return this;
} }
......
...@@ -673,7 +673,7 @@ static bool AnWord(String* str) { ...@@ -673,7 +673,7 @@ static bool AnWord(String* str) {
} }
Object* String::TryFlatten() { Object* String::SlowTryFlatten(PretenureFlag pretenure) {
#ifdef DEBUG #ifdef DEBUG
// Do not attempt to flatten in debug mode when allocation is not // Do not attempt to flatten in debug mode when allocation is not
// allowed. This is to avoid an assertion failure when allocating. // allowed. This is to avoid an assertion failure when allocating.
...@@ -691,7 +691,7 @@ Object* String::TryFlatten() { ...@@ -691,7 +691,7 @@ Object* String::TryFlatten() {
// There's little point in putting the flat string in new space if the // There's little point in putting the flat string in new space if the
// cons string is in old space. It can never get GCed until there is // cons string is in old space. It can never get GCed until there is
// an old space GC. // an old space GC.
PretenureFlag tenure = Heap::InNewSpace(this) ? NOT_TENURED : TENURED; PretenureFlag tenure = Heap::InNewSpace(this) ? pretenure : TENURED;
int len = length(); int len = length();
Object* object; Object* object;
String* result; String* result;
...@@ -2768,7 +2768,7 @@ Object* JSObject::DefineGetterSetter(String* name, ...@@ -2768,7 +2768,7 @@ Object* JSObject::DefineGetterSetter(String* name,
} }
// Try to flatten before operating on the string. // Try to flatten before operating on the string.
name->TryFlattenIfNotFlat(); name->TryFlatten();
// Check if there is an API defined callback object which prohibits // Check if there is an API defined callback object which prohibits
// callback overwriting in this object or it's prototype chain. // callback overwriting in this object or it's prototype chain.
...@@ -3546,7 +3546,7 @@ int String::Utf8Length() { ...@@ -3546,7 +3546,7 @@ int String::Utf8Length() {
// doesn't make Utf8Length faster, but it is very likely that // doesn't make Utf8Length faster, but it is very likely that
// the string will be accessed later (for example by WriteUtf8) // the string will be accessed later (for example by WriteUtf8)
// so it's still a good idea. // so it's still a good idea.
TryFlattenIfNotFlat(); TryFlatten();
Access<StringInputBuffer> buffer(&string_input_buffer); Access<StringInputBuffer> buffer(&string_input_buffer);
buffer->Reset(0, this); buffer->Reset(0, this);
int result = 0; int result = 0;
...@@ -4637,9 +4637,9 @@ uint32_t String::ComputeHashField(unibrow::CharacterStream* buffer, ...@@ -4637,9 +4637,9 @@ uint32_t String::ComputeHashField(unibrow::CharacterStream* buffer,
} }
Object* String::SubString(int start, int end) { Object* String::SubString(int start, int end, PretenureFlag pretenure) {
if (start == 0 && end == length()) return this; if (start == 0 && end == length()) return this;
Object* result = Heap::AllocateSubString(this, start, end); Object* result = Heap::AllocateSubString(this, start, end, pretenure);
return result; return result;
} }
......
...@@ -3837,13 +3837,13 @@ class String: public HeapObject { ...@@ -3837,13 +3837,13 @@ class String: public HeapObject {
// Try to flatten the top level ConsString that is hiding behind this // Try to flatten the top level ConsString that is hiding behind this
// string. This is a no-op unless the string is a ConsString. Flatten // string. This is a no-op unless the string is a ConsString. Flatten
// mutates the ConsString and might return a failure. // mutates the ConsString and might return a failure.
Object* TryFlatten(); Object* SlowTryFlatten(PretenureFlag pretenure);
// Try to flatten the string. Checks first inline to see if it is necessary. // Try to flatten the string. Checks first inline to see if it is necessary.
// Do not handle allocation failures. After calling TryFlattenIfNotFlat, the // Do not handle allocation failures. After calling TryFlatten, the
// string could still be a ConsString, in which case a failure is returned. // string could still be a ConsString, in which case a failure is returned.
// Use FlattenString from Handles.cc to be sure to flatten. // Use FlattenString from Handles.cc to be sure to flatten.
inline Object* TryFlattenIfNotFlat(); inline Object* TryFlatten(PretenureFlag pretenure = NOT_TENURED);
Vector<const char> ToAsciiVector(); Vector<const char> ToAsciiVector();
Vector<const uc16> ToUC16Vector(); Vector<const uc16> ToUC16Vector();
...@@ -3853,7 +3853,7 @@ class String: public HeapObject { ...@@ -3853,7 +3853,7 @@ class String: public HeapObject {
bool MarkAsUndetectable(); bool MarkAsUndetectable();
// Return a substring. // Return a substring.
Object* SubString(int from, int to); Object* SubString(int from, int to, PretenureFlag pretenure = NOT_TENURED);
// String equality operations. // String equality operations.
inline bool Equals(String* other); inline bool Equals(String* other);
......
...@@ -1234,7 +1234,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source, ...@@ -1234,7 +1234,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
Counters::total_parse_size.Increment(source->length()); Counters::total_parse_size.Increment(source->length());
// Initialize parser state. // Initialize parser state.
source->TryFlattenIfNotFlat(); source->TryFlatten();
scanner_.Init(source, stream, 0, JAVASCRIPT); scanner_.Init(source, stream, 0, JAVASCRIPT);
ASSERT(target_stack_ == NULL); ASSERT(target_stack_ == NULL);
...@@ -1289,7 +1289,7 @@ FunctionLiteral* Parser::ParseLazy(Handle<String> source, ...@@ -1289,7 +1289,7 @@ FunctionLiteral* Parser::ParseLazy(Handle<String> source,
bool is_expression) { bool is_expression) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT); CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
HistogramTimerScope timer(&Counters::parse_lazy); HistogramTimerScope timer(&Counters::parse_lazy);
source->TryFlattenIfNotFlat(); source->TryFlatten();
Counters::total_parse_size.Increment(source->length()); Counters::total_parse_size.Increment(source->length());
SafeStringInputBuffer buffer(source.location()); SafeStringInputBuffer buffer(source.location());
...@@ -1338,7 +1338,7 @@ FunctionLiteral* Parser::ParseJson(Handle<String> source, ...@@ -1338,7 +1338,7 @@ FunctionLiteral* Parser::ParseJson(Handle<String> source,
Counters::total_parse_size.Increment(source->length()); Counters::total_parse_size.Increment(source->length());
// Initialize parser state. // Initialize parser state.
source->TryFlattenIfNotFlat(); source->TryFlatten(TENURED);
scanner_.Init(source, stream, 0, JSON); scanner_.Init(source, stream, 0, JSON);
ASSERT(target_stack_ == NULL); ASSERT(target_stack_ == NULL);
...@@ -5088,11 +5088,10 @@ FunctionLiteral* MakeLazyAST(Handle<Script> script, ...@@ -5088,11 +5088,10 @@ FunctionLiteral* MakeLazyAST(Handle<Script> script,
always_allow_natives_syntax = allow_natives_syntax_before; always_allow_natives_syntax = allow_natives_syntax_before;
// Parse the function by pulling the function source from the script source. // Parse the function by pulling the function source from the script source.
Handle<String> script_source(String::cast(script->source())); Handle<String> script_source(String::cast(script->source()));
Handle<String> function_source =
SubString(script_source, start_position, end_position, TENURED);
FunctionLiteral* result = FunctionLiteral* result =
parser.ParseLazy(SubString(script_source, start_position, end_position), parser.ParseLazy(function_source, name, start_position, is_expression);
name,
start_position,
is_expression);
return result; return result;
} }
......
...@@ -2608,8 +2608,8 @@ static Object* Runtime_StringLocaleCompare(Arguments args) { ...@@ -2608,8 +2608,8 @@ static Object* Runtime_StringLocaleCompare(Arguments args) {
int d = str1->Get(0) - str2->Get(0); int d = str1->Get(0) - str2->Get(0);
if (d != 0) return Smi::FromInt(d); if (d != 0) return Smi::FromInt(d);
str1->TryFlattenIfNotFlat(); str1->TryFlatten();
str2->TryFlattenIfNotFlat(); str2->TryFlatten();
static StringInputBuffer buf1; static StringInputBuffer buf1;
static StringInputBuffer buf2; static StringInputBuffer buf2;
...@@ -2818,7 +2818,7 @@ static Object* Runtime_NumberToPrecision(Arguments args) { ...@@ -2818,7 +2818,7 @@ static Object* Runtime_NumberToPrecision(Arguments args) {
// string->Get(index). // string->Get(index).
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) { static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
if (index < static_cast<uint32_t>(string->length())) { if (index < static_cast<uint32_t>(string->length())) {
string->TryFlattenIfNotFlat(); string->TryFlatten();
return LookupSingleCharacterStringFromCode( return LookupSingleCharacterStringFromCode(
string->Get(index)); string->Get(index));
} }
...@@ -3072,7 +3072,7 @@ Object* Runtime::SetObjectProperty(Handle<Object> object, ...@@ -3072,7 +3072,7 @@ Object* Runtime::SetObjectProperty(Handle<Object> object,
result = SetElement(js_object, index, value); result = SetElement(js_object, index, value);
} else { } else {
Handle<String> key_string = Handle<String>::cast(key); Handle<String> key_string = Handle<String>::cast(key);
key_string->TryFlattenIfNotFlat(); key_string->TryFlatten();
result = SetProperty(js_object, key_string, value, attr); result = SetProperty(js_object, key_string, value, attr);
} }
if (result.is_null()) return Failure::Exception(); if (result.is_null()) return Failure::Exception();
...@@ -3121,7 +3121,7 @@ Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object, ...@@ -3121,7 +3121,7 @@ Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object,
return js_object->SetElement(index, *value); return js_object->SetElement(index, *value);
} else { } else {
Handle<String> key_string = Handle<String>::cast(key); Handle<String> key_string = Handle<String>::cast(key);
key_string->TryFlattenIfNotFlat(); key_string->TryFlatten();
return js_object->IgnoreAttributesAndSetLocalProperty(*key_string, return js_object->IgnoreAttributesAndSetLocalProperty(*key_string,
*value, *value,
attr); attr);
...@@ -3173,7 +3173,7 @@ Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object, ...@@ -3173,7 +3173,7 @@ Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object,
key_string = Handle<String>::cast(converted); key_string = Handle<String>::cast(converted);
} }
key_string->TryFlattenIfNotFlat(); key_string->TryFlatten();
return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION); return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION);
} }
...@@ -3669,7 +3669,7 @@ static Object* Runtime_StringToNumber(Arguments args) { ...@@ -3669,7 +3669,7 @@ static Object* Runtime_StringToNumber(Arguments args) {
NoHandleAllocation ha; NoHandleAllocation ha;
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_CHECKED(String, subject, args[0]); CONVERT_CHECKED(String, subject, args[0]);
subject->TryFlattenIfNotFlat(); subject->TryFlatten();
return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX)); return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX));
} }
...@@ -3751,7 +3751,7 @@ static Object* Runtime_URIEscape(Arguments args) { ...@@ -3751,7 +3751,7 @@ static Object* Runtime_URIEscape(Arguments args) {
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]); CONVERT_CHECKED(String, source, args[0]);
source->TryFlattenIfNotFlat(); source->TryFlatten();
int escaped_length = 0; int escaped_length = 0;
int length = source->length(); int length = source->length();
...@@ -3864,7 +3864,7 @@ static Object* Runtime_URIUnescape(Arguments args) { ...@@ -3864,7 +3864,7 @@ static Object* Runtime_URIUnescape(Arguments args) {
ASSERT(args.length() == 1); ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]); CONVERT_CHECKED(String, source, args[0]);
source->TryFlattenIfNotFlat(); source->TryFlatten();
bool ascii = true; bool ascii = true;
int length = source->length(); int length = source->length();
...@@ -3904,7 +3904,7 @@ static Object* Runtime_StringParseInt(Arguments args) { ...@@ -3904,7 +3904,7 @@ static Object* Runtime_StringParseInt(Arguments args) {
CONVERT_CHECKED(String, s, args[0]); CONVERT_CHECKED(String, s, args[0]);
CONVERT_SMI_CHECKED(radix, args[1]); CONVERT_SMI_CHECKED(radix, args[1]);
s->TryFlattenIfNotFlat(); s->TryFlatten();
int len = s->length(); int len = s->length();
int i; int i;
...@@ -4074,7 +4074,7 @@ static Object* ConvertCase(Arguments args, ...@@ -4074,7 +4074,7 @@ static Object* ConvertCase(Arguments args,
NoHandleAllocation ha; NoHandleAllocation ha;
CONVERT_CHECKED(String, s, args[0]); CONVERT_CHECKED(String, s, args[0]);
s->TryFlattenIfNotFlat(); s->TryFlatten();
int input_string_length = s->length(); int input_string_length = s->length();
// Assume that the string is not empty; we need this assumption later // Assume that the string is not empty; we need this assumption later
...@@ -4111,7 +4111,7 @@ static Object* Runtime_StringTrim(Arguments args) { ...@@ -4111,7 +4111,7 @@ static Object* Runtime_StringTrim(Arguments args) {
CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]); CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]);
CONVERT_BOOLEAN_CHECKED(trimRight, args[2]); CONVERT_BOOLEAN_CHECKED(trimRight, args[2]);
s->TryFlattenIfNotFlat(); s->TryFlatten();
int length = s->length(); int length = s->length();
int left = 0; int left = 0;
...@@ -4679,8 +4679,8 @@ static Object* Runtime_StringCompare(Arguments args) { ...@@ -4679,8 +4679,8 @@ static Object* Runtime_StringCompare(Arguments args) {
if (d < 0) return Smi::FromInt(LESS); if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER); else if (d > 0) return Smi::FromInt(GREATER);
x->TryFlattenIfNotFlat(); x->TryFlatten();
y->TryFlattenIfNotFlat(); y->TryFlatten();
return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y) return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
: StringInputBufferCompare(x, y); : StringInputBufferCompare(x, y);
......
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