Index: src/macro-assembler-ia32.cc |
=================================================================== |
--- src/macro-assembler-ia32.cc (revision 469) |
+++ src/macro-assembler-ia32.cc (working copy) |
@@ -99,8 +99,6 @@ |
Register addr_; |
Register scratch_; |
- const char* GetName() { return "RecordWriteStub"; } |
- |
#ifdef DEBUG |
void Print() { |
PrintF("RecordWriteStub (object reg %d), (addr reg %d), (scratch reg %d)\n", |
@@ -589,6 +587,57 @@ |
} |
+void MacroAssembler::TryGetFunctionPrototype(Register function, |
+ Register result, |
+ Register scratch, |
+ Label* miss) { |
+ // Check that the receiver isn't a smi. |
+ test(function, Immediate(kSmiTagMask)); |
Erik Corry
2008/10/08 13:29:08
We normally have an assert here in case we ever de
|
+ j(zero, miss, not_taken); |
+ |
+ // Check that the function really is a function. |
+ mov(result, FieldOperand(function, HeapObject::kMapOffset)); |
+ movzx_b(scratch, FieldOperand(result, Map::kInstanceTypeOffset)); |
+ cmp(scratch, JS_FUNCTION_TYPE); |
+ j(not_equal, miss, not_taken); |
+ |
+ // Make sure that the function has an instance prototype. |
+ Label non_instance; |
+ movzx_b(scratch, FieldOperand(result, Map::kBitFieldOffset)); |
+ test(scratch, Immediate(1 << Map::kHasNonInstancePrototype)); |
+ j(not_zero, &non_instance, not_taken); |
+ |
+ // Get the prototype or initial map from the function. |
+ mov(result, |
+ FieldOperand(function, JSFunction::kPrototypeOrInitialMapOffset)); |
+ |
+ // If the prototype or initial map is the hole, don't return it and |
+ // simply miss the cache instead. This will allow us to allocate a |
+ // prototype object on-demand in the runtime system. |
+ cmp(Operand(result), Immediate(Factory::the_hole_value())); |
+ j(equal, miss, not_taken); |
+ |
+ // If the function does not have an initial map, we're done. |
+ Label done; |
+ mov(scratch, FieldOperand(result, HeapObject::kMapOffset)); |
+ movzx_b(scratch, FieldOperand(scratch, Map::kInstanceTypeOffset)); |
+ cmp(scratch, MAP_TYPE); |
+ j(not_equal, &done); |
+ |
+ // Get the prototype from the initial map. |
+ mov(result, FieldOperand(result, Map::kPrototypeOffset)); |
+ jmp(&done); |
+ |
+ // Non-instance prototype: Fetch prototype from constructor field |
+ // in initial map. |
+ bind(&non_instance); |
+ mov(result, FieldOperand(result, Map::kConstructorOffset)); |
+ |
+ // All done. |
+ bind(&done); |
+} |
+ |
+ |
void MacroAssembler::CallStub(CodeStub* stub) { |
ASSERT(allow_stub_calls()); // calls are not allowed in some stubs |
call(stub->GetCode(), RelocInfo::CODE_TARGET); |