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

Side by Side Diff: runtime/vm/tags.cc

Issue 227433004: Add runtime and native entry tags (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/tags.h" 5 #include "vm/tags.h"
6 6
7 #include "vm/isolate.h" 7 #include "vm/isolate.h"
8 #include "vm/json_stream.h" 8 #include "vm/json_stream.h"
9 #include "vm/native_entry.h"
9 10
10 namespace dart { 11 namespace dart {
11 12
12 const char* VMTag::TagName(uword tag) { 13 const char* VMTag::TagName(uword tag) {
14 if (IsNativeEntryTag(tag)) {
15 const uint8_t* native_reverse_lookup = NativeEntry::ResolveSymbol(tag);
16 if (native_reverse_lookup != NULL) {
17 return reinterpret_cast<const char*>(native_reverse_lookup);
18 }
19 return "Unknown native entry";
20 } else if (IsRuntimeEntryTag(tag)) {
21 const char* runtime_entry_name = RuntimeEntryTagName(tag);
22 ASSERT(runtime_entry_name != NULL);
23 return runtime_entry_name;
24 }
13 ASSERT(tag != kInvalidTagId); 25 ASSERT(tag != kInvalidTagId);
14 ASSERT(tag < kNumVMTags); 26 ASSERT(tag < kNumVMTags);
15 const TagEntry& entry = entries_[tag]; 27 const TagEntry& entry = entries_[tag];
16 ASSERT(entry.id == tag); 28 ASSERT(entry.id == tag);
17 return entry.name; 29 return entry.name;
18 } 30 }
19 31
20 32
33 bool VMTag::IsNativeEntryTag(uword tag) {
34 ASSERT(tag != kInvalidTagId);
35 ASSERT(tag != kNumVMTags);
36 return (tag > kNumVMTags) && !IsRuntimeEntryTag(tag);
37 }
38
39
40 struct RegisteredRuntimeEntry {
41 const char* name;
42 uword entry;
43 RegisteredRuntimeEntry* next;
44 };
45
46 static RegisteredRuntimeEntry* runtime_entry_list = NULL;
47
48
49 bool VMTag::IsRuntimeEntryTag(uword id) {
50 RegisteredRuntimeEntry* current = runtime_entry_list;
51 while (current != NULL) {
52 if (current->entry == id) {
53 return true;
54 }
55 current = current->next;
56 }
57 return false;
58 }
59
60
61 const char* VMTag::RuntimeEntryTagName(uword id) {
62 RegisteredRuntimeEntry* current = runtime_entry_list;
63 while (current != NULL) {
64 if (current->entry == id) {
65 return current->name;
66 }
67 current = current->next;
68 }
69 return NULL;
70 }
71
72
73 void VMTag::RegisterRuntimeEntry(const RuntimeEntry* runtime_entry) {
74 RegisteredRuntimeEntry* entry =
75 reinterpret_cast<RegisteredRuntimeEntry*>(malloc(sizeof(*entry)));
siva 2014/04/10 17:58:22 Do we need a new type RegisteredRuntimeEntry here
Cutch 2014/04/10 20:17:32 Done.
76 ASSERT(entry != NULL);
77 entry->name = runtime_entry->name();
78 entry->entry = reinterpret_cast<uword>(runtime_entry->function());
79 entry->next = runtime_entry_list;
80 runtime_entry_list = entry;
81 }
82
83
21 VMTag::TagEntry VMTag::entries_[] = { 84 VMTag::TagEntry VMTag::entries_[] = {
22 { "InvalidTag", kInvalidTagId, }, 85 { "InvalidTag", kInvalidTagId, },
23 #define DEFINE_VM_TAG_ENTRY(tag) \ 86 #define DEFINE_VM_TAG_ENTRY(tag) \
24 { ""#tag, k##tag##TagId }, 87 { ""#tag, k##tag##TagId },
25 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY) 88 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY)
26 #undef DEFINE_VM_TAG_ENTRY 89 #undef DEFINE_VM_TAG_ENTRY
27 { "kNumVMTags", kNumVMTags }, 90 { "kNumVMTags", kNumVMTags },
28 }; 91 };
29 92
30 93
(...skipping 12 matching lines...) Expand all
43 106
44 107
45 VMTagCounters::VMTagCounters() { 108 VMTagCounters::VMTagCounters() {
46 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) { 109 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) {
47 counters_[i] = 0; 110 counters_[i] = 0;
48 } 111 }
49 } 112 }
50 113
51 114
52 void VMTagCounters::Increment(uword tag) { 115 void VMTagCounters::Increment(uword tag) {
116 if (VMTag::IsRuntimeEntryTag(tag)) {
117 counters_[VMTag::kRuntimeTagId]++;
118 return;
119 } else if (tag > VMTag::kNumVMTags) {
120 // Assume native entry.
121 counters_[VMTag::kNativeTagId]++;
122 return;
123 }
53 ASSERT(tag != VMTag::kInvalidTagId); 124 ASSERT(tag != VMTag::kInvalidTagId);
54 ASSERT(tag < VMTag::kNumVMTags); 125 ASSERT(tag < VMTag::kNumVMTags);
55 counters_[tag]++; 126 counters_[tag]++;
56 } 127 }
57 128
58 129
59 int64_t VMTagCounters::count(uword tag) { 130 int64_t VMTagCounters::count(uword tag) {
60 ASSERT(tag != VMTag::kInvalidTagId); 131 ASSERT(tag != VMTag::kInvalidTagId);
61 ASSERT(tag < VMTag::kNumVMTags); 132 ASSERT(tag < VMTag::kNumVMTags);
62 return counters_[tag]; 133 return counters_[tag];
63 } 134 }
64 135
65 136
66 void VMTagCounters::PrintToJSONObject(JSONObject* obj) { 137 void VMTagCounters::PrintToJSONObject(JSONObject* obj) {
67 { 138 {
68 JSONArray arr(obj, "names"); 139 JSONArray arr(obj, "names");
69 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 140 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
70 arr.AddValue(VMTag::TagName(i)); 141 arr.AddValue(VMTag::TagName(i));
71 } 142 }
72 } 143 }
73 { 144 {
74 JSONArray arr(obj, "counters"); 145 JSONArray arr(obj, "counters");
75 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 146 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
76 arr.AddValue64(counters_[i]); 147 arr.AddValue64(counters_[i]);
77 } 148 }
78 } 149 }
79 } 150 }
80 151
81 } // namespace dart 152 } // namespace dart
OLDNEW
« runtime/vm/tags.h ('K') | « runtime/vm/tags.h ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698