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

Unified Diff: vm/object.h

Issue 11087070: - Get rid of RawClosure class and use RawInstance for closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 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 side-by-side diff with in-line comments
Download patch
Index: vm/object.h
===================================================================
--- vm/object.h (revision 13487)
+++ vm/object.h (working copy)
@@ -27,6 +27,7 @@
#undef DEFINE_FORWARD_DECLARATION
class Api;
class Assembler;
+class Closure;
class Code;
class LocalScope;
class Symbols;
@@ -421,6 +422,7 @@
friend void ClassTable::Register(const Class& cls);
friend void RawObject::Validate(Isolate* isolate) const;
+ friend class Closure;
friend class SnapshotReader;
// Disallow allocation.
@@ -3005,6 +3007,9 @@
*NativeFieldAddr(index) = value;
}
+ // Returns true if the instance is a closure object.
+ bool IsClosure() const;
+
static intptr_t InstanceSize() {
return RoundedAllocationSize(sizeof(RawInstance));
}
@@ -3033,6 +3038,7 @@
// TODO(iposva): Determine if this gets in the way of Smi.
HEAP_OBJECT_IMPLEMENTATION(Instance, Object);
friend class Class;
+ friend class Closure;
};
@@ -5451,46 +5457,70 @@
};
-class Closure : public Instance {
+class Closure : public AllStatic {
public:
- RawFunction* function() const { return raw_ptr()->function_; }
+ static RawFunction* function(const Instance& closure) {
+ return *FunctionAddr(closure);
Ivan Posva 2012/10/11 04:04:22 ASSERT(closure.IsClosure());
siva 2012/10/11 17:45:58 Done.
+ }
static intptr_t function_offset() {
- return OFFSET_OF(RawClosure, function_);
+ return static_cast<intptr_t>(kFunctionOffset * kWordSize);
}
- RawContext* context() const { return raw_ptr()->context_; }
- static intptr_t context_offset() { return OFFSET_OF(RawClosure, context_); }
+ static RawContext* context(const Instance& closure) {
+ return *ContextAddr(closure);
Ivan Posva 2012/10/11 04:04:22 ditto: ASSERT
siva 2012/10/11 17:45:58 Done.
+ }
+ static intptr_t context_offset() {
+ return static_cast<intptr_t>(kContextOffset * kWordSize);
+ }
- virtual RawAbstractTypeArguments* GetTypeArguments() const {
- return raw_ptr()->type_arguments_;
+ static RawAbstractTypeArguments* GetTypeArguments(const Instance& closure) {
+ return *TypeArgumentsAddr(closure);
}
- virtual void SetTypeArguments(const AbstractTypeArguments& value) const {
- StorePointer(&raw_ptr()->type_arguments_, value.raw());
+ static void SetTypeArguments(const Instance& closure,
+ const AbstractTypeArguments& value) {
+ closure.StorePointer(TypeArgumentsAddr(closure), value.raw());
}
static intptr_t type_arguments_offset() {
- return OFFSET_OF(RawClosure, type_arguments_);
+ return static_cast<intptr_t>(kTypeArgumentsOffset * kWordSize);
}
- // TODO(iposva): Remove smrck support once mapping to arbitrary is available.
- RawInteger* smrck() const { return raw_ptr()->smrck_; }
- void set_smrck(const Integer& smrck) const {
- StorePointer(&raw_ptr()->smrck_, smrck.raw());
- }
- static intptr_t smrck_offset() { return OFFSET_OF(RawClosure, smrck_); }
-
static intptr_t InstanceSize() {
- return RoundedAllocationSize(sizeof(RawClosure));
+ intptr_t size = sizeof(RawInstance) + (kNumFields * kWordSize);
+ ASSERT(size == Object::RoundedAllocationSize(size));
+ return size;
}
- static RawClosure* New(const Function& function,
- const Context& context,
- Heap::Space space = Heap::kNew);
+ static RawInstance* New(const Function& function,
+ const Context& context,
+ Heap::Space space = Heap::kNew);
private:
- void set_function(const Function& value) const;
- void set_context(const Context& value) const;
+ static const int kTypeArgumentsOffset = 1;
+ static const int kFunctionOffset = 2;
+ static const int kContextOffset = 3;
+ static const int kNumFields = 3;
- HEAP_OBJECT_IMPLEMENTATION(Closure, Instance);
+ static RawAbstractTypeArguments** TypeArgumentsAddr(const Instance& obj) {
+ return reinterpret_cast<RawAbstractTypeArguments**>(
Ivan Posva 2012/10/11 04:04:22 Actually the ASSERTs might make more sense here.
siva 2012/10/11 17:45:58 Done.
+ reinterpret_cast<intptr_t>(obj.raw_ptr()) + type_arguments_offset());
+ }
+ static RawFunction** FunctionAddr(const Instance& obj) {
+ return reinterpret_cast<RawFunction**>(
+ reinterpret_cast<intptr_t>(obj.raw_ptr()) + function_offset());
+ }
+ static RawContext** ContextAddr(const Instance& obj) {
+ return reinterpret_cast<RawContext**>(
+ reinterpret_cast<intptr_t>(obj.raw_ptr()) + context_offset());
+ }
+ static void set_function(const Instance& closure,
+ const Function& value) {
+ closure.StorePointer(FunctionAddr(closure), value.raw());
+ }
+ static void set_context(const Instance& closure,
+ const Context& value) {
+ closure.StorePointer(ContextAddr(closure), value.raw());
+ }
+
friend class Class;
};
@@ -5681,11 +5711,7 @@
#endif
set_vtable(builtin_vtables_[cid]);
} else {
-#if !defined(DEBUG)
- Isolate* isolate = Isolate::Current();
-#endif
- RawClass* raw_class = isolate->class_table()->At(cid);
- set_vtable(raw_class->ptr()->handle_vtable_);
+ set_vtable(builtin_vtables_[kInstanceCid]);
}
}

Powered by Google App Engine
This is Rietveld 408576698