v8/test/cctest/test-factory.cc
Peter Marshall 2f852e5e54 [factory] Make sure large code objects actually go to large code space
If the size of a large code object is larger than
kMaxRegularHeapObjectSize, then it should be allocated in the large code
space. Currently if the size is > kMaxRegularHeapObjectSize but <
512000, then it can still be allocated in the normal code space.

Change-Id: I72dbd38803c3d5d414bae85e9e0b15482e50e1c2
Reviewed-on: https://chromium-review.googlesource.com/c/1363137
Reviewed-by: Ulan Degenbaev <ulan@chromium.org>
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58046}
2018-12-05 16:54:30 +00:00

47 lines
1.3 KiB
C++

// 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*>(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<byte[]> 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<Object> self_ref;
Handle<Code> 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