- 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
This commit is contained in:
bak@chromium.org 2010-02-26 14:37:33 +00:00
parent 1d330492af
commit 4766a592ce
10 changed files with 51 additions and 49 deletions

View File

@ -2615,7 +2615,7 @@ int String::WriteAscii(char* buffer, int start, int length) const {
StringTracker::RecordWrite(str);
// Flatten the string for efficiency. This applies whether we are
// using StringInputBuffer or Get(i) to access the characters.
str->TryFlattenIfNotFlat();
str->TryFlatten();
int end = length;
if ( (length == -1) || (length > str->length() - start) )
end = str->length() - start;

View File

@ -203,7 +203,7 @@ void TransformToFastProperties(Handle<JSObject> object,
void FlattenString(Handle<String> string) {
CALL_HEAP_FUNCTION_VOID(string->TryFlattenIfNotFlat());
CALL_HEAP_FUNCTION_VOID(string->TryFlatten());
ASSERT(string->IsFlat());
}
@ -362,8 +362,11 @@ Handle<Object> LookupSingleCharacterStringFromCode(uint32_t index) {
}
Handle<String> SubString(Handle<String> str, int start, int end) {
CALL_HEAP_FUNCTION(str->SubString(start, end), String);
Handle<String> SubString(Handle<String> str,
int start,
int end,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(str->SubString(start, end, pretenure), String);
}

View File

@ -287,7 +287,10 @@ Handle<FixedArray> GetEnumPropertyKeys(Handle<JSObject> object,
Handle<FixedArray> UnionOfKeys(Handle<FixedArray> first,
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.

View File

@ -2012,7 +2012,8 @@ Object* Heap::AllocateConsString(String* first, String* second) {
Object* Heap::AllocateSubString(String* buffer,
int start,
int end) {
int end,
PretenureFlag pretenure) {
int length = end - start;
if (length == 1) {
@ -2028,16 +2029,13 @@ Object* Heap::AllocateSubString(String* buffer,
}
// Make an attempt to flatten the buffer to reduce access time.
if (!buffer->IsFlat()) {
buffer->TryFlatten();
}
buffer->TryFlatten();
Object* result = buffer->IsAsciiRepresentation()
? AllocateRawAsciiString(length)
: AllocateRawTwoByteString(length);
? AllocateRawAsciiString(length, pretenure )
: AllocateRawTwoByteString(length, pretenure);
if (result->IsFailure()) return result;
String* string_result = String::cast(result);
// Copy the characters into the new object.
if (buffer->IsAsciiRepresentation()) {
ASSERT(string_result->IsAsciiRepresentation());

View File

@ -556,7 +556,8 @@ class Heap : public AllStatic {
// Please note this does not perform a garbage collection.
static Object* AllocateSubString(String* buffer,
int start,
int end);
int end,
PretenureFlag pretenure = NOT_TENURED);
// Allocate a new external string object, which is backed by a string
// resource that resides outside the V8 heap.

View File

@ -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
// is inlined, it can be helpful in the flat case to not call out to Flatten.
if (!IsFlat()) {
return TryFlatten();
}
return this;
if (IsFlat()) return this;
return SlowTryFlatten(pretenure);
}

View File

@ -673,7 +673,7 @@ static bool AnWord(String* str) {
}
Object* String::TryFlatten() {
Object* String::SlowTryFlatten(PretenureFlag pretenure) {
#ifdef DEBUG
// Do not attempt to flatten in debug mode when allocation is not
// allowed. This is to avoid an assertion failure when allocating.
@ -691,7 +691,7 @@ Object* String::TryFlatten() {
// 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
// an old space GC.
PretenureFlag tenure = Heap::InNewSpace(this) ? NOT_TENURED : TENURED;
PretenureFlag tenure = Heap::InNewSpace(this) ? pretenure : TENURED;
int len = length();
Object* object;
String* result;
@ -2768,7 +2768,7 @@ Object* JSObject::DefineGetterSetter(String* name,
}
// Try to flatten before operating on the string.
name->TryFlattenIfNotFlat();
name->TryFlatten();
// Check if there is an API defined callback object which prohibits
// callback overwriting in this object or it's prototype chain.
@ -3546,7 +3546,7 @@ int String::Utf8Length() {
// doesn't make Utf8Length faster, but it is very likely that
// the string will be accessed later (for example by WriteUtf8)
// so it's still a good idea.
TryFlattenIfNotFlat();
TryFlatten();
Access<StringInputBuffer> buffer(&string_input_buffer);
buffer->Reset(0, this);
int result = 0;
@ -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;
Object* result = Heap::AllocateSubString(this, start, end);
Object* result = Heap::AllocateSubString(this, start, end, pretenure);
return result;
}

View File

@ -3837,13 +3837,13 @@ class String: public HeapObject {
// 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
// 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.
// 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.
// 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 uc16> ToUC16Vector();
@ -3853,7 +3853,7 @@ class String: public HeapObject {
bool MarkAsUndetectable();
// Return a substring.
Object* SubString(int from, int to);
Object* SubString(int from, int to, PretenureFlag pretenure = NOT_TENURED);
// String equality operations.
inline bool Equals(String* other);

View File

@ -1234,7 +1234,7 @@ FunctionLiteral* Parser::ParseProgram(Handle<String> source,
Counters::total_parse_size.Increment(source->length());
// Initialize parser state.
source->TryFlattenIfNotFlat();
source->TryFlatten();
scanner_.Init(source, stream, 0, JAVASCRIPT);
ASSERT(target_stack_ == NULL);
@ -1289,7 +1289,7 @@ FunctionLiteral* Parser::ParseLazy(Handle<String> source,
bool is_expression) {
CompilationZoneScope zone_scope(DONT_DELETE_ON_EXIT);
HistogramTimerScope timer(&Counters::parse_lazy);
source->TryFlattenIfNotFlat();
source->TryFlatten();
Counters::total_parse_size.Increment(source->length());
SafeStringInputBuffer buffer(source.location());
@ -1338,7 +1338,7 @@ FunctionLiteral* Parser::ParseJson(Handle<String> source,
Counters::total_parse_size.Increment(source->length());
// Initialize parser state.
source->TryFlattenIfNotFlat();
source->TryFlatten(TENURED);
scanner_.Init(source, stream, 0, JSON);
ASSERT(target_stack_ == NULL);
@ -5088,11 +5088,10 @@ FunctionLiteral* MakeLazyAST(Handle<Script> script,
always_allow_natives_syntax = allow_natives_syntax_before;
// Parse the function by pulling the function source from the script source.
Handle<String> script_source(String::cast(script->source()));
Handle<String> function_source =
SubString(script_source, start_position, end_position, TENURED);
FunctionLiteral* result =
parser.ParseLazy(SubString(script_source, start_position, end_position),
name,
start_position,
is_expression);
parser.ParseLazy(function_source, name, start_position, is_expression);
return result;
}

View File

@ -2608,8 +2608,8 @@ static Object* Runtime_StringLocaleCompare(Arguments args) {
int d = str1->Get(0) - str2->Get(0);
if (d != 0) return Smi::FromInt(d);
str1->TryFlattenIfNotFlat();
str2->TryFlattenIfNotFlat();
str1->TryFlatten();
str2->TryFlatten();
static StringInputBuffer buf1;
static StringInputBuffer buf2;
@ -2818,7 +2818,7 @@ static Object* Runtime_NumberToPrecision(Arguments args) {
// string->Get(index).
static Handle<Object> GetCharAt(Handle<String> string, uint32_t index) {
if (index < static_cast<uint32_t>(string->length())) {
string->TryFlattenIfNotFlat();
string->TryFlatten();
return LookupSingleCharacterStringFromCode(
string->Get(index));
}
@ -3072,7 +3072,7 @@ Object* Runtime::SetObjectProperty(Handle<Object> object,
result = SetElement(js_object, index, value);
} else {
Handle<String> key_string = Handle<String>::cast(key);
key_string->TryFlattenIfNotFlat();
key_string->TryFlatten();
result = SetProperty(js_object, key_string, value, attr);
}
if (result.is_null()) return Failure::Exception();
@ -3121,7 +3121,7 @@ Object* Runtime::ForceSetObjectProperty(Handle<JSObject> js_object,
return js_object->SetElement(index, *value);
} else {
Handle<String> key_string = Handle<String>::cast(key);
key_string->TryFlattenIfNotFlat();
key_string->TryFlatten();
return js_object->IgnoreAttributesAndSetLocalProperty(*key_string,
*value,
attr);
@ -3173,7 +3173,7 @@ Object* Runtime::ForceDeleteObjectProperty(Handle<JSObject> js_object,
key_string = Handle<String>::cast(converted);
}
key_string->TryFlattenIfNotFlat();
key_string->TryFlatten();
return js_object->DeleteProperty(*key_string, JSObject::FORCE_DELETION);
}
@ -3669,7 +3669,7 @@ static Object* Runtime_StringToNumber(Arguments args) {
NoHandleAllocation ha;
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, subject, args[0]);
subject->TryFlattenIfNotFlat();
subject->TryFlatten();
return Heap::NumberFromDouble(StringToDouble(subject, ALLOW_HEX));
}
@ -3751,7 +3751,7 @@ static Object* Runtime_URIEscape(Arguments args) {
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
source->TryFlattenIfNotFlat();
source->TryFlatten();
int escaped_length = 0;
int length = source->length();
@ -3864,7 +3864,7 @@ static Object* Runtime_URIUnescape(Arguments args) {
ASSERT(args.length() == 1);
CONVERT_CHECKED(String, source, args[0]);
source->TryFlattenIfNotFlat();
source->TryFlatten();
bool ascii = true;
int length = source->length();
@ -3904,7 +3904,7 @@ static Object* Runtime_StringParseInt(Arguments args) {
CONVERT_CHECKED(String, s, args[0]);
CONVERT_SMI_CHECKED(radix, args[1]);
s->TryFlattenIfNotFlat();
s->TryFlatten();
int len = s->length();
int i;
@ -4074,7 +4074,7 @@ static Object* ConvertCase(Arguments args,
NoHandleAllocation ha;
CONVERT_CHECKED(String, s, args[0]);
s->TryFlattenIfNotFlat();
s->TryFlatten();
int input_string_length = s->length();
// Assume that the string is not empty; we need this assumption later
@ -4111,7 +4111,7 @@ static Object* Runtime_StringTrim(Arguments args) {
CONVERT_BOOLEAN_CHECKED(trimLeft, args[1]);
CONVERT_BOOLEAN_CHECKED(trimRight, args[2]);
s->TryFlattenIfNotFlat();
s->TryFlatten();
int length = s->length();
int left = 0;
@ -4679,8 +4679,8 @@ static Object* Runtime_StringCompare(Arguments args) {
if (d < 0) return Smi::FromInt(LESS);
else if (d > 0) return Smi::FromInt(GREATER);
x->TryFlattenIfNotFlat();
y->TryFlattenIfNotFlat();
x->TryFlatten();
y->TryFlatten();
return (x->IsFlat() && y->IsFlat()) ? FlatStringCompare(x, y)
: StringInputBufferCompare(x, y);