diff --git a/src/heap/heap-inl.h b/src/heap/heap-inl.h index b368420427..863b955a89 100644 --- a/src/heap/heap-inl.h +++ b/src/heap/heap-inl.h @@ -202,7 +202,7 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, allocation = old_space_->AllocateRaw(size_in_bytes, alignment); } } else if (CODE_SPACE == space) { - if (size_in_bytes <= code_space()->AreaSize()) { + if (size_in_bytes <= code_space()->AreaSize() && !large_object) { allocation = code_space_->AllocateRawUnaligned(size_in_bytes); } else { allocation = code_lo_space_->AllocateRaw(size_in_bytes); @@ -214,6 +214,7 @@ AllocationResult Heap::AllocateRaw(int size_in_bytes, AllocationSpace space, DCHECK(FLAG_young_generation_large_objects); allocation = new_lo_space_->AllocateRaw(size_in_bytes); } else if (CODE_LO_SPACE == space) { + DCHECK(large_object); allocation = code_lo_space_->AllocateRaw(size_in_bytes); } else if (MAP_SPACE == space) { allocation = map_space_->AllocateRawUnaligned(size_in_bytes); diff --git a/src/objects-debug.cc b/src/objects-debug.cc index 4fd886dffa..99cc318d11 100644 --- a/src/objects-debug.cc +++ b/src/objects-debug.cc @@ -1209,6 +1209,8 @@ void Code::CodeVerify(Isolate* isolate) { CHECK_LE(constant_pool_offset(), InstructionSize()); CHECK(IsAligned(raw_instruction_start(), kCodeAlignment)); relocation_info()->ObjectVerify(isolate); + CHECK(Code::SizeFor(body_size()) <= kMaxRegularHeapObjectSize || + isolate->heap()->InSpace(*this, CODE_LO_SPACE)); Address last_gc_pc = kNullAddress; for (RelocIterator it(*this); !it.done(); it.next()) { diff --git a/test/cctest/BUILD.gn b/test/cctest/BUILD.gn index b10ed98a19..e41b91be51 100644 --- a/test/cctest/BUILD.gn +++ b/test/cctest/BUILD.gn @@ -180,6 +180,7 @@ v8_source_set("cctest_sources") { "test-double.cc", "test-dtoa.cc", "test-elements-kind.cc", + "test-factory.cc", "test-fast-dtoa.cc", "test-feedback-vector.cc", "test-feedback-vector.h", diff --git a/test/cctest/test-factory.cc b/test/cctest/test-factory.cc new file mode 100644 index 0000000000..a282f4bccd --- /dev/null +++ b/test/cctest/test-factory.cc @@ -0,0 +1,46 @@ +// Copyright 2018 the V8 project authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "include/v8.h" + +#include "src/handles-inl.h" +#include "src/isolate.h" +#include "test/cctest/cctest.h" + +namespace v8 { +namespace internal { +namespace test_factory { + +TEST(Factory_NewCode) { + LocalContext env; + v8::Isolate* isolate = env->GetIsolate(); + Isolate* i_isolate = reinterpret_cast(isolate); + HandleScope scope(i_isolate); + + // Create a big function that ends up in CODE_LO_SPACE. + const int instruction_size = kMaxRegularHeapObjectSize + 1; + std::unique_ptr instructions(new byte[instruction_size]); + + CodeDesc desc; + desc.buffer = instructions.get(); + desc.buffer_size = instruction_size; + desc.instr_size = instruction_size; + desc.reloc_size = 0; + desc.constant_pool_size = 0; + desc.unwinding_info = nullptr; + desc.unwinding_info_size = 0; + desc.origin = nullptr; + Handle self_ref; + Handle code = + i_isolate->factory()->NewCode(desc, Code::WASM_FUNCTION, self_ref); + + CHECK(i_isolate->heap()->InSpace(*code, CODE_LO_SPACE)); +#if VERIFY_HEAP + code->ObjectVerify(i_isolate); +#endif +} + +} // namespace test_factory +} // namespace internal +} // namespace v8