OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #ifndef VM_ISOLATE_H_ | 5 #ifndef VM_ISOLATE_H_ |
6 #define VM_ISOLATE_H_ | 6 #define VM_ISOLATE_H_ |
7 | 7 |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "platform/thread.h" | 10 #include "platform/thread.h" |
11 #include "vm/base_isolate.h" | 11 #include "vm/base_isolate.h" |
12 #include "vm/class_table.h" | 12 #include "vm/class_table.h" |
13 #include "vm/gc_callbacks.h" | 13 #include "vm/gc_callbacks.h" |
14 #include "vm/megamorphic_cache_table.h" | 14 #include "vm/megamorphic_cache_table.h" |
15 #include "vm/store_buffer.h" | 15 #include "vm/store_buffer.h" |
16 #include "vm/timer.h" | 16 #include "vm/timer.h" |
17 | 17 |
18 namespace dart { | 18 namespace dart { |
19 | 19 |
20 // Forward declarations. | 20 // Forward declarations. |
21 class ApiState; | 21 class ApiState; |
22 class CodeIndexTable; | 22 class CodeIndexTable; |
23 class Debugger; | 23 class Debugger; |
24 class Function; | 24 class Function; |
25 class HandleScope; | 25 class HandleScope; |
26 class HandleVisitor; | 26 class HandleVisitor; |
27 class Heap; | 27 class Heap; |
28 class ICData; | 28 class ICData; |
| 29 class Instance; |
29 class LongJump; | 30 class LongJump; |
30 class MessageHandler; | 31 class MessageHandler; |
31 class Mutex; | 32 class Mutex; |
32 class ObjectPointerVisitor; | 33 class ObjectPointerVisitor; |
33 class ObjectStore; | 34 class ObjectStore; |
34 class RawInstance; | 35 class RawInstance; |
35 class RawArray; | 36 class RawArray; |
36 class RawContext; | 37 class RawContext; |
37 class RawDouble; | 38 class RawDouble; |
38 class RawMint; | 39 class RawMint; |
39 class RawObject; | 40 class RawObject; |
40 class RawInteger; | 41 class RawInteger; |
41 class RawError; | 42 class RawError; |
42 class Simulator; | 43 class Simulator; |
43 class StackResource; | 44 class StackResource; |
44 class StackZone; | 45 class StackZone; |
45 class StubCode; | 46 class StubCode; |
46 class RawFloat32x4; | 47 class RawFloat32x4; |
47 class RawUint32x4; | 48 class RawUint32x4; |
48 | 49 |
49 | 50 |
50 // Used by the deoptimization infrastructure to defer allocation of unboxed | 51 // Used by the deoptimization infrastructure to defer allocation of unboxed |
51 // objects until frame is fully rewritten and GC is safe. | 52 // objects until frame is fully rewritten and GC is safe. |
52 // See callers of Isolate::DeferObjectMaterialization. | 53 // Describes a stack slot that should be populated with a reference to the |
53 class DeferredObject { | 54 // materialized object. |
| 55 class DeferredSlot { |
54 public: | 56 public: |
55 DeferredObject(RawInstance** slot, DeferredObject* next) | 57 DeferredSlot(RawInstance** slot, DeferredSlot* next) |
56 : slot_(slot), next_(next) { } | 58 : slot_(slot), next_(next) { } |
57 virtual ~DeferredObject() { } | 59 virtual ~DeferredSlot() { } |
58 | 60 |
59 RawInstance** slot() const { return slot_; } | 61 RawInstance** slot() const { return slot_; } |
60 DeferredObject* next() const { return next_; } | 62 DeferredSlot* next() const { return next_; } |
61 | 63 |
62 virtual void Materialize() = 0; | 64 virtual void Materialize() = 0; |
63 | 65 |
64 private: | 66 private: |
65 RawInstance** const slot_; | 67 RawInstance** const slot_; |
66 DeferredObject* const next_; | 68 DeferredSlot* const next_; |
67 | 69 |
68 DISALLOW_COPY_AND_ASSIGN(DeferredObject); | 70 DISALLOW_COPY_AND_ASSIGN(DeferredSlot); |
69 }; | 71 }; |
70 | 72 |
71 | 73 |
72 class DeferredDouble : public DeferredObject { | 74 class DeferredDouble : public DeferredSlot { |
73 public: | 75 public: |
74 DeferredDouble(double value, RawInstance** slot, DeferredObject* next) | 76 DeferredDouble(double value, RawInstance** slot, DeferredSlot* next) |
75 : DeferredObject(slot, next), value_(value) { } | 77 : DeferredSlot(slot, next), value_(value) { } |
76 | 78 |
77 virtual void Materialize(); | 79 virtual void Materialize(); |
78 | 80 |
79 double value() const { return value_; } | 81 double value() const { return value_; } |
80 | 82 |
81 private: | 83 private: |
82 const double value_; | 84 const double value_; |
83 | 85 |
84 DISALLOW_COPY_AND_ASSIGN(DeferredDouble); | 86 DISALLOW_COPY_AND_ASSIGN(DeferredDouble); |
85 }; | 87 }; |
86 | 88 |
87 | 89 |
88 class DeferredMint : public DeferredObject { | 90 class DeferredMint : public DeferredSlot { |
89 public: | 91 public: |
90 DeferredMint(int64_t value, RawInstance** slot, DeferredObject* next) | 92 DeferredMint(int64_t value, RawInstance** slot, DeferredSlot* next) |
91 : DeferredObject(slot, next), value_(value) { } | 93 : DeferredSlot(slot, next), value_(value) { } |
92 | 94 |
93 virtual void Materialize(); | 95 virtual void Materialize(); |
94 | 96 |
95 int64_t value() const { return value_; } | 97 int64_t value() const { return value_; } |
96 | 98 |
97 private: | 99 private: |
98 const int64_t value_; | 100 const int64_t value_; |
99 | 101 |
100 DISALLOW_COPY_AND_ASSIGN(DeferredMint); | 102 DISALLOW_COPY_AND_ASSIGN(DeferredMint); |
101 }; | 103 }; |
102 | 104 |
103 | 105 |
104 class DeferredFloat32x4 : public DeferredObject { | 106 class DeferredFloat32x4 : public DeferredSlot { |
105 public: | 107 public: |
106 DeferredFloat32x4(simd128_value_t value, RawInstance** slot, | 108 DeferredFloat32x4(simd128_value_t value, RawInstance** slot, |
107 DeferredObject* next) | 109 DeferredSlot* next) |
108 : DeferredObject(slot, next), value_(value) { } | 110 : DeferredSlot(slot, next), value_(value) { } |
109 | 111 |
110 virtual void Materialize(); | 112 virtual void Materialize(); |
111 | 113 |
112 simd128_value_t value() const { return value_; } | 114 simd128_value_t value() const { return value_; } |
113 | 115 |
114 private: | 116 private: |
115 const simd128_value_t value_; | 117 const simd128_value_t value_; |
116 | 118 |
117 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); | 119 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4); |
118 }; | 120 }; |
119 | 121 |
120 | 122 |
121 class DeferredUint32x4 : public DeferredObject { | 123 class DeferredUint32x4 : public DeferredSlot { |
122 public: | 124 public: |
123 DeferredUint32x4(simd128_value_t value, RawInstance** slot, | 125 DeferredUint32x4(simd128_value_t value, RawInstance** slot, |
124 DeferredObject* next) | 126 DeferredSlot* next) |
125 : DeferredObject(slot, next), value_(value) { } | 127 : DeferredSlot(slot, next), value_(value) { } |
126 | 128 |
127 virtual void Materialize(); | 129 virtual void Materialize(); |
128 | 130 |
129 simd128_value_t value() const { return value_; } | 131 simd128_value_t value() const { return value_; } |
130 | 132 |
131 private: | 133 private: |
132 const simd128_value_t value_; | 134 const simd128_value_t value_; |
133 | 135 |
134 DISALLOW_COPY_AND_ASSIGN(DeferredUint32x4); | 136 DISALLOW_COPY_AND_ASSIGN(DeferredUint32x4); |
135 }; | 137 }; |
136 | 138 |
137 | 139 |
| 140 // Describes a slot that contains a reference to an object that had its |
| 141 // allocation removed by AllocationSinking pass. |
| 142 // Object itself is described and materialized by DeferredObject. |
| 143 class DeferredObjectRef : public DeferredSlot { |
| 144 public: |
| 145 DeferredObjectRef(intptr_t index, RawInstance** slot, DeferredSlot* next) |
| 146 : DeferredSlot(slot, next), index_(index) { } |
| 147 |
| 148 virtual void Materialize(); |
| 149 |
| 150 intptr_t index() const { return index_; } |
| 151 |
| 152 private: |
| 153 const intptr_t index_; |
| 154 |
| 155 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef); |
| 156 }; |
| 157 |
| 158 |
| 159 // Describes an object which allocation was removed by AllocationSinking pass. |
| 160 // Arguments for materialization are stored as a part of expression stack |
| 161 // for the bottommost deoptimized frame so that GC could discover them. |
| 162 // They will be removed from the stack at the very end of deoptimization. |
| 163 class DeferredObject { |
| 164 public: |
| 165 DeferredObject(intptr_t field_count, intptr_t* args) |
| 166 : field_count_(field_count), |
| 167 args_(reinterpret_cast<RawObject**>(args)), |
| 168 object_(NULL) { } |
| 169 |
| 170 intptr_t ArgumentCount() const { |
| 171 return kFieldsStartIndex + kFieldEntrySize * field_count_; |
| 172 } |
| 173 |
| 174 RawInstance* object(); |
| 175 |
| 176 private: |
| 177 enum { |
| 178 kClassIndex = 0, |
| 179 kFieldsStartIndex = kClassIndex + 1 |
| 180 }; |
| 181 |
| 182 enum { |
| 183 kFieldIndex = 0, |
| 184 kValueIndex, |
| 185 kFieldEntrySize, |
| 186 }; |
| 187 |
| 188 // Materializes the object. Returns amount of values that were consumed |
| 189 // and should be removed from the expression stack at the very end of |
| 190 // deoptimization. |
| 191 void Materialize(); |
| 192 |
| 193 RawObject* GetClass() const { |
| 194 return args_[kClassIndex]; |
| 195 } |
| 196 |
| 197 RawObject* GetField(intptr_t index) const { |
| 198 return args_[kFieldsStartIndex + kFieldEntrySize * index + kFieldIndex]; |
| 199 } |
| 200 |
| 201 RawObject* GetValue(intptr_t index) const { |
| 202 return args_[kFieldsStartIndex + kFieldEntrySize * index + kValueIndex]; |
| 203 } |
| 204 |
| 205 // Amount of fields that have to be initialized. |
| 206 const intptr_t field_count_; |
| 207 |
| 208 // Pointer to the first materialization argument on the stack. |
| 209 // The first argument is Class of the instance to materialize followed by |
| 210 // Field, value pairs. |
| 211 RawObject** args_; |
| 212 |
| 213 // Object materialized from this description. |
| 214 const Instance* object_; |
| 215 |
| 216 DISALLOW_COPY_AND_ASSIGN(DeferredObject); |
| 217 }; |
| 218 |
| 219 |
138 class Isolate : public BaseIsolate { | 220 class Isolate : public BaseIsolate { |
139 public: | 221 public: |
140 ~Isolate(); | 222 ~Isolate(); |
141 | 223 |
142 static inline Isolate* Current() { | 224 static inline Isolate* Current() { |
143 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); | 225 return reinterpret_cast<Isolate*>(Thread::GetThreadLocal(isolate_key)); |
144 } | 226 } |
145 | 227 |
146 static void SetCurrent(Isolate* isolate); | 228 static void SetCurrent(Isolate* isolate); |
147 | 229 |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
417 } | 499 } |
418 intptr_t* deopt_frame_copy() const { return deopt_frame_copy_; } | 500 intptr_t* deopt_frame_copy() const { return deopt_frame_copy_; } |
419 void SetDeoptFrameCopy(intptr_t* value, intptr_t size) { | 501 void SetDeoptFrameCopy(intptr_t* value, intptr_t size) { |
420 ASSERT((value == NULL) || (size > 0)); | 502 ASSERT((value == NULL) || (size > 0)); |
421 ASSERT((value == NULL) || (deopt_frame_copy_ == NULL)); | 503 ASSERT((value == NULL) || (deopt_frame_copy_ == NULL)); |
422 deopt_frame_copy_ = value; | 504 deopt_frame_copy_ = value; |
423 deopt_frame_copy_size_ = size; | 505 deopt_frame_copy_size_ = size; |
424 } | 506 } |
425 intptr_t deopt_frame_copy_size() const { return deopt_frame_copy_size_; } | 507 intptr_t deopt_frame_copy_size() const { return deopt_frame_copy_size_; } |
426 | 508 |
| 509 void PrepareForDeferredMaterialization(intptr_t count) { |
| 510 if (count > 0) { |
| 511 deferred_objects_ = new DeferredObject*[count]; |
| 512 deferred_objects_count_ = count; |
| 513 } |
| 514 } |
| 515 |
| 516 void DeleteDeferredObjects() { |
| 517 for (intptr_t i = 0; i < deferred_objects_count_; i++) { |
| 518 delete deferred_objects_[i]; |
| 519 } |
| 520 delete[] deferred_objects_; |
| 521 deferred_objects_ = NULL; |
| 522 deferred_objects_count_ = 0; |
| 523 } |
| 524 |
| 525 DeferredObject* GetDeferredObject(intptr_t idx) const { |
| 526 return deferred_objects_[idx]; |
| 527 } |
| 528 |
| 529 void SetDeferredObjectAt(intptr_t idx, DeferredObject* object) { |
| 530 deferred_objects_[idx] = object; |
| 531 } |
| 532 |
| 533 intptr_t DeferredObjectsCount() const { |
| 534 return deferred_objects_count_; |
| 535 } |
| 536 |
| 537 void DeferMaterializedObjectRef(intptr_t idx, intptr_t* slot) { |
| 538 deferred_object_refs_ = new DeferredObjectRef( |
| 539 idx, |
| 540 reinterpret_cast<RawInstance**>(slot), |
| 541 deferred_object_refs_); |
| 542 } |
| 543 |
427 void DeferDoubleMaterialization(double value, RawDouble** slot) { | 544 void DeferDoubleMaterialization(double value, RawDouble** slot) { |
428 deferred_objects_ = new DeferredDouble( | 545 deferred_boxes_ = new DeferredDouble( |
429 value, | 546 value, |
430 reinterpret_cast<RawInstance**>(slot), | 547 reinterpret_cast<RawInstance**>(slot), |
431 deferred_objects_); | 548 deferred_boxes_); |
432 } | 549 } |
433 | 550 |
434 void DeferMintMaterialization(int64_t value, RawMint** slot) { | 551 void DeferMintMaterialization(int64_t value, RawMint** slot) { |
435 deferred_objects_ = new DeferredMint(value, | 552 deferred_boxes_ = new DeferredMint( |
436 reinterpret_cast<RawInstance**>(slot), | 553 value, |
437 deferred_objects_); | 554 reinterpret_cast<RawInstance**>(slot), |
| 555 deferred_boxes_); |
438 } | 556 } |
439 | 557 |
440 void DeferFloat32x4Materialization(simd128_value_t value, | 558 void DeferFloat32x4Materialization(simd128_value_t value, |
441 RawFloat32x4** slot) { | 559 RawFloat32x4** slot) { |
442 deferred_objects_ = new DeferredFloat32x4( | 560 deferred_boxes_ = new DeferredFloat32x4( |
443 value, | 561 value, |
444 reinterpret_cast<RawInstance**>(slot), | 562 reinterpret_cast<RawInstance**>(slot), |
445 deferred_objects_); | 563 deferred_boxes_); |
446 } | 564 } |
447 | 565 |
448 void DeferUint32x4Materialization(simd128_value_t value, | 566 void DeferUint32x4Materialization(simd128_value_t value, |
449 RawUint32x4** slot) { | 567 RawUint32x4** slot) { |
450 deferred_objects_ = new DeferredUint32x4( | 568 deferred_boxes_ = new DeferredUint32x4( |
451 value, | 569 value, |
452 reinterpret_cast<RawInstance**>(slot), | 570 reinterpret_cast<RawInstance**>(slot), |
453 deferred_objects_); | 571 deferred_boxes_); |
454 } | 572 } |
455 | 573 |
456 DeferredObject* DetachDeferredObjects() { | 574 // Populate all deferred slots that contain boxes for double, mint, simd |
457 DeferredObject* list = deferred_objects_; | 575 // values. |
458 deferred_objects_ = NULL; | 576 void MaterializeDeferredBoxes(); |
459 return list; | 577 |
460 } | 578 // Populate all slots containing references to objects which allocations |
| 579 // were eliminated by AllocationSinking pass. |
| 580 void MaterializeDeferredObjects(); |
461 | 581 |
462 static char* GetStatus(const char* request); | 582 static char* GetStatus(const char* request); |
463 | 583 |
464 private: | 584 private: |
465 Isolate(); | 585 Isolate(); |
466 | 586 |
467 void BuildName(const char* name_prefix); | 587 void BuildName(const char* name_prefix); |
468 void PrintInvokedFunctions(); | 588 void PrintInvokedFunctions(); |
469 | 589 |
470 static bool FetchStacktrace(); | 590 static bool FetchStacktrace(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
504 bool is_runnable_; | 624 bool is_runnable_; |
505 IsolateRunState running_state_; | 625 IsolateRunState running_state_; |
506 GcPrologueCallbacks gc_prologue_callbacks_; | 626 GcPrologueCallbacks gc_prologue_callbacks_; |
507 GcEpilogueCallbacks gc_epilogue_callbacks_; | 627 GcEpilogueCallbacks gc_epilogue_callbacks_; |
508 | 628 |
509 // Deoptimization support. | 629 // Deoptimization support. |
510 intptr_t* deopt_cpu_registers_copy_; | 630 intptr_t* deopt_cpu_registers_copy_; |
511 fpu_register_t* deopt_fpu_registers_copy_; | 631 fpu_register_t* deopt_fpu_registers_copy_; |
512 intptr_t* deopt_frame_copy_; | 632 intptr_t* deopt_frame_copy_; |
513 intptr_t deopt_frame_copy_size_; | 633 intptr_t deopt_frame_copy_size_; |
514 DeferredObject* deferred_objects_; | 634 DeferredSlot* deferred_boxes_; |
| 635 DeferredSlot* deferred_object_refs_; |
| 636 |
| 637 intptr_t deferred_objects_count_; |
| 638 DeferredObject** deferred_objects_; |
515 | 639 |
516 // Status support. | 640 // Status support. |
517 char* stacktrace_; | 641 char* stacktrace_; |
518 intptr_t stack_frame_index_; | 642 intptr_t stack_frame_index_; |
519 | 643 |
520 static Dart_IsolateCreateCallback create_callback_; | 644 static Dart_IsolateCreateCallback create_callback_; |
521 static Dart_IsolateInterruptCallback interrupt_callback_; | 645 static Dart_IsolateInterruptCallback interrupt_callback_; |
522 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; | 646 static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
523 static Dart_IsolateShutdownCallback shutdown_callback_; | 647 static Dart_IsolateShutdownCallback shutdown_callback_; |
524 static Dart_FileOpenCallback file_open_callback_; | 648 static Dart_FileOpenCallback file_open_callback_; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 | 762 |
639 private: | 763 private: |
640 Isolate::IsolateRunState saved_state_; | 764 Isolate::IsolateRunState saved_state_; |
641 | 765 |
642 DISALLOW_COPY_AND_ASSIGN(IsolateRunStateManager); | 766 DISALLOW_COPY_AND_ASSIGN(IsolateRunStateManager); |
643 }; | 767 }; |
644 | 768 |
645 } // namespace dart | 769 } // namespace dart |
646 | 770 |
647 #endif // VM_ISOLATE_H_ | 771 #endif // VM_ISOLATE_H_ |
OLD | NEW |