Commit 6d250412 authored by yangguo@chromium.org's avatar yangguo@chromium.org

Clean up some uses of Failures and MaybeObjects.

R=mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20914 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2194f3f8
...@@ -73,10 +73,10 @@ static C* FindInstanceOf(Isolate* isolate, Object* obj) { ...@@ -73,10 +73,10 @@ static C* FindInstanceOf(Isolate* isolate, Object* obj) {
// Entry point that never should be called. // Entry point that never should be called.
MaybeObject* Accessors::IllegalSetter(Isolate* isolate, Object* Accessors::IllegalSetter(Isolate* isolate,
JSObject*, JSObject*,
Object*, Object*,
void*) { void*) {
UNREACHABLE(); UNREACHABLE();
return NULL; return NULL;
} }
...@@ -90,10 +90,10 @@ Object* Accessors::IllegalGetAccessor(Isolate* isolate, ...@@ -90,10 +90,10 @@ Object* Accessors::IllegalGetAccessor(Isolate* isolate,
} }
MaybeObject* Accessors::ReadOnlySetAccessor(Isolate* isolate, Object* Accessors::ReadOnlySetAccessor(Isolate* isolate,
JSObject*, JSObject*,
Object* value, Object* value,
void*) { void*) {
// According to ECMA-262, section 8.6.2.2, page 28, setting // According to ECMA-262, section 8.6.2.2, page 28, setting
// read-only properties must be silently ignored. // read-only properties must be silently ignored.
return value; return value;
...@@ -174,9 +174,9 @@ bool Accessors::IsJSObjectFieldAccessor<HeapType>(Handle<HeapType> type, ...@@ -174,9 +174,9 @@ bool Accessors::IsJSObjectFieldAccessor<HeapType>(Handle<HeapType> type,
// //
MaybeObject* Accessors::ArrayGetLength(Isolate* isolate, Object* Accessors::ArrayGetLength(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
// Traverse the prototype chain until we reach an array. // Traverse the prototype chain until we reach an array.
JSArray* holder = FindInstanceOf<JSArray>(isolate, object); JSArray* holder = FindInstanceOf<JSArray>(isolate, object);
return holder == NULL ? Smi::FromInt(0) : holder->length(); return holder == NULL ? Smi::FromInt(0) : holder->length();
...@@ -199,10 +199,10 @@ Handle<Object> Accessors::FlattenNumber(Isolate* isolate, ...@@ -199,10 +199,10 @@ Handle<Object> Accessors::FlattenNumber(Isolate* isolate,
} }
MaybeObject* Accessors::ArraySetLength(Isolate* isolate, Object* Accessors::ArraySetLength(Isolate* isolate,
JSObject* object_raw, JSObject* object_raw,
Object* value_raw, Object* value_raw,
void*) { void*) {
HandleScope scope(isolate); HandleScope scope(isolate);
Handle<JSObject> object(object_raw, isolate); Handle<JSObject> object(object_raw, isolate);
Handle<Object> value(value_raw, isolate); Handle<Object> value(value_raw, isolate);
...@@ -851,18 +851,18 @@ Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function, ...@@ -851,18 +851,18 @@ Handle<Object> Accessors::FunctionSetPrototype(Handle<JSFunction> function,
} }
MaybeObject* Accessors::FunctionGetPrototype(Isolate* isolate, Object* Accessors::FunctionGetPrototype(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
HandleScope scope(isolate); HandleScope scope(isolate);
return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate)); return *GetFunctionPrototype(isolate, Handle<Object>(object, isolate));
} }
MaybeObject* Accessors::FunctionSetPrototype(Isolate* isolate, Object* Accessors::FunctionSetPrototype(Isolate* isolate,
JSObject* object, JSObject* object,
Object* value, Object* value,
void*) { void*) {
Handle<Object> result; Handle<Object> result;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, result, isolate, result,
...@@ -885,9 +885,9 @@ const AccessorDescriptor Accessors::FunctionPrototype = { ...@@ -885,9 +885,9 @@ const AccessorDescriptor Accessors::FunctionPrototype = {
// //
MaybeObject* Accessors::FunctionGetLength(Isolate* isolate, Object* Accessors::FunctionGetLength(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
JSFunction* function = FindInstanceOf<JSFunction>(isolate, object); JSFunction* function = FindInstanceOf<JSFunction>(isolate, object);
if (function == NULL) return Smi::FromInt(0); if (function == NULL) return Smi::FromInt(0);
// Check if already compiled. // Check if already compiled.
...@@ -917,9 +917,9 @@ const AccessorDescriptor Accessors::FunctionLength = { ...@@ -917,9 +917,9 @@ const AccessorDescriptor Accessors::FunctionLength = {
// //
MaybeObject* Accessors::FunctionGetName(Isolate* isolate, Object* Accessors::FunctionGetName(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
return holder == NULL return holder == NULL
? isolate->heap()->undefined_value() ? isolate->heap()->undefined_value()
...@@ -948,7 +948,7 @@ Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) { ...@@ -948,7 +948,7 @@ Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
} }
static MaybeObject* ConstructArgumentsObjectForInlinedFunction( static Object* ConstructArgumentsObjectForInlinedFunction(
JavaScriptFrame* frame, JavaScriptFrame* frame,
Handle<JSFunction> inlined_function, Handle<JSFunction> inlined_function,
int inlined_frame_index) { int inlined_frame_index) {
...@@ -976,9 +976,9 @@ static MaybeObject* ConstructArgumentsObjectForInlinedFunction( ...@@ -976,9 +976,9 @@ static MaybeObject* ConstructArgumentsObjectForInlinedFunction(
} }
MaybeObject* Accessors::FunctionGetArguments(Isolate* isolate, Object* Accessors::FunctionGetArguments(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
HandleScope scope(isolate); HandleScope scope(isolate);
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
if (holder == NULL) return isolate->heap()->undefined_value(); if (holder == NULL) return isolate->heap()->undefined_value();
...@@ -1100,9 +1100,9 @@ class FrameFunctionIterator { ...@@ -1100,9 +1100,9 @@ class FrameFunctionIterator {
}; };
MaybeObject* Accessors::FunctionGetCaller(Isolate* isolate, Object* Accessors::FunctionGetCaller(Isolate* isolate,
Object* object, Object* object,
void*) { void*) {
HandleScope scope(isolate); HandleScope scope(isolate);
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object); JSFunction* holder = FindInstanceOf<JSFunction>(isolate, object);
......
...@@ -115,40 +115,40 @@ class Accessors : public AllStatic { ...@@ -115,40 +115,40 @@ class Accessors : public AllStatic {
private: private:
// Accessor functions only used through the descriptor. // Accessor functions only used through the descriptor.
static MaybeObject* FunctionSetPrototype(Isolate* isolate, static Object* FunctionSetPrototype(Isolate* isolate,
JSObject* object, JSObject* object,
Object*, Object*,
void*); void*);
static MaybeObject* FunctionGetPrototype(Isolate* isolate, static Object* FunctionGetPrototype(Isolate* isolate,
Object* object, Object* object,
void*); void*);
static MaybeObject* FunctionGetLength(Isolate* isolate, static Object* FunctionGetLength(Isolate* isolate,
Object* object, Object* object,
void*); void*);
static MaybeObject* FunctionGetName(Isolate* isolate, Object* object, void*); static Object* FunctionGetName(Isolate* isolate, Object* object, void*);
static MaybeObject* FunctionGetArguments(Isolate* isolate, static Object* FunctionGetArguments(Isolate* isolate,
Object* object, Object* object,
void*); void*);
static MaybeObject* FunctionGetCaller(Isolate* isolate, static Object* FunctionGetCaller(Isolate* isolate,
Object* object, Object* object,
void*); void*);
static MaybeObject* ArraySetLength(Isolate* isolate, static Object* ArraySetLength(Isolate* isolate,
JSObject* object, JSObject* object,
Object*, Object*,
void*); void*);
static MaybeObject* ArrayGetLength(Isolate* isolate, Object* object, void*); static Object* ArrayGetLength(Isolate* isolate, Object* object, void*);
// Helper functions. // Helper functions.
static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value); static Handle<Object> FlattenNumber(Isolate* isolate, Handle<Object> value);
static MaybeObject* IllegalSetter(Isolate* isolate, static Object* IllegalSetter(Isolate* isolate,
JSObject*, JSObject*,
Object*, Object*,
void*); void*);
static Object* IllegalGetAccessor(Isolate* isolate, Object* object, void*); static Object* IllegalGetAccessor(Isolate* isolate, Object* object, void*);
static MaybeObject* ReadOnlySetAccessor(Isolate* isolate, static Object* ReadOnlySetAccessor(Isolate* isolate,
JSObject*, JSObject*,
Object* value, Object* value,
void*); void*);
}; };
} } // namespace v8::internal } } // namespace v8::internal
......
...@@ -114,7 +114,7 @@ MUST_USE_RESULT static MaybeHandle<Object> Invoke( ...@@ -114,7 +114,7 @@ MUST_USE_RESULT static MaybeHandle<Object> Invoke(
isolate->clear_pending_message(); isolate->clear_pending_message();
} }
return Handle<Object>(value->ToObjectUnchecked(), isolate); return Handle<Object>(value, isolate);
} }
......
...@@ -4531,7 +4531,7 @@ STRUCT_LIST(MAKE_CASE) ...@@ -4531,7 +4531,7 @@ STRUCT_LIST(MAKE_CASE)
#undef MAKE_CASE #undef MAKE_CASE
default: default:
UNREACHABLE(); UNREACHABLE();
return Failure::InternalError(); return exception();
} }
int size = map->instance_size(); int size = map->instance_size();
AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED); AllocationSpace space = SelectSpace(size, OLD_POINTER_SPACE, TENURED);
......
...@@ -1012,13 +1012,6 @@ class MacroAssembler: public Assembler { ...@@ -1012,13 +1012,6 @@ class MacroAssembler: public Assembler {
Register scratch, Register scratch,
AllocationFlags flags); AllocationFlags flags);
// Helper for PopHandleScope. Allowed to perform a GC and returns
// NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
// possibly returns a failure object indicating an allocation failure.
MUST_USE_RESULT MaybeObject* PopHandleScopeHelper(Register saved,
Register scratch,
bool gc_allowed);
// Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
void InNewSpace(Register object, void InNewSpace(Register object,
Register scratch, Register scratch,
......
...@@ -661,11 +661,6 @@ bool MaybeObject::IsRetryAfterGC() { ...@@ -661,11 +661,6 @@ bool MaybeObject::IsRetryAfterGC() {
} }
bool MaybeObject::IsException() {
return this == Failure::Exception();
}
Failure* Failure::cast(MaybeObject* obj) { Failure* Failure::cast(MaybeObject* obj) {
ASSERT(HAS_FAILURE_TAG(obj)); ASSERT(HAS_FAILURE_TAG(obj));
return reinterpret_cast<Failure*>(obj); return reinterpret_cast<Failure*>(obj);
...@@ -1297,16 +1292,6 @@ AllocationSpace Failure::allocation_space() const { ...@@ -1297,16 +1292,6 @@ AllocationSpace Failure::allocation_space() const {
} }
Failure* Failure::InternalError() {
return Construct(INTERNAL_ERROR);
}
Failure* Failure::Exception() {
return Construct(EXCEPTION);
}
intptr_t Failure::value() const { intptr_t Failure::value() const {
return static_cast<intptr_t>( return static_cast<intptr_t>(
reinterpret_cast<uintptr_t>(this) >> kFailureTagSize); reinterpret_cast<uintptr_t>(this) >> kFailureTagSize);
......
...@@ -929,7 +929,6 @@ class MaybeObject BASE_EMBEDDED { ...@@ -929,7 +929,6 @@ class MaybeObject BASE_EMBEDDED {
public: public:
inline bool IsFailure(); inline bool IsFailure();
inline bool IsRetryAfterGC(); inline bool IsRetryAfterGC();
inline bool IsException();
inline bool ToObject(Object** obj) { inline bool ToObject(Object** obj) {
if (IsFailure()) return false; if (IsFailure()) return false;
*obj = reinterpret_cast<Object*>(this); *obj = reinterpret_cast<Object*>(this);
...@@ -1665,9 +1664,8 @@ class Smi: public Object { ...@@ -1665,9 +1664,8 @@ class Smi: public Object {
}; };
// Failure is used for reporting out of memory situations and // Failure is mainly used for reporting a situation requiring a GC.
// propagating exceptions through the runtime system. Failure objects // Failure objects are transient and cannot occur as part of the object graph.
// are transient and cannot occur as part of the object graph.
// //
// Failures are a single word, encoded as follows: // Failures are a single word, encoded as follows:
// +-------------------------+---+--+--+ // +-------------------------+---+--+--+
...@@ -1679,9 +1677,6 @@ class Smi: public Object { ...@@ -1679,9 +1677,6 @@ class Smi: public Object {
// The low two bits, 0-1, are the failure tag, 11. The next two bits, // The low two bits, 0-1, are the failure tag, 11. The next two bits,
// 2-3, are a failure type tag 'tt' with possible values: // 2-3, are a failure type tag 'tt' with possible values:
// 00 RETRY_AFTER_GC // 00 RETRY_AFTER_GC
// 01 EXCEPTION
// 10 INTERNAL_ERROR
// 11 OUT_OF_MEMORY_EXCEPTION
// //
// The next three bits, 4-6, are an allocation space tag 'sss'. The // The next three bits, 4-6, are an allocation space tag 'sss'. The
// allocation space tag is 000 for all failure types except // allocation space tag is 000 for all failure types except
...@@ -1694,13 +1689,8 @@ const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1; ...@@ -1694,13 +1689,8 @@ const int kFailureTypeTagMask = (1 << kFailureTypeTagSize) - 1;
class Failure: public MaybeObject { class Failure: public MaybeObject {
public: public:
// RuntimeStubs assumes EXCEPTION = 1 in the compiler-generated code.
enum Type { enum Type {
RETRY_AFTER_GC = 0, RETRY_AFTER_GC = 0
EXCEPTION = 1, // Returning this marker tells the real exception
// is in Isolate::pending_exception.
INTERNAL_ERROR = 2,
OUT_OF_MEMORY_EXCEPTION = 3
}; };
inline Type type() const; inline Type type() const;
...@@ -1710,8 +1700,6 @@ class Failure: public MaybeObject { ...@@ -1710,8 +1700,6 @@ class Failure: public MaybeObject {
static inline Failure* RetryAfterGC(AllocationSpace space); static inline Failure* RetryAfterGC(AllocationSpace space);
static inline Failure* RetryAfterGC(); // NEW_SPACE static inline Failure* RetryAfterGC(); // NEW_SPACE
static inline Failure* Exception();
static inline Failure* InternalError();
// Casting. // Casting.
static inline Failure* cast(MaybeObject* object); static inline Failure* cast(MaybeObject* object);
......
...@@ -1005,11 +1005,11 @@ size_t PagedSpace::CommittedPhysicalMemory() { ...@@ -1005,11 +1005,11 @@ size_t PagedSpace::CommittedPhysicalMemory() {
} }
MaybeObject* PagedSpace::FindObject(Address addr) { Object* PagedSpace::FindObject(Address addr) {
// Note: this function can only be called on precisely swept spaces. // Note: this function can only be called on precisely swept spaces.
ASSERT(!heap()->mark_compact_collector()->in_use()); ASSERT(!heap()->mark_compact_collector()->in_use());
if (!Contains(addr)) return Failure::Exception(); if (!Contains(addr)) return Smi::FromInt(0); // Signaling not found.
Page* p = Page::FromAddress(addr); Page* p = Page::FromAddress(addr);
HeapObjectIterator it(p, NULL); HeapObjectIterator it(p, NULL);
...@@ -1020,7 +1020,7 @@ MaybeObject* PagedSpace::FindObject(Address addr) { ...@@ -1020,7 +1020,7 @@ MaybeObject* PagedSpace::FindObject(Address addr) {
} }
UNREACHABLE(); UNREACHABLE();
return Failure::Exception(); return Smi::FromInt(0);
} }
...@@ -3015,12 +3015,12 @@ size_t LargeObjectSpace::CommittedPhysicalMemory() { ...@@ -3015,12 +3015,12 @@ size_t LargeObjectSpace::CommittedPhysicalMemory() {
// GC support // GC support
MaybeObject* LargeObjectSpace::FindObject(Address a) { Object* LargeObjectSpace::FindObject(Address a) {
LargePage* page = FindPage(a); LargePage* page = FindPage(a);
if (page != NULL) { if (page != NULL) {
return page->GetObject(); return page->GetObject();
} }
return Failure::Exception(); return Smi::FromInt(0); // Signaling not found.
} }
...@@ -3101,7 +3101,7 @@ bool LargeObjectSpace::Contains(HeapObject* object) { ...@@ -3101,7 +3101,7 @@ bool LargeObjectSpace::Contains(HeapObject* object) {
bool owned = (chunk->owner() == this); bool owned = (chunk->owner() == this);
SLOW_ASSERT(!owned || !FindObject(address)->IsFailure()); SLOW_ASSERT(!owned || FindObject(address)->IsHeapObject());
return owned; return owned;
} }
......
...@@ -1722,10 +1722,10 @@ class PagedSpace : public Space { ...@@ -1722,10 +1722,10 @@ class PagedSpace : public Space {
bool Contains(HeapObject* o) { return Contains(o->address()); } bool Contains(HeapObject* o) { return Contains(o->address()); }
// Given an address occupied by a live object, return that object if it is // Given an address occupied by a live object, return that object if it is
// in this space, or Failure::Exception() if it is not. The implementation // in this space, or a Smi if it is not. The implementation iterates over
// iterates over objects in the page containing the address, the cost is // objects in the page containing the address, the cost is linear in the
// linear in the number of objects in the page. It may be slow. // number of objects in the page. It may be slow.
MUST_USE_RESULT MaybeObject* FindObject(Address addr); Object* FindObject(Address addr);
// During boot the free_space_map is created, and afterwards we may need // During boot the free_space_map is created, and afterwards we may need
// to write it into the free list nodes that were already created. // to write it into the free list nodes that were already created.
...@@ -2841,10 +2841,9 @@ class LargeObjectSpace : public Space { ...@@ -2841,10 +2841,9 @@ class LargeObjectSpace : public Space {
return page_count_; return page_count_;
} }
// Finds an object for a given address, returns Failure::Exception() // Finds an object for a given address, returns a Smi if it is not found.
// if it is not found. The function iterates through all objects in this // The function iterates through all objects in this space, may be slow.
// space, may be slow. Object* FindObject(Address a);
MaybeObject* FindObject(Address a);
// Finds a large object page containing the given address, returns NULL // Finds a large object page containing the given address, returns NULL
// if such a page doesn't exist. // if such a page doesn't exist.
...@@ -2872,7 +2871,7 @@ class LargeObjectSpace : public Space { ...@@ -2872,7 +2871,7 @@ class LargeObjectSpace : public Space {
#endif #endif
// Checks whether an address is in the object area in this space. It // Checks whether an address is in the object area in this space. It
// iterates all objects in the space. May be slow. // iterates all objects in the space. May be slow.
bool SlowContains(Address addr) { return !FindObject(addr)->IsFailure(); } bool SlowContains(Address addr) { return FindObject(addr)->IsHeapObject(); }
private: private:
intptr_t max_capacity_; intptr_t max_capacity_;
......
...@@ -432,7 +432,6 @@ class StubCompiler BASE_EMBEDDED { ...@@ -432,7 +432,6 @@ class StubCompiler BASE_EMBEDDED {
Isolate* isolate_; Isolate* isolate_;
const ExtraICState extra_ic_state_; const ExtraICState extra_ic_state_;
MacroAssembler masm_; MacroAssembler masm_;
Failure* failure_;
}; };
......
...@@ -349,8 +349,8 @@ union IeeeDoubleBigEndianArchType { ...@@ -349,8 +349,8 @@ union IeeeDoubleBigEndianArchType {
// AccessorCallback // AccessorCallback
struct AccessorDescriptor { struct AccessorDescriptor {
MaybeObject* (*getter)(Isolate* isolate, Object* object, void* data); Object* (*getter)(Isolate* isolate, Object* object, void* data);
MaybeObject* (*setter)( Object* (*setter)(
Isolate* isolate, JSObject* object, Object* value, void* data); Isolate* isolate, JSObject* object, Object* value, void* data);
void* data; void* data;
}; };
......
...@@ -1506,13 +1506,6 @@ class MacroAssembler: public Assembler { ...@@ -1506,13 +1506,6 @@ class MacroAssembler: public Assembler {
Register scratch, Register scratch,
AllocationFlags flags); AllocationFlags flags);
// Helper for PopHandleScope. Allowed to perform a GC and returns
// NULL if gc_allowed. Does not perform a GC if !gc_allowed, and
// possibly returns a failure object indicating an allocation failure.
Object* PopHandleScopeHelper(Register saved,
Register scratch,
bool gc_allowed);
// Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace. // Helper for implementing JumpIfNotInNewSpace and JumpIfInNewSpace.
void InNewSpace(Register object, void InNewSpace(Register object,
Register scratch, Register scratch,
......
...@@ -104,8 +104,8 @@ TEST(StressHandles) { ...@@ -104,8 +104,8 @@ TEST(StressHandles) {
} }
static MaybeObject* TestAccessorGet(Isolate* isolate, Object* object, void*) { static Object* TestAccessorGet(Isolate* isolate, Object* object, void*) {
return AllocateAfterFailures(); return *Test();
} }
......
...@@ -240,7 +240,6 @@ TEST(Tagging) { ...@@ -240,7 +240,6 @@ TEST(Tagging) {
Failure::RetryAfterGC(NEW_SPACE)->allocation_space()); Failure::RetryAfterGC(NEW_SPACE)->allocation_space());
CHECK_EQ(OLD_POINTER_SPACE, CHECK_EQ(OLD_POINTER_SPACE,
Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space()); Failure::RetryAfterGC(OLD_POINTER_SPACE)->allocation_space());
CHECK(Failure::Exception()->IsFailure());
CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi()); CHECK(Smi::FromInt(Smi::kMinValue)->IsSmi());
CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi()); CHECK(Smi::FromInt(Smi::kMaxValue)->IsSmi());
} }
......
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