Chromium Code Reviews| Index: runtime/vm/isolate.h |
| =================================================================== |
| --- runtime/vm/isolate.h (revision 24200) |
| +++ runtime/vm/isolate.h (working copy) |
| @@ -11,6 +11,7 @@ |
| #include "vm/base_isolate.h" |
| #include "vm/class_table.h" |
| #include "vm/gc_callbacks.h" |
| +#include "vm/handles.h" |
| #include "vm/megamorphic_cache_table.h" |
| #include "vm/store_buffer.h" |
| #include "vm/timer.h" |
| @@ -18,9 +19,13 @@ |
| namespace dart { |
| // Forward declarations. |
| +class AbstractType; |
| class ApiState; |
| +class Array; |
| +class Class; |
| class CodeIndexTable; |
| class Debugger; |
| +class Field; |
| class Function; |
| class HandleScope; |
| class HandleVisitor; |
| @@ -30,6 +35,7 @@ |
| class LongJump; |
| class MessageHandler; |
| class Mutex; |
| +class Object; |
| class ObjectPointerVisitor; |
| class ObjectStore; |
| class RawInstance; |
| @@ -40,12 +46,14 @@ |
| class RawObject; |
| class RawInteger; |
| class RawError; |
| +class RawFloat32x4; |
| +class RawUint32x4; |
| class Simulator; |
| class StackResource; |
| class StackZone; |
| class StubCode; |
| -class RawFloat32x4; |
| -class RawUint32x4; |
| +class TypeArguments; |
| +class TypeParameter; |
| class ObjectHistogram; |
| @@ -217,6 +225,17 @@ |
| DISALLOW_COPY_AND_ASSIGN(DeferredObject); |
| }; |
| +#define REUSABLE_HANDLE_LIST(V) \ |
| + V(Object) \ |
| + V(Array) \ |
| + V(String) \ |
| + V(Instance) \ |
| + V(Function) \ |
| + V(Field) \ |
| + V(Class) \ |
| + V(AbstractType) \ |
| + V(TypeParameter) \ |
| + V(TypeArguments) \ |
| class Isolate : public BaseIsolate { |
| public: |
| @@ -595,6 +614,7 @@ |
| char* GetStatusStacktrace(); |
| char* GetStatusStackFrame(intptr_t index); |
| char* DoStacktraceInterrupt(Dart_IsolateInterruptCallback cb); |
| + template<class T> T* AllocateReusableHandle(); |
| static ThreadLocalKey isolate_key; |
| StoreBuffer store_buffer_; |
| @@ -643,6 +663,14 @@ |
| intptr_t stack_frame_index_; |
| ObjectHistogram* object_histogram_; |
| + // Reusable handles support. |
| +#define REUSABLE_HANDLE_FIELDS(object) \ |
| + object* object##_handle_; \ |
| + |
| + REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_FIELDS) |
| +#undef REUSABLE_HANDLE_FIELDS |
| + VMHandles handles_; |
|
Ivan Posva
2013/06/22 01:01:36
reusable_handles_?
siva
2013/07/18 20:39:23
Done.
|
| + |
| static Dart_IsolateCreateCallback create_callback_; |
| static Dart_IsolateInterruptCallback interrupt_callback_; |
| static Dart_IsolateUnhandledExceptionCallback unhandled_exception_callback_; |
| @@ -653,9 +681,63 @@ |
| static Dart_FileCloseCallback file_close_callback_; |
| static Dart_IsolateInterruptCallback vmstats_callback_; |
| + friend class ReusableHandleScope; |
| DISALLOW_COPY_AND_ASSIGN(Isolate); |
| }; |
| +// The class ReusableHandleScope is used in regions of the |
| +// virtual machine where isolate specific reusable handles are used. |
| +// This class asserts that we do not add code that will result in recursive |
| +// uses of reusable handles. |
| +// It is used as follows: |
| +// { |
| +// ReusableHandleScope reused_handles(isolate); |
| +// .... |
| +// ..... |
| +// code that uses isolate specific reusable handles. |
| +// Array& funcs = reused_handles.ArrayHandle(); |
| +// .... |
| +// } |
| +#if defined(DEBUG) |
| +class ReusableHandleScope : public StackResource { |
| +#else |
| +class ReusableHandleScope : public ValueObject { |
| +#endif |
| + |
| + public: |
| + explicit ReusableHandleScope(Isolate* isolate) : isolate_(isolate) { |
| +#if defined(DEBUG) |
| + ASSERT(!isolate->reusable_handle_scope_active()); |
| + isolate->set_reusable_handle_scope_active(true); |
| +#endif // defined(DEBUG) |
| + } |
| + ReusableHandleScope() : isolate_(Isolate::Current()) { |
| +#if defined(DEBUG) |
| + ASSERT(!isolate_->reusable_handle_scope_active()); |
| + isolate_->set_reusable_handle_scope_active(true); |
| +#endif // defined(DEBUG) |
| + } |
| + ~ReusableHandleScope() { |
| +#if defined(DEBUG) |
| + ASSERT(isolate_->reusable_handle_scope_active()); |
| + isolate_->set_reusable_handle_scope_active(false); |
| +#endif // defined(DEBUG) |
|
Ivan Posva
2013/06/22 01:01:36
To not keep objects alive longer than needed we sh
siva
2013/07/18 20:39:23
Done.
|
| + } |
| + |
| +#define REUSABLE_HANDLE_ACCESSORS(object) \ |
| + object& object##Handle() { \ |
| + ASSERT(isolate_->object##_handle_ != NULL); \ |
| + return *isolate_->object##_handle_; \ |
| + } \ |
| + |
| + REUSABLE_HANDLE_LIST(REUSABLE_HANDLE_ACCESSORS) |
| +#undef REUSABLE_HANDLE_ACCESSORS |
| + |
| + private: |
| + Isolate* isolate_; |
| + DISALLOW_COPY_AND_ASSIGN(ReusableHandleScope); |
| +}; |
| + |
| // When we need to execute code in an isolate, we use the |
| // StartIsolateScope. |
| class StartIsolateScope { |