Use Unique<Map> in CompareMap.
authortitzer@chromium.org <titzer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 19 Sep 2013 17:02:57 +0000 (17:02 +0000)
committertitzer@chromium.org <titzer@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 19 Sep 2013 17:02:57 +0000 (17:02 +0000)
BUG=
R=verwaest@chromium.org

Review URL: https://codereview.chromium.org/24243005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16843 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/arm/lithium-arm.h
src/hydrogen-instructions.cc
src/hydrogen-instructions.h
src/ia32/lithium-ia32.h
src/mips/lithium-mips.h
src/unique.h
src/x64/lithium-x64.h
test/cctest/test-unique.cc

index 6c4d73af8b2f0c3ef3f826fc082bf091db35a242..9c91a030044346e1b75763caff118d125523cdfa 100644 (file)
@@ -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 d69e613605feba5a9ac863aaf3cefeb319dcaf41..d8a438054d5f0a53227992a29ef9f9970ecca4ee 100644 (file)
@@ -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 75b18f4ba69dce36917637a22b25ea9cd725c47a..5128ed32809ed0b56ac8b86aa600ead77a3a5ba1 100644 (file)
@@ -1393,7 +1393,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();
@@ -1409,11 +1409,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 99beda4eee8cba1c5106e0e4694a6c766bd0482f..20e64c48f2f7a5e5e6a671ee8d6ba3a96d6d844b 100644 (file)
@@ -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 cfc0909e9d0b1c32933cc2dd0d43d3aa916ec61e..4cfa128b5da5b46e55bf9e4a31c2ad8f967c6b38 100644 (file)
@@ -1287,7 +1287,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 96a5329754a44589f8346d5ce0f0bc23f20adeac..206fd4e7c678b231f073bc58d0e7664659e4452b 100644 (file)
@@ -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 f827ef6badc9ddaa84354d3c2f8ef5f0fe83441b..136b2940a917a4d8b9efe266787b6a224800699f 100644 (file)
@@ -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(); }
 };
 
 
index ca5b958344a70d49edd04ff0875d60dad592b87c..8a81dec2cfc8bb8498f66ea750dd20461f1e0dfb 100644 (file)
 
 using namespace v8::internal;
 
+#define MAKE_HANDLES_AND_DISALLOW_ALLOCATION  \
+Isolate* isolate = CcTest::i_isolate();       \
+Factory* factory = isolate->factory();        \
+HandleScope sc(isolate);                      \
+Handle<String> handles[] = {                  \
+  factory->InternalizeUtf8String("A"),        \
+  factory->InternalizeUtf8String("B"),        \
+  factory->InternalizeUtf8String("C"),        \
+  factory->InternalizeUtf8String("D"),        \
+  factory->InternalizeUtf8String("E"),        \
+  factory->InternalizeUtf8String("F"),        \
+  factory->InternalizeUtf8String("G")         \
+};                                            \
+DisallowHeapAllocation _disable
+
+#define MAKE_UNIQUES_A_B_C        \
+  Unique<String> A(handles[0]);   \
+  Unique<String> B(handles[1]);   \
+  Unique<String> C(handles[2])
+
+#define MAKE_UNIQUES_A_B_C_D_E_F_G    \
+  Unique<String> A(handles[0]);       \
+  Unique<String> B(handles[1]);       \
+  Unique<String> C(handles[2]);       \
+  Unique<String> D(handles[3]);       \
+  Unique<String> E(handles[4]);       \
+  Unique<String> F(handles[5]);       \
+  Unique<String> G(handles[6])
+
 template <class T, class U>
 void CheckHashCodeEqual(Unique<T> a, Unique<U> b) {
   int64_t hasha = static_cast<int64_t>(a.Hashcode());
@@ -58,11 +87,9 @@ void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) {
 
 TEST(UniqueCreate) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  Handle<String> A = handles[0], B = handles[1];
 
-  Handle<String> A = factory->InternalizeUtf8String("A");
   Unique<String> HA(A);
 
   CHECK(*HA.handle() == *A);
@@ -77,7 +104,6 @@ TEST(UniqueCreate) {
   CHECK(HA2 == HA);
   CHECK_EQ(*HA2.handle(), *HA.handle());
 
-  Handle<String> B = factory->InternalizeUtf8String("B");
   Unique<String> HB(B);
 
   CheckHashCodeNotEqual(HA, HB);
@@ -93,11 +119,9 @@ TEST(UniqueCreate) {
 
 TEST(UniqueSubsume) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  Handle<String> A = handles[0];
 
-  Handle<String> A = factory->InternalizeUtf8String("A");
   Unique<String> HA(A);
 
   CHECK(*HA.handle() == *A);
@@ -116,13 +140,8 @@ TEST(UniqueSubsume) {
 
 TEST(UniqueSet_Add) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -148,13 +167,8 @@ TEST(UniqueSet_Add) {
 
 TEST(UniqueSet_Contains) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -184,13 +198,8 @@ TEST(UniqueSet_Contains) {
 
 TEST(UniqueSet_At) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -226,13 +235,8 @@ static void CHECK_SETS(
 
 TEST(UniqueSet_Equals) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -269,13 +273,8 @@ TEST(UniqueSet_Equals) {
 
 TEST(UniqueSet_IsSubset1) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -309,17 +308,8 @@ TEST(UniqueSet_IsSubset1) {
 
 TEST(UniqueSet_IsSubset2) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
-  Unique<String> D(factory->InternalizeUtf8String("D"));
-  Unique<String> E(factory->InternalizeUtf8String("E"));
-  Unique<String> F(factory->InternalizeUtf8String("F"));
-  Unique<String> G(factory->InternalizeUtf8String("G"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C_D_E_F_G;
 
   Zone zone(isolate);
 
@@ -361,20 +351,11 @@ TEST(UniqueSet_IsSubsetExhaustive) {
   const int kSetSize = 6;
 
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C_D_E_F_G;
 
   Zone zone(isolate);
 
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
-  Unique<String> D(factory->InternalizeUtf8String("D"));
-  Unique<String> E(factory->InternalizeUtf8String("E"));
-  Unique<String> F(factory->InternalizeUtf8String("F"));
-  Unique<String> G(factory->InternalizeUtf8String("G"));
-
   Unique<String> elements[] = {
     A, B, C, D, E, F, G
   };
@@ -393,13 +374,8 @@ TEST(UniqueSet_IsSubsetExhaustive) {
 
 TEST(UniqueSet_Intersect1) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -439,20 +415,11 @@ TEST(UniqueSet_IntersectExhaustive) {
   const int kSetSize = 6;
 
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C_D_E_F_G;
 
   Zone zone(isolate);
 
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
-  Unique<String> D(factory->InternalizeUtf8String("D"));
-  Unique<String> E(factory->InternalizeUtf8String("E"));
-  Unique<String> F(factory->InternalizeUtf8String("F"));
-  Unique<String> G(factory->InternalizeUtf8String("G"));
-
   Unique<String> elements[] = {
     A, B, C, D, E, F, G
   };
@@ -475,13 +442,8 @@ TEST(UniqueSet_IntersectExhaustive) {
 
 TEST(UniqueSet_Union1) {
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
-
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C;
 
   Zone zone(isolate);
 
@@ -521,20 +483,11 @@ TEST(UniqueSet_UnionExhaustive) {
   const int kSetSize = 6;
 
   CcTest::InitializeVM();
-  Isolate* isolate = CcTest::i_isolate();
-  Factory* factory = isolate->factory();
-  HandleScope sc(isolate);
+  MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
+  MAKE_UNIQUES_A_B_C_D_E_F_G;
 
   Zone zone(isolate);
 
-  Unique<String> A(factory->InternalizeUtf8String("A"));
-  Unique<String> B(factory->InternalizeUtf8String("B"));
-  Unique<String> C(factory->InternalizeUtf8String("C"));
-  Unique<String> D(factory->InternalizeUtf8String("D"));
-  Unique<String> E(factory->InternalizeUtf8String("E"));
-  Unique<String> F(factory->InternalizeUtf8String("F"));
-  Unique<String> G(factory->InternalizeUtf8String("G"));
-
   Unique<String> elements[] = {
     A, B, C, D, E, F, G
   };