Handlify ten allocator functions from the Heap.
R=mvstanton@chromium.org Review URL: https://codereview.chromium.org/227623002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20546 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
622ddd3495
commit
0a11d550c7
@ -9,11 +9,10 @@
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
Handle<Box> Factory::NewBox(Handle<Object> value, PretenureFlag pretenure) {
|
||||
CALL_HEAP_FUNCTION(
|
||||
isolate(),
|
||||
isolate()->heap()->AllocateBox(*value, pretenure),
|
||||
Box);
|
||||
Handle<Box> Factory::NewBox(Handle<Object> value) {
|
||||
Handle<Box> result = Handle<Box>::cast(NewStruct(BOX_TYPE));
|
||||
result->set_value(*value);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -1294,9 +1293,14 @@ Handle<JSObject> Factory::NewJSObjectWithMemento(
|
||||
|
||||
Handle<JSModule> Factory::NewJSModule(Handle<Context> context,
|
||||
Handle<ScopeInfo> scope_info) {
|
||||
CALL_HEAP_FUNCTION(
|
||||
isolate(),
|
||||
isolate()->heap()->AllocateJSModule(*context, *scope_info), JSModule);
|
||||
// Allocate a fresh map. Modules do not have a prototype.
|
||||
Handle<Map> map = NewMap(JS_MODULE_TYPE, JSModule::kSize);
|
||||
// Allocate the object based on the map.
|
||||
Handle<JSModule> module =
|
||||
Handle<JSModule>::cast(NewJSObjectFromMap(map, TENURED));
|
||||
module->set_context(*context);
|
||||
module->set_scope_info(*scope_info);
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
@ -1392,10 +1396,12 @@ Handle<JSObject> Factory::NewJSObjectFromMap(
|
||||
|
||||
Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
|
||||
PretenureFlag pretenure) {
|
||||
CALL_HEAP_FUNCTION(isolate(),
|
||||
isolate()->heap()->AllocateJSArray(elements_kind,
|
||||
pretenure),
|
||||
JSArray);
|
||||
Context* native_context = isolate()->context()->native_context();
|
||||
JSFunction* array_function = native_context->array_function();
|
||||
Map* map = array_function->initial_map();
|
||||
Map* transition_map = isolate()->get_initial_js_array_map(elements_kind);
|
||||
if (transition_map != NULL) map = transition_map;
|
||||
return Handle<JSArray>::cast(NewJSObjectFromMap(handle(map), pretenure));
|
||||
}
|
||||
|
||||
|
||||
@ -1404,14 +1410,9 @@ Handle<JSArray> Factory::NewJSArray(ElementsKind elements_kind,
|
||||
int capacity,
|
||||
ArrayStorageAllocationMode mode,
|
||||
PretenureFlag pretenure) {
|
||||
CALL_HEAP_FUNCTION(isolate(),
|
||||
isolate()->heap()->AllocateJSArrayAndStorage(
|
||||
elements_kind,
|
||||
length,
|
||||
capacity,
|
||||
mode,
|
||||
pretenure),
|
||||
JSArray);
|
||||
Handle<JSArray> array = NewJSArray(elements_kind, pretenure);
|
||||
NewJSArrayStorage(array, length, capacity, mode);
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,11 +14,6 @@ namespace internal {
|
||||
|
||||
class Factory V8_FINAL {
|
||||
public:
|
||||
// Allocate a new boxed value.
|
||||
Handle<Box> NewBox(
|
||||
Handle<Object> value,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
|
||||
// Allocates a fixed array initialized with undefined values.
|
||||
Handle<FixedArray> NewFixedArray(
|
||||
int size,
|
||||
@ -71,6 +66,9 @@ class Factory V8_FINAL {
|
||||
int deopt_entry_count,
|
||||
PretenureFlag pretenure);
|
||||
|
||||
// Create a new boxed value.
|
||||
Handle<Box> NewBox(Handle<Object> value);
|
||||
|
||||
// Create a pre-tenured empty AccessorPair.
|
||||
Handle<AccessorPair> NewAccessorPair();
|
||||
|
||||
@ -331,10 +329,13 @@ class Factory V8_FINAL {
|
||||
|
||||
// JS arrays are pretenured when allocated by the parser.
|
||||
|
||||
// Create a JSArray with no elements.
|
||||
Handle<JSArray> NewJSArray(
|
||||
ElementsKind elements_kind,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
|
||||
// Create a JSArray with a specified length and elements initialized
|
||||
// according to the specified mode.
|
||||
Handle<JSArray> NewJSArray(
|
||||
ElementsKind elements_kind,
|
||||
int length,
|
||||
@ -353,7 +354,7 @@ class Factory V8_FINAL {
|
||||
INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE, pretenure);
|
||||
}
|
||||
|
||||
// Allocate a JSArray with no elements
|
||||
// Create a JSArray with the given elements.
|
||||
Handle<JSArray> NewJSArrayWithElements(
|
||||
Handle<FixedArrayBase> elements,
|
||||
ElementsKind elements_kind,
|
||||
|
82
src/heap.cc
82
src/heap.cc
@ -3010,15 +3010,6 @@ MaybeObject* Heap::AllocatePropertyCell() {
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateBox(Object* value, PretenureFlag pretenure) {
|
||||
Box* result;
|
||||
MaybeObject* maybe_result = AllocateStruct(BOX_TYPE);
|
||||
if (!maybe_result->To(&result)) return maybe_result;
|
||||
result->set_value(value);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateAllocationSite() {
|
||||
AllocationSite* site;
|
||||
MaybeObject* maybe_result = Allocate(allocation_site_map(),
|
||||
@ -4545,67 +4536,6 @@ MaybeObject* Heap::AllocateJSObject(JSFunction* constructor,
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) {
|
||||
// Allocate a fresh map. Modules do not have a prototype.
|
||||
Map* map;
|
||||
MaybeObject* maybe_map = AllocateMap(JS_MODULE_TYPE, JSModule::kSize);
|
||||
if (!maybe_map->To(&map)) return maybe_map;
|
||||
// Allocate the object based on the map.
|
||||
JSModule* module;
|
||||
MaybeObject* maybe_module = AllocateJSObjectFromMap(map, TENURED);
|
||||
if (!maybe_module->To(&module)) return maybe_module;
|
||||
module->set_context(context);
|
||||
module->set_scope_info(scope_info);
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateJSArrayAndStorage(
|
||||
ElementsKind elements_kind,
|
||||
int length,
|
||||
int capacity,
|
||||
ArrayStorageAllocationMode mode,
|
||||
PretenureFlag pretenure) {
|
||||
MaybeObject* maybe_array = AllocateJSArray(elements_kind, pretenure);
|
||||
JSArray* array;
|
||||
if (!maybe_array->To(&array)) return maybe_array;
|
||||
|
||||
// TODO(mvstanton): this body of code is duplicate with AllocateJSArrayStorage
|
||||
// for performance reasons.
|
||||
ASSERT(capacity >= length);
|
||||
|
||||
if (capacity == 0) {
|
||||
array->set_length(Smi::FromInt(0));
|
||||
array->set_elements(empty_fixed_array());
|
||||
return array;
|
||||
}
|
||||
|
||||
FixedArrayBase* elms;
|
||||
MaybeObject* maybe_elms = NULL;
|
||||
if (IsFastDoubleElementsKind(elements_kind)) {
|
||||
if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
|
||||
maybe_elms = AllocateUninitializedFixedDoubleArray(capacity);
|
||||
} else {
|
||||
ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
|
||||
maybe_elms = AllocateFixedDoubleArrayWithHoles(capacity);
|
||||
}
|
||||
} else {
|
||||
ASSERT(IsFastSmiOrObjectElementsKind(elements_kind));
|
||||
if (mode == DONT_INITIALIZE_ARRAY_ELEMENTS) {
|
||||
maybe_elms = AllocateUninitializedFixedArray(capacity);
|
||||
} else {
|
||||
ASSERT(mode == INITIALIZE_ARRAY_ELEMENTS_WITH_HOLE);
|
||||
maybe_elms = AllocateFixedArrayWithHoles(capacity);
|
||||
}
|
||||
}
|
||||
if (!maybe_elms->To(&elms)) return maybe_elms;
|
||||
|
||||
array->set_elements(elms);
|
||||
array->set_length(Smi::FromInt(length));
|
||||
return array;
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateJSArrayStorage(
|
||||
JSArray* array,
|
||||
int length,
|
||||
@ -5112,18 +5042,6 @@ MaybeObject* Heap::AllocateRawTwoByteString(int length,
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateJSArray(
|
||||
ElementsKind elements_kind,
|
||||
PretenureFlag pretenure) {
|
||||
Context* native_context = isolate()->context()->native_context();
|
||||
JSFunction* array_function = native_context->array_function();
|
||||
Map* map = array_function->initial_map();
|
||||
Map* transition_map = isolate()->get_initial_js_array_map(elements_kind);
|
||||
if (transition_map != NULL) map = transition_map;
|
||||
return AllocateJSObjectFromMap(map, pretenure);
|
||||
}
|
||||
|
||||
|
||||
MaybeObject* Heap::AllocateEmptyFixedArray() {
|
||||
int size = FixedArray::SizeFor(0);
|
||||
Object* result;
|
||||
|
36
src/heap.h
36
src/heap.h
@ -713,27 +713,6 @@ class Heap {
|
||||
PretenureFlag pretenure = NOT_TENURED,
|
||||
AllocationSite* allocation_site = NULL);
|
||||
|
||||
MUST_USE_RESULT MaybeObject* AllocateJSModule(Context* context,
|
||||
ScopeInfo* scope_info);
|
||||
|
||||
// Allocate a JSArray with no elements
|
||||
MUST_USE_RESULT MaybeObject* AllocateEmptyJSArray(
|
||||
ElementsKind elements_kind,
|
||||
PretenureFlag pretenure = NOT_TENURED) {
|
||||
return AllocateJSArrayAndStorage(elements_kind, 0, 0,
|
||||
DONT_INITIALIZE_ARRAY_ELEMENTS,
|
||||
pretenure);
|
||||
}
|
||||
|
||||
// Allocate a JSArray with a specified length but elements that are left
|
||||
// uninitialized.
|
||||
MUST_USE_RESULT MaybeObject* AllocateJSArrayAndStorage(
|
||||
ElementsKind elements_kind,
|
||||
int length,
|
||||
int capacity,
|
||||
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
|
||||
MUST_USE_RESULT MaybeObject* AllocateJSArrayStorage(
|
||||
JSArray* array,
|
||||
int length,
|
||||
@ -747,12 +726,6 @@ class Heap {
|
||||
MUST_USE_RESULT MaybeObject* CopyJSObject(JSObject* source,
|
||||
AllocationSite* site = NULL);
|
||||
|
||||
// Allocates a JS ArrayBuffer object.
|
||||
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
|
||||
// failed.
|
||||
// Please note this does not perform a garbage collection.
|
||||
MUST_USE_RESULT MaybeObject* AllocateJSArrayBuffer();
|
||||
|
||||
// Allocates a Harmony proxy or function proxy.
|
||||
// Returns Failure::RetryAfterGC(requested_bytes, space) if the allocation
|
||||
// failed.
|
||||
@ -2204,11 +2177,6 @@ class Heap {
|
||||
Object* to_number,
|
||||
byte kind);
|
||||
|
||||
// Allocate a JSArray with no elements
|
||||
MUST_USE_RESULT MaybeObject* AllocateJSArray(
|
||||
ElementsKind elements_kind,
|
||||
PretenureFlag pretenure = NOT_TENURED);
|
||||
|
||||
// Allocate empty fixed array.
|
||||
MUST_USE_RESULT MaybeObject* AllocateEmptyFixedArray();
|
||||
|
||||
@ -2232,10 +2200,6 @@ class Heap {
|
||||
// Allocate a tenured JS global property cell initialized with the hole.
|
||||
MUST_USE_RESULT MaybeObject* AllocatePropertyCell();
|
||||
|
||||
// Allocate Box.
|
||||
MUST_USE_RESULT MaybeObject* AllocateBox(Object* value,
|
||||
PretenureFlag pretenure);
|
||||
|
||||
// Performs a minor collection in new generation.
|
||||
void Scavenge();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user