1// Copyright (c) 2013, 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 RUNTIME_VM_TAGS_H_
6#define RUNTIME_VM_TAGS_H_
7
8#include "vm/allocation.h"
9#include "vm/thread_stack_resource.h"
10
11namespace dart {
12
13class Isolate;
14class JSONObject;
15class RuntimeEntry;
16
17#define VM_TAG_LIST(V) \
18 V(Idle) /* isolate is idle and is_runnable() */ \
19 V(LoadWait) /* isolate is idle and !is_runnable() */ \
20 V(VM) /* Catch all */ \
21 V(LoadBytecode) \
22 V(CompileOptimized) \
23 V(CompileUnoptimized) \
24 V(ClassLoading) \
25 V(CompileParseRegExp) \
26 V(DartCompiled) \
27 V(DartInterpreted) \
28 V(GCNewSpace) \
29 V(GCOldSpace) \
30 V(GCIdle) \
31 V(Embedder) \
32 V(Runtime) \
33 V(Native)
34
35class VMTag : public AllStatic {
36 public:
37 enum VMTagId {
38 kInvalidTagId = 0,
39#define DEFINE_VM_TAG_ID(tag) k##tag##TagId,
40 VM_TAG_LIST(DEFINE_VM_TAG_ID)
41#undef DEFINE_VM_TAG_KIND
42 kNumVMTags,
43 //
44 // All tags below |kNumVMTags| are special meta-data tags and do not
45 // indicate the state of the VM during a sample.
46 //
47 kRootTagId, // Special tag used as root of all profiles.
48 kTruncatedTagId, // Special tag used to indicate a truncated call stack.
49 // Code transition tags (used by unit tests).
50 kNoneCodeTagId,
51 kOptimizedCodeTagId,
52 kUnoptimizedCodeTagId,
53 kNativeCodeTagId,
54 kInlineStartCodeTagId,
55 kInlineEndCodeTagId,
56 kLastTagId,
57 };
58
59 static bool IsVMTag(uword id) {
60 return (id != kInvalidTagId) && (id < kNumVMTags);
61 }
62 static const char* TagName(uword id);
63 static bool IsNativeEntryTag(uword id);
64 static bool IsDartTag(uword id);
65 static bool IsExitFrameTag(uword id);
66 static bool IsRuntimeEntryTag(uword id);
67 static const char* RuntimeEntryTagName(uword id);
68
69 static void RegisterRuntimeEntry(RuntimeEntry* runtime_entry);
70
71 private:
72 struct TagEntry {
73 const char* name;
74 uword id;
75 };
76 static TagEntry entries_[];
77};
78
79class VMTagScope : ThreadStackResource {
80 public:
81 VMTagScope(Thread* thread, uword tag, bool conditional_set = true);
82 ~VMTagScope();
83
84 private:
85 uword previous_tag_;
86
87 DISALLOW_ALLOCATION();
88 DISALLOW_IMPLICIT_CONSTRUCTORS(VMTagScope);
89};
90
91class VMTagCounters {
92 public:
93 VMTagCounters();
94
95 void Increment(uword tag);
96
97 int64_t count(uword tag);
98
99#ifndef PRODUCT
100 void PrintToJSONObject(JSONObject* obj);
101#endif // !PRODUCT
102
103 private:
104 int64_t counters_[VMTag::kNumVMTags];
105};
106
107class UserTags : public AllStatic {
108 public:
109 // UserTag id space: [kUserTagIdOffset, kUserTagIdOffset + kMaxUserTags).
110 static const intptr_t kMaxUserTags = 256;
111 static const uword kUserTagIdOffset = 0x4096;
112 static const uword kDefaultUserTag = kUserTagIdOffset;
113 static const char* TagName(uword tag_id);
114 static bool IsUserTag(uword tag_id) {
115 return (tag_id >= kUserTagIdOffset) &&
116 (tag_id < kUserTagIdOffset + kMaxUserTags);
117 }
118};
119
120} // namespace dart
121
122#endif // RUNTIME_VM_TAGS_H_
123