diff --git a/src/heap.cc b/src/heap.cc index f8d22a2e36..aa7a5c7139 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -277,7 +277,9 @@ void Heap::GarbageCollectionPrologue() { int Heap::SizeOfObjects() { int total = 0; AllSpaces spaces; - while (Space* space = spaces.next()) total += space->Size(); + while (Space* space = spaces.next()) { + total += space->Size(); + } return total; } diff --git a/src/math.js b/src/math.js index db75cb28ae..91bf206a8b 100644 --- a/src/math.js +++ b/src/math.js @@ -184,6 +184,7 @@ function MathTan(x) { function SetupMath() { // Setup math constants. // ECMA-262, section 15.8.1.1. + %OptimizeObjectForAddingMultipleProperties($Math, 26); %SetProperty($Math, "E", 2.7182818284590452354, diff --git a/src/runtime.cc b/src/runtime.cc index 0da4be8216..5518d15529 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1022,6 +1022,30 @@ static Object* Runtime_InitializeConstContextSlot(Arguments args) { } +static Object* Runtime_OptimizeObjectForAddingMultipleProperties( + Arguments args) { + HandleScope scope; + ASSERT(args.length() == 2); + CONVERT_ARG_CHECKED(JSObject, object, 0); + CONVERT_SMI_CHECKED(properties, args[1]); + if (object->HasFastProperties()) { + NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, properties); + } + return *object; +} + + +static Object* Runtime_TransformToFastProperties(Arguments args) { + HandleScope scope; + ASSERT(args.length() == 1); + CONVERT_ARG_CHECKED(JSObject, object, 0); + if (!object->HasFastProperties() && !object->IsGlobalObject()) { + TransformToFastProperties(object, 0); + } + return *object; +} + + static Object* Runtime_RegExpExec(Arguments args) { HandleScope scope; ASSERT(args.length() == 4); diff --git a/src/runtime.h b/src/runtime.h index cdf21dcabf..d47ca18e79 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -247,6 +247,8 @@ namespace internal { F(InitializeVarGlobal, -1 /* 1 or 2 */) \ F(InitializeConstGlobal, 2) \ F(InitializeConstContextSlot, 3) \ + F(OptimizeObjectForAddingMultipleProperties, 2) \ + F(TransformToFastProperties, 1) \ \ /* Debugging */ \ F(DebugPrint, 1) \ diff --git a/src/spaces.h b/src/spaces.h index 4760a42402..15f0628476 100644 --- a/src/spaces.h +++ b/src/spaces.h @@ -1574,7 +1574,7 @@ class FixedSpace : public PagedSpace { // Give a fixed sized block of memory to the space's free list. void Free(Address start) { free_list_.Free(start); - accounting_stats_.DeallocateBytes(Map::kSize); + accounting_stats_.DeallocateBytes(object_size_in_bytes_); } // Prepares for a mark-compact GC. diff --git a/src/v8natives.js b/src/v8natives.js index 841c920852..605df4920d 100644 --- a/src/v8natives.js +++ b/src/v8natives.js @@ -46,12 +46,16 @@ const $isFinite = GlobalIsFinite; // Helper function used to install functions on objects. function InstallFunctions(object, attributes, functions) { + if (functions.length >= 8) { + %OptimizeObjectForAddingMultipleProperties(object, functions.length >> 1); + } for (var i = 0; i < functions.length; i += 2) { var key = functions[i]; var f = functions[i + 1]; %FunctionSetName(f, key); %SetProperty(object, key, f, attributes); } + %TransformToFastProperties(object); } // Emulates JSC by installing functions on a hidden prototype that @@ -454,8 +458,10 @@ function NumberToJSON(key) { function SetupNumber() { // Setup the constructor property on the Number prototype object. + %OptimizeObjectForAddingMultipleProperties($Number.prototype, 8); %SetProperty($Number.prototype, "constructor", $Number, DONT_ENUM); + %OptimizeObjectForAddingMultipleProperties($Number, 5); // ECMA-262 section 15.7.3.1. %SetProperty($Number, "MAX_VALUE",