Commit 0e76f83b authored by lrn@chromium.org's avatar lrn@chromium.org

X64: Made hash computation in serializer accept 64-bit pointers.

Also changed api Wrap function to only wrap suitably small pointers as Smis.
Added Smi validity check and factory meethod for intptr_t.

Review URL: http://codereview.chromium.org/113023


git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@1875 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 525b43d6
......@@ -2680,10 +2680,13 @@ Local<Value> v8::External::Wrap(void* data) {
ENTER_V8;
if ((reinterpret_cast<intptr_t>(data) & kAlignedPointerMask) == 0) {
uintptr_t data_ptr = reinterpret_cast<uintptr_t>(data);
int data_value = static_cast<int>(data_ptr >> kAlignedPointerShift);
intptr_t data_value =
static_cast<intptr_t>(data_ptr >> kAlignedPointerShift);
STATIC_ASSERT(sizeof(data_ptr) == sizeof(data_value));
i::Handle<i::Object> obj(i::Smi::FromInt(data_value));
return Utils::ToLocal(obj);
if (i::Smi::IsIntptrValid(data_value)) {
i::Handle<i::Object> obj(i::Smi::FromIntptr(data_value));
return Utils::ToLocal(obj);
}
}
return ExternalNewImpl(data);
}
......@@ -2694,7 +2697,8 @@ void* v8::External::Unwrap(v8::Handle<v8::Value> value) {
i::Handle<i::Object> obj = Utils::OpenHandle(*value);
if (obj->IsSmi()) {
// The external value was an aligned pointer.
uintptr_t result = i::Smi::cast(*obj)->value() << kAlignedPointerShift;
uintptr_t result = static_cast<uintptr_t>(
i::Smi::cast(*obj)->value()) << kAlignedPointerShift;
return reinterpret_cast<void*>(result);
}
return ExternalValueImpl(obj);
......
......@@ -688,6 +688,14 @@ int Smi::value() {
Smi* Smi::FromInt(int value) {
ASSERT(Smi::IsValid(value));
intptr_t tagged_value =
(static_cast<intptr_t>(value) << kSmiTagSize) | kSmiTag;
return reinterpret_cast<Smi*>(tagged_value);
}
Smi* Smi::FromIntptr(intptr_t value) {
ASSERT(Smi::IsValid(value));
return reinterpret_cast<Smi*>((value << kSmiTagSize) | kSmiTag);
}
......@@ -784,6 +792,18 @@ bool Smi::IsValid(int value) {
}
bool Smi::IsIntptrValid(intptr_t value) {
#ifdef DEBUG
bool in_range = (value >= kMinValue) && (value <= kMaxValue);
#endif
// See Smi::IsValid(int) for description.
bool result =
((static_cast<uintptr_t>(value) + 0x40000000U) < 0x80000000U);
ASSERT(result == in_range);
return result;
}
MapWord MapWord::FromMap(Map* map) {
return MapWord(reinterpret_cast<uintptr_t>(map));
}
......
......@@ -782,9 +782,13 @@ class Smi: public Object {
// Convert a value to a Smi object.
static inline Smi* FromInt(int value);
static inline Smi* FromIntptr(intptr_t value);
// Returns whether value can be represented in a Smi.
static inline bool IsValid(int value);
static inline bool IsIntptrValid(intptr_t);
// Casting.
static inline Smi* cast(Object* object);
......
......@@ -70,7 +70,7 @@ class ExternalReferenceEncoder {
private:
HashMap encodings_;
static uint32_t Hash(Address key) {
return reinterpret_cast<uint32_t>(key) >> 2;
return static_cast<uint32_t>(reinterpret_cast<uintptr_t>(key) >> 2);
}
int IndexOf(Address key) const;
......
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