Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(317)

Side by Side Diff: runtime/vm/isolate.h

Issue 24834002: Refactor some deoptimization code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/deopt_instructions.cc ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/handles.h" 14 #include "vm/handles.h"
15 #include "vm/megamorphic_cache_table.h" 15 #include "vm/megamorphic_cache_table.h"
16 #include "vm/store_buffer.h" 16 #include "vm/store_buffer.h"
17 #include "vm/timer.h" 17 #include "vm/timer.h"
18 18
19 namespace dart { 19 namespace dart {
20 20
21 // Forward declarations. 21 // Forward declarations.
22 class AbstractType; 22 class AbstractType;
23 class ApiState; 23 class ApiState;
24 class Array; 24 class Array;
25 class Class; 25 class Class;
26 class CodeIndexTable; 26 class CodeIndexTable;
27 class Debugger; 27 class Debugger;
28 class DeoptContext;
28 class Field; 29 class Field;
29 class Function; 30 class Function;
30 class HandleScope; 31 class HandleScope;
31 class HandleVisitor; 32 class HandleVisitor;
32 class Heap; 33 class Heap;
33 class ICData; 34 class ICData;
34 class Instance; 35 class Instance;
35 class LongJump; 36 class LongJump;
36 class MessageHandler; 37 class MessageHandler;
37 class Mutex; 38 class Mutex;
(...skipping 13 matching lines...) Expand all
51 class Simulator; 52 class Simulator;
52 class StackResource; 53 class StackResource;
53 class StackZone; 54 class StackZone;
54 class StubCode; 55 class StubCode;
55 class TypeArguments; 56 class TypeArguments;
56 class TypeParameter; 57 class TypeParameter;
57 class ObjectHistogram; 58 class ObjectHistogram;
58 class ObjectIdRing; 59 class ObjectIdRing;
59 60
60 61
61 // Used by the deoptimization infrastructure to defer allocation of unboxed
62 // objects until frame is fully rewritten and GC is safe.
63 // Describes a stack slot that should be populated with a reference to the
64 // materialized object.
65 class DeferredSlot {
66 public:
67 DeferredSlot(RawInstance** slot, DeferredSlot* next)
68 : slot_(slot), next_(next) { }
69 virtual ~DeferredSlot() { }
70
71 RawInstance** slot() const { return slot_; }
72 DeferredSlot* next() const { return next_; }
73
74 virtual void Materialize() = 0;
75
76 private:
77 RawInstance** const slot_;
78 DeferredSlot* const next_;
79
80 DISALLOW_COPY_AND_ASSIGN(DeferredSlot);
81 };
82
83
84 class DeferredDouble : public DeferredSlot {
85 public:
86 DeferredDouble(double value, RawInstance** slot, DeferredSlot* next)
87 : DeferredSlot(slot, next), value_(value) { }
88
89 virtual void Materialize();
90
91 double value() const { return value_; }
92
93 private:
94 const double value_;
95
96 DISALLOW_COPY_AND_ASSIGN(DeferredDouble);
97 };
98
99
100 class DeferredMint : public DeferredSlot {
101 public:
102 DeferredMint(int64_t value, RawInstance** slot, DeferredSlot* next)
103 : DeferredSlot(slot, next), value_(value) { }
104
105 virtual void Materialize();
106
107 int64_t value() const { return value_; }
108
109 private:
110 const int64_t value_;
111
112 DISALLOW_COPY_AND_ASSIGN(DeferredMint);
113 };
114
115
116 class DeferredFloat32x4 : public DeferredSlot {
117 public:
118 DeferredFloat32x4(simd128_value_t value, RawInstance** slot,
119 DeferredSlot* next)
120 : DeferredSlot(slot, next), value_(value) { }
121
122 virtual void Materialize();
123
124 simd128_value_t value() const { return value_; }
125
126 private:
127 const simd128_value_t value_;
128
129 DISALLOW_COPY_AND_ASSIGN(DeferredFloat32x4);
130 };
131
132
133 class DeferredUint32x4 : public DeferredSlot {
134 public:
135 DeferredUint32x4(simd128_value_t value, RawInstance** slot,
136 DeferredSlot* next)
137 : DeferredSlot(slot, next), value_(value) { }
138
139 virtual void Materialize();
140
141 simd128_value_t value() const { return value_; }
142
143 private:
144 const simd128_value_t value_;
145
146 DISALLOW_COPY_AND_ASSIGN(DeferredUint32x4);
147 };
148
149
150 // Describes a slot that contains a reference to an object that had its
151 // allocation removed by AllocationSinking pass.
152 // Object itself is described and materialized by DeferredObject.
153 class DeferredObjectRef : public DeferredSlot {
154 public:
155 DeferredObjectRef(intptr_t index, RawInstance** slot, DeferredSlot* next)
156 : DeferredSlot(slot, next), index_(index) { }
157
158 virtual void Materialize();
159
160 intptr_t index() const { return index_; }
161
162 private:
163 const intptr_t index_;
164
165 DISALLOW_COPY_AND_ASSIGN(DeferredObjectRef);
166 };
167
168
169 // Describes an object which allocation was removed by AllocationSinking pass.
170 // Arguments for materialization are stored as a part of expression stack
171 // for the bottommost deoptimized frame so that GC could discover them.
172 // They will be removed from the stack at the very end of deoptimization.
173 class DeferredObject {
174 public:
175 DeferredObject(intptr_t field_count, intptr_t* args)
176 : field_count_(field_count),
177 args_(reinterpret_cast<RawObject**>(args)),
178 object_(NULL) { }
179
180 intptr_t ArgumentCount() const {
181 return kFieldsStartIndex + kFieldEntrySize * field_count_;
182 }
183
184 RawInstance* object();
185
186 private:
187 enum {
188 kClassIndex = 0,
189 kFieldsStartIndex = kClassIndex + 1
190 };
191
192 enum {
193 kFieldIndex = 0,
194 kValueIndex,
195 kFieldEntrySize,
196 };
197
198 // Materializes the object. Returns amount of values that were consumed
199 // and should be removed from the expression stack at the very end of
200 // deoptimization.
201 void Materialize();
202
203 RawObject* GetClass() const {
204 return args_[kClassIndex];
205 }
206
207 RawObject* GetField(intptr_t index) const {
208 return args_[kFieldsStartIndex + kFieldEntrySize * index + kFieldIndex];
209 }
210
211 RawObject* GetValue(intptr_t index) const {
212 return args_[kFieldsStartIndex + kFieldEntrySize * index + kValueIndex];
213 }
214
215 // Amount of fields that have to be initialized.
216 const intptr_t field_count_;
217
218 // Pointer to the first materialization argument on the stack.
219 // The first argument is Class of the instance to materialize followed by
220 // Field, value pairs.
221 RawObject** args_;
222
223 // Object materialized from this description.
224 const Instance* object_;
225
226 DISALLOW_COPY_AND_ASSIGN(DeferredObject);
227 };
228
229 #define REUSABLE_HANDLE_LIST(V) \ 62 #define REUSABLE_HANDLE_LIST(V) \
230 V(Object) \ 63 V(Object) \
231 V(Array) \ 64 V(Array) \
232 V(String) \ 65 V(String) \
233 V(Instance) \ 66 V(Instance) \
234 V(Function) \ 67 V(Function) \
235 V(Field) \ 68 V(Field) \
236 V(Class) \ 69 V(Class) \
237 V(AbstractType) \ 70 V(AbstractType) \
238 V(TypeParameter) \ 71 V(TypeParameter) \
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
496 static Dart_FileReadCallback file_read_callback() { 329 static Dart_FileReadCallback file_read_callback() {
497 return file_read_callback_; 330 return file_read_callback_;
498 } 331 }
499 static Dart_FileWriteCallback file_write_callback() { 332 static Dart_FileWriteCallback file_write_callback() {
500 return file_write_callback_; 333 return file_write_callback_;
501 } 334 }
502 static Dart_FileCloseCallback file_close_callback() { 335 static Dart_FileCloseCallback file_close_callback() {
503 return file_close_callback_; 336 return file_close_callback_;
504 } 337 }
505 338
506 intptr_t* deopt_cpu_registers_copy() const {
507 return deopt_cpu_registers_copy_;
508 }
509 void set_deopt_cpu_registers_copy(intptr_t* value) {
510 ASSERT((value == NULL) || (deopt_cpu_registers_copy_ == NULL));
511 deopt_cpu_registers_copy_ = value;
512 }
513 fpu_register_t* deopt_fpu_registers_copy() const {
514 return deopt_fpu_registers_copy_;
515 }
516 void set_deopt_fpu_registers_copy(fpu_register_t* value) {
517 ASSERT((value == NULL) || (deopt_fpu_registers_copy_ == NULL));
518 deopt_fpu_registers_copy_ = value;
519 }
520 intptr_t* deopt_frame_copy() const { return deopt_frame_copy_; }
521 void SetDeoptFrameCopy(intptr_t* value, intptr_t size) {
522 ASSERT((value == NULL) || (size > 0));
523 ASSERT((value == NULL) || (deopt_frame_copy_ == NULL));
524 deopt_frame_copy_ = value;
525 deopt_frame_copy_size_ = size;
526 }
527 intptr_t deopt_frame_copy_size() const { return deopt_frame_copy_size_; }
528
529 void set_object_id_ring(ObjectIdRing* ring) { 339 void set_object_id_ring(ObjectIdRing* ring) {
530 object_id_ring_ = ring; 340 object_id_ring_ = ring;
531 } 341 }
532 ObjectIdRing* object_id_ring() { 342 ObjectIdRing* object_id_ring() {
533 return object_id_ring_; 343 return object_id_ring_;
534 } 344 }
535 345
536 void PrepareForDeferredMaterialization(intptr_t count) { 346 DeoptContext* deopt_context() const { return deopt_context_; }
537 if (count > 0) { 347 void set_deopt_context(DeoptContext* value) {
538 deferred_objects_ = new DeferredObject*[count]; 348 ASSERT(value == NULL || deopt_context_ == NULL);
539 deferred_objects_count_ = count; 349 deopt_context_ = value;
540 }
541 } 350 }
542 351
543 void DeleteDeferredObjects() {
544 for (intptr_t i = 0; i < deferred_objects_count_; i++) {
545 delete deferred_objects_[i];
546 }
547 delete[] deferred_objects_;
548 deferred_objects_ = NULL;
549 deferred_objects_count_ = 0;
550 }
551
552 DeferredObject* GetDeferredObject(intptr_t idx) const {
553 return deferred_objects_[idx];
554 }
555
556 void SetDeferredObjectAt(intptr_t idx, DeferredObject* object) {
557 deferred_objects_[idx] = object;
558 }
559
560 intptr_t DeferredObjectsCount() const {
561 return deferred_objects_count_;
562 }
563
564 void DeferMaterializedObjectRef(intptr_t idx, intptr_t* slot) {
565 deferred_object_refs_ = new DeferredObjectRef(
566 idx,
567 reinterpret_cast<RawInstance**>(slot),
568 deferred_object_refs_);
569 }
570
571 void DeferDoubleMaterialization(double value, RawDouble** slot) {
572 deferred_boxes_ = new DeferredDouble(
573 value,
574 reinterpret_cast<RawInstance**>(slot),
575 deferred_boxes_);
576 }
577
578 void DeferMintMaterialization(int64_t value, RawMint** slot) {
579 deferred_boxes_ = new DeferredMint(
580 value,
581 reinterpret_cast<RawInstance**>(slot),
582 deferred_boxes_);
583 }
584
585 void DeferFloat32x4Materialization(simd128_value_t value,
586 RawFloat32x4** slot) {
587 deferred_boxes_ = new DeferredFloat32x4(
588 value,
589 reinterpret_cast<RawInstance**>(slot),
590 deferred_boxes_);
591 }
592
593 void DeferUint32x4Materialization(simd128_value_t value,
594 RawUint32x4** slot) {
595 deferred_boxes_ = new DeferredUint32x4(
596 value,
597 reinterpret_cast<RawInstance**>(slot),
598 deferred_boxes_);
599 }
600
601 // Populate all deferred slots that contain boxes for double, mint, simd
602 // values.
603 void MaterializeDeferredBoxes();
604
605 // Populate all slots containing references to objects which allocations
606 // were eliminated by AllocationSinking pass.
607 void MaterializeDeferredObjects();
608
609 static char* GetStatus(const char* request); 352 static char* GetStatus(const char* request);
610 353
611 intptr_t BlockClassFinalization() { 354 intptr_t BlockClassFinalization() {
612 ASSERT(defer_finalization_count_ >= 0); 355 ASSERT(defer_finalization_count_ >= 0);
613 return defer_finalization_count_++; 356 return defer_finalization_count_++;
614 } 357 }
615 358
616 intptr_t UnblockClassFinalization() { 359 intptr_t UnblockClassFinalization() {
617 ASSERT(defer_finalization_count_ > 0); 360 ASSERT(defer_finalization_count_ > 0);
618 return defer_finalization_count_--; 361 return defer_finalization_count_--;
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 intptr_t deopt_id_; 404 intptr_t deopt_id_;
662 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_. 405 Mutex* mutex_; // protects stack_limit_ and saved_stack_limit_.
663 uword stack_limit_; 406 uword stack_limit_;
664 uword saved_stack_limit_; 407 uword saved_stack_limit_;
665 MessageHandler* message_handler_; 408 MessageHandler* message_handler_;
666 uword spawn_data_; 409 uword spawn_data_;
667 bool is_runnable_; 410 bool is_runnable_;
668 GcPrologueCallbacks gc_prologue_callbacks_; 411 GcPrologueCallbacks gc_prologue_callbacks_;
669 GcEpilogueCallbacks gc_epilogue_callbacks_; 412 GcEpilogueCallbacks gc_epilogue_callbacks_;
670 intptr_t defer_finalization_count_; 413 intptr_t defer_finalization_count_;
671 414 DeoptContext* deopt_context_;
672 // Deoptimization support.
673 intptr_t* deopt_cpu_registers_copy_;
674 fpu_register_t* deopt_fpu_registers_copy_;
675 intptr_t* deopt_frame_copy_;
676 intptr_t deopt_frame_copy_size_;
677 DeferredSlot* deferred_boxes_;
678 DeferredSlot* deferred_object_refs_;
679
680 intptr_t deferred_objects_count_;
681 DeferredObject** deferred_objects_;
682 415
683 // Status support. 416 // Status support.
684 char* stacktrace_; 417 char* stacktrace_;
685 intptr_t stack_frame_index_; 418 intptr_t stack_frame_index_;
686 ObjectHistogram* object_histogram_; 419 ObjectHistogram* object_histogram_;
687 420
688 // Ring buffer of objects assigned an id. 421 // Ring buffer of objects assigned an id.
689 ObjectIdRing* object_id_ring_; 422 ObjectIdRing* object_id_ring_;
690 423
691 // Reusable handles support. 424 // Reusable handles support.
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 Isolate* isolate_; 530 Isolate* isolate_;
798 char* script_url_; 531 char* script_url_;
799 char* library_url_; 532 char* library_url_;
800 char* function_name_; 533 char* function_name_;
801 char* exception_callback_name_; 534 char* exception_callback_name_;
802 }; 535 };
803 536
804 } // namespace dart 537 } // namespace dart
805 538
806 #endif // VM_ISOLATE_H_ 539 #endif // VM_ISOLATE_H_
OLDNEW
« no previous file with comments | « runtime/vm/deopt_instructions.cc ('k') | runtime/vm/isolate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698