Avoid map transitions and multiple backing arrays for builtin prototypes

while adding functions and other properties.  This gives around 2% on
context-create, more if we don't GC on every new context.  Also fix
accounting bug in cell space.
Review URL: http://codereview.chromium.org/165449

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2681 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
whesse@chromium.org 2009-08-13 12:35:59 +00:00
parent 5a3998c1f4
commit d0d03d9980
6 changed files with 37 additions and 2 deletions

View File

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

View File

@ -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,

View File

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

View File

@ -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) \

View File

@ -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.

View File

@ -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",