Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
megamorphic_cache_table.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
6
7#include <stdlib.h>
9#include "vm/object.h"
10#include "vm/object_store.h"
11#include "vm/stub_code.h"
12#include "vm/symbols.h"
13
14namespace dart {
15
16MegamorphicCachePtr MegamorphicCacheTable::Lookup(Thread* thread,
17 const String& name,
18 const Array& descriptor) {
19 auto object_store = thread->isolate_group()->object_store();
21
22 ASSERT(name.IsSymbol());
23 // TODO(rmacnak): ASSERT(descriptor.IsCanonical());
24
25 // TODO(rmacnak): Make a proper hashtable a la symbol table.
26 auto& table =
27 GrowableObjectArray::Handle(object_store->megamorphic_cache_table());
29 if (table.IsNull()) {
31 object_store->set_megamorphic_cache_table(table);
32 } else {
33 for (intptr_t i = 0; i < table.Length(); i++) {
34 cache ^= table.At(i);
35 if ((cache.target_name() == name.ptr()) &&
36 (cache.arguments_descriptor() == descriptor.ptr())) {
37 return cache.ptr();
38 }
39 }
40 }
41
42 cache = MegamorphicCache::New(name, descriptor);
43 table.Add(cache, Heap::kOld);
44 return cache.ptr();
45}
46
48 auto isolate_group = thread->isolate_group();
49 SafepointMutexLocker ml(isolate_group->megamorphic_table_mutex());
50
51 StackZone zone(thread);
52 intptr_t size = 0;
54 Array& buckets = Array::Handle();
56 isolate_group->object_store()->megamorphic_cache_table());
57 if (table.IsNull()) return;
58 intptr_t max_size = 0;
59 for (intptr_t i = 0; i < table.Length(); i++) {
60 cache ^= table.At(i);
61 buckets = cache.buckets();
63 size += Array::InstanceSize(buckets.Length());
64 if (buckets.Length() > max_size) {
65 max_size = buckets.Length();
66 }
67 }
68 OS::PrintErr("%" Pd " megamorphic caches using %" Pd "KB.\n", table.Length(),
69 size / 1024);
70
71 intptr_t* probe_counts = new intptr_t[max_size];
72 intptr_t entry_count = 0;
73 intptr_t max_probe_count = 0;
74 for (intptr_t i = 0; i < max_size; i++) {
75 probe_counts[i] = 0;
76 }
77 for (intptr_t i = 0; i < table.Length(); i++) {
78 cache ^= table.At(i);
79 buckets = cache.buckets();
80 intptr_t mask = cache.mask();
81 intptr_t capacity = mask + 1;
82 for (intptr_t j = 0; j < capacity; j++) {
83 intptr_t class_id =
84 Smi::Value(Smi::RawCast(cache.GetClassId(buckets, j)));
85 if (class_id != kIllegalCid) {
86 intptr_t probe_count = 0;
87 intptr_t probe_index =
88 (class_id * MegamorphicCache::kSpreadFactor) & mask;
89 intptr_t probe_cid;
90 while (true) {
91 probe_count++;
92 probe_cid =
93 Smi::Value(Smi::RawCast(cache.GetClassId(buckets, probe_index)));
94 if (probe_cid == class_id) {
95 break;
96 }
97 probe_index = (probe_index + 1) & mask;
98 }
99 probe_counts[probe_count]++;
100 if (probe_count > max_probe_count) {
101 max_probe_count = probe_count;
102 }
103 entry_count++;
104 }
105 }
106 }
107 intptr_t cumulative_entries = 0;
108 for (intptr_t i = 0; i <= max_probe_count; i++) {
109 cumulative_entries += probe_counts[i];
110 OS::PrintErr("Megamorphic probe %" Pd ": %" Pd " (%lf)\n", i,
111 probe_counts[i],
112 static_cast<double>(cumulative_entries) /
113 static_cast<double>(entry_count));
114 }
115 delete[] probe_counts;
116}
117
118} // namespace dart
SI F table(const skcms_Curve *curve, F v)
static intptr_t InstanceSize()
Definition object.h:10910
intptr_t Length() const
Definition object.h:10808
static GrowableObjectArrayPtr New(Heap::Space space=Heap::kNew)
Definition object.h:11118
@ kOld
Definition heap.h:39
ObjectStore * object_store() const
Definition isolate.h:505
Mutex * megamorphic_table_mutex()
Definition isolate.h:512
static void PrintSizes(Thread *thread)
static MegamorphicCachePtr Lookup(Thread *thread, const String &name, const Array &descriptor)
static constexpr intptr_t kSpreadFactor
Definition object.h:7571
static intptr_t InstanceSize()
Definition object.h:7605
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
ObjectPtr ptr() const
Definition object.h:332
static Object & Handle()
Definition object.h:407
static ObjectPtr RawCast(ObjectPtr obj)
Definition object.h:325
intptr_t Value() const
Definition object.h:9969
IsolateGroup * isolate_group() const
Definition thread.h:540
#define ASSERT(E)
const char *const name
@ kIllegalCid
Definition class_id.h:214
#define Pd
Definition globals.h:408