2016-06-02 13:16:39 +00:00
|
|
|
// Copyright 2016 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 "src/v8.h"
|
|
|
|
|
2016-09-01 12:01:33 +00:00
|
|
|
#include "src/factory.h"
|
|
|
|
#include "src/isolate.h"
|
2016-06-02 13:16:39 +00:00
|
|
|
#include "src/objects.h"
|
2016-09-01 12:01:33 +00:00
|
|
|
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
|
|
|
|
// (disallowed) include: src/factory.h -> src/objects-inl.h
|
|
|
|
#include "src/objects-inl.h"
|
|
|
|
// FIXME(mstarzinger, marja): This is weird, but required because of the missing
|
2017-02-07 14:05:02 +00:00
|
|
|
// (disallowed) include: src/feedback-vector.h ->
|
|
|
|
// src/feedback-vector-inl.h
|
|
|
|
#include "src/feedback-vector-inl.h"
|
2016-06-02 13:16:39 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
static Handle<Code> GetDummyCode(Isolate* isolate) {
|
|
|
|
CodeDesc desc = {nullptr, // buffer
|
|
|
|
0, // buffer_size
|
|
|
|
0, // instr_size
|
|
|
|
0, // reloc_size
|
|
|
|
0, // constant_pool_size
|
2016-06-27 15:06:32 +00:00
|
|
|
nullptr, // unwinding_info
|
|
|
|
0, // unwinding_info_size
|
2016-06-02 13:16:39 +00:00
|
|
|
nullptr}; // origin
|
2017-03-15 16:12:02 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState);
|
2016-06-02 13:16:39 +00:00
|
|
|
Handle<Code> self_ref;
|
|
|
|
return isolate->factory()->NewCode(desc, flags, self_ref);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
TEST(CodeCache) {
|
|
|
|
CcTest::InitializeVM();
|
|
|
|
Isolate* isolate = CcTest::i_isolate();
|
|
|
|
Factory* factory = isolate->factory();
|
|
|
|
HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
Handle<Map> map =
|
2017-06-30 11:26:14 +00:00
|
|
|
factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize, PACKED_ELEMENTS);
|
2016-06-02 13:16:39 +00:00
|
|
|
|
|
|
|
// This number should be large enough to cause the code cache to use its
|
|
|
|
// hash table storage format.
|
|
|
|
static const int kEntries = 150;
|
|
|
|
|
|
|
|
// Prepare name/code pairs.
|
2017-08-29 12:40:31 +00:00
|
|
|
std::vector<Handle<Name>> names;
|
|
|
|
std::vector<Handle<Code>> codes;
|
|
|
|
names.reserve(kEntries);
|
|
|
|
codes.reserve(kEntries);
|
2016-06-02 13:16:39 +00:00
|
|
|
for (int i = 0; i < kEntries; i++) {
|
2017-08-29 12:40:31 +00:00
|
|
|
names.push_back(isolate->factory()->NewSymbol());
|
|
|
|
codes.push_back(GetDummyCode(isolate));
|
2016-06-02 13:16:39 +00:00
|
|
|
}
|
|
|
|
Handle<Name> bad_name = isolate->factory()->NewSymbol();
|
2017-03-15 16:12:02 +00:00
|
|
|
Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, kNoExtraICState);
|
2016-06-02 13:16:39 +00:00
|
|
|
|
|
|
|
// Cache name/code pairs.
|
|
|
|
for (int i = 0; i < kEntries; i++) {
|
|
|
|
Handle<Name> name = names.at(i);
|
|
|
|
Handle<Code> code = codes.at(i);
|
|
|
|
Map::UpdateCodeCache(map, name, code);
|
|
|
|
CHECK_EQ(*code, map->LookupInCodeCache(*name, code->flags()));
|
|
|
|
}
|
2017-03-15 16:12:02 +00:00
|
|
|
CHECK_NULL(map->LookupInCodeCache(*bad_name, flags));
|
2016-06-02 13:16:39 +00:00
|
|
|
|
|
|
|
// Check that lookup works not only right after storing.
|
|
|
|
for (int i = 0; i < kEntries; i++) {
|
|
|
|
Handle<Name> name = names.at(i);
|
|
|
|
Handle<Code> code = codes.at(i);
|
|
|
|
CHECK_EQ(*code, map->LookupInCodeCache(*name, code->flags()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|