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

Side by Side Diff: vm/code_index_table.h

Issue 10082017: Remove code index table. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | vm/code_index_table.cc » ('j') | vm/find_code_object_test.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
5 #ifndef VM_CODE_INDEX_TABLE_H_
6 #define VM_CODE_INDEX_TABLE_H_
7
8 #include "platform/assert.h"
9 #include "vm/globals.h"
10
11 namespace dart {
12
13 // Forward declarations.
14 class Array;
15 class Code;
16 class Function;
17 class Isolate;
18 class ObjectPointerVisitor;
19 class RawArray;
20 class RawCode;
21 class RawFunction;
22
23 // This class is used to lookup a Code object given a pc.
24 // This functionality is used while stack walking in order to find the Dart
25 // function corresponding to a frame (enables the pc descriptors for
26 // a stack frame to be located).
27 // Most code objects fit within a normal page (PageSpace::KPageSize) but some
28 // code objects may be larger than the size of a normal page.
29 // These code objects are referred to as "large codes" in this code and are
30 // handled by maintaining separate index lists.
31 class CodeIndexTable {
32 public:
33 ~CodeIndexTable();
34
35 // Add specified compiled function to the code index table.
36 void AddCode(const Code& code);
37
38 // Lookup code index table to find the code object corresponding to the
39 // specified 'pc'. If there is no corresponding code object a null object
40 // is returned.
41 RawCode* LookupCode(uword pc) const;
42
43 // Visit all object pointers (support for GC).
44 void VisitObjectPointers(ObjectPointerVisitor* visitor);
45
46 // Initialize the code index table for specified isolate.
47 static void Init(Isolate* isolate);
48
49 private:
50 static const int kInitialSize = 16;
51 static const bool kIsSorted = true;
52 static const bool kIsNotSorted = false;
53
54 template<typename T>
55 class IndexArray {
56 public:
57 explicit IndexArray(int initial_capacity)
58 : length_(0),
59 capacity_(initial_capacity),
60 data_(NULL) {
61 data_ = reinterpret_cast<T*>(malloc(capacity_ * sizeof(T)));
62 ASSERT(data_ != NULL);
63 }
64 ~IndexArray() {
65 free(data_);
66 data_ = NULL;
67 capacity_ = 0;
68 length_ = 0;
69 }
70 intptr_t length() const { return length_; }
71 T* data() const { return data_; }
72 bool IsFull() const { return length_ >= capacity_; }
73 T& At(intptr_t index) const {
74 ASSERT(0 <= index);
75 ASSERT(index < length_);
76 ASSERT(length_ <= capacity_);
77 return data_[index];
78 }
79 void Add(const T& value) {
80 ASSERT(length_ < capacity_);
81 data_[length_] = value;
82 length_ += 1;
83 }
84 void Resize(int new_capacity) {
85 ASSERT(new_capacity > capacity_);
86 T* new_data = reinterpret_cast<T*>(realloc(reinterpret_cast<void*>(data_),
87 new_capacity * sizeof(T)));
88 ASSERT(new_data != NULL);
89 data_ = new_data;
90 capacity_ = new_capacity;
91 }
92
93 private:
94 intptr_t length_;
95 intptr_t capacity_;
96 T* data_;
97 DISALLOW_COPY_AND_ASSIGN(IndexArray);
98 };
99
100 // PC range for a function.
101 typedef struct {
102 uword entrypoint; // Entry point for the function.
103 intptr_t size; // Code size for the function.
104 } PcRange;
105
106 // Information about function pc ranges for a code page.
107 typedef struct {
108 uword page_start; // Start address of code page.
109 IndexArray<PcRange>* pc_ranges; // Array of entry points in a code page.
110 } CodePageInfo;
111
112 // Constructor.
113 CodeIndexTable();
114
115 // Add code page information to the index table.
116 int AddPageIndex(uword page_start);
117
118 // Find the index corresponding to the code page in the index table.
119 int FindPageIndex(uword page_start) const;
120
121 // Add information about a code object (entrypoint, size, code object)
122 // at the specified index of the index table.
123 void AddCodeToList(int page_index,
124 uword entrypoint,
125 intptr_t size,
126 const Code& code);
127
128 // Add information about a large code object (entrypoint, size, code object)
129 // to the large code object list.
130 void AddLargeCode(uword entrypoint, intptr_t size, const Code& code);
131
132 // Helper function to add a code object to the list.
133 void AddCodeHelper(IndexArray<PcRange>* pc_ranges,
134 const Array& codes,
135 uword entrypoint,
136 intptr_t size,
137 const Code& func);
138
139 // Lookup code corresponding to the pc in the large functions list
140 RawCode* LookupLargeCode(uword pc) const;
141
142 // Lookup code corresponding to the pc in the functions list
143 // present at the specified page index.
144 static RawCode* LookupCodeFromList(IndexArray<PcRange>* pc_ranges,
145 const Array& functions,
146 uword pc,
147 bool sorted);
148
149 // Find index of pc in the pc ranges array, returns -1 if the pc
150 // is not found in the array.
151 static intptr_t FindPcIndex(const IndexArray<PcRange>& pc_ranges,
152 uword pc,
153 bool sorted);
154
155 // Grow the index table to the specified new size.
156 void GrowCodeIndexTable(int new_size);
157
158 IndexArray<CodePageInfo>* code_pages_; // Array of code pages information.
159 RawArray* code_lists_; // Array of pointers to code lists (arrays).
160 IndexArray<PcRange>* largecode_pc_ranges_; // pc ranges of large codes.
161 RawArray* largecode_list_; // Array of pointer to large code objects.
162
163 DISALLOW_COPY_AND_ASSIGN(CodeIndexTable);
164 };
165
166 } // namespace dart
167
168 #endif // VM_CODE_INDEX_TABLE_H_
OLDNEW
« no previous file with comments | « no previous file | vm/code_index_table.cc » ('j') | vm/find_code_object_test.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698