Flutter Engine
The Flutter Engine
reverse_pc_lookup_cache.cc
Go to the documentation of this file.
1// Copyright (c) 2018, 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 "vm/isolate.h"
8#include "vm/object.h"
9#include "vm/object_store.h"
10#include "vm/stub_code.h"
11
12namespace dart {
13
14CodePtr ReversePc::FindCodeInGroup(IsolateGroup* group,
15 uword pc,
16 bool is_return_address) {
17#if defined(DART_PRECOMPILED_RUNTIME)
18 // This can run in the middle of GC and must not allocate handles.
19 NoSafepointScope no_safepoint;
20
21 if (is_return_address) {
22 pc--;
23 }
24
25 // This expected number of tables is low (one per loading unit), so we go
26 // through them linearly. If this changes, would could sort the table list
27 // during deserialization and binary search for the table.
28 GrowableObjectArrayPtr tables = group->object_store()->instructions_tables();
29 intptr_t tables_length = Smi::Value(tables->untag()->length());
30 for (intptr_t i = 0; i < tables_length; i++) {
31 InstructionsTablePtr table = static_cast<InstructionsTablePtr>(
32 tables->untag()->data()->untag()->element(i));
34 if (code != Code::null()) {
35 return code;
36 }
37 }
38#endif // defined(DART_PRECOMPILED_RUNTIME)
39 return Code::null();
40}
41
42const UntaggedCompressedStackMaps::Payload* ReversePc::FindStackMapInGroup(
43 IsolateGroup* group,
44 uword pc,
45 bool is_return_address,
46 uword* code_start,
47 const UntaggedCompressedStackMaps::Payload** global_table) {
48#if defined(DART_PRECOMPILED_RUNTIME)
49 // This can run in the middle of GC and must not allocate handles.
50 NoSafepointScope no_safepoint;
51
52 if (is_return_address) {
53 pc--;
54 }
55
56 // This expected number of tables is low (one per loading unit), so we go
57 // through them linearly. If this changes, would could sort the table list
58 // during deserialization and binary search for the table.
59 GrowableObjectArrayPtr tables = group->object_store()->instructions_tables();
60 intptr_t tables_length = Smi::Value(tables->untag()->length());
61 for (intptr_t i = 0; i < tables_length; i++) {
62 InstructionsTablePtr table = static_cast<InstructionsTablePtr>(
63 tables->untag()->data()->untag()->element(i));
64 auto map = InstructionsTable::FindStackMap(table, pc, code_start);
65 if (map != nullptr) {
66 // Take global table from the first table.
67 table = static_cast<InstructionsTablePtr>(
68 tables->untag()->data()->untag()->element(0));
70 return map;
71 }
72 }
73#endif // defined(DART_PRECOMPILED_RUNTIME)
74
75 *code_start = 0;
76 return nullptr;
77}
78
81 uword pc,
82 bool is_return_address,
83 uword* code_start,
84 const UntaggedCompressedStackMaps::Payload** global_table) {
85 ASSERT(FLAG_precompiled_mode);
86 NoSafepointScope no_safepoint;
87
88 auto map = FindStackMapInGroup(group, pc, is_return_address, code_start,
89 global_table);
90 if (map == nullptr) {
91 map = FindStackMapInGroup(Dart::vm_isolate_group(), pc, is_return_address,
92 code_start, global_table);
93 }
94 return map;
95}
96
97CodePtr ReversePc::FindCode(IsolateGroup* group,
98 uword pc,
99 bool is_return_address) {
100 ASSERT(FLAG_precompiled_mode);
101 NoSafepointScope no_safepoint;
102
103 auto code_descriptor = FindCodeInGroup(group, pc, is_return_address);
104 if (code_descriptor == Code::null()) {
105 code_descriptor =
106 FindCodeInGroup(Dart::vm_isolate_group(), pc, is_return_address);
107 }
108 return code_descriptor;
109}
110
112 uword pc,
113 bool is_return_address) {
114 ASSERT(FLAG_precompiled_mode);
115 NoSafepointScope no_safepoint;
116
117 return FindCode(group, pc, is_return_address);
118}
119
120} // namespace dart
SI F table(const skcms_Curve *curve, F v)
static IsolateGroup * vm_isolate_group()
Definition: dart.h:69
static CodePtr FindCode(InstructionsTablePtr table, uword pc)
Definition: object.cc:15610
static const UntaggedCompressedStackMaps::Payload * FindStackMap(InstructionsTablePtr table, uword pc, uword *start_pc)
Definition: object.cc:15594
static const UntaggedCompressedStackMaps::Payload * GetCanonicalStackMap(InstructionsTablePtr table)
Definition: object.cc:15587
static ObjectPtr null()
Definition: object.h:433
static CodePtr Lookup(IsolateGroup *group, uword pc, bool is_return_address)
static const UntaggedCompressedStackMaps::Payload * FindStackMap(IsolateGroup *group, uword pc, bool is_return_address, uword *code_start, const UntaggedCompressedStackMaps::Payload **global_table)
intptr_t Value() const
Definition: object.h:9990
#define ASSERT(E)
Definition: dart_vm.cc:33
uintptr_t uword
Definition: globals.h:501
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition: SkVx.h:680