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

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 char* native_reverse_lookup = NativeEntry::ReverseLookup(tag);
16 if (native_reverse_lookup != NULL) {
17 return 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 #define DECLARE_RUNTIME_ENTRY_POINT(name) \
40 extern void DRT_##name(NativeArguments arguments);
41 RUNTIME_ENTRY_TAG_LIST(DECLARE_RUNTIME_ENTRY_POINT);
42 #undef DECLARE_RUNTIME_ENTRY_POINT
43
44 #define REGISTER_RUNTIME_ENTRY(name) \
45 { ""#name, reinterpret_cast<uword>(&DRT_##name) },
46
47 static struct RuntimeEntries {
48 const char* name;
49 uword entry;
50 } RuntimeTagEntries[] = {
51 RUNTIME_ENTRY_TAG_LIST(REGISTER_RUNTIME_ENTRY)
52 };
53
54
55 bool VMTag::IsRuntimeEntryTag(uword id) {
56 int num_entries = sizeof(RuntimeTagEntries) / sizeof(struct RuntimeEntries);
57 for (int i = 0; i < num_entries; i++) {
58 if (RuntimeTagEntries[i].entry == id) {
59 return true;
60 }
61 }
62 return false;
63 }
64
65
66 const char* VMTag::RuntimeEntryTagName(uword id) {
67 int num_entries = sizeof(RuntimeTagEntries) / sizeof(struct RuntimeEntries);
68 for (int i = 0; i < num_entries; i++) {
69 if (RuntimeTagEntries[i].entry == id) {
70 return RuntimeTagEntries[i].name;
71 }
72 }
73 return NULL;
74 }
75
76
21 VMTag::TagEntry VMTag::entries_[] = { 77 VMTag::TagEntry VMTag::entries_[] = {
22 { "InvalidTag", kInvalidTagId, }, 78 { "InvalidTag", kInvalidTagId, },
23 #define DEFINE_VM_TAG_ENTRY(tag) \ 79 #define DEFINE_VM_TAG_ENTRY(tag) \
24 { ""#tag, k##tag##TagId }, 80 { ""#tag, k##tag##TagId },
25 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY) 81 VM_TAG_LIST(DEFINE_VM_TAG_ENTRY)
26 #undef DEFINE_VM_TAG_ENTRY 82 #undef DEFINE_VM_TAG_ENTRY
27 { "kNumVMTags", kNumVMTags }, 83 { "kNumVMTags", kNumVMTags },
28 }; 84 };
29 85
30 86
(...skipping 12 matching lines...) Expand all
43 99
44 100
45 VMTagCounters::VMTagCounters() { 101 VMTagCounters::VMTagCounters() {
46 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) { 102 for (intptr_t i = 0; i < VMTag::kNumVMTags; i++) {
47 counters_[i] = 0; 103 counters_[i] = 0;
48 } 104 }
49 } 105 }
50 106
51 107
52 void VMTagCounters::Increment(uword tag) { 108 void VMTagCounters::Increment(uword tag) {
109 if (VMTag::IsRuntimeEntryTag(tag)) {
110 counters_[VMTag::kRuntimeTagId]++;
111 return;
112 } else if (tag > VMTag::kNumVMTags) {
113 // Assume native entry.
114 counters_[VMTag::kNativeTagId]++;
115 return;
116 }
53 ASSERT(tag != VMTag::kInvalidTagId); 117 ASSERT(tag != VMTag::kInvalidTagId);
54 ASSERT(tag < VMTag::kNumVMTags); 118 ASSERT(tag < VMTag::kNumVMTags);
55 counters_[tag]++; 119 counters_[tag]++;
56 } 120 }
57 121
58 122
59 int64_t VMTagCounters::count(uword tag) { 123 int64_t VMTagCounters::count(uword tag) {
60 ASSERT(tag != VMTag::kInvalidTagId); 124 ASSERT(tag != VMTag::kInvalidTagId);
61 ASSERT(tag < VMTag::kNumVMTags); 125 ASSERT(tag < VMTag::kNumVMTags);
62 return counters_[tag]; 126 return counters_[tag];
63 } 127 }
64 128
65 129
66 void VMTagCounters::PrintToJSONObject(JSONObject* obj) { 130 void VMTagCounters::PrintToJSONObject(JSONObject* obj) {
67 { 131 {
68 JSONArray arr(obj, "names"); 132 JSONArray arr(obj, "names");
69 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 133 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
70 arr.AddValue(VMTag::TagName(i)); 134 arr.AddValue(VMTag::TagName(i));
71 } 135 }
72 } 136 }
73 { 137 {
74 JSONArray arr(obj, "counters"); 138 JSONArray arr(obj, "counters");
75 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) { 139 for (intptr_t i = 1; i < VMTag::kNumVMTags; i++) {
76 arr.AddValue64(counters_[i]); 140 arr.AddValue64(counters_[i]);
77 } 141 }
78 } 142 }
79 } 143 }
80 144
81 } // namespace dart 145 } // 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