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

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
« no previous file with comments | « runtime/vm/tags.h ('k') | runtime/vm/unit_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
10 #include "vm/runtime_entry.h"
9 11
10 namespace dart { 12 namespace dart {
11 13
12 const char* VMTag::TagName(uword tag) { 14 const char* VMTag::TagName(uword tag) {
15 if (IsNativeEntryTag(tag)) {
16 const uint8_t* native_reverse_lookup = NativeEntry::ResolveSymbol(tag);
17 if (native_reverse_lookup != NULL) {
18 return reinterpret_cast<const char*>(native_reverse_lookup);
19 }
20 return "Unknown native entry";
21 } else if (IsRuntimeEntryTag(tag)) {
22 const char* runtime_entry_name = RuntimeEntryTagName(tag);
23 ASSERT(runtime_entry_name != NULL);
24 return runtime_entry_name;
25 }
13 ASSERT(tag != kInvalidTagId); 26 ASSERT(tag != kInvalidTagId);
14 ASSERT(tag < kNumVMTags); 27 ASSERT(tag < kNumVMTags);
15 const TagEntry& entry = entries_[tag]; 28 const TagEntry& entry = entries_[tag];
16 ASSERT(entry.id == tag); 29 ASSERT(entry.id == tag);
17 return entry.name; 30 return entry.name;
18 } 31 }
19 32
20 33
34 bool VMTag::IsNativeEntryTag(uword tag) {
35 ASSERT(tag != kInvalidTagId);
36 ASSERT(tag != kNumVMTags);
37 return (tag > kNumVMTags) && !IsRuntimeEntryTag(tag);
38 }
39
40 static RuntimeEntry* runtime_entry_list = NULL;
41
42 bool VMTag::IsRuntimeEntryTag(uword id) {
43 const RuntimeEntry* current = runtime_entry_list;
44 while (current != NULL) {
45 if (reinterpret_cast<uword>(current->function()) == id) {
46 return true;
47 }
48 current = current->next();
49 }
50 return false;
51 }
52
53
54 const char* VMTag::RuntimeEntryTagName(uword id) {
55 const RuntimeEntry* current = runtime_entry_list;
56 while (current != NULL) {
57 if (reinterpret_cast<uword>(current->function()) == id) {
58 return current->name();
59 }
60 current = current->next();
61 }
62 return NULL;
63 }
64
65
66 void VMTag::RegisterRuntimeEntry(RuntimeEntry* runtime_entry) {
67 ASSERT(runtime_entry != NULL);
68 runtime_entry->set_next(runtime_entry_list);
69 runtime_entry_list = runtime_entry;
70 }
71
72
21 VMTag::TagEntry VMTag::entries_[] = { 73 VMTag::TagEntry VMTag::entries_[] = {
22 { "InvalidTag", kInvalidTagId, }, 74 { "InvalidTag", kInvalidTagId, },
23 #define DEFINE_VM_TAG_ENTRY(tag) \ 75 #define DEFINE_VM_TAG_ENTRY(tag) \
24 { ""#tag, k##tag##TagId }, 76 { ""#tag, k##tag##TagId },
25 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY) 77 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY)
26 #undef DEFINE_VM_TAG_ENTRY 78 #undef DEFINE_VM_TAG_ENTRY
27 { "kNumVMTags", kNumVMTags }, 79 { "kNumVMTags", kNumVMTags },
28 }; 80 };
29 81
30 82
(...skipping 12 matching lines...) Expand all
43 95
44 96
45 VMTagCounters::VMTagCounters() { 97 VMTagCounters::VMTagCounters() {
46 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) { 98 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) {
47 counters_[i] = 0; 99 counters_[i] = 0;
48 } 100 }
49 } 101 }
50 102
51 103
52 void VMTagCounters::Increment(uword tag) { 104 void VMTagCounters::Increment(uword tag) {
105 if (VMTag::IsRuntimeEntryTag(tag)) {
106 counters_[VMTag::kRuntimeTagId]++;
107 return;
108 } else if (tag > VMTag::kNumVMTags) {
109 // Assume native entry.
110 counters_[VMTag::kNativeTagId]++;
111 return;
112 }
53 ASSERT(tag != VMTag::kInvalidTagId); 113 ASSERT(tag != VMTag::kInvalidTagId);
54 ASSERT(tag < VMTag::kNumVMTags); 114 ASSERT(tag < VMTag::kNumVMTags);
55 counters_[tag]++; 115 counters_[tag]++;
56 } 116 }
57 117
58 118
59 int64_t VMTagCounters::count(uword tag) { 119 int64_t VMTagCounters::count(uword tag) {
60 ASSERT(tag != VMTag::kInvalidTagId); 120 ASSERT(tag != VMTag::kInvalidTagId);
61 ASSERT(tag < VMTag::kNumVMTags); 121 ASSERT(tag < VMTag::kNumVMTags);
62 return counters_[tag]; 122 return counters_[tag];
63 } 123 }
64 124
65 125
66 void VMTagCounters::PrintToJSONObject(JSONObject* obj) { 126 void VMTagCounters::PrintToJSONObject(JSONObject* obj) {
67 { 127 {
68 JSONArray arr(obj, "names"); 128 JSONArray arr(obj, "names");
69 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 129 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
70 arr.AddValue(VMTag::TagName(i)); 130 arr.AddValue(VMTag::TagName(i));
71 } 131 }
72 } 132 }
73 { 133 {
74 JSONArray arr(obj, "counters"); 134 JSONArray arr(obj, "counters");
75 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 135 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
76 arr.AddValue64(counters_[i]); 136 arr.AddValue64(counters_[i]);
77 } 137 }
78 } 138 }
79 } 139 }
80 140
81 } // namespace dart 141 } // namespace dart
OLDNEW
« no previous file with comments | « 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