Reviewers: Toon Verwaest,

Message:
Now you get your asserts!

Description:
Use Unique<Map> in CompareMap.

BUG=

Please review this at https://codereview.chromium.org/24243005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+21, -12 lines):
  M src/arm/lithium-arm.h
  M src/hydrogen-instructions.h
  M src/hydrogen-instructions.cc
  M src/ia32/lithium-ia32.h
  M src/mips/lithium-mips.h
  M src/unique.h
  M src/x64/lithium-x64.h


Index: src/arm/lithium-arm.h
diff --git a/src/arm/lithium-arm.h b/src/arm/lithium-arm.h
index 6c4d73af8b2f0c3ef3f826fc082bf091db35a242..9c91a030044346e1b75763caff118d125523cdfa 100644
--- a/src/arm/lithium-arm.h
+++ b/src/arm/lithium-arm.h
@@ -1305,7 +1305,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> {
   DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
   DECLARE_HYDROGEN_ACCESSOR(CompareMap)

-  Handle<Map> map() const { return hydrogen()->map(); }
+  Handle<Map> map() const { return hydrogen()->map().handle(); }
 };


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index d69e613605feba5a9ac863aaf3cefeb319dcaf41..d8a438054d5f0a53227992a29ef9f9970ecca4ee 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1052,7 +1052,7 @@ Representation HBranch::observed_input_representation(int index) {

 void HCompareMap::PrintDataTo(StringStream* stream) {
   value()->PrintNameTo(stream);
-  stream->Add(" (%p)", *map());
+  stream->Add(" (%p)", *map().handle());
   HControlInstruction::PrintDataTo(stream);
 }

Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 5bb7f484b5a75a50eef40cfd3a4b0f2ffb6fccb1..f36282f827e47ad45f76de9c883f1bd5d67ab10a 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -1392,7 +1392,7 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction {

   virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE;

-  Handle<Map> map() const { return map_; }
+  Unique<Map> map() const { return map_; }

virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
     return Representation::Tagged();
@@ -1408,11 +1408,12 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction {
               Handle<Map> map,
               HBasicBlock* true_target = NULL,
               HBasicBlock* false_target = NULL)
- : HUnaryControlInstruction(value, true_target, false_target), map_(map) {
+      : HUnaryControlInstruction(value, true_target, false_target),
+        map_(Unique<Map>(map)) {
     ASSERT(!map.is_null());
   }

-  Handle<Map> map_;
+  Unique<Map> map_;
 };


Index: src/ia32/lithium-ia32.h
diff --git a/src/ia32/lithium-ia32.h b/src/ia32/lithium-ia32.h
index 99beda4eee8cba1c5106e0e4694a6c766bd0482f..20e64c48f2f7a5e5e6a671ee8d6ba3a96d6d844b 100644
--- a/src/ia32/lithium-ia32.h
+++ b/src/ia32/lithium-ia32.h
@@ -1296,7 +1296,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> {
   DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
   DECLARE_HYDROGEN_ACCESSOR(CompareMap)

-  Handle<Map> map() const { return hydrogen()->map(); }
+  Handle<Map> map() const { return hydrogen()->map().handle(); }
 };


Index: src/mips/lithium-mips.h
diff --git a/src/mips/lithium-mips.h b/src/mips/lithium-mips.h
index 3ab8f37a15fced123b33c020c785a9c4a4a47462..2104501ef7c50b1776ec4cfae4608b1a003cc083 100644
--- a/src/mips/lithium-mips.h
+++ b/src/mips/lithium-mips.h
@@ -1286,7 +1286,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> {
   DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
   DECLARE_HYDROGEN_ACCESSOR(CompareMap)

-  Handle<Map> map() const { return hydrogen()->map(); }
+  Handle<Map> map() const { return hydrogen()->map().handle(); }
 };


Index: src/unique.h
diff --git a/src/unique.h b/src/unique.h
index 96a5329754a44589f8346d5ce0f0bc23f20adeac..206fd4e7c678b231f073bc58d0e7664659e4452b 100644
--- a/src/unique.h
+++ b/src/unique.h
@@ -29,6 +29,7 @@
 #define V8_HYDROGEN_UNIQUE_H_

 #include "handles.h"
+#include "objects.h"
 #include "utils.h"
 #include "zone.h"

@@ -53,13 +54,20 @@ class UniqueSet;
 template <typename T>
 class Unique V8_FINAL {
  public:
-  // TODO(titzer): make private and introduce some builder/owner class.
+  // TODO(titzer): make private and introduce a factory.
   explicit Unique(Handle<T> handle) {
     if (handle.is_null()) {
       raw_address_ = NULL;
     } else {
+ // This is a best-effort check to prevent comparing Unique<T>'s created + // in different GC eras; we require heap allocation to be disallowed at
+      // creation time.
+      // NOTE: we currently consider maps to be non-movable, so no special
+      // assurance is required for creating a Unique<Map>.
+      // TODO(titzer): other immortable immovable objects are also fine.
+      ASSERT(!AllowHeapAllocation::IsAllowed() || handle->IsMap());
       raw_address_ = reinterpret_cast<Address>(*handle);
-      ASSERT_NE(raw_address_, NULL);
+ ASSERT_NE(raw_address_, NULL); // Non-null should imply non-zero address.
     }
     handle_ = handle;
   }
@@ -69,7 +77,7 @@ class Unique V8_FINAL {
     : raw_address_(raw_address), handle_(handle) { }

   // Constructor for handling automatic up casting.
-  // Ex. Unique<JSFunction> can be passed when Unique<Object> is expected.
+  // Eg. Unique<JSFunction> can be passed when Unique<Object> is expected.
   template <class S> Unique(Unique<S> uniq) {
 #ifdef DEBUG
     T* a = NULL;
@@ -78,7 +86,7 @@ class Unique V8_FINAL {
     USE(a);
 #endif
     raw_address_ = uniq.raw_address_;
- handle_ = uniq.handle_; // Creates a new handle sharing the same location.
+    handle_ = uniq.handle_;
   }

   template <typename U>
Index: src/x64/lithium-x64.h
diff --git a/src/x64/lithium-x64.h b/src/x64/lithium-x64.h
index f827ef6badc9ddaa84354d3c2f8ef5f0fe83441b..136b2940a917a4d8b9efe266787b6a224800699f 100644
--- a/src/x64/lithium-x64.h
+++ b/src/x64/lithium-x64.h
@@ -1246,7 +1246,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> {
   DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
   DECLARE_HYDROGEN_ACCESSOR(CompareMap)

-  Handle<Map> map() const { return hydrogen()->map(); }
+  Handle<Map> map() const { return hydrogen()->map().handle(); }
 };




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to