| 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 RUNTIME_VM_REUSABLE_HANDLES_H_ | 5 #ifndef RUNTIME_VM_REUSABLE_HANDLES_H_ |
| 6 #define RUNTIME_VM_REUSABLE_HANDLES_H_ | 6 #define RUNTIME_VM_REUSABLE_HANDLES_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/handles.h" | 9 #include "vm/handles.h" |
| 10 #include "vm/object.h" | 10 #include "vm/object.h" |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 // code that uses funcs | 28 // code that uses funcs |
| 29 // .... | 29 // .... |
| 30 // } | 30 // } |
| 31 // | 31 // |
| 32 | 32 |
| 33 | 33 |
| 34 #if defined(DEBUG) | 34 #if defined(DEBUG) |
| 35 #define REUSABLE_SCOPE(name) \ | 35 #define REUSABLE_SCOPE(name) \ |
| 36 class Reusable##name##HandleScope : public ValueObject { \ | 36 class Reusable##name##HandleScope : public ValueObject { \ |
| 37 public: \ | 37 public: \ |
| 38 explicit Reusable##name##HandleScope(Thread* thread) \ | 38 explicit Reusable##name##HandleScope(Thread* thread) : thread_(thread) { \ |
| 39 : thread_(thread) { \ | |
| 40 ASSERT(!thread->reusable_##name##_handle_scope_active()); \ | 39 ASSERT(!thread->reusable_##name##_handle_scope_active()); \ |
| 41 thread->set_reusable_##name##_handle_scope_active(true); \ | 40 thread->set_reusable_##name##_handle_scope_active(true); \ |
| 42 } \ | 41 } \ |
| 43 Reusable##name##HandleScope() : thread_(Thread::Current()) { \ | 42 Reusable##name##HandleScope() : thread_(Thread::Current()) { \ |
| 44 ASSERT(!thread_->reusable_##name##_handle_scope_active()); \ | 43 ASSERT(!thread_->reusable_##name##_handle_scope_active()); \ |
| 45 thread_->set_reusable_##name##_handle_scope_active(true); \ | 44 thread_->set_reusable_##name##_handle_scope_active(true); \ |
| 46 } \ | 45 } \ |
| 47 ~Reusable##name##HandleScope() { \ | 46 ~Reusable##name##HandleScope() { \ |
| 48 ASSERT(thread_->reusable_##name##_handle_scope_active()); \ | 47 ASSERT(thread_->reusable_##name##_handle_scope_active()); \ |
| 49 thread_->set_reusable_##name##_handle_scope_active(false); \ | 48 thread_->set_reusable_##name##_handle_scope_active(false); \ |
| 50 Handle().raw_ = name::null(); \ | 49 Handle().raw_ = name::null(); \ |
| 51 } \ | 50 } \ |
| 52 name& Handle() const { \ | 51 name& Handle() const { \ |
| 53 ASSERT(thread_->name##_handle_ != NULL); \ | 52 ASSERT(thread_->name##_handle_ != NULL); \ |
| 54 return *thread_->name##_handle_; \ | 53 return *thread_->name##_handle_; \ |
| 55 } \ | 54 } \ |
| 55 \ |
| 56 private: \ | 56 private: \ |
| 57 Thread* thread_; \ | 57 Thread* thread_; \ |
| 58 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \ | 58 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \ |
| 59 }; | 59 }; |
| 60 #else | 60 #else |
| 61 #define REUSABLE_SCOPE(name) \ | 61 #define REUSABLE_SCOPE(name) \ |
| 62 class Reusable##name##HandleScope : public ValueObject { \ | 62 class Reusable##name##HandleScope : public ValueObject { \ |
| 63 public: \ | 63 public: \ |
| 64 explicit Reusable##name##HandleScope(Thread* thread) \ | 64 explicit Reusable##name##HandleScope(Thread* thread) \ |
| 65 : handle_(thread->name##_handle_) { \ | 65 : handle_(thread->name##_handle_) {} \ |
| 66 } \ | |
| 67 Reusable##name##HandleScope() \ | 66 Reusable##name##HandleScope() \ |
| 68 : handle_(Thread::Current()->name##_handle_) { \ | 67 : handle_(Thread::Current()->name##_handle_) {} \ |
| 69 } \ | 68 ~Reusable##name##HandleScope() { handle_->raw_ = name::null(); } \ |
| 70 ~Reusable##name##HandleScope() { \ | |
| 71 handle_->raw_ = name::null(); \ | |
| 72 } \ | |
| 73 name& Handle() const { \ | 69 name& Handle() const { \ |
| 74 ASSERT(handle_ != NULL); \ | 70 ASSERT(handle_ != NULL); \ |
| 75 return *handle_; \ | 71 return *handle_; \ |
| 76 } \ | 72 } \ |
| 73 \ |
| 77 private: \ | 74 private: \ |
| 78 name* handle_; \ | 75 name* handle_; \ |
| 79 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \ | 76 DISALLOW_COPY_AND_ASSIGN(Reusable##name##HandleScope); \ |
| 80 }; | 77 }; |
| 81 #endif // defined(DEBUG) | 78 #endif // defined(DEBUG) |
| 82 REUSABLE_HANDLE_LIST(REUSABLE_SCOPE) | 79 REUSABLE_HANDLE_LIST(REUSABLE_SCOPE) |
| 83 #undef REUSABLE_SCOPE | 80 #undef REUSABLE_SCOPE |
| 84 | 81 |
| 85 #define REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread) \ | 82 #define REUSABLE_ABSTRACT_TYPE_HANDLESCOPE(thread) \ |
| 86 ReusableAbstractTypeHandleScope reused_abstract_type(thread); | 83 ReusableAbstractTypeHandleScope reused_abstract_type(thread); |
| 87 #define REUSABLE_ARRAY_HANDLESCOPE(thread) \ | 84 #define REUSABLE_ARRAY_HANDLESCOPE(thread) \ |
| 88 ReusableArrayHandleScope reused_array_handle(thread); | 85 ReusableArrayHandleScope reused_array_handle(thread); |
| 89 #define REUSABLE_CLASS_HANDLESCOPE(thread) \ | 86 #define REUSABLE_CLASS_HANDLESCOPE(thread) \ |
| 90 ReusableClassHandleScope reused_class_handle(thread); | 87 ReusableClassHandleScope reused_class_handle(thread); |
| 91 #define REUSABLE_CODE_HANDLESCOPE(thread) \ | 88 #define REUSABLE_CODE_HANDLESCOPE(thread) \ |
| 92 ReusableCodeHandleScope reused_code_handle(thread); | 89 ReusableCodeHandleScope reused_code_handle(thread); |
| 93 #define REUSABLE_ERROR_HANDLESCOPE(thread) \ | 90 #define REUSABLE_ERROR_HANDLESCOPE(thread) \ |
| 94 ReusableErrorHandleScope reused_error_handle(thread); | 91 ReusableErrorHandleScope reused_error_handle(thread); |
| 95 #define REUSABLE_EXCEPTION_HANDLERS_HANDLESCOPE(thread) \ | 92 #define REUSABLE_EXCEPTION_HANDLERS_HANDLESCOPE(thread) \ |
| 96 ReusableExceptionHandlersHandleScope \ | 93 ReusableExceptionHandlersHandleScope reused_exception_handlers_handle(thread); |
| 97 reused_exception_handlers_handle(thread); | |
| 98 #define REUSABLE_FIELD_HANDLESCOPE(thread) \ | 94 #define REUSABLE_FIELD_HANDLESCOPE(thread) \ |
| 99 ReusableFieldHandleScope reused_field_handle(thread); | 95 ReusableFieldHandleScope reused_field_handle(thread); |
| 100 #define REUSABLE_FUNCTION_HANDLESCOPE(thread) \ | 96 #define REUSABLE_FUNCTION_HANDLESCOPE(thread) \ |
| 101 ReusableFunctionHandleScope reused_function_handle(thread); | 97 ReusableFunctionHandleScope reused_function_handle(thread); |
| 102 #define REUSABLE_GROWABLE_OBJECT_ARRAY_HANDLESCOPE(thread) \ | 98 #define REUSABLE_GROWABLE_OBJECT_ARRAY_HANDLESCOPE(thread) \ |
| 103 ReusableGrowableObjectArrayHandleScope \ | 99 ReusableGrowableObjectArrayHandleScope reused_growable_object_array_handle( \ |
| 104 reused_growable_object_array_handle(thread) | 100 thread) |
| 105 #define REUSABLE_INSTANCE_HANDLESCOPE(thread) \ | 101 #define REUSABLE_INSTANCE_HANDLESCOPE(thread) \ |
| 106 ReusableInstanceHandleScope reused_instance_handle(thread); | 102 ReusableInstanceHandleScope reused_instance_handle(thread); |
| 107 #define REUSABLE_LIBRARY_HANDLESCOPE(thread) \ | 103 #define REUSABLE_LIBRARY_HANDLESCOPE(thread) \ |
| 108 ReusableLibraryHandleScope reused_library_handle(thread); | 104 ReusableLibraryHandleScope reused_library_handle(thread); |
| 109 #define REUSABLE_OBJECT_HANDLESCOPE(thread) \ | 105 #define REUSABLE_OBJECT_HANDLESCOPE(thread) \ |
| 110 ReusableObjectHandleScope reused_object_handle(thread); | 106 ReusableObjectHandleScope reused_object_handle(thread); |
| 111 #define REUSABLE_PC_DESCRIPTORS_HANDLESCOPE(thread) \ | 107 #define REUSABLE_PC_DESCRIPTORS_HANDLESCOPE(thread) \ |
| 112 ReusablePcDescriptorsHandleScope reused_pc_descriptors_handle(thread); | 108 ReusablePcDescriptorsHandleScope reused_pc_descriptors_handle(thread); |
| 113 #define REUSABLE_SMI_HANDLESCOPE(thread) \ | 109 #define REUSABLE_SMI_HANDLESCOPE(thread) \ |
| 114 ReusableSmiHandleScope reused_smi_handle(thread); | 110 ReusableSmiHandleScope reused_smi_handle(thread); |
| 115 #define REUSABLE_STRING_HANDLESCOPE(thread) \ | 111 #define REUSABLE_STRING_HANDLESCOPE(thread) \ |
| 116 ReusableStringHandleScope reused_string_handle(thread); | 112 ReusableStringHandleScope reused_string_handle(thread); |
| 117 #define REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread) \ | 113 #define REUSABLE_TYPE_ARGUMENTS_HANDLESCOPE(thread) \ |
| 118 ReusableTypeArgumentsHandleScope reused_type_arguments_handle(thread); | 114 ReusableTypeArgumentsHandleScope reused_type_arguments_handle(thread); |
| 119 #define REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread) \ | 115 #define REUSABLE_TYPE_PARAMETER_HANDLESCOPE(thread) \ |
| 120 ReusableTypeParameterHandleScope reused_type_parameter(thread); | 116 ReusableTypeParameterHandleScope reused_type_parameter(thread); |
| 121 | 117 |
| 122 } // namespace dart | 118 } // namespace dart |
| 123 | 119 |
| 124 #endif // RUNTIME_VM_REUSABLE_HANDLES_H_ | 120 #endif // RUNTIME_VM_REUSABLE_HANDLES_H_ |
| OLD | NEW |