| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/stub_code.h" | 5 #include "vm/stub_code.h" |
| 6 | 6 |
| 7 #include "platform/assert.h" | 7 #include "platform/assert.h" |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
| 10 #include "vm/disassembler.h" | 10 #include "vm/disassembler.h" |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 return AllocateArray_entry()->code(); | 117 return AllocateArray_entry()->code(); |
| 118 } | 118 } |
| 119 Code& stub = Code::Handle(zone, cls.allocation_stub()); | 119 Code& stub = Code::Handle(zone, cls.allocation_stub()); |
| 120 if (stub.IsNull()) { | 120 if (stub.IsNull()) { |
| 121 Assembler assembler; | 121 Assembler assembler; |
| 122 const char* name = cls.ToCString(); | 122 const char* name = cls.ToCString(); |
| 123 StubCode::GenerateAllocationStubForClass(&assembler, cls); | 123 StubCode::GenerateAllocationStubForClass(&assembler, cls); |
| 124 | 124 |
| 125 if (thread->IsMutatorThread()) { | 125 if (thread->IsMutatorThread()) { |
| 126 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); | 126 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); |
| 127 stub.set_owner(cls); | 127 // Check if background compilation thread has not already added the stub. |
| 128 cls.set_allocation_stub(stub); | 128 if (cls.allocation_stub() == Code::null()) { |
| 129 stub.set_owner(cls); |
| 130 cls.set_allocation_stub(stub); |
| 131 } |
| 129 } else { | 132 } else { |
| 130 // This part of stub code generation must be at a safepoint. | 133 // This part of stub code generation must be at a safepoint. |
| 131 // Stop mutator thread before creating the instruction object and | 134 // Stop mutator thread before creating the instruction object and |
| 132 // installing code. | 135 // installing code. |
| 133 // Mutator thread may not run code while we are creating the | 136 // Mutator thread may not run code while we are creating the |
| 134 // instruction object, since the creation of instruction object | 137 // instruction object, since the creation of instruction object |
| 135 // changes code page access permissions (makes them temporary not | 138 // changes code page access permissions (makes them temporary not |
| 136 // executable). | 139 // executable). |
| 137 { | 140 { |
| 138 SafepointOperationScope safepoint_scope(thread); | 141 SafepointOperationScope safepoint_scope(thread); |
| 142 stub = cls.allocation_stub(); |
| 143 // Check if stub was already generated. |
| 144 if (!stub.IsNull()) { |
| 145 return stub.raw(); |
| 146 } |
| 139 // Do not Garbage collect during this stage and instead allow the | 147 // Do not Garbage collect during this stage and instead allow the |
| 140 // heap to grow. | 148 // heap to grow. |
| 141 NoHeapGrowthControlScope no_growth_control; | 149 NoHeapGrowthControlScope no_growth_control; |
| 142 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); | 150 stub ^= Code::FinalizeCode(name, &assembler, false /* optimized */); |
| 143 stub.set_owner(cls); | 151 stub.set_owner(cls); |
| 144 cls.set_allocation_stub(stub); | 152 cls.set_allocation_stub(stub); |
| 145 } | 153 } |
| 146 Isolate* isolate = thread->isolate(); | 154 Isolate* isolate = thread->isolate(); |
| 147 if (isolate->heap()->NeedsGarbageCollection()) { | 155 if (isolate->heap()->NeedsGarbageCollection()) { |
| 148 isolate->heap()->CollectAllGarbage(); | 156 isolate->heap()->CollectAllGarbage(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 if ((name##_entry() != NULL) && \ | 212 if ((name##_entry() != NULL) && \ |
| 205 (entry_point == name##_entry()->EntryPoint())) { \ | 213 (entry_point == name##_entry()->EntryPoint())) { \ |
| 206 return ""#name; \ | 214 return ""#name; \ |
| 207 } | 215 } |
| 208 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); | 216 VM_STUB_CODE_LIST(VM_STUB_CODE_TESTER); |
| 209 #undef VM_STUB_CODE_TESTER | 217 #undef VM_STUB_CODE_TESTER |
| 210 return NULL; | 218 return NULL; |
| 211 } | 219 } |
| 212 | 220 |
| 213 } // namespace dart | 221 } // namespace dart |
| OLD | NEW |