Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(626)

Side by Side Diff: test/cctest/test-code-cache.cc

Issue 2021373002: Refactor Maps' code_cache (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: windows don't want no constexpr Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/v8.h"
6
7 #include "src/list.h"
8 #include "src/objects.h"
9 #include "test/cctest/cctest.h"
10
11 namespace v8 {
12 namespace internal {
13
14 namespace {
15
16 static Handle<Code> GetDummyCode(Isolate* isolate) {
17 CodeDesc desc = {nullptr, // buffer
18 0, // buffer_size
19 0, // instr_size
20 0, // reloc_size
21 0, // constant_pool_size
22 nullptr}; // origin
23 Code::Flags flags = Code::ComputeFlags(Code::LOAD_IC, MONOMORPHIC,
24 kNoExtraICState, kCacheOnReceiver);
25 Handle<Code> self_ref;
26 return isolate->factory()->NewCode(desc, flags, self_ref);
27 }
28
29 } // namespace
30
31 TEST(CodeCache) {
32 CcTest::InitializeVM();
33 Isolate* isolate = CcTest::i_isolate();
34 Factory* factory = isolate->factory();
35 HandleScope handle_scope(isolate);
36
37 Handle<Map> map =
38 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize, FAST_ELEMENTS);
39
40 // This number should be large enough to cause the code cache to use its
41 // hash table storage format.
42 static const int kEntries = 150;
43
44 // Prepare name/code pairs.
45 List<Handle<Name>> names(kEntries);
46 List<Handle<Code>> codes(kEntries);
47 for (int i = 0; i < kEntries; i++) {
48 names.Add(isolate->factory()->NewSymbol());
49 codes.Add(GetDummyCode(isolate));
50 }
51 Handle<Name> bad_name = isolate->factory()->NewSymbol();
52 Code::Flags bad_flags = Code::ComputeFlags(
53 Code::LOAD_IC, MONOMORPHIC, kNoExtraICState, kCacheOnPrototype);
54 DCHECK(bad_flags != codes[0]->flags());
55
56 // Cache name/code pairs.
57 for (int i = 0; i < kEntries; i++) {
58 Handle<Name> name = names.at(i);
59 Handle<Code> code = codes.at(i);
60 Map::UpdateCodeCache(map, name, code);
61 CHECK_EQ(*code, map->LookupInCodeCache(*name, code->flags()));
62 CHECK_NULL(map->LookupInCodeCache(*name, bad_flags));
63 }
64 CHECK_NULL(map->LookupInCodeCache(*bad_name, bad_flags));
65
66 // Check that lookup works not only right after storing.
67 for (int i = 0; i < kEntries; i++) {
68 Handle<Name> name = names.at(i);
69 Handle<Code> code = codes.at(i);
70 CHECK_EQ(*code, map->LookupInCodeCache(*name, code->flags()));
71 }
72 }
73
74 } // namespace internal
75 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/cctest.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698