Reviewers: antonm,

Description:
[Isolates] Add debugging code to ensure consistent Isolate class layout.

Please review this at http://codereview.chromium.org/6628036/

Affected files:
  M src/isolate.h
  M src/isolate.cc


Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index e3119479413b11136d0da968091b16bece130e17..346aa4f46d97072d736e4452c37ceebc6e01a6da 100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -801,4 +801,13 @@ void Isolate::ResetEagerOptimizingData() {
   compilation_cache_->ResetEagerOptimizingData();
 }

+
+#ifdef DEBUG
+#define ISOLATE_FIELD_OFFSET(type, name, ignored)                       \
+const intptr_t Isolate::name##_debug_offset_ = OFFSET_OF(Isolate, name##_);
+ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
+ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
+#undef ISOLATE_FIELD_OFFSET
+#endif
+
 } }  // namespace v8::internal
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index 9ce59943d177e70f82467e2e4287ea3805a28b01..25db5747d80c519feb3649e82559e4de67b2e62b 100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -669,14 +669,23 @@ class Isolate {
   static const int kBMMaxShift = 250;        // See StringSearchBase.

   // Accessors.
-#define GLOBAL_ACCESSOR(type, name, initialvalue) \ - type name() const { return name##_; } \
-  void set_##name(type value) { name##_ = value; }
+#define GLOBAL_ACCESSOR(type, name, initialvalue)                       \
+  inline type name() const {                                            \
+    ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
+    return name##_;                                                     \
+  }                                                                     \
+  inline void set_##name(type value) {                                  \
+    ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
+    name##_ = value;                                                    \
+  }
   ISOLATE_INIT_LIST(GLOBAL_ACCESSOR)
 #undef GLOBAL_ACCESSOR

-#define GLOBAL_ARRAY_ACCESSOR(type, name, length) \
-  type* name() { return &(name##_[0]); }
+#define GLOBAL_ARRAY_ACCESSOR(type, name, length)                       \
+  inline type* name() {                                                 \
+    ASSERT(OFFSET_OF(Isolate, name##_) == name##_debug_offset_);        \
+    return &(name##_)[0];                                               \
+  }
   ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_ACCESSOR)
 #undef GLOBAL_ARRAY_ACCESSOR

@@ -1090,6 +1099,17 @@ class Isolate {
   ISOLATE_INIT_ARRAY_LIST(GLOBAL_ARRAY_BACKING_STORE)
 #undef GLOBAL_ARRAY_BACKING_STORE

+#ifdef DEBUG
+  // This class is huge and has a number of fields controlled by
+  // preprocessor defines. Make sure the offsets of these fields agree
+  // between compilation units.
+#define ISOLATE_FIELD_OFFSET(type, name, ignored) \
+  static const intptr_t name##_debug_offset_;
+  ISOLATE_INIT_LIST(ISOLATE_FIELD_OFFSET)
+  ISOLATE_INIT_ARRAY_LIST(ISOLATE_FIELD_OFFSET)
+#undef ISOLATE_FIELD_OFFSET
+#endif
+
   friend class ExecutionAccess;
   friend class IsolateInitializer;
   friend class v8::Isolate;


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to