Commit e1ebbcbb authored by titzer@chromium.org's avatar titzer@chromium.org

Use Unique<Map> in CompareMap.

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
parent 873f02db
...@@ -1305,7 +1305,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> { ...@@ -1305,7 +1305,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> {
DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch") DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
DECLARE_HYDROGEN_ACCESSOR(CompareMap) DECLARE_HYDROGEN_ACCESSOR(CompareMap)
Handle<Map> map() const { return hydrogen()->map(); } Handle<Map> map() const { return hydrogen()->map().handle(); }
}; };
......
...@@ -1052,7 +1052,7 @@ Representation HBranch::observed_input_representation(int index) { ...@@ -1052,7 +1052,7 @@ Representation HBranch::observed_input_representation(int index) {
void HCompareMap::PrintDataTo(StringStream* stream) { void HCompareMap::PrintDataTo(StringStream* stream) {
value()->PrintNameTo(stream); value()->PrintNameTo(stream);
stream->Add(" (%p)", *map()); stream->Add(" (%p)", *map().handle());
HControlInstruction::PrintDataTo(stream); HControlInstruction::PrintDataTo(stream);
} }
......
...@@ -1393,7 +1393,7 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction { ...@@ -1393,7 +1393,7 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction {
virtual void PrintDataTo(StringStream* stream) V8_OVERRIDE; 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 { virtual Representation RequiredInputRepresentation(int index) V8_OVERRIDE {
return Representation::Tagged(); return Representation::Tagged();
...@@ -1409,11 +1409,12 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction { ...@@ -1409,11 +1409,12 @@ class HCompareMap V8_FINAL : public HUnaryControlInstruction {
Handle<Map> map, Handle<Map> map,
HBasicBlock* true_target = NULL, HBasicBlock* true_target = NULL,
HBasicBlock* false_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()); ASSERT(!map.is_null());
} }
Handle<Map> map_; Unique<Map> map_;
}; };
......
...@@ -1296,7 +1296,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> { ...@@ -1296,7 +1296,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> {
DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch") DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
DECLARE_HYDROGEN_ACCESSOR(CompareMap) DECLARE_HYDROGEN_ACCESSOR(CompareMap)
Handle<Map> map() const { return hydrogen()->map(); } Handle<Map> map() const { return hydrogen()->map().handle(); }
}; };
......
...@@ -1287,7 +1287,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> { ...@@ -1287,7 +1287,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 1> {
DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch") DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
DECLARE_HYDROGEN_ACCESSOR(CompareMap) DECLARE_HYDROGEN_ACCESSOR(CompareMap)
Handle<Map> map() const { return hydrogen()->map(); } Handle<Map> map() const { return hydrogen()->map().handle(); }
}; };
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#define V8_HYDROGEN_UNIQUE_H_ #define V8_HYDROGEN_UNIQUE_H_
#include "handles.h" #include "handles.h"
#include "objects.h"
#include "utils.h" #include "utils.h"
#include "zone.h" #include "zone.h"
...@@ -53,13 +54,20 @@ class UniqueSet; ...@@ -53,13 +54,20 @@ class UniqueSet;
template <typename T> template <typename T>
class Unique V8_FINAL { class Unique V8_FINAL {
public: public:
// TODO(titzer): make private and introduce some builder/owner class. // TODO(titzer): make private and introduce a factory.
explicit Unique(Handle<T> handle) { explicit Unique(Handle<T> handle) {
if (handle.is_null()) { if (handle.is_null()) {
raw_address_ = NULL; raw_address_ = NULL;
} else { } 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); 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; handle_ = handle;
} }
...@@ -69,7 +77,7 @@ class Unique V8_FINAL { ...@@ -69,7 +77,7 @@ class Unique V8_FINAL {
: raw_address_(raw_address), handle_(handle) { } : raw_address_(raw_address), handle_(handle) { }
// Constructor for handling automatic up casting. // 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) { template <class S> Unique(Unique<S> uniq) {
#ifdef DEBUG #ifdef DEBUG
T* a = NULL; T* a = NULL;
...@@ -78,7 +86,7 @@ class Unique V8_FINAL { ...@@ -78,7 +86,7 @@ class Unique V8_FINAL {
USE(a); USE(a);
#endif #endif
raw_address_ = uniq.raw_address_; raw_address_ = uniq.raw_address_;
handle_ = uniq.handle_; // Creates a new handle sharing the same location. handle_ = uniq.handle_;
} }
template <typename U> template <typename U>
......
...@@ -1246,7 +1246,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> { ...@@ -1246,7 +1246,7 @@ class LCmpMapAndBranch V8_FINAL : public LControlInstruction<1, 0> {
DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch") DECLARE_CONCRETE_INSTRUCTION(CmpMapAndBranch, "cmp-map-and-branch")
DECLARE_HYDROGEN_ACCESSOR(CompareMap) DECLARE_HYDROGEN_ACCESSOR(CompareMap)
Handle<Map> map() const { return hydrogen()->map(); } Handle<Map> map() const { return hydrogen()->map().handle(); }
}; };
......
...@@ -36,6 +36,35 @@ ...@@ -36,6 +36,35 @@
using namespace v8::internal; 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> template <class T, class U>
void CheckHashCodeEqual(Unique<T> a, Unique<U> b) { void CheckHashCodeEqual(Unique<T> a, Unique<U> b) {
int64_t hasha = static_cast<int64_t>(a.Hashcode()); int64_t hasha = static_cast<int64_t>(a.Hashcode());
...@@ -58,11 +87,9 @@ void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) { ...@@ -58,11 +87,9 @@ void CheckHashCodeNotEqual(Unique<T> a, Unique<U> b) {
TEST(UniqueCreate) { TEST(UniqueCreate) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); Handle<String> A = handles[0], B = handles[1];
HandleScope sc(isolate);
Handle<String> A = factory->InternalizeUtf8String("A");
Unique<String> HA(A); Unique<String> HA(A);
CHECK(*HA.handle() == *A); CHECK(*HA.handle() == *A);
...@@ -77,7 +104,6 @@ TEST(UniqueCreate) { ...@@ -77,7 +104,6 @@ TEST(UniqueCreate) {
CHECK(HA2 == HA); CHECK(HA2 == HA);
CHECK_EQ(*HA2.handle(), *HA.handle()); CHECK_EQ(*HA2.handle(), *HA.handle());
Handle<String> B = factory->InternalizeUtf8String("B");
Unique<String> HB(B); Unique<String> HB(B);
CheckHashCodeNotEqual(HA, HB); CheckHashCodeNotEqual(HA, HB);
...@@ -93,11 +119,9 @@ TEST(UniqueCreate) { ...@@ -93,11 +119,9 @@ TEST(UniqueCreate) {
TEST(UniqueSubsume) { TEST(UniqueSubsume) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); Handle<String> A = handles[0];
HandleScope sc(isolate);
Handle<String> A = factory->InternalizeUtf8String("A");
Unique<String> HA(A); Unique<String> HA(A);
CHECK(*HA.handle() == *A); CHECK(*HA.handle() == *A);
...@@ -116,13 +140,8 @@ TEST(UniqueSubsume) { ...@@ -116,13 +140,8 @@ TEST(UniqueSubsume) {
TEST(UniqueSet_Add) { TEST(UniqueSet_Add) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -148,13 +167,8 @@ TEST(UniqueSet_Add) { ...@@ -148,13 +167,8 @@ TEST(UniqueSet_Add) {
TEST(UniqueSet_Contains) { TEST(UniqueSet_Contains) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -184,13 +198,8 @@ TEST(UniqueSet_Contains) { ...@@ -184,13 +198,8 @@ TEST(UniqueSet_Contains) {
TEST(UniqueSet_At) { TEST(UniqueSet_At) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -226,13 +235,8 @@ static void CHECK_SETS( ...@@ -226,13 +235,8 @@ static void CHECK_SETS(
TEST(UniqueSet_Equals) { TEST(UniqueSet_Equals) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -269,13 +273,8 @@ TEST(UniqueSet_Equals) { ...@@ -269,13 +273,8 @@ TEST(UniqueSet_Equals) {
TEST(UniqueSet_IsSubset1) { TEST(UniqueSet_IsSubset1) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -309,17 +308,8 @@ TEST(UniqueSet_IsSubset1) { ...@@ -309,17 +308,8 @@ TEST(UniqueSet_IsSubset1) {
TEST(UniqueSet_IsSubset2) { TEST(UniqueSet_IsSubset2) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C_D_E_F_G;
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"));
Zone zone(isolate); Zone zone(isolate);
...@@ -361,20 +351,11 @@ TEST(UniqueSet_IsSubsetExhaustive) { ...@@ -361,20 +351,11 @@ TEST(UniqueSet_IsSubsetExhaustive) {
const int kSetSize = 6; const int kSetSize = 6;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C_D_E_F_G;
HandleScope sc(isolate);
Zone zone(isolate); 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[] = { Unique<String> elements[] = {
A, B, C, D, E, F, G A, B, C, D, E, F, G
}; };
...@@ -393,13 +374,8 @@ TEST(UniqueSet_IsSubsetExhaustive) { ...@@ -393,13 +374,8 @@ TEST(UniqueSet_IsSubsetExhaustive) {
TEST(UniqueSet_Intersect1) { TEST(UniqueSet_Intersect1) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -439,20 +415,11 @@ TEST(UniqueSet_IntersectExhaustive) { ...@@ -439,20 +415,11 @@ TEST(UniqueSet_IntersectExhaustive) {
const int kSetSize = 6; const int kSetSize = 6;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C_D_E_F_G;
HandleScope sc(isolate);
Zone zone(isolate); 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[] = { Unique<String> elements[] = {
A, B, C, D, E, F, G A, B, C, D, E, F, G
}; };
...@@ -475,13 +442,8 @@ TEST(UniqueSet_IntersectExhaustive) { ...@@ -475,13 +442,8 @@ TEST(UniqueSet_IntersectExhaustive) {
TEST(UniqueSet_Union1) { TEST(UniqueSet_Union1) {
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C;
HandleScope sc(isolate);
Unique<String> A(factory->InternalizeUtf8String("A"));
Unique<String> B(factory->InternalizeUtf8String("B"));
Unique<String> C(factory->InternalizeUtf8String("C"));
Zone zone(isolate); Zone zone(isolate);
...@@ -521,20 +483,11 @@ TEST(UniqueSet_UnionExhaustive) { ...@@ -521,20 +483,11 @@ TEST(UniqueSet_UnionExhaustive) {
const int kSetSize = 6; const int kSetSize = 6;
CcTest::InitializeVM(); CcTest::InitializeVM();
Isolate* isolate = CcTest::i_isolate(); MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
Factory* factory = isolate->factory(); MAKE_UNIQUES_A_B_C_D_E_F_G;
HandleScope sc(isolate);
Zone zone(isolate); 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[] = { Unique<String> elements[] = {
A, B, C, D, E, F, G A, B, C, D, E, F, G
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment