2012-01-26 21:47:57 +00:00
|
|
|
// Copyright 2012 the V8 project authors. All rights reserved.
|
2013-03-07 11:12:26 +00:00
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are
|
|
|
|
// met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright
|
|
|
|
// notice, this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above
|
|
|
|
// copyright notice, this list of conditions and the following
|
|
|
|
// disclaimer in the documentation and/or other materials provided
|
|
|
|
// with the distribution.
|
|
|
|
// * Neither the name of Google Inc. nor the names of its
|
|
|
|
// contributors may be used to endorse or promote products derived
|
|
|
|
// from this software without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
2013-12-18 08:09:37 +00:00
|
|
|
#include <utility>
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-05-17 12:13:44 +00:00
|
|
|
#include "src/api/api-inl.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/assembler-inl.h"
|
|
|
|
#include "src/codegen/compilation-cache.h"
|
|
|
|
#include "src/codegen/macro-assembler-inl.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/debug/debug.h"
|
2019-05-20 13:01:00 +00:00
|
|
|
#include "src/deoptimizer/deoptimizer.h"
|
2019-05-22 07:55:37 +00:00
|
|
|
#include "src/execution/execution.h"
|
2019-05-22 12:44:24 +00:00
|
|
|
#include "src/handles/global-handles.h"
|
2019-05-13 16:13:44 +00:00
|
|
|
#include "src/heap/combined-heap.h"
|
2018-04-09 19:11:22 +00:00
|
|
|
#include "src/heap/factory.h"
|
2015-08-20 15:47:59 +00:00
|
|
|
#include "src/heap/gc-tracer.h"
|
2019-02-14 21:10:30 +00:00
|
|
|
#include "src/heap/heap-inl.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/heap/incremental-marking.h"
|
|
|
|
#include "src/heap/mark-compact.h"
|
2015-10-29 13:59:34 +00:00
|
|
|
#include "src/heap/memory-reducer.h"
|
2018-08-20 13:30:37 +00:00
|
|
|
#include "src/heap/remembered-set.h"
|
2014-08-22 11:43:39 +00:00
|
|
|
#include "src/ic/ic.h"
|
2019-05-24 13:51:59 +00:00
|
|
|
#include "src/numbers/hash-seed-inl.h"
|
2019-05-20 08:54:18 +00:00
|
|
|
#include "src/objects/elements.h"
|
|
|
|
#include "src/objects/field-type.h"
|
2019-02-08 12:43:15 +00:00
|
|
|
#include "src/objects/frame-array-inl.h"
|
2018-12-17 17:01:48 +00:00
|
|
|
#include "src/objects/heap-number-inl.h"
|
2018-07-25 14:11:56 +00:00
|
|
|
#include "src/objects/js-array-inl.h"
|
2018-05-23 13:29:02 +00:00
|
|
|
#include "src/objects/js-collection-inl.h"
|
2018-08-09 09:08:20 +00:00
|
|
|
#include "src/objects/managed.h"
|
2019-05-23 08:51:46 +00:00
|
|
|
#include "src/objects/objects-inl.h"
|
2018-10-23 23:02:20 +00:00
|
|
|
#include "src/objects/slots.h"
|
2019-05-20 08:54:18 +00:00
|
|
|
#include "src/objects/transitions.h"
|
2019-06-17 15:16:39 +00:00
|
|
|
#include "src/regexp/regexp.h"
|
2015-05-07 10:25:36 +00:00
|
|
|
#include "src/snapshot/snapshot.h"
|
2019-05-23 13:27:57 +00:00
|
|
|
#include "src/utils/ostreams.h"
|
2014-06-03 08:12:43 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2015-12-09 11:25:26 +00:00
|
|
|
#include "test/cctest/heap/heap-tester.h"
|
2016-05-20 13:30:22 +00:00
|
|
|
#include "test/cctest/heap/heap-utils.h"
|
2015-10-01 13:48:05 +00:00
|
|
|
#include "test/cctest/test-feedback-vector.h"
|
2017-07-28 07:01:59 +00:00
|
|
|
#include "test/cctest/test-transitions.h"
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-08-21 07:09:08 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
2017-08-11 10:04:47 +00:00
|
|
|
namespace heap {
|
2015-08-21 07:09:08 +00:00
|
|
|
|
2017-06-16 10:07:41 +00:00
|
|
|
// We only start allocation-site tracking with the second instantiation.
|
|
|
|
static const int kPretenureCreationCount =
|
|
|
|
AllocationSite::kPretenureMinimumCreated + 1;
|
|
|
|
|
2018-11-13 06:16:42 +00:00
|
|
|
static void CheckMap(Map map, int type, int instance_size) {
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(map.IsHeapObject());
|
2019-05-13 16:13:44 +00:00
|
|
|
DCHECK(IsValidHeapObject(CcTest::heap(), map));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(ReadOnlyRoots(CcTest::heap()).meta_map(), map.map());
|
|
|
|
CHECK_EQ(type, map.instance_type());
|
|
|
|
CHECK_EQ(instance_size, map.instance_size());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(HeapMaps) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-07-04 09:10:05 +00:00
|
|
|
ReadOnlyRoots roots(CcTest::heap());
|
|
|
|
CheckMap(roots.meta_map(), MAP_TYPE, Map::kSize);
|
|
|
|
CheckMap(roots.heap_number_map(), HEAP_NUMBER_TYPE, HeapNumber::kSize);
|
|
|
|
CheckMap(roots.fixed_array_map(), FIXED_ARRAY_TYPE, kVariableSizeSentinel);
|
|
|
|
CheckMap(roots.hash_table_map(), HASH_TABLE_TYPE, kVariableSizeSentinel);
|
|
|
|
CheckMap(roots.string_map(), STRING_TYPE, kVariableSizeSentinel);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2017-02-01 09:29:50 +00:00
|
|
|
static void VerifyStoredPrototypeMap(Isolate* isolate,
|
|
|
|
int stored_map_context_index,
|
|
|
|
int stored_ctor_context_index) {
|
|
|
|
Handle<Context> context = isolate->native_context();
|
|
|
|
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<Map> this_map(Map::cast(context->get(stored_map_context_index)),
|
|
|
|
isolate);
|
2017-02-01 09:29:50 +00:00
|
|
|
|
|
|
|
Handle<JSFunction> fun(
|
2018-06-23 09:05:50 +00:00
|
|
|
JSFunction::cast(context->get(stored_ctor_context_index)), isolate);
|
2019-05-23 07:47:44 +00:00
|
|
|
Handle<JSObject> proto(JSObject::cast(fun->initial_map().prototype()),
|
2018-06-23 09:05:50 +00:00
|
|
|
isolate);
|
|
|
|
Handle<Map> that_map(proto->map(), isolate);
|
2017-02-01 09:29:50 +00:00
|
|
|
|
|
|
|
CHECK(proto->HasFastProperties());
|
|
|
|
CHECK_EQ(*this_map, *that_map);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks that critical maps stored on the context (mostly used for fast-path
|
|
|
|
// checks) are unchanged after initialization.
|
|
|
|
TEST(ContextMaps) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
VerifyStoredPrototypeMap(isolate,
|
|
|
|
Context::STRING_FUNCTION_PROTOTYPE_MAP_INDEX,
|
|
|
|
Context::STRING_FUNCTION_INDEX);
|
|
|
|
VerifyStoredPrototypeMap(isolate, Context::REGEXP_PROTOTYPE_MAP_INDEX,
|
|
|
|
Context::REGEXP_FUNCTION_INDEX);
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2017-02-02 12:38:51 +00:00
|
|
|
TEST(InitialObjects) {
|
|
|
|
LocalContext env;
|
|
|
|
HandleScope scope(CcTest::i_isolate());
|
|
|
|
Handle<Context> context = v8::Utils::OpenHandle(*env);
|
|
|
|
// Initial ArrayIterator prototype.
|
|
|
|
CHECK_EQ(
|
|
|
|
context->initial_array_iterator_prototype(),
|
|
|
|
*v8::Utils::OpenHandle(*CompileRun("[][Symbol.iterator]().__proto__")));
|
|
|
|
// Initial Array prototype.
|
|
|
|
CHECK_EQ(context->initial_array_prototype(),
|
|
|
|
*v8::Utils::OpenHandle(*CompileRun("Array.prototype")));
|
|
|
|
// Initial Generator prototype.
|
|
|
|
CHECK_EQ(context->initial_generator_prototype(),
|
|
|
|
*v8::Utils::OpenHandle(
|
|
|
|
*CompileRun("(function*(){}).__proto__.prototype")));
|
|
|
|
// Initial Iterator prototype.
|
|
|
|
CHECK_EQ(context->initial_iterator_prototype(),
|
|
|
|
*v8::Utils::OpenHandle(
|
|
|
|
*CompileRun("[][Symbol.iterator]().__proto__.__proto__")));
|
|
|
|
// Initial Object prototype.
|
|
|
|
CHECK_EQ(context->initial_object_prototype(),
|
|
|
|
*v8::Utils::OpenHandle(*CompileRun("Object.prototype")));
|
|
|
|
}
|
|
|
|
|
2018-12-25 00:19:47 +00:00
|
|
|
static void CheckOddball(Isolate* isolate, Object obj, const char* string) {
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(obj.IsOddball());
|
2013-09-03 06:59:01 +00:00
|
|
|
Handle<Object> handle(obj, isolate);
|
2018-12-25 00:19:47 +00:00
|
|
|
Object print_string = *Object::ToString(isolate, handle).ToHandleChecked();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(String::cast(print_string).IsOneByteEqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckSmi(Isolate* isolate, int value, const char* string) {
|
2013-09-03 06:59:01 +00:00
|
|
|
Handle<Object> handle(Smi::FromInt(value), isolate);
|
2018-12-25 00:19:47 +00:00
|
|
|
Object print_string = *Object::ToString(isolate, handle).ToHandleChecked();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(String::cast(print_string).IsOneByteEqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckNumber(Isolate* isolate, double value, const char* string) {
|
2014-04-16 06:18:37 +00:00
|
|
|
Handle<Object> number = isolate->factory()->NewNumber(value);
|
|
|
|
CHECK(number->IsNumber());
|
|
|
|
Handle<Object> print_string =
|
2015-08-28 09:21:23 +00:00
|
|
|
Object::ToString(isolate, number).ToHandleChecked();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(String::cast(*print_string).IsOneByteEqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2016-08-04 08:12:40 +00:00
|
|
|
void CheckEmbeddedObjectsAreEqual(Handle<Code> lhs, Handle<Code> rhs) {
|
2019-04-30 06:57:15 +00:00
|
|
|
int mode_mask = RelocInfo::ModeMask(RelocInfo::FULL_EMBEDDED_OBJECT);
|
2016-08-04 08:12:40 +00:00
|
|
|
RelocIterator lhs_it(*lhs, mode_mask);
|
|
|
|
RelocIterator rhs_it(*rhs, mode_mask);
|
|
|
|
while (!lhs_it.done() && !rhs_it.done()) {
|
|
|
|
CHECK(lhs_it.rinfo()->target_object() == rhs_it.rinfo()->target_object());
|
|
|
|
|
|
|
|
lhs_it.next();
|
|
|
|
rhs_it.next();
|
|
|
|
}
|
|
|
|
CHECK(lhs_it.done() == rhs_it.done());
|
|
|
|
}
|
|
|
|
|
|
|
|
HEAP_TEST(TestNewSpaceRefsInCopiedCode) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope sc(isolate);
|
|
|
|
|
2017-07-06 09:13:09 +00:00
|
|
|
Handle<HeapNumber> value = factory->NewHeapNumber(1.000123);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*value));
|
2016-08-04 08:12:40 +00:00
|
|
|
|
|
|
|
i::byte buffer[i::Assembler::kMinimalBufferSize];
|
2019-01-16 18:29:52 +00:00
|
|
|
MacroAssembler masm(isolate, v8::internal::CodeObjectRequired::kYes,
|
|
|
|
ExternalAssemblerBuffer(buffer, sizeof(buffer)));
|
2016-08-04 08:12:40 +00:00
|
|
|
// Add a new-space reference to the code.
|
|
|
|
masm.Push(value);
|
|
|
|
|
|
|
|
CodeDesc desc;
|
2017-05-31 14:00:11 +00:00
|
|
|
masm.GetCode(isolate, &desc);
|
2019-04-29 16:15:47 +00:00
|
|
|
Handle<Code> code = Factory::CodeBuilder(isolate, desc, Code::STUB).Build();
|
2016-08-04 08:12:40 +00:00
|
|
|
|
2017-11-28 09:49:59 +00:00
|
|
|
Handle<Code> copy;
|
|
|
|
{
|
|
|
|
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
|
|
|
|
copy = factory->CopyCode(code);
|
|
|
|
}
|
2016-08-04 08:12:40 +00:00
|
|
|
|
|
|
|
CheckEmbeddedObjectsAreEqual(code, copy);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2016-08-04 08:12:40 +00:00
|
|
|
CheckEmbeddedObjectsAreEqual(code, copy);
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
static void CheckFindCodeObject(Isolate* isolate) {
|
2008-08-22 13:33:59 +00:00
|
|
|
// Test FindCodeObject
|
|
|
|
#define __ assm.
|
|
|
|
|
2019-01-16 18:29:52 +00:00
|
|
|
Assembler assm(AssemblerOptions{});
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
__ nop(); // supported on all architectures
|
|
|
|
|
|
|
|
CodeDesc desc;
|
2017-05-31 14:00:11 +00:00
|
|
|
assm.GetCode(isolate, &desc);
|
2019-04-29 16:15:47 +00:00
|
|
|
Handle<Code> code = Factory::CodeBuilder(isolate, desc, Code::STUB).Build();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(code->IsCode());
|
|
|
|
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj = HeapObject::cast(*code);
|
2019-05-23 07:47:44 +00:00
|
|
|
Address obj_addr = obj.address();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
for (int i = 0; i < obj.Size(); i += kTaggedSize) {
|
2018-12-25 00:19:47 +00:00
|
|
|
Object found = isolate->FindCodeObject(obj_addr + i);
|
2014-04-16 11:38:56 +00:00
|
|
|
CHECK_EQ(*code, found);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-29 16:15:47 +00:00
|
|
|
Handle<Code> copy = Factory::CodeBuilder(isolate, desc, Code::STUB).Build();
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj_copy = HeapObject::cast(*copy);
|
2018-12-25 00:19:47 +00:00
|
|
|
Object not_right =
|
2019-05-23 07:47:44 +00:00
|
|
|
isolate->FindCodeObject(obj_copy.address() + obj_copy.Size() / 2);
|
2014-04-16 11:38:56 +00:00
|
|
|
CHECK(not_right != *code);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-19 15:25:04 +00:00
|
|
|
TEST(HandleNull) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope outer_scope(isolate);
|
|
|
|
LocalContext context;
|
2018-12-25 00:19:47 +00:00
|
|
|
Handle<Object> n(Object(0), isolate);
|
2014-03-19 15:25:04 +00:00
|
|
|
CHECK(!n.is_null());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(HeapObjects) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-02-25 14:46:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope sc(isolate);
|
2014-04-16 06:18:37 +00:00
|
|
|
Handle<Object> value = factory->NewNumber(1.000123);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1.000123, value->Number());
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumber(1.0);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1.0, value->Number());
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromInt(1024);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(1024.0, value->Number());
|
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromInt(Smi::kMinValue);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
2014-04-16 06:18:37 +00:00
|
|
|
CHECK_EQ(Smi::kMinValue, Handle<Smi>::cast(value)->value());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromInt(Smi::kMaxValue);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsSmi());
|
|
|
|
CHECK(value->IsNumber());
|
2014-04-16 06:18:37 +00:00
|
|
|
CHECK_EQ(Smi::kMaxValue, Handle<Smi>::cast(value)->value());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-01-16 07:42:00 +00:00
|
|
|
#if !defined(V8_TARGET_ARCH_64_BIT)
|
2009-10-08 12:36:12 +00:00
|
|
|
// TODO(lrn): We need a NumberFromIntptr function in order to test this.
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromInt(Smi::kMinValue - 1);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(static_cast<double>(Smi::kMinValue - 1), value->Number());
|
2009-10-08 12:36:12 +00:00
|
|
|
#endif
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromUint(static_cast<uint32_t>(Smi::kMaxValue) + 1);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
2009-10-08 12:36:12 +00:00
|
|
|
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(Smi::kMaxValue) + 1),
|
|
|
|
value->Number());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-16 06:18:37 +00:00
|
|
|
value = factory->NewNumberFromUint(static_cast<uint32_t>(1) << 31);
|
2013-01-07 15:02:56 +00:00
|
|
|
CHECK(value->IsHeapNumber());
|
|
|
|
CHECK(value->IsNumber());
|
|
|
|
CHECK_EQ(static_cast<double>(static_cast<uint32_t>(1) << 31),
|
|
|
|
value->Number());
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// nan oddball checks
|
2014-04-16 06:18:37 +00:00
|
|
|
CHECK(factory->nan_value()->IsNumber());
|
|
|
|
CHECK(std::isnan(factory->nan_value()->Number()));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<String> s = factory->NewStringFromStaticChars("fisk hest ");
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(s->IsString());
|
|
|
|
CHECK_EQ(10, s->length());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:34:20 +00:00
|
|
|
Handle<String> object_string = Handle<String>::cast(factory->Object_string());
|
2019-05-23 07:47:44 +00:00
|
|
|
Handle<JSGlobalObject> global(CcTest::i_isolate()->context().global_object(),
|
2018-06-23 09:05:50 +00:00
|
|
|
isolate);
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(global, object_string));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for oddballs
|
2018-07-04 09:10:05 +00:00
|
|
|
ReadOnlyRoots roots(heap);
|
|
|
|
CheckOddball(isolate, roots.true_value(), "true");
|
|
|
|
CheckOddball(isolate, roots.false_value(), "false");
|
|
|
|
CheckOddball(isolate, roots.null_value(), "null");
|
|
|
|
CheckOddball(isolate, roots.undefined_value(), "undefined");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for Smis
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckSmi(isolate, 0, "0");
|
|
|
|
CheckSmi(isolate, 42, "42");
|
|
|
|
CheckSmi(isolate, -42, "-42");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check ToString for Numbers
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckNumber(isolate, 1.1, "1.1");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-25 14:46:09 +00:00
|
|
|
CheckFindCodeObject(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Tagging) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2009-05-22 14:01:06 +00:00
|
|
|
int request = 24;
|
2010-05-27 12:30:45 +00:00
|
|
|
CHECK_EQ(request, static_cast<int>(OBJECT_POINTER_ALIGN(request)));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(Smi::FromInt(42).IsSmi());
|
|
|
|
CHECK(Smi::FromInt(Smi::kMinValue).IsSmi());
|
|
|
|
CHECK(Smi::FromInt(Smi::kMaxValue).IsSmi());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GarbageCollection) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope sc(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Check GC.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
Handle<JSGlobalObject> global(CcTest::i_isolate()->context().global_object(),
|
2018-06-23 09:05:50 +00:00
|
|
|
isolate);
|
2013-02-28 17:03:34 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<String> prop_namex = factory->InternalizeUtf8String("theSlotx");
|
|
|
|
Handle<String> obj_name = factory->InternalizeUtf8String("theObject");
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
|
|
|
Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate a function and keep it in global object's property.
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> function = factory->NewFunctionForTest(name);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, global, name, function).Check();
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate an object. Unrooted after leaving the scope.
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, prop_name, twenty_three).Check();
|
|
|
|
Object::SetProperty(isolate, obj, prop_namex, twenty_four).Check();
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2014-04-11 12:47:34 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23),
|
2018-07-17 08:49:20 +00:00
|
|
|
*Object::GetProperty(isolate, obj, prop_name).ToHandleChecked());
|
2014-04-11 12:47:34 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(24),
|
2018-07-17 08:49:20 +00:00
|
|
|
*Object::GetProperty(isolate, obj, prop_namex).ToHandleChecked());
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// Function should be alive.
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(global, name));
|
2010-03-05 09:51:10 +00:00
|
|
|
// Check function is retained.
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> func_value =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, global, name).ToHandleChecked();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(func_value->IsJSFunction());
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope inner_scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
// Allocate another object, make it reachable from global.
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, global, obj_name, obj).Check();
|
|
|
|
Object::SetProperty(isolate, obj, prop_name, twenty_three).Check();
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// After gc, it should survive.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(global, obj_name));
|
2014-04-11 12:47:34 +00:00
|
|
|
Handle<Object> obj =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, global, obj_name).ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
CHECK(obj->IsJSObject());
|
2014-04-11 12:47:34 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23),
|
2018-07-17 08:49:20 +00:00
|
|
|
*Object::GetProperty(isolate, obj, prop_name).ToHandleChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
static void VerifyStringAllocation(Isolate* isolate, const char* string) {
|
|
|
|
HandleScope scope(isolate);
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> s = isolate->factory()->NewStringFromUtf8(
|
|
|
|
CStrVector(string)).ToHandleChecked();
|
2019-04-29 14:56:08 +00:00
|
|
|
CHECK_EQ(strlen(string), s->length());
|
2009-03-17 09:33:06 +00:00
|
|
|
for (int index = 0; index < s->length(); index++) {
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK_EQ(static_cast<uint16_t>(string[index]), s->Get(index));
|
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(String) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = reinterpret_cast<Isolate*>(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-03-15 12:06:53 +00:00
|
|
|
VerifyStringAllocation(isolate, "a");
|
|
|
|
VerifyStringAllocation(isolate, "ab");
|
|
|
|
VerifyStringAllocation(isolate, "abc");
|
|
|
|
VerifyStringAllocation(isolate, "abcd");
|
|
|
|
VerifyStringAllocation(isolate, "fiskerdrengen er paa havet");
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(LocalHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
const char* name = "Kasper the spunky";
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> string = factory->NewStringFromAsciiChecked(name);
|
2019-04-29 14:56:08 +00:00
|
|
|
CHECK_EQ(strlen(name), string->length());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(GlobalHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
Handle<Object> h3;
|
|
|
|
Handle<Object> h4;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromStaticChars("fisk");
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
h1 = global_handles->Create(*i);
|
|
|
|
h2 = global_handles->Create(*u);
|
|
|
|
h3 = global_handles->Create(*i);
|
|
|
|
h4 = global_handles->Create(*u);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// after gc, it should survive
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK((*h1).IsString());
|
|
|
|
CHECK((*h2).IsHeapNumber());
|
|
|
|
CHECK((*h3).IsString());
|
|
|
|
CHECK((*h4).IsHeapNumber());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK_EQ(*h3, *h1);
|
2013-12-18 08:09:37 +00:00
|
|
|
GlobalHandles::Destroy(h1.location());
|
|
|
|
GlobalHandles::Destroy(h3.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK_EQ(*h4, *h2);
|
2013-12-18 08:09:37 +00:00
|
|
|
GlobalHandles::Destroy(h2.location());
|
|
|
|
GlobalHandles::Destroy(h4.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static bool WeakPointerCleared = false;
|
|
|
|
|
2013-12-18 08:09:37 +00:00
|
|
|
static void TestWeakGlobalHandleCallback(
|
2016-05-06 12:29:00 +00:00
|
|
|
const v8::WeakCallbackInfo<void>& data) {
|
2013-12-18 08:09:37 +00:00
|
|
|
std::pair<v8::Persistent<v8::Value>*, int>* p =
|
|
|
|
reinterpret_cast<std::pair<v8::Persistent<v8::Value>*, int>*>(
|
|
|
|
data.GetParameter());
|
|
|
|
if (p->second == 1234) WeakPointerCleared = true;
|
|
|
|
p->first->Reset();
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2017-05-02 12:14:23 +00:00
|
|
|
TEST(WeakGlobalUnmodifiedApiHandlesScavenge) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
LocalContext context;
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
|
|
|
|
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
|
|
|
|
{
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Create an Api object that is unmodified.
|
2018-12-17 13:34:08 +00:00
|
|
|
Local<v8::Function> function = FunctionTemplate::New(context->GetIsolate())
|
|
|
|
->GetFunction(context.local())
|
|
|
|
.ToLocalChecked();
|
|
|
|
Local<v8::Object> i =
|
|
|
|
function->NewInstance(context.local()).ToLocalChecked();
|
2017-05-02 12:14:23 +00:00
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
|
|
|
|
|
|
|
h1 = global_handles->Create(*u);
|
2018-12-17 13:34:08 +00:00
|
|
|
h2 = global_handles->Create(*(reinterpret_cast<internal::Address*>(*i)));
|
2017-05-02 12:14:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
|
|
|
|
GlobalHandles::MakeWeak(
|
|
|
|
h2.location(), reinterpret_cast<void*>(&handle_and_id),
|
|
|
|
&TestWeakGlobalHandleCallback, v8::WeakCallbackType::kParameter);
|
|
|
|
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK((*h1).IsHeapNumber());
|
2017-05-02 12:14:23 +00:00
|
|
|
CHECK(WeakPointerCleared);
|
|
|
|
GlobalHandles::Destroy(h1.location());
|
|
|
|
}
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(WeakGlobalHandlesMark) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_incremental_marking = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h1;
|
|
|
|
Handle<Object> h2;
|
|
|
|
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromStaticChars("fisk");
|
2013-02-15 09:27:10 +00:00
|
|
|
Handle<Object> u = factory->NewNumber(1.12344);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2011-03-18 20:35:07 +00:00
|
|
|
h1 = global_handles->Create(*i);
|
|
|
|
h2 = global_handles->Create(*u);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Make sure the objects are promoted.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(!Heap::InYoungGeneration(*h1) && !Heap::InYoungGeneration(*h2));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-12-18 08:09:37 +00:00
|
|
|
std::pair<Handle<Object>*, int> handle_and_id(&h2, 1234);
|
2016-05-06 12:29:00 +00:00
|
|
|
GlobalHandles::MakeWeak(
|
|
|
|
h2.location(), reinterpret_cast<void*>(&handle_and_id),
|
|
|
|
&TestWeakGlobalHandleCallback, v8::WeakCallbackType::kParameter);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Incremental marking potentially marked handles before they turned weak.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK((*h1).IsString());
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(WeakPointerCleared);
|
2013-12-18 08:09:37 +00:00
|
|
|
GlobalHandles::Destroy(h1.location());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
2012-08-02 14:20:38 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
TEST(DeleteWeakGlobalHandle) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-02-15 09:27:10 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
WeakPointerCleared = false;
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<Object> h;
|
|
|
|
{
|
2013-02-15 09:27:10 +00:00
|
|
|
HandleScope scope(isolate);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<Object> i = factory->NewStringFromStaticChars("fisk");
|
2011-03-18 20:35:07 +00:00
|
|
|
h = global_handles->Create(*i);
|
2010-03-05 09:51:10 +00:00
|
|
|
}
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-12-18 08:09:37 +00:00
|
|
|
std::pair<Handle<Object>*, int> handle_and_id(&h, 1234);
|
2016-05-06 12:29:00 +00:00
|
|
|
GlobalHandles::MakeWeak(h.location(), reinterpret_cast<void*>(&handle_and_id),
|
|
|
|
&TestWeakGlobalHandleCallback,
|
|
|
|
v8::WeakCallbackType::kParameter);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(!WeakPointerCleared);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK(WeakPointerCleared);
|
|
|
|
}
|
|
|
|
|
2015-07-24 12:02:41 +00:00
|
|
|
TEST(BytecodeArray) {
|
2017-06-13 09:25:18 +00:00
|
|
|
if (FLAG_never_compact) return;
|
2017-12-02 00:30:37 +00:00
|
|
|
static const uint8_t kRawBytes[] = {0xC3, 0x7E, 0xA5, 0x5A};
|
2015-07-24 12:02:41 +00:00
|
|
|
static const int kRawBytesSize = sizeof(kRawBytes);
|
2019-05-30 19:55:07 +00:00
|
|
|
static const int32_t kFrameSize = 32;
|
|
|
|
static const int32_t kParameterCount = 2;
|
2015-07-24 12:02:41 +00:00
|
|
|
|
2017-11-20 12:13:24 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
2015-07-24 12:02:41 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> constant_pool =
|
|
|
|
factory->NewFixedArray(5, AllocationType::kOld);
|
2015-08-27 11:11:09 +00:00
|
|
|
for (int i = 0; i < 5; i++) {
|
2015-08-27 12:13:23 +00:00
|
|
|
Handle<Object> number = factory->NewHeapNumber(i);
|
|
|
|
constant_pool->set(i, *number);
|
2015-08-27 11:11:09 +00:00
|
|
|
}
|
|
|
|
|
2015-07-24 12:02:41 +00:00
|
|
|
// Allocate and initialize BytecodeArray
|
2015-08-27 10:32:26 +00:00
|
|
|
Handle<BytecodeArray> array = factory->NewBytecodeArray(
|
2015-08-27 11:11:09 +00:00
|
|
|
kRawBytesSize, kRawBytes, kFrameSize, kParameterCount, constant_pool);
|
2015-07-24 12:02:41 +00:00
|
|
|
|
|
|
|
CHECK(array->IsBytecodeArray());
|
|
|
|
CHECK_EQ(array->length(), (int)sizeof(kRawBytes));
|
2015-07-24 14:56:26 +00:00
|
|
|
CHECK_EQ(array->frame_size(), kFrameSize);
|
2015-08-27 10:32:26 +00:00
|
|
|
CHECK_EQ(array->parameter_count(), kParameterCount);
|
2015-08-27 11:11:09 +00:00
|
|
|
CHECK_EQ(array->constant_pool(), *constant_pool);
|
2015-07-24 12:02:41 +00:00
|
|
|
CHECK_LE(array->address(), array->GetFirstBytecodeAddress());
|
|
|
|
CHECK_GE(array->address() + array->BytecodeArraySize(),
|
|
|
|
array->GetFirstBytecodeAddress() + array->length());
|
|
|
|
for (int i = 0; i < kRawBytesSize; i++) {
|
2018-08-21 17:13:31 +00:00
|
|
|
CHECK_EQ(Memory<uint8_t>(array->GetFirstBytecodeAddress() + i),
|
2018-04-13 22:28:05 +00:00
|
|
|
kRawBytes[i]);
|
2015-07-24 12:02:41 +00:00
|
|
|
CHECK_EQ(array->get(i), kRawBytes[i]);
|
|
|
|
}
|
|
|
|
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArray old_constant_pool_address = *constant_pool;
|
2015-08-27 11:11:09 +00:00
|
|
|
|
|
|
|
// Perform a full garbage collection and force the constant pool to be on an
|
|
|
|
// evacuation candidate.
|
2019-01-15 00:23:43 +00:00
|
|
|
Page* evac_page = Page::FromHeapObject(*constant_pool);
|
2016-11-03 12:12:38 +00:00
|
|
|
heap::ForceEvacuationCandidate(evac_page);
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-07-24 12:02:41 +00:00
|
|
|
|
2015-08-27 11:11:09 +00:00
|
|
|
// BytecodeArray should survive.
|
2015-07-24 12:02:41 +00:00
|
|
|
CHECK_EQ(array->length(), kRawBytesSize);
|
|
|
|
CHECK_EQ(array->frame_size(), kFrameSize);
|
|
|
|
for (int i = 0; i < kRawBytesSize; i++) {
|
|
|
|
CHECK_EQ(array->get(i), kRawBytes[i]);
|
2018-08-21 17:13:31 +00:00
|
|
|
CHECK_EQ(Memory<uint8_t>(array->GetFirstBytecodeAddress() + i),
|
2018-04-13 22:28:05 +00:00
|
|
|
kRawBytes[i]);
|
2015-07-24 12:02:41 +00:00
|
|
|
}
|
2015-08-27 11:11:09 +00:00
|
|
|
|
|
|
|
// Constant pool should have been migrated.
|
|
|
|
CHECK_EQ(array->constant_pool(), *constant_pool);
|
|
|
|
CHECK_NE(array->constant_pool(), old_constant_pool_address);
|
2015-07-24 12:02:41 +00:00
|
|
|
}
|
|
|
|
|
2017-08-21 08:40:04 +00:00
|
|
|
TEST(BytecodeArrayAging) {
|
2017-12-02 00:30:37 +00:00
|
|
|
static const uint8_t kRawBytes[] = {0xC3, 0x7E, 0xA5, 0x5A};
|
2017-08-21 08:40:04 +00:00
|
|
|
static const int kRawBytesSize = sizeof(kRawBytes);
|
2019-05-30 19:55:07 +00:00
|
|
|
static const int32_t kFrameSize = 32;
|
|
|
|
static const int32_t kParameterCount = 2;
|
2017-08-21 08:40:04 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
Handle<BytecodeArray> array =
|
|
|
|
factory->NewBytecodeArray(kRawBytesSize, kRawBytes, kFrameSize,
|
|
|
|
kParameterCount, factory->empty_fixed_array());
|
|
|
|
|
|
|
|
CHECK_EQ(BytecodeArray::kFirstBytecodeAge, array->bytecode_age());
|
|
|
|
array->MakeOlder();
|
|
|
|
CHECK_EQ(BytecodeArray::kQuadragenarianBytecodeAge, array->bytecode_age());
|
|
|
|
array->set_bytecode_age(BytecodeArray::kLastBytecodeAge);
|
|
|
|
array->MakeOlder();
|
|
|
|
CHECK_EQ(BytecodeArray::kLastBytecodeAge, array->bytecode_age());
|
|
|
|
}
|
2015-07-24 12:02:41 +00:00
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
static const char* not_so_random_string_table[] = {
|
|
|
|
"abstract",
|
|
|
|
"boolean",
|
|
|
|
"break",
|
|
|
|
"byte",
|
|
|
|
"case",
|
|
|
|
"catch",
|
|
|
|
"char",
|
|
|
|
"class",
|
|
|
|
"const",
|
|
|
|
"continue",
|
|
|
|
"debugger",
|
|
|
|
"default",
|
|
|
|
"delete",
|
|
|
|
"do",
|
|
|
|
"double",
|
|
|
|
"else",
|
|
|
|
"enum",
|
|
|
|
"export",
|
|
|
|
"extends",
|
|
|
|
"false",
|
|
|
|
"final",
|
|
|
|
"finally",
|
|
|
|
"float",
|
|
|
|
"for",
|
|
|
|
"function",
|
|
|
|
"goto",
|
|
|
|
"if",
|
|
|
|
"implements",
|
|
|
|
"import",
|
|
|
|
"in",
|
|
|
|
"instanceof",
|
|
|
|
"int",
|
|
|
|
"interface",
|
|
|
|
"long",
|
|
|
|
"native",
|
|
|
|
"new",
|
|
|
|
"null",
|
|
|
|
"package",
|
|
|
|
"private",
|
|
|
|
"protected",
|
|
|
|
"public",
|
|
|
|
"return",
|
|
|
|
"short",
|
|
|
|
"static",
|
|
|
|
"super",
|
|
|
|
"switch",
|
|
|
|
"synchronized",
|
|
|
|
"this",
|
|
|
|
"throw",
|
|
|
|
"throws",
|
|
|
|
"transient",
|
|
|
|
"true",
|
|
|
|
"try",
|
|
|
|
"typeof",
|
|
|
|
"var",
|
|
|
|
"void",
|
|
|
|
"volatile",
|
|
|
|
"while",
|
|
|
|
"with",
|
2018-09-13 14:55:18 +00:00
|
|
|
nullptr
|
2008-08-22 13:33:59 +00:00
|
|
|
};
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
static void CheckInternalizedStrings(const char** strings) {
|
2014-04-29 13:58:55 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2018-09-13 14:55:18 +00:00
|
|
|
for (const char* string = *strings; *strings != nullptr;
|
|
|
|
string = *strings++) {
|
2014-04-29 13:58:55 +00:00
|
|
|
HandleScope scope(isolate);
|
|
|
|
Handle<String> a =
|
|
|
|
isolate->factory()->InternalizeUtf8String(CStrVector(string));
|
|
|
|
// InternalizeUtf8String may return a failure if a GC is needed.
|
2013-02-28 17:03:34 +00:00
|
|
|
CHECK(a->IsInternalizedString());
|
2014-04-23 15:43:39 +00:00
|
|
|
Handle<String> b = factory->InternalizeUtf8String(string);
|
|
|
|
CHECK_EQ(*b, *a);
|
2019-04-26 14:47:04 +00:00
|
|
|
CHECK(b->IsOneByteEqualTo(CStrVector(string)));
|
2014-04-29 13:58:55 +00:00
|
|
|
b = isolate->factory()->InternalizeUtf8String(CStrVector(string));
|
|
|
|
CHECK_EQ(*b, *a);
|
2019-04-26 14:47:04 +00:00
|
|
|
CHECK(b->IsOneByteEqualTo(CStrVector(string)));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
TEST(StringTable) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-23 15:43:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-02-28 17:03:34 +00:00
|
|
|
CheckInternalizedStrings(not_so_random_string_table);
|
|
|
|
CheckInternalizedStrings(not_so_random_string_table);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(FunctionAllocation) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> function = factory->NewFunctionForTest(name);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
|
|
|
Handle<Smi> twenty_four(Smi::FromInt(24), isolate);
|
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, prop_name, twenty_three).Check();
|
2014-04-11 12:47:34 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23),
|
2018-07-17 08:49:20 +00:00
|
|
|
*Object::GetProperty(isolate, obj, prop_name).ToHandleChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
// Check that we can add properties to function objects.
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, function, prop_name, twenty_four).Check();
|
2018-07-17 08:49:20 +00:00
|
|
|
CHECK_EQ(
|
|
|
|
Smi::FromInt(24),
|
|
|
|
*Object::GetProperty(isolate, function, prop_name).ToHandleChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ObjectProperties) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2018-07-04 09:10:05 +00:00
|
|
|
Handle<String> object_string(
|
|
|
|
String::cast(ReadOnlyRoots(CcTest::heap()).Object_string()), isolate);
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> object =
|
|
|
|
Object::GetProperty(isolate, CcTest::i_isolate()->global_object(),
|
|
|
|
object_string)
|
|
|
|
.ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(constructor);
|
|
|
|
Handle<String> first = factory->InternalizeUtf8String("first");
|
|
|
|
Handle<String> second = factory->InternalizeUtf8String("second");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> one(Smi::FromInt(1), isolate);
|
|
|
|
Handle<Smi> two(Smi::FromInt(2), isolate);
|
|
|
|
|
2008-08-22 13:33:59 +00:00
|
|
|
// check for empty
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, first, one).Check();
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete first
|
2017-10-16 10:55:06 +00:00
|
|
|
CHECK(Just(true) ==
|
|
|
|
JSReceiver::DeleteProperty(obj, first, LanguageMode::kSloppy));
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first and then second
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, first, one).Check();
|
|
|
|
Object::SetProperty(isolate, obj, second, two).Check();
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
|
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete first and then second
|
2017-10-16 10:55:06 +00:00
|
|
|
CHECK(Just(true) ==
|
|
|
|
JSReceiver::DeleteProperty(obj, first, LanguageMode::kSloppy));
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
|
2017-10-16 10:55:06 +00:00
|
|
|
CHECK(Just(true) ==
|
|
|
|
JSReceiver::DeleteProperty(obj, second, LanguageMode::kSloppy));
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
|
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// add first and then second
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, first, one).Check();
|
|
|
|
Object::SetProperty(isolate, obj, second, two).Check();
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
|
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// delete second and then first
|
2017-10-16 10:55:06 +00:00
|
|
|
CHECK(Just(true) ==
|
|
|
|
JSReceiver::DeleteProperty(obj, second, LanguageMode::kSloppy));
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, first));
|
2017-10-16 10:55:06 +00:00
|
|
|
CHECK(Just(true) ==
|
|
|
|
JSReceiver::DeleteProperty(obj, first, LanguageMode::kSloppy));
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, first));
|
|
|
|
CHECK(Just(false) == JSReceiver::HasOwnProperty(obj, second));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// check string and internalized string match
|
2012-01-30 14:57:36 +00:00
|
|
|
const char* string1 = "fisk";
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> s1 = factory->NewStringFromAsciiChecked(string1);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, s1, one).Check();
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s1_string = factory->InternalizeUtf8String(string1);
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s1_string));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-02-28 17:03:34 +00:00
|
|
|
// check internalized string and string match
|
2012-01-30 14:57:36 +00:00
|
|
|
const char* string2 = "fugl";
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> s2_string = factory->InternalizeUtf8String(string2);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, s2_string, one).Check();
|
2014-04-17 13:27:02 +00:00
|
|
|
Handle<String> s2 = factory->NewStringFromAsciiChecked(string2);
|
2015-03-02 12:22:27 +00:00
|
|
|
CHECK(Just(true) == JSReceiver::HasOwnProperty(obj, s2));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSObjectMaps) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("theFunction");
|
2017-11-08 12:56:08 +00:00
|
|
|
Handle<JSFunction> function = factory->NewFunctionForTest(name);
|
2010-03-05 09:51:10 +00:00
|
|
|
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String("theSlot");
|
|
|
|
Handle<JSObject> obj = factory->NewJSObject(function);
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<Map> initial_map(function->initial_map(), isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set a propery
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, prop_name, twenty_three).Check();
|
2014-04-11 12:47:34 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(23),
|
2018-07-17 08:49:20 +00:00
|
|
|
*Object::GetProperty(isolate, obj, prop_name).ToHandleChecked());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Check the map has changed
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(*initial_map != obj->map());
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSArray) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<String> name = factory->InternalizeUtf8String("Array");
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> fun_obj =
|
|
|
|
Object::GetProperty(isolate, CcTest::i_isolate()->global_object(), name)
|
|
|
|
.ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(fun_obj);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Allocate the object.
|
2014-04-17 11:57:08 +00:00
|
|
|
Handle<Object> element;
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> object = factory->NewJSObject(function);
|
2010-03-05 09:51:10 +00:00
|
|
|
Handle<JSArray> array = Handle<JSArray>::cast(object);
|
2010-08-31 08:05:42 +00:00
|
|
|
// We just initialized the VM, no heap allocation failure yet.
|
2014-03-18 11:38:27 +00:00
|
|
|
JSArray::Initialize(array, 0);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Set array length to 0.
|
2015-06-19 14:56:57 +00:00
|
|
|
JSArray::SetLength(array, 0);
|
2016-10-07 13:05:07 +00:00
|
|
|
CHECK_EQ(Smi::kZero, array->length());
|
2011-09-22 11:30:04 +00:00
|
|
|
// Must be in fast mode.
|
2017-06-30 18:00:44 +00:00
|
|
|
CHECK(array->HasSmiOrObjectElements());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// array[length] = name.
|
2019-01-23 17:13:08 +00:00
|
|
|
Object::SetElement(isolate, array, 0, name, ShouldThrow::kDontThrow).Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(Smi::FromInt(1), array->length());
|
2014-04-17 11:57:08 +00:00
|
|
|
element = i::Object::GetElement(isolate, array, 0).ToHandleChecked();
|
|
|
|
CHECK_EQ(*element, *name);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2010-03-05 09:51:10 +00:00
|
|
|
// Set array length with larger than smi value.
|
2015-06-19 14:56:57 +00:00
|
|
|
JSArray::SetLength(array, static_cast<uint32_t>(Smi::kMaxValue) + 1);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
uint32_t int_length = 0;
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(array->length().ToArrayIndex(&int_length));
|
2015-06-19 14:56:57 +00:00
|
|
|
CHECK_EQ(static_cast<uint32_t>(Smi::kMaxValue) + 1, int_length);
|
2009-07-28 08:43:51 +00:00
|
|
|
CHECK(array->HasDictionaryElements()); // Must be in slow mode.
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// array[length] = name.
|
2019-01-23 17:13:08 +00:00
|
|
|
Object::SetElement(isolate, array, int_length, name, ShouldThrow::kDontThrow)
|
2017-10-16 10:55:06 +00:00
|
|
|
.Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
uint32_t new_int_length = 0;
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(array->length().ToArrayIndex(&new_int_length));
|
2008-08-22 13:33:59 +00:00
|
|
|
CHECK_EQ(static_cast<double>(int_length), new_int_length - 1);
|
2014-04-17 11:57:08 +00:00
|
|
|
element = Object::GetElement(isolate, array, int_length).ToHandleChecked();
|
|
|
|
CHECK_EQ(*element, *name);
|
|
|
|
element = Object::GetElement(isolate, array, 0).ToHandleChecked();
|
|
|
|
CHECK_EQ(*element, *name);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(JSObjectCopy) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope sc(CcTest::isolate());
|
2018-07-04 09:10:05 +00:00
|
|
|
Handle<String> object_string(
|
|
|
|
String::cast(ReadOnlyRoots(CcTest::heap()).Object_string()), isolate);
|
2018-07-17 08:49:20 +00:00
|
|
|
Handle<Object> object =
|
|
|
|
Object::GetProperty(isolate, CcTest::i_isolate()->global_object(),
|
|
|
|
object_string)
|
|
|
|
.ToHandleChecked();
|
2014-04-09 12:21:47 +00:00
|
|
|
Handle<JSFunction> constructor = Handle<JSFunction>::cast(object);
|
2013-06-04 10:30:05 +00:00
|
|
|
Handle<JSObject> obj = factory->NewJSObject(constructor);
|
|
|
|
Handle<String> first = factory->InternalizeUtf8String("first");
|
|
|
|
Handle<String> second = factory->InternalizeUtf8String("second");
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2013-09-17 11:01:43 +00:00
|
|
|
Handle<Smi> one(Smi::FromInt(1), isolate);
|
|
|
|
Handle<Smi> two(Smi::FromInt(2), isolate);
|
|
|
|
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, obj, first, one).Check();
|
|
|
|
Object::SetProperty(isolate, obj, second, two).Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-01-23 17:13:08 +00:00
|
|
|
Object::SetElement(isolate, obj, 0, first, ShouldThrow::kDontThrow).Check();
|
|
|
|
Object::SetElement(isolate, obj, 1, second, ShouldThrow::kDontThrow).Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Make the clone.
|
2014-04-17 11:57:08 +00:00
|
|
|
Handle<Object> value1, value2;
|
2014-04-29 07:02:11 +00:00
|
|
|
Handle<JSObject> clone = factory->CopyJSObject(obj);
|
2010-03-05 09:51:10 +00:00
|
|
|
CHECK(!clone.is_identical_to(obj));
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-17 11:57:08 +00:00
|
|
|
value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
|
|
|
|
value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
|
|
|
|
CHECK_EQ(*value1, *value2);
|
|
|
|
value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
|
|
|
|
value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
|
|
|
|
CHECK_EQ(*value1, *value2);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2018-07-17 08:49:20 +00:00
|
|
|
value1 = Object::GetProperty(isolate, obj, first).ToHandleChecked();
|
|
|
|
value2 = Object::GetProperty(isolate, clone, first).ToHandleChecked();
|
2014-04-17 11:57:08 +00:00
|
|
|
CHECK_EQ(*value1, *value2);
|
2018-07-17 08:49:20 +00:00
|
|
|
value1 = Object::GetProperty(isolate, obj, second).ToHandleChecked();
|
|
|
|
value2 = Object::GetProperty(isolate, clone, second).ToHandleChecked();
|
2014-04-17 11:57:08 +00:00
|
|
|
CHECK_EQ(*value1, *value2);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Flip the values.
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, clone, first, two).Check();
|
|
|
|
Object::SetProperty(isolate, clone, second, one).Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2019-01-23 17:13:08 +00:00
|
|
|
Object::SetElement(isolate, clone, 0, second, ShouldThrow::kDontThrow)
|
|
|
|
.Check();
|
|
|
|
Object::SetElement(isolate, clone, 1, first, ShouldThrow::kDontThrow).Check();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2014-04-17 11:57:08 +00:00
|
|
|
value1 = Object::GetElement(isolate, obj, 1).ToHandleChecked();
|
|
|
|
value2 = Object::GetElement(isolate, clone, 0).ToHandleChecked();
|
|
|
|
CHECK_EQ(*value1, *value2);
|
|
|
|
value1 = Object::GetElement(isolate, obj, 0).ToHandleChecked();
|
|
|
|
value2 = Object::GetElement(isolate, clone, 1).ToHandleChecked();
|
|
|
|
CHECK_EQ(*value1, *value2);
|
|
|
|
|
2018-07-17 08:49:20 +00:00
|
|
|
value1 = Object::GetProperty(isolate, obj, second).ToHandleChecked();
|
|
|
|
value2 = Object::GetProperty(isolate, clone, first).ToHandleChecked();
|
2014-04-17 11:57:08 +00:00
|
|
|
CHECK_EQ(*value1, *value2);
|
2018-07-17 08:49:20 +00:00
|
|
|
value1 = Object::GetProperty(isolate, obj, first).ToHandleChecked();
|
|
|
|
value2 = Object::GetProperty(isolate, clone, second).ToHandleChecked();
|
2014-04-17 11:57:08 +00:00
|
|
|
CHECK_EQ(*value1, *value2);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(StringAllocation) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2017-12-02 00:30:37 +00:00
|
|
|
const unsigned char chars[] = {0xE5, 0xA4, 0xA7};
|
2008-08-22 13:33:59 +00:00
|
|
|
for (int length = 0; length < 100; length++) {
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2014-09-10 12:38:12 +00:00
|
|
|
char* non_one_byte = NewArray<char>(3 * length + 1);
|
|
|
|
char* one_byte = NewArray<char>(length + 1);
|
|
|
|
non_one_byte[3 * length] = 0;
|
|
|
|
one_byte[length] = 0;
|
2008-08-22 13:33:59 +00:00
|
|
|
for (int i = 0; i < length; i++) {
|
2014-09-10 12:38:12 +00:00
|
|
|
one_byte[i] = 'a';
|
|
|
|
non_one_byte[3 * i] = chars[0];
|
|
|
|
non_one_byte[3 * i + 1] = chars[1];
|
|
|
|
non_one_byte[3 * i + 2] = chars[2];
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2014-09-10 12:38:12 +00:00
|
|
|
Handle<String> non_one_byte_sym = factory->InternalizeUtf8String(
|
|
|
|
Vector<const char>(non_one_byte, 3 * length));
|
|
|
|
CHECK_EQ(length, non_one_byte_sym->length());
|
|
|
|
Handle<String> one_byte_sym =
|
2019-05-22 16:18:05 +00:00
|
|
|
factory->InternalizeString(OneByteVector(one_byte, length));
|
2014-09-10 12:38:12 +00:00
|
|
|
CHECK_EQ(length, one_byte_sym->length());
|
|
|
|
Handle<String> non_one_byte_str =
|
|
|
|
factory->NewStringFromUtf8(Vector<const char>(non_one_byte, 3 * length))
|
|
|
|
.ToHandleChecked();
|
|
|
|
non_one_byte_str->Hash();
|
|
|
|
CHECK_EQ(length, non_one_byte_str->length());
|
|
|
|
Handle<String> one_byte_str =
|
|
|
|
factory->NewStringFromUtf8(Vector<const char>(one_byte, length))
|
|
|
|
.ToHandleChecked();
|
|
|
|
one_byte_str->Hash();
|
|
|
|
CHECK_EQ(length, one_byte_str->length());
|
|
|
|
DeleteArray(non_one_byte);
|
|
|
|
DeleteArray(one_byte);
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-02-11 13:02:20 +00:00
|
|
|
static int ObjectsFoundInHeap(Heap* heap, Handle<Object> objs[], int size) {
|
2008-08-22 13:33:59 +00:00
|
|
|
// Count the number of objects found in the heap.
|
|
|
|
int found_count = 0;
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator iterator(heap);
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2008-08-22 13:33:59 +00:00
|
|
|
for (int i = 0; i < size; i++) {
|
|
|
|
if (*objs[i] == obj) {
|
|
|
|
found_count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return found_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Iteration) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Array of objects to scan haep for.
|
|
|
|
const int objs_count = 6;
|
|
|
|
Handle<Object> objs[objs_count];
|
|
|
|
int next_objs_index = 0;
|
|
|
|
|
2015-04-07 11:31:57 +00:00
|
|
|
// Allocate a JS array to OLD_SPACE and NEW_SPACE
|
2013-06-04 10:30:05 +00:00
|
|
|
objs[next_objs_index++] = factory->NewJSArray(10);
|
2019-03-11 19:04:02 +00:00
|
|
|
objs[next_objs_index++] =
|
|
|
|
factory->NewJSArray(10, HOLEY_ELEMENTS, AllocationType::kOld);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
2008-09-05 12:34:09 +00:00
|
|
|
// Allocate a small string to OLD_DATA_SPACE and NEW_SPACE
|
2014-09-10 12:38:12 +00:00
|
|
|
objs[next_objs_index++] = factory->NewStringFromStaticChars("abcdefghij");
|
2008-08-22 13:33:59 +00:00
|
|
|
objs[next_objs_index++] =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewStringFromStaticChars("abcdefghij", AllocationType::kOld);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
// Allocate a large string (for large object space).
|
2016-09-06 12:58:59 +00:00
|
|
|
int large_size = kMaxRegularHeapObjectSize + 1;
|
2008-08-22 13:33:59 +00:00
|
|
|
char* str = new char[large_size];
|
|
|
|
for (int i = 0; i < large_size - 1; ++i) str[i] = 'a';
|
|
|
|
str[large_size - 1] = '\0';
|
2019-03-11 19:04:02 +00:00
|
|
|
objs[next_objs_index++] =
|
|
|
|
factory->NewStringFromAsciiChecked(str, AllocationType::kOld);
|
2008-08-22 13:33:59 +00:00
|
|
|
delete[] str;
|
|
|
|
|
|
|
|
// Add a Map object to look for.
|
2018-06-23 09:05:50 +00:00
|
|
|
objs[next_objs_index++] =
|
2019-05-23 07:47:44 +00:00
|
|
|
Handle<Map>(HeapObject::cast(*objs[0]).map(), isolate);
|
2008-08-22 13:33:59 +00:00
|
|
|
|
|
|
|
CHECK_EQ(objs_count, next_objs_index);
|
2013-09-19 09:46:15 +00:00
|
|
|
CHECK_EQ(objs_count, ObjectsFoundInHeap(CcTest::heap(), objs, objs_count));
|
2008-08-22 13:33:59 +00:00
|
|
|
}
|
2010-03-25 13:10:50 +00:00
|
|
|
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
TEST(TestBytecodeFlushing) {
|
|
|
|
#ifndef V8_LITE_MODE
|
|
|
|
FLAG_opt = false;
|
|
|
|
FLAG_always_opt = false;
|
|
|
|
i::FLAG_optimize_for_size = false;
|
|
|
|
#endif // V8_LITE_MODE
|
|
|
|
i::FLAG_flush_bytecode = true;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
Isolate* i_isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = i_isolate->factory();
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
const char* source =
|
|
|
|
"function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check function is compiled.
|
|
|
|
Handle<Object> func_value =
|
|
|
|
Object::GetProperty(i_isolate, i_isolate->global_object(), foo_name)
|
|
|
|
.ToHandleChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
|
|
|
|
// The code will survive at least two GCs.
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
CcTest::CollectAllGarbage();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
|
|
|
|
// Simulate several GCs that use full marking.
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// foo should no longer be in the compilation cache
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(!function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
CHECK(!function->is_compiled());
|
|
|
|
// Call foo to get it recompiled.
|
|
|
|
CompileRun("foo()");
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
CHECK(function->is_compiled());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifndef V8_LITE_MODE
|
|
|
|
|
|
|
|
TEST(TestOptimizeAfterBytecodeFlushingCandidate) {
|
|
|
|
FLAG_opt = true;
|
|
|
|
FLAG_always_opt = false;
|
|
|
|
i::FLAG_optimize_for_size = false;
|
|
|
|
i::FLAG_incremental_marking = true;
|
|
|
|
i::FLAG_flush_bytecode = true;
|
|
|
|
i::FLAG_allow_natives_syntax = true;
|
|
|
|
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
const char* source =
|
|
|
|
"function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
|
|
|
"foo()";
|
|
|
|
Handle<String> foo_name = factory->InternalizeUtf8String("foo");
|
|
|
|
|
|
|
|
// This compile will add the code to the compilation cache.
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun(source);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check function is compiled.
|
|
|
|
Handle<Object> func_value =
|
|
|
|
Object::GetProperty(isolate, isolate->global_object(), foo_name)
|
|
|
|
.ToHandleChecked();
|
|
|
|
CHECK(func_value->IsJSFunction());
|
|
|
|
Handle<JSFunction> function = Handle<JSFunction>::cast(func_value);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
|
|
|
|
// The code will survive at least two GCs.
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
CcTest::CollectAllGarbage();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
|
|
|
|
// Simulate several GCs that use incremental marking.
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
}
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(!function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
CHECK(!function->is_compiled());
|
|
|
|
|
|
|
|
// This compile will compile the function again.
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("foo();");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate several GCs that use incremental marking but make sure
|
|
|
|
// the loop breaks once the function is enqueued as a candidate.
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2019-05-23 07:47:44 +00:00
|
|
|
if (function->shared().GetBytecodeArray().IsOld()) break;
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Force optimization while incremental marking is active and while
|
|
|
|
// the function is enqueued as a candidate.
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"%PrepareFunctionForOptimization(foo);"
|
|
|
|
"%OptimizeFunctionOnNextCall(foo); foo();");
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Simulate one final GC and make sure the candidate wasn't flushed.
|
|
|
|
CcTest::CollectAllGarbage();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(function->shared().is_compiled());
|
[SFI] Add support for flushing old Bytecode from SharedFunctionInfos.
This change makes the SFI to bytecode link pseudo-weak. The marking visitors
check whether the bytecode is old, and if so, don't mark it and instead
push the SFI onto a bytecode_flushing_candidates worklist. Once marking
is complete, this list is walked, and for any of the candidates who's bytecode
has not been marked (i.e., is only referenced by the shared function info),
the bytecode is flushed and the SFI has the function data replaced with
an UncompiledData (which overwrites the flushed bytecode array).
Since we don't track JSFunctions, these can still think the underlying
function is compiled, and so calling them will invoke
InterpreterEntryTrampoline. As such, logic is added to
InterpreterEntryTrampoline to detect flushed functions, and enter
CompileLazy instead.
BUG=v8:8395
Change-Id: I4afba79f814ca9a92dec45d59485935845a6669d
Reviewed-on: https://chromium-review.googlesource.com/c/1348433
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58158}
2018-12-11 13:33:07 +00:00
|
|
|
CHECK(function->is_compiled());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // V8_LITE_MODE
|
|
|
|
|
2016-02-04 08:15:52 +00:00
|
|
|
TEST(TestUseOfIncrementalBarrierOnCompileLazy) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-02-04 08:15:52 +00:00
|
|
|
// Turn off always_opt because it interferes with running the built-in for
|
|
|
|
// the last call to g().
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_always_opt = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2016-02-04 08:15:52 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function make_closure(x) {"
|
|
|
|
" return function() { return x + 3 };"
|
|
|
|
"}"
|
2019-04-30 11:04:41 +00:00
|
|
|
"var f = make_closure(5);"
|
|
|
|
"%PrepareFunctionForOptimization(f); f();"
|
2016-02-04 08:15:52 +00:00
|
|
|
"var g = make_closure(5);");
|
|
|
|
|
|
|
|
// Check f is compiled.
|
|
|
|
Handle<String> f_name = factory->InternalizeUtf8String("f");
|
|
|
|
Handle<Object> f_value =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, isolate->global_object(), f_name)
|
|
|
|
.ToHandleChecked();
|
2016-02-04 08:15:52 +00:00
|
|
|
Handle<JSFunction> f_function = Handle<JSFunction>::cast(f_value);
|
|
|
|
CHECK(f_function->is_compiled());
|
|
|
|
|
|
|
|
// Check g is not compiled.
|
|
|
|
Handle<String> g_name = factory->InternalizeUtf8String("g");
|
|
|
|
Handle<Object> g_value =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, isolate->global_object(), g_name)
|
|
|
|
.ToHandleChecked();
|
2016-02-04 08:15:52 +00:00
|
|
|
Handle<JSFunction> g_function = Handle<JSFunction>::cast(g_value);
|
2016-04-13 10:54:31 +00:00
|
|
|
CHECK(!g_function->is_compiled());
|
2016-02-04 08:15:52 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap);
|
2016-02-04 08:15:52 +00:00
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(f); f();");
|
|
|
|
|
|
|
|
// g should now have available an optimized function, unmarked by gc. The
|
|
|
|
// CompileLazy built-in will discover it and install it in the closure, and
|
|
|
|
// the incremental write barrier should be used.
|
|
|
|
CompileRun("g();");
|
|
|
|
CHECK(g_function->is_compiled());
|
|
|
|
}
|
2012-11-08 10:26:50 +00:00
|
|
|
|
2014-10-31 14:51:48 +00:00
|
|
|
TEST(CompilationCacheCachingBehavior) {
|
Reland "[Compiler] Remove code aging support."
> This reverts commit 42d3d36bc3b4e76cbdf883432dcc3647526fbf58.
>
> Original change's description:
> > [Compiler] Remove code aging support.
> >
> > Code aging is no longer supported by any remaining compilers now
> > that full codegen has been removed. This CL removes all vestiges of
> > code aging.
> >
> > BUG=v8:6409
> >
> > Change-Id: I945ebcc20c7c55120550c8ee36188bfa042ea65e
> > Reviewed-on: https://chromium-review.googlesource.com/619153
> > Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
> > Reviewed-by: Yang Guo <yangguo@chromium.org>
> > Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
> > Reviewed-by: Marja Hölttä <marja@chromium.org>
> > Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
> > Cr-Commit-Position: refs/heads/master@{#47501}
>
> TBR=ulan@chromium.org,rmcilroy@chromium.org,marja@chromium.org,yangguo@chromium.org,mstarzinger@chromium.org,rodolph.perfetta@arm.com
>
> Change-Id: I9d8b2985e2d472697908270d93a35eb7ef9c88a8
> No-Presubmit: true
> No-Tree-Checks: true
> No-Try: true
> Bug: v8:6409
> Reviewed-on: https://chromium-review.googlesource.com/625998
> Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
> Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#47506}
TBR=ulan@chromium.org,rmcilroy@chromium.org,marja@chromium.org,yangguo@chromium.org,mstarzinger@chromium.org,rodolph.perfetta@arm.com
Change-Id: I68785c6be7686e874b3848103e3a34483eaeb519
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: v8:6409
Reviewed-on: https://chromium-review.googlesource.com/625919
Reviewed-by: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#47535}
2017-08-23 08:22:33 +00:00
|
|
|
// If we do not have the compilation cache turned off, this test is invalid.
|
|
|
|
if (!FLAG_compilation_cache) {
|
2014-10-31 14:51:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
CompilationCache* compilation_cache = isolate->compilation_cache();
|
2016-03-10 12:43:51 +00:00
|
|
|
LanguageMode language_mode = construct_language_mode(FLAG_use_strict);
|
2014-10-31 14:51:48 +00:00
|
|
|
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
const char* raw_source =
|
|
|
|
"function foo() {"
|
|
|
|
" var x = 42;"
|
|
|
|
" var y = 42;"
|
|
|
|
" var z = x + y;"
|
|
|
|
"};"
|
2016-11-09 17:19:32 +00:00
|
|
|
"foo();";
|
2014-10-31 14:51:48 +00:00
|
|
|
Handle<String> source = factory->InternalizeUtf8String(raw_source);
|
|
|
|
Handle<Context> native_context = isolate->native_context();
|
|
|
|
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun(raw_source);
|
|
|
|
}
|
|
|
|
|
2016-04-18 09:00:27 +00:00
|
|
|
// The script should be in the cache now.
|
2018-02-16 18:09:00 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
MaybeHandle<SharedFunctionInfo> cached_script =
|
|
|
|
compilation_cache->LookupScript(source, Handle<Object>(), 0, 0,
|
|
|
|
v8::ScriptOriginOptions(true, false),
|
|
|
|
native_context, language_mode);
|
|
|
|
CHECK(!cached_script.is_null());
|
2016-01-14 11:48:11 +00:00
|
|
|
}
|
2014-10-31 14:51:48 +00:00
|
|
|
|
2018-02-16 18:09:00 +00:00
|
|
|
// Check that the code cache entry survives at least one GC.
|
|
|
|
{
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
MaybeHandle<SharedFunctionInfo> cached_script =
|
|
|
|
compilation_cache->LookupScript(source, Handle<Object>(), 0, 0,
|
|
|
|
v8::ScriptOriginOptions(true, false),
|
|
|
|
native_context, language_mode);
|
|
|
|
CHECK(!cached_script.is_null());
|
|
|
|
|
|
|
|
// Progress code age until it's old and ready for GC.
|
|
|
|
Handle<SharedFunctionInfo> shared = cached_script.ToHandleChecked();
|
|
|
|
CHECK(shared->HasBytecodeArray());
|
|
|
|
const int kAgingThreshold = 6;
|
|
|
|
for (int i = 0; i < kAgingThreshold; i++) {
|
2019-05-23 07:47:44 +00:00
|
|
|
shared->GetBytecodeArray().MakeOlder();
|
2018-02-16 18:09:00 +00:00
|
|
|
}
|
2014-10-31 14:51:48 +00:00
|
|
|
}
|
|
|
|
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2018-02-16 18:09:00 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
// Ensure code aging cleared the entry from the cache.
|
|
|
|
MaybeHandle<SharedFunctionInfo> cached_script =
|
|
|
|
compilation_cache->LookupScript(source, Handle<Object>(), 0, 0,
|
|
|
|
v8::ScriptOriginOptions(true, false),
|
|
|
|
native_context, language_mode);
|
|
|
|
CHECK(cached_script.is_null());
|
|
|
|
}
|
2014-10-31 14:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-09 11:01:19 +00:00
|
|
|
static void OptimizeEmptyFunction(const char* name) {
|
|
|
|
HandleScope scope(CcTest::i_isolate());
|
|
|
|
EmbeddedVector<char, 256> source;
|
|
|
|
SNPrintF(source,
|
|
|
|
"function %s() { return 0; }"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(%s);"
|
2015-04-09 11:01:19 +00:00
|
|
|
"%s(); %s();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(%s);"
|
|
|
|
"%s();",
|
2019-04-30 11:04:41 +00:00
|
|
|
name, name, name, name, name, name);
|
2019-04-29 11:06:49 +00:00
|
|
|
CompileRun(source.begin());
|
2015-04-09 11:01:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Count the number of native contexts in the weak list of native contexts.
|
|
|
|
int CountNativeContexts() {
|
2010-10-18 14:59:03 +00:00
|
|
|
int count = 0;
|
2018-12-25 00:19:47 +00:00
|
|
|
Object object = CcTest::heap()->native_contexts_list();
|
2019-05-23 07:47:44 +00:00
|
|
|
while (!object.IsUndefined(CcTest::i_isolate())) {
|
2010-10-18 14:59:03 +00:00
|
|
|
count++;
|
2019-05-23 07:47:44 +00:00
|
|
|
object = Context::cast(object).next_context_link();
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
2015-12-02 12:35:12 +00:00
|
|
|
return count;
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(TestInternalWeakLists) {
|
2015-04-09 11:01:19 +00:00
|
|
|
FLAG_always_opt = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2011-03-18 20:35:07 +00:00
|
|
|
v8::V8::Initialize();
|
|
|
|
|
2012-12-10 15:14:20 +00:00
|
|
|
// Some flags turn Scavenge collections into Mark-sweep collections
|
|
|
|
// and hence are incompatible with this test case.
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2015-03-06 12:36:16 +00:00
|
|
|
FLAG_retain_maps_for_n_gc = 0;
|
2012-12-10 15:14:20 +00:00
|
|
|
|
2014-07-29 13:08:51 +00:00
|
|
|
static const int kNumTestContexts = 10;
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2014-07-29 13:08:51 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx[kNumTestContexts];
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2010-10-18 14:59:03 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(0, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
// Create a number of global contests which gets linked together.
|
|
|
|
for (int i = 0; i < kNumTestContexts; i++) {
|
2013-09-19 08:54:58 +00:00
|
|
|
ctx[i] = v8::Context::New(CcTest::isolate());
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2013-07-08 09:07:57 +00:00
|
|
|
// Collect garbage that might have been created by one of the
|
|
|
|
// installed extensions.
|
|
|
|
isolate->compilation_cache()->Clear();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-07-29 13:08:51 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(i + 1, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
|
|
|
|
ctx[i]->Enter();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2015-04-09 11:01:19 +00:00
|
|
|
// Create a handle scope so no function objects get stuck in the outer
|
|
|
|
// handle scope.
|
2013-03-15 12:06:53 +00:00
|
|
|
HandleScope scope(isolate);
|
2015-04-09 11:01:19 +00:00
|
|
|
OptimizeEmptyFunction("f1");
|
|
|
|
OptimizeEmptyFunction("f2");
|
|
|
|
OptimizeEmptyFunction("f3");
|
|
|
|
OptimizeEmptyFunction("f4");
|
|
|
|
OptimizeEmptyFunction("f5");
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Remove function f1, and
|
|
|
|
CompileRun("f1=null");
|
|
|
|
|
|
|
|
// Scavenge treats these references as strong.
|
2014-07-29 13:08:51 +00:00
|
|
|
for (int j = 0; j < 10; j++) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark compact handles the weak references.
|
2013-02-15 09:27:10 +00:00
|
|
|
isolate->compilation_cache()->Clear();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
|
|
|
// Get rid of f3 and f5 in the same way.
|
|
|
|
CompileRun("f3=null");
|
2014-07-29 13:08:51 +00:00
|
|
|
for (int j = 0; j < 10; j++) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
CompileRun("f5=null");
|
2014-07-29 13:08:51 +00:00
|
|
|
for (int j = 0; j < 10; j++) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2010-12-07 11:31:57 +00:00
|
|
|
}
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-12-07 11:31:57 +00:00
|
|
|
|
2010-10-18 14:59:03 +00:00
|
|
|
ctx[i]->Exit();
|
|
|
|
}
|
|
|
|
|
2010-10-18 17:01:30 +00:00
|
|
|
// Force compilation cache cleanup.
|
2014-12-22 14:27:19 +00:00
|
|
|
CcTest::heap()->NotifyContextDisposed(true);
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2010-10-18 17:01:30 +00:00
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
// Dispose the native contexts one by one.
|
2010-10-18 14:59:03 +00:00
|
|
|
for (int i = 0; i < kNumTestContexts; i++) {
|
2013-05-02 20:18:42 +00:00
|
|
|
// TODO(dcarney): is there a better way to do this?
|
2018-12-17 13:34:08 +00:00
|
|
|
i::Address* unsafe = reinterpret_cast<i::Address*>(*ctx[i]);
|
2019-05-23 07:47:44 +00:00
|
|
|
*unsafe = ReadOnlyRoots(CcTest::heap()).undefined_value().ptr();
|
2010-10-18 14:59:03 +00:00
|
|
|
ctx[i].Clear();
|
|
|
|
|
|
|
|
// Scavenge treats these references as strong.
|
2014-07-29 13:08:51 +00:00
|
|
|
for (int j = 0; j < 10; j++) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(i::NEW_SPACE);
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(kNumTestContexts - i, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Mark compact handles the weak references.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(kNumTestContexts - i - 1, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
CHECK_EQ(0, CountNativeContexts());
|
2010-10-18 14:59:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-16 12:33:20 +00:00
|
|
|
TEST(TestSizeOfRegExpCode) {
|
|
|
|
if (!FLAG_regexp_optimization) return;
|
|
|
|
|
|
|
|
v8::V8::Initialize();
|
|
|
|
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
LocalContext context;
|
|
|
|
|
|
|
|
// Adjust source below and this check to match
|
2019-06-17 15:16:39 +00:00
|
|
|
// RegExp::kRegExpTooLargeToOptimize.
|
|
|
|
CHECK_EQ(i::RegExp::kRegExpTooLargeToOptimize, 20 * KB);
|
2014-12-16 12:33:20 +00:00
|
|
|
|
|
|
|
// Compile a regexp that is much larger if we are using regexp optimizations.
|
|
|
|
CompileRun(
|
|
|
|
"var reg_exp_source = '(?:a|bc|def|ghij|klmno|pqrstu)';"
|
|
|
|
"var half_size_reg_exp;"
|
2015-06-10 09:55:22 +00:00
|
|
|
"while (reg_exp_source.length < 20 * 1024) {"
|
2014-12-16 12:33:20 +00:00
|
|
|
" half_size_reg_exp = reg_exp_source;"
|
|
|
|
" reg_exp_source = reg_exp_source + reg_exp_source;"
|
|
|
|
"}"
|
|
|
|
// Flatten string.
|
|
|
|
"reg_exp_source.match(/f/);");
|
|
|
|
|
|
|
|
// Get initial heap size after several full GCs, which will stabilize
|
|
|
|
// the heap size and return with sweeping finished completely.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-12-16 12:33:20 +00:00
|
|
|
MarkCompactCollector* collector = CcTest::heap()->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
int initial_size = static_cast<int>(CcTest::heap()->SizeOfObjects());
|
|
|
|
|
|
|
|
CompileRun("'foo'.match(reg_exp_source);");
|
2017-08-02 07:58:31 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-12-16 12:33:20 +00:00
|
|
|
int size_with_regexp = static_cast<int>(CcTest::heap()->SizeOfObjects());
|
|
|
|
|
|
|
|
CompileRun("'foo'.match(half_size_reg_exp);");
|
2017-08-02 07:58:31 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-12-16 12:33:20 +00:00
|
|
|
int size_with_optimized_regexp =
|
|
|
|
static_cast<int>(CcTest::heap()->SizeOfObjects());
|
|
|
|
|
|
|
|
int size_of_regexp_code = size_with_regexp - initial_size;
|
|
|
|
|
2015-06-10 09:55:22 +00:00
|
|
|
// On some platforms the debug-code flag causes huge amounts of regexp code
|
|
|
|
// to be emitted, breaking this test.
|
|
|
|
if (!FLAG_debug_code) {
|
|
|
|
CHECK_LE(size_of_regexp_code, 1 * MB);
|
|
|
|
}
|
2014-12-16 12:33:20 +00:00
|
|
|
|
|
|
|
// Small regexp is half the size, but compiles to more than twice the code
|
|
|
|
// due to the optimization steps.
|
|
|
|
CHECK_GE(size_with_optimized_regexp,
|
|
|
|
size_with_regexp + size_of_regexp_code * 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 12:40:22 +00:00
|
|
|
HEAP_TEST(TestSizeOfObjects) {
|
2012-01-11 10:33:34 +00:00
|
|
|
v8::V8::Initialize();
|
2018-04-09 19:11:22 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2016-08-11 14:21:44 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
MarkCompactCollector* collector = heap->mark_compact_collector();
|
2012-01-11 10:33:34 +00:00
|
|
|
|
|
|
|
// Get initial heap size after several full GCs, which will stabilize
|
|
|
|
// the heap size and return with sweeping finished completely.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-07-15 08:24:44 +00:00
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
2014-04-25 09:50:42 +00:00
|
|
|
}
|
2016-08-11 14:21:44 +00:00
|
|
|
int initial_size = static_cast<int>(heap->SizeOfObjects());
|
2012-01-11 10:33:34 +00:00
|
|
|
|
|
|
|
{
|
2018-04-09 19:11:22 +00:00
|
|
|
HandleScope scope(isolate);
|
2012-01-11 10:33:34 +00:00
|
|
|
// Allocate objects on several different old-space pages so that
|
2014-04-25 09:50:42 +00:00
|
|
|
// concurrent sweeper threads will be busy sweeping the old space on
|
|
|
|
// subsequent GC runs.
|
2014-03-19 11:31:43 +00:00
|
|
|
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
2012-01-11 10:59:21 +00:00
|
|
|
int filler_size = static_cast<int>(FixedArray::SizeFor(8192));
|
2012-01-11 10:33:34 +00:00
|
|
|
for (int i = 1; i <= 100; i++) {
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(8192, AllocationType::kOld);
|
2012-01-11 10:59:21 +00:00
|
|
|
CHECK_EQ(initial_size + i * filler_size,
|
2016-08-11 14:21:44 +00:00
|
|
|
static_cast<int>(heap->SizeOfObjects()));
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// The heap size should go back to initial size after a full GC, even
|
|
|
|
// though sweeping didn't finish yet.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2012-05-02 12:58:40 +00:00
|
|
|
// Normally sweeping would not be complete here, but no guarantees.
|
2016-08-11 14:21:44 +00:00
|
|
|
CHECK_EQ(initial_size, static_cast<int>(heap->SizeOfObjects()));
|
2014-04-25 09:50:42 +00:00
|
|
|
// Waiting for sweeper threads should not change heap size.
|
2014-07-15 08:24:44 +00:00
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
2016-08-11 14:21:44 +00:00
|
|
|
CHECK_EQ(initial_size, static_cast<int>(heap->SizeOfObjects()));
|
2012-01-11 10:33:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-29 13:18:13 +00:00
|
|
|
TEST(TestAlignmentCalculations) {
|
2015-06-02 22:56:00 +00:00
|
|
|
// Maximum fill amounts are consistent.
|
2018-12-19 19:10:21 +00:00
|
|
|
int maximum_double_misalignment = kDoubleSize - kTaggedSize;
|
2015-05-29 13:18:13 +00:00
|
|
|
int max_word_fill = Heap::GetMaximumFillToAlign(kWordAligned);
|
|
|
|
CHECK_EQ(0, max_word_fill);
|
|
|
|
int max_double_fill = Heap::GetMaximumFillToAlign(kDoubleAligned);
|
|
|
|
CHECK_EQ(maximum_double_misalignment, max_double_fill);
|
|
|
|
int max_double_unaligned_fill = Heap::GetMaximumFillToAlign(kDoubleUnaligned);
|
|
|
|
CHECK_EQ(maximum_double_misalignment, max_double_unaligned_fill);
|
|
|
|
|
2018-04-13 22:28:05 +00:00
|
|
|
Address base = kNullAddress;
|
2015-05-29 13:18:13 +00:00
|
|
|
int fill = 0;
|
|
|
|
|
|
|
|
// Word alignment never requires fill.
|
|
|
|
fill = Heap::GetFillToAlign(base, kWordAligned);
|
|
|
|
CHECK_EQ(0, fill);
|
2018-12-19 19:10:21 +00:00
|
|
|
fill = Heap::GetFillToAlign(base + kTaggedSize, kWordAligned);
|
2015-05-29 13:18:13 +00:00
|
|
|
CHECK_EQ(0, fill);
|
|
|
|
|
|
|
|
// No fill is required when address is double aligned.
|
|
|
|
fill = Heap::GetFillToAlign(base, kDoubleAligned);
|
|
|
|
CHECK_EQ(0, fill);
|
|
|
|
// Fill is required if address is not double aligned.
|
2018-12-19 19:10:21 +00:00
|
|
|
fill = Heap::GetFillToAlign(base + kTaggedSize, kDoubleAligned);
|
2015-05-29 13:18:13 +00:00
|
|
|
CHECK_EQ(maximum_double_misalignment, fill);
|
|
|
|
// kDoubleUnaligned has the opposite fill amounts.
|
|
|
|
fill = Heap::GetFillToAlign(base, kDoubleUnaligned);
|
|
|
|
CHECK_EQ(maximum_double_misalignment, fill);
|
2018-12-19 19:10:21 +00:00
|
|
|
fill = Heap::GetFillToAlign(base + kTaggedSize, kDoubleUnaligned);
|
2015-05-29 13:18:13 +00:00
|
|
|
CHECK_EQ(0, fill);
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:47:47 +00:00
|
|
|
static HeapObject NewSpaceAllocateAligned(int size,
|
|
|
|
AllocationAlignment alignment) {
|
2015-05-29 13:18:13 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
AllocationResult allocation =
|
|
|
|
heap->new_space()->AllocateRawAligned(size, alignment);
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj;
|
2015-05-29 13:18:13 +00:00
|
|
|
allocation.To(&obj);
|
2019-08-20 12:17:23 +00:00
|
|
|
heap->CreateFillerObjectAt(obj.address(), size);
|
2015-05-29 13:18:13 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-06-02 22:56:00 +00:00
|
|
|
// Get new space allocation into the desired alignment.
|
|
|
|
static Address AlignNewSpace(AllocationAlignment alignment, int offset) {
|
2016-06-06 15:12:08 +00:00
|
|
|
Address* top_addr = CcTest::heap()->new_space()->allocation_top_address();
|
|
|
|
int fill = Heap::GetFillToAlign(*top_addr, alignment);
|
2019-02-14 09:42:58 +00:00
|
|
|
int allocation = fill + offset;
|
|
|
|
if (allocation) {
|
|
|
|
NewSpaceAllocateAligned(allocation, kWordAligned);
|
2015-06-02 22:56:00 +00:00
|
|
|
}
|
2016-06-06 15:12:08 +00:00
|
|
|
return *top_addr;
|
2015-06-02 22:56:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-29 13:18:13 +00:00
|
|
|
TEST(TestAlignedAllocation) {
|
2018-12-19 19:10:21 +00:00
|
|
|
// Double misalignment is 4 on 32-bit platforms or when pointer compression
|
|
|
|
// is enabled, 0 on 64-bit ones when pointer compression is disabled.
|
|
|
|
const intptr_t double_misalignment = kDoubleSize - kTaggedSize;
|
2016-06-06 15:12:08 +00:00
|
|
|
Address* top_addr = CcTest::heap()->new_space()->allocation_top_address();
|
2015-06-02 22:56:00 +00:00
|
|
|
Address start;
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj;
|
|
|
|
HeapObject filler;
|
2015-05-29 13:18:13 +00:00
|
|
|
if (double_misalignment) {
|
2015-06-02 22:56:00 +00:00
|
|
|
// Allocate a pointer sized object that must be double aligned at an
|
|
|
|
// aligned address.
|
|
|
|
start = AlignNewSpace(kDoubleAligned, 0);
|
2018-12-19 19:10:21 +00:00
|
|
|
obj = NewSpaceAllocateAligned(kTaggedSize, kDoubleAligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address(), kDoubleAlignment));
|
2015-06-02 22:56:00 +00:00
|
|
|
// There is no filler.
|
2018-12-19 19:10:21 +00:00
|
|
|
CHECK_EQ(kTaggedSize, *top_addr - start);
|
2015-06-02 22:56:00 +00:00
|
|
|
|
|
|
|
// Allocate a second pointer sized object that must be double aligned at an
|
|
|
|
// unaligned address.
|
2018-12-19 19:10:21 +00:00
|
|
|
start = AlignNewSpace(kDoubleAligned, kTaggedSize);
|
|
|
|
obj = NewSpaceAllocateAligned(kTaggedSize, kDoubleAligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address(), kDoubleAlignment));
|
2015-06-02 22:56:00 +00:00
|
|
|
// There is a filler object before the object.
|
|
|
|
filler = HeapObject::FromAddress(start);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(obj != filler && filler.IsFiller() && filler.Size() == kTaggedSize);
|
2018-12-19 19:10:21 +00:00
|
|
|
CHECK_EQ(kTaggedSize + double_misalignment, *top_addr - start);
|
2015-06-02 22:56:00 +00:00
|
|
|
|
|
|
|
// Similarly for kDoubleUnaligned.
|
|
|
|
start = AlignNewSpace(kDoubleUnaligned, 0);
|
2018-12-19 19:10:21 +00:00
|
|
|
obj = NewSpaceAllocateAligned(kTaggedSize, kDoubleUnaligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address() + kTaggedSize, kDoubleAlignment));
|
2018-12-19 19:10:21 +00:00
|
|
|
CHECK_EQ(kTaggedSize, *top_addr - start);
|
|
|
|
start = AlignNewSpace(kDoubleUnaligned, kTaggedSize);
|
|
|
|
obj = NewSpaceAllocateAligned(kTaggedSize, kDoubleUnaligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address() + kTaggedSize, kDoubleAlignment));
|
2015-06-02 22:56:00 +00:00
|
|
|
// There is a filler object before the object.
|
|
|
|
filler = HeapObject::FromAddress(start);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(obj != filler && filler.IsFiller() && filler.Size() == kTaggedSize);
|
2018-12-19 19:10:21 +00:00
|
|
|
CHECK_EQ(kTaggedSize + double_misalignment, *top_addr - start);
|
2015-05-29 13:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-20 15:47:47 +00:00
|
|
|
static HeapObject OldSpaceAllocateAligned(int size,
|
|
|
|
AllocationAlignment alignment) {
|
2015-05-29 13:18:13 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
AllocationResult allocation =
|
|
|
|
heap->old_space()->AllocateRawAligned(size, alignment);
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj;
|
2015-05-29 13:18:13 +00:00
|
|
|
allocation.To(&obj);
|
2019-08-20 12:17:23 +00:00
|
|
|
heap->CreateFillerObjectAt(obj.address(), size);
|
2015-05-29 13:18:13 +00:00
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
|
2015-06-02 22:56:00 +00:00
|
|
|
// Get old space allocation into the desired alignment.
|
|
|
|
static Address AlignOldSpace(AllocationAlignment alignment, int offset) {
|
2016-06-06 15:12:08 +00:00
|
|
|
Address* top_addr = CcTest::heap()->old_space()->allocation_top_address();
|
|
|
|
int fill = Heap::GetFillToAlign(*top_addr, alignment);
|
2015-06-02 22:56:00 +00:00
|
|
|
int allocation = fill + offset;
|
|
|
|
if (allocation) {
|
|
|
|
OldSpaceAllocateAligned(allocation, kWordAligned);
|
|
|
|
}
|
2016-06-06 15:12:08 +00:00
|
|
|
Address top = *top_addr;
|
2015-06-02 22:56:00 +00:00
|
|
|
// Now force the remaining allocation onto the free list.
|
2018-01-09 08:56:07 +00:00
|
|
|
CcTest::heap()->old_space()->FreeLinearAllocationArea();
|
2015-06-02 22:56:00 +00:00
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-29 13:18:13 +00:00
|
|
|
// Test the case where allocation must be done from the free list, so filler
|
|
|
|
// may precede or follow the object.
|
|
|
|
TEST(TestAlignedOverAllocation) {
|
2016-09-06 11:02:21 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
// Test checks for fillers before and behind objects and requires a fresh
|
|
|
|
// page and empty free list.
|
|
|
|
heap::AbandonCurrentlyFreeMemory(heap->old_space());
|
|
|
|
// Allocate a dummy object to properly set up the linear allocation info.
|
2018-12-19 19:10:21 +00:00
|
|
|
AllocationResult dummy = heap->old_space()->AllocateRawUnaligned(kTaggedSize);
|
2016-09-06 11:02:21 +00:00
|
|
|
CHECK(!dummy.IsRetry());
|
2019-08-20 12:17:23 +00:00
|
|
|
heap->CreateFillerObjectAt(dummy.ToObjectChecked().address(), kTaggedSize);
|
2016-09-06 11:02:21 +00:00
|
|
|
|
2018-12-19 19:10:21 +00:00
|
|
|
// Double misalignment is 4 on 32-bit platforms or when pointer compression
|
|
|
|
// is enabled, 0 on 64-bit ones when pointer compression is disabled.
|
|
|
|
const intptr_t double_misalignment = kDoubleSize - kTaggedSize;
|
2015-06-02 22:56:00 +00:00
|
|
|
Address start;
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj;
|
|
|
|
HeapObject filler;
|
2015-05-29 13:18:13 +00:00
|
|
|
if (double_misalignment) {
|
2015-06-02 22:56:00 +00:00
|
|
|
start = AlignOldSpace(kDoubleAligned, 0);
|
2018-12-19 19:10:21 +00:00
|
|
|
obj = OldSpaceAllocateAligned(kTaggedSize, kDoubleAligned);
|
2017-08-30 13:42:58 +00:00
|
|
|
// The object is aligned.
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address(), kDoubleAlignment));
|
2015-05-29 13:18:13 +00:00
|
|
|
// Try the opposite alignment case.
|
2018-12-19 19:10:21 +00:00
|
|
|
start = AlignOldSpace(kDoubleAligned, kTaggedSize);
|
|
|
|
obj = OldSpaceAllocateAligned(kTaggedSize, kDoubleAligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address(), kDoubleAlignment));
|
2017-02-15 15:42:27 +00:00
|
|
|
filler = HeapObject::FromAddress(start);
|
|
|
|
CHECK(obj != filler);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(filler.IsFiller());
|
|
|
|
CHECK_EQ(kTaggedSize, filler.Size());
|
|
|
|
CHECK(obj != filler && filler.IsFiller() && filler.Size() == kTaggedSize);
|
2015-05-29 13:18:13 +00:00
|
|
|
|
|
|
|
// Similarly for kDoubleUnaligned.
|
2015-06-02 22:56:00 +00:00
|
|
|
start = AlignOldSpace(kDoubleUnaligned, 0);
|
2018-12-19 19:10:21 +00:00
|
|
|
obj = OldSpaceAllocateAligned(kTaggedSize, kDoubleUnaligned);
|
2017-08-30 13:42:58 +00:00
|
|
|
// The object is aligned.
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address() + kTaggedSize, kDoubleAlignment));
|
2015-05-29 13:18:13 +00:00
|
|
|
// Try the opposite alignment case.
|
2018-12-19 19:10:21 +00:00
|
|
|
start = AlignOldSpace(kDoubleUnaligned, kTaggedSize);
|
|
|
|
obj = OldSpaceAllocateAligned(kTaggedSize, kDoubleUnaligned);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(IsAligned(obj.address() + kTaggedSize, kDoubleAlignment));
|
2017-02-15 15:42:27 +00:00
|
|
|
filler = HeapObject::FromAddress(start);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(obj != filler && filler.IsFiller() && filler.Size() == kTaggedSize);
|
2015-05-29 13:18:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-14 09:42:58 +00:00
|
|
|
TEST(HeapNumberAlignment) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope sc(isolate);
|
|
|
|
|
|
|
|
const auto required_alignment =
|
|
|
|
HeapObject::RequiredAlignment(*factory->heap_number_map());
|
|
|
|
const int maximum_misalignment =
|
|
|
|
Heap::GetMaximumFillToAlign(required_alignment);
|
|
|
|
|
|
|
|
for (int offset = 0; offset <= maximum_misalignment; offset += kTaggedSize) {
|
|
|
|
AlignNewSpace(required_alignment, offset);
|
|
|
|
Handle<Object> number_new = factory->NewNumber(1.000123);
|
|
|
|
CHECK(number_new->IsHeapNumber());
|
2019-02-18 08:58:18 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*number_new));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(0, Heap::GetFillToAlign(HeapObject::cast(*number_new).address(),
|
2019-02-14 09:42:58 +00:00
|
|
|
required_alignment));
|
|
|
|
|
|
|
|
AlignOldSpace(required_alignment, offset);
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<Object> number_old =
|
|
|
|
factory->NewNumber(1.000321, AllocationType::kOld);
|
2019-02-14 09:42:58 +00:00
|
|
|
CHECK(number_old->IsHeapNumber());
|
|
|
|
CHECK(heap->InOldSpace(*number_old));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(0, Heap::GetFillToAlign(HeapObject::cast(*number_old).address(),
|
2019-02-14 09:42:58 +00:00
|
|
|
required_alignment));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MutableHeapNumberAlignment) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope sc(isolate);
|
|
|
|
|
|
|
|
const auto required_alignment =
|
|
|
|
HeapObject::RequiredAlignment(*factory->mutable_heap_number_map());
|
|
|
|
const int maximum_misalignment =
|
|
|
|
Heap::GetMaximumFillToAlign(required_alignment);
|
|
|
|
|
|
|
|
for (int offset = 0; offset <= maximum_misalignment; offset += kTaggedSize) {
|
|
|
|
AlignNewSpace(required_alignment, offset);
|
|
|
|
Handle<Object> number_new = factory->NewMutableHeapNumber(1.000123);
|
|
|
|
CHECK(number_new->IsMutableHeapNumber());
|
2019-02-18 08:58:18 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*number_new));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(0, Heap::GetFillToAlign(HeapObject::cast(*number_new).address(),
|
2019-02-14 09:42:58 +00:00
|
|
|
required_alignment));
|
|
|
|
|
|
|
|
AlignOldSpace(required_alignment, offset);
|
|
|
|
Handle<Object> number_old =
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewMutableHeapNumber(1.000321, AllocationType::kOld);
|
2019-02-14 09:42:58 +00:00
|
|
|
CHECK(number_old->IsMutableHeapNumber());
|
|
|
|
CHECK(heap->InOldSpace(*number_old));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(0, Heap::GetFillToAlign(HeapObject::cast(*number_old).address(),
|
2019-02-14 09:42:58 +00:00
|
|
|
required_alignment));
|
|
|
|
}
|
|
|
|
}
|
2015-05-29 13:18:13 +00:00
|
|
|
|
2019-06-13 10:51:22 +00:00
|
|
|
TEST(TestSizeOfObjectsVsHeapObjectIteratorPrecision) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator iterator(CcTest::heap());
|
2014-05-22 11:13:37 +00:00
|
|
|
intptr_t size_of_objects_1 = CcTest::heap()->SizeOfObjects();
|
2010-11-15 10:38:24 +00:00
|
|
|
intptr_t size_of_objects_2 = 0;
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (!obj.IsFreeSpace()) {
|
|
|
|
size_of_objects_2 += obj.Size();
|
2012-09-14 11:16:56 +00:00
|
|
|
}
|
2010-11-15 10:38:24 +00:00
|
|
|
}
|
2012-01-31 13:33:44 +00:00
|
|
|
// Delta must be within 5% of the larger result.
|
|
|
|
// TODO(gc): Tighten this up by distinguishing between byte
|
|
|
|
// arrays that are real and those that merely mark free space
|
|
|
|
// on the heap.
|
2010-11-15 10:38:24 +00:00
|
|
|
if (size_of_objects_1 > size_of_objects_2) {
|
|
|
|
intptr_t delta = size_of_objects_1 - size_of_objects_2;
|
2016-04-12 16:13:08 +00:00
|
|
|
PrintF("Heap::SizeOfObjects: %" V8PRIdPTR
|
|
|
|
", "
|
|
|
|
"Iterator: %" V8PRIdPTR
|
|
|
|
", "
|
|
|
|
"delta: %" V8PRIdPTR "\n",
|
2010-11-15 10:38:24 +00:00
|
|
|
size_of_objects_1, size_of_objects_2, delta);
|
2012-01-31 13:33:44 +00:00
|
|
|
CHECK_GT(size_of_objects_1 / 20, delta);
|
2010-11-15 10:38:24 +00:00
|
|
|
} else {
|
|
|
|
intptr_t delta = size_of_objects_2 - size_of_objects_1;
|
2016-04-12 16:13:08 +00:00
|
|
|
PrintF("Heap::SizeOfObjects: %" V8PRIdPTR
|
|
|
|
", "
|
|
|
|
"Iterator: %" V8PRIdPTR
|
|
|
|
", "
|
|
|
|
"delta: %" V8PRIdPTR "\n",
|
2010-11-15 10:38:24 +00:00
|
|
|
size_of_objects_1, size_of_objects_2, delta);
|
2011-09-19 18:36:47 +00:00
|
|
|
CHECK_GT(size_of_objects_2 / 20, delta);
|
2010-11-15 10:38:24 +00:00
|
|
|
}
|
|
|
|
}
|
2010-12-21 10:49:40 +00:00
|
|
|
|
2011-09-20 13:37:40 +00:00
|
|
|
TEST(GrowAndShrinkNewSpace) {
|
2016-09-07 09:21:12 +00:00
|
|
|
// Avoid shrinking new space in GC epilogue. This can happen if allocation
|
|
|
|
// throughput samples have been taken while executing the benchmark.
|
|
|
|
FLAG_predictable = true;
|
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
NewSpace* new_space = heap->new_space();
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2016-04-05 13:11:47 +00:00
|
|
|
if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
|
2012-04-26 14:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-02-01 08:20:31 +00:00
|
|
|
// Make sure we're in a consistent state to start out.
|
2017-04-27 18:48:47 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2019-02-18 08:58:18 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
new_space->Shrink();
|
2017-02-01 08:20:31 +00:00
|
|
|
|
2011-09-20 13:37:40 +00:00
|
|
|
// Explicitly growing should double the space capacity.
|
2016-11-14 16:46:42 +00:00
|
|
|
size_t old_capacity, new_capacity;
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2011-09-20 13:37:40 +00:00
|
|
|
new_space->Grow();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(2 * old_capacity, new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope temporary_scope(CcTest::isolate());
|
|
|
|
heap::SimulateFullSpace(new_space);
|
|
|
|
}
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(old_capacity, new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Explicitly shrinking should not affect space capacity.
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2011-09-20 13:37:40 +00:00
|
|
|
new_space->Shrink();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(old_capacity, new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
2011-09-22 14:50:20 +00:00
|
|
|
// Let the scavenger empty the new space.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2011-09-22 14:50:20 +00:00
|
|
|
CHECK_LE(new_space->Size(), old_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Explicitly shrinking should halve the space capacity.
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2011-09-20 13:37:40 +00:00
|
|
|
new_space->Shrink();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(old_capacity, 2 * new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
|
|
|
|
// Consecutive shrinking should not affect space capacity.
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2011-09-20 13:37:40 +00:00
|
|
|
new_space->Shrink();
|
|
|
|
new_space->Shrink();
|
|
|
|
new_space->Shrink();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(old_capacity, new_capacity);
|
2011-09-20 13:37:40 +00:00
|
|
|
}
|
2011-11-08 12:42:02 +00:00
|
|
|
|
|
|
|
TEST(CollectingAllAvailableGarbageShrinksNewSpace) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = CcTest::heap();
|
2016-04-05 13:11:47 +00:00
|
|
|
if (heap->MaxSemiSpaceSize() == heap->InitialSemiSpaceSize()) {
|
2012-04-26 14:45:58 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-09-19 09:46:15 +00:00
|
|
|
NewSpace* new_space = heap->new_space();
|
2016-11-14 16:46:42 +00:00
|
|
|
size_t old_capacity, new_capacity;
|
2014-09-18 12:52:12 +00:00
|
|
|
old_capacity = new_space->TotalCapacity();
|
2011-11-08 12:42:02 +00:00
|
|
|
new_space->Grow();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(2 * old_capacity, new_capacity);
|
|
|
|
{
|
|
|
|
v8::HandleScope temporary_scope(CcTest::isolate());
|
|
|
|
heap::SimulateFullSpace(new_space);
|
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-09-18 12:52:12 +00:00
|
|
|
new_capacity = new_space->TotalCapacity();
|
2016-09-08 11:20:42 +00:00
|
|
|
CHECK_EQ(old_capacity, new_capacity);
|
2011-11-08 12:42:02 +00:00
|
|
|
}
|
2011-11-30 11:13:36 +00:00
|
|
|
|
2011-12-14 14:01:54 +00:00
|
|
|
static int NumberOfGlobalObjects() {
|
|
|
|
int count = 0;
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator iterator(CcTest::heap());
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = iterator.Next(); !obj.is_null();
|
|
|
|
obj = iterator.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (obj.IsJSGlobalObject()) count++;
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2015-12-02 12:35:12 +00:00
|
|
|
return count;
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that we don't embed maps from foreign contexts into
|
|
|
|
// optimized code.
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMap) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-14 14:01:54 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2011-12-14 14:01:54 +00:00
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-14 14:01:54 +00:00
|
|
|
CompileRun("var v = {x: 42}");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> v =
|
|
|
|
ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked();
|
2011-12-14 14:01:54 +00:00
|
|
|
ctx2->Enter();
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust());
|
2011-12-14 14:01:54 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() { return o.x; }"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
2011-12-14 14:01:54 +00:00
|
|
|
"f();");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(42, res->Int32Value(ctx2).FromJust());
|
|
|
|
CHECK(ctx2->Global()
|
|
|
|
->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0))
|
|
|
|
.FromJust());
|
2011-12-14 14:01:54 +00:00
|
|
|
ctx2->Exit();
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1)->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2014-07-24 08:28:02 +00:00
|
|
|
isolate->ContextDisposedNotification();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(1, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that we don't embed functions from foreign contexts into
|
|
|
|
// optimized code.
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaFunction) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-14 14:01:54 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2011-12-14 14:01:54 +00:00
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-14 14:01:54 +00:00
|
|
|
CompileRun("var v = function() { return 42; }");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> v =
|
|
|
|
ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked();
|
2011-12-14 14:01:54 +00:00
|
|
|
ctx2->Enter();
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust());
|
2011-12-14 14:01:54 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f(x) { return x(); }"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f(o);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
2011-12-14 14:01:54 +00:00
|
|
|
"f(o);");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(42, res->Int32Value(ctx2).FromJust());
|
|
|
|
CHECK(ctx2->Global()
|
|
|
|
->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0))
|
|
|
|
.FromJust());
|
2011-12-14 14:01:54 +00:00
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2014-07-24 08:28:02 +00:00
|
|
|
isolate->ContextDisposedNotification();
|
2011-12-14 14:01:54 +00:00
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(1, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2011-12-14 14:01:54 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMapKeyed) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2011-12-19 12:39:52 +00:00
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-19 12:39:52 +00:00
|
|
|
CompileRun("var v = [42, 43]");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> v =
|
|
|
|
ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked();
|
2011-12-19 12:39:52 +00:00
|
|
|
ctx2->Enter();
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust());
|
2011-12-19 12:39:52 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() { return o[0]; }"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(42, res->Int32Value(ctx2).FromJust());
|
|
|
|
CHECK(ctx2->Global()
|
|
|
|
->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0))
|
|
|
|
.FromJust());
|
2011-12-19 12:39:52 +00:00
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2014-07-24 08:28:02 +00:00
|
|
|
isolate->ContextDisposedNotification();
|
2011-12-19 12:39:52 +00:00
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(1, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-08-17 09:03:08 +00:00
|
|
|
TEST(LeakNativeContextViaMapProto) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2013-05-08 07:45:16 +00:00
|
|
|
v8::HandleScope outer_scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Persistent<v8::Context> ctx1p;
|
|
|
|
v8::Persistent<v8::Context> ctx2p;
|
2013-05-08 07:45:16 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2013-05-28 11:54:52 +00:00
|
|
|
ctx1p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
ctx2p.Reset(isolate, v8::Context::New(isolate));
|
|
|
|
v8::Local<v8::Context>::New(isolate, ctx1p)->Enter();
|
2013-05-08 07:45:16 +00:00
|
|
|
}
|
2011-12-19 12:39:52 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(2, NumberOfGlobalObjects());
|
2011-12-19 12:39:52 +00:00
|
|
|
|
|
|
|
{
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::HandleScope inner_scope(isolate);
|
2011-12-19 12:39:52 +00:00
|
|
|
CompileRun("var v = { y: 42}");
|
2013-05-28 11:54:52 +00:00
|
|
|
v8::Local<v8::Context> ctx1 = v8::Local<v8::Context>::New(isolate, ctx1p);
|
|
|
|
v8::Local<v8::Context> ctx2 = v8::Local<v8::Context>::New(isolate, ctx2p);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> v =
|
|
|
|
ctx1->Global()->Get(ctx1, v8_str("v")).ToLocalChecked();
|
2011-12-19 12:39:52 +00:00
|
|
|
ctx2->Enter();
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(ctx2->Global()->Set(ctx2, v8_str("o"), v).FromJust());
|
2011-12-19 12:39:52 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
|
|
|
" var p = {x: 42};"
|
|
|
|
" p.__proto__ = o;"
|
|
|
|
" return p.x;"
|
|
|
|
"}"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2011-12-19 12:39:52 +00:00
|
|
|
"for (var i = 0; i < 10; ++i) f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(42, res->Int32Value(ctx2).FromJust());
|
|
|
|
CHECK(ctx2->Global()
|
|
|
|
->Set(ctx2, v8_str("o"), v8::Int32::New(isolate, 0))
|
|
|
|
.FromJust());
|
2011-12-19 12:39:52 +00:00
|
|
|
ctx2->Exit();
|
|
|
|
ctx1->Exit();
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx1p.Reset();
|
2014-07-24 08:28:02 +00:00
|
|
|
isolate->ContextDisposedNotification();
|
2011-12-19 12:39:52 +00:00
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-11-27 16:59:28 +00:00
|
|
|
CHECK_EQ(1, NumberOfGlobalObjects());
|
2013-11-22 12:43:17 +00:00
|
|
|
ctx2p.Reset();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2011-12-19 12:39:52 +00:00
|
|
|
CHECK_EQ(0, NumberOfGlobalObjects());
|
|
|
|
}
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(InstanceOfStubWriteBarrier) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-08-23 15:15:27 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2012-10-12 11:41:14 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_verify_heap = true;
|
2012-01-11 09:49:47 +00:00
|
|
|
#endif
|
2012-10-12 11:41:14 +00:00
|
|
|
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer()) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_force_marking_deque_overflows) return;
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope outer_scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
{
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-01-11 09:39:37 +00:00
|
|
|
CompileRun(
|
|
|
|
"function foo () { }"
|
|
|
|
"function mkbar () { return new (new Function(\"\")) (); }"
|
|
|
|
"function f (x) { return (x instanceof foo); }"
|
|
|
|
"function g () { f(mkbar()); }"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2012-01-11 09:39:37 +00:00
|
|
|
"f(new foo()); f(new foo());"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f(new foo()); g();");
|
|
|
|
}
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2015-08-07 09:36:42 +00:00
|
|
|
marking->Stop();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::heap()->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2012-01-11 09:39:37 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
i::Handle<JSFunction> f = i::Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2012-01-11 09:39:37 +00:00
|
|
|
|
|
|
|
CHECK(f->IsOptimized());
|
|
|
|
|
2017-08-12 12:17:52 +00:00
|
|
|
IncrementalMarking::MarkingState* marking_state = marking->marking_state();
|
2017-08-10 16:54:55 +00:00
|
|
|
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kStepSizeInMs = 100;
|
2017-08-10 16:54:55 +00:00
|
|
|
while (!marking_state->IsBlack(f->code()) && !marking->IsStopped()) {
|
2012-04-03 07:32:19 +00:00
|
|
|
// Discard any pending GC requests otherwise we will get GC when we enter
|
|
|
|
// code below.
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kStepSizeInMs, IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2012-01-11 09:39:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
|
|
|
|
{
|
2013-09-19 08:54:58 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Object> global = CcTest::global();
|
|
|
|
v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
|
|
|
|
global->Get(ctx, v8_str("g")).ToLocalChecked());
|
|
|
|
g->Call(ctx, global, 0, nullptr).ToLocalChecked();
|
2012-01-11 09:39:37 +00:00
|
|
|
}
|
|
|
|
|
2013-09-19 09:46:15 +00:00
|
|
|
CcTest::heap()->incremental_marking()->set_should_hurry(true);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2012-01-11 09:39:37 +00:00
|
|
|
}
|
2012-01-19 13:38:37 +00:00
|
|
|
|
2015-08-21 07:09:08 +00:00
|
|
|
HEAP_TEST(GCFlags) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2015-08-21 07:09:08 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
|
|
|
|
heap->set_current_gc_flags(Heap::kNoGCFlags);
|
2015-08-25 10:59:40 +00:00
|
|
|
CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_);
|
2015-08-21 07:09:08 +00:00
|
|
|
|
2018-09-19 08:19:40 +00:00
|
|
|
// Check whether we appropriately reset flags after GC.
|
|
|
|
CcTest::heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask,
|
|
|
|
GarbageCollectionReason::kTesting);
|
2015-08-25 10:59:40 +00:00
|
|
|
CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_);
|
2015-08-21 07:09:08 +00:00
|
|
|
|
|
|
|
MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
marking->Stop();
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(Heap::kReduceMemoryFootprintMask,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2015-08-25 10:59:40 +00:00
|
|
|
CHECK_NE(0, heap->current_gc_flags_ & Heap::kReduceMemoryFootprintMask);
|
2015-08-21 07:09:08 +00:00
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2015-08-21 10:05:18 +00:00
|
|
|
// NewSpace scavenges should not overwrite the flags.
|
2015-08-25 10:59:40 +00:00
|
|
|
CHECK_NE(0, heap->current_gc_flags_ & Heap::kReduceMemoryFootprintMask);
|
2015-08-21 07:09:08 +00:00
|
|
|
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-08-25 10:59:40 +00:00
|
|
|
CHECK_EQ(Heap::kNoGCFlags, heap->current_gc_flags_);
|
2015-08-21 07:09:08 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 02:08:21 +00:00
|
|
|
HEAP_TEST(Regress845060) {
|
|
|
|
// Regression test for crbug.com/845060, where a raw pointer to a string's
|
|
|
|
// data was kept across an allocation. If the allocation causes GC and
|
|
|
|
// moves the string, such raw pointers become invalid.
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
|
|
|
|
// Preparation: create a string in new space.
|
|
|
|
Local<Value> str = CompileRun("var str = (new Array(10000)).join('x'); str");
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*v8::Utils::OpenHandle(*str)));
|
2018-05-22 02:08:21 +00:00
|
|
|
|
|
|
|
// Idle incremental marking sets the "kReduceMemoryFootprint" flag, which
|
|
|
|
// causes from_space to be unmapped after scavenging.
|
|
|
|
heap->StartIdleIncrementalMarking(GarbageCollectionReason::kTesting);
|
|
|
|
CHECK(heap->ShouldReduceMemory());
|
|
|
|
|
|
|
|
// Run the test (which allocates results) until the original string was
|
|
|
|
// promoted to old space. Unmapping of from_space causes accesses to any
|
|
|
|
// stale raw pointers to crash.
|
2019-06-24 14:15:46 +00:00
|
|
|
CompileRun("while (%InYoungGeneration(str)) { str.split(''); }");
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(!Heap::InYoungGeneration(*v8::Utils::OpenHandle(*str)));
|
2018-05-22 02:08:21 +00:00
|
|
|
}
|
2015-08-21 07:09:08 +00:00
|
|
|
|
2014-10-13 16:27:55 +00:00
|
|
|
TEST(IdleNotificationFinishMarking) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-08-23 15:15:27 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-10-13 16:27:55 +00:00
|
|
|
CcTest::InitializeVM();
|
2016-05-20 13:30:22 +00:00
|
|
|
const int initial_gc_count = CcTest::heap()->gc_count();
|
|
|
|
heap::SimulateFullSpace(CcTest::heap()->old_space());
|
2014-10-13 16:27:55 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2015-08-07 09:36:42 +00:00
|
|
|
marking->Stop();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::heap()->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2014-10-13 16:27:55 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->gc_count(), initial_gc_count);
|
2014-10-13 16:27:55 +00:00
|
|
|
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kStepSizeInMs = 100;
|
2014-10-13 16:27:55 +00:00
|
|
|
do {
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kStepSizeInMs, IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2016-09-06 15:28:54 +00:00
|
|
|
} while (
|
2017-06-23 12:32:55 +00:00
|
|
|
!CcTest::heap()->mark_compact_collector()->marking_worklist()->IsEmpty());
|
2014-10-13 16:27:55 +00:00
|
|
|
|
2015-03-18 10:01:23 +00:00
|
|
|
marking->SetWeakClosureWasOverApproximatedForTesting(true);
|
|
|
|
|
2014-10-13 16:27:55 +00:00
|
|
|
// The next idle notification has to finish incremental marking.
|
2015-03-24 08:29:52 +00:00
|
|
|
const double kLongIdleTime = 1000.0;
|
|
|
|
CcTest::isolate()->IdleNotificationDeadline(
|
|
|
|
(v8::base::TimeTicks::HighResolutionNow().ToInternalValue() /
|
|
|
|
static_cast<double>(v8::base::Time::kMicrosecondsPerSecond)) +
|
|
|
|
kLongIdleTime);
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_EQ(CcTest::heap()->gc_count(), initial_gc_count + 1);
|
2014-10-13 16:27:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-04-05 15:36:31 +00:00
|
|
|
// Test that HAllocateObject will always return an object in new-space.
|
|
|
|
TEST(OptimizedAllocationAlwaysInNewSpace) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(CcTest::heap()->new_space());
|
2014-03-19 11:31:43 +00:00
|
|
|
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
2012-04-05 15:36:31 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function c(x) {"
|
|
|
|
" this.x = x;"
|
|
|
|
" for (var i = 0; i < 32; i++) {"
|
|
|
|
" this['x' + i] = x;"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"function f(x) { return new c(x); };"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2012-04-05 15:36:31 +00:00
|
|
|
"f(1); f(2); f(3);"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f(4);");
|
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(4, res.As<v8::Object>()
|
|
|
|
->GetRealNamedProperty(ctx, v8_str("x"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(ctx)
|
|
|
|
.FromJust());
|
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSReceiver> o =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res));
|
2013-03-07 14:00:53 +00:00
|
|
|
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*o));
|
2013-03-07 14:00:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-08-27 07:42:23 +00:00
|
|
|
TEST(OptimizedPretenuringAllocationFolding) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-08-27 07:42:23 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-08-27 07:42:23 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array();"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [[{}], [1.1]];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements-1]"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2013-08-27 07:42:23 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-08-27 07:42:23 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> int_array =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> int_array_handle = i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(int_array)));
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> double_array =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> double_array_handle = i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(double_array)));
|
2015-11-09 19:48:08 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSReceiver> o =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res));
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*int_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*double_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements()));
|
2013-08-27 07:42:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-25 07:47:53 +00:00
|
|
|
TEST(OptimizedPretenuringObjectArrayLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
2017-06-16 10:07:41 +00:00
|
|
|
FLAG_stress_incremental_marking) {
|
2017-05-29 11:06:13 +00:00
|
|
|
return;
|
2017-06-16 10:07:41 +00:00
|
|
|
}
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-03-07 14:00:53 +00:00
|
|
|
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [{}, {}, {}];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-03-07 14:00:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2013-03-07 14:00:53 +00:00
|
|
|
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(o->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
2013-03-07 14:00:53 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 09:30:47 +00:00
|
|
|
TEST(OptimizedPretenuringNestedInObjectProperties) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
|
|
|
// Grow new space until maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep the nested literal alive while its root is freed
|
|
|
|
i::ScopedVector<char> source(1024);
|
|
|
|
i::SNPrintF(source,
|
|
|
|
"let number_elements = %d;"
|
|
|
|
"let elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (let i = 0; i < number_elements; i++) {"
|
|
|
|
" let l = {a: {c: 2.2, d: {e: 3.3}}, b: 1.1}; "
|
|
|
|
" elements[i] = l.a;"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements-1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2018-06-21 09:30:47 +00:00
|
|
|
"f(); gc(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2018-06-21 09:30:47 +00:00
|
|
|
|
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
|
|
|
|
|
|
|
// Nested literal sites are only pretenured if the top level
|
|
|
|
// literal is pretenured
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*o));
|
2018-06-21 09:30:47 +00:00
|
|
|
}
|
2013-03-07 14:00:53 +00:00
|
|
|
|
2013-06-25 07:47:53 +00:00
|
|
|
TEST(OptimizedPretenuringMixedInObjectProperties) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-04-10 13:52:08 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-04-10 13:52:08 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = {a: {c: 2.2, d: {}}, b: 1.1};"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-04-10 13:52:08 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2013-04-10 13:52:08 +00:00
|
|
|
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
2014-06-10 14:01:08 +00:00
|
|
|
FieldIndex idx1 = FieldIndex::ForPropertyIndex(o->map(), 0);
|
|
|
|
FieldIndex idx2 = FieldIndex::ForPropertyIndex(o->map(), 1);
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx1)));
|
2014-11-11 10:24:52 +00:00
|
|
|
if (!o->IsUnboxedDoubleField(idx2)) {
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(o->RawFastPropertyAt(idx2)));
|
2014-11-11 10:24:52 +00:00
|
|
|
} else {
|
|
|
|
CHECK_EQ(1.1, o->RawFastDoublePropertyAt(idx2));
|
|
|
|
}
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2018-12-08 02:59:17 +00:00
|
|
|
JSObject inner_object = JSObject::cast(o->RawFastPropertyAt(idx1));
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(inner_object));
|
2019-05-23 07:47:44 +00:00
|
|
|
if (!inner_object.IsUnboxedDoubleField(idx1)) {
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(inner_object.RawFastPropertyAt(idx1)));
|
2014-11-11 10:24:52 +00:00
|
|
|
} else {
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(2.2, inner_object.RawFastDoublePropertyAt(idx1));
|
2014-11-11 10:24:52 +00:00
|
|
|
}
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(inner_object.RawFastPropertyAt(idx2)));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringDoubleArrayProperties) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
2018-05-08 12:53:25 +00:00
|
|
|
// Grow new space until maximum capacity reached.
|
2014-06-03 07:55:38 +00:00
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = {a: 1.1, b: 2.2};"
|
|
|
|
" }"
|
|
|
|
" return elements[i - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
2018-07-04 09:10:05 +00:00
|
|
|
CHECK_EQ(o->property_array(),
|
|
|
|
ReadOnlyRoots(CcTest::heap()).empty_property_array());
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringdoubleArrayLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [1.1, 2.2, 3.3];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(o->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedMixedArrayLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [[{}, {}, {}], [1.1, 2.2, 3.3]];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> int_array =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> int_array_handle = i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(int_array)));
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> double_array =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> double_array_handle = i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(double_array)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*int_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(int_array_handle->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*double_array_handle));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(double_array_handle->elements()));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedObjectLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [[{}, {}, {}],[{}, {}, {}]];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> int_array_1 =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSObject> int_array_handle_1 = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(int_array_1)));
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> int_array_2 =
|
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSObject> int_array_handle_2 = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(int_array_2)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*int_array_handle_1));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(int_array_handle_1->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*int_array_handle_2));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(int_array_handle_2->elements()));
|
2013-06-25 07:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(OptimizedPretenuringNestedDoubleLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
2013-06-25 07:47:53 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2014-06-03 07:55:38 +00:00
|
|
|
// Grow new space unitl maximum capacity reached.
|
|
|
|
while (!CcTest::heap()->new_space()->IsAtMaximumCapacity()) {
|
|
|
|
CcTest::heap()->new_space()->Grow();
|
|
|
|
}
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
i::ScopedVector<char> source(1024);
|
2017-06-16 10:07:41 +00:00
|
|
|
i::SNPrintF(source,
|
|
|
|
"var number_elements = %d;"
|
|
|
|
"var elements = new Array(number_elements);"
|
|
|
|
"function f() {"
|
|
|
|
" for (var i = 0; i < number_elements; i++) {"
|
|
|
|
" elements[i] = [[1.1, 1.2, 1.3],[2.1, 2.2, 2.3]];"
|
|
|
|
" }"
|
|
|
|
" return elements[number_elements - 1];"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%%PrepareFunctionForOptimization(f);"
|
2017-06-16 10:07:41 +00:00
|
|
|
"f(); gc();"
|
|
|
|
"f(); f();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();",
|
|
|
|
kPretenureCreationCount);
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-04-29 11:06:49 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(source.begin());
|
2013-06-25 07:47:53 +00:00
|
|
|
|
|
|
|
v8::Local<v8::Value> double_array_1 =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("0")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> double_array_handle_1 = i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(double_array_1)));
|
2013-06-25 07:47:53 +00:00
|
|
|
v8::Local<v8::Value> double_array_2 =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Object::Cast(*res)->Get(ctx, v8_str("1")).ToLocalChecked();
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> double_array_handle_2 = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(double_array_2)));
|
2013-06-25 07:47:53 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2015-04-07 11:31:57 +00:00
|
|
|
CHECK(CcTest::heap()->InOldSpace(*o));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*double_array_handle_1));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(double_array_handle_1->elements()));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(*double_array_handle_2));
|
|
|
|
CHECK(CcTest::heap()->InOldSpace(double_array_handle_2->elements()));
|
2013-04-10 13:52:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-05-27 07:48:36 +00:00
|
|
|
// Test regular array literals allocation.
|
|
|
|
TEST(OptimizedAllocationArrayLiterals) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-07-15 15:12:16 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!CcTest::i_isolate()->use_optimizer() || FLAG_always_opt) return;
|
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-07-15 15:12:16 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2013-07-15 15:12:16 +00:00
|
|
|
v8::Local<v8::Value> res = CompileRun(
|
|
|
|
"function f() {"
|
2014-05-27 07:48:36 +00:00
|
|
|
" var numbers = new Array(1, 2, 3);"
|
|
|
|
" numbers[0] = 3.14;"
|
|
|
|
" return numbers;"
|
2013-07-15 15:12:16 +00:00
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(f);"
|
2013-07-15 15:12:16 +00:00
|
|
|
"f(); f(); f();"
|
|
|
|
"%OptimizeFunctionOnNextCall(f);"
|
|
|
|
"f();");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(static_cast<int>(3.14), v8::Object::Cast(*res)
|
|
|
|
->Get(ctx, v8_str("0"))
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Int32Value(ctx)
|
|
|
|
.FromJust());
|
2013-07-15 15:12:16 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSObject> o = Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(res)));
|
2014-05-27 07:48:36 +00:00
|
|
|
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(o->elements()));
|
2013-07-15 15:12:16 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 06:16:42 +00:00
|
|
|
static int CountMapTransitions(i::Isolate* isolate, Map map) {
|
2017-07-28 07:01:59 +00:00
|
|
|
DisallowHeapAllocation no_gc;
|
2018-06-05 10:21:35 +00:00
|
|
|
return TransitionsAccessor(isolate, map, &no_gc).NumberOfTransitions();
|
2012-05-16 10:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Test that map transitions are cleared and maps are collected with
|
|
|
|
// incremental marking as well.
|
|
|
|
TEST(Regress1465) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_trace_incremental_marking = true;
|
|
|
|
FLAG_retain_maps_for_n_gc = 0;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-06-05 10:21:35 +00:00
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
i::Isolate* i_isolate = CcTest::i_isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Local<v8::Context> ctx = isolate->GetCurrentContext();
|
2012-08-02 14:20:38 +00:00
|
|
|
static const int transitions_count = 256;
|
2012-05-16 10:07:50 +00:00
|
|
|
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("function F() {}");
|
2012-08-02 14:20:38 +00:00
|
|
|
{
|
2014-03-19 11:31:43 +00:00
|
|
|
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
2012-08-02 14:20:38 +00:00
|
|
|
for (int i = 0; i < transitions_count; i++) {
|
|
|
|
EmbeddedVector<char, 64> buffer;
|
2014-06-13 16:43:27 +00:00
|
|
|
SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
|
2019-04-29 11:06:49 +00:00
|
|
|
CompileRun(buffer.begin());
|
2012-08-02 14:20:38 +00:00
|
|
|
}
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("var root = new F;");
|
2012-05-16 10:07:50 +00:00
|
|
|
}
|
2012-08-02 14:20:38 +00:00
|
|
|
|
2015-11-16 16:48:43 +00:00
|
|
|
i::Handle<JSReceiver> root =
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("root")).ToLocalChecked()));
|
2012-05-16 10:07:50 +00:00
|
|
|
|
|
|
|
// Count number of live transitions before marking.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_before = CountMapTransitions(i_isolate, root->map());
|
2012-05-16 10:07:50 +00:00
|
|
|
CompileRun("%DebugPrint(root);");
|
2012-08-02 14:20:38 +00:00
|
|
|
CHECK_EQ(transitions_count, transitions_before);
|
2012-05-16 10:07:50 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2012-05-16 10:07:50 +00:00
|
|
|
|
|
|
|
// Count number of live transitions after marking. Note that one transition
|
|
|
|
// is left, because 'o' still holds an instance of one transition target.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_after = CountMapTransitions(i_isolate, root->map());
|
2012-05-16 10:07:50 +00:00
|
|
|
CompileRun("%DebugPrint(root);");
|
|
|
|
CHECK_EQ(1, transitions_after);
|
|
|
|
}
|
2012-05-29 16:39:26 +00:00
|
|
|
|
2019-02-08 12:43:15 +00:00
|
|
|
static i::Handle<JSObject> GetByName(const char* name) {
|
|
|
|
return i::Handle<JSObject>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(
|
|
|
|
CcTest::global()
|
|
|
|
->Get(CcTest::isolate()->GetCurrentContext(), v8_str(name))
|
|
|
|
.ToLocalChecked())));
|
|
|
|
}
|
2012-05-29 16:39:26 +00:00
|
|
|
|
2014-04-14 08:58:00 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
static void AddTransitions(int transitions_count) {
|
|
|
|
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
|
|
|
for (int i = 0; i < transitions_count; i++) {
|
|
|
|
EmbeddedVector<char, 64> buffer;
|
2014-06-13 16:43:27 +00:00
|
|
|
SNPrintF(buffer, "var o = new F; o.prop%d = %d;", i, i);
|
2019-04-29 11:06:49 +00:00
|
|
|
CompileRun(buffer.begin());
|
2014-04-14 08:58:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void AddPropertyTo(
|
|
|
|
int gc_count, Handle<JSObject> object, const char* property_name) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Handle<String> prop_name = factory->InternalizeUtf8String(property_name);
|
|
|
|
Handle<Smi> twenty_three(Smi::FromInt(23), isolate);
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_gc_interval = gc_count;
|
|
|
|
FLAG_gc_global = true;
|
|
|
|
FLAG_retain_maps_for_n_gc = 0;
|
2014-04-14 08:58:00 +00:00
|
|
|
CcTest::heap()->set_allocation_timeout(gc_count);
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, object, prop_name, twenty_three).Check();
|
2014-04-14 08:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArrayShrinksDuringAllocToZero) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-04-14 08:58:00 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-06-05 10:21:35 +00:00
|
|
|
i::Isolate* i_isolate = CcTest::i_isolate();
|
2014-04-14 08:58:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
static const int transitions_count = 10;
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("function F() { }");
|
2014-04-14 08:58:00 +00:00
|
|
|
AddTransitions(transitions_count);
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("var root = new F;");
|
2014-04-14 08:58:00 +00:00
|
|
|
Handle<JSObject> root = GetByName("root");
|
|
|
|
|
|
|
|
// Count number of live transitions before marking.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_before = CountMapTransitions(i_isolate, root->map());
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(transitions_count, transitions_before);
|
|
|
|
|
|
|
|
// Get rid of o
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("o = new F;"
|
|
|
|
"root = new F");
|
2014-04-14 08:58:00 +00:00
|
|
|
root = GetByName("root");
|
|
|
|
AddPropertyTo(2, root, "funny");
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2014-04-14 08:58:00 +00:00
|
|
|
|
|
|
|
// Count number of live transitions after marking. Note that one transition
|
|
|
|
// is left, because 'o' still holds an instance of one transition target.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_after =
|
2019-05-23 07:47:44 +00:00
|
|
|
CountMapTransitions(i_isolate, Map::cast(root->map().GetBackPointer()));
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(1, transitions_after);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArrayShrinksDuringAllocToOne) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-04-14 08:58:00 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-06-05 10:21:35 +00:00
|
|
|
i::Isolate* i_isolate = CcTest::i_isolate();
|
2014-04-14 08:58:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
static const int transitions_count = 10;
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("function F() {}");
|
2014-04-14 08:58:00 +00:00
|
|
|
AddTransitions(transitions_count);
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("var root = new F;");
|
2014-04-14 08:58:00 +00:00
|
|
|
Handle<JSObject> root = GetByName("root");
|
|
|
|
|
|
|
|
// Count number of live transitions before marking.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_before = CountMapTransitions(i_isolate, root->map());
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(transitions_count, transitions_before);
|
|
|
|
|
|
|
|
root = GetByName("root");
|
|
|
|
AddPropertyTo(2, root, "funny");
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2014-04-14 08:58:00 +00:00
|
|
|
|
|
|
|
// Count number of live transitions after marking. Note that one transition
|
|
|
|
// is left, because 'o' still holds an instance of one transition target.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_after =
|
2019-05-23 07:47:44 +00:00
|
|
|
CountMapTransitions(i_isolate, Map::cast(root->map().GetBackPointer()));
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(2, transitions_after);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(TransitionArrayShrinksDuringAllocToOnePropertyFound) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-04-14 08:58:00 +00:00
|
|
|
CcTest::InitializeVM();
|
2018-06-05 10:21:35 +00:00
|
|
|
i::Isolate* i_isolate = CcTest::i_isolate();
|
2014-04-14 08:58:00 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
static const int transitions_count = 10;
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("function F() {}");
|
2014-04-14 08:58:00 +00:00
|
|
|
AddTransitions(transitions_count);
|
2014-04-16 10:45:57 +00:00
|
|
|
CompileRun("var root = new F;");
|
2014-04-14 08:58:00 +00:00
|
|
|
Handle<JSObject> root = GetByName("root");
|
|
|
|
|
|
|
|
// Count number of live transitions before marking.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_before = CountMapTransitions(i_isolate, root->map());
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(transitions_count, transitions_before);
|
|
|
|
|
|
|
|
root = GetByName("root");
|
|
|
|
AddPropertyTo(0, root, "prop9");
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2014-04-14 08:58:00 +00:00
|
|
|
|
|
|
|
// Count number of live transitions after marking. Note that one transition
|
|
|
|
// is left, because 'o' still holds an instance of one transition target.
|
2018-06-05 10:21:35 +00:00
|
|
|
int transitions_after =
|
2019-05-23 07:47:44 +00:00
|
|
|
CountMapTransitions(i_isolate, Map::cast(root->map().GetBackPointer()));
|
2014-04-14 08:58:00 +00:00
|
|
|
CHECK_EQ(1, transitions_after);
|
|
|
|
}
|
|
|
|
#endif // DEBUG
|
|
|
|
|
|
|
|
|
2012-06-22 09:29:49 +00:00
|
|
|
TEST(ReleaseOverReservedPages) {
|
2014-04-14 13:52:41 +00:00
|
|
|
if (FLAG_never_compact) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_trace_gc = true;
|
2012-07-31 14:59:32 +00:00
|
|
|
// The optimizer can allocate stuff, messing up the test.
|
2018-10-22 11:45:45 +00:00
|
|
|
#ifndef V8_LITE_MODE
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_opt = false;
|
|
|
|
FLAG_always_opt = false;
|
2018-10-22 11:45:45 +00:00
|
|
|
#endif // V8_LITE_MODE
|
2017-11-20 12:13:24 +00:00
|
|
|
// - Parallel compaction increases fragmentation, depending on how existing
|
|
|
|
// memory is distributed. Since this is non-deterministic because of
|
|
|
|
// concurrent sweeping, we disable it for this test.
|
|
|
|
// - Concurrent sweeping adds non determinism, depending on when memory is
|
|
|
|
// available for further reuse.
|
|
|
|
// - Fast evacuation of pages may result in a different page count in old
|
|
|
|
// space.
|
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_page_promotion = false;
|
2017-11-20 12:13:24 +00:00
|
|
|
FLAG_parallel_compaction = false;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2016-09-07 09:21:12 +00:00
|
|
|
// If there's snapshot available, we don't know whether 20 small arrays will
|
|
|
|
// fit on the initial pages.
|
|
|
|
if (!isolate->snapshot_available()) return;
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-09-19 09:46:15 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-02-18 08:58:18 +00:00
|
|
|
// Ensure that the young generation is empty.
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2012-06-22 09:29:49 +00:00
|
|
|
static const int number_of_test_pages = 20;
|
|
|
|
|
|
|
|
// Prepare many pages with low live-bytes count.
|
2015-04-07 11:31:57 +00:00
|
|
|
PagedSpace* old_space = heap->old_space();
|
2016-05-20 13:30:22 +00:00
|
|
|
const int initial_page_count = old_space->CountTotalPages();
|
|
|
|
const int overall_page_count = number_of_test_pages + initial_page_count;
|
2012-06-22 09:29:49 +00:00
|
|
|
for (int i = 0; i < number_of_test_pages; i++) {
|
2014-03-19 11:31:43 +00:00
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(old_space);
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewFixedArray(1, AllocationType::kOld);
|
2012-06-22 09:29:49 +00:00
|
|
|
}
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_EQ(overall_page_count, old_space->CountTotalPages());
|
2012-06-22 09:29:49 +00:00
|
|
|
|
|
|
|
// Triggering one GC will cause a lot of garbage to be discovered but
|
|
|
|
// even spread across all allocated pages.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_GE(overall_page_count, old_space->CountTotalPages());
|
2012-06-22 09:29:49 +00:00
|
|
|
|
|
|
|
// Triggering subsequent GCs should cause at least half of the pages
|
|
|
|
// to be released to the OS after at most two cycles.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_GE(overall_page_count, old_space->CountTotalPages());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-05-20 13:30:22 +00:00
|
|
|
CHECK_GE(overall_page_count, old_space->CountTotalPages() * 2);
|
2012-06-22 09:29:49 +00:00
|
|
|
|
2016-08-28 07:28:14 +00:00
|
|
|
// Triggering a last-resort GC should cause all pages to be released to the
|
|
|
|
// OS so that other processes can seize the memory. If we get a failure here
|
|
|
|
// where there are 2 pages left instead of 1, then we should increase the
|
|
|
|
// size of the first page a little in SizeOfFirstPage in spaces.cc. The
|
|
|
|
// first page should be small in order to reduce memory used when the VM
|
|
|
|
// boots, but if the 20 small arrays don't fit on the first page then that's
|
|
|
|
// an indication that it is too small.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2019-02-18 08:58:18 +00:00
|
|
|
CHECK_GE(initial_page_count, old_space->CountTotalPages());
|
2012-06-22 09:29:49 +00:00
|
|
|
}
|
2012-07-18 13:39:53 +00:00
|
|
|
|
2015-05-11 10:57:55 +00:00
|
|
|
static int forced_gc_counter = 0;
|
|
|
|
|
|
|
|
void MockUseCounterCallback(v8::Isolate* isolate,
|
|
|
|
v8::Isolate::UseCounterFeature feature) {
|
2015-11-02 19:22:32 +00:00
|
|
|
isolate->GetCurrentContext();
|
2015-05-11 10:57:55 +00:00
|
|
|
if (feature == v8::Isolate::kForcedGC) {
|
|
|
|
forced_gc_counter++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CountForcedGC) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_expose_gc = true;
|
2015-05-11 10:57:55 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
|
|
|
isolate->SetUseCounterCallback(MockUseCounterCallback);
|
|
|
|
|
|
|
|
forced_gc_counter = 0;
|
|
|
|
const char* source = "gc();";
|
|
|
|
CompileRun(source);
|
|
|
|
CHECK_GT(forced_gc_counter, 0);
|
|
|
|
}
|
|
|
|
|
2012-07-18 13:39:53 +00:00
|
|
|
|
2012-07-27 09:54:56 +00:00
|
|
|
#ifdef OBJECT_PRINT
|
|
|
|
TEST(PrintSharedFunctionInfo) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2012-07-27 09:54:56 +00:00
|
|
|
const char* source = "f = function() { return 987654321; }\n"
|
|
|
|
"g = function() { return 123456789; }\n";
|
|
|
|
CompileRun(source);
|
2015-11-09 19:48:08 +00:00
|
|
|
i::Handle<JSFunction> g = i::Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("g")).ToLocalChecked())));
|
2012-07-27 09:54:56 +00:00
|
|
|
|
2018-06-14 12:46:07 +00:00
|
|
|
StdoutStream os;
|
2019-05-23 07:47:44 +00:00
|
|
|
g->shared().Print(os);
|
2014-09-30 10:29:32 +00:00
|
|
|
os << std::endl;
|
2012-07-27 09:54:56 +00:00
|
|
|
}
|
|
|
|
#endif // OBJECT_PRINT
|
2012-07-30 13:09:09 +00:00
|
|
|
|
|
|
|
|
2015-02-04 09:46:05 +00:00
|
|
|
TEST(IncrementalMarkingPreservesMonomorphicCallIC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt) return;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2012-08-01 11:24:14 +00:00
|
|
|
v8::Local<v8::Value> fun1, fun2;
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2012-08-01 11:24:14 +00:00
|
|
|
{
|
|
|
|
CompileRun("function fun() {};");
|
2015-11-17 07:14:46 +00:00
|
|
|
fun1 = CcTest::global()->Get(ctx, v8_str("fun")).ToLocalChecked();
|
2012-08-01 11:24:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
CompileRun("function fun() {};");
|
2015-11-17 07:14:46 +00:00
|
|
|
fun2 = CcTest::global()->Get(ctx, v8_str("fun")).ToLocalChecked();
|
2012-08-01 11:24:14 +00:00
|
|
|
}
|
|
|
|
|
2015-11-17 07:14:46 +00:00
|
|
|
// Prepare function f that contains type feedback for the two closures.
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("fun1"), fun1).FromJust());
|
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("fun2"), fun2).FromJust());
|
2019-03-25 15:05:47 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f(a, b) { a(); b(); } %EnsureFeedbackVectorForFunction(f); "
|
|
|
|
"f(fun1, fun2);");
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2012-08-01 11:24:14 +00:00
|
|
|
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector(f->feedback_vector(), f->GetIsolate());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper feedback_helper(feedback_vector);
|
2014-02-10 21:38:17 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
int expected_slots = 2;
|
2015-10-01 13:48:05 +00:00
|
|
|
CHECK_EQ(expected_slots, feedback_helper.slot_count());
|
2015-06-04 16:22:29 +00:00
|
|
|
int slot1 = 0;
|
|
|
|
int slot2 = 1;
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeak());
|
|
|
|
CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeak());
|
2012-08-01 11:24:14 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2012-08-01 11:24:14 +00:00
|
|
|
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(feedback_vector->Get(feedback_helper.slot(slot1))->IsWeak());
|
|
|
|
CHECK(feedback_vector->Get(feedback_helper.slot(slot2))->IsWeak());
|
2012-08-01 11:24:14 +00:00
|
|
|
}
|
2012-08-06 10:35:48 +00:00
|
|
|
|
|
|
|
|
2015-10-01 13:48:05 +00:00
|
|
|
static void CheckVectorIC(Handle<JSFunction> f, int slot_index,
|
2014-11-27 16:36:18 +00:00
|
|
|
InlineCacheState desired_state) {
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> vector =
|
|
|
|
Handle<FeedbackVector>(f->feedback_vector(), f->GetIsolate());
|
2015-10-01 13:48:05 +00:00
|
|
|
FeedbackVectorHelper helper(vector);
|
2017-02-07 15:19:35 +00:00
|
|
|
FeedbackSlot slot = helper.slot(slot_index);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(vector, slot);
|
2019-02-13 12:24:26 +00:00
|
|
|
CHECK(nexus.ic_state() == desired_state);
|
2014-11-27 16:36:18 +00:00
|
|
|
}
|
|
|
|
|
2015-04-02 09:39:32 +00:00
|
|
|
TEST(IncrementalMarkingPreservesMonomorphicConstructor) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
|
|
|
if (FLAG_always_opt) return;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2015-04-02 09:39:32 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2015-04-02 09:39:32 +00:00
|
|
|
// Prepare function f that contains a monomorphic IC for object
|
|
|
|
// originating from the same native context.
|
|
|
|
CompileRun(
|
|
|
|
"function fun() { this.x = 1; };"
|
2019-03-25 15:05:47 +00:00
|
|
|
"function f(o) { return new o(); }"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f);"
|
|
|
|
"f(fun); f(fun);");
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2015-04-02 09:39:32 +00:00
|
|
|
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FeedbackVector> vector(f->feedback_vector(), f->GetIsolate());
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(vector->Get(FeedbackSlot(0))->IsWeakOrCleared());
|
2015-04-02 09:39:32 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-04-02 09:39:32 +00:00
|
|
|
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(vector->Get(FeedbackSlot(0))->IsWeakOrCleared());
|
2015-04-02 09:39:32 +00:00
|
|
|
}
|
|
|
|
|
2014-01-07 14:14:34 +00:00
|
|
|
TEST(IncrementalMarkingPreservesMonomorphicIC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
|
|
|
if (FLAG_always_opt) return;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2012-08-06 10:35:48 +00:00
|
|
|
// Prepare function f that contains a monomorphic IC for object
|
2012-08-17 09:03:08 +00:00
|
|
|
// originating from the same native context.
|
2019-03-25 15:05:47 +00:00
|
|
|
CompileRun(
|
|
|
|
"function fun() { this.x = 1; }; var obj = new fun();"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f);"
|
|
|
|
"function f(o) { return o.x; } f(obj); f(obj);");
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2012-08-06 10:35:48 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
CheckVectorIC(f, 0, MONOMORPHIC);
|
2012-08-06 10:35:48 +00:00
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2012-08-06 10:35:48 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
CheckVectorIC(f, 0, MONOMORPHIC);
|
2012-08-06 10:35:48 +00:00
|
|
|
}
|
|
|
|
|
2014-12-02 14:25:17 +00:00
|
|
|
TEST(IncrementalMarkingPreservesPolymorphicIC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
|
|
|
if (FLAG_always_opt) return;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-12-02 14:25:17 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Value> obj1, obj2;
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2014-12-02 14:25:17 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
|
2015-11-09 19:48:08 +00:00
|
|
|
obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
|
2014-12-02 14:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 2; }; var obj = new fun();");
|
2015-11-09 19:48:08 +00:00
|
|
|
obj2 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
|
2014-12-02 14:25:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare function f that contains a polymorphic IC for objects
|
|
|
|
// originating from two different native contexts.
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("obj1"), obj1).FromJust());
|
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("obj2"), obj2).FromJust());
|
2019-03-25 15:05:47 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f(o) { return o.x; }; "
|
|
|
|
"%EnsureFeedbackVectorForFunction(f);"
|
|
|
|
"f(obj1); f(obj1); f(obj2);");
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2014-12-02 14:25:17 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
CheckVectorIC(f, 0, POLYMORPHIC);
|
2014-12-02 14:25:17 +00:00
|
|
|
|
|
|
|
// Fire context dispose notification.
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-12-02 14:25:17 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
CheckVectorIC(f, 0, POLYMORPHIC);
|
2014-12-02 14:25:17 +00:00
|
|
|
}
|
|
|
|
|
2016-05-27 08:09:12 +00:00
|
|
|
TEST(ContextDisposeDoesntClearPolymorphicIC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
|
|
|
if (FLAG_always_opt) return;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2015-02-19 09:56:06 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
v8::Local<v8::Value> obj1, obj2;
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = CcTest::isolate()->GetCurrentContext();
|
2015-02-19 09:56:06 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 1; }; var obj = new fun();");
|
2015-11-09 19:48:08 +00:00
|
|
|
obj1 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
|
2015-02-19 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
LocalContext env;
|
|
|
|
CompileRun("function fun() { this.x = 2; }; var obj = new fun();");
|
2015-11-09 19:48:08 +00:00
|
|
|
obj2 = env->Global()->Get(env.local(), v8_str("obj")).ToLocalChecked();
|
2015-02-19 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prepare function f that contains a polymorphic IC for objects
|
|
|
|
// originating from two different native contexts.
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("obj1"), obj1).FromJust());
|
|
|
|
CHECK(CcTest::global()->Set(ctx, v8_str("obj2"), obj2).FromJust());
|
2019-03-25 15:05:47 +00:00
|
|
|
CompileRun(
|
|
|
|
"function f(o) { return o.x; }; "
|
|
|
|
"%EnsureFeedbackVectorForFunction(f);"
|
|
|
|
"f(obj1); f(obj1); f(obj2);");
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> f = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()->Get(ctx, v8_str("f")).ToLocalChecked())));
|
2015-02-19 09:56:06 +00:00
|
|
|
|
2015-06-04 16:22:29 +00:00
|
|
|
CheckVectorIC(f, 0, POLYMORPHIC);
|
2015-02-19 09:56:06 +00:00
|
|
|
|
|
|
|
// Fire context dispose notification.
|
|
|
|
CcTest::isolate()->ContextDisposedNotification();
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-02-19 09:56:06 +00:00
|
|
|
|
2016-05-27 08:09:12 +00:00
|
|
|
CheckVectorIC(f, 0, POLYMORPHIC);
|
2015-02-19 09:56:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-09-10 12:38:12 +00:00
|
|
|
class SourceResource : public v8::String::ExternalOneByteStringResource {
|
2012-08-29 07:51:48 +00:00
|
|
|
public:
|
|
|
|
explicit SourceResource(const char* data)
|
|
|
|
: data_(data), length_(strlen(data)) { }
|
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
void Dispose() override {
|
2012-08-29 07:51:48 +00:00
|
|
|
i::DeleteArray(data_);
|
2017-10-13 16:33:03 +00:00
|
|
|
data_ = nullptr;
|
2012-08-29 07:51:48 +00:00
|
|
|
}
|
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
const char* data() const override { return data_; }
|
2012-08-29 07:51:48 +00:00
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
size_t length() const override { return length_; }
|
2012-08-29 07:51:48 +00:00
|
|
|
|
2017-10-13 16:33:03 +00:00
|
|
|
bool IsDisposed() { return data_ == nullptr; }
|
2012-08-29 07:51:48 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char* data_;
|
|
|
|
size_t length_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
void ReleaseStackTraceDataTest(v8::Isolate* isolate, const char* source,
|
|
|
|
const char* accessor) {
|
2012-08-29 07:51:48 +00:00
|
|
|
// Test that the data retained by the Error.stack accessor is released
|
|
|
|
// after the first time the accessor is fired. We use external string
|
|
|
|
// to check whether the data is being released since the external string
|
|
|
|
// resource's callback is fired when the external string is GC'ed.
|
2014-09-19 08:01:35 +00:00
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
|
|
|
v8::HandleScope scope(isolate);
|
2012-08-29 07:51:48 +00:00
|
|
|
SourceResource* resource = new SourceResource(i::StrDup(source));
|
|
|
|
{
|
2014-09-19 08:01:35 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Context> ctx = isolate->GetCurrentContext();
|
|
|
|
v8::Local<v8::String> source_string =
|
|
|
|
v8::String::NewExternalOneByte(isolate, resource).ToLocalChecked();
|
2016-09-07 10:02:58 +00:00
|
|
|
i_isolate->heap()->CollectAllAvailableGarbage(
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Script::Compile(ctx, source_string)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(ctx)
|
|
|
|
.ToLocalChecked();
|
2012-08-29 07:51:48 +00:00
|
|
|
CHECK(!resource->IsDisposed());
|
|
|
|
}
|
2014-09-19 08:01:35 +00:00
|
|
|
// i_isolate->heap()->CollectAllAvailableGarbage();
|
2013-07-24 12:16:02 +00:00
|
|
|
CHECK(!resource->IsDisposed());
|
|
|
|
|
|
|
|
CompileRun(accessor);
|
2016-09-07 10:02:58 +00:00
|
|
|
i_isolate->heap()->CollectAllAvailableGarbage(
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2012-08-29 07:51:48 +00:00
|
|
|
|
|
|
|
// External source has been released.
|
|
|
|
CHECK(resource->IsDisposed());
|
|
|
|
delete resource;
|
|
|
|
}
|
2012-09-20 10:45:38 +00:00
|
|
|
|
|
|
|
|
2014-09-19 08:01:35 +00:00
|
|
|
UNINITIALIZED_TEST(ReleaseStackTraceData) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt) {
|
2014-03-03 11:11:39 +00:00
|
|
|
// TODO(ulan): Remove this once the memory leak via code_next_link is fixed.
|
|
|
|
// See: https://codereview.chromium.org/181833004/
|
|
|
|
return;
|
|
|
|
}
|
2018-10-22 11:45:45 +00:00
|
|
|
#ifndef V8_LITE_MODE
|
|
|
|
// ICs retain objects.
|
|
|
|
FLAG_use_ic = false;
|
|
|
|
#endif // V8_LITE_MODE
|
2013-11-19 11:52:47 +00:00
|
|
|
FLAG_concurrent_recompilation = false;
|
2015-04-29 09:54:34 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
2014-09-19 08:01:35 +00:00
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Context::New(isolate)->Enter();
|
|
|
|
static const char* source1 = "var error = null; "
|
|
|
|
/* Normal Error */ "try { "
|
|
|
|
" throw new Error(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* source2 = "var error = null; "
|
|
|
|
/* Stack overflow */ "try { "
|
|
|
|
" (function f() { f(); })(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* source3 = "var error = null; "
|
|
|
|
/* Normal Error */ "try { "
|
|
|
|
/* as prototype */ " throw new Error(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = {}; "
|
|
|
|
" error.__proto__ = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* source4 = "var error = null; "
|
|
|
|
/* Stack overflow */ "try { "
|
|
|
|
/* as prototype */ " (function f() { f(); })(); "
|
|
|
|
"} catch (e) { "
|
|
|
|
" error = {}; "
|
|
|
|
" error.__proto__ = e; "
|
|
|
|
"} ";
|
|
|
|
static const char* getter = "error.stack";
|
|
|
|
static const char* setter = "error.stack = 0";
|
|
|
|
|
|
|
|
ReleaseStackTraceDataTest(isolate, source1, setter);
|
|
|
|
ReleaseStackTraceDataTest(isolate, source2, setter);
|
|
|
|
// We do not test source3 and source4 with setter, since the setter is
|
|
|
|
// supposed to (untypically) write to the receiver, not the holder. This is
|
|
|
|
// to emulate the behavior of a data property.
|
|
|
|
|
|
|
|
ReleaseStackTraceDataTest(isolate, source1, getter);
|
|
|
|
ReleaseStackTraceDataTest(isolate, source2, getter);
|
|
|
|
ReleaseStackTraceDataTest(isolate, source3, getter);
|
|
|
|
ReleaseStackTraceDataTest(isolate, source4, getter);
|
|
|
|
}
|
2014-09-19 08:25:56 +00:00
|
|
|
isolate->Dispose();
|
2012-11-12 14:54:29 +00:00
|
|
|
}
|
|
|
|
|
2019-02-08 12:43:15 +00:00
|
|
|
// TODO(mmarchini) also write tests for async/await and Promise.all
|
|
|
|
void DetailedErrorStackTraceTest(const char* src,
|
|
|
|
std::function<void(Handle<FrameArray>)> test) {
|
|
|
|
FLAG_detailed_error_stack_trace = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
|
|
|
|
v8::TryCatch try_catch(CcTest::isolate());
|
|
|
|
CompileRun(src);
|
|
|
|
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
Handle<Object> exception = v8::Utils::OpenHandle(*try_catch.Exception());
|
|
|
|
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Handle<Name> key = isolate->factory()->stack_trace_symbol();
|
|
|
|
|
2019-06-06 12:44:36 +00:00
|
|
|
Handle<FixedArray> stack_trace(Handle<FixedArray>::cast(
|
2019-04-12 07:08:53 +00:00
|
|
|
Object::GetProperty(isolate, exception, key).ToHandleChecked()));
|
2019-02-08 12:43:15 +00:00
|
|
|
|
2019-06-06 12:44:36 +00:00
|
|
|
test(GetFrameArrayFromStackTrace(isolate, stack_trace));
|
2019-02-08 12:43:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// * Test interpreted function error
|
|
|
|
TEST(DetailedErrorStackTrace) {
|
|
|
|
static const char* source =
|
|
|
|
"function func1(arg1) { "
|
|
|
|
" let err = new Error(); "
|
|
|
|
" throw err; "
|
|
|
|
"} "
|
|
|
|
"function func2(arg1, arg2) { "
|
|
|
|
" func1(42); "
|
|
|
|
"} "
|
|
|
|
"class Foo {}; "
|
|
|
|
"function main(arg1, arg2) { "
|
|
|
|
" func2(arg1, false); "
|
|
|
|
"} "
|
|
|
|
"var foo = new Foo(); "
|
|
|
|
"main(foo); ";
|
|
|
|
|
|
|
|
DetailedErrorStackTraceTest(source, [](Handle<FrameArray> stack_trace) {
|
|
|
|
FixedArray foo_parameters = stack_trace->Parameters(0);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(foo_parameters.length(), 1);
|
|
|
|
CHECK(foo_parameters.get(0).IsSmi());
|
|
|
|
CHECK_EQ(Smi::ToInt(foo_parameters.get(0)), 42);
|
2019-02-08 12:43:15 +00:00
|
|
|
|
|
|
|
FixedArray bar_parameters = stack_trace->Parameters(1);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(bar_parameters.length(), 2);
|
|
|
|
CHECK(bar_parameters.get(0).IsJSObject());
|
|
|
|
CHECK(bar_parameters.get(1).IsBoolean());
|
2019-02-08 12:43:15 +00:00
|
|
|
Handle<Object> foo = Handle<Object>::cast(GetByName("foo"));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(bar_parameters.get(0), *foo);
|
|
|
|
CHECK(!bar_parameters.get(1).BooleanValue(CcTest::i_isolate()));
|
2019-02-08 12:43:15 +00:00
|
|
|
|
|
|
|
FixedArray main_parameters = stack_trace->Parameters(2);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(main_parameters.length(), 2);
|
|
|
|
CHECK(main_parameters.get(0).IsJSObject());
|
|
|
|
CHECK(main_parameters.get(1).IsUndefined());
|
|
|
|
CHECK_EQ(main_parameters.get(0), *foo);
|
2019-02-08 12:43:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// * Test optimized function with inline frame error
|
|
|
|
TEST(DetailedErrorStackTraceInline) {
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
static const char* source =
|
2019-04-30 11:04:41 +00:00
|
|
|
"function add(x) { "
|
|
|
|
" if (x == 42) "
|
|
|
|
" throw new Error(); "
|
|
|
|
" return x + x; "
|
|
|
|
"} "
|
|
|
|
"add(0); "
|
|
|
|
"add(1); "
|
|
|
|
"function foo(x) { "
|
|
|
|
" return add(x + 1) "
|
|
|
|
"} "
|
|
|
|
"%PrepareFunctionForOptimization(foo); "
|
|
|
|
"foo(40); "
|
|
|
|
"%OptimizeFunctionOnNextCall(foo); "
|
|
|
|
"foo(41); ";
|
2019-02-08 12:43:15 +00:00
|
|
|
|
|
|
|
DetailedErrorStackTraceTest(source, [](Handle<FrameArray> stack_trace) {
|
|
|
|
FixedArray parameters_add = stack_trace->Parameters(0);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(parameters_add.length(), 1);
|
|
|
|
CHECK(parameters_add.get(0).IsSmi());
|
|
|
|
CHECK_EQ(Smi::ToInt(parameters_add.get(0)), 42);
|
2019-02-08 12:43:15 +00:00
|
|
|
|
|
|
|
FixedArray parameters_foo = stack_trace->Parameters(1);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(parameters_foo.length(), 1);
|
|
|
|
CHECK(parameters_foo.get(0).IsSmi());
|
|
|
|
CHECK_EQ(Smi::ToInt(parameters_foo.get(0)), 41);
|
2019-02-08 12:43:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// * Test builtin exit error
|
|
|
|
TEST(DetailedErrorStackTraceBuiltinExit) {
|
|
|
|
static const char* source =
|
|
|
|
"function test(arg1) { "
|
|
|
|
" (new Number()).toFixed(arg1); "
|
|
|
|
"} "
|
|
|
|
"test(9999); ";
|
|
|
|
|
|
|
|
DetailedErrorStackTraceTest(source, [](Handle<FrameArray> stack_trace) {
|
|
|
|
FixedArray parameters = stack_trace->Parameters(0);
|
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(parameters.length(), 2);
|
|
|
|
CHECK(parameters.get(0).IsSmi());
|
|
|
|
CHECK_EQ(Smi::ToInt(parameters.get(0)), 9999);
|
2019-02-08 12:43:15 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2013-01-21 12:26:29 +00:00
|
|
|
TEST(Regress169928) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2018-10-22 11:45:45 +00:00
|
|
|
#ifndef V8_LITE_MODE
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_opt = false;
|
2018-10-22 11:45:45 +00:00
|
|
|
#endif // V8_LITE_MODE
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2015-11-09 19:48:08 +00:00
|
|
|
LocalContext env;
|
2013-06-04 10:30:05 +00:00
|
|
|
Factory* factory = isolate->factory();
|
2013-04-10 08:29:39 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Some flags turn Scavenge collections into Mark-sweep collections
|
|
|
|
// and hence are incompatible with this test case.
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_gc_global || FLAG_stress_compaction ||
|
|
|
|
FLAG_stress_incremental_marking)
|
|
|
|
return;
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Prepare the environment
|
|
|
|
CompileRun("function fastliteralcase(literal, value) {"
|
|
|
|
" literal[0] = value;"
|
|
|
|
" return literal;"
|
|
|
|
"}"
|
|
|
|
"function get_standard_literal() {"
|
|
|
|
" var literal = [1, 2, 3];"
|
|
|
|
" return literal;"
|
|
|
|
"}"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 1);"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 1.5);"
|
|
|
|
"obj = fastliteralcase(get_standard_literal(), 2);");
|
|
|
|
|
|
|
|
// prepare the heap
|
|
|
|
v8::Local<v8::String> mote_code_string =
|
|
|
|
v8_str("fastliteralcase(mote, 2.5);");
|
|
|
|
|
|
|
|
v8::Local<v8::String> array_name = v8_str("mote");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK(CcTest::global()
|
|
|
|
->Set(env.local(), array_name, v8::Int32::New(CcTest::isolate(), 0))
|
|
|
|
.FromJust());
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// First make sure we flip spaces
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Allocate the object.
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> array_data =
|
|
|
|
factory->NewFixedArray(2, AllocationType::kYoung);
|
2013-01-21 12:26:29 +00:00
|
|
|
array_data->set(0, Smi::FromInt(1));
|
|
|
|
array_data->set(1, Smi::FromInt(2));
|
|
|
|
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::AllocateAllButNBytes(
|
|
|
|
CcTest::heap()->new_space(),
|
2018-12-19 19:10:21 +00:00
|
|
|
JSArray::kSize + AllocationMemento::kSize + kTaggedSize);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
2015-06-02 11:46:04 +00:00
|
|
|
Handle<JSArray> array =
|
2017-06-30 11:26:14 +00:00
|
|
|
factory->NewJSArrayWithElements(array_data, PACKED_SMI_ELEMENTS);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
CHECK_EQ(Smi::FromInt(2), array->length());
|
2017-06-30 18:00:44 +00:00
|
|
|
CHECK(array->HasSmiOrObjectElements());
|
2013-01-21 12:26:29 +00:00
|
|
|
|
2013-07-19 13:30:49 +00:00
|
|
|
// We need filler the size of AllocationMemento object, plus an extra
|
2013-01-21 12:26:29 +00:00
|
|
|
// fill pointer value.
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject obj;
|
2015-05-15 17:04:48 +00:00
|
|
|
AllocationResult allocation =
|
|
|
|
CcTest::heap()->new_space()->AllocateRawUnaligned(
|
2018-12-19 19:10:21 +00:00
|
|
|
AllocationMemento::kSize + kTaggedSize);
|
2014-04-30 12:25:18 +00:00
|
|
|
CHECK(allocation.To(&obj));
|
2019-05-23 07:47:44 +00:00
|
|
|
Address addr_obj = obj.address();
|
2016-02-25 14:36:13 +00:00
|
|
|
CcTest::heap()->CreateFillerObjectAt(addr_obj,
|
2019-08-20 12:17:23 +00:00
|
|
|
AllocationMemento::kSize + kTaggedSize);
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// Give the array a name, making sure not to allocate strings.
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Object> array_obj = v8::Utils::ToLocal(array);
|
|
|
|
CHECK(CcTest::global()->Set(env.local(), array_name, array_obj).FromJust());
|
2013-01-21 12:26:29 +00:00
|
|
|
|
|
|
|
// This should crash with a protection violation if we are running a build
|
|
|
|
// with the bug.
|
2014-03-19 11:31:43 +00:00
|
|
|
AlwaysAllocateScope aa_scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Script::Compile(env.local(), mote_code_string)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->Run(env.local())
|
|
|
|
.ToLocalChecked();
|
2013-01-21 12:26:29 +00:00
|
|
|
}
|
2013-01-23 16:15:15 +00:00
|
|
|
|
2015-08-21 11:41:46 +00:00
|
|
|
TEST(LargeObjectSlotRecording) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-06-13 09:25:18 +00:00
|
|
|
if (FLAG_never_compact) return;
|
|
|
|
ManualGCScope manual_gc_scope;
|
2015-08-21 11:41:46 +00:00
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
|
|
|
|
// Create an object on an evacuation candidate.
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> lit =
|
|
|
|
isolate->factory()->NewFixedArray(4, AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
Page* evac_page = Page::FromHeapObject(*lit);
|
2016-11-03 12:12:38 +00:00
|
|
|
heap::ForceEvacuationCandidate(evac_page);
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArray old_location = *lit;
|
2015-08-21 11:41:46 +00:00
|
|
|
|
|
|
|
// Allocate a large object.
|
2016-09-06 12:58:59 +00:00
|
|
|
int size = Max(1000000, kMaxRegularHeapObjectSize + KB);
|
2017-09-19 13:08:15 +00:00
|
|
|
CHECK_LT(kMaxRegularHeapObjectSize, size);
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> lo =
|
|
|
|
isolate->factory()->NewFixedArray(size, AllocationType::kOld);
|
2015-08-21 11:41:46 +00:00
|
|
|
CHECK(heap->lo_space()->Contains(*lo));
|
|
|
|
|
|
|
|
// Start incremental marking to active write barrier.
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
2015-08-21 11:41:46 +00:00
|
|
|
|
|
|
|
// Create references from the large object to the object on the evacuation
|
|
|
|
// candidate.
|
2015-11-12 14:33:01 +00:00
|
|
|
const int kStep = size / 10;
|
|
|
|
for (int i = 0; i < size; i += kStep) {
|
2015-08-21 11:41:46 +00:00
|
|
|
lo->set(i, *lit);
|
|
|
|
CHECK(lo->get(i) == old_location);
|
|
|
|
}
|
|
|
|
|
2019-02-07 10:58:09 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap, true);
|
|
|
|
|
2015-08-21 11:41:46 +00:00
|
|
|
// Move the evaucation candidate object.
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-08-21 11:41:46 +00:00
|
|
|
|
|
|
|
// Verify that the pointers in the large object got updated.
|
2015-11-12 14:33:01 +00:00
|
|
|
for (int i = 0; i < size; i += kStep) {
|
2015-08-21 11:41:46 +00:00
|
|
|
CHECK_EQ(lo->get(i), *lit);
|
|
|
|
CHECK(lo->get(i) != old_location);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-25 13:32:18 +00:00
|
|
|
class DummyVisitor : public RootVisitor {
|
2013-03-18 11:26:09 +00:00
|
|
|
public:
|
2018-12-06 17:53:25 +00:00
|
|
|
void VisitRootPointers(Root root, const char* description,
|
|
|
|
FullObjectSlot start, FullObjectSlot end) override {}
|
2013-03-18 11:26:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(DeferredHandles) {
|
2013-04-10 08:29:39 +00:00
|
|
|
CcTest::InitializeVM();
|
2013-09-19 09:17:13 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2013-03-18 11:26:09 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2013-09-10 06:43:23 +00:00
|
|
|
v8::HandleScope scope(reinterpret_cast<v8::Isolate*>(isolate));
|
2014-01-16 08:17:40 +00:00
|
|
|
HandleScopeData* data = isolate->handle_scope_data();
|
2018-07-04 09:10:05 +00:00
|
|
|
Handle<Object> init(ReadOnlyRoots(heap).empty_string(), isolate);
|
2013-03-18 11:26:09 +00:00
|
|
|
while (data->next < data->limit) {
|
2018-07-04 09:10:05 +00:00
|
|
|
Handle<Object> obj(ReadOnlyRoots(heap).empty_string(), isolate);
|
2013-03-18 11:26:09 +00:00
|
|
|
}
|
|
|
|
// An entire block of handles has been filled.
|
|
|
|
// Next handle would require a new block.
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(data->next == data->limit);
|
2013-03-18 11:26:09 +00:00
|
|
|
|
|
|
|
DeferredHandleScope deferred(isolate);
|
|
|
|
DummyVisitor visitor;
|
|
|
|
isolate->handle_scope_implementer()->Iterate(&visitor);
|
2014-02-07 07:06:13 +00:00
|
|
|
delete deferred.Detach();
|
2013-03-18 11:26:09 +00:00
|
|
|
}
|
2013-05-29 11:13:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(IncrementalMarkingStepMakesBigProgressWithLargeObjects) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-08-23 11:18:19 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2013-05-29 11:13:59 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("function f(n) {"
|
|
|
|
" var a = new Array(n);"
|
|
|
|
" for (var i = 0; i < n; i += 100) a[i] = i;"
|
|
|
|
"};"
|
|
|
|
"f(10 * 1024 * 1024);");
|
2013-09-19 09:46:15 +00:00
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2015-08-25 10:59:40 +00:00
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::heap()->StartIncrementalMarking(
|
|
|
|
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
|
2015-08-25 10:59:40 +00:00
|
|
|
}
|
2019-02-07 10:58:09 +00:00
|
|
|
heap::SimulateIncrementalMarking(CcTest::heap());
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(marking->IsComplete() ||
|
|
|
|
marking->IsReadyToOverApproximateWeakClosure());
|
2013-05-29 11:13:59 +00:00
|
|
|
}
|
2013-11-14 15:14:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
TEST(DisableInlineAllocation) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-11-14 15:14:37 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"function test() {"
|
|
|
|
" var x = [];"
|
|
|
|
" for (var i = 0; i < 10; i++) {"
|
|
|
|
" x[i] = [ {}, [1,2,3], [1,x,3] ];"
|
|
|
|
" }"
|
|
|
|
"}"
|
|
|
|
"function run() {"
|
|
|
|
" %PrepareFunctionForOptimization(test);"
|
|
|
|
" %OptimizeFunctionOnNextCall(test);"
|
|
|
|
" test();"
|
|
|
|
" %DeoptimizeFunction(test);"
|
|
|
|
"}");
|
2013-11-14 15:14:37 +00:00
|
|
|
|
|
|
|
// Warm-up with inline allocation enabled.
|
|
|
|
CompileRun("test(); test(); run();");
|
|
|
|
|
|
|
|
// Run test with inline allocation disabled.
|
|
|
|
CcTest::heap()->DisableInlineAllocation();
|
|
|
|
CompileRun("run()");
|
|
|
|
|
|
|
|
// Run test with inline allocation re-enabled.
|
|
|
|
CcTest::heap()->EnableInlineAllocation();
|
|
|
|
CompileRun("run()");
|
|
|
|
}
|
2013-11-19 16:57:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
static int AllocationSitesCount(Heap* heap) {
|
|
|
|
int count = 0;
|
2019-05-23 07:47:44 +00:00
|
|
|
for (Object site = heap->allocation_sites_list(); site.IsAllocationSite();) {
|
2018-12-14 20:42:15 +00:00
|
|
|
AllocationSite cur = AllocationSite::cast(site);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(cur.HasWeakNext());
|
|
|
|
site = cur.weak_next();
|
2013-11-19 16:57:49 +00:00
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2018-06-19 17:06:31 +00:00
|
|
|
static int SlimAllocationSiteCount(Heap* heap) {
|
|
|
|
int count = 0;
|
2018-12-25 00:19:47 +00:00
|
|
|
for (Object weak_list = heap->allocation_sites_list();
|
2019-05-23 07:47:44 +00:00
|
|
|
weak_list.IsAllocationSite();) {
|
2018-12-14 20:42:15 +00:00
|
|
|
AllocationSite weak_cur = AllocationSite::cast(weak_list);
|
2019-05-23 07:47:44 +00:00
|
|
|
for (Object site = weak_cur.nested_site(); site.IsAllocationSite();) {
|
2018-12-14 20:42:15 +00:00
|
|
|
AllocationSite cur = AllocationSite::cast(site);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(!cur.HasWeakNext());
|
|
|
|
site = cur.nested_site();
|
2018-06-19 17:06:31 +00:00
|
|
|
count++;
|
|
|
|
}
|
2019-05-23 07:47:44 +00:00
|
|
|
weak_list = weak_cur.weak_next();
|
2018-06-19 17:06:31 +00:00
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
2013-11-19 16:57:49 +00:00
|
|
|
|
|
|
|
TEST(EnsureAllocationSiteDependentCodesProcessed) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt || !FLAG_opt) return;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2013-11-19 16:57:49 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
GlobalHandles* global_handles = isolate->global_handles();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2013-11-20 14:20:07 +00:00
|
|
|
|
2013-11-19 16:57:49 +00:00
|
|
|
// The allocation site at the head of the list is ours.
|
|
|
|
Handle<AllocationSite> site;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
|
|
|
v8::HandleScope scope(context->GetIsolate());
|
|
|
|
|
|
|
|
int count = AllocationSitesCount(heap);
|
2019-04-30 11:04:41 +00:00
|
|
|
CompileRun(
|
|
|
|
"var bar = function() { return (new Array()); };"
|
|
|
|
"%PrepareFunctionForOptimization(bar);"
|
|
|
|
"var a = bar();"
|
|
|
|
"bar();"
|
|
|
|
"bar();");
|
2013-11-19 16:57:49 +00:00
|
|
|
|
|
|
|
// One allocation site should have been created.
|
|
|
|
int new_count = AllocationSitesCount(heap);
|
2013-11-19 17:29:43 +00:00
|
|
|
CHECK_EQ(new_count, (count + 1));
|
2013-11-19 16:57:49 +00:00
|
|
|
site = Handle<AllocationSite>::cast(
|
|
|
|
global_handles->Create(
|
|
|
|
AllocationSite::cast(heap->allocation_sites_list())));
|
|
|
|
|
|
|
|
CompileRun("%OptimizeFunctionOnNextCall(bar); bar();");
|
|
|
|
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<JSFunction> bar_handle = Handle<JSFunction>::cast(
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("bar"))
|
|
|
|
.ToLocalChecked())));
|
2016-07-11 08:39:08 +00:00
|
|
|
|
|
|
|
int dependency_group_count = 0;
|
2018-11-28 23:53:16 +00:00
|
|
|
DependentCode dependency = site->dependent_code();
|
2018-08-08 12:00:48 +00:00
|
|
|
while (dependency != ReadOnlyRoots(heap).empty_weak_fixed_array()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(dependency.group() ==
|
2016-07-11 08:39:08 +00:00
|
|
|
DependentCode::kAllocationSiteTransitionChangedGroup ||
|
2019-05-23 07:47:44 +00:00
|
|
|
dependency.group() ==
|
2016-07-11 08:39:08 +00:00
|
|
|
DependentCode::kAllocationSiteTenuringChangedGroup);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(1, dependency.count());
|
|
|
|
CHECK(dependency.object_at(0)->IsWeak());
|
2018-11-08 21:42:34 +00:00
|
|
|
Code function_bar =
|
2019-05-23 07:47:44 +00:00
|
|
|
Code::cast(dependency.object_at(0)->GetHeapObjectAssumeWeak());
|
2016-07-11 08:39:08 +00:00
|
|
|
CHECK_EQ(bar_handle->code(), function_bar);
|
2019-05-23 07:47:44 +00:00
|
|
|
dependency = dependency.next_link();
|
2016-07-11 08:39:08 +00:00
|
|
|
dependency_group_count++;
|
|
|
|
}
|
2017-08-30 15:19:11 +00:00
|
|
|
// Expect a dependent code object for transitioning and pretenuring.
|
|
|
|
CHECK_EQ(2, dependency_group_count);
|
2013-11-19 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function, even though we
|
|
|
|
// still have the allocation site alive.
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2013-11-19 16:57:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// The site still exists because of our global handle, but the code is no
|
|
|
|
// longer referred to by dependent_code().
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(site->dependent_code().object_at(0)->IsCleared());
|
2013-11-19 16:57:49 +00:00
|
|
|
}
|
2014-01-15 11:42:19 +00:00
|
|
|
|
2018-06-19 17:06:31 +00:00
|
|
|
void CheckNumberOfAllocations(Heap* heap, const char* source,
|
|
|
|
int expected_full_alloc,
|
|
|
|
int expected_slim_alloc) {
|
|
|
|
int prev_fat_alloc_count = AllocationSitesCount(heap);
|
|
|
|
int prev_slim_alloc_count = SlimAllocationSiteCount(heap);
|
|
|
|
|
|
|
|
CompileRun(source);
|
|
|
|
|
|
|
|
int fat_alloc_sites = AllocationSitesCount(heap) - prev_fat_alloc_count;
|
|
|
|
int slim_alloc_sites = SlimAllocationSiteCount(heap) - prev_slim_alloc_count;
|
|
|
|
|
|
|
|
CHECK_EQ(expected_full_alloc, fat_alloc_sites);
|
|
|
|
CHECK_EQ(expected_slim_alloc, slim_alloc_sites);
|
|
|
|
}
|
|
|
|
|
2017-07-24 12:12:34 +00:00
|
|
|
TEST(AllocationSiteCreation) {
|
2017-08-17 12:40:24 +00:00
|
|
|
FLAG_always_opt = false;
|
2017-07-24 12:12:34 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
2019-05-09 10:35:22 +00:00
|
|
|
i::FLAG_allow_natives_syntax = true;
|
2017-07-24 12:12:34 +00:00
|
|
|
|
|
|
|
// Array literals.
|
2019-05-09 10:35:22 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f1() {"
|
|
|
|
" return []; "
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f1); f1();",
|
|
|
|
1, 0);
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f2() {"
|
|
|
|
" return [1, 2];"
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f2); f2();",
|
|
|
|
1, 0);
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f3() {"
|
|
|
|
" return [[1], [2]];"
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f3); f3();",
|
2018-08-23 09:50:54 +00:00
|
|
|
1, 2);
|
2018-06-19 17:06:31 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
2018-08-23 09:50:54 +00:00
|
|
|
"function f4() { "
|
2018-06-19 17:06:31 +00:00
|
|
|
"return [0, [1, 1.1, 1.2, "
|
|
|
|
"], 1.5, [2.1, 2.2], 3];"
|
2019-05-09 10:35:22 +00:00
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f4); f4();",
|
2018-06-19 17:06:31 +00:00
|
|
|
1, 2);
|
2017-07-24 12:12:34 +00:00
|
|
|
|
2019-05-09 10:35:22 +00:00
|
|
|
// Object literals have lazy AllocationSites
|
2018-08-23 09:50:54 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
2019-05-09 10:35:22 +00:00
|
|
|
"function f5() {"
|
|
|
|
" return {};"
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f5); f5();",
|
2018-08-23 09:50:54 +00:00
|
|
|
0, 0);
|
|
|
|
|
2017-08-21 09:04:41 +00:00
|
|
|
// No AllocationSites are created for the empty object literal.
|
|
|
|
for (int i = 0; i < 5; i++) {
|
2018-06-19 17:06:31 +00:00
|
|
|
CheckNumberOfAllocations(heap, "f5(); ", 0, 0);
|
|
|
|
}
|
|
|
|
|
2019-05-09 10:35:22 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f6() {"
|
|
|
|
" return {a:1};"
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f6); f6();",
|
|
|
|
0, 0);
|
2018-06-19 17:06:31 +00:00
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap, "f6(); ", 1, 0);
|
|
|
|
|
2019-05-09 10:35:22 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f7() {"
|
|
|
|
" return {a:1, b:2};"
|
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f7); f7(); ",
|
2018-06-19 17:06:31 +00:00
|
|
|
0, 0);
|
|
|
|
CheckNumberOfAllocations(heap, "f7(); ", 1, 0);
|
|
|
|
|
2018-06-26 11:49:46 +00:00
|
|
|
// No Allocation sites are created for object subliterals
|
2018-06-19 17:06:31 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f8() {"
|
|
|
|
"return {a:{}, b:{ a:2, c:{ d:{f:{}}} } }; "
|
2019-05-09 10:35:22 +00:00
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f8); f8();",
|
2018-06-19 17:06:31 +00:00
|
|
|
0, 0);
|
2018-06-26 11:49:46 +00:00
|
|
|
CheckNumberOfAllocations(heap, "f8(); ", 1, 0);
|
2017-07-24 12:12:34 +00:00
|
|
|
|
|
|
|
// We currently eagerly create allocation sites if there are sub-arrays.
|
2018-06-26 11:49:46 +00:00
|
|
|
// Allocation sites are created only for array subliterals
|
2018-06-19 17:06:31 +00:00
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
"function f9() {"
|
|
|
|
"return {a:[1, 2, 3], b:{ a:2, c:{ d:{f:[]} } }}; "
|
2019-05-09 10:35:22 +00:00
|
|
|
"};"
|
|
|
|
"%EnsureFeedbackVectorForFunction(f9); f9(); ",
|
2018-06-26 11:49:46 +00:00
|
|
|
1, 2);
|
2018-06-19 17:06:31 +00:00
|
|
|
|
2017-07-24 12:12:34 +00:00
|
|
|
// No new AllocationSites created on the second invocation.
|
2018-06-19 17:06:31 +00:00
|
|
|
CheckNumberOfAllocations(heap, "f9(); ", 0, 0);
|
2019-05-09 10:35:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(AllocationSiteCreationForIIFE) {
|
|
|
|
// No feedback vectors and hence no allocation sites.
|
|
|
|
// TODO(mythria): Once lazy feedback allocation is enabled by default
|
|
|
|
// re-evaluate if we need any of these tests.
|
|
|
|
if (FLAG_lite_mode || FLAG_lazy_feedback_allocation) return;
|
|
|
|
FLAG_always_opt = false;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
i::FLAG_enable_one_shot_optimization = true;
|
|
|
|
|
|
|
|
// No allocation sites within IIFE/top-level
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
(function f4() {
|
|
|
|
return [ 0, [ 1, 1.1, 1.2,], 1.5, [2.1, 2.2], 3 ];
|
|
|
|
})();
|
|
|
|
)",
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
l = [ 1, 2, 3, 4];
|
|
|
|
)",
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
a = [];
|
|
|
|
)",
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
(function f4() {
|
|
|
|
return [];
|
|
|
|
})();
|
|
|
|
)",
|
|
|
|
0, 0);
|
2018-08-10 12:41:06 +00:00
|
|
|
|
|
|
|
// No allocation sites for literals in an iife/top level code even if it has
|
|
|
|
// array subliterals
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
(function f10() {
|
|
|
|
return {a: [1], b: [2]};
|
|
|
|
})();
|
|
|
|
)",
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
l = {
|
|
|
|
a: 1,
|
|
|
|
b: {
|
|
|
|
c: [5],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
)",
|
|
|
|
0, 0);
|
|
|
|
|
|
|
|
// Eagerly create allocation sites for literals within a loop of iife or
|
|
|
|
// top-level code
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
(function f11() {
|
|
|
|
while(true) {
|
|
|
|
return {a: [1], b: [2]};
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
)",
|
|
|
|
1, 2);
|
|
|
|
|
|
|
|
CheckNumberOfAllocations(heap,
|
|
|
|
R"(
|
|
|
|
for (i = 0; i < 1; ++i) {
|
|
|
|
l = {
|
|
|
|
a: 1,
|
|
|
|
b: {
|
|
|
|
c: [5],
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)",
|
|
|
|
1, 1);
|
2017-07-24 12:12:34 +00:00
|
|
|
}
|
2014-01-15 11:42:19 +00:00
|
|
|
|
|
|
|
TEST(CellsInOptimizedCodeAreWeak) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt || !FLAG_opt) return;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-01-15 11:42:19 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2014-01-15 11:42:19 +00:00
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Handle<Code> code;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
|
|
|
HandleScope scope(heap->isolate());
|
|
|
|
|
2016-01-04 07:11:45 +00:00
|
|
|
CompileRun(
|
|
|
|
"bar = (function() {"
|
|
|
|
" function bar() {"
|
|
|
|
" return foo(1);"
|
|
|
|
" };"
|
2019-04-30 11:04:41 +00:00
|
|
|
" %PrepareFunctionForOptimization(bar);"
|
2016-01-04 07:11:45 +00:00
|
|
|
" var foo = function(x) { with (x) { return 1 + x; } };"
|
|
|
|
" %NeverOptimizeFunction(foo);"
|
|
|
|
" bar(foo);"
|
|
|
|
" bar(foo);"
|
|
|
|
" bar(foo);"
|
|
|
|
" %OptimizeFunctionOnNextCall(bar);"
|
|
|
|
" bar(foo);"
|
|
|
|
" return bar;})();");
|
2014-01-15 11:42:19 +00:00
|
|
|
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<JSFunction> bar = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
2015-11-09 19:48:08 +00:00
|
|
|
*v8::Local<v8::Function>::Cast(CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("bar"))
|
|
|
|
.ToLocalChecked())));
|
2018-06-23 09:05:50 +00:00
|
|
|
code = scope.CloseAndEscape(Handle<Code>(bar->code(), isolate));
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(code->marked_for_deoptimization());
|
2018-11-14 16:40:09 +00:00
|
|
|
CHECK(code->embedded_objects_cleared());
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ObjectsInOptimizedCodeAreWeak) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt || !FLAG_opt) return;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-01-15 11:42:19 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2014-01-15 11:42:19 +00:00
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Handle<Code> code;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
|
|
|
HandleScope scope(heap->isolate());
|
|
|
|
|
2016-01-04 07:11:45 +00:00
|
|
|
CompileRun(
|
|
|
|
"function bar() {"
|
|
|
|
" return foo(1);"
|
|
|
|
"};"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(bar);"
|
2016-01-04 07:11:45 +00:00
|
|
|
"function foo(x) { with (x) { return 1 + x; } };"
|
|
|
|
"%NeverOptimizeFunction(foo);"
|
|
|
|
"bar();"
|
|
|
|
"bar();"
|
|
|
|
"bar();"
|
|
|
|
"%OptimizeFunctionOnNextCall(bar);"
|
|
|
|
"bar();");
|
2014-01-15 11:42:19 +00:00
|
|
|
|
2015-10-23 12:26:49 +00:00
|
|
|
Handle<JSFunction> bar = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
2015-11-09 19:48:08 +00:00
|
|
|
*v8::Local<v8::Function>::Cast(CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("bar"))
|
|
|
|
.ToLocalChecked())));
|
2018-06-23 09:05:50 +00:00
|
|
|
code = scope.CloseAndEscape(Handle<Code>(bar->code(), isolate));
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(code->marked_for_deoptimization());
|
2018-11-14 16:40:09 +00:00
|
|
|
CHECK(code->embedded_objects_cleared());
|
2014-01-15 11:42:19 +00:00
|
|
|
}
|
2014-03-11 11:36:55 +00:00
|
|
|
|
2016-06-28 12:34:24 +00:00
|
|
|
TEST(NewSpaceObjectsInOptimizedCode) {
|
2017-08-10 07:54:33 +00:00
|
|
|
if (FLAG_always_opt || !FLAG_opt) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2016-06-28 12:34:24 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2018-07-10 08:07:58 +00:00
|
|
|
HandleScope outer_scope(isolate);
|
2016-06-28 12:34:24 +00:00
|
|
|
Handle<Code> code;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
2018-07-10 08:07:58 +00:00
|
|
|
HandleScope scope(isolate);
|
2016-06-28 12:34:24 +00:00
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"var foo;"
|
|
|
|
"var bar;"
|
|
|
|
"(function() {"
|
|
|
|
" function foo_func(x) { with (x) { return 1 + x; } };"
|
|
|
|
" %NeverOptimizeFunction(foo_func);"
|
|
|
|
" function bar_func() {"
|
|
|
|
" return foo(1);"
|
|
|
|
" };"
|
2019-04-30 11:04:41 +00:00
|
|
|
" %PrepareFunctionForOptimization(bar_func);"
|
2016-06-28 12:34:24 +00:00
|
|
|
" bar = bar_func;"
|
|
|
|
" foo = foo_func;"
|
|
|
|
" bar_func();"
|
|
|
|
" bar_func();"
|
|
|
|
" bar_func();"
|
|
|
|
" %OptimizeFunctionOnNextCall(bar_func);"
|
|
|
|
" bar_func();"
|
|
|
|
"})();");
|
|
|
|
|
|
|
|
Handle<JSFunction> bar = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("bar"))
|
|
|
|
.ToLocalChecked())));
|
|
|
|
|
|
|
|
Handle<JSFunction> foo = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("foo"))
|
|
|
|
.ToLocalChecked())));
|
|
|
|
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*foo));
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(!Heap::InYoungGeneration(*foo));
|
2016-06-28 12:34:24 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
2018-07-10 08:07:58 +00:00
|
|
|
CcTest::heap()->Verify();
|
2016-06-28 12:34:24 +00:00
|
|
|
#endif
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(!bar->code().marked_for_deoptimization());
|
2018-06-23 09:05:50 +00:00
|
|
|
code = scope.CloseAndEscape(Handle<Code>(bar->code(), isolate));
|
2016-06-28 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-06-28 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(code->marked_for_deoptimization());
|
2018-11-14 16:40:09 +00:00
|
|
|
CHECK(code->embedded_objects_cleared());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ObjectsInEagerlyDeoptimizedCodeAreWeak) {
|
|
|
|
if (FLAG_always_opt || !FLAG_opt) return;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
|
|
|
if (!isolate->use_optimizer()) return;
|
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Handle<Code> code;
|
|
|
|
{
|
|
|
|
LocalContext context;
|
|
|
|
HandleScope scope(heap->isolate());
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function bar() {"
|
|
|
|
" return foo(1);"
|
|
|
|
"};"
|
|
|
|
"function foo(x) { with (x) { return 1 + x; } };"
|
|
|
|
"%NeverOptimizeFunction(foo);"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(bar);"
|
2018-11-14 16:40:09 +00:00
|
|
|
"bar();"
|
|
|
|
"bar();"
|
|
|
|
"bar();"
|
|
|
|
"%OptimizeFunctionOnNextCall(bar);"
|
|
|
|
"bar();"
|
|
|
|
"%DeoptimizeFunction(bar);");
|
|
|
|
|
|
|
|
Handle<JSFunction> bar = Handle<JSFunction>::cast(v8::Utils::OpenHandle(
|
|
|
|
*v8::Local<v8::Function>::Cast(CcTest::global()
|
|
|
|
->Get(context.local(), v8_str("bar"))
|
|
|
|
.ToLocalChecked())));
|
|
|
|
code = scope.CloseAndEscape(Handle<Code>(bar->code(), isolate));
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(code->marked_for_deoptimization());
|
|
|
|
|
|
|
|
// Now make sure that a gc should get rid of the function
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(code->marked_for_deoptimization());
|
|
|
|
CHECK(code->embedded_objects_cleared());
|
2016-06-28 12:34:24 +00:00
|
|
|
}
|
2014-03-11 11:36:55 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
static Handle<JSFunction> OptimizeDummyFunction(v8::Isolate* isolate,
|
|
|
|
const char* name) {
|
2014-03-26 15:14:51 +00:00
|
|
|
EmbeddedVector<char, 256> source;
|
2014-06-13 16:43:27 +00:00
|
|
|
SNPrintF(source,
|
2019-04-30 11:04:41 +00:00
|
|
|
"function %s() { return 0; }"
|
|
|
|
"%%PrepareFunctionForOptimization(%s);"
|
|
|
|
"%s(); %s();"
|
|
|
|
"%%OptimizeFunctionOnNextCall(%s);"
|
|
|
|
"%s();",
|
|
|
|
name, name, name, name, name, name);
|
2019-04-29 11:06:49 +00:00
|
|
|
CompileRun(source.begin());
|
2015-11-09 19:48:08 +00:00
|
|
|
i::Handle<JSFunction> fun = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()
|
|
|
|
->Get(isolate->GetCurrentContext(), v8_str(name))
|
|
|
|
.ToLocalChecked())));
|
2014-03-26 15:14:51 +00:00
|
|
|
return fun;
|
|
|
|
}
|
|
|
|
|
2018-11-08 21:42:34 +00:00
|
|
|
static int GetCodeChainLength(Code code) {
|
2014-03-26 15:14:51 +00:00
|
|
|
int result = 0;
|
2019-05-23 07:47:44 +00:00
|
|
|
while (code.next_code_link().IsCode()) {
|
2014-03-26 15:14:51 +00:00
|
|
|
result++;
|
2019-05-23 07:47:44 +00:00
|
|
|
code = Code::cast(code.next_code_link());
|
2014-03-26 15:14:51 +00:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NextCodeLinkIsWeak) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_always_opt = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-03-26 15:14:51 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2014-03-26 15:14:51 +00:00
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Handle<Code> code;
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-03-26 15:14:51 +00:00
|
|
|
int code_chain_length_before, code_chain_length_after;
|
|
|
|
{
|
|
|
|
HandleScope scope(heap->isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
Handle<JSFunction> mortal =
|
|
|
|
OptimizeDummyFunction(CcTest::isolate(), "mortal");
|
|
|
|
Handle<JSFunction> immortal =
|
|
|
|
OptimizeDummyFunction(CcTest::isolate(), "immortal");
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(immortal->code().next_code_link(), mortal->code());
|
2014-03-26 15:14:51 +00:00
|
|
|
code_chain_length_before = GetCodeChainLength(immortal->code());
|
|
|
|
// Keep the immortal code and let the mortal code die.
|
2018-06-23 09:05:50 +00:00
|
|
|
code = scope.CloseAndEscape(Handle<Code>(immortal->code(), isolate));
|
2014-03-26 15:14:51 +00:00
|
|
|
CompileRun("mortal = null; immortal = null;");
|
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-03-26 15:14:51 +00:00
|
|
|
// Now mortal code should be dead.
|
|
|
|
code_chain_length_after = GetCodeChainLength(*code);
|
|
|
|
CHECK_EQ(code_chain_length_before - 1, code_chain_length_after);
|
|
|
|
}
|
|
|
|
|
2017-11-02 17:52:31 +00:00
|
|
|
TEST(NextCodeLinkInCodeDataContainerIsCleared) {
|
|
|
|
FLAG_always_opt = false;
|
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
|
|
|
if (!isolate->use_optimizer()) return;
|
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Handle<CodeDataContainer> code_data_container;
|
|
|
|
{
|
|
|
|
HandleScope scope(heap->isolate());
|
|
|
|
Handle<JSFunction> mortal1 =
|
|
|
|
OptimizeDummyFunction(CcTest::isolate(), "mortal1");
|
|
|
|
Handle<JSFunction> mortal2 =
|
|
|
|
OptimizeDummyFunction(CcTest::isolate(), "mortal2");
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(mortal2->code().next_code_link(), mortal1->code());
|
2018-06-23 09:05:50 +00:00
|
|
|
code_data_container = scope.CloseAndEscape(Handle<CodeDataContainer>(
|
2019-05-23 07:47:44 +00:00
|
|
|
mortal2->code().code_data_container(), isolate));
|
2017-11-02 17:52:31 +00:00
|
|
|
CompileRun("mortal1 = null; mortal2 = null;");
|
|
|
|
}
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(code_data_container->next_code_link().IsUndefined(isolate));
|
2017-11-02 17:52:31 +00:00
|
|
|
}
|
2014-03-26 15:14:51 +00:00
|
|
|
|
|
|
|
static Handle<Code> DummyOptimizedCode(Isolate* isolate) {
|
|
|
|
i::byte buffer[i::Assembler::kMinimalBufferSize];
|
2019-01-16 18:29:52 +00:00
|
|
|
MacroAssembler masm(isolate, v8::internal::CodeObjectRequired::kYes,
|
|
|
|
ExternalAssemblerBuffer(buffer, sizeof(buffer)));
|
2014-03-26 15:14:51 +00:00
|
|
|
CodeDesc desc;
|
2014-05-12 13:47:01 +00:00
|
|
|
masm.Push(isolate->factory()->undefined_value());
|
2018-01-11 14:06:17 +00:00
|
|
|
masm.Push(isolate->factory()->undefined_value());
|
|
|
|
masm.Drop(2);
|
2017-05-31 14:00:11 +00:00
|
|
|
masm.GetCode(isolate, &desc);
|
2019-04-29 16:15:47 +00:00
|
|
|
Handle<Code> code =
|
|
|
|
Factory::CodeBuilder(isolate, desc, Code::OPTIMIZED_FUNCTION)
|
|
|
|
.set_self_reference(masm.CodeObject())
|
|
|
|
.Build();
|
2014-03-26 15:14:51 +00:00
|
|
|
CHECK(code->IsCode());
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NextCodeLinkIsWeak2) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-03-26 15:14:51 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::internal::Heap* heap = CcTest::heap();
|
|
|
|
|
2017-04-28 15:36:46 +00:00
|
|
|
if (!isolate->use_optimizer()) return;
|
2014-03-26 15:14:51 +00:00
|
|
|
HandleScope outer_scope(heap->isolate());
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-03-26 15:14:51 +00:00
|
|
|
Handle<Context> context(Context::cast(heap->native_contexts_list()), isolate);
|
|
|
|
Handle<Code> new_head;
|
|
|
|
Handle<Object> old_head(context->get(Context::OPTIMIZED_CODE_LIST), isolate);
|
|
|
|
{
|
|
|
|
HandleScope scope(heap->isolate());
|
|
|
|
Handle<Code> immortal = DummyOptimizedCode(isolate);
|
|
|
|
Handle<Code> mortal = DummyOptimizedCode(isolate);
|
|
|
|
mortal->set_next_code_link(*old_head);
|
|
|
|
immortal->set_next_code_link(*mortal);
|
|
|
|
context->set(Context::OPTIMIZED_CODE_LIST, *immortal);
|
|
|
|
new_head = scope.CloseAndEscape(immortal);
|
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2014-03-26 15:14:51 +00:00
|
|
|
// Now mortal code should be dead.
|
|
|
|
CHECK_EQ(*old_head, new_head->next_code_link());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
static bool weak_ic_cleared = false;
|
|
|
|
|
2015-04-24 12:35:14 +00:00
|
|
|
static void ClearWeakIC(
|
|
|
|
const v8::WeakCallbackInfo<v8::Persistent<v8::Object>>& data) {
|
2014-04-11 10:36:09 +00:00
|
|
|
printf("clear weak is called\n");
|
|
|
|
weak_ic_cleared = true;
|
2015-04-24 12:35:14 +00:00
|
|
|
data.GetParameter()->Reset();
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-02 09:39:32 +00:00
|
|
|
TEST(WeakFunctionInConstructor) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (FLAG_always_opt) return;
|
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
2019-05-08 15:54:26 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2015-04-02 09:39:32 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2015-11-09 19:48:08 +00:00
|
|
|
LocalContext env;
|
2015-04-02 09:39:32 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
CompileRun(
|
|
|
|
"function createObj(obj) {"
|
|
|
|
" return new obj();"
|
|
|
|
"}");
|
2015-11-09 19:48:08 +00:00
|
|
|
i::Handle<JSFunction> createObj = Handle<JSFunction>::cast(
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Function>::Cast(
|
|
|
|
CcTest::global()
|
|
|
|
->Get(env.local(), v8_str("createObj"))
|
|
|
|
.ToLocalChecked())));
|
2015-04-02 09:39:32 +00:00
|
|
|
|
|
|
|
v8::Persistent<v8::Object> garbage;
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
const char* source =
|
|
|
|
" (function() {"
|
|
|
|
" function hat() { this.x = 5; }"
|
2019-05-08 15:54:26 +00:00
|
|
|
" %EnsureFeedbackVectorForFunction(hat);"
|
|
|
|
" %EnsureFeedbackVectorForFunction(createObj);"
|
2015-04-02 09:39:32 +00:00
|
|
|
" createObj(hat);"
|
|
|
|
" createObj(hat);"
|
|
|
|
" return hat;"
|
|
|
|
" })();";
|
2015-11-09 19:48:08 +00:00
|
|
|
garbage.Reset(isolate, CompileRun(env.local(), source)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->ToObject(env.local())
|
|
|
|
.ToLocalChecked());
|
2015-04-02 09:39:32 +00:00
|
|
|
}
|
|
|
|
weak_ic_cleared = false;
|
2015-04-24 12:35:14 +00:00
|
|
|
garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter);
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-04-02 09:39:32 +00:00
|
|
|
CHECK(weak_ic_cleared);
|
|
|
|
|
|
|
|
// We've determined the constructor in createObj has had it's weak cell
|
|
|
|
// cleared. Now, verify that one additional call with a new function
|
|
|
|
// allows monomorphicity.
|
2017-02-07 14:05:02 +00:00
|
|
|
Handle<FeedbackVector> feedback_vector =
|
|
|
|
Handle<FeedbackVector>(createObj->feedback_vector(), CcTest::i_isolate());
|
2015-04-02 09:39:32 +00:00
|
|
|
for (int i = 0; i < 20; i++) {
|
2018-10-26 00:23:24 +00:00
|
|
|
MaybeObject slot_value = feedback_vector->Get(FeedbackSlot(0));
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(slot_value->IsWeakOrCleared());
|
|
|
|
if (slot_value->IsCleared()) break;
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-04-02 09:39:32 +00:00
|
|
|
}
|
|
|
|
|
2018-10-26 00:23:24 +00:00
|
|
|
MaybeObject slot_value = feedback_vector->Get(FeedbackSlot(0));
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(slot_value->IsCleared());
|
2015-04-02 09:39:32 +00:00
|
|
|
CompileRun(
|
|
|
|
"function coat() { this.x = 6; }"
|
|
|
|
"createObj(coat);");
|
2018-05-23 06:53:49 +00:00
|
|
|
slot_value = feedback_vector->Get(FeedbackSlot(0));
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(slot_value->IsWeak());
|
2015-04-02 09:39:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
// Checks that the value returned by execution of the source is weak.
|
|
|
|
void CheckWeakness(const char* source) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_compaction = false;
|
|
|
|
FLAG_stress_incremental_marking = false;
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-04-11 10:36:09 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
2015-11-09 19:48:08 +00:00
|
|
|
LocalContext env;
|
2014-04-11 10:36:09 +00:00
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
v8::Persistent<v8::Object> garbage;
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
garbage.Reset(isolate, CompileRun(env.local(), source)
|
|
|
|
.ToLocalChecked()
|
|
|
|
->ToObject(env.local())
|
|
|
|
.ToLocalChecked());
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
weak_ic_cleared = false;
|
2015-04-24 12:35:14 +00:00
|
|
|
garbage.SetWeak(&garbage, &ClearWeakIC, v8::WeakCallbackType::kParameter);
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-04-11 10:36:09 +00:00
|
|
|
CHECK(weak_ic_cleared);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Each of the following "weak IC" tests creates an IC that embeds a map with
|
|
|
|
// the prototype pointing to _proto_ and checks that the _proto_ dies on GC.
|
|
|
|
TEST(WeakMapInMonomorphicLoadIC) {
|
2019-03-25 15:05:47 +00:00
|
|
|
CheckWeakness(
|
|
|
|
"function loadIC(obj) {"
|
|
|
|
" return obj.name;"
|
|
|
|
"}"
|
|
|
|
"%EnsureFeedbackVectorForFunction(loadIC);"
|
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-02 14:25:17 +00:00
|
|
|
TEST(WeakMapInPolymorphicLoadIC) {
|
|
|
|
CheckWeakness(
|
|
|
|
"function loadIC(obj) {"
|
|
|
|
" return obj.name;"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(loadIC);"
|
2014-12-02 14:25:17 +00:00
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" var poly = Object.create(proto);"
|
|
|
|
" poly.x = true;"
|
|
|
|
" loadIC(poly);"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
TEST(WeakMapInMonomorphicKeyedLoadIC) {
|
2019-03-25 15:05:47 +00:00
|
|
|
CheckWeakness(
|
|
|
|
"function keyedLoadIC(obj, field) {"
|
|
|
|
" return obj[field];"
|
|
|
|
"}"
|
|
|
|
"%EnsureFeedbackVectorForFunction(keyedLoadIC);"
|
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-02 14:25:17 +00:00
|
|
|
TEST(WeakMapInPolymorphicKeyedLoadIC) {
|
|
|
|
CheckWeakness(
|
|
|
|
"function keyedLoadIC(obj, field) {"
|
|
|
|
" return obj[field];"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(keyedLoadIC);"
|
2014-12-02 14:25:17 +00:00
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" keyedLoadIC(obj, 'name');"
|
|
|
|
" var poly = Object.create(proto);"
|
|
|
|
" poly.x = true;"
|
|
|
|
" keyedLoadIC(poly, 'name');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
TEST(WeakMapInMonomorphicStoreIC) {
|
2019-03-25 15:05:47 +00:00
|
|
|
CheckWeakness(
|
|
|
|
"function storeIC(obj, value) {"
|
|
|
|
" obj.name = value;"
|
|
|
|
"}"
|
|
|
|
"%EnsureFeedbackVectorForFunction(storeIC);"
|
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-02 14:25:17 +00:00
|
|
|
TEST(WeakMapInPolymorphicStoreIC) {
|
|
|
|
CheckWeakness(
|
|
|
|
"function storeIC(obj, value) {"
|
|
|
|
" obj.name = value;"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(storeIC);"
|
2014-12-02 14:25:17 +00:00
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" storeIC(obj, 'x');"
|
|
|
|
" var poly = Object.create(proto);"
|
|
|
|
" poly.x = true;"
|
|
|
|
" storeIC(poly, 'x');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
TEST(WeakMapInMonomorphicKeyedStoreIC) {
|
2019-03-25 15:05:47 +00:00
|
|
|
CheckWeakness(
|
|
|
|
"function keyedStoreIC(obj, field, value) {"
|
|
|
|
" obj[field] = value;"
|
|
|
|
"}"
|
|
|
|
"%EnsureFeedbackVectorForFunction(keyedStoreIC);"
|
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-02 14:25:17 +00:00
|
|
|
TEST(WeakMapInPolymorphicKeyedStoreIC) {
|
|
|
|
CheckWeakness(
|
|
|
|
"function keyedStoreIC(obj, field, value) {"
|
|
|
|
" obj[field] = value;"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(keyedStoreIC);"
|
2014-12-02 14:25:17 +00:00
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" keyedStoreIC(obj, 'x');"
|
|
|
|
" var poly = Object.create(proto);"
|
|
|
|
" poly.x = true;"
|
|
|
|
" keyedStoreIC(poly, 'x');"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-11 10:36:09 +00:00
|
|
|
TEST(WeakMapInMonomorphicCompareNilIC) {
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
CheckWeakness(
|
|
|
|
"function compareNilIC(obj) {"
|
|
|
|
" return obj == null;"
|
|
|
|
"}"
|
|
|
|
"%EnsureFeedbackVectorForFunction(compareNilIC);"
|
|
|
|
" (function() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" compareNilIC(obj);"
|
|
|
|
" compareNilIC(obj);"
|
|
|
|
" compareNilIC(obj);"
|
|
|
|
" return proto;"
|
|
|
|
" })();");
|
2014-04-11 10:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-18 13:09:37 +00:00
|
|
|
Handle<JSFunction> GetFunctionByName(Isolate* isolate, const char* name) {
|
|
|
|
Handle<String> str = isolate->factory()->InternalizeUtf8String(name);
|
|
|
|
Handle<Object> obj =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, isolate->global_object(), str)
|
|
|
|
.ToHandleChecked();
|
2014-12-18 13:09:37 +00:00
|
|
|
return Handle<JSFunction>::cast(obj);
|
|
|
|
}
|
|
|
|
|
2017-09-28 15:03:01 +00:00
|
|
|
void CheckIC(Handle<JSFunction> function, int slot_index,
|
2016-05-27 08:09:12 +00:00
|
|
|
InlineCacheState state) {
|
2018-11-30 19:58:04 +00:00
|
|
|
FeedbackVector vector = function->feedback_vector();
|
2017-08-22 14:24:16 +00:00
|
|
|
FeedbackSlot slot(slot_index);
|
2018-01-31 13:51:30 +00:00
|
|
|
FeedbackNexus nexus(vector, slot);
|
2019-02-13 12:24:26 +00:00
|
|
|
CHECK_EQ(nexus.ic_state(), state);
|
2014-12-18 13:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(MonomorphicStaysMonomorphicAfterGC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2014-12-18 13:09:37 +00:00
|
|
|
if (FLAG_always_opt) return;
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2014-12-18 13:09:37 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-12-18 13:09:37 +00:00
|
|
|
CompileRun(
|
|
|
|
"function loadIC(obj) {"
|
|
|
|
" return obj.name;"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(loadIC);"
|
2014-12-18 13:09:37 +00:00
|
|
|
"function testIC() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" return proto;"
|
|
|
|
"};");
|
|
|
|
Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC");
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("(testIC())");
|
|
|
|
}
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2017-09-28 15:03:01 +00:00
|
|
|
CheckIC(loadIC, 0, MONOMORPHIC);
|
2014-12-18 13:09:37 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("(testIC())");
|
|
|
|
}
|
2017-09-28 15:03:01 +00:00
|
|
|
CheckIC(loadIC, 0, MONOMORPHIC);
|
2014-12-18 13:09:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(PolymorphicStaysPolymorphicAfterGC) {
|
2018-10-19 22:19:25 +00:00
|
|
|
if (!FLAG_use_ic) return;
|
2014-12-18 13:09:37 +00:00
|
|
|
if (FLAG_always_opt) return;
|
2017-06-12 11:03:01 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2014-12-18 13:09:37 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-03-25 15:05:47 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-12-18 13:09:37 +00:00
|
|
|
CompileRun(
|
|
|
|
"function loadIC(obj) {"
|
|
|
|
" return obj.name;"
|
|
|
|
"}"
|
2019-03-25 15:05:47 +00:00
|
|
|
"%EnsureFeedbackVectorForFunction(loadIC);"
|
2014-12-18 13:09:37 +00:00
|
|
|
"function testIC() {"
|
|
|
|
" var proto = {'name' : 'weak'};"
|
|
|
|
" var obj = Object.create(proto);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" loadIC(obj);"
|
|
|
|
" var poly = Object.create(proto);"
|
|
|
|
" poly.x = true;"
|
|
|
|
" loadIC(poly);"
|
|
|
|
" return proto;"
|
|
|
|
"};");
|
|
|
|
Handle<JSFunction> loadIC = GetFunctionByName(isolate, "loadIC");
|
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("(testIC())");
|
|
|
|
}
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2017-09-28 15:03:01 +00:00
|
|
|
CheckIC(loadIC, 0, POLYMORPHIC);
|
2014-12-18 13:09:37 +00:00
|
|
|
{
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CompileRun("(testIC())");
|
|
|
|
}
|
2017-09-28 15:03:01 +00:00
|
|
|
CheckIC(loadIC, 0, POLYMORPHIC);
|
2014-12-18 13:09:37 +00:00
|
|
|
}
|
|
|
|
|
2014-03-11 11:53:40 +00:00
|
|
|
#ifdef DEBUG
|
2014-03-11 11:36:55 +00:00
|
|
|
TEST(AddInstructionChangesNewSpacePromotion) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
|
|
|
FLAG_expose_gc = true;
|
|
|
|
FLAG_stress_compaction = true;
|
|
|
|
FLAG_gc_interval = 1000;
|
2014-03-11 11:36:55 +00:00
|
|
|
CcTest::InitializeVM();
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_allocation_site_pretenuring) return;
|
2014-03-11 11:36:55 +00:00
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
2015-11-09 19:48:08 +00:00
|
|
|
LocalContext env;
|
2014-03-11 11:36:55 +00:00
|
|
|
CompileRun(
|
|
|
|
"function add(a, b) {"
|
|
|
|
" return a + b;"
|
|
|
|
"}"
|
|
|
|
"add(1, 2);"
|
|
|
|
"add(\"a\", \"b\");"
|
|
|
|
"var oldSpaceObject;"
|
|
|
|
"gc();"
|
|
|
|
"function crash(x) {"
|
|
|
|
" var object = {a: null, b: null};"
|
|
|
|
" var result = add(1.5, x | 0);"
|
|
|
|
" object.a = result;"
|
|
|
|
" oldSpaceObject = object;"
|
|
|
|
" return object;"
|
|
|
|
"}"
|
2019-04-30 11:04:41 +00:00
|
|
|
"%PrepareFunctionForOptimization(crash);"
|
2014-03-11 11:36:55 +00:00
|
|
|
"crash(1);"
|
|
|
|
"crash(1);"
|
|
|
|
"%OptimizeFunctionOnNextCall(crash);"
|
|
|
|
"crash(1);");
|
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Object> global = CcTest::global();
|
|
|
|
v8::Local<v8::Function> g = v8::Local<v8::Function>::Cast(
|
|
|
|
global->Get(env.local(), v8_str("crash")).ToLocalChecked());
|
|
|
|
v8::Local<v8::Value> args1[] = {v8_num(1)};
|
2014-03-11 11:36:55 +00:00
|
|
|
heap->DisableInlineAllocation();
|
|
|
|
heap->set_allocation_timeout(1);
|
2015-11-09 19:48:08 +00:00
|
|
|
g->Call(env.local(), global, 1, args1).ToLocalChecked();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2014-03-11 11:36:55 +00:00
|
|
|
}
|
2014-03-27 10:41:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
void OnFatalErrorExpectOOM(const char* location, const char* message) {
|
|
|
|
// Exit with 0 if the location matches our expectation.
|
|
|
|
exit(strcmp(location, "CALL_AND_RETRY_LAST"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CEntryStubOOM) {
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_allow_natives_syntax = true;
|
2014-03-27 10:41:45 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-11-09 19:48:08 +00:00
|
|
|
CcTest::isolate()->SetFatalErrorHandler(OnFatalErrorExpectOOM);
|
2014-03-27 10:41:45 +00:00
|
|
|
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::Value> result = CompileRun(
|
2018-08-23 14:13:19 +00:00
|
|
|
"%SetAllocationTimeout(1, 1);"
|
2014-03-27 10:41:45 +00:00
|
|
|
"var a = [];"
|
|
|
|
"a.__proto__ = [];"
|
|
|
|
"a.unshift(1)");
|
|
|
|
|
|
|
|
CHECK(result->IsNumber());
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // DEBUG
|
2014-03-31 14:14:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
static void InterruptCallback357137(v8::Isolate* isolate, void* data) { }
|
|
|
|
|
|
|
|
|
|
|
|
static void RequestInterrupt(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
2017-10-13 16:33:03 +00:00
|
|
|
CcTest::isolate()->RequestInterrupt(&InterruptCallback357137, nullptr);
|
2014-03-31 14:14:54 +00:00
|
|
|
}
|
|
|
|
|
2016-09-28 17:51:48 +00:00
|
|
|
HEAP_TEST(Regress538257) {
|
2017-11-20 12:13:24 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
2015-10-02 11:49:55 +00:00
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
// Set heap limits.
|
2019-06-05 21:08:15 +00:00
|
|
|
create_params.constraints.set_max_young_generation_size_in_bytes(3 * MB);
|
2017-10-20 15:18:53 +00:00
|
|
|
#ifdef DEBUG
|
2019-06-05 21:08:15 +00:00
|
|
|
create_params.constraints.set_max_old_generation_size_in_bytes(20 * MB);
|
2017-10-20 15:18:53 +00:00
|
|
|
#else
|
2019-06-05 21:08:15 +00:00
|
|
|
create_params.constraints.set_max_old_generation_size_in_bytes(6 * MB);
|
2017-10-20 15:18:53 +00:00
|
|
|
#endif
|
2015-10-02 11:49:55 +00:00
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
isolate->Enter();
|
|
|
|
{
|
|
|
|
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
|
2016-04-06 11:52:22 +00:00
|
|
|
Heap* heap = i_isolate->heap();
|
2015-10-02 11:49:55 +00:00
|
|
|
HandleScope handle_scope(i_isolate);
|
2016-04-06 11:52:22 +00:00
|
|
|
PagedSpace* old_space = heap->old_space();
|
2015-10-02 11:49:55 +00:00
|
|
|
const int kMaxObjects = 10000;
|
|
|
|
const int kFixedArrayLen = 512;
|
|
|
|
Handle<FixedArray> objects[kMaxObjects];
|
2016-04-06 11:52:22 +00:00
|
|
|
for (int i = 0; (i < kMaxObjects) &&
|
|
|
|
heap->CanExpandOldGeneration(old_space->AreaSize());
|
2015-10-02 11:49:55 +00:00
|
|
|
i++) {
|
2019-03-11 19:04:02 +00:00
|
|
|
objects[i] = i_isolate->factory()->NewFixedArray(kFixedArrayLen,
|
|
|
|
AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
heap::ForceEvacuationCandidate(Page::FromHeapObject(*objects[i]));
|
2015-10-02 11:49:55 +00:00
|
|
|
}
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(old_space);
|
2018-09-19 08:19:40 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-10-02 11:49:55 +00:00
|
|
|
// If we get this far, we've successfully aborted compaction. Any further
|
|
|
|
// allocations might trigger OOM.
|
|
|
|
}
|
|
|
|
isolate->Exit();
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-03-31 14:14:54 +00:00
|
|
|
TEST(Regress357137) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope hscope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
|
|
|
global->Set(
|
|
|
|
v8::String::NewFromUtf8(isolate, "interrupt", v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked(),
|
|
|
|
v8::FunctionTemplate::New(isolate, RequestInterrupt));
|
2017-10-13 16:33:03 +00:00
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(!context.IsEmpty());
|
2014-03-31 14:14:54 +00:00
|
|
|
v8::Context::Scope cscope(context);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> result = CompileRun(
|
|
|
|
"var locals = '';"
|
|
|
|
"for (var i = 0; i < 512; i++) locals += 'var v' + i + '= 42;';"
|
|
|
|
"eval('function f() {' + locals + 'return function() { return v0; }; }');"
|
|
|
|
"interrupt();" // This triggers a fake stack overflow in f.
|
|
|
|
"f()()");
|
2015-11-09 19:48:08 +00:00
|
|
|
CHECK_EQ(42.0, result->ToNumber(context).ToLocalChecked()->Value());
|
2014-03-31 14:14:54 +00:00
|
|
|
}
|
2014-04-24 09:04:12 +00:00
|
|
|
|
|
|
|
|
2015-07-27 13:29:14 +00:00
|
|
|
TEST(Regress507979) {
|
|
|
|
const int kFixedArrayLen = 10;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
Handle<FixedArray> o1 = isolate->factory()->NewFixedArray(kFixedArrayLen);
|
|
|
|
Handle<FixedArray> o2 = isolate->factory()->NewFixedArray(kFixedArrayLen);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*o1));
|
|
|
|
CHECK(Heap::InYoungGeneration(*o2));
|
2015-07-27 13:29:14 +00:00
|
|
|
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator it(isolate->heap(),
|
|
|
|
i::HeapObjectIterator::kFilterUnreachable);
|
2015-07-27 13:29:14 +00:00
|
|
|
|
|
|
|
// Replace parts of an object placed before a live object with a filler. This
|
|
|
|
// way the filler object shares the mark bits with the following live object.
|
2018-07-10 12:58:11 +00:00
|
|
|
o1->Shrink(isolate, kFixedArrayLen - 1);
|
2015-07-27 13:29:14 +00:00
|
|
|
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = it.Next(); !obj.is_null(); obj = it.Next()) {
|
2015-07-27 13:29:14 +00:00
|
|
|
// Let's not optimize the loop away.
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_NE(obj.address(), kNullAddress);
|
2015-07-27 13:29:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-28 15:33:24 +00:00
|
|
|
TEST(Regress388880) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_incremental_marking = false;
|
|
|
|
FLAG_expose_gc = true;
|
2014-07-28 15:33:24 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
|
2014-09-19 14:59:14 +00:00
|
|
|
Handle<Map> map1 = Map::Create(isolate, 1);
|
2016-02-18 14:33:34 +00:00
|
|
|
Handle<String> name = factory->NewStringFromStaticChars("foo");
|
|
|
|
name = factory->InternalizeString(name);
|
2014-07-28 15:33:24 +00:00
|
|
|
Handle<Map> map2 =
|
2018-06-19 09:00:37 +00:00
|
|
|
Map::CopyWithField(isolate, map1, name, FieldType::Any(isolate), NONE,
|
2018-05-28 15:44:58 +00:00
|
|
|
PropertyConstness::kMutable, Representation::Tagged(),
|
|
|
|
OMIT_TRANSITION)
|
2016-01-26 15:03:40 +00:00
|
|
|
.ToHandleChecked();
|
2014-07-28 15:33:24 +00:00
|
|
|
|
2016-11-10 10:16:21 +00:00
|
|
|
size_t desired_offset = Page::kPageSize - map1->instance_size();
|
2014-07-28 15:33:24 +00:00
|
|
|
|
2015-10-07 09:13:54 +00:00
|
|
|
// Allocate padding objects in old pointer space so, that object allocated
|
2014-07-28 15:33:24 +00:00
|
|
|
// afterwards would end at the end of the page.
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2018-10-23 11:52:20 +00:00
|
|
|
size_t padding_size =
|
|
|
|
desired_offset - MemoryChunkLayout::ObjectStartOffsetInDataPage();
|
2019-03-11 19:04:02 +00:00
|
|
|
heap::CreatePadding(heap, static_cast<int>(padding_size),
|
|
|
|
AllocationType::kOld);
|
2014-07-28 15:33:24 +00:00
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<JSObject> o = factory->NewJSObjectFromMap(map1, AllocationType::kOld);
|
2017-07-17 23:30:32 +00:00
|
|
|
o->set_raw_properties_or_hash(*factory->empty_fixed_array());
|
2014-07-28 15:33:24 +00:00
|
|
|
|
2015-07-06 13:59:30 +00:00
|
|
|
// Ensure that the object allocated where we need it.
|
2019-01-15 00:23:43 +00:00
|
|
|
Page* page = Page::FromHeapObject(*o);
|
2015-07-06 13:59:30 +00:00
|
|
|
CHECK_EQ(desired_offset, page->Offset(o->address()));
|
2014-07-28 15:33:24 +00:00
|
|
|
|
|
|
|
// Now we have an object right at the end of the page.
|
|
|
|
|
|
|
|
// Enable incremental marking to trigger actions in Heap::AdjustLiveBytes()
|
|
|
|
// that would cause crash.
|
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
2015-08-07 09:36:42 +00:00
|
|
|
marking->Stop();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::heap()->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2014-07-28 15:33:24 +00:00
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
|
|
|
|
// Now everything is set up for crashing in JSObject::MigrateFastToFast()
|
|
|
|
// when it calls heap->AdjustLiveBytes(...).
|
2019-06-07 08:39:21 +00:00
|
|
|
JSObject::MigrateToMap(isolate, o, map2);
|
2014-07-28 15:33:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-31 13:11:30 +00:00
|
|
|
TEST(Regress3631) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_expose_gc = true;
|
2014-10-31 13:11:30 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
|
|
|
v8::Local<v8::Value> result = CompileRun(
|
|
|
|
"var weak_map = new WeakMap();"
|
|
|
|
"var future_keys = [];"
|
|
|
|
"for (var i = 0; i < 50; i++) {"
|
|
|
|
" var key = {'k' : i + 0.1};"
|
|
|
|
" weak_map.set(key, 1);"
|
|
|
|
" future_keys.push({'x' : i + 0.2});"
|
|
|
|
"}"
|
|
|
|
"weak_map");
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::heap()->StartIncrementalMarking(
|
|
|
|
i::Heap::kNoGCFlags, i::GarbageCollectionReason::kTesting);
|
2014-10-31 13:11:30 +00:00
|
|
|
}
|
|
|
|
// Incrementally mark the backing store.
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSReceiver> obj =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(result));
|
2018-12-08 02:59:17 +00:00
|
|
|
Handle<JSWeakCollection> weak_map(JSWeakCollection::cast(*obj), isolate);
|
2019-02-07 10:58:09 +00:00
|
|
|
SimulateIncrementalMarking(heap);
|
2014-10-31 13:11:30 +00:00
|
|
|
// Stash the backing store in a handle.
|
|
|
|
Handle<Object> save(weak_map->table(), isolate);
|
|
|
|
// The following line will update the backing store.
|
|
|
|
CompileRun(
|
|
|
|
"for (var i = 0; i < 50; i++) {"
|
|
|
|
" weak_map.set(future_keys[i], i);"
|
|
|
|
"}");
|
|
|
|
heap->incremental_marking()->set_should_hurry(true);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2014-10-31 13:11:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-18 12:50:02 +00:00
|
|
|
TEST(Regress442710) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
|
|
|
|
HandleScope sc(isolate);
|
2019-05-23 07:47:44 +00:00
|
|
|
Handle<JSGlobalObject> global(CcTest::i_isolate()->context().global_object(),
|
2018-06-23 09:05:50 +00:00
|
|
|
isolate);
|
2014-12-18 12:50:02 +00:00
|
|
|
Handle<JSArray> array = factory->NewJSArray(2);
|
|
|
|
|
|
|
|
Handle<String> name = factory->InternalizeUtf8String("testArray");
|
2019-01-23 16:34:14 +00:00
|
|
|
Object::SetProperty(isolate, global, name, array).Check();
|
2014-12-18 12:50:02 +00:00
|
|
|
CompileRun("testArray[0] = 1; testArray[1] = 2; testArray.shift();");
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2014-12-18 12:50:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 12:40:22 +00:00
|
|
|
HEAP_TEST(NumberStringCacheSize) {
|
2015-01-15 11:48:57 +00:00
|
|
|
// Test that the number-string cache has not been resized in the snapshot.
|
2015-01-15 11:22:04 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2015-02-25 11:14:40 +00:00
|
|
|
if (!isolate->snapshot_available()) return;
|
2015-01-15 11:22:04 +00:00
|
|
|
Heap* heap = isolate->heap();
|
2015-08-21 12:40:22 +00:00
|
|
|
CHECK_EQ(Heap::kInitialNumberStringCacheSize * 2,
|
2019-05-23 07:47:44 +00:00
|
|
|
heap->number_string_cache().length());
|
2015-01-15 11:22:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-03-23 11:20:38 +00:00
|
|
|
TEST(Regress3877) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
CompileRun("function cls() { this.x = 10; }");
|
2018-08-14 07:18:05 +00:00
|
|
|
Handle<WeakFixedArray> weak_prototype_holder = factory->NewWeakFixedArray(1);
|
2015-03-23 11:20:38 +00:00
|
|
|
{
|
|
|
|
HandleScope inner_scope(isolate);
|
|
|
|
v8::Local<v8::Value> result = CompileRun("cls.prototype");
|
2015-11-16 16:48:43 +00:00
|
|
|
Handle<JSReceiver> proto =
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(result));
|
2018-08-14 07:18:05 +00:00
|
|
|
weak_prototype_holder->Set(0, HeapObjectReference::Weak(*proto));
|
2015-03-23 11:20:38 +00:00
|
|
|
}
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(!weak_prototype_holder->Get(0)->IsCleared());
|
2015-03-23 11:20:38 +00:00
|
|
|
CompileRun(
|
|
|
|
"var a = { };"
|
|
|
|
"a.x = new cls();"
|
|
|
|
"cls.prototype = null;");
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-03-23 11:20:38 +00:00
|
|
|
}
|
|
|
|
// The map of a.x keeps prototype alive
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(!weak_prototype_holder->Get(0)->IsCleared());
|
2015-03-23 11:20:38 +00:00
|
|
|
// Change the map of a.x and make the previous map garbage collectable.
|
|
|
|
CompileRun("a.x.__proto__ = {};");
|
|
|
|
for (int i = 0; i < 4; i++) {
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-03-23 11:20:38 +00:00
|
|
|
}
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(weak_prototype_holder->Get(0)->IsCleared());
|
2015-03-23 11:20:38 +00:00
|
|
|
}
|
|
|
|
|
2018-04-16 07:28:28 +00:00
|
|
|
Handle<WeakFixedArray> AddRetainedMap(Isolate* isolate, Heap* heap) {
|
|
|
|
HandleScope inner_scope(isolate);
|
|
|
|
Handle<Map> map = Map::Create(isolate, 1);
|
|
|
|
v8::Local<v8::Value> result =
|
|
|
|
CompileRun("(function () { return {x : 10}; })();");
|
|
|
|
Handle<JSReceiver> proto =
|
|
|
|
v8::Utils::OpenHandle(*v8::Local<v8::Object>::Cast(result));
|
2018-06-25 10:54:01 +00:00
|
|
|
Map::SetPrototype(isolate, map, proto);
|
2018-04-16 07:28:28 +00:00
|
|
|
heap->AddRetainedMap(map);
|
|
|
|
Handle<WeakFixedArray> array = isolate->factory()->NewWeakFixedArray(1);
|
|
|
|
array->Set(0, HeapObjectReference::Weak(*map));
|
|
|
|
return inner_scope.CloseAndEscape(array);
|
2015-03-24 14:35:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CheckMapRetainingFor(int n) {
|
|
|
|
FLAG_retain_maps_for_n_gc = n;
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
2018-04-16 07:28:28 +00:00
|
|
|
Handle<WeakFixedArray> array_with_map = AddRetainedMap(isolate, heap);
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(array_with_map->Get(0)->IsWeak());
|
2015-03-06 12:36:16 +00:00
|
|
|
for (int i = 0; i < n; i++) {
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2015-03-06 12:36:16 +00:00
|
|
|
}
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(array_with_map->Get(0)->IsWeak());
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
Reland [in-place weak refs] Fix MaybeObject function names
E.g., "ToWeakHeapObject" was misleading, since it didn't convert to a weak heap
object, instead returned a weakly pointed heap object. Change the function names
(in this case, to "GetHeapObjectIfWeak") to reflect this.
Also make casts explicit, if a MaybeObject is an Object, we can call cast<Object>().
Previous version: https://chromium-review.googlesource.com/1219025
BUG=v8:7308
TBR=ishell@chromium.org, ulan@chromium.org, ahaas@chromium.org, yangguo@chromium.org, tebbi@chromium.org
Change-Id: I503d4a2a3a68f85e9e02e1c2f9fc1c4187c8e9a1
Reviewed-on: https://chromium-review.googlesource.com/1226800
Reviewed-by: Marja Hölttä <marja@chromium.org>
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55934}
2018-09-17 07:36:25 +00:00
|
|
|
CHECK(array_with_map->Get(0)->IsCleared());
|
2015-03-06 12:36:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MapRetaining) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-08-23 11:18:19 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2015-03-06 12:36:16 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
CheckMapRetainingFor(FLAG_retain_maps_for_n_gc);
|
|
|
|
CheckMapRetainingFor(0);
|
|
|
|
CheckMapRetainingFor(1);
|
|
|
|
CheckMapRetainingFor(7);
|
|
|
|
}
|
|
|
|
|
2015-04-28 11:13:22 +00:00
|
|
|
TEST(PreprocessStackTrace) {
|
|
|
|
// Do not automatically trigger early GC.
|
|
|
|
FLAG_gc_interval = -1;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2015-05-28 12:49:31 +00:00
|
|
|
v8::TryCatch try_catch(CcTest::isolate());
|
2015-04-28 11:13:22 +00:00
|
|
|
CompileRun("throw new Error();");
|
|
|
|
CHECK(try_catch.HasCaught());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Handle<Object> exception = v8::Utils::OpenHandle(*try_catch.Exception());
|
|
|
|
Handle<Name> key = isolate->factory()->stack_trace_symbol();
|
|
|
|
Handle<Object> stack_trace =
|
2018-07-17 08:49:20 +00:00
|
|
|
Object::GetProperty(isolate, exception, key).ToHandleChecked();
|
2015-04-28 11:13:22 +00:00
|
|
|
Handle<Object> code =
|
|
|
|
Object::GetElement(isolate, stack_trace, 3).ToHandleChecked();
|
|
|
|
CHECK(code->IsCode());
|
|
|
|
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-04-28 11:13:22 +00:00
|
|
|
|
|
|
|
Handle<Object> pos =
|
|
|
|
Object::GetElement(isolate, stack_trace, 3).ToHandleChecked();
|
|
|
|
CHECK(pos->IsSmi());
|
|
|
|
|
2019-04-12 07:08:53 +00:00
|
|
|
Handle<FrameArray> frame_array = Handle<FrameArray>::cast(stack_trace);
|
|
|
|
int array_length = frame_array->FrameCount();
|
2015-04-28 11:13:22 +00:00
|
|
|
for (int i = 0; i < array_length; i++) {
|
|
|
|
Handle<Object> element =
|
|
|
|
Object::GetElement(isolate, stack_trace, i).ToHandleChecked();
|
|
|
|
CHECK(!element->IsCode());
|
|
|
|
}
|
|
|
|
}
|
2015-05-12 14:00:47 +00:00
|
|
|
|
|
|
|
|
2015-05-26 11:51:18 +00:00
|
|
|
void AllocateInSpace(Isolate* isolate, size_t bytes, AllocationSpace space) {
|
2017-09-19 13:08:15 +00:00
|
|
|
CHECK_LE(FixedArray::kHeaderSize, bytes);
|
2018-12-19 19:10:21 +00:00
|
|
|
CHECK(IsAligned(bytes, kTaggedSize));
|
2015-05-21 10:19:09 +00:00
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
|
|
|
int elements =
|
2018-12-19 19:10:21 +00:00
|
|
|
static_cast<int>((bytes - FixedArray::kHeaderSize) / kTaggedSize);
|
2015-05-26 11:51:18 +00:00
|
|
|
Handle<FixedArray> array = factory->NewFixedArray(
|
2019-03-11 19:04:02 +00:00
|
|
|
elements,
|
|
|
|
space == NEW_SPACE ? AllocationType::kYoung : AllocationType::kOld);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK((space == NEW_SPACE) == Heap::InYoungGeneration(*array));
|
2015-05-21 10:19:09 +00:00
|
|
|
CHECK_EQ(bytes, static_cast<size_t>(array->Size()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(NewSpaceAllocationCounter) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
size_t counter1 = heap->NewSpaceAllocationCounter();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2017-01-25 07:41:34 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE); // Ensure new space is empty.
|
2015-05-21 10:19:09 +00:00
|
|
|
const size_t kSize = 1024;
|
2015-05-26 11:51:18 +00:00
|
|
|
AllocateInSpace(isolate, kSize, NEW_SPACE);
|
2015-05-21 10:19:09 +00:00
|
|
|
size_t counter2 = heap->NewSpaceAllocationCounter();
|
|
|
|
CHECK_EQ(kSize, counter2 - counter1);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2015-05-21 10:19:09 +00:00
|
|
|
size_t counter3 = heap->NewSpaceAllocationCounter();
|
2015-06-04 01:28:14 +00:00
|
|
|
CHECK_EQ(0U, counter3 - counter2);
|
2015-05-21 10:19:09 +00:00
|
|
|
// Test counter overflow.
|
2017-03-17 15:18:18 +00:00
|
|
|
size_t max_counter = static_cast<size_t>(-1);
|
2015-05-21 10:19:09 +00:00
|
|
|
heap->set_new_space_allocation_counter(max_counter - 10 * kSize);
|
|
|
|
size_t start = heap->NewSpaceAllocationCounter();
|
|
|
|
for (int i = 0; i < 20; i++) {
|
2015-05-26 11:51:18 +00:00
|
|
|
AllocateInSpace(isolate, kSize, NEW_SPACE);
|
2015-05-21 10:19:09 +00:00
|
|
|
size_t counter = heap->NewSpaceAllocationCounter();
|
|
|
|
CHECK_EQ(kSize, counter - start);
|
|
|
|
start = counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-26 11:51:18 +00:00
|
|
|
TEST(OldSpaceAllocationCounter) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
size_t counter1 = heap->OldGenerationAllocationCounter();
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2015-05-26 11:51:18 +00:00
|
|
|
const size_t kSize = 1024;
|
|
|
|
AllocateInSpace(isolate, kSize, OLD_SPACE);
|
|
|
|
size_t counter2 = heap->OldGenerationAllocationCounter();
|
2015-05-26 15:42:20 +00:00
|
|
|
// TODO(ulan): replace all CHECK_LE with CHECK_EQ after v8:4148 is fixed.
|
|
|
|
CHECK_LE(kSize, counter2 - counter1);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2015-05-26 11:51:18 +00:00
|
|
|
size_t counter3 = heap->OldGenerationAllocationCounter();
|
2015-05-26 15:48:20 +00:00
|
|
|
CHECK_EQ(0u, counter3 - counter2);
|
2015-05-26 11:51:18 +00:00
|
|
|
AllocateInSpace(isolate, kSize, OLD_SPACE);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2015-05-26 11:51:18 +00:00
|
|
|
size_t counter4 = heap->OldGenerationAllocationCounter();
|
2015-05-26 15:42:20 +00:00
|
|
|
CHECK_LE(kSize, counter4 - counter3);
|
2015-05-26 11:51:18 +00:00
|
|
|
// Test counter overflow.
|
2017-03-17 15:18:18 +00:00
|
|
|
size_t max_counter = static_cast<size_t>(-1);
|
2016-09-28 13:27:44 +00:00
|
|
|
heap->set_old_generation_allocation_counter_at_last_gc(max_counter -
|
|
|
|
10 * kSize);
|
2015-05-26 11:51:18 +00:00
|
|
|
size_t start = heap->OldGenerationAllocationCounter();
|
|
|
|
for (int i = 0; i < 20; i++) {
|
|
|
|
AllocateInSpace(isolate, kSize, OLD_SPACE);
|
|
|
|
size_t counter = heap->OldGenerationAllocationCounter();
|
2015-05-26 15:42:20 +00:00
|
|
|
CHECK_LE(kSize, counter - start);
|
2015-05-26 11:51:18 +00:00
|
|
|
start = counter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-26 08:00:04 +00:00
|
|
|
static void CheckLeak(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2019-01-07 12:28:05 +00:00
|
|
|
Object message(
|
2018-12-17 13:34:08 +00:00
|
|
|
*reinterpret_cast<Address*>(isolate->pending_message_obj_address()));
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(message.IsTheHole(isolate));
|
2015-05-26 08:00:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(MessageObjectLeak) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
|
|
|
global->Set(
|
|
|
|
v8::String::NewFromUtf8(isolate, "check", v8::NewStringType::kNormal)
|
|
|
|
.ToLocalChecked(),
|
|
|
|
v8::FunctionTemplate::New(isolate, CheckLeak));
|
2017-10-13 16:33:03 +00:00
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
|
2015-05-26 08:00:04 +00:00
|
|
|
v8::Context::Scope cscope(context);
|
|
|
|
|
|
|
|
const char* test =
|
|
|
|
"try {"
|
|
|
|
" throw 'message 1';"
|
|
|
|
"} catch (e) {"
|
|
|
|
"}"
|
|
|
|
"check();"
|
|
|
|
"L: try {"
|
|
|
|
" throw 'message 2';"
|
|
|
|
"} finally {"
|
|
|
|
" break L;"
|
|
|
|
"}"
|
|
|
|
"check();";
|
|
|
|
CompileRun(test);
|
|
|
|
|
|
|
|
const char* flag = "--turbo-filter=*";
|
2019-04-23 18:17:01 +00:00
|
|
|
FlagList::SetFlagsFromString(flag, strlen(flag));
|
2015-05-26 08:00:04 +00:00
|
|
|
FLAG_always_opt = true;
|
|
|
|
|
|
|
|
CompileRun(test);
|
|
|
|
}
|
2015-05-26 11:51:18 +00:00
|
|
|
|
|
|
|
|
2015-06-25 12:19:55 +00:00
|
|
|
static void CheckEqualSharedFunctionInfos(
|
|
|
|
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
Handle<Object> obj1 = v8::Utils::OpenHandle(*args[0]);
|
|
|
|
Handle<Object> obj2 = v8::Utils::OpenHandle(*args[1]);
|
|
|
|
Handle<JSFunction> fun1 = Handle<JSFunction>::cast(obj1);
|
|
|
|
Handle<JSFunction> fun2 = Handle<JSFunction>::cast(obj2);
|
|
|
|
CHECK(fun1->shared() == fun2->shared());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void RemoveCodeAndGC(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Handle<Object> obj = v8::Utils::OpenHandle(*args[0]);
|
|
|
|
Handle<JSFunction> fun = Handle<JSFunction>::cast(obj);
|
2018-07-09 09:34:34 +00:00
|
|
|
// Bytecode is code too.
|
|
|
|
SharedFunctionInfo::DiscardCompiled(isolate, handle(fun->shared(), isolate));
|
2017-09-28 11:59:42 +00:00
|
|
|
fun->set_code(*BUILTIN_CODE(isolate, CompileLazy));
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2015-06-25 12:19:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(CanonicalSharedFunctionInfo) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::Isolate* isolate = CcTest::isolate();
|
|
|
|
v8::HandleScope scope(isolate);
|
2015-11-09 19:48:08 +00:00
|
|
|
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
|
2015-06-25 12:19:55 +00:00
|
|
|
global->Set(isolate, "check", v8::FunctionTemplate::New(
|
|
|
|
isolate, CheckEqualSharedFunctionInfos));
|
|
|
|
global->Set(isolate, "remove",
|
|
|
|
v8::FunctionTemplate::New(isolate, RemoveCodeAndGC));
|
2017-10-13 16:33:03 +00:00
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate, nullptr, global);
|
2015-06-25 12:19:55 +00:00
|
|
|
v8::Context::Scope cscope(context);
|
|
|
|
CompileRun(
|
|
|
|
"function f() { return function g() {}; }"
|
|
|
|
"var g1 = f();"
|
|
|
|
"remove(f);"
|
|
|
|
"var g2 = f();"
|
|
|
|
"check(g1, g2);");
|
|
|
|
|
|
|
|
CompileRun(
|
|
|
|
"function f() { return (function() { return function g() {}; })(); }"
|
|
|
|
"var g1 = f();"
|
|
|
|
"remove(f);"
|
|
|
|
"var g2 = f();"
|
|
|
|
"check(g1, g2);");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-08-21 08:12:11 +00:00
|
|
|
TEST(ScriptIterator) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
LocalContext context;
|
|
|
|
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2015-08-21 08:12:11 +00:00
|
|
|
|
|
|
|
int script_count = 0;
|
|
|
|
{
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator it(heap);
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = it.Next(); !obj.is_null(); obj = it.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (obj.IsScript()) script_count++;
|
2015-08-21 08:12:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
Script::Iterator iterator(isolate);
|
2018-12-17 12:49:34 +00:00
|
|
|
for (Script script = iterator.Next(); !script.is_null();
|
|
|
|
script = iterator.Next()) {
|
|
|
|
script_count--;
|
|
|
|
}
|
2015-08-21 08:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_EQ(0, script_count);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(SharedFunctionInfoIterator) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
LocalContext context;
|
|
|
|
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
CcTest::CollectAllGarbage();
|
2015-08-21 08:12:11 +00:00
|
|
|
|
|
|
|
int sfi_count = 0;
|
|
|
|
{
|
2019-06-13 10:51:22 +00:00
|
|
|
HeapObjectIterator it(heap);
|
2019-05-31 10:59:12 +00:00
|
|
|
for (HeapObject obj = it.Next(); !obj.is_null(); obj = it.Next()) {
|
2019-05-23 07:47:44 +00:00
|
|
|
if (!obj.IsSharedFunctionInfo()) continue;
|
2015-10-27 11:40:31 +00:00
|
|
|
sfi_count++;
|
2015-08-21 08:12:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2016-12-15 17:19:55 +00:00
|
|
|
SharedFunctionInfo::GlobalIterator iterator(isolate);
|
2018-11-28 19:57:30 +00:00
|
|
|
while (!iterator.Next().is_null()) sfi_count--;
|
2015-08-21 08:12:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CHECK_EQ(0, sfi_count);
|
|
|
|
}
|
|
|
|
|
2018-04-09 19:11:22 +00:00
|
|
|
// This is the same as Factory::NewByteArray, except it doesn't retry on
|
|
|
|
// allocation failure.
|
2019-03-11 19:04:02 +00:00
|
|
|
AllocationResult HeapTester::AllocateByteArrayForTest(
|
|
|
|
Heap* heap, int length, AllocationType allocation_type) {
|
2018-04-09 19:11:22 +00:00
|
|
|
DCHECK(length >= 0 && length <= ByteArray::kMaxLength);
|
|
|
|
int size = ByteArray::SizeFor(length);
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject result;
|
2018-04-09 19:11:22 +00:00
|
|
|
{
|
2019-03-11 19:04:02 +00:00
|
|
|
AllocationResult allocation = heap->AllocateRaw(size, allocation_type);
|
2018-04-09 19:11:22 +00:00
|
|
|
if (!allocation.To(&result)) return allocation;
|
|
|
|
}
|
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
result.set_map_after_allocation(ReadOnlyRoots(heap).byte_array_map(),
|
|
|
|
SKIP_WRITE_BARRIER);
|
|
|
|
ByteArray::cast(result).set_length(length);
|
|
|
|
ByteArray::cast(result).clear_padding();
|
2018-04-09 19:11:22 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-02-17 11:52:31 +00:00
|
|
|
HEAP_TEST(Regress587004) {
|
2017-11-20 12:13:24 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2016-02-17 11:52:31 +00:00
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
FLAG_verify_heap = false;
|
|
|
|
#endif
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
2016-09-06 12:58:59 +00:00
|
|
|
const int N =
|
2018-12-19 19:10:21 +00:00
|
|
|
(kMaxRegularHeapObjectSize - FixedArray::kHeaderSize) / kTaggedSize;
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> array = factory->NewFixedArray(N, AllocationType::kOld);
|
2016-02-17 11:52:31 +00:00
|
|
|
CHECK(heap->old_space()->Contains(*array));
|
|
|
|
Handle<Object> number = factory->NewHeapNumber(1.0);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*number));
|
2016-02-17 11:52:31 +00:00
|
|
|
for (int i = 0; i < N; i++) {
|
|
|
|
array->set(i, *number);
|
|
|
|
}
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2016-11-18 11:11:30 +00:00
|
|
|
heap->RightTrimFixedArray(*array, N - 1);
|
2016-02-17 11:52:31 +00:00
|
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
2018-11-24 08:51:21 +00:00
|
|
|
ByteArray byte_array;
|
2016-02-17 11:52:31 +00:00
|
|
|
const int M = 256;
|
|
|
|
// Don't allow old space expansion. The test works without this flag too,
|
|
|
|
// but becomes very slow.
|
|
|
|
heap->set_force_oom(true);
|
2019-03-11 19:04:02 +00:00
|
|
|
while (
|
|
|
|
AllocateByteArrayForTest(heap, M, AllocationType::kOld).To(&byte_array)) {
|
2016-02-17 11:52:31 +00:00
|
|
|
for (int j = 0; j < M; j++) {
|
2019-05-23 07:47:44 +00:00
|
|
|
byte_array.set(j, 0x31);
|
2016-02-17 11:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Re-enable old space expansion to avoid OOM crash.
|
|
|
|
heap->set_force_oom(false);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2016-02-17 11:52:31 +00:00
|
|
|
}
|
2015-10-29 13:59:34 +00:00
|
|
|
|
2016-02-25 17:28:50 +00:00
|
|
|
HEAP_TEST(Regress589413) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-02-25 17:28:50 +00:00
|
|
|
FLAG_stress_compaction = true;
|
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
|
|
|
FLAG_parallel_compaction = false;
|
2017-11-20 12:13:24 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2016-02-25 17:28:50 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
// Get the heap in clean state.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2016-02-25 17:28:50 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
// Fill the new space with byte arrays with elements looking like pointers.
|
|
|
|
const int M = 256;
|
2018-11-24 08:51:21 +00:00
|
|
|
ByteArray byte_array;
|
2019-03-11 19:04:02 +00:00
|
|
|
while (AllocateByteArrayForTest(heap, M, AllocationType::kYoung)
|
|
|
|
.To(&byte_array)) {
|
2016-02-25 17:28:50 +00:00
|
|
|
for (int j = 0; j < M; j++) {
|
2019-05-23 07:47:44 +00:00
|
|
|
byte_array.set(j, 0x31);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
// Add the array in root set.
|
2018-06-11 09:53:20 +00:00
|
|
|
handle(byte_array, isolate);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
// Make sure the byte arrays will be promoted on the next GC.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2016-02-25 17:28:50 +00:00
|
|
|
// This number is close to large free list category threshold.
|
2017-12-02 00:30:37 +00:00
|
|
|
const int N = 0x3EEE;
|
2016-02-25 17:28:50 +00:00
|
|
|
{
|
2018-11-25 02:24:43 +00:00
|
|
|
std::vector<FixedArray> arrays;
|
2016-02-25 17:28:50 +00:00
|
|
|
std::set<Page*> pages;
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArray array;
|
2016-02-25 17:28:50 +00:00
|
|
|
// Fill all pages with fixed arrays.
|
|
|
|
heap->set_force_oom(true);
|
2019-03-11 19:04:02 +00:00
|
|
|
while (
|
|
|
|
AllocateFixedArrayForTest(heap, N, AllocationType::kOld).To(&array)) {
|
2016-02-25 17:28:50 +00:00
|
|
|
arrays.push_back(array);
|
2018-11-25 02:24:43 +00:00
|
|
|
pages.insert(Page::FromHeapObject(array));
|
2016-02-25 17:28:50 +00:00
|
|
|
// Add the array in root set.
|
2018-06-11 09:53:20 +00:00
|
|
|
handle(array, isolate);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
// Expand and full one complete page with fixed arrays.
|
|
|
|
heap->set_force_oom(false);
|
2019-03-11 19:04:02 +00:00
|
|
|
while (
|
|
|
|
AllocateFixedArrayForTest(heap, N, AllocationType::kOld).To(&array)) {
|
2016-02-25 17:28:50 +00:00
|
|
|
arrays.push_back(array);
|
2018-11-25 02:24:43 +00:00
|
|
|
pages.insert(Page::FromHeapObject(array));
|
2016-02-25 17:28:50 +00:00
|
|
|
// Add the array in root set.
|
2018-06-11 09:53:20 +00:00
|
|
|
handle(array, isolate);
|
2016-02-25 17:28:50 +00:00
|
|
|
// Do not expand anymore.
|
|
|
|
heap->set_force_oom(true);
|
|
|
|
}
|
|
|
|
// Expand and mark the new page as evacuation candidate.
|
|
|
|
heap->set_force_oom(false);
|
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<HeapObject> ec_obj =
|
|
|
|
factory->NewFixedArray(5000, AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
Page* ec_page = Page::FromHeapObject(*ec_obj);
|
2016-11-03 12:12:38 +00:00
|
|
|
heap::ForceEvacuationCandidate(ec_page);
|
2016-02-25 17:28:50 +00:00
|
|
|
// Make all arrays point to evacuation candidate so that
|
|
|
|
// slots are recorded for them.
|
|
|
|
for (size_t j = 0; j < arrays.size(); j++) {
|
|
|
|
array = arrays[j];
|
|
|
|
for (int i = 0; i < N; i++) {
|
2019-05-23 07:47:44 +00:00
|
|
|
array.set(i, *ec_obj);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 13:30:22 +00:00
|
|
|
heap::SimulateIncrementalMarking(heap);
|
2016-02-25 17:28:50 +00:00
|
|
|
for (size_t j = 0; j < arrays.size(); j++) {
|
2016-11-18 11:11:30 +00:00
|
|
|
heap->RightTrimFixedArray(arrays[j], N - 1);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// Force allocation from the free list.
|
|
|
|
heap->set_force_oom(true);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2016-02-25 17:28:50 +00:00
|
|
|
}
|
|
|
|
|
2016-05-04 09:33:05 +00:00
|
|
|
TEST(Regress598319) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-06-13 14:39:46 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2016-05-04 09:33:05 +00:00
|
|
|
// This test ensures that no white objects can cross the progress bar of large
|
|
|
|
// objects during incremental marking. It checks this by using Shift() during
|
|
|
|
// incremental marking.
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
|
2019-02-06 15:23:06 +00:00
|
|
|
// The size of the array should be larger than kProgressBarScanningChunk.
|
|
|
|
const int kNumberOfObjects = Max(FixedArray::kMaxRegularLength + 1, 128 * KB);
|
2016-05-04 09:33:05 +00:00
|
|
|
|
|
|
|
struct Arr {
|
|
|
|
Arr(Isolate* isolate, int number_of_objects) {
|
2019-03-11 19:04:02 +00:00
|
|
|
root = isolate->factory()->NewFixedArray(1, AllocationType::kOld);
|
2016-05-04 09:33:05 +00:00
|
|
|
{
|
|
|
|
// Temporary scope to avoid getting any other objects into the root set.
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> tmp = isolate->factory()->NewFixedArray(
|
|
|
|
number_of_objects, AllocationType::kOld);
|
2016-05-04 09:33:05 +00:00
|
|
|
root->set(0, *tmp);
|
2019-05-23 07:47:44 +00:00
|
|
|
for (int i = 0; i < get().length(); i++) {
|
2019-03-11 19:04:02 +00:00
|
|
|
tmp = isolate->factory()->NewFixedArray(100, AllocationType::kOld);
|
2019-05-23 07:47:44 +00:00
|
|
|
get().set(i, *tmp);
|
2016-05-04 09:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArray get() { return FixedArray::cast(root->get(0)); }
|
2016-05-04 09:33:05 +00:00
|
|
|
|
|
|
|
Handle<FixedArray> root;
|
|
|
|
} arr(isolate, kNumberOfObjects);
|
|
|
|
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_EQ(arr.get().length(), kNumberOfObjects);
|
2016-05-04 09:33:05 +00:00
|
|
|
CHECK(heap->lo_space()->Contains(arr.get()));
|
2019-01-29 12:21:28 +00:00
|
|
|
LargePage* page = LargePage::FromHeapObject(arr.get());
|
2016-05-04 09:33:05 +00:00
|
|
|
CHECK_NOT_NULL(page);
|
|
|
|
|
|
|
|
// GC to cleanup state
|
2016-12-05 10:15:02 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2016-05-04 09:33:05 +00:00
|
|
|
MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(heap->lo_space()->Contains(arr.get()));
|
2017-08-12 12:17:52 +00:00
|
|
|
IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
IncrementalMarking::MarkingState* marking_state = marking->marking_state();
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsWhite(arr.get()));
|
2019-05-23 07:47:44 +00:00
|
|
|
for (int i = 0; i < arr.get().length(); i++) {
|
|
|
|
HeapObject arr_value = HeapObject::cast(arr.get().get(i));
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsWhite(arr_value));
|
2016-05-04 09:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Start incremental marking.
|
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2016-05-04 09:33:05 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
|
|
|
|
// Check that we have not marked the interesting array during root scanning.
|
2019-05-23 07:47:44 +00:00
|
|
|
for (int i = 0; i < arr.get().length(); i++) {
|
|
|
|
HeapObject arr_value = HeapObject::cast(arr.get().get(i));
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsWhite(arr_value));
|
2016-05-04 09:33:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Now we search for a state where we are in incremental marking and have
|
|
|
|
// only partially marked the large object.
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kSmallStepSizeInMs = 0.1;
|
2016-05-04 09:33:05 +00:00
|
|
|
while (!marking->IsComplete()) {
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kSmallStepSizeInMs,
|
|
|
|
i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2019-03-20 19:01:07 +00:00
|
|
|
if (page->IsFlagSet(Page::HAS_PROGRESS_BAR) && page->ProgressBar() > 0) {
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK_NE(page->ProgressBar(), arr.get().Size());
|
2016-05-04 09:33:05 +00:00
|
|
|
{
|
|
|
|
// Shift by 1, effectively moving one white object across the progress
|
|
|
|
// bar, meaning that we will miss marking it.
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Handle<JSArray> js_array = isolate->factory()->NewJSArrayWithElements(
|
2018-06-23 09:05:50 +00:00
|
|
|
Handle<FixedArray>(arr.get(), isolate));
|
2016-05-04 09:33:05 +00:00
|
|
|
js_array->GetElementsAccessor()->Shift(js_array);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Finish marking with bigger steps to speed up test.
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kLargeStepSizeInMs = 1000;
|
2016-05-04 09:33:05 +00:00
|
|
|
while (!marking->IsComplete()) {
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kLargeStepSizeInMs,
|
|
|
|
i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2016-05-04 09:33:05 +00:00
|
|
|
if (marking->IsReadyToOverApproximateWeakClosure()) {
|
|
|
|
marking->FinalizeIncrementally();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK(marking->IsComplete());
|
|
|
|
|
|
|
|
// All objects need to be black after marking. If a white object crossed the
|
|
|
|
// progress bar, we would fail here.
|
2019-05-23 07:47:44 +00:00
|
|
|
for (int i = 0; i < arr.get().length(); i++) {
|
|
|
|
HeapObject arr_value = HeapObject::cast(arr.get().get(i));
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(arr_value));
|
2016-05-04 09:33:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-19 11:44:54 +00:00
|
|
|
Handle<FixedArray> ShrinkArrayAndCheckSize(Heap* heap, int length) {
|
|
|
|
// Make sure there is no garbage and the compilation cache is empty.
|
|
|
|
for (int i = 0; i < 5; i++) {
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
}
|
|
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
|
|
|
size_t size_before_allocation = heap->SizeOfObjects();
|
|
|
|
Handle<FixedArray> array =
|
2019-03-11 19:04:02 +00:00
|
|
|
heap->isolate()->factory()->NewFixedArray(length, AllocationType::kOld);
|
2017-08-19 11:44:54 +00:00
|
|
|
size_t size_after_allocation = heap->SizeOfObjects();
|
|
|
|
CHECK_EQ(size_after_allocation, size_before_allocation + array->Size());
|
2018-07-10 12:58:11 +00:00
|
|
|
array->Shrink(heap->isolate(), 1);
|
2017-08-19 11:44:54 +00:00
|
|
|
size_t size_after_shrinking = heap->SizeOfObjects();
|
|
|
|
// Shrinking does not change the space size immediately.
|
|
|
|
CHECK_EQ(size_after_allocation, size_after_shrinking);
|
|
|
|
// GC and sweeping updates the size to acccount for shrinking.
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
heap->mark_compact_collector()->EnsureSweepingCompleted();
|
|
|
|
intptr_t size_after_gc = heap->SizeOfObjects();
|
|
|
|
CHECK_EQ(size_after_gc, size_before_allocation + array->Size());
|
|
|
|
return array;
|
|
|
|
}
|
|
|
|
|
2016-05-11 16:56:34 +00:00
|
|
|
TEST(Regress609761) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
2018-12-19 19:10:21 +00:00
|
|
|
int length = kMaxRegularHeapObjectSize / kTaggedSize + 1;
|
2017-08-19 11:44:54 +00:00
|
|
|
Handle<FixedArray> array = ShrinkArrayAndCheckSize(heap, length);
|
|
|
|
CHECK(heap->lo_space()->Contains(*array));
|
|
|
|
}
|
2016-05-11 16:56:34 +00:00
|
|
|
|
2017-08-19 11:44:54 +00:00
|
|
|
TEST(LiveBytes) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Handle<FixedArray> array = ShrinkArrayAndCheckSize(heap, 2000);
|
|
|
|
CHECK(heap->old_space()->Contains(*array));
|
2016-05-11 16:56:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 13:09:28 +00:00
|
|
|
TEST(Regress615489) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-05-30 13:09:28 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-05-30 13:09:28 +00:00
|
|
|
|
|
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
i::IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2016-05-30 13:09:28 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
marking->StartBlackAllocationForTesting();
|
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate(CcTest::i_isolate());
|
|
|
|
v8::HandleScope inner(CcTest::isolate());
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(500, AllocationType::kOld)->Size();
|
2016-05-30 13:09:28 +00:00
|
|
|
}
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kStepSizeInMs = 100;
|
2016-05-30 13:09:28 +00:00
|
|
|
while (!marking->IsComplete()) {
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2016-05-30 13:09:28 +00:00
|
|
|
if (marking->IsReadyToOverApproximateWeakClosure()) {
|
|
|
|
marking->FinalizeIncrementally();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK(marking->IsComplete());
|
|
|
|
intptr_t size_before = heap->SizeOfObjects();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-05-30 13:09:28 +00:00
|
|
|
intptr_t size_after = heap->SizeOfObjects();
|
|
|
|
// Live size does not increase after garbage collection.
|
|
|
|
CHECK_LE(size_after, size_before);
|
|
|
|
}
|
|
|
|
|
2016-08-16 11:59:10 +00:00
|
|
|
class StaticOneByteResource : public v8::String::ExternalOneByteStringResource {
|
|
|
|
public:
|
|
|
|
explicit StaticOneByteResource(const char* data) : data_(data) {}
|
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
~StaticOneByteResource() override = default;
|
2016-08-16 11:59:10 +00:00
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
const char* data() const override { return data_; }
|
2016-08-16 11:59:10 +00:00
|
|
|
|
2018-09-14 14:02:15 +00:00
|
|
|
size_t length() const override { return strlen(data_); }
|
2016-08-16 11:59:10 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const char* data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(Regress631969) {
|
2016-11-18 12:55:53 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-08-16 11:59:10 +00:00
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
|
|
|
FLAG_parallel_compaction = false;
|
2017-11-20 12:13:24 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2016-08-16 11:59:10 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
// Get the heap in clean state.
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2016-08-16 11:59:10 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
// Allocate two strings in a fresh page and mark the page as evacuation
|
|
|
|
// candidate.
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<String> s1 =
|
|
|
|
factory->NewStringFromStaticChars("123456789", AllocationType::kOld);
|
|
|
|
Handle<String> s2 =
|
|
|
|
factory->NewStringFromStaticChars("01234", AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
heap::ForceEvacuationCandidate(Page::FromHeapObject(*s1));
|
2016-08-16 11:59:10 +00:00
|
|
|
|
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
|
|
|
|
|
|
|
// Allocate a cons string and promote it to a fresh page in the old space.
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
|
|
|
Handle<String> s3;
|
|
|
|
factory->NewConsString(s1, s2).ToHandle(&s3);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2016-08-16 11:59:10 +00:00
|
|
|
|
|
|
|
// Finish incremental marking.
|
2019-02-07 10:58:09 +00:00
|
|
|
const double kStepSizeInMs = 100;
|
2016-08-16 11:59:10 +00:00
|
|
|
IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
while (!marking->IsComplete()) {
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->V8Step(kStepSizeInMs, i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
|
|
|
|
StepOrigin::kV8);
|
2016-08-16 11:59:10 +00:00
|
|
|
if (marking->IsReadyToOverApproximateWeakClosure()) {
|
|
|
|
marking->FinalizeIncrementally();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
StaticOneByteResource external_string("12345678901234");
|
|
|
|
s3->MakeExternal(&external_string);
|
2016-09-07 10:02:58 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2018-07-04 09:31:54 +00:00
|
|
|
// This avoids the GC from trying to free stack allocated resources.
|
2018-07-26 06:42:03 +00:00
|
|
|
i::Handle<i::ExternalOneByteString>::cast(s3)->SetResource(isolate,
|
|
|
|
nullptr);
|
2016-08-16 11:59:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-09 10:50:28 +00:00
|
|
|
TEST(LeftTrimFixedArrayInBlackArea) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-08-09 10:50:28 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
i::IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2016-08-09 10:50:28 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
marking->StartBlackAllocationForTesting();
|
|
|
|
|
|
|
|
// Ensure that we allocate a new page, set up a bump pointer area, and
|
|
|
|
// perform the allocation in a black area.
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(4, AllocationType::kOld);
|
|
|
|
Handle<FixedArray> array =
|
|
|
|
isolate->factory()->NewFixedArray(50, AllocationType::kOld);
|
2016-08-09 10:50:28 +00:00
|
|
|
CHECK(heap->old_space()->Contains(*array));
|
2017-08-12 12:17:52 +00:00
|
|
|
IncrementalMarking::MarkingState* marking_state = marking->marking_state();
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(*array));
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
// Now left trim the allocated black area. A filler has to be installed
|
|
|
|
// for the trimmed area and all mark bits of the trimmed area have to be
|
|
|
|
// cleared.
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArrayBase trimmed = heap->LeftTrimFixedArray(*array, 10);
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(trimmed));
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ContinuousLeftTrimFixedArrayInBlackArea) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-08-09 10:50:28 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
i::IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2016-08-09 10:50:28 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
marking->StartBlackAllocationForTesting();
|
|
|
|
|
|
|
|
// Ensure that we allocate a new page, set up a bump pointer area, and
|
|
|
|
// perform the allocation in a black area.
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(10, AllocationType::kOld);
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
// Allocate the fixed array that will be trimmed later.
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
isolate->factory()->NewFixedArray(100, AllocationType::kOld);
|
2016-08-09 10:50:28 +00:00
|
|
|
Address start_address = array->address();
|
|
|
|
Address end_address = start_address + array->Size();
|
|
|
|
Page* page = Page::FromAddress(start_address);
|
2019-02-22 17:34:05 +00:00
|
|
|
IncrementalMarking::NonAtomicMarkingState* marking_state =
|
|
|
|
marking->non_atomic_marking_state();
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(*array));
|
|
|
|
CHECK(marking_state->bitmap(page)->AllBitsSetInRange(
|
2016-08-09 10:50:28 +00:00
|
|
|
page->AddressToMarkbitIndex(start_address),
|
|
|
|
page->AddressToMarkbitIndex(end_address)));
|
|
|
|
CHECK(heap->old_space()->Contains(*array));
|
|
|
|
|
2018-11-25 02:24:43 +00:00
|
|
|
FixedArrayBase previous = *array;
|
|
|
|
FixedArrayBase trimmed;
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
// First trim in one word steps.
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
trimmed = heap->LeftTrimFixedArray(previous, 1);
|
2019-05-23 07:47:44 +00:00
|
|
|
HeapObject filler = HeapObject::FromAddress(previous.address());
|
|
|
|
CHECK(filler.IsFiller());
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(trimmed));
|
|
|
|
CHECK(marking_state->IsBlack(previous));
|
2016-08-09 10:50:28 +00:00
|
|
|
previous = trimmed;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Then trim in two and three word steps.
|
|
|
|
for (int i = 2; i <= 3; i++) {
|
|
|
|
for (int j = 0; j < 10; j++) {
|
|
|
|
trimmed = heap->LeftTrimFixedArray(previous, i);
|
2019-05-23 07:47:44 +00:00
|
|
|
HeapObject filler = HeapObject::FromAddress(previous.address());
|
|
|
|
CHECK(filler.IsFiller());
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(trimmed));
|
|
|
|
CHECK(marking_state->IsBlack(previous));
|
2016-08-09 10:50:28 +00:00
|
|
|
previous = trimmed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
}
|
|
|
|
|
2018-05-29 13:06:17 +00:00
|
|
|
TEST(ContinuousRightTrimFixedArrayInBlackArea) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-08-09 10:50:28 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
2018-05-29 13:06:17 +00:00
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
i::IncrementalMarking* marking = heap->incremental_marking();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking() || marking->IsStopped());
|
|
|
|
if (marking->IsStopped()) {
|
2016-09-07 10:02:58 +00:00
|
|
|
heap->StartIncrementalMarking(i::Heap::kNoGCFlags,
|
|
|
|
i::GarbageCollectionReason::kTesting);
|
2016-08-09 10:50:28 +00:00
|
|
|
}
|
|
|
|
CHECK(marking->IsMarking());
|
|
|
|
marking->StartBlackAllocationForTesting();
|
|
|
|
|
|
|
|
// Ensure that we allocate a new page, set up a bump pointer area, and
|
|
|
|
// perform the allocation in a black area.
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(10, AllocationType::kOld);
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
// Allocate the fixed array that will be trimmed later.
|
2018-05-29 13:06:17 +00:00
|
|
|
Handle<FixedArray> array =
|
2019-03-11 19:04:02 +00:00
|
|
|
CcTest::i_isolate()->factory()->NewFixedArray(100, AllocationType::kOld);
|
2016-08-09 10:50:28 +00:00
|
|
|
Address start_address = array->address();
|
|
|
|
Address end_address = start_address + array->Size();
|
|
|
|
Page* page = Page::FromAddress(start_address);
|
2019-02-22 17:34:05 +00:00
|
|
|
IncrementalMarking::NonAtomicMarkingState* marking_state =
|
|
|
|
marking->non_atomic_marking_state();
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsBlack(*array));
|
2017-03-24 18:54:04 +00:00
|
|
|
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->bitmap(page)->AllBitsSetInRange(
|
2016-08-09 10:50:28 +00:00
|
|
|
page->AddressToMarkbitIndex(start_address),
|
|
|
|
page->AddressToMarkbitIndex(end_address)));
|
|
|
|
CHECK(heap->old_space()->Contains(*array));
|
|
|
|
|
|
|
|
// Trim it once by one word to make checking for white marking color uniform.
|
2018-12-19 19:10:21 +00:00
|
|
|
Address previous = end_address - kTaggedSize;
|
2018-05-29 13:06:17 +00:00
|
|
|
isolate->heap()->RightTrimFixedArray(*array, 1);
|
|
|
|
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject filler = HeapObject::FromAddress(previous);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(filler.IsFiller());
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsImpossible(filler));
|
2016-08-09 10:50:28 +00:00
|
|
|
|
|
|
|
// Trim 10 times by one, two, and three word.
|
|
|
|
for (int i = 1; i <= 3; i++) {
|
|
|
|
for (int j = 0; j < 10; j++) {
|
2018-12-19 19:10:21 +00:00
|
|
|
previous -= kTaggedSize * i;
|
2018-05-29 13:06:17 +00:00
|
|
|
isolate->heap()->RightTrimFixedArray(*array, i);
|
2018-12-20 15:47:47 +00:00
|
|
|
HeapObject filler = HeapObject::FromAddress(previous);
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(filler.IsFiller());
|
2017-08-10 16:54:55 +00:00
|
|
|
CHECK(marking_state->IsWhite(filler));
|
2016-08-09 10:50:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
heap::GcAndSweep(heap, OLD_SPACE);
|
|
|
|
}
|
|
|
|
|
2016-06-10 13:17:10 +00:00
|
|
|
TEST(Regress618958) {
|
2017-05-29 11:06:13 +00:00
|
|
|
if (!FLAG_incremental_marking) return;
|
2016-06-10 13:17:10 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
bool isolate_is_locked = true;
|
2018-08-10 11:26:23 +00:00
|
|
|
CcTest::isolate()->AdjustAmountOfExternalAllocatedMemory(100 * MB);
|
2016-06-10 13:17:10 +00:00
|
|
|
int mark_sweep_count_before = heap->ms_count();
|
|
|
|
heap->MemoryPressureNotification(MemoryPressureLevel::kCritical,
|
|
|
|
isolate_is_locked);
|
|
|
|
int mark_sweep_count_after = heap->ms_count();
|
|
|
|
int mark_sweeps_performed = mark_sweep_count_after - mark_sweep_count_before;
|
|
|
|
// The memory pressuer handler either performed two GCs or performed one and
|
|
|
|
// started incremental marking.
|
|
|
|
CHECK(mark_sweeps_performed == 2 ||
|
|
|
|
(mark_sweeps_performed == 1 &&
|
|
|
|
!heap->incremental_marking()->IsStopped()));
|
|
|
|
}
|
|
|
|
|
2018-11-22 15:55:28 +00:00
|
|
|
TEST(YoungGenerationLargeObjectAllocationScavenge) {
|
2018-09-26 11:56:16 +00:00
|
|
|
if (FLAG_minor_mc) return;
|
2018-07-02 10:15:19 +00:00
|
|
|
FLAG_young_generation_large_objects = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
2018-11-21 15:50:50 +00:00
|
|
|
if (!isolate->serializer_enabled()) return;
|
2018-07-02 10:15:19 +00:00
|
|
|
|
2018-11-26 10:57:00 +00:00
|
|
|
// TODO(hpayer): Update the test as soon as we have a tenure limit for LO.
|
|
|
|
Handle<FixedArray> array_small = isolate->factory()->NewFixedArray(200000);
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*array_small);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK_EQ(NEW_LO_SPACE, chunk->owner_identity());
|
2019-01-28 13:13:10 +00:00
|
|
|
CHECK(chunk->IsFlagSet(MemoryChunk::LARGE_PAGE));
|
|
|
|
CHECK(chunk->IsFlagSet(MemoryChunk::TO_PAGE));
|
2018-09-26 11:56:16 +00:00
|
|
|
|
|
|
|
Handle<Object> number = isolate->factory()->NewHeapNumber(123.456);
|
|
|
|
array_small->set(0, *number);
|
|
|
|
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
|
|
|
|
// After the first young generation GC array_small will be in the old
|
|
|
|
// generation large object space.
|
2019-01-15 00:23:43 +00:00
|
|
|
chunk = MemoryChunk::FromHeapObject(*array_small);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK_EQ(LO_SPACE, chunk->owner_identity());
|
2019-01-28 13:13:10 +00:00
|
|
|
CHECK(!chunk->InYoungGeneration());
|
2018-09-26 11:56:16 +00:00
|
|
|
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2018-07-02 10:15:19 +00:00
|
|
|
}
|
|
|
|
|
2018-11-22 15:55:28 +00:00
|
|
|
TEST(YoungGenerationLargeObjectAllocationMarkCompact) {
|
|
|
|
if (FLAG_minor_mc) return;
|
|
|
|
FLAG_young_generation_large_objects = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
2018-11-26 10:57:00 +00:00
|
|
|
if (!isolate->serializer_enabled()) return;
|
2018-11-22 15:55:28 +00:00
|
|
|
|
2018-11-26 10:57:00 +00:00
|
|
|
// TODO(hpayer): Update the test as soon as we have a tenure limit for LO.
|
|
|
|
Handle<FixedArray> array_small = isolate->factory()->NewFixedArray(200000);
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*array_small);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK_EQ(NEW_LO_SPACE, chunk->owner_identity());
|
2019-01-28 13:13:10 +00:00
|
|
|
CHECK(chunk->IsFlagSet(MemoryChunk::LARGE_PAGE));
|
|
|
|
CHECK(chunk->IsFlagSet(MemoryChunk::TO_PAGE));
|
2018-11-22 15:55:28 +00:00
|
|
|
|
|
|
|
Handle<Object> number = isolate->factory()->NewHeapNumber(123.456);
|
|
|
|
array_small->set(0, *number);
|
|
|
|
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
|
|
|
|
|
|
|
// After the first full GC array_small will be in the old generation
|
|
|
|
// large object space.
|
2019-01-15 00:23:43 +00:00
|
|
|
chunk = MemoryChunk::FromHeapObject(*array_small);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK_EQ(LO_SPACE, chunk->owner_identity());
|
2019-01-28 13:13:10 +00:00
|
|
|
CHECK(!chunk->InYoungGeneration());
|
2018-11-22 15:55:28 +00:00
|
|
|
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
|
|
|
}
|
|
|
|
|
2018-11-26 18:51:53 +00:00
|
|
|
TEST(YoungGenerationLargeObjectAllocationReleaseScavenger) {
|
|
|
|
if (FLAG_minor_mc) return;
|
|
|
|
FLAG_young_generation_large_objects = true;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
if (!isolate->serializer_enabled()) return;
|
|
|
|
|
|
|
|
{
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
for (int i = 0; i < 10; i++) {
|
|
|
|
Handle<FixedArray> array_small = isolate->factory()->NewFixedArray(20000);
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*array_small);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK_EQ(NEW_LO_SPACE, chunk->owner_identity());
|
2019-01-28 13:13:10 +00:00
|
|
|
CHECK(chunk->IsFlagSet(MemoryChunk::TO_PAGE));
|
2018-11-26 18:51:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CHECK(isolate->heap()->new_lo_space()->IsEmpty());
|
|
|
|
CHECK_EQ(0, isolate->heap()->new_lo_space()->Size());
|
|
|
|
CHECK_EQ(0, isolate->heap()->new_lo_space()->SizeOfObjects());
|
|
|
|
CHECK(isolate->heap()->lo_space()->IsEmpty());
|
|
|
|
CHECK_EQ(0, isolate->heap()->lo_space()->Size());
|
|
|
|
CHECK_EQ(0, isolate->heap()->lo_space()->SizeOfObjects());
|
|
|
|
}
|
|
|
|
|
2016-06-29 09:36:57 +00:00
|
|
|
TEST(UncommitUnusedLargeObjectMemory) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> array =
|
|
|
|
isolate->factory()->NewFixedArray(200000, AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*array);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK(chunk->owner_identity() == LO_SPACE);
|
2016-06-29 09:36:57 +00:00
|
|
|
|
|
|
|
intptr_t size_before = array->Size();
|
|
|
|
size_t committed_memory_before = chunk->CommittedPhysicalMemory();
|
|
|
|
|
2018-07-10 12:58:11 +00:00
|
|
|
array->Shrink(isolate, 1);
|
2016-06-29 09:36:57 +00:00
|
|
|
CHECK(array->Size() < size_before);
|
|
|
|
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-06-29 09:36:57 +00:00
|
|
|
CHECK(chunk->CommittedPhysicalMemory() < committed_memory_before);
|
2017-12-15 17:59:57 +00:00
|
|
|
size_t shrinked_size = RoundUp(
|
|
|
|
(array->address() - chunk->address()) + array->Size(), CommitPageSize());
|
2016-06-29 09:36:57 +00:00
|
|
|
CHECK_EQ(shrinked_size, chunk->CommittedPhysicalMemory());
|
|
|
|
}
|
2016-06-30 15:00:54 +00:00
|
|
|
|
|
|
|
TEST(RememberedSetRemoveRange) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Handle<FixedArray> array = isolate->factory()->NewFixedArray(
|
|
|
|
Page::kPageSize / kTaggedSize, AllocationType::kOld);
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*array);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK(chunk->owner_identity() == LO_SPACE);
|
2016-06-30 15:00:54 +00:00
|
|
|
Address start = array->address();
|
|
|
|
// Maps slot to boolean indicator of whether the slot should be in the set.
|
|
|
|
std::map<Address, bool> slots;
|
|
|
|
slots[start + 0] = true;
|
2018-12-19 19:10:21 +00:00
|
|
|
slots[start + kTaggedSize] = true;
|
|
|
|
slots[start + Page::kPageSize - kTaggedSize] = true;
|
2016-06-30 15:00:54 +00:00
|
|
|
slots[start + Page::kPageSize] = true;
|
2018-12-19 19:10:21 +00:00
|
|
|
slots[start + Page::kPageSize + kTaggedSize] = true;
|
|
|
|
slots[chunk->area_end() - kTaggedSize] = true;
|
2016-06-30 15:00:54 +00:00
|
|
|
|
|
|
|
for (auto x : slots) {
|
|
|
|
RememberedSet<OLD_TO_NEW>::Insert(chunk, x.first);
|
|
|
|
}
|
|
|
|
|
2017-07-18 12:53:39 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::Iterate(chunk,
|
2018-10-23 23:02:20 +00:00
|
|
|
[&slots](MaybeObjectSlot slot) {
|
|
|
|
CHECK(slots[slot.address()]);
|
2017-07-18 12:53:39 +00:00
|
|
|
return KEEP_SLOT;
|
|
|
|
},
|
|
|
|
SlotSet::PREFREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
|
2018-12-19 19:10:21 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::RemoveRange(chunk, start, start + kTaggedSize,
|
2016-10-07 09:15:45 +00:00
|
|
|
SlotSet::FREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
slots[start] = false;
|
2017-07-18 12:53:39 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::Iterate(chunk,
|
2018-10-23 23:02:20 +00:00
|
|
|
[&slots](MaybeObjectSlot slot) {
|
|
|
|
CHECK(slots[slot.address()]);
|
2017-07-18 12:53:39 +00:00
|
|
|
return KEEP_SLOT;
|
|
|
|
},
|
|
|
|
SlotSet::PREFREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
|
2018-12-19 19:10:21 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::RemoveRange(chunk, start + kTaggedSize,
|
2016-10-07 09:15:45 +00:00
|
|
|
start + Page::kPageSize,
|
|
|
|
SlotSet::FREE_EMPTY_BUCKETS);
|
2018-12-19 19:10:21 +00:00
|
|
|
slots[start + kTaggedSize] = false;
|
|
|
|
slots[start + Page::kPageSize - kTaggedSize] = false;
|
2017-07-18 12:53:39 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::Iterate(chunk,
|
2018-10-23 23:02:20 +00:00
|
|
|
[&slots](MaybeObjectSlot slot) {
|
|
|
|
CHECK(slots[slot.address()]);
|
2017-07-18 12:53:39 +00:00
|
|
|
return KEEP_SLOT;
|
|
|
|
},
|
|
|
|
SlotSet::PREFREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
|
2016-10-07 09:15:45 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::RemoveRange(chunk, start,
|
2018-12-19 19:10:21 +00:00
|
|
|
start + Page::kPageSize + kTaggedSize,
|
2016-10-07 09:15:45 +00:00
|
|
|
SlotSet::FREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
slots[start + Page::kPageSize] = false;
|
2017-07-18 12:53:39 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::Iterate(chunk,
|
2018-10-23 23:02:20 +00:00
|
|
|
[&slots](MaybeObjectSlot slot) {
|
|
|
|
CHECK(slots[slot.address()]);
|
2017-07-18 12:53:39 +00:00
|
|
|
return KEEP_SLOT;
|
|
|
|
},
|
|
|
|
SlotSet::PREFREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
|
2018-12-19 19:10:21 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::RemoveRange(chunk, chunk->area_end() - kTaggedSize,
|
|
|
|
chunk->area_end(),
|
|
|
|
SlotSet::FREE_EMPTY_BUCKETS);
|
|
|
|
slots[chunk->area_end() - kTaggedSize] = false;
|
2017-07-18 12:53:39 +00:00
|
|
|
RememberedSet<OLD_TO_NEW>::Iterate(chunk,
|
2018-10-23 23:02:20 +00:00
|
|
|
[&slots](MaybeObjectSlot slot) {
|
|
|
|
CHECK(slots[slot.address()]);
|
2017-07-18 12:53:39 +00:00
|
|
|
return KEEP_SLOT;
|
|
|
|
},
|
|
|
|
SlotSet::PREFREE_EMPTY_BUCKETS);
|
2016-06-30 15:00:54 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 14:06:10 +00:00
|
|
|
HEAP_TEST(Regress670675) {
|
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-05-29 11:06:13 +00:00
|
|
|
FLAG_stress_incremental_marking = false;
|
2016-12-06 14:06:10 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
i::MarkCompactCollector* collector = heap->mark_compact_collector();
|
2017-04-26 22:16:41 +00:00
|
|
|
CcTest::CollectAllGarbage();
|
2016-12-06 14:06:10 +00:00
|
|
|
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
|
|
|
i::IncrementalMarking* marking = CcTest::heap()->incremental_marking();
|
|
|
|
if (marking->IsStopped()) {
|
|
|
|
marking->Start(i::GarbageCollectionReason::kTesting);
|
|
|
|
}
|
2019-02-18 08:58:18 +00:00
|
|
|
size_t array_length = 128 * KB;
|
2016-12-06 14:06:10 +00:00
|
|
|
size_t n = heap->OldGenerationSpaceAvailable() / array_length;
|
2016-12-13 10:25:33 +00:00
|
|
|
for (size_t i = 0; i < n + 40; i++) {
|
2016-12-06 14:06:10 +00:00
|
|
|
{
|
|
|
|
HandleScope inner_scope(isolate);
|
2018-11-30 14:07:24 +00:00
|
|
|
isolate->factory()->NewFixedArray(static_cast<int>(array_length),
|
2019-03-11 19:04:02 +00:00
|
|
|
AllocationType::kOld);
|
2016-12-06 14:06:10 +00:00
|
|
|
}
|
|
|
|
if (marking->IsStopped()) break;
|
|
|
|
double deadline = heap->MonotonicallyIncreasingTimeInMs() + 1;
|
2019-02-07 10:58:09 +00:00
|
|
|
marking->AdvanceWithDeadline(
|
2017-10-11 13:58:19 +00:00
|
|
|
deadline, IncrementalMarking::GC_VIA_STACK_GUARD, StepOrigin::kV8);
|
2016-12-06 14:06:10 +00:00
|
|
|
}
|
|
|
|
DCHECK(marking->IsStopped());
|
|
|
|
}
|
|
|
|
|
2017-08-09 15:56:12 +00:00
|
|
|
namespace {
|
|
|
|
Handle<Code> GenerateDummyImmovableCode(Isolate* isolate) {
|
2019-01-16 18:29:52 +00:00
|
|
|
Assembler assm(AssemblerOptions{});
|
2017-08-09 15:56:12 +00:00
|
|
|
|
|
|
|
const int kNumberOfNops = 1 << 10;
|
|
|
|
for (int i = 0; i < kNumberOfNops; i++) {
|
|
|
|
assm.nop(); // supported on all architectures
|
|
|
|
}
|
|
|
|
|
|
|
|
CodeDesc desc;
|
|
|
|
assm.GetCode(isolate, &desc);
|
2019-04-29 16:15:47 +00:00
|
|
|
Handle<Code> code =
|
|
|
|
Factory::CodeBuilder(isolate, desc, Code::STUB).set_immovable().Build();
|
2017-08-09 15:56:12 +00:00
|
|
|
CHECK(code->IsCode());
|
|
|
|
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
} // namespace
|
|
|
|
|
2017-01-17 14:19:58 +00:00
|
|
|
HEAP_TEST(Regress5831) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
2017-08-09 15:56:12 +00:00
|
|
|
// Used to ensure that the generated code is not collected.
|
|
|
|
const int kInitialSize = 32;
|
|
|
|
Handle<FixedArray> array = isolate->factory()->NewFixedArray(kInitialSize);
|
|
|
|
|
|
|
|
// Ensure that all immovable code space pages are full and we overflow into
|
|
|
|
// LO_SPACE.
|
|
|
|
const int kMaxIterations = 1 << 16;
|
|
|
|
bool overflowed_into_lospace = false;
|
|
|
|
for (int i = 0; i < kMaxIterations; i++) {
|
|
|
|
Handle<Code> code = GenerateDummyImmovableCode(isolate);
|
2018-07-10 12:58:11 +00:00
|
|
|
array = FixedArray::SetAndGrow(isolate, array, i, code);
|
2017-08-09 15:56:12 +00:00
|
|
|
CHECK(heap->code_space()->Contains(code->address()) ||
|
2018-11-21 19:19:02 +00:00
|
|
|
heap->code_lo_space()->Contains(*code));
|
|
|
|
if (heap->code_lo_space()->Contains(*code)) {
|
2017-08-09 15:56:12 +00:00
|
|
|
overflowed_into_lospace = true;
|
|
|
|
break;
|
2017-01-17 14:19:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-09 15:56:12 +00:00
|
|
|
CHECK(overflowed_into_lospace);
|
2017-01-17 14:19:58 +00:00
|
|
|
|
|
|
|
// Fake a serializer run.
|
|
|
|
isolate->serializer_enabled_ = true;
|
|
|
|
|
|
|
|
// Generate the code.
|
2017-08-09 15:56:12 +00:00
|
|
|
Handle<Code> code = GenerateDummyImmovableCode(isolate);
|
2017-09-19 13:08:15 +00:00
|
|
|
CHECK_GE(i::kMaxRegularHeapObjectSize, code->Size());
|
2018-05-22 16:58:12 +00:00
|
|
|
CHECK(!heap->code_space()->first_page()->Contains(code->address()));
|
2017-01-17 14:19:58 +00:00
|
|
|
|
|
|
|
// Ensure it's not in large object space.
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk* chunk = MemoryChunk::FromHeapObject(*code);
|
2019-06-04 10:53:21 +00:00
|
|
|
CHECK(chunk->owner_identity() != LO_SPACE);
|
2017-01-17 14:19:58 +00:00
|
|
|
CHECK(chunk->NeverEvacuate());
|
|
|
|
}
|
|
|
|
|
2017-09-15 12:41:19 +00:00
|
|
|
TEST(Regress6800) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
const int kRootLength = 1000;
|
|
|
|
Handle<FixedArray> root =
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(kRootLength, AllocationType::kOld);
|
2017-09-15 12:41:19 +00:00
|
|
|
{
|
|
|
|
HandleScope inner_scope(isolate);
|
|
|
|
Handle<FixedArray> new_space_array = isolate->factory()->NewFixedArray(1);
|
|
|
|
for (int i = 0; i < kRootLength; i++) {
|
|
|
|
root->set(i, *new_space_array);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < kRootLength; i++) {
|
2018-07-04 09:10:05 +00:00
|
|
|
root->set(i, ReadOnlyRoots(CcTest::heap()).undefined_value());
|
2017-09-15 12:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CHECK_EQ(0, RememberedSet<OLD_TO_NEW>::NumberOfPreFreedEmptyBuckets(
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk::FromHeapObject(*root)));
|
2017-09-15 12:41:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(Regress6800LargeObject) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
2018-12-19 19:10:21 +00:00
|
|
|
const int kRootLength = i::kMaxRegularHeapObjectSize / kTaggedSize;
|
2017-09-15 12:41:19 +00:00
|
|
|
Handle<FixedArray> root =
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(kRootLength, AllocationType::kOld);
|
2017-09-15 12:41:19 +00:00
|
|
|
CcTest::heap()->lo_space()->Contains(*root);
|
|
|
|
{
|
|
|
|
HandleScope inner_scope(isolate);
|
|
|
|
Handle<FixedArray> new_space_array = isolate->factory()->NewFixedArray(1);
|
|
|
|
for (int i = 0; i < kRootLength; i++) {
|
|
|
|
root->set(i, *new_space_array);
|
|
|
|
}
|
|
|
|
for (int i = 0; i < kRootLength; i++) {
|
2018-07-04 09:10:05 +00:00
|
|
|
root->set(i, ReadOnlyRoots(CcTest::heap()).undefined_value());
|
2017-09-15 12:41:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
|
|
|
CHECK_EQ(0, RememberedSet<OLD_TO_NEW>::NumberOfPreFreedEmptyBuckets(
|
2019-01-15 00:23:43 +00:00
|
|
|
MemoryChunk::FromHeapObject(*root)));
|
2017-09-15 12:41:19 +00:00
|
|
|
}
|
|
|
|
|
2017-05-29 15:03:50 +00:00
|
|
|
HEAP_TEST(RegressMissingWriteBarrierInAllocate) {
|
|
|
|
if (!FLAG_incremental_marking) return;
|
2017-08-23 15:15:27 +00:00
|
|
|
ManualGCScope manual_gc_scope;
|
2017-05-29 15:03:50 +00:00
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
Isolate* isolate = heap->isolate();
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
2018-04-09 19:11:22 +00:00
|
|
|
Handle<Map> map;
|
2017-05-29 15:03:50 +00:00
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
2018-04-09 19:11:22 +00:00
|
|
|
map = isolate->factory()->NewMap(HEAP_NUMBER_TYPE, HeapNumber::kSize);
|
2017-05-29 15:03:50 +00:00
|
|
|
}
|
|
|
|
heap->incremental_marking()->StartBlackAllocationForTesting();
|
|
|
|
Handle<HeapObject> object;
|
|
|
|
{
|
|
|
|
AlwaysAllocateScope always_allocate(isolate);
|
2019-03-11 19:04:02 +00:00
|
|
|
object = handle(isolate->factory()->NewForTest(map, AllocationType::kOld),
|
|
|
|
isolate);
|
2017-05-29 15:03:50 +00:00
|
|
|
}
|
2018-04-09 19:11:22 +00:00
|
|
|
// The object is black. If Factory::New sets the map without write-barrier,
|
2017-05-29 15:03:50 +00:00
|
|
|
// then the map is white and will be freed prematurely.
|
|
|
|
heap::SimulateIncrementalMarking(heap, true);
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
MarkCompactCollector* collector = heap->mark_compact_collector();
|
|
|
|
if (collector->sweeping_in_progress()) {
|
|
|
|
collector->EnsureSweepingCompleted();
|
|
|
|
}
|
2019-05-23 07:47:44 +00:00
|
|
|
CHECK(object->map().IsMap());
|
2017-05-29 15:03:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-19 16:03:41 +00:00
|
|
|
HEAP_TEST(MarkCompactEpochCounter) {
|
|
|
|
ManualGCScope manual_gc_scope;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
v8::HandleScope scope(CcTest::isolate());
|
|
|
|
Heap* heap = CcTest::heap();
|
2019-07-08 15:36:05 +00:00
|
|
|
unsigned epoch0 = heap->mark_compact_collector()->epoch();
|
2018-12-19 16:03:41 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2019-07-08 15:36:05 +00:00
|
|
|
unsigned epoch1 = heap->mark_compact_collector()->epoch();
|
2018-12-19 16:03:41 +00:00
|
|
|
CHECK_EQ(epoch0 + 1, epoch1);
|
|
|
|
heap::SimulateIncrementalMarking(heap, true);
|
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2019-07-08 15:36:05 +00:00
|
|
|
unsigned epoch2 = heap->mark_compact_collector()->epoch();
|
2018-12-19 16:03:41 +00:00
|
|
|
CHECK_EQ(epoch1 + 1, epoch2);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2019-07-08 15:36:05 +00:00
|
|
|
unsigned epoch3 = heap->mark_compact_collector()->epoch();
|
2018-12-19 16:03:41 +00:00
|
|
|
CHECK_EQ(epoch2, epoch3);
|
|
|
|
}
|
|
|
|
|
2017-07-18 07:59:59 +00:00
|
|
|
UNINITIALIZED_TEST(ReinitializeStringHashSeed) {
|
|
|
|
// Enable rehashing and create an isolate and context.
|
|
|
|
i::FLAG_rehash_snapshot = true;
|
|
|
|
for (int i = 1; i < 3; i++) {
|
|
|
|
i::FLAG_hash_seed = 1337 * i;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
{
|
|
|
|
v8::Isolate::Scope isolate_scope(isolate);
|
2018-07-16 09:52:50 +00:00
|
|
|
CHECK_EQ(static_cast<uint64_t>(1337 * i),
|
2019-02-14 21:10:30 +00:00
|
|
|
HashSeed(reinterpret_cast<i::Isolate*>(isolate)));
|
2017-07-18 07:59:59 +00:00
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
v8::Local<v8::Context> context = v8::Context::New(isolate);
|
|
|
|
CHECK(!context.IsEmpty());
|
|
|
|
v8::Context::Scope context_scope(context);
|
|
|
|
}
|
|
|
|
isolate->Dispose();
|
2019-05-14 17:23:02 +00:00
|
|
|
ReadOnlyHeap::ClearSharedHeapForTest();
|
2017-07-18 07:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-22 12:44:38 +00:00
|
|
|
const int kHeapLimit = 100 * MB;
|
|
|
|
Isolate* oom_isolate = nullptr;
|
|
|
|
|
|
|
|
void OOMCallback(const char* location, bool is_heap_oom) {
|
|
|
|
Heap* heap = oom_isolate->heap();
|
|
|
|
size_t kSlack = heap->new_space()->Capacity();
|
|
|
|
CHECK_LE(heap->OldGenerationCapacity(), kHeapLimit + kSlack);
|
|
|
|
CHECK_LE(heap->memory_allocator()->Size(), heap->MaxReserved() + kSlack);
|
|
|
|
base::OS::ExitProcess(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(OutOfMemory) {
|
2018-03-23 20:19:37 +00:00
|
|
|
if (FLAG_stress_incremental_marking) return;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) return;
|
|
|
|
#endif
|
2018-03-22 12:44:38 +00:00
|
|
|
FLAG_max_old_space_size = kHeapLimit / MB;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
oom_isolate = i_isolate;
|
|
|
|
isolate->SetOOMErrorHandler(OOMCallback);
|
|
|
|
{
|
|
|
|
Factory* factory = i_isolate->factory();
|
|
|
|
HandleScope handle_scope(i_isolate);
|
|
|
|
while (true) {
|
|
|
|
factory->NewFixedArray(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-28 16:58:31 +00:00
|
|
|
UNINITIALIZED_TEST(OutOfMemoryIneffectiveGC) {
|
|
|
|
if (!FLAG_detect_ineffective_gcs_near_heap_limit) return;
|
|
|
|
if (FLAG_stress_incremental_marking) return;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) return;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FLAG_max_old_space_size = kHeapLimit / MB;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
v8::Isolate* isolate = v8::Isolate::New(create_params);
|
|
|
|
Isolate* i_isolate = reinterpret_cast<Isolate*>(isolate);
|
|
|
|
oom_isolate = i_isolate;
|
|
|
|
isolate->SetOOMErrorHandler(OOMCallback);
|
|
|
|
Factory* factory = i_isolate->factory();
|
|
|
|
Heap* heap = i_isolate->heap();
|
|
|
|
heap->CollectAllGarbage(Heap::kNoGCFlags, GarbageCollectionReason::kTesting);
|
|
|
|
{
|
|
|
|
HandleScope scope(i_isolate);
|
2018-05-04 09:35:59 +00:00
|
|
|
while (heap->OldGenerationSizeOfObjects() <
|
2018-03-28 16:58:31 +00:00
|
|
|
heap->MaxOldGenerationSize() * 0.9) {
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewFixedArray(100, AllocationType::kOld);
|
2018-03-28 16:58:31 +00:00
|
|
|
}
|
|
|
|
{
|
|
|
|
int initial_ms_count = heap->ms_count();
|
2018-04-05 10:49:38 +00:00
|
|
|
int ineffective_ms_start = initial_ms_count;
|
2018-03-28 16:58:31 +00:00
|
|
|
while (heap->ms_count() < initial_ms_count + 10) {
|
|
|
|
HandleScope inner_scope(i_isolate);
|
2019-03-11 19:04:02 +00:00
|
|
|
factory->NewFixedArray(30000, AllocationType::kOld);
|
2018-04-10 13:27:23 +00:00
|
|
|
if (heap->tracer()->AverageMarkCompactMutatorUtilization() >= 0.3) {
|
2018-04-05 10:49:38 +00:00
|
|
|
ineffective_ms_start = heap->ms_count() + 1;
|
|
|
|
}
|
2018-03-28 16:58:31 +00:00
|
|
|
}
|
2018-04-05 10:49:38 +00:00
|
|
|
int consecutive_ineffective_ms = heap->ms_count() - ineffective_ms_start;
|
|
|
|
CHECK_IMPLIES(
|
|
|
|
consecutive_ineffective_ms >= 4,
|
|
|
|
heap->tracer()->AverageMarkCompactMutatorUtilization() >= 0.3);
|
2018-03-28 16:58:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
isolate->Dispose();
|
|
|
|
}
|
|
|
|
|
2017-11-02 20:19:04 +00:00
|
|
|
HEAP_TEST(Regress779503) {
|
|
|
|
// The following regression test ensures that the Scavenger does not allocate
|
|
|
|
// over invalid slots. More specific, the Scavenger should not sweep a page
|
|
|
|
// that it currently processes because it might allocate over the currently
|
|
|
|
// processed slot.
|
|
|
|
const int kArraySize = 2048;
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = CcTest::heap();
|
|
|
|
heap::SealCurrentObjects(heap);
|
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
// The byte array filled with kHeapObjectTag ensures that we cannot read
|
|
|
|
// from the slot again and interpret it as heap value. Doing so will crash.
|
|
|
|
Handle<ByteArray> byte_array = isolate->factory()->NewByteArray(kArraySize);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*byte_array));
|
2017-11-02 20:19:04 +00:00
|
|
|
for (int i = 0; i < kArraySize; i++) {
|
|
|
|
byte_array->set(i, kHeapObjectTag);
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
// The FixedArray in old space serves as space for slots.
|
|
|
|
Handle<FixedArray> fixed_array =
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(kArraySize, AllocationType::kOld);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(!Heap::InYoungGeneration(*fixed_array));
|
2017-11-02 20:19:04 +00:00
|
|
|
for (int i = 0; i < kArraySize; i++) {
|
|
|
|
fixed_array->set(i, *byte_array);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Delay sweeper tasks to allow the scavenger to sweep the page it is
|
|
|
|
// currently scavenging.
|
2018-07-10 08:07:58 +00:00
|
|
|
heap->delay_sweeper_tasks_for_testing_ = true;
|
2017-11-02 20:19:04 +00:00
|
|
|
CcTest::CollectGarbage(OLD_SPACE);
|
2019-02-11 15:07:56 +00:00
|
|
|
CHECK(Heap::InYoungGeneration(*byte_array));
|
2017-11-02 20:19:04 +00:00
|
|
|
}
|
|
|
|
// Scavenging and sweeping the same page will crash as slots will be
|
|
|
|
// overridden.
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
2018-07-10 08:07:58 +00:00
|
|
|
heap->delay_sweeper_tasks_for_testing_ = false;
|
2017-11-02 20:19:04 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 20:19:37 +00:00
|
|
|
struct OutOfMemoryState {
|
|
|
|
Heap* heap;
|
|
|
|
bool oom_triggered;
|
|
|
|
size_t old_generation_capacity_at_oom;
|
|
|
|
size_t memory_allocator_size_at_oom;
|
2018-04-03 17:30:50 +00:00
|
|
|
size_t new_space_capacity_at_oom;
|
2019-02-11 14:01:02 +00:00
|
|
|
size_t new_lo_space_size_at_oom;
|
2019-01-15 17:11:25 +00:00
|
|
|
size_t current_heap_limit;
|
|
|
|
size_t initial_heap_limit;
|
2018-03-23 20:19:37 +00:00
|
|
|
};
|
|
|
|
|
2018-03-26 11:33:00 +00:00
|
|
|
size_t NearHeapLimitCallback(void* raw_state, size_t current_heap_limit,
|
|
|
|
size_t initial_heap_limit) {
|
2018-03-23 20:19:37 +00:00
|
|
|
OutOfMemoryState* state = static_cast<OutOfMemoryState*>(raw_state);
|
|
|
|
Heap* heap = state->heap;
|
|
|
|
state->oom_triggered = true;
|
|
|
|
state->old_generation_capacity_at_oom = heap->OldGenerationCapacity();
|
|
|
|
state->memory_allocator_size_at_oom = heap->memory_allocator()->Size();
|
2018-04-03 17:30:50 +00:00
|
|
|
state->new_space_capacity_at_oom = heap->new_space()->Capacity();
|
2019-02-11 14:01:02 +00:00
|
|
|
state->new_lo_space_size_at_oom = heap->new_lo_space()->Size();
|
2019-01-15 17:11:25 +00:00
|
|
|
state->current_heap_limit = current_heap_limit;
|
|
|
|
state->initial_heap_limit = initial_heap_limit;
|
2018-03-26 11:33:00 +00:00
|
|
|
return initial_heap_limit + 100 * MB;
|
2018-03-23 20:19:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t MemoryAllocatorSizeFromHeapCapacity(size_t capacity) {
|
|
|
|
// Size to capacity factor.
|
2018-10-23 11:52:20 +00:00
|
|
|
double factor =
|
|
|
|
Page::kPageSize * 1.0 / MemoryChunkLayout::AllocatableMemoryInDataPage();
|
2018-03-23 20:19:37 +00:00
|
|
|
// Some tables (e.g. deoptimization table) are allocated directly with the
|
|
|
|
// memory allocator. Allow some slack to account for them.
|
2018-10-11 13:04:34 +00:00
|
|
|
size_t slack = 5 * MB;
|
2018-03-23 20:19:37 +00:00
|
|
|
return static_cast<size_t>(capacity * factor) + slack;
|
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(OutOfMemorySmallObjects) {
|
|
|
|
if (FLAG_stress_incremental_marking) return;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) return;
|
|
|
|
#endif
|
|
|
|
const size_t kOldGenerationLimit = 300 * MB;
|
|
|
|
FLAG_max_old_space_size = kOldGenerationLimit / MB;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
Isolate* isolate =
|
|
|
|
reinterpret_cast<Isolate*>(v8::Isolate::New(create_params));
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
OutOfMemoryState state;
|
|
|
|
state.heap = heap;
|
|
|
|
state.oom_triggered = false;
|
2018-03-26 11:33:00 +00:00
|
|
|
heap->AddNearHeapLimitCallback(NearHeapLimitCallback, &state);
|
2018-03-23 20:19:37 +00:00
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
while (!state.oom_triggered) {
|
|
|
|
factory->NewFixedArray(100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_LE(state.old_generation_capacity_at_oom,
|
2018-04-03 17:30:50 +00:00
|
|
|
kOldGenerationLimit + state.new_space_capacity_at_oom);
|
2018-03-23 20:19:37 +00:00
|
|
|
CHECK_LE(kOldGenerationLimit, state.old_generation_capacity_at_oom +
|
2018-04-03 17:30:50 +00:00
|
|
|
state.new_space_capacity_at_oom);
|
2018-03-23 20:19:37 +00:00
|
|
|
CHECK_LE(
|
|
|
|
state.memory_allocator_size_at_oom,
|
|
|
|
MemoryAllocatorSizeFromHeapCapacity(state.old_generation_capacity_at_oom +
|
2018-04-03 17:30:50 +00:00
|
|
|
2 * state.new_space_capacity_at_oom));
|
2018-03-23 20:19:37 +00:00
|
|
|
reinterpret_cast<v8::Isolate*>(isolate)->Dispose();
|
|
|
|
}
|
|
|
|
|
|
|
|
UNINITIALIZED_TEST(OutOfMemoryLargeObjects) {
|
|
|
|
if (FLAG_stress_incremental_marking) return;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) return;
|
|
|
|
#endif
|
|
|
|
const size_t kOldGenerationLimit = 300 * MB;
|
|
|
|
FLAG_max_old_space_size = kOldGenerationLimit / MB;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
Isolate* isolate =
|
|
|
|
reinterpret_cast<Isolate*>(v8::Isolate::New(create_params));
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
OutOfMemoryState state;
|
|
|
|
state.heap = heap;
|
|
|
|
state.oom_triggered = false;
|
2018-03-26 11:33:00 +00:00
|
|
|
heap->AddNearHeapLimitCallback(NearHeapLimitCallback, &state);
|
2018-03-23 20:19:37 +00:00
|
|
|
const int kFixedArrayLength = 1000000;
|
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
while (!state.oom_triggered) {
|
|
|
|
factory->NewFixedArray(kFixedArrayLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_LE(state.old_generation_capacity_at_oom, kOldGenerationLimit);
|
2019-07-12 11:47:40 +00:00
|
|
|
CHECK_LE(kOldGenerationLimit, state.old_generation_capacity_at_oom +
|
|
|
|
state.new_space_capacity_at_oom +
|
2019-02-11 14:01:02 +00:00
|
|
|
state.new_lo_space_size_at_oom +
|
2018-03-23 20:19:37 +00:00
|
|
|
FixedArray::SizeFor(kFixedArrayLength));
|
|
|
|
CHECK_LE(
|
|
|
|
state.memory_allocator_size_at_oom,
|
|
|
|
MemoryAllocatorSizeFromHeapCapacity(state.old_generation_capacity_at_oom +
|
2019-02-11 14:01:02 +00:00
|
|
|
2 * state.new_space_capacity_at_oom +
|
|
|
|
state.new_lo_space_size_at_oom));
|
2018-03-23 20:19:37 +00:00
|
|
|
reinterpret_cast<v8::Isolate*>(isolate)->Dispose();
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:11:25 +00:00
|
|
|
UNINITIALIZED_TEST(RestoreHeapLimit) {
|
|
|
|
if (FLAG_stress_incremental_marking) return;
|
|
|
|
#ifdef VERIFY_HEAP
|
|
|
|
if (FLAG_verify_heap) return;
|
|
|
|
#endif
|
|
|
|
ManualGCScope manual_gc_scope;
|
|
|
|
const size_t kOldGenerationLimit = 300 * MB;
|
|
|
|
FLAG_max_old_space_size = kOldGenerationLimit / MB;
|
|
|
|
v8::Isolate::CreateParams create_params;
|
|
|
|
create_params.array_buffer_allocator = CcTest::array_buffer_allocator();
|
|
|
|
Isolate* isolate =
|
|
|
|
reinterpret_cast<Isolate*>(v8::Isolate::New(create_params));
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
OutOfMemoryState state;
|
|
|
|
state.heap = heap;
|
|
|
|
state.oom_triggered = false;
|
|
|
|
heap->AddNearHeapLimitCallback(NearHeapLimitCallback, &state);
|
|
|
|
heap->AutomaticallyRestoreInitialHeapLimit(0.5);
|
|
|
|
const int kFixedArrayLength = 1000000;
|
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
while (!state.oom_triggered) {
|
|
|
|
factory->NewFixedArray(kFixedArrayLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
heap->MemoryPressureNotification(MemoryPressureLevel::kCritical, true);
|
|
|
|
state.oom_triggered = false;
|
|
|
|
{
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
while (!state.oom_triggered) {
|
|
|
|
factory->NewFixedArray(kFixedArrayLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
CHECK_EQ(state.current_heap_limit, state.initial_heap_limit);
|
|
|
|
reinterpret_cast<v8::Isolate*>(isolate)->Dispose();
|
|
|
|
}
|
|
|
|
|
2018-05-22 16:03:55 +00:00
|
|
|
void HeapTester::UncommitFromSpace(Heap* heap) {
|
|
|
|
heap->UncommitFromSpace();
|
|
|
|
heap->memory_allocator()->unmapper()->EnsureUnmappingCompleted();
|
|
|
|
}
|
|
|
|
|
2018-08-09 09:08:20 +00:00
|
|
|
class DeleteNative {
|
|
|
|
public:
|
|
|
|
static void Deleter(void* arg) {
|
|
|
|
delete reinterpret_cast<DeleteNative*>(arg);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
TEST(Regress8014) {
|
|
|
|
Isolate* isolate = CcTest::InitIsolateOnce();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
{
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
for (int i = 0; i < 10000; i++) {
|
|
|
|
auto handle = Managed<DeleteNative>::FromRawPtr(isolate, 1000000,
|
|
|
|
new DeleteNative());
|
|
|
|
USE(handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int ms_count = heap->ms_count();
|
|
|
|
heap->MemoryPressureNotification(MemoryPressureLevel::kCritical, true);
|
|
|
|
// Several GCs can be triggred by the above call.
|
|
|
|
// The bad case triggers 10000 GCs.
|
|
|
|
CHECK_LE(heap->ms_count(), ms_count + 10);
|
|
|
|
}
|
|
|
|
|
2018-12-21 13:43:00 +00:00
|
|
|
TEST(Regress8617) {
|
|
|
|
ManualGCScope manual_gc_scope;
|
|
|
|
FLAG_manual_evacuation_candidates_selection = true;
|
|
|
|
LocalContext env;
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
heap::SimulateFullSpace(heap->old_space());
|
|
|
|
// Step 1. Create a function and ensure that it is in the old space.
|
|
|
|
Handle<Object> foo =
|
|
|
|
v8::Utils::OpenHandle(*CompileRun("function foo() { return 42; };"
|
|
|
|
"foo;"));
|
2019-02-11 15:07:56 +00:00
|
|
|
if (heap->InYoungGeneration(*foo)) {
|
2018-12-21 13:43:00 +00:00
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
}
|
|
|
|
// Step 2. Create an object with a reference to foo in the descriptor array.
|
|
|
|
CompileRun(
|
|
|
|
"var obj = {};"
|
|
|
|
"obj.method = foo;"
|
|
|
|
"obj;");
|
|
|
|
// Step 3. Make sure that foo moves during Mark-Compact.
|
2019-01-15 00:23:43 +00:00
|
|
|
Page* ec_page = Page::FromAddress(foo->ptr());
|
2018-12-21 13:43:00 +00:00
|
|
|
heap::ForceEvacuationCandidate(ec_page);
|
|
|
|
// Step 4. Start incremental marking.
|
|
|
|
heap::SimulateIncrementalMarking(heap, false);
|
|
|
|
CHECK(ec_page->IsEvacuationCandidate());
|
|
|
|
// Step 5. Install a new descriptor array on the map of the object.
|
|
|
|
// This runs the marking barrier for the descriptor array.
|
|
|
|
// In the bad case it sets the number of marked descriptors but does not
|
|
|
|
// change the color of the descriptor array.
|
|
|
|
CompileRun("obj.bar = 10;");
|
|
|
|
// Step 6. Promote the descriptor array to old space. During promotion
|
|
|
|
// the Scavenger will not record the slot of foo in the descriptor array.
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
CcTest::CollectGarbage(NEW_SPACE);
|
|
|
|
// Step 7. Complete the Mark-Compact.
|
|
|
|
CcTest::CollectAllGarbage();
|
|
|
|
// Step 8. Use the descriptor for foo, which contains a stale pointer.
|
|
|
|
CompileRun("obj.method()");
|
|
|
|
}
|
|
|
|
|
2019-01-22 10:06:28 +00:00
|
|
|
HEAP_TEST(MemoryReducerActivationForSmallHeaps) {
|
|
|
|
ManualGCScope manual_gc_scope;
|
|
|
|
LocalContext env;
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
CHECK_EQ(heap->memory_reducer()->state_.action, MemoryReducer::Action::kDone);
|
|
|
|
HandleScope scope(isolate);
|
|
|
|
const size_t kActivationThreshold = 1 * MB;
|
|
|
|
size_t initial_capacity = heap->OldGenerationCapacity();
|
|
|
|
while (heap->OldGenerationCapacity() <
|
|
|
|
initial_capacity + kActivationThreshold) {
|
2019-03-11 19:04:02 +00:00
|
|
|
isolate->factory()->NewFixedArray(1 * KB, AllocationType::kOld);
|
2019-01-22 10:06:28 +00:00
|
|
|
}
|
|
|
|
CHECK_EQ(heap->memory_reducer()->state_.action, MemoryReducer::Action::kWait);
|
|
|
|
}
|
|
|
|
|
2019-05-02 13:51:10 +00:00
|
|
|
TEST(CodeObjectRegistry) {
|
|
|
|
// We turn off compaction to ensure that code is not moving.
|
|
|
|
FLAG_never_compact = true;
|
|
|
|
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Heap* heap = isolate->heap();
|
|
|
|
|
|
|
|
Handle<Code> code1;
|
|
|
|
HandleScope outer_scope(heap->isolate());
|
|
|
|
Address code2_address;
|
|
|
|
{
|
|
|
|
code1 = DummyOptimizedCode(isolate);
|
|
|
|
Handle<Code> code2 = DummyOptimizedCode(isolate);
|
|
|
|
code2_address = code2->address();
|
|
|
|
// If this check breaks, change the allocation to ensure that both code
|
|
|
|
// objects are on the same page.
|
|
|
|
CHECK_EQ(MemoryChunk::FromHeapObject(*code1),
|
|
|
|
MemoryChunk::FromHeapObject(*code2));
|
2019-05-16 18:07:24 +00:00
|
|
|
CHECK(MemoryChunk::FromHeapObject(*code1)->Contains(code1->address()));
|
|
|
|
CHECK(MemoryChunk::FromHeapObject(*code2)->Contains(code2->address()));
|
2019-05-02 13:51:10 +00:00
|
|
|
}
|
|
|
|
CcTest::CollectAllAvailableGarbage();
|
2019-05-16 18:07:24 +00:00
|
|
|
CHECK(MemoryChunk::FromHeapObject(*code1)->Contains(code1->address()));
|
|
|
|
CHECK(MemoryChunk::FromAddress(code2_address)->Contains(code2_address));
|
2019-05-02 13:51:10 +00:00
|
|
|
}
|
|
|
|
|
2017-08-11 10:04:47 +00:00
|
|
|
} // namespace heap
|
2015-08-21 07:09:08 +00:00
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|
2017-11-08 20:31:18 +00:00
|
|
|
|
|
|
|
#undef __
|