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> {
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(); }
};
......
......@@ -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);
}
......
......@@ -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_;
};
......
......@@ -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(); }
};
......
......@@ -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(); }
};
......
......@@ -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>
......
......@@ -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(); }
};
......
......@@ -36,6 +36,35 @@
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
};
......
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