Handlify six allocator functions from the Heap.

R=yangguo@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20533 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c9b0492b
...@@ -178,16 +178,21 @@ Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData( ...@@ -178,16 +178,21 @@ Handle<DeoptimizationOutputData> Factory::NewDeoptimizationOutputData(
Handle<AccessorPair> Factory::NewAccessorPair() { Handle<AccessorPair> Factory::NewAccessorPair() {
CALL_HEAP_FUNCTION(isolate(), Handle<AccessorPair> accessors =
isolate()->heap()->AllocateAccessorPair(), Handle<AccessorPair>::cast(NewStruct(ACCESSOR_PAIR_TYPE));
AccessorPair); accessors->set_getter(*the_hole_value(), SKIP_WRITE_BARRIER);
accessors->set_setter(*the_hole_value(), SKIP_WRITE_BARRIER);
accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER);
return accessors;
} }
Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() { Handle<TypeFeedbackInfo> Factory::NewTypeFeedbackInfo() {
CALL_HEAP_FUNCTION(isolate(), Handle<TypeFeedbackInfo> info =
isolate()->heap()->AllocateTypeFeedbackInfo(), Handle<TypeFeedbackInfo>::cast(NewStruct(TYPE_FEEDBACK_INFO_TYPE));
TypeFeedbackInfo); info->initialize_storage();
info->set_feedback_vector(*empty_fixed_array(), SKIP_WRITE_BARRIER);
return info;
} }
...@@ -568,10 +573,12 @@ Handle<Symbol> Factory::NewPrivateSymbol() { ...@@ -568,10 +573,12 @@ Handle<Symbol> Factory::NewPrivateSymbol() {
Handle<Context> Factory::NewNativeContext() { Handle<Context> Factory::NewNativeContext() {
CALL_HEAP_FUNCTION( Handle<FixedArray> array = NewFixedArray(Context::NATIVE_CONTEXT_SLOTS);
isolate(), array->set_map_no_write_barrier(*native_context_map());
isolate()->heap()->AllocateNativeContext(), Handle<Context> context = Handle<Context>::cast(array);
Context); context->set_js_array_maps(*undefined_value());
ASSERT(context->IsNativeContext());
return context;
} }
...@@ -585,10 +592,13 @@ Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function, ...@@ -585,10 +592,13 @@ Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function,
Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) { Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) {
CALL_HEAP_FUNCTION( Handle<FixedArray> array =
isolate(), NewFixedArray(scope_info->ContextLength(), TENURED);
isolate()->heap()->AllocateModuleContext(*scope_info), array->set_map_no_write_barrier(*module_context_map());
Context); // Instance link will be set later.
Handle<Context> context = Handle<Context>::cast(array);
context->set_extension(Smi::FromInt(0));
return context;
} }
...@@ -1219,17 +1229,18 @@ Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, ...@@ -1219,17 +1229,18 @@ Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name,
Handle<ScopeInfo> Factory::NewScopeInfo(int length) { Handle<ScopeInfo> Factory::NewScopeInfo(int length) {
CALL_HEAP_FUNCTION( Handle<FixedArray> array = NewFixedArray(length, TENURED);
isolate(), array->set_map_no_write_barrier(*scope_info_map());
isolate()->heap()->AllocateScopeInfo(length), Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(array);
ScopeInfo); return scope_info;
} }
Handle<JSObject> Factory::NewExternal(void* value) { Handle<JSObject> Factory::NewExternal(void* value) {
CALL_HEAP_FUNCTION(isolate(), Handle<Foreign> foreign = NewForeign(static_cast<Address>(value));
isolate()->heap()->AllocateExternal(value), Handle<JSObject> external = NewJSObjectFromMap(external_map());
JSObject); external->SetInternalField(0, *foreign);
return external;
} }
......
...@@ -70,9 +70,11 @@ class Factory V8_FINAL { ...@@ -70,9 +70,11 @@ class Factory V8_FINAL {
Handle<DeoptimizationOutputData> NewDeoptimizationOutputData( Handle<DeoptimizationOutputData> NewDeoptimizationOutputData(
int deopt_entry_count, int deopt_entry_count,
PretenureFlag pretenure); PretenureFlag pretenure);
// Allocates a pre-tenured empty AccessorPair.
// Create a pre-tenured empty AccessorPair.
Handle<AccessorPair> NewAccessorPair(); Handle<AccessorPair> NewAccessorPair();
// Create an empty TypeFeedbackInfo.
Handle<TypeFeedbackInfo> NewTypeFeedbackInfo(); Handle<TypeFeedbackInfo> NewTypeFeedbackInfo();
Handle<String> InternalizeUtf8String(Vector<const char> str); Handle<String> InternalizeUtf8String(Vector<const char> str);
...@@ -405,8 +407,10 @@ class Factory V8_FINAL { ...@@ -405,8 +407,10 @@ class Factory V8_FINAL {
Handle<Context> context, Handle<Context> context,
PretenureFlag pretenure = TENURED); PretenureFlag pretenure = TENURED);
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length); Handle<ScopeInfo> NewScopeInfo(int length);
// Create an External object for V8's external API.
Handle<JSObject> NewExternal(void* value); Handle<JSObject> NewExternal(void* value);
Handle<Code> NewCode(const CodeDesc& desc, Handle<Code> NewCode(const CodeDesc& desc,
......
...@@ -2690,29 +2690,6 @@ MaybeObject* Heap::AllocatePolymorphicCodeCache() { ...@@ -2690,29 +2690,6 @@ MaybeObject* Heap::AllocatePolymorphicCodeCache() {
} }
MaybeObject* Heap::AllocateAccessorPair() {
AccessorPair* accessors;
{ MaybeObject* maybe_accessors = AllocateStruct(ACCESSOR_PAIR_TYPE);
if (!maybe_accessors->To(&accessors)) return maybe_accessors;
}
accessors->set_getter(the_hole_value(), SKIP_WRITE_BARRIER);
accessors->set_setter(the_hole_value(), SKIP_WRITE_BARRIER);
accessors->set_access_flags(Smi::FromInt(0), SKIP_WRITE_BARRIER);
return accessors;
}
MaybeObject* Heap::AllocateTypeFeedbackInfo() {
TypeFeedbackInfo* info;
{ MaybeObject* maybe_info = AllocateStruct(TYPE_FEEDBACK_INFO_TYPE);
if (!maybe_info->To(&info)) return maybe_info;
}
info->initialize_storage();
info->set_feedback_vector(empty_fixed_array(), SKIP_WRITE_BARRIER);
return info;
}
MaybeObject* Heap::AllocateAliasedArgumentsEntry(int aliased_context_slot) { MaybeObject* Heap::AllocateAliasedArgumentsEntry(int aliased_context_slot) {
AliasedArgumentsEntry* entry; AliasedArgumentsEntry* entry;
{ MaybeObject* maybe_entry = AllocateStruct(ALIASED_ARGUMENTS_ENTRY_TYPE); { MaybeObject* maybe_entry = AllocateStruct(ALIASED_ARGUMENTS_ENTRY_TYPE);
...@@ -5509,21 +5486,6 @@ MaybeObject* Heap::AllocatePrivateSymbol() { ...@@ -5509,21 +5486,6 @@ MaybeObject* Heap::AllocatePrivateSymbol() {
} }
MaybeObject* Heap::AllocateNativeContext() {
Object* result;
{ MaybeObject* maybe_result =
AllocateFixedArray(Context::NATIVE_CONTEXT_SLOTS);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
Context* context = reinterpret_cast<Context*>(result);
context->set_map_no_write_barrier(native_context_map());
context->set_js_array_maps(undefined_value());
ASSERT(context->IsNativeContext());
ASSERT(result->IsContext());
return result;
}
MaybeObject* Heap::AllocateGlobalContext(JSFunction* function, MaybeObject* Heap::AllocateGlobalContext(JSFunction* function,
ScopeInfo* scope_info) { ScopeInfo* scope_info) {
Object* result; Object* result;
...@@ -5543,20 +5505,6 @@ MaybeObject* Heap::AllocateGlobalContext(JSFunction* function, ...@@ -5543,20 +5505,6 @@ MaybeObject* Heap::AllocateGlobalContext(JSFunction* function,
} }
MaybeObject* Heap::AllocateModuleContext(ScopeInfo* scope_info) {
Object* result;
{ MaybeObject* maybe_result =
AllocateFixedArray(scope_info->ContextLength(), TENURED);
if (!maybe_result->ToObject(&result)) return maybe_result;
}
Context* context = reinterpret_cast<Context*>(result);
context->set_map_no_write_barrier(module_context_map());
// Instance link will be set later.
context->set_extension(Smi::FromInt(0));
return context;
}
MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) { MaybeObject* Heap::AllocateFunctionContext(int length, JSFunction* function) {
ASSERT(length >= Context::MIN_CONTEXT_SLOTS); ASSERT(length >= Context::MIN_CONTEXT_SLOTS);
Object* result; Object* result;
...@@ -5629,29 +5577,6 @@ MaybeObject* Heap::AllocateBlockContext(JSFunction* function, ...@@ -5629,29 +5577,6 @@ MaybeObject* Heap::AllocateBlockContext(JSFunction* function,
} }
MaybeObject* Heap::AllocateScopeInfo(int length) {
FixedArray* scope_info;
MaybeObject* maybe_scope_info = AllocateFixedArray(length, TENURED);
if (!maybe_scope_info->To(&scope_info)) return maybe_scope_info;
scope_info->set_map_no_write_barrier(scope_info_map());
return scope_info;
}
MaybeObject* Heap::AllocateExternal(void* value) {
Foreign* foreign;
{ MaybeObject* maybe_result = AllocateForeign(static_cast<Address>(value));
if (!maybe_result->To(&foreign)) return maybe_result;
}
JSObject* external;
{ MaybeObject* maybe_result = AllocateJSObjectFromMap(external_map());
if (!maybe_result->To(&external)) return maybe_result;
}
external->SetInternalField(0, foreign);
return external;
}
MaybeObject* Heap::AllocateStruct(InstanceType type) { MaybeObject* Heap::AllocateStruct(InstanceType type) {
Map* map; Map* map;
switch (type) { switch (type) {
......
...@@ -816,21 +816,9 @@ class Heap { ...@@ -816,21 +816,9 @@ class Heap {
// Allocates an empty code cache. // Allocates an empty code cache.
MUST_USE_RESULT MaybeObject* AllocateCodeCache(); MUST_USE_RESULT MaybeObject* AllocateCodeCache();
// Allocates a serialized scope info.
MUST_USE_RESULT MaybeObject* AllocateScopeInfo(int length);
// Allocates an External object for v8's external API.
MUST_USE_RESULT MaybeObject* AllocateExternal(void* value);
// Allocates an empty PolymorphicCodeCache. // Allocates an empty PolymorphicCodeCache.
MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache(); MUST_USE_RESULT MaybeObject* AllocatePolymorphicCodeCache();
// Allocates a pre-tenured empty AccessorPair.
MUST_USE_RESULT MaybeObject* AllocateAccessorPair();
// Allocates an empty TypeFeedbackInfo.
MUST_USE_RESULT MaybeObject* AllocateTypeFeedbackInfo();
// Allocates an AliasedArgumentsEntry. // Allocates an AliasedArgumentsEntry.
MUST_USE_RESULT MaybeObject* AllocateAliasedArgumentsEntry(int slot); MUST_USE_RESULT MaybeObject* AllocateAliasedArgumentsEntry(int slot);
...@@ -1052,16 +1040,10 @@ class Heap { ...@@ -1052,16 +1040,10 @@ class Heap {
MUST_USE_RESULT MaybeObject* AllocateHashTable( MUST_USE_RESULT MaybeObject* AllocateHashTable(
int length, PretenureFlag pretenure = NOT_TENURED); int length, PretenureFlag pretenure = NOT_TENURED);
// Allocate a native (but otherwise uninitialized) context.
MUST_USE_RESULT MaybeObject* AllocateNativeContext();
// Allocate a global context. // Allocate a global context.
MUST_USE_RESULT MaybeObject* AllocateGlobalContext(JSFunction* function, MUST_USE_RESULT MaybeObject* AllocateGlobalContext(JSFunction* function,
ScopeInfo* scope_info); ScopeInfo* scope_info);
// Allocate a module context.
MUST_USE_RESULT MaybeObject* AllocateModuleContext(ScopeInfo* scope_info);
// Allocate a function context. // Allocate a function context.
MUST_USE_RESULT MaybeObject* AllocateFunctionContext(int length, MUST_USE_RESULT MaybeObject* AllocateFunctionContext(int length,
JSFunction* function); JSFunction* function);
......
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