Revision: 3976
Author: [email protected]
Date: Fri Feb 26 06:37:33 2010
Log: - Pushed source code for functions into old space.
- Renamed TryFlattenIfNotFlat to TryFlatten.

Review URL: http://codereview.chromium.org/661181
http://code.google.com/p/v8/source/detail?r=3976

Modified:
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/handles.cc
 /branches/bleeding_edge/src/handles.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/heap.h
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/runtime.cc

=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Feb 26 03:51:33 2010
+++ /branches/bleeding_edge/src/api.cc  Fri Feb 26 06:37:33 2010
@@ -2615,7 +2615,7 @@
   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;
=======================================
--- /branches/bleeding_edge/src/handles.cc      Tue Feb 16 07:29:35 2010
+++ /branches/bleeding_edge/src/handles.cc      Fri Feb 26 06:37:33 2010
@@ -203,7 +203,7 @@


 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<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);
 }


=======================================
--- /branches/bleeding_edge/src/handles.h       Wed Feb 10 06:44:15 2010
+++ /branches/bleeding_edge/src/handles.h       Fri Feb 26 06:37:33 2010
@@ -287,7 +287,10 @@
 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.
=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Feb 26 04:00:10 2010
+++ /branches/bleeding_edge/src/heap.cc Fri Feb 26 06:37:33 2010
@@ -2012,7 +2012,8 @@

 Object* Heap::AllocateSubString(String* buffer,
                                 int start,
-                                int end) {
+                                int end,
+                                PretenureFlag pretenure) {
   int length = end - start;

   if (length == 1) {
@@ -2028,16 +2029,13 @@
   }

   // 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());
=======================================
--- /branches/bleeding_edge/src/heap.h  Fri Feb 26 03:51:33 2010
+++ /branches/bleeding_edge/src/heap.h  Fri Feb 26 06:37:33 2010
@@ -556,7 +556,8 @@
   // 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.
=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Thu Feb 25 07:43:27 2010
+++ /branches/bleeding_edge/src/objects-inl.h   Fri Feb 26 06:37:33 2010
@@ -1640,13 +1640,11 @@
 }


-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);
 }


=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Feb 25 07:43:27 2010
+++ /branches/bleeding_edge/src/objects.cc      Fri Feb 26 06:37:33 2010
@@ -673,7 +673,7 @@
 }


-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 @@
// 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 @@
   }

   // 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 @@
   // 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 @@
 }


-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;
 }

=======================================
--- /branches/bleeding_edge/src/objects.h       Thu Feb 25 07:43:27 2010
+++ /branches/bleeding_edge/src/objects.h       Fri Feb 26 06:37:33 2010
@@ -3837,13 +3837,13 @@
   // 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 @@
   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);
=======================================
--- /branches/bleeding_edge/src/parser.cc       Tue Feb 16 07:14:34 2010
+++ /branches/bleeding_edge/src/parser.cc       Fri Feb 26 06:37:33 2010
@@ -1234,7 +1234,7 @@
   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 @@
                                    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 @@
   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 @@
   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;
 }

=======================================
--- /branches/bleeding_edge/src/runtime.cc      Fri Feb 26 02:24:58 2010
+++ /branches/bleeding_edge/src/runtime.cc      Fri Feb 26 06:37:33 2010
@@ -2608,8 +2608,8 @@
   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 @@
 // 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 @@
       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 @@
       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 @@
     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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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 @@
   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);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to