Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 1326 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); | 1337 Handle<Code> ic(Builtins::builtin(Builtins::KeyedStoreIC_Miss)); |
| 1338 __ Jump(ic, RelocInfo::CODE_TARGET); | 1338 __ Jump(ic, RelocInfo::CODE_TARGET); |
| 1339 | 1339 |
| 1340 // Return the generated code. | 1340 // Return the generated code. |
| 1341 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); | 1341 return GetCode(transition == NULL ? FIELD : MAP_TRANSITION, name); |
| 1342 } | 1342 } |
| 1343 | 1343 |
| 1344 | 1344 |
| 1345 Object* ConstructStubCompiler::CompileConstructStub( | 1345 Object* ConstructStubCompiler::CompileConstructStub( |
| 1346 SharedFunctionInfo* shared) { | 1346 SharedFunctionInfo* shared) { |
| 1347 // Not implemented yet - just jump to generic stub. | 1347 // ----------- S t a t e ------------- |
| 1348 // -- r0 : argc | |
| 1349 // -- r1 : constructor | |
| 1350 // -- lr : return address | |
| 1351 // -- [sp] : last argument | |
| 1352 // ----------------------------------- | |
| 1353 Label generic_stub_call; | |
| 1354 | |
| 1355 // Use r7 for holding undefined which is used in several places below. | |
| 1356 __ LoadRoot(r7, Heap::kUndefinedValueRootIndex); | |
| 1357 | |
| 1358 #ifdef ENABLE_DEBUGGER_SUPPORT | |
| 1359 // Check to see whether there are any break points in the function code. If | |
| 1360 // there are jump to the generic constructor stub which calls the actual | |
| 1361 // code for the function thereby hitting the break points. | |
| 1362 __ ldr(r2, FieldMemOperand(r1, JSFunction::kSharedFunctionInfoOffset)); | |
| 1363 __ ldr(r2, FieldMemOperand(r2, SharedFunctionInfo::kDebugInfoOffset)); | |
| 1364 __ cmp(r2, r7); | |
|
Erik Corry
2009/09/07 10:21:45
I'd like to see a performance bot run with and wit
Søren Thygesen Gjesse
2009/09/07 10:26:43
I will do that.
| |
| 1365 __ b(ne, &generic_stub_call); | |
| 1366 #endif | |
| 1367 | |
| 1368 // Load the initial map and verify that it is in fact a map. | |
| 1369 // r1: constructor function | |
| 1370 // r7: undefined | |
| 1371 __ ldr(r2, FieldMemOperand(r1, JSFunction::kPrototypeOrInitialMapOffset)); | |
| 1372 __ tst(r2, Operand(kSmiTagMask)); | |
| 1373 __ b(eq, &generic_stub_call); | |
| 1374 __ CompareObjectType(r2, r3, r4, MAP_TYPE); | |
| 1375 __ b(ne, &generic_stub_call); | |
| 1376 | |
| 1377 #ifdef DEBUG | |
| 1378 // Cannot construct functions this way. | |
| 1379 // r0: argc | |
| 1380 // r1: constructor function | |
| 1381 // r2: initial map | |
| 1382 // r7: undefined | |
| 1383 __ CompareInstanceType(r2, r3, JS_FUNCTION_TYPE); | |
| 1384 __ Check(ne, "Function constructed by construct stub."); | |
| 1385 #endif | |
| 1386 | |
| 1387 // Now allocate the JSObject in new space. | |
| 1388 // r0: argc | |
| 1389 // r1: constructor function | |
| 1390 // r2: initial map | |
| 1391 // r7: undefined | |
| 1392 __ ldrb(r3, FieldMemOperand(r2, Map::kInstanceSizeOffset)); | |
| 1393 // Make sure that the maximum heap object size will never cause us | |
| 1394 // problem here, because it is always greater than the maximum | |
| 1395 // instance size that can be represented in a byte. | |
| 1396 ASSERT(Heap::MaxObjectSizeInPagedSpace() >= JSObject::kMaxInstanceSize); | |
|
Erik Corry
2009/09/07 10:21:45
Unnecessary assert.
Søren Thygesen Gjesse
2009/09/07 10:26:43
Done.
| |
| 1397 __ AllocateObjectInNewSpace(r3, | |
| 1398 r4, | |
| 1399 r5, | |
| 1400 r6, | |
| 1401 &generic_stub_call, | |
| 1402 NO_ALLOCATION_FLAGS); | |
| 1403 | |
| 1404 // Allocated the JSObject, now initialize the fields. Map is set to initial | |
| 1405 // map and properties and elements are set to empty fixed array. | |
| 1406 // r0: argc | |
| 1407 // r1: constructor function | |
| 1408 // r2: initial map | |
| 1409 // r3: object size (in words) | |
| 1410 // r4: JSObject (not tagged) | |
| 1411 // r7: undefined | |
| 1412 __ LoadRoot(r6, Heap::kEmptyFixedArrayRootIndex); | |
| 1413 __ mov(r5, r4); | |
| 1414 ASSERT_EQ(0 * kPointerSize, JSObject::kMapOffset); | |
| 1415 __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1416 ASSERT_EQ(1 * kPointerSize, JSObject::kPropertiesOffset); | |
| 1417 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1418 ASSERT_EQ(2 * kPointerSize, JSObject::kElementsOffset); | |
| 1419 __ str(r6, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1420 | |
| 1421 // Calculate the location of the first argument. The stack contains only the | |
| 1422 // argc arguments. | |
| 1423 __ add(r1, sp, Operand(r0, LSL, kPointerSizeLog2)); | |
| 1424 | |
| 1425 // Fill all the in-object properties with undefined. | |
| 1426 // r0: argc | |
| 1427 // r1: first argument | |
| 1428 // r3: object size (in words) | |
| 1429 // r4: JSObject (not tagged) | |
| 1430 // r5: First in-object property of JSObject (not tagged) | |
| 1431 // r7: undefined | |
| 1432 // Fill the initialized properties with a constant value or a passed argument | |
| 1433 // depending on the this.x = ...; assignment in the function. | |
| 1434 for (int i = 0; i < shared->this_property_assignments_count(); i++) { | |
| 1435 if (shared->IsThisPropertyAssignmentArgument(i)) { | |
| 1436 Label not_passed, next; | |
| 1437 // Check if the argument assigned to the property is actually passed. | |
| 1438 int arg_number = shared->GetThisPropertyAssignmentArgument(i); | |
| 1439 __ cmp(r0, Operand(arg_number)); | |
| 1440 __ b(le, ¬_passed); | |
| 1441 // Argument passed - find it on the stack. | |
| 1442 __ ldr(r2, MemOperand(r1, (arg_number + 1) * -kPointerSize)); | |
| 1443 __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1444 __ b(&next); | |
| 1445 __ bind(¬_passed); | |
| 1446 // Set the property to undefined. | |
| 1447 __ str(r7, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1448 __ bind(&next); | |
| 1449 } else { | |
| 1450 // Set the property to the constant value. | |
| 1451 Handle<Object> constant(shared->GetThisPropertyAssignmentConstant(i)); | |
| 1452 __ mov(r2, Operand(constant)); | |
| 1453 __ str(r2, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1454 } | |
| 1455 } | |
| 1456 | |
| 1457 // Fill the unused in-object property fields with undefined. | |
| 1458 for (int i = shared->this_property_assignments_count(); | |
| 1459 i < shared->CalculateInObjectProperties(); | |
| 1460 i++) { | |
| 1461 __ str(r7, MemOperand(r5, kPointerSize, PostIndex)); | |
| 1462 } | |
| 1463 | |
| 1464 // r0: argc | |
| 1465 // r4: JSObject (not tagged) | |
| 1466 // Move argc to r1 and the JSObject to return to r0 and tag it. | |
| 1467 __ mov(r1, r0); | |
| 1468 __ mov(r0, r4); | |
| 1469 __ orr(r0, r0, Operand(kHeapObjectTag)); | |
| 1470 | |
| 1471 // r0: JSObject | |
| 1472 // r1: argc | |
| 1473 // Remove caller arguments and receiver from the stack and return. | |
| 1474 __ add(sp, sp, Operand(r1, LSL, kPointerSizeLog2)); | |
| 1475 __ add(sp, sp, Operand(kPointerSize)); | |
| 1476 __ IncrementCounter(&Counters::constructed_objects, 1, r1, r2); | |
| 1477 __ IncrementCounter(&Counters::constructed_objects_stub, 1, r1, r2); | |
| 1478 __ Jump(lr); | |
| 1479 | |
| 1480 // Jump to the generic stub in case the specialized code cannot handle the | |
| 1481 // construction. | |
| 1482 __ bind(&generic_stub_call); | |
| 1348 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); | 1483 Code* code = Builtins::builtin(Builtins::JSConstructStubGeneric); |
| 1349 Handle<Code> generic_construct_stub(code); | 1484 Handle<Code> generic_construct_stub(code); |
| 1350 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); | 1485 __ Jump(generic_construct_stub, RelocInfo::CODE_TARGET); |
| 1351 | 1486 |
| 1352 // Return the generated code. | 1487 // Return the generated code. |
| 1353 return GetCode(); | 1488 return GetCode(); |
| 1354 } | 1489 } |
| 1355 | 1490 |
| 1356 | 1491 |
| 1357 #undef __ | 1492 #undef __ |
| 1358 | 1493 |
| 1359 } } // namespace v8::internal | 1494 } } // namespace v8::internal |
| OLD | NEW |