| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 30 matching lines...) Expand all Loading... |
| 41 __ movq(reg, Operand(rbp, index * kPointerSize)); | 41 __ movq(reg, Operand(rbp, index * kPointerSize)); |
| 42 } | 42 } |
| 43 | 43 |
| 44 | 44 |
| 45 void FastCodeGenerator::EmitReceiverMapCheck() { | 45 void FastCodeGenerator::EmitReceiverMapCheck() { |
| 46 Comment cmnt(masm(), ";; MapCheck(this)"); | 46 Comment cmnt(masm(), ";; MapCheck(this)"); |
| 47 if (FLAG_print_ir) { | 47 if (FLAG_print_ir) { |
| 48 PrintF("MapCheck(this)\n"); | 48 PrintF("MapCheck(this)\n"); |
| 49 } | 49 } |
| 50 | 50 |
| 51 ASSERT(info()->has_receiver() && info()->receiver()->IsHeapObject()); |
| 52 Handle<HeapObject> object = Handle<HeapObject>::cast(info()->receiver()); |
| 53 Handle<Map> map(object->map()); |
| 54 |
| 51 EmitLoadReceiver(rdx); | 55 EmitLoadReceiver(rdx); |
| 52 __ JumpIfSmi(rdx, bailout()); | 56 __ CheckMap(rdx, map, bailout(), false); |
| 53 | |
| 54 ASSERT(has_receiver() && receiver()->IsHeapObject()); | |
| 55 Handle<HeapObject> object = Handle<HeapObject>::cast(receiver()); | |
| 56 Handle<Map> map(object->map()); | |
| 57 __ Cmp(FieldOperand(rdx, HeapObject::kMapOffset), map); | |
| 58 __ j(not_equal, bailout()); | |
| 59 } | 57 } |
| 60 | 58 |
| 61 | 59 |
| 62 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<String> name) { | 60 void FastCodeGenerator::EmitGlobalMapCheck() { |
| 63 // Compile global variable accesses as load IC calls. The only live | 61 Comment cmnt(masm(), ";; GlobalMapCheck"); |
| 64 // registers are rsi (context) and possibly rdx (this). Both are also | 62 if (FLAG_print_ir) { |
| 65 // saved in the stack and rsi is preserved by the call. | 63 PrintF(";; GlobalMapCheck()"); |
| 66 __ push(CodeGenerator::GlobalObject()); | 64 } |
| 67 __ Move(rcx, name); | 65 |
| 68 Handle<Code> ic(Builtins::builtin(Builtins::LoadIC_Initialize)); | 66 ASSERT(info()->has_global_object()); |
| 69 __ Call(ic, RelocInfo::CODE_TARGET_CONTEXT); | 67 Handle<Map> map(info()->global_object()->map()); |
| 70 if (has_this_properties()) { | 68 |
| 71 // Restore this. | 69 __ movq(rbx, CodeGenerator::GlobalObject()); |
| 72 EmitLoadReceiver(rdx); | 70 __ CheckMap(rbx, map, bailout(), true); |
| 73 } else { | 71 } |
| 74 __ nop(); // Not test rax, indicates IC has no inlined code at call site. | 72 |
| 73 |
| 74 void FastCodeGenerator::EmitGlobalVariableLoad(Handle<Object> cell) { |
| 75 ASSERT(cell->IsJSGlobalPropertyCell()); |
| 76 __ Move(rax, cell); |
| 77 __ movq(rax, FieldOperand(rax, JSGlobalPropertyCell::kValueOffset)); |
| 78 if (FLAG_debug_code) { |
| 79 __ Cmp(rax, Factory::the_hole_value()); |
| 80 __ Check(not_equal, "DontDelete cells can't contain the hole"); |
| 75 } | 81 } |
| 76 } | 82 } |
| 77 | 83 |
| 78 | 84 |
| 79 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { | 85 void FastCodeGenerator::EmitThisPropertyStore(Handle<String> name) { |
| 80 LookupResult lookup; | 86 LookupResult lookup; |
| 81 receiver()->Lookup(*name, &lookup); | 87 info()->receiver()->Lookup(*name, &lookup); |
| 82 | 88 |
| 83 ASSERT(lookup.holder() == *receiver()); | 89 ASSERT(lookup.holder() == *info()->receiver()); |
| 84 ASSERT(lookup.type() == FIELD); | 90 ASSERT(lookup.type() == FIELD); |
| 85 Handle<Map> map(Handle<HeapObject>::cast(receiver())->map()); | 91 Handle<Map> map(Handle<HeapObject>::cast(info()->receiver())->map()); |
| 86 int index = lookup.GetFieldIndex() - map->inobject_properties(); | 92 int index = lookup.GetFieldIndex() - map->inobject_properties(); |
| 87 int offset = index * kPointerSize; | 93 int offset = index * kPointerSize; |
| 88 | 94 |
| 89 // Negative offsets are inobject properties. | 95 // Negative offsets are inobject properties. |
| 90 if (offset < 0) { | 96 if (offset < 0) { |
| 91 offset += map->instance_size(); | 97 offset += map->instance_size(); |
| 92 __ movq(rcx, rdx); // Copy receiver for write barrier. | 98 __ movq(rcx, rdx); // Copy receiver for write barrier. |
| 93 } else { | 99 } else { |
| 94 offset += FixedArray::kHeaderSize; | 100 offset += FixedArray::kHeaderSize; |
| 95 __ movq(rcx, FieldOperand(rdx, JSObject::kPropertiesOffset)); | 101 __ movq(rcx, FieldOperand(rdx, JSObject::kPropertiesOffset)); |
| 96 } | 102 } |
| 97 // Perform the store. | 103 // Perform the store. |
| 98 __ movq(FieldOperand(rcx, offset), rax); | 104 __ movq(FieldOperand(rcx, offset), rax); |
| 99 // Preserve value from write barrier in case it's needed. | 105 // Preserve value from write barrier in case it's needed. |
| 100 __ movq(rbx, rax); | 106 __ movq(rbx, rax); |
| 101 __ RecordWrite(rcx, offset, rbx, rdi); | 107 __ RecordWrite(rcx, offset, rbx, rdi); |
| 102 } | 108 } |
| 103 | 109 |
| 104 | 110 |
| 105 void FastCodeGenerator::Generate(CompilationInfo* info) { | 111 void FastCodeGenerator::Generate(CompilationInfo* compilation_info) { |
| 106 ASSERT(info_ == NULL); | 112 ASSERT(info_ == NULL); |
| 107 info_ = info; | 113 info_ = compilation_info; |
| 108 | 114 |
| 109 // Save the caller's frame pointer and set up our own. | 115 // Save the caller's frame pointer and set up our own. |
| 110 Comment prologue_cmnt(masm(), ";; Prologue"); | 116 Comment prologue_cmnt(masm(), ";; Prologue"); |
| 111 __ push(rbp); | 117 __ push(rbp); |
| 112 __ movq(rbp, rsp); | 118 __ movq(rbp, rsp); |
| 113 __ push(rsi); // Context. | 119 __ push(rsi); // Context. |
| 114 __ push(rdi); // Closure. | 120 __ push(rdi); // Closure. |
| 115 // Note that we keep a live register reference to esi (context) at this | 121 // Note that we keep a live register reference to esi (context) at this |
| 116 // point. | 122 // point. |
| 117 | 123 |
| 118 // Receiver (this) is allocated to rdx if there are this properties. | 124 // Receiver (this) is allocated to rdx if there are this properties. |
| 119 if (has_this_properties()) EmitReceiverMapCheck(); | 125 if (info()->has_this_properties()) EmitReceiverMapCheck(); |
| 120 | 126 |
| 121 VisitStatements(info->function()->body()); | 127 // If there is a global variable access check if the global object |
| 128 // is the same as at lazy-compilation time. |
| 129 if (info()->has_globals()) EmitGlobalMapCheck(); |
| 130 |
| 131 VisitStatements(info()->function()->body()); |
| 122 | 132 |
| 123 Comment return_cmnt(masm(), ";; Return(<undefined>)"); | 133 Comment return_cmnt(masm(), ";; Return(<undefined>)"); |
| 124 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); | 134 __ LoadRoot(rax, Heap::kUndefinedValueRootIndex); |
| 125 | 135 |
| 126 Comment epilogue_cmnt(masm(), ";; Epilogue"); | 136 Comment epilogue_cmnt(masm(), ";; Epilogue"); |
| 127 __ movq(rsp, rbp); | 137 __ movq(rsp, rbp); |
| 128 __ pop(rbp); | 138 __ pop(rbp); |
| 129 __ ret((scope()->num_parameters() + 1) * kPointerSize); | 139 __ ret((scope()->num_parameters() + 1) * kPointerSize); |
| 130 | 140 |
| 131 __ bind(&bailout_); | 141 __ bind(&bailout_); |
| 132 } | 142 } |
| 133 | 143 |
| 134 | 144 |
| 135 #undef __ | 145 #undef __ |
| 136 | 146 |
| 137 | 147 |
| 138 } } // namespace v8::internal | 148 } } // namespace v8::internal |
| OLD | NEW |