[cleanup] Refactor the Factory

There is no good reason to have the meat of most objects' initialization
logic in heap.cc, all wrapped by the CALL_HEAP_FUNCTION macro. Instead,
this CL changes the protocol between Heap and Factory to be AllocateRaw,
and all object initialization work after (possibly retried) successful
raw allocation happens in the Factory.

This saves about 20KB of binary size on x64.

Cq-Include-Trybots: luci.v8.try:v8_linux_noi18n_rel_ng
Change-Id: Icbfdc4266d7be8b48d2fe085f03411743dc6a0ca
Reviewed-on: https://chromium-review.googlesource.com/959533
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Hannes Payer <hpayer@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52416}
This commit is contained in:
Jakob Kummerow 2018-04-05 16:37:55 -07:00 committed by Commit Bot
parent 54f2aac554
commit f9a2e24bbc
147 changed files with 1695 additions and 2651 deletions

View File

@ -1725,9 +1725,6 @@ v8_source_set("v8_base") {
"src/external-reference-table.h",
"src/external-reference.cc",
"src/external-reference.h",
"src/factory-inl.h",
"src/factory.cc",
"src/factory.h",
"src/fast-dtoa.cc",
"src/fast-dtoa.h",
"src/feedback-vector-inl.h",
@ -1771,6 +1768,9 @@ v8_source_set("v8_base") {
"src/heap/concurrent-marking.h",
"src/heap/embedder-tracing.cc",
"src/heap/embedder-tracing.h",
"src/heap/factory-inl.h",
"src/heap/factory.cc",
"src/heap/factory.h",
"src/heap/gc-idle-time-handler.cc",
"src/heap/gc-idle-time-handler.h",
"src/heap/gc-tracer.cc",

View File

@ -8,6 +8,8 @@ include_rules = [
"+src/compiler/code-assembler.h",
"+src/compiler/wasm-compiler.h",
"-src/heap",
"+src/heap/factory.h",
"+src/heap/factory-inl.h",
"+src/heap/heap.h",
"+src/heap/heap-inl.h",
"-src/inspector",

View File

@ -8,8 +8,8 @@
#include "src/contexts.h"
#include "src/deoptimizer.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/frames-inl.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/messages.h"
#include "src/property-details.h"

View File

@ -9,7 +9,7 @@
#include "src/contexts.h"
#include "src/debug/debug-interface.h"
#include "src/detachable-vector.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects/js-collection.h"

View File

@ -12,8 +12,8 @@
#include "src/base/platform/elapsed-timer.h"
#include "src/compiler.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/handles.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"

View File

@ -32,8 +32,8 @@
#include "src/base/hashmap.h"
#include "src/conversions.h"
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/utils.h"

View File

@ -11,8 +11,8 @@
#include "src/ast/modules.h"
#include "src/ast/variables.h"
#include "src/bailout-reason.h"
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/label.h"
#include "src/objects/literal-objects.h"

View File

@ -5,8 +5,8 @@
#include "src/ast/compile-time-value.h"
#include "src/ast/ast.h"
#include "src/factory.h"
#include "src/handles-inl.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -5,7 +5,7 @@
#ifndef V8_BOOTSTRAPPER_H_
#define V8_BOOTSTRAPPER_H_
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects/shared-function-info.h"
#include "src/snapshot/natives.h"
#include "src/visitors.h"

View File

@ -8,8 +8,8 @@
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h"
#include "src/factory-inl.h"
#include "src/frame-constants.h"
#include "src/heap/factory-inl.h"
#include "src/builtins/builtins-array-gen.h"

View File

@ -5,7 +5,7 @@
#include "src/builtins/builtins-async-gen.h"
#include "src/builtins/builtins-utils-gen.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/objects/shared-function-info.h"
namespace v8 {

View File

@ -6,7 +6,7 @@
#include "src/builtins/builtins-iterator-gen.h"
#include "src/builtins/builtins-utils-gen.h"
#include "src/code-stub-assembler.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/objects/hash-table.h"
namespace v8 {

View File

@ -6,7 +6,7 @@
#include "src/builtins/builtins.h"
#include "src/conversions.h"
#include "src/counters.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -4,7 +4,7 @@
#include "src/builtins/builtins-iterator-gen.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
namespace v8 {
namespace internal {

View File

@ -5,7 +5,7 @@
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/code-stub-assembler.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/objects/property-descriptor-object.h"
#include "src/objects/shared-function-info.h"

View File

@ -11,7 +11,7 @@
#include "src/code-factory.h"
#include "src/code-stub-assembler.h"
#include "src/counters.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/objects/js-regexp-string-iterator.h"
#include "src/objects/js-regexp.h"
#include "src/objects/regexp-match-info.h"

View File

@ -10,9 +10,9 @@
#include "src/code-factory.h"
#include "src/conversions-inl.h"
#include "src/counters.h"
#include "src/factory.h"
#include "src/futex-emulation.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
namespace v8 {

View File

@ -8,7 +8,7 @@
#include "src/builtins/builtins-utils-gen.h"
#include "src/builtins/builtins.h"
#include "src/code-factory.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/objects.h"
namespace v8 {

View File

@ -36,9 +36,7 @@ TNode<Map> TypedArrayBuiltinsAssembler::LoadMapForType(
DispatchTypedArrayByElementsKind(
elements_kind,
[&](ElementsKind kind, int size, int typed_array_fun_index) {
ExternalArrayType type =
isolate()->factory()->GetArrayTypeFromElementsKind(kind);
Handle<Map> map(isolate()->heap()->MapForFixedTypedArray(type));
Handle<Map> map(isolate()->heap()->MapForFixedTypedArray(kind));
var_typed_map = HeapConstant(map);
});

View File

@ -8,7 +8,7 @@
#include "src/arguments.h"
#include "src/base/logging.h"
#include "src/builtins/builtins.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
namespace v8 {

View File

@ -14,7 +14,6 @@
#include "src/code-stub-assembler.h"
#include "src/code-stubs-utils.h"
#include "src/counters.h"
#include "src/factory.h"
#include "src/gdb-jit.h"
#include "src/heap/heap-inl.h"
#include "src/ic/ic-stats.h"

View File

@ -7,8 +7,8 @@
#include "src/allocation.h"
#include "src/assembler.h"
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/interface-descriptors.h"
#include "src/macro-assembler.h"
#include "src/ostreams.h"

View File

@ -5,8 +5,8 @@
#include "src/compilation-cache.h"
#include "src/counters.h"
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
#include "src/objects/compilation-cache-inl.h"
#include "src/visitors.h"

View File

@ -4,8 +4,8 @@
#include "src/compilation-dependencies.h"
#include "src/factory.h"
#include "src/handles-inl.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/zone/zone.h"

View File

@ -13,7 +13,7 @@
#include "src/compiler/node-properties.h"
#include "src/compiler/node.h"
#include "src/compiler/schedule.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
namespace v8 {
namespace internal {

View File

@ -8,7 +8,7 @@
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties.h"
#include "src/compiler/simplified-operator.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
namespace v8 {

View File

@ -7,7 +7,7 @@
#include "src/compiler/common-operator.h"
#include "src/compiler/type-cache.h"
#include "src/compiler/types.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -7,7 +7,7 @@
#include "src/compiler/node-properties.h"
#include "src/compiler/pipeline.h"
#include "src/compiler/scheduler.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
namespace v8 {
namespace internal {

View File

@ -12,8 +12,8 @@
#include "src/compiler/machine-operator.h"
#include "src/compiler/node.h"
#include "src/compiler/operator.h"
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
namespace v8 {
namespace internal {

View File

@ -10,7 +10,7 @@
#include "src/code-factory.h"
#include "src/compiler/machine-operator.h"
#include "src/compiler/node-matchers.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
namespace v8 {
namespace internal {

View File

@ -30,7 +30,7 @@
#include "src/compiler/pipeline.h"
#include "src/compiler/simd-scalar-lowering.h"
#include "src/compiler/zone-stats.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/log-inl.h"
#include "src/trap-handler/trap-handler.h"

View File

@ -12,8 +12,8 @@
#include "src/assert-scope.h"
#include "src/char-predicates-inl.h"
#include "src/dtoa.h"
#include "src/factory.h"
#include "src/handles.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
#include "src/objects/bigint.h"
#include "src/strtod.h"

View File

@ -15,10 +15,10 @@
#include "src/debug/debug-interface.h"
#include "src/debug/interface-types.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/flags.h"
#include "src/frames.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/objects/debug-objects.h"
#include "src/runtime/runtime.h"
#include "src/source-position-table.h"

View File

@ -6,8 +6,8 @@
#include "src/arguments.h"
#include "src/conversions.h"
#include "src/factory.h"
#include "src/frames.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/messages.h"
#include "src/objects-inl.h"

View File

@ -5,11 +5,10 @@
#ifndef V8_FEEDBACK_VECTOR_INL_H_
#define V8_FEEDBACK_VECTOR_INL_H_
#include "src/factory-inl.h"
#include "src/feedback-vector.h"
#include "src/globals.h"
#include "src/heap/factory-inl.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
#include "src/objects/maybe-object-inl.h"
#include "src/objects/shared-function-info.h"

View File

@ -2,10 +2,10 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_FACTORY_INL_H_
#define V8_FACTORY_INL_H_
#ifndef V8_HEAP_FACTORY_INL_H_
#define V8_HEAP_FACTORY_INL_H_
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/handles-inl.h"
#include "src/objects-inl.h"
@ -153,4 +153,4 @@ Handle<String> Factory::Uint32ToString(uint32_t value) {
} // namespace internal
} // namespace v8
#endif // V8_FACTORY_INL_H_
#endif // V8_HEAP_FACTORY_INL_H_

File diff suppressed because it is too large Load Diff

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_FACTORY_H_
#define V8_FACTORY_H_
#ifndef V8_HEAP_FACTORY_H_
#define V8_HEAP_FACTORY_H_
#include "src/builtins/builtins.h"
#include "src/globals.h"
@ -102,6 +102,7 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<WeakFixedArray> NewWeakFixedArray(
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates a property array initialized with undefined values.
Handle<PropertyArray> NewPropertyArray(int length,
PretenureFlag pretenure = NOT_TENURED);
// Tries allocating a fixed array initialized with undefined values.
@ -134,17 +135,16 @@ class V8_EXPORT_PRIVATE Factory final {
bool has_seen_proto);
// Allocate a new uninitialized fixed double array.
// The function returns a pre-allocated empty fixed array for capacity = 0,
// The function returns a pre-allocated empty fixed array for length = 0,
// so the return type must be the general fixed array class.
Handle<FixedArrayBase> NewFixedDoubleArray(
int size,
PretenureFlag pretenure = NOT_TENURED);
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocate a new fixed double array with hole values.
Handle<FixedArrayBase> NewFixedDoubleArrayWithHoles(
int size,
PretenureFlag pretenure = NOT_TENURED);
int size, PretenureFlag pretenure = NOT_TENURED);
// Allocates a FeedbackMedata object and zeroes the data section.
Handle<FeedbackMetadata> NewFeedbackMetadata(int slot_count);
Handle<FrameArray> NewFrameArray(int number_of_frames,
@ -154,10 +154,10 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<OrderedHashMap> NewOrderedHashMap();
Handle<SmallOrderedHashSet> NewSmallOrderedHashSet(
int size = SmallOrderedHashSet::kMinCapacity,
int capacity = SmallOrderedHashSet::kMinCapacity,
PretenureFlag pretenure = NOT_TENURED);
Handle<SmallOrderedHashMap> NewSmallOrderedHashMap(
int size = SmallOrderedHashMap::kMinCapacity,
int capacity = SmallOrderedHashMap::kMinCapacity,
PretenureFlag pretenure = NOT_TENURED);
// Create a new PrototypeInfo struct.
@ -198,12 +198,12 @@ class V8_EXPORT_PRIVATE Factory final {
}
Handle<String> InternalizeOneByteString(Vector<const uint8_t> str);
Handle<String> InternalizeOneByteString(
Handle<SeqOneByteString>, int from, int length);
Handle<String> InternalizeOneByteString(Handle<SeqOneByteString>, int from,
int length);
Handle<String> InternalizeTwoByteString(Vector<const uc16> str);
template<class StringTableKey>
template <class StringTableKey>
Handle<String> InternalizeStringWithKey(StringTableKey* key);
// Internalized strings are created in the old generation (data space).
@ -243,10 +243,9 @@ class V8_EXPORT_PRIVATE Factory final {
}
inline Handle<String> NewStringFromAsciiChecked(
const char* str,
PretenureFlag pretenure = NOT_TENURED) {
return NewStringFromOneByte(
OneByteVector(str), pretenure).ToHandleChecked();
const char* str, PretenureFlag pretenure = NOT_TENURED) {
return NewStringFromOneByte(OneByteVector(str), pretenure)
.ToHandleChecked();
}
// UTF8 strings are pretenured when used for regexp literal patterns and
@ -298,11 +297,9 @@ class V8_EXPORT_PRIVATE Factory final {
// characters of the string are uninitialized. Currently used in regexp code
// only, where they are pretenured.
MUST_USE_RESULT MaybeHandle<SeqOneByteString> NewRawOneByteString(
int length,
PretenureFlag pretenure = NOT_TENURED);
int length, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT MaybeHandle<SeqTwoByteString> NewRawTwoByteString(
int length,
PretenureFlag pretenure = NOT_TENURED);
int length, PretenureFlag pretenure = NOT_TENURED);
// Creates a single character string where the character has given code.
// A cache is used for Latin1 codes.
@ -321,9 +318,7 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<String> NewSurrogatePairString(uint16_t lead, uint16_t trail);
// Create a new string object which holds a proper substring of a string.
Handle<String> NewProperSubString(Handle<String> str,
int begin,
int end);
Handle<String> NewProperSubString(Handle<String> str, int begin, int end);
// Create a new string object which holds a substring of a string.
inline Handle<String> NewSubString(Handle<String> str, int begin, int end);
@ -342,7 +337,7 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<ExternalOneByteString> NewNativeSourceString(
const ExternalOneByteString::Resource* resource);
// Create a symbol.
// Create a symbol in old space.
Handle<Symbol> NewSymbol();
Handle<Symbol> NewPrivateSymbol();
Handle<Symbol> NewPrivateFieldSymbol();
@ -433,8 +428,8 @@ class V8_EXPORT_PRIVATE Factory final {
PretenureFlag pretenure = NOT_TENURED);
Handle<FixedTypedArrayBase> NewFixedTypedArray(
int length, ExternalArrayType array_type, bool initialize,
PretenureFlag pretenure = NOT_TENURED);
size_t length, size_t byte_length, ExternalArrayType array_type,
bool initialize, PretenureFlag pretenure = NOT_TENURED);
Handle<Cell> NewCell(Handle<Object> value);
@ -448,21 +443,30 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<TransitionArray> NewTransitionArray(int capacity);
// Allocate a tenured AllocationSite. It's payload is null.
// Allocate a tenured AllocationSite. Its payload is null.
Handle<AllocationSite> NewAllocationSite();
// Allocates and initializes a new Map.
Handle<Map> NewMap(InstanceType type, int instance_size,
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
int inobject_properties = 0);
// Initializes the fields of a newly created Map. Exposed for tests and
// heap setup; other code should just call NewMap which takes care of it.
Map* InitializeMap(Map* map, InstanceType type, int instance_size,
ElementsKind elements_kind, int inobject_properties);
Handle<HeapObject> NewFillerObject(int size,
bool double_align,
// Allocate a block of memory in the given space (filled with a filler).
// Used as a fall-back for generated code when the space is full.
Handle<HeapObject> NewFillerObject(int size, bool double_align,
AllocationSpace space);
Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);
// Returns a deep copy of the JavaScript object.
// Properties and elements are copied too.
Handle<JSObject> CopyJSObject(Handle<JSObject> object);
// Same as above, but also takes an AllocationSite to be appended in an
// AllocationMemento.
Handle<JSObject> CopyJSObjectWithAllocationSite(Handle<JSObject> object,
Handle<AllocationSite> site);
@ -486,20 +490,18 @@ class V8_EXPORT_PRIVATE Factory final {
// of it in old space.
Handle<FixedArray> CopyAndTenureFixedCOWArray(Handle<FixedArray> array);
Handle<FixedDoubleArray> CopyFixedDoubleArray(
Handle<FixedDoubleArray> array);
Handle<FixedDoubleArray> CopyFixedDoubleArray(Handle<FixedDoubleArray> array);
Handle<FeedbackVector> CopyFeedbackVector(Handle<FeedbackVector> array);
// Numbers (e.g. literals) are pretenured by the parser.
// The return value may be a smi or a heap number.
Handle<Object> NewNumber(double value,
PretenureFlag pretenure = NOT_TENURED);
Handle<Object> NewNumber(double value, PretenureFlag pretenure = NOT_TENURED);
Handle<Object> NewNumberFromInt(int32_t value,
PretenureFlag pretenure = NOT_TENURED);
Handle<Object> NewNumberFromUint(uint32_t value,
PretenureFlag pretenure = NOT_TENURED);
PretenureFlag pretenure = NOT_TENURED);
inline Handle<Object> NewNumberFromSize(
size_t value, PretenureFlag pretenure = NOT_TENURED);
inline Handle<Object> NewNumberFromInt64(
@ -525,6 +527,8 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<JSObject> NewArgumentsObject(Handle<JSFunction> callee, int length);
// Allocates and initializes a new JavaScript object based on a
// constructor.
// JS objects are pretenured when allocated by the bootstrapper and
// runtime.
Handle<JSObject> NewJSObject(Handle<JSFunction> constructor,
@ -536,11 +540,13 @@ class V8_EXPORT_PRIVATE Factory final {
// Global objects are pretenured and initialized based on a constructor.
Handle<JSGlobalObject> NewJSGlobalObject(Handle<JSFunction> constructor);
// Allocates and initializes a new JavaScript object based on a map.
// Passing an allocation site means that a memento will be created that
// points to the site.
// JS objects are pretenured when allocated by the bootstrapper and
// runtime.
Handle<JSObject> NewJSObjectFromMap(
Handle<Map> map,
PretenureFlag pretenure = NOT_TENURED,
Handle<Map> map, PretenureFlag pretenure = NOT_TENURED,
Handle<AllocationSite> allocation_site = Handle<AllocationSite>::null());
Handle<JSObject> NewSlowJSObjectFromMap(
Handle<Map> map,
@ -577,9 +583,7 @@ class V8_EXPORT_PRIVATE Factory final {
PretenureFlag pretenure = NOT_TENURED);
void NewJSArrayStorage(
Handle<JSArray> array,
int length,
int capacity,
Handle<JSArray> array, int length, int capacity,
ArrayStorageAllocationMode mode = DONT_INITIALIZE_ARRAY_ELEMENTS);
Handle<JSWeakMap> NewJSWeakMap();
@ -594,8 +598,9 @@ class V8_EXPORT_PRIVATE Factory final {
SharedFlag shared = SharedFlag::kNotShared,
PretenureFlag pretenure = NOT_TENURED);
ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind);
size_t GetExternalArrayElementSize(ExternalArrayType type);
static void TypeAndSizeForElementsKind(ElementsKind kind,
ExternalArrayType* array_type,
size_t* element_size);
Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type,
PretenureFlag pretenure = NOT_TENURED);
@ -614,7 +619,6 @@ class V8_EXPORT_PRIVATE Factory final {
size_t number_of_elements,
PretenureFlag pretenure = NOT_TENURED);
Handle<JSDataView> NewJSDataView();
Handle<JSDataView> NewJSDataView(Handle<JSArrayBuffer> buffer,
size_t byte_offset, size_t byte_length);
@ -686,7 +690,6 @@ class V8_EXPORT_PRIVATE Factory final {
// Create a serialized scope info.
Handle<ScopeInfo> NewScopeInfo(int length);
Handle<ModuleInfoEntry> NewModuleInfoEntry();
Handle<ModuleInfo> NewModuleInfo();
Handle<PreParsedScopeData> NewPreParsedScopeData();
@ -697,6 +700,8 @@ class V8_EXPORT_PRIVATE Factory final {
// Creates a new CodeDataContainer for a Code object.
Handle<CodeDataContainer> NewCodeDataContainer(int flags);
// Allocates a new code object (fully initialized). All header fields of the
// returned object are immutable and the code object is write protected.
// The reference to the Code object is stored in self_reference.
// This allows generated code to reference its own Code object
// by containing this handle.
@ -714,6 +719,8 @@ class V8_EXPORT_PRIVATE Factory final {
// Allocates a new, empty code object for use by builtin deserialization. The
// given {size} argument specifies the size of the entire code object.
// Can only be used when code space is unprotected and requires manual
// initialization by the caller.
Handle<Code> NewCodeForDeserialization(uint32_t size);
#ifdef V8_EMBEDDED_BUILTINS
@ -762,8 +769,6 @@ class V8_EXPORT_PRIVATE Factory final {
inline Handle<String> Uint32ToString(uint32_t value);
Handle<JSFunction> InstallMembers(Handle<JSFunction> function);
#define ROOT_ACCESSOR(type, name, camel_name) inline Handle<type> name();
ROOT_LIST(ROOT_ACCESSOR)
#undef ROOT_ACCESSOR
@ -855,18 +860,14 @@ class V8_EXPORT_PRIVATE Factory final {
// Creates a new FixedArray that holds the data associated with the
// atom regexp and stores it in the regexp.
void SetRegExpAtomData(Handle<JSRegExp> regexp,
JSRegExp::Type type,
Handle<String> source,
JSRegExp::Flags flags,
void SetRegExpAtomData(Handle<JSRegExp> regexp, JSRegExp::Type type,
Handle<String> source, JSRegExp::Flags flags,
Handle<Object> match_pattern);
// Creates a new FixedArray that holds the data associated with the
// irregexp regexp and stores it in the regexp.
void SetRegExpIrregexpData(Handle<JSRegExp> regexp,
JSRegExp::Type type,
Handle<String> source,
JSRegExp::Flags flags,
void SetRegExpIrregexpData(Handle<JSRegExp> regexp, JSRegExp::Type type,
Handle<String> source, JSRegExp::Flags flags,
int capture_count);
// Returns the value for a known global constant (a property of the global
@ -884,19 +885,46 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<CallHandlerInfo> NewCallHandlerInfo(bool has_no_side_effect = false);
HeapObject* NewForTest(Handle<Map> map, PretenureFlag pretenure) {
return New(map, pretenure);
}
private:
Isolate* isolate() { return reinterpret_cast<Isolate*>(this); }
// Creates a heap object based on the map. The fields of the heap object are
// not initialized by New<>() functions. It's the responsibility of the caller
// to do that.
template<typename T>
Handle<T> New(Handle<Map> map, AllocationSpace space);
HeapObject* AllocateRawWithImmortalMap(
int size, PretenureFlag pretenure, Map* map,
AllocationAlignment alignment = kWordAligned);
HeapObject* AllocateRawWithAllocationSite(
Handle<Map> map, PretenureFlag pretenure,
Handle<AllocationSite> allocation_site);
template<typename T>
Handle<T> New(Handle<Map> map,
AllocationSpace space,
Handle<AllocationSite> allocation_site);
// Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
HeapObject* AllocateRawArray(int size, PretenureFlag pretenure);
HeapObject* AllocateRawFixedArray(int length, PretenureFlag pretenure);
Handle<FixedArray> NewFixedArrayWithFiller(Heap::RootListIndex map_root_index,
int length, Object* filler,
PretenureFlag pretenure);
// Creates a heap object based on the map. The fields of the heap object are
// not initialized, it's the responsibility of the caller to do that.
HeapObject* New(Handle<Map> map, PretenureFlag pretenure);
template <typename T>
Handle<T> CopyArrayWithMap(Handle<T> src, Handle<Map> map);
template <typename T>
Handle<T> CopyArrayAndGrow(Handle<T> src, int grow_by,
PretenureFlag pretenure);
template <bool is_one_byte, typename T>
Handle<String> AllocateInternalizedStringImpl(T t, int chars,
uint32_t hash_field);
Handle<String> AllocateOneByteInternalizedString(Vector<const uint8_t> str,
uint32_t hash_field);
Handle<String> AllocateTwoByteInternalizedString(Vector<const uc16> str,
uint32_t hash_field);
MaybeHandle<String> NewStringFromTwoByte(const uc16* string, int length,
PretenureFlag pretenure);
@ -918,6 +946,16 @@ class V8_EXPORT_PRIVATE Factory final {
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandle<String> name, MaybeHandle<HeapObject> maybe_function_data,
int maybe_builtin_index, FunctionKind kind = kNormalFunction);
void InitializeAllocationMemento(AllocationMemento* memento,
AllocationSite* allocation_site);
// Initializes a JSObject based on its map.
void InitializeJSObjectFromMap(Handle<JSObject> obj,
Handle<Object> properties, Handle<Map> map);
// Initializes JSObject body starting at given offset.
void InitializeJSObjectBody(Handle<JSObject> obj, Handle<Map> map,
int start_offset);
};
// Utility class to simplify argument handling around JSFunction creation.
@ -975,4 +1013,4 @@ class NewFunctionArgs final {
} // namespace internal
} // namespace v8
#endif // V8_FACTORY_H_
#endif // V8_HEAP_FACTORY_H_

View File

@ -128,161 +128,6 @@ size_t Heap::NewSpaceAllocationCounter() {
return new_space_allocation_counter_ + new_space()->AllocatedSinceLastGC();
}
template <>
bool inline Heap::IsOneByte(Vector<const char> str, int chars) {
// TODO(dcarney): incorporate Latin-1 check when Latin-1 is supported?
return chars == str.length();
}
template <>
bool inline Heap::IsOneByte(String* str, int chars) {
return str->IsOneByteRepresentation();
}
AllocationResult Heap::AllocateInternalizedStringFromUtf8(
Vector<const char> str, int chars, uint32_t hash_field) {
if (IsOneByte(str, chars)) {
return AllocateOneByteInternalizedString(Vector<const uint8_t>::cast(str),
hash_field);
}
return AllocateInternalizedStringImpl<false>(str, chars, hash_field);
}
template <typename T>
AllocationResult Heap::AllocateInternalizedStringImpl(T t, int chars,
uint32_t hash_field) {
if (IsOneByte(t, chars)) {
return AllocateInternalizedStringImpl<true>(t, chars, hash_field);
}
return AllocateInternalizedStringImpl<false>(t, chars, hash_field);
}
AllocationResult Heap::AllocateOneByteInternalizedString(
Vector<const uint8_t> str, uint32_t hash_field) {
CHECK_GE(String::kMaxLength, str.length());
// The canonical empty_string is the only zero-length string we allow.
DCHECK_IMPLIES(str.length() == 0, roots_[kempty_stringRootIndex] == nullptr);
// Compute map and object size.
Map* map = one_byte_internalized_string_map();
int size = SeqOneByteString::SizeFor(str.length());
// Allocate string.
HeapObject* result = nullptr;
{
AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
if (!allocation.To(&result)) return allocation;
}
// String maps are all immortal immovable objects.
result->set_map_after_allocation(map, SKIP_WRITE_BARRIER);
// Set length and hash fields of the allocated string.
String* answer = String::cast(result);
answer->set_length(str.length());
answer->set_hash_field(hash_field);
DCHECK_EQ(size, answer->Size());
// Fill in the characters.
MemCopy(answer->address() + SeqOneByteString::kHeaderSize, str.start(),
str.length());
return answer;
}
AllocationResult Heap::AllocateTwoByteInternalizedString(Vector<const uc16> str,
uint32_t hash_field) {
CHECK_GE(String::kMaxLength, str.length());
DCHECK_NE(0, str.length()); // Use Heap::empty_string() instead.
// Compute map and object size.
Map* map = internalized_string_map();
int size = SeqTwoByteString::SizeFor(str.length());
// Allocate string.
HeapObject* result = nullptr;
{
AllocationResult allocation = AllocateRaw(size, OLD_SPACE);
if (!allocation.To(&result)) return allocation;
}
result->set_map_after_allocation(map);
// Set length and hash fields of the allocated string.
String* answer = String::cast(result);
answer->set_length(str.length());
answer->set_hash_field(hash_field);
DCHECK_EQ(size, answer->Size());
// Fill in the characters.
MemCopy(answer->address() + SeqTwoByteString::kHeaderSize, str.start(),
str.length() * kUC16Size);
return answer;
}
AllocationResult Heap::CopyFixedArray(FixedArray* src) {
if (src->length() == 0) return src;
return CopyFixedArrayWithMap(src, src->map());
}
AllocationResult Heap::CopyFixedDoubleArray(FixedDoubleArray* src) {
if (src->length() == 0) return src;
return CopyFixedDoubleArrayWithMap(src, src->map());
}
AllocationResult Heap::AllocateFixedArrayWithMap(RootListIndex map_root_index,
int length,
PretenureFlag pretenure) {
return AllocateFixedArrayWithFiller(map_root_index, length, pretenure,
undefined_value());
}
AllocationResult Heap::AllocateFixedArray(int length, PretenureFlag pretenure) {
return AllocateFixedArrayWithFiller(Heap::kFixedArrayMapRootIndex, length,
pretenure, undefined_value());
}
AllocationResult Heap::AllocateWeakFixedArray(int length,
PretenureFlag pretenure) {
// Zero-length case must be handled outside, where the knowledge about
// the map is.
DCHECK_LT(0, length);
HeapObject* result = nullptr;
{
AllocationResult allocation = AllocateRawWeakFixedArray(length, pretenure);
if (!allocation.To(&result)) return allocation;
}
DCHECK(RootIsImmortalImmovable(Heap::kWeakFixedArrayMapRootIndex));
Map* map = Map::cast(root(Heap::kWeakFixedArrayMapRootIndex));
result->set_map_after_allocation(map, SKIP_WRITE_BARRIER);
WeakFixedArray* array = WeakFixedArray::cast(result);
array->set_length(length);
MemsetPointer(array->data_start(),
HeapObjectReference::Strong(undefined_value()), length);
return array;
}
AllocationResult Heap::AllocateRawFixedArray(int length,
PretenureFlag pretenure) {
if (length < 0 || length > FixedArray::kMaxLength) {
FatalProcessOutOfMemory("invalid array length");
}
return AllocateRawArray(FixedArray::SizeFor(length), pretenure);
}
AllocationResult Heap::AllocateRawWeakFixedArray(int length,
PretenureFlag pretenure) {
if (length < 0 || length > WeakFixedArray::kMaxLength) {
FatalProcessOutOfMemory("invalid array length");
}
return AllocateRawArray(WeakFixedArray::SizeFor(length), pretenure);
}
AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space,
AllocationAlignment alignment) {
DCHECK(AllowHandleAllocation::IsAllowed());
@ -357,7 +202,6 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space,
return allocation;
}
void Heap::OnAllocationEvent(HeapObject* object, int size_in_bytes) {
for (auto& tracker : allocation_trackers_) {
tracker->AllocationEvent(object->address(), size_in_bytes);
@ -703,7 +547,6 @@ AlwaysAllocateScope::~AlwaysAllocateScope() {
CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
: heap_(heap) {
DCHECK(!heap_->unprotected_memory_chunks_registry_enabled());
if (heap_->write_protect_code_memory()) {
heap_->increment_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndWritable();
@ -719,7 +562,6 @@ CodeSpaceMemoryModificationScope::CodeSpaceMemoryModificationScope(Heap* heap)
}
CodeSpaceMemoryModificationScope::~CodeSpaceMemoryModificationScope() {
DCHECK(!heap_->unprotected_memory_chunks_registry_enabled());
if (heap_->write_protect_code_memory()) {
heap_->decrement_code_space_memory_modification_scope_depth();
heap_->code_space()->SetReadAndExecutable();

File diff suppressed because it is too large Load Diff

View File

@ -682,9 +682,6 @@ class Heap {
// given alignment.
static int GetFillToAlign(Address address, AllocationAlignment alignment);
template <typename T>
static inline bool IsOneByte(T t, int chars);
void FatalProcessOutOfMemory(const char* location);
V8_EXPORT_PRIVATE static bool RootIsImmortalImmovable(int root_index);
@ -832,7 +829,7 @@ class Heap {
void UnprotectAndRegisterMemoryChunk(MemoryChunk* chunk);
void UnprotectAndRegisterMemoryChunk(HeapObject* object);
void ProtectUnprotectedMemoryChunks();
V8_EXPORT_PRIVATE void ProtectUnprotectedMemoryChunks();
void EnableUnprotectedMemoryChunksRegistry() {
unprotected_memory_chunks_registry_enabled_ = true;
@ -1130,9 +1127,7 @@ class Heap {
bool RootCanBeTreatedAsConstant(RootListIndex root_index);
Map* MapForFixedTypedArray(ExternalArrayType array_type);
RootListIndex RootIndexForFixedTypedArray(ExternalArrayType array_type);
RootListIndex RootIndexForEmptyFixedTypedArray(ElementsKind kind);
Map* MapForFixedTypedArray(ElementsKind elements_kind);
FixedTypedArrayBase* EmptyFixedTypedArrayForMap(const Map* map);
void RegisterStrongRoots(Object** start, Object** end);
@ -1858,15 +1853,6 @@ class Heap {
inline void UpdateOldSpaceLimits();
// Initializes a JSObject based on its map.
void InitializeJSObjectFromMap(JSObject* obj, Object* properties, Map* map);
// Initializes JSObject body starting at given offset.
void InitializeJSObjectBody(JSObject* obj, Map* map, int start_offset);
void InitializeAllocationMemento(AllocationMemento* memento,
AllocationSite* allocation_site);
bool CreateInitialMaps();
void CreateInternalAccessorInfoObjects();
void CreateInitialObjects();
@ -2107,96 +2093,12 @@ class Heap {
// Allocation methods. =======================================================
// ===========================================================================
// Returns a deep copy of the JavaScript object.
// Properties and elements are copied too.
// Optionally takes an AllocationSite to be appended in an AllocationMemento.
MUST_USE_RESULT AllocationResult CopyJSObject(JSObject* source,
AllocationSite* site = nullptr);
// Allocates a JS Map in the heap.
MUST_USE_RESULT AllocationResult
AllocateMap(InstanceType instance_type, int instance_size,
ElementsKind elements_kind = TERMINAL_FAST_ELEMENTS_KIND,
int inobject_properties = 0);
// Allocates and initializes a new JavaScript object based on a
// constructor.
// If allocation_site is non-null, then a memento is emitted after the object
// that points to the site.
MUST_USE_RESULT AllocationResult AllocateJSObject(
JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED,
AllocationSite* allocation_site = nullptr);
// Allocates and initializes a new JavaScript object based on a map.
// Passing an allocation site means that a memento will be created that
// points to the site.
MUST_USE_RESULT AllocationResult
AllocateJSObjectFromMap(Map* map, PretenureFlag pretenure = NOT_TENURED,
AllocationSite* allocation_site = nullptr);
// Allocates a HeapNumber from value.
MUST_USE_RESULT AllocationResult AllocateHeapNumber(
MutableMode mode = IMMUTABLE, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT AllocationResult
AllocateBigInt(int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates a byte array of the specified length
MUST_USE_RESULT AllocationResult
AllocateByteArray(int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates a bytecode array with given contents.
MUST_USE_RESULT AllocationResult
AllocateBytecodeArray(int length, const byte* raw_bytecodes, int frame_size,
int parameter_count, FixedArray* constant_pool);
MUST_USE_RESULT AllocationResult CopyCode(Code* code,
CodeDataContainer* data_container);
MUST_USE_RESULT AllocationResult
CopyBytecodeArray(BytecodeArray* bytecode_array);
// Allocates a fixed array-like object with given map and initialized with
// undefined values.
MUST_USE_RESULT inline AllocationResult AllocateFixedArrayWithMap(
RootListIndex map_root_index, int length,
PretenureFlag pretenure = NOT_TENURED);
// Allocates a fixed array initialized with undefined values
MUST_USE_RESULT inline AllocationResult AllocateFixedArray(
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates an array allowing in-place weak references, initialized with
// undefined values
MUST_USE_RESULT inline AllocationResult AllocateWeakFixedArray(
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocate memory for an uninitialized FixedArray.
MUST_USE_RESULT inline AllocationResult AllocateRawFixedArray(
int length, PretenureFlag pretenure);
// Allocate memory for an uninitialized WeakFixedArray.
MUST_USE_RESULT inline AllocationResult AllocateRawWeakFixedArray(
int length, PretenureFlag pretenure);
// Allocates a property array initialized with undefined values
MUST_USE_RESULT AllocationResult
AllocatePropertyArray(int length, PretenureFlag pretenure = NOT_TENURED);
// Allocate a feedback vector for the given shared function info. The slots
// are pre-filled with undefined.
MUST_USE_RESULT AllocationResult
AllocateFeedbackVector(SharedFunctionInfo* shared, PretenureFlag pretenure);
// Allocate an uninitialized feedback vector.
MUST_USE_RESULT AllocationResult
AllocateRawFeedbackVector(int length, PretenureFlag pretenure);
MUST_USE_RESULT AllocationResult AllocateSmallOrderedHashSet(
int length, PretenureFlag pretenure = NOT_TENURED);
MUST_USE_RESULT AllocationResult AllocateSmallOrderedHashMap(
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocate an uninitialized object. The memory is non-executable if the
// hardware and OS allow. This is the single choke-point for allocations
// performed by the runtime and should not be bypassed (to extend this to
@ -2205,184 +2107,22 @@ class Heap {
int size_in_bytes, AllocationSpace space,
AllocationAlignment aligment = kWordAligned);
HeapObject* AllocateRawWithRetry(
int size, AllocationSpace space,
AllocationAlignment alignment = kWordAligned);
HeapObject* AllocateRawCodeInLargeObjectSpace(int size);
// Allocates a heap object based on the map.
MUST_USE_RESULT AllocationResult
Allocate(Map* map, AllocationSpace space,
AllocationSite* allocation_site = nullptr);
MUST_USE_RESULT AllocationResult Allocate(Map* map, AllocationSpace space);
// Allocates a partial map for bootstrapping.
MUST_USE_RESULT AllocationResult
AllocatePartialMap(InstanceType instance_type, int instance_size);
// Allocate a block of memory in the given space (filled with a filler).
// Used as a fall-back for generated code when the space is full.
MUST_USE_RESULT AllocationResult
AllocateFillerObject(int size, bool double_align, AllocationSpace space);
// Allocate memory for an uninitialized array (e.g., a FixedArray or similar).
MUST_USE_RESULT AllocationResult AllocateRawArray(int size,
PretenureFlag pretenure);
// Allocate an uninitialized fixed double array.
MUST_USE_RESULT AllocationResult
AllocateRawFixedDoubleArray(int length, PretenureFlag pretenure);
// Allocate an initialized fixed array with the given filler value.
MUST_USE_RESULT AllocationResult
AllocateFixedArrayWithFiller(RootListIndex map_root_index, int length,
PretenureFlag pretenure, Object* filler);
// Allocate and partially initializes a String. There are two String
// encodings: one-byte and two-byte. These functions allocate a string of
// the given length and set its map and length fields. The characters of
// the string are uninitialized.
MUST_USE_RESULT AllocationResult
AllocateRawOneByteString(int length, PretenureFlag pretenure);
MUST_USE_RESULT AllocationResult
AllocateRawTwoByteString(int length, PretenureFlag pretenure);
// Allocates an internalized string in old space based on the character
// stream.
MUST_USE_RESULT inline AllocationResult AllocateInternalizedStringFromUtf8(
Vector<const char> str, int chars, uint32_t hash_field);
MUST_USE_RESULT inline AllocationResult AllocateOneByteInternalizedString(
Vector<const uint8_t> str, uint32_t hash_field);
MUST_USE_RESULT inline AllocationResult AllocateTwoByteInternalizedString(
Vector<const uc16> str, uint32_t hash_field);
template <bool is_one_byte, typename T>
MUST_USE_RESULT AllocationResult
AllocateInternalizedStringImpl(T t, int chars, uint32_t hash_field);
template <typename T>
MUST_USE_RESULT inline AllocationResult AllocateInternalizedStringImpl(
T t, int chars, uint32_t hash_field);
// Allocates an uninitialized fixed array. It must be filled by the caller.
MUST_USE_RESULT AllocationResult AllocateUninitializedFixedArray(
int length, PretenureFlag pretenure = NOT_TENURED);
// Make a copy of src and return it.
MUST_USE_RESULT inline AllocationResult CopyFixedArray(FixedArray* src);
// Make a copy of src, also grow the copy, and return the copy.
template <typename T>
MUST_USE_RESULT AllocationResult CopyArrayAndGrow(T* src, int grow_by,
PretenureFlag pretenure);
// Make a copy of src, also grow the copy, and return the copy.
MUST_USE_RESULT AllocationResult CopyPropertyArrayAndGrow(
PropertyArray* src, int grow_by, PretenureFlag pretenure);
// Make a copy of src, also grow the copy, and return the copy.
MUST_USE_RESULT AllocationResult CopyFixedArrayUpTo(FixedArray* src,
int new_len,
PretenureFlag pretenure);
// Make a copy of src, set the map, and return the copy.
template <typename T>
MUST_USE_RESULT AllocationResult CopyArrayWithMap(T* src, Map* map);
// Make a copy of src, set the map, and return the copy.
MUST_USE_RESULT AllocationResult CopyFixedArrayWithMap(FixedArray* src,
Map* map);
// Make a copy of src, set the map, and return the copy.
MUST_USE_RESULT AllocationResult CopyPropertyArray(PropertyArray* src);
// Make a copy of src and return it.
MUST_USE_RESULT inline AllocationResult CopyFixedDoubleArray(
FixedDoubleArray* src);
// Make a copy of src and return it.
MUST_USE_RESULT AllocationResult CopyFeedbackVector(FeedbackVector* src);
// Computes a single character string where the character has code.
// A cache is used for one-byte (Latin1) codes.
MUST_USE_RESULT AllocationResult
LookupSingleCharacterStringFromCode(uint16_t code);
// Allocate a symbol in old space.
MUST_USE_RESULT AllocationResult AllocateSymbol();
// Allocates an external array of the specified length and type.
MUST_USE_RESULT AllocationResult AllocateFixedTypedArrayWithExternalPointer(
int length, ExternalArrayType array_type, void* external_pointer,
PretenureFlag pretenure);
// Allocates a fixed typed array of the specified length and type.
MUST_USE_RESULT AllocationResult
AllocateFixedTypedArray(int length, ExternalArrayType array_type,
bool initialize, PretenureFlag pretenure);
// Make a copy of src and return it.
MUST_USE_RESULT AllocationResult CopyAndTenureFixedCOWArray(FixedArray* src);
// Make a copy of src, set the map, and return the copy.
MUST_USE_RESULT AllocationResult
CopyFixedDoubleArrayWithMap(FixedDoubleArray* src, Map* map);
// Allocates a fixed double array with uninitialized values. Returns
MUST_USE_RESULT AllocationResult AllocateUninitializedFixedDoubleArray(
int length, PretenureFlag pretenure = NOT_TENURED);
// Allocates a FeedbackMedata object and zeroes the data section.
MUST_USE_RESULT AllocationResult AllocateFeedbackMetadata(int slot_count);
// Allocate empty fixed array like objects.
MUST_USE_RESULT AllocationResult AllocateEmptyFixedArray();
MUST_USE_RESULT AllocationResult AllocateEmptyWeakFixedArray();
MUST_USE_RESULT AllocationResult AllocateEmptyScopeInfo();
MUST_USE_RESULT AllocationResult AllocateEmptyBoilerplateDescription();
// Allocate empty fixed typed array of given type.
MUST_USE_RESULT AllocationResult
AllocateEmptyFixedTypedArray(ExternalArrayType array_type);
// Allocate a tenured simple cell.
MUST_USE_RESULT AllocationResult AllocateCell(Object* value);
// Allocate a tenured simple feedback cell.
MUST_USE_RESULT AllocationResult AllocateFeedbackCell(Map* map,
HeapObject* value);
// Allocate a tenured JS global property cell initialized with the hole.
MUST_USE_RESULT AllocationResult AllocatePropertyCell(Name* name);
MUST_USE_RESULT AllocationResult AllocateWeakCell(HeapObject* value);
MUST_USE_RESULT AllocationResult AllocateTransitionArray(int capacity);
// Allocates a new utility object in the old generation.
MUST_USE_RESULT AllocationResult
AllocateStruct(InstanceType type, PretenureFlag pretenure = NOT_TENURED);
// Allocates a new foreign object.
MUST_USE_RESULT AllocationResult
AllocateForeign(Address address, PretenureFlag pretenure = NOT_TENURED);
// Allocates a new code object (mostly uninitialized). Can only be used when
// code space is unprotected and requires manual initialization by the caller.
MUST_USE_RESULT AllocationResult AllocateCode(int object_size,
Movability movability);
// Allocates a new code object (fully initialized). All header fields of the
// returned object are immutable and the code object is write protected.
MUST_USE_RESULT AllocationResult AllocateCode(
const CodeDesc& desc, Code::Kind kind, Handle<Object> self_ref,
int32_t builtin_index, ByteArray* reloc_info,
CodeDataContainer* data_container, ByteArray* source_position_table,
DeoptimizationData* deopt_data, Movability movability, uint32_t stub_key,
bool is_turbofanned, int stack_slots, int safepoint_table_offset,
int handler_table_offset);
MUST_USE_RESULT AllocationResult AllocateJSPromise(
JSFunction* constructor, PretenureFlag pretenure = NOT_TENURED);
void set_force_oom(bool value) { force_oom_ = value; }
// ===========================================================================

View File

@ -8,8 +8,8 @@
#include "src/ast/context-slot-cache.h"
#include "src/compilation-cache.h"
#include "src/contexts.h"
#include "src/factory.h"
#include "src/heap-symbols.h"
#include "src/heap/factory.h"
#include "src/heap/heap.h"
#include "src/interpreter/interpreter.h"
#include "src/isolate.h"
@ -78,6 +78,58 @@ const Heap::StructTable Heap::struct_table[] = {
#undef DATA_HANDLER_ELEMENT
};
AllocationResult Heap::AllocateMap(InstanceType instance_type,
int instance_size,
ElementsKind elements_kind,
int inobject_properties) {
STATIC_ASSERT(LAST_JS_OBJECT_TYPE == LAST_TYPE);
DCHECK_IMPLIES(instance_type >= FIRST_JS_OBJECT_TYPE &&
!Map::CanHaveFastTransitionableElementsKind(instance_type),
IsDictionaryElementsKind(elements_kind) ||
IsTerminalElementsKind(elements_kind));
HeapObject* result = nullptr;
AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE);
if (!allocation.To(&result)) return allocation;
result->set_map_after_allocation(meta_map(), SKIP_WRITE_BARRIER);
return isolate()->factory()->InitializeMap(Map::cast(result), instance_type,
instance_size, elements_kind,
inobject_properties);
}
AllocationResult Heap::AllocatePartialMap(InstanceType instance_type,
int instance_size) {
Object* result = nullptr;
AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE);
if (!allocation.To(&result)) return allocation;
// Map::cast cannot be used due to uninitialized map field.
Map* map = reinterpret_cast<Map*>(result);
map->set_map_after_allocation(reinterpret_cast<Map*>(root(kMetaMapRootIndex)),
SKIP_WRITE_BARRIER);
map->set_instance_type(instance_type);
map->set_instance_size(instance_size);
// Initialize to only containing tagged fields.
if (FLAG_unbox_double_fields) {
map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout());
}
// GetVisitorId requires a properly initialized LayoutDescriptor.
map->set_visitor_id(Map::GetVisitorId(map));
map->set_inobject_properties_start_or_constructor_function_index(0);
DCHECK(!map->IsJSObjectMap());
map->set_prototype_validity_cell(Smi::FromInt(Map::kPrototypeChainValid));
map->SetInObjectUnusedPropertyFields(0);
map->set_bit_field(0);
map->set_bit_field2(0);
DCHECK(!map->is_in_retained_map_list());
int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) |
Map::OwnsDescriptorsBit::encode(true) |
Map::ConstructionCounterBits::encode(Map::kNoSlackTracking);
map->set_bit_field3(bit_field3);
map->set_weak_cell_cache(Smi::kZero);
map->set_elements_kind(TERMINAL_FAST_ELEMENTS_KIND);
return map;
}
namespace {
void FinalizePartialMap(Heap* heap, Map* map) {
@ -93,6 +145,41 @@ void FinalizePartialMap(Heap* heap, Map* map) {
} // namespace
AllocationResult Heap::Allocate(Map* map, AllocationSpace space) {
DCHECK(map->instance_type() != MAP_TYPE);
int size = map->instance_size();
HeapObject* result = nullptr;
AllocationResult allocation = AllocateRaw(size, space);
if (!allocation.To(&result)) return allocation;
// New space objects are allocated white.
WriteBarrierMode write_barrier_mode =
space == NEW_SPACE ? SKIP_WRITE_BARRIER : UPDATE_WRITE_BARRIER;
result->set_map_after_allocation(map, write_barrier_mode);
return result;
}
AllocationResult Heap::AllocateEmptyFixedTypedArray(
ExternalArrayType array_type) {
int size = OBJECT_POINTER_ALIGN(FixedTypedArrayBase::kDataOffset);
HeapObject* object = nullptr;
AllocationResult allocation = AllocateRaw(
size, OLD_SPACE,
array_type == kExternalFloat64Array ? kDoubleAligned : kWordAligned);
if (!allocation.To(&object)) return allocation;
object->set_map_after_allocation(MapForFixedTypedArray(array_type),
SKIP_WRITE_BARRIER);
FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(object);
elements->set_base_pointer(elements, SKIP_WRITE_BARRIER);
elements->set_external_pointer(
ExternalReference::fixed_typed_array_base_data_offset(isolate())
.address(),
SKIP_WRITE_BARRIER);
elements->set_length(0);
return elements;
}
bool Heap::CreateInitialMaps() {
HeapObject* obj = nullptr;
{
@ -131,14 +218,18 @@ bool Heap::CreateInitialMaps() {
// Allocate the empty array.
{
AllocationResult allocation = AllocateEmptyFixedArray();
if (!allocation.To(&obj)) return false;
AllocationResult alloc = AllocateRaw(FixedArray::SizeFor(0), OLD_SPACE);
if (!alloc.To(&obj)) return false;
obj->set_map_after_allocation(fixed_array_map(), SKIP_WRITE_BARRIER);
FixedArray::cast(obj)->set_length(0);
}
set_empty_fixed_array(FixedArray::cast(obj));
{
AllocationResult allocation = AllocateEmptyWeakFixedArray();
if (!allocation.To(&obj)) return false;
AllocationResult alloc = AllocateRaw(WeakFixedArray::SizeFor(0), OLD_SPACE);
if (!alloc.To(&obj)) return false;
obj->set_map_after_allocation(weak_fixed_array_map(), SKIP_WRITE_BARRIER);
WeakFixedArray::cast(obj)->set_length(0);
}
set_empty_weak_fixed_array(WeakFixedArray::cast(obj));
@ -186,11 +277,12 @@ bool Heap::CreateInitialMaps() {
// Allocate the empty descriptor array.
{
STATIC_ASSERT(DescriptorArray::kFirstIndex != 0);
AllocationResult allocation =
AllocateUninitializedFixedArray(DescriptorArray::kFirstIndex, TENURED);
if (!allocation.To(&obj)) return false;
int length = DescriptorArray::kFirstIndex;
int size = FixedArray::SizeFor(length);
if (!AllocateRaw(size, OLD_SPACE).To(&obj)) return false;
obj->set_map_after_allocation(descriptor_array_map(), SKIP_WRITE_BARRIER);
DescriptorArray::cast(obj)->set_length(length);
}
obj->set_map_no_write_barrier(descriptor_array_map());
set_empty_descriptor_array(DescriptorArray::cast(obj));
DescriptorArray::cast(obj)->set(DescriptorArray::kDescriptorLengthIndex,
Smi::kZero);
@ -301,9 +393,11 @@ bool Heap::CreateInitialMaps() {
{
// The invalid_prototype_validity_cell is needed for JSObject maps.
Smi* value = Smi::FromInt(Map::kPrototypeChainInvalid);
Cell* cell;
if (!AllocateCell(value).To(&cell)) return false;
set_invalid_prototype_validity_cell(cell);
AllocationResult alloc = AllocateRaw(Cell::kSize, OLD_SPACE);
if (!alloc.To(&obj)) return false;
obj->set_map_after_allocation(cell_map(), SKIP_WRITE_BARRIER);
Cell::cast(obj)->set_value(value);
set_invalid_prototype_validity_cell(Cell::cast(obj));
}
ALLOCATE_MAP(PROPERTY_CELL_TYPE, PropertyCell::kSize, global_property_cell)
@ -367,14 +461,19 @@ bool Heap::CreateInitialMaps() {
}
{
AllocationResult allocation = AllocateEmptyScopeInfo();
if (!allocation.To(&obj)) return false;
AllocationResult alloc = AllocateRaw(FixedArray::SizeFor(0), OLD_SPACE);
if (!alloc.To(&obj)) return false;
obj->set_map_after_allocation(scope_info_map(), SKIP_WRITE_BARRIER);
FixedArray::cast(obj)->set_length(0);
}
set_empty_scope_info(ScopeInfo::cast(obj));
{
AllocationResult allocation = AllocateEmptyBoilerplateDescription();
if (!allocation.To(&obj)) return false;
AllocationResult alloc = AllocateRaw(FixedArray::SizeFor(0), OLD_SPACE);
if (!alloc.To(&obj)) return false;
obj->set_map_after_allocation(boilerplate_description_map(),
SKIP_WRITE_BARRIER);
FixedArray::cast(obj)->set_length(0);
}
set_empty_boilerplate_description(BoilerplateDescription::cast(obj));
@ -392,30 +491,34 @@ bool Heap::CreateInitialMaps() {
set_false_value(Oddball::cast(obj));
Oddball::cast(obj)->set_kind(Oddball::kFalse);
{ // Empty arrays
{
ByteArray * byte_array;
if (!AllocateByteArray(0, TENURED).To(&byte_array)) return false;
set_empty_byte_array(byte_array);
}
{
PropertyArray* property_array;
if (!AllocatePropertyArray(0, TENURED).To(&property_array)) return false;
set_empty_property_array(property_array);
}
#define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
{ \
FixedTypedArrayBase* obj; \
if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array).To(&obj)) \
return false; \
set_empty_fixed_##type##_array(obj); \
}
TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY)
#undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY
// Empty arrays.
{
if (!AllocateRaw(ByteArray::SizeFor(0), OLD_SPACE).To(&obj)) return false;
obj->set_map_after_allocation(byte_array_map(), SKIP_WRITE_BARRIER);
ByteArray::cast(obj)->set_length(0);
set_empty_byte_array(ByteArray::cast(obj));
}
{
if (!AllocateRaw(FixedArray::SizeFor(0), OLD_SPACE).To(&obj)) {
return false;
}
obj->set_map_after_allocation(property_array_map(), SKIP_WRITE_BARRIER);
PropertyArray::cast(obj)->initialize_length(0);
set_empty_property_array(PropertyArray::cast(obj));
}
#define ALLOCATE_EMPTY_FIXED_TYPED_ARRAY(Type, type, TYPE, ctype, size) \
{ \
FixedTypedArrayBase* obj; \
if (!AllocateEmptyFixedTypedArray(kExternal##Type##Array).To(&obj)) \
return false; \
set_empty_fixed_##type##_array(obj); \
}
TYPED_ARRAYS(ALLOCATE_EMPTY_FIXED_TYPED_ARRAY)
#undef ALLOCATE_EMPTY_FIXED_TYPED_ARRAY
DCHECK(!InNewSpace(empty_fixed_array()));
return true;
}

View File

@ -281,8 +281,9 @@ AllocationResult LocalAllocationBuffer::AllocateRawAligned(
}
bool PagedSpace::EnsureLinearAllocationArea(int size_in_bytes) {
if (allocation_info_.top() + size_in_bytes <= allocation_info_.limit())
if (allocation_info_.top() + size_in_bytes <= allocation_info_.limit()) {
return true;
}
return SlowRefillLinearAllocationArea(size_in_bytes);
}

View File

@ -5,7 +5,7 @@
#if V8_TARGET_ARCH_IA32
#include "src/codegen.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/heap/heap.h"
#include "src/isolate.h"
#include "src/macro-assembler.h"

View File

@ -7,8 +7,8 @@
#include <vector>
#include "src/factory.h"
#include "src/feedback-vector.h"
#include "src/heap/factory.h"
#include "src/ic/stub-cache.h"
#include "src/isolate.h"
#include "src/macro-assembler.h"

View File

@ -4,7 +4,7 @@
#include "src/interpreter/handler-table-builder.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/interpreter/bytecode-register.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -7,8 +7,8 @@
#include "src/allocation.h"
#include "src/builtins/builtins.h"
#include "src/code-factory.h"
#include "src/factory-inl.h"
#include "src/frames.h"
#include "src/heap/factory-inl.h"
#include "src/interpreter/bytecodes.h"
#include "src/interpreter/interpreter-assembler.h"
#include "src/interpreter/interpreter-intrinsics.h"

View File

@ -10,7 +10,7 @@
#include <memory>
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/string-case.h"

View File

@ -7,7 +7,6 @@
#include "src/char-predicates-inl.h"
#include "src/conversions.h"
#include "src/debug/debug.h"
#include "src/factory.h"
#include "src/field-type.h"
#include "src/messages.h"
#include "src/objects-inl.h"
@ -15,7 +14,6 @@
#include "src/string-hasher.h"
#include "src/transitions.h"
#include "src/unicode-cache.h"
#include "src/zone/zone-containers.h"
namespace v8 {
namespace internal {

View File

@ -5,7 +5,7 @@
#ifndef V8_JSON_PARSER_H_
#define V8_JSON_PARSER_H_
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/zone/zone-containers.h"

View File

@ -6,7 +6,7 @@
#include "src/api-arguments-inl.h"
#include "src/elements.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/identity-map.h"
#include "src/isolate-inl.h"
#include "src/objects-inl.h"

View File

@ -5,8 +5,8 @@
#ifndef V8_LOOKUP_H_
#define V8_LOOKUP_H_
#include "src/factory.h"
#include "src/globals.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/objects/descriptor-array.h"

View File

@ -5,9 +5,9 @@
#ifndef V8_MANAGED_H_
#define V8_MANAGED_H_
#include "src/factory.h"
#include "src/global-handles.h"
#include "src/handles.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
namespace v8 {

View File

@ -18,15 +18,13 @@
#include "src/builtins/builtins.h"
#include "src/contexts-inl.h"
#include "src/conversions-inl.h"
#include "src/factory.h"
#include "src/feedback-vector-inl.h"
#include "src/field-index-inl.h"
#include "src/field-type.h"
#include "src/handles-inl.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/heap/heap.h"
#include "src/isolate-inl.h"
#include "src/isolate.h"
#include "src/keys.h"
#include "src/layout-descriptor-inl.h"
#include "src/lookup-cache-inl.h"
@ -37,7 +35,6 @@
#include "src/objects/data-handler-inl.h"
#include "src/objects/fixed-array-inl.h"
#include "src/objects/hash-table-inl.h"
#include "src/objects/hash-table.h"
#include "src/objects/js-array-inl.h"
#include "src/objects/js-collection-inl.h"
#include "src/objects/js-promise-inl.h"

View File

@ -4416,7 +4416,7 @@ class Foreign: public HeapObject {
typedef BodyDescriptor BodyDescriptorWeak;
private:
friend class Heap;
friend class Factory;
friend class SerializerDeserializer;
friend class StartupSerializer;

View File

@ -11,8 +11,8 @@
#include <memory>
#include "src/api.h"
#include "src/factory.h"
#include "src/global-handles.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/managed.h"
#include "src/objects-inl.h"

View File

@ -6,7 +6,7 @@
#include "src/accessors.h"
#include "src/ast/ast.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects/literal-objects-inl.h"

View File

@ -8,7 +8,7 @@
#include "src/objects/string.h"
#include "src/conversions-inl.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects/name-inl.h"
#include "src/string-hasher-inl.h"

View File

@ -4,7 +4,7 @@
#include "src/objects/template-objects.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/property-descriptor.h"

View File

@ -5,7 +5,7 @@
#include "src/property-descriptor.h"
#include "src/bootstrapper.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/lookup.h"
#include "src/objects-inl.h"

View File

@ -8,7 +8,7 @@
#include "src/assembler-inl.h"
#include "src/code-stubs.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/log.h"
#include "src/macro-assembler.h"
#include "src/objects-inl.h"

View File

@ -11,7 +11,7 @@
#include "src/compilation-cache.h"
#include "src/elements.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/messages.h"
#include "src/ostreams.h"

View File

@ -7,7 +7,7 @@
#include <vector>
#include "src/char-predicates-inl.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/ostreams.h"

View File

@ -4,7 +4,7 @@
#include "src/regexp/regexp-utils.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/regexp/jsregexp.h"

View File

@ -6,7 +6,7 @@
#include "src/regexp/x64/regexp-macro-assembler-x64.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/log.h"
#include "src/macro-assembler.h"
#include "src/objects-inl.h"

View File

@ -8,7 +8,7 @@
#include "src/code-stubs.h"
#include "src/conversions-inl.h"
#include "src/elements.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/keys.h"
#include "src/messages.h"

View File

@ -8,7 +8,7 @@
#include "src/base/macros.h"
#include "src/base/platform/mutex.h"
#include "src/conversions-inl.h"
#include "src/factory.h"
#include "src/heap/factory.h"
// Implement Atomic accesses to SharedArrayBuffers as defined in the
// SharedArrayBuffer draft spec, found here

View File

@ -6,7 +6,7 @@
#include "src/arguments.h"
#include "src/conversions-inl.h"
#include "src/factory.h"
#include "src/heap/factory.h"
namespace v8 {
namespace internal {

View File

@ -7,7 +7,7 @@
#include "src/arguments.h"
#include "src/conversions-inl.h"
#include "src/date.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/messages.h"

View File

@ -6,7 +6,7 @@
#include "src/arguments.h"
#include "src/elements.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/keys.h"
#include "src/objects-inl.h"

View File

@ -5,7 +5,7 @@
#include "src/runtime/runtime-utils.h"
#include "src/arguments.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
namespace v8 {

View File

@ -151,9 +151,9 @@ RUNTIME_FUNCTION(Runtime_ThrowInvalidTypedArrayAlignment) {
Handle<String> type =
isolate->factory()->NewStringFromAsciiChecked(ElementsKindToType(kind));
ExternalArrayType external_type =
isolate->factory()->GetArrayTypeFromElementsKind(kind);
size_t size = isolate->factory()->GetExternalArrayElementSize(external_type);
ExternalArrayType external_type;
size_t size;
Factory::TypeAndSizeForElementsKind(kind, &external_type, &size);
Handle<Object> element_size =
handle(Smi::FromInt(static_cast<int>(size)), isolate);

View File

@ -14,8 +14,8 @@
#include "src/api-natives.h"
#include "src/api.h"
#include "src/arguments.h"
#include "src/factory.h"
#include "src/global-handles.h"
#include "src/heap/factory.h"
#include "src/intl.h"
#include "src/isolate-inl.h"
#include "src/messages.h"

View File

@ -6,7 +6,7 @@
#include "src/arguments.h"
#include "src/elements.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate-inl.h"
#include "src/objects-inl.h"

View File

@ -6,7 +6,7 @@
#include "src/arguments.h"
#include "src/elements.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/messages.h"
#include "src/objects-inl.h"
#include "src/runtime/runtime.h"

View File

@ -9,8 +9,8 @@
#include "src/compiler/wasm-compiler.h"
#include "src/conversions.h"
#include "src/debug/debug.h"
#include "src/factory.h"
#include "src/frame-constants.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
#include "src/objects/frame-array-inl.h"
#include "src/trap-handler/trap-handler.h"

View File

@ -6,8 +6,8 @@
#define V8_STRING_BUILDER_H_
#include "src/assert-scope.h"
#include "src/factory.h"
#include "src/handles.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/utils.h"

View File

@ -10,12 +10,11 @@
#include "src/api.h"
#include "src/base/logging.h"
#include "src/conversions.h"
#include "src/factory.h"
#include "src/flags.h"
#include "src/handles-inl.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/snapshot/code-serializer.h"
#include "src/transitions.h"
#include "src/wasm/wasm-engine.h"

View File

@ -10,8 +10,8 @@
#include "src/compiler/wasm-compiler.h"
#include "src/debug/debug-scopes.h"
#include "src/debug/debug.h"
#include "src/factory.h"
#include "src/frames-inl.h"
#include "src/heap/factory.h"
#include "src/identity-map.h"
#include "src/isolate.h"
#include "src/wasm/module-decoder.h"

View File

@ -9,11 +9,10 @@
#include "src/assert-scope.h"
#include "src/ast/ast.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/handles.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "src/objects.h"
#include "src/parsing/parse-info.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/wasm-engine.h"

View File

@ -4,7 +4,7 @@
#include "src/wasm/wasm-result.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/heap/heap.h"
#include "src/isolate-inl.h"
#include "src/objects.h"

View File

@ -34,8 +34,8 @@
#include "include/v8-platform.h"
#include "src/assembler.h"
#include "src/debug/debug-interface.h"
#include "src/factory.h"
#include "src/flags.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "src/utils.h"

View File

@ -5,7 +5,7 @@
#include "src/assembler.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/node-properties.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/value-helper.h"

View File

@ -8,7 +8,7 @@
#include "src/compiler/js-operator.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
#include "src/property.h"
#include "test/cctest/cctest.h"

View File

@ -10,7 +10,7 @@
#include "src/compiler/operator-properties.h"
#include "src/compiler/simplified-operator.h"
#include "src/compiler/typer.h"
#include "src/factory-inl.h"
#include "src/heap/factory-inl.h"
#include "src/isolate.h"
#include "src/objects.h"
#include "test/cctest/cctest.h"

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "src/objects-inl.h"
#include "test/cctest/compiler/function-tester.h"

View File

@ -86,6 +86,15 @@ class HeapTester {
// test-api.cc
static void ResetWeakHandle(bool global_gc);
// test-heap.cc
static AllocationResult AllocateByteArrayForTest(Heap* heap, int length,
PretenureFlag pretenure);
// test-mark-compact.cc
static AllocationResult AllocateMapForTest(v8::internal::Isolate* isolate);
static AllocationResult AllocateFixedArrayForTest(Heap* heap, int length,
PretenureFlag pretenure);
};
} // namespace heap

View File

@ -4,7 +4,7 @@
#include "test/cctest/heap/heap-utils.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/heap/heap-inl.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact.h"

View File

@ -39,28 +39,24 @@ namespace v8 {
namespace internal {
namespace heap {
AllocationResult HeapTester::AllocateAfterFailures() {
Handle<Object> HeapTester::TestAllocateAfterFailures() {
// Similar to what the factory's retrying logic does in the last-resort case,
// we wrap the allocator function in an AlwaysAllocateScope. Test that
// all allocations succeed immediately without any retry.
CcTest::CollectAllAvailableGarbage();
AlwaysAllocateScope scope(CcTest::i_isolate());
Heap* heap = CcTest::heap();
int size = FixedArray::SizeFor(100);
// New space.
heap->AllocateByteArray(100).ToObjectChecked();
heap->AllocateFixedArray(100, NOT_TENURED).ToObjectChecked();
HeapObject* obj = heap->AllocateRaw(size, NEW_SPACE).ToObjectChecked();
// In order to pass heap verification on Isolate teardown, mark the
// allocated area as a filler.
heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
// Make sure we can allocate through optimized allocation functions
// for specific kinds.
heap->AllocateFixedArray(100).ToObjectChecked();
heap->AllocateHeapNumber().ToObjectChecked();
Object* object = heap->AllocateJSObject(
*CcTest::i_isolate()->object_function()).ToObjectChecked();
heap->CopyJSObject(JSObject::cast(object)).ToObjectChecked();
// Old data space.
// Old space.
heap::SimulateFullSpace(heap->old_space());
heap->AllocateByteArray(100, TENURED).ToObjectChecked();
// Old pointer space.
heap::SimulateFullSpace(heap->old_space());
heap->AllocateFixedArray(10000, TENURED).ToObjectChecked();
obj = heap->AllocateRaw(size, OLD_SPACE).ToObjectChecked();
heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
// Large object space.
static const size_t kLargeObjectSpaceFillerLength =
@ -70,34 +66,26 @@ AllocationResult HeapTester::AllocateAfterFailures() {
CHECK_GT(kLargeObjectSpaceFillerSize,
static_cast<size_t>(heap->old_space()->AreaSize()));
while (heap->OldGenerationSpaceAvailable() > kLargeObjectSpaceFillerSize) {
heap->AllocateFixedArray(
kLargeObjectSpaceFillerLength, TENURED).ToObjectChecked();
obj = heap->AllocateRaw(kLargeObjectSpaceFillerSize, OLD_SPACE)
.ToObjectChecked();
heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
}
heap->AllocateFixedArray(
kLargeObjectSpaceFillerLength, TENURED).ToObjectChecked();
obj = heap->AllocateRaw(kLargeObjectSpaceFillerSize, OLD_SPACE)
.ToObjectChecked();
heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
// Map space.
heap::SimulateFullSpace(heap->map_space());
int instance_size = JSObject::kHeaderSize;
heap->AllocateMap(JS_OBJECT_TYPE, instance_size).ToObjectChecked();
obj = heap->AllocateRaw(Map::kSize, MAP_SPACE).ToObjectChecked();
heap->CreateFillerObjectAt(obj->address(), Map::kSize,
ClearRecordedSlots::kNo);
// Test that we can allocate in old pointer space and code space.
// Code space.
heap::SimulateFullSpace(heap->code_space());
heap->AllocateFixedArray(100, TENURED).ToObjectChecked();
Code* illegal = CcTest::i_isolate()->builtins()->builtin(Builtins::kIllegal);
heap->CopyCode(illegal, illegal->code_data_container()).ToObjectChecked();
// Return success.
return heap->true_value();
}
Handle<Object> HeapTester::TestAllocateAfterFailures() {
// Similar to what the CALL_AND_RETRY macro does in the last-resort case, we
// are wrapping the allocator function in an AlwaysAllocateScope. Test that
// all allocations succeed immediately without any retry.
CcTest::CollectAllAvailableGarbage();
AlwaysAllocateScope scope(CcTest::i_isolate());
return handle(AllocateAfterFailures().ToObjectChecked(), CcTest::i_isolate());
size = CcTest::i_isolate()->builtins()->builtin(Builtins::kIllegal)->Size();
obj = heap->AllocateRaw(size, CODE_SPACE).ToObjectChecked();
heap->CreateFillerObjectAt(obj->address(), size, ClearRecordedSlots::kNo);
return CcTest::i_isolate()->factory()->true_value();
}

View File

@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/heap/mark-compact.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -36,9 +36,9 @@
#include "src/deoptimizer.h"
#include "src/elements.h"
#include "src/execution.h"
#include "src/factory.h"
#include "src/field-type.h"
#include "src/global-handles.h"
#include "src/heap/factory.h"
#include "src/heap/gc-tracer.h"
#include "src/heap/incremental-marking.h"
#include "src/heap/mark-compact.h"
@ -1550,6 +1550,7 @@ TEST(TestSizeOfRegExpCode) {
HEAP_TEST(TestSizeOfObjects) {
v8::V8::Initialize();
Isolate* isolate = CcTest::i_isolate();
Heap* heap = CcTest::heap();
MarkCompactCollector* collector = heap->mark_compact_collector();
@ -1562,13 +1563,14 @@ HEAP_TEST(TestSizeOfObjects) {
int initial_size = static_cast<int>(heap->SizeOfObjects());
{
HandleScope scope(isolate);
// Allocate objects on several different old-space pages so that
// concurrent sweeper threads will be busy sweeping the old space on
// subsequent GC runs.
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
for (int i = 1; i <= 100; i++) {
heap->AllocateFixedArray(8192, TENURED).ToObjectChecked();
isolate->factory()->NewFixedArray(8192, TENURED);
CHECK_EQ(initial_size + i * filler_size,
static_cast<int>(heap->SizeOfObjects()));
}
@ -5027,6 +5029,25 @@ TEST(SharedFunctionInfoIterator) {
CHECK_EQ(0, sfi_count);
}
// This is the same as Factory::NewByteArray, except it doesn't retry on
// allocation failure.
AllocationResult HeapTester::AllocateByteArrayForTest(Heap* heap, int length,
PretenureFlag pretenure) {
DCHECK(length >= 0 && length <= ByteArray::kMaxLength);
int size = ByteArray::SizeFor(length);
AllocationSpace space = heap->SelectSpace(pretenure);
HeapObject* result = nullptr;
{
AllocationResult allocation = heap->AllocateRaw(size, space);
if (!allocation.To(&result)) return allocation;
}
result->set_map_after_allocation(heap->byte_array_map(), SKIP_WRITE_BARRIER);
ByteArray::cast(result)->set_length(length);
ByteArray::cast(result)->clear_padding();
return result;
}
HEAP_TEST(Regress587004) {
ManualGCScope manual_gc_scope;
#ifdef VERIFY_HEAP
@ -5055,7 +5076,7 @@ HEAP_TEST(Regress587004) {
// Don't allow old space expansion. The test works without this flag too,
// but becomes very slow.
heap->set_force_oom(true);
while (heap->AllocateByteArray(M, TENURED).To(&byte_array)) {
while (AllocateByteArrayForTest(heap, M, TENURED).To(&byte_array)) {
for (int j = 0; j < M; j++) {
byte_array->set(j, 0x31);
}
@ -5082,7 +5103,7 @@ HEAP_TEST(Regress589413) {
// Fill the new space with byte arrays with elements looking like pointers.
const int M = 256;
ByteArray* byte_array;
while (heap->AllocateByteArray(M).To(&byte_array)) {
while (AllocateByteArrayForTest(heap, M, NOT_TENURED).To(&byte_array)) {
for (int j = 0; j < M; j++) {
byte_array->set(j, 0x31);
}
@ -5099,7 +5120,7 @@ HEAP_TEST(Regress589413) {
FixedArray* array;
// Fill all pages with fixed arrays.
heap->set_force_oom(true);
while (heap->AllocateFixedArray(N, TENURED).To(&array)) {
while (AllocateFixedArrayForTest(heap, N, TENURED).To(&array)) {
arrays.push_back(array);
pages.insert(Page::FromAddress(array->address()));
// Add the array in root set.
@ -5107,7 +5128,7 @@ HEAP_TEST(Regress589413) {
}
// Expand and full one complete page with fixed arrays.
heap->set_force_oom(false);
while (heap->AllocateFixedArray(N, TENURED).To(&array)) {
while (AllocateFixedArrayForTest(heap, N, TENURED).To(&array)) {
arrays.push_back(array);
pages.insert(Page::FromAddress(array->address()));
// Add the array in root set.
@ -5824,20 +5845,18 @@ HEAP_TEST(RegressMissingWriteBarrierInAllocate) {
Isolate* isolate = heap->isolate();
CcTest::CollectAllGarbage();
heap::SimulateIncrementalMarking(heap, false);
Map* map;
Handle<Map> map;
{
AlwaysAllocateScope always_allocate(isolate);
map = Map::cast(heap->AllocateMap(HEAP_NUMBER_TYPE, HeapNumber::kSize)
.ToObjectChecked());
map = isolate->factory()->NewMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
}
heap->incremental_marking()->StartBlackAllocationForTesting();
Handle<HeapObject> object;
{
AlwaysAllocateScope always_allocate(isolate);
object = Handle<HeapObject>(
heap->Allocate(map, OLD_SPACE).ToObjectChecked(), isolate);
object = handle(isolate->factory()->NewForTest(map, TENURED), isolate);
}
// The object is black. If Heap::Allocate sets the map without write-barrier,
// The object is black. If Factory::New sets the map without write-barrier,
// then the map is white and will be freed prematurely.
heap::SimulateIncrementalMarking(heap, true);
CcTest::CollectAllGarbage();

View File

@ -32,13 +32,13 @@ Page* HeapTester::AllocateByteArraysOnPage(
AlwaysAllocateScope always_allocate(isolate);
heap::SimulateFullSpace(old_space);
ByteArray* byte_array;
CHECK(heap->AllocateByteArray(kLength, TENURED).To(&byte_array));
CHECK(AllocateByteArrayForTest(heap, kLength, TENURED).To(&byte_array));
byte_arrays->push_back(byte_array);
page = Page::FromAddress(byte_array->address());
CHECK_EQ(page->area_size() % kSize, 0u);
size_t n = page->area_size() / kSize;
for (size_t i = 1; i < n; i++) {
CHECK(heap->AllocateByteArray(kLength, TENURED).To(&byte_array));
CHECK(AllocateByteArrayForTest(heap, kLength, TENURED).To(&byte_array));
byte_arrays->push_back(byte_array);
CHECK_EQ(page, Page::FromAddress(byte_array->address()));
}

View File

@ -96,6 +96,38 @@ HEAP_TEST(NoPromotion) {
}
}
// This is the same as Factory::NewMap, except it doesn't retry on
// allocation failure.
AllocationResult HeapTester::AllocateMapForTest(Isolate* isolate) {
Heap* heap = isolate->heap();
HeapObject* obj;
AllocationResult alloc = heap->AllocateRaw(Map::kSize, MAP_SPACE);
if (!alloc.To(&obj)) return alloc;
obj->set_map_after_allocation(heap->meta_map(), SKIP_WRITE_BARRIER);
return isolate->factory()->InitializeMap(Map::cast(obj), JS_OBJECT_TYPE,
JSObject::kHeaderSize,
TERMINAL_FAST_ELEMENTS_KIND, 0);
}
// This is the same as Factory::NewFixedArray, except it doesn't retry
// on allocation failure.
AllocationResult HeapTester::AllocateFixedArrayForTest(
Heap* heap, int length, PretenureFlag pretenure) {
DCHECK(length >= 0 && length <= FixedArray::kMaxLength);
int size = FixedArray::SizeFor(length);
AllocationSpace space = heap->SelectSpace(pretenure);
HeapObject* obj;
{
AllocationResult result = heap->AllocateRaw(size, space);
if (!result.To(&obj)) return result;
}
obj->set_map_after_allocation(heap->fixed_array_map(), SKIP_WRITE_BARRIER);
FixedArray* array = FixedArray::cast(obj);
array->set_length(length);
MemsetPointer(array->data_start(), heap->undefined_value(), length);
return array;
}
HEAP_TEST(MarkCompactCollector) {
FLAG_incremental_marking = false;
FLAG_retain_maps_for_n_gc = 0;
@ -114,17 +146,17 @@ HEAP_TEST(MarkCompactCollector) {
const int arraysize = 100;
AllocationResult allocation;
do {
allocation = heap->AllocateFixedArray(arraysize);
allocation = AllocateFixedArrayForTest(heap, arraysize, NOT_TENURED);
} while (!allocation.IsRetry());
CcTest::CollectGarbage(NEW_SPACE);
heap->AllocateFixedArray(arraysize).ToObjectChecked();
AllocateFixedArrayForTest(heap, arraysize, NOT_TENURED).ToObjectChecked();
// keep allocating maps until it fails
do {
allocation = heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize);
allocation = AllocateMapForTest(isolate);
} while (!allocation.IsRetry());
CcTest::CollectGarbage(MAP_SPACE);
heap->AllocateMap(JS_OBJECT_TYPE, JSObject::kHeaderSize).ToObjectChecked();
AllocateMapForTest(isolate).ToObjectChecked();
{ HandleScope scope(isolate);
// allocate a garbage

View File

@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/factory.h"
#include "src/heap/array-buffer-tracker.h"
#include "src/heap/factory.h"
#include "src/heap/spaces-inl.h"
#include "src/isolate.h"
#include "src/objects-inl.h"

View File

@ -28,7 +28,7 @@
#include <stdlib.h>
#include "src/base/platform/platform.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/heap/spaces-inl.h"
#include "src/objects-inl.h"
#include "src/snapshot/snapshot.h"

View File

@ -4,7 +4,7 @@
#include "src/api.h"
#include "src/assembler-inl.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/isolate.h"
#include "test/cctest/cctest.h"
#include "test/cctest/heap/heap-utils.h"

View File

@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/factory.h" // for i::Factory::NewExternalStringFrom*Byte
#include "src/feedback-vector-inl.h" // for include "src/factory.h"
#include "src/heap/factory-inl.h"
#include "src/objects-inl.h"
#include "src/parsing/scanner-character-streams.h"
#include "src/parsing/scanner.h"

View File

@ -4,7 +4,7 @@
#include <stdlib.h>
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/objects-inl.h"
#include "test/cctest/cctest.h"

View File

@ -31,7 +31,7 @@
#include "src/base/utils/random-number-generator.h"
#include "src/disassembler.h"
#include "src/double.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/macro-assembler.h"
#include "src/ostreams.h"
#include "src/simulator.h"

View File

@ -41,7 +41,7 @@
#include "src/arm64/utils-arm64.h"
#include "src/base/platform/platform.h"
#include "src/base/utils/random-number-generator.h"
#include "src/factory.h"
#include "src/heap/factory.h"
#include "src/macro-assembler.h"
#include "test/cctest/cctest.h"
#include "test/cctest/test-utils-arm64.h"

Some files were not shown because too many files have changed in this diff Show More