blob: 6c64350e8d149c5836829b70626970c47798cf11 [file] [log] [blame]
fschneider@chromium.org086aac62010-03-17 13:18:24 +00001// Copyright 2010 the V8 project authors. All rights reserved.
2// Redistribution and use in source and binary forms, with or without
3// modification, are permitted provided that the following conditions are
4// met:
5//
6// * Redistributions of source code must retain the above copyright
7// notice, this list of conditions and the following disclaimer.
8// * Redistributions in binary form must reproduce the above
9// copyright notice, this list of conditions and the following
10// disclaimer in the documentation and/or other materials provided
11// with the distribution.
12// * Neither the name of Google Inc. nor the names of its
13// contributors may be used to endorse or promote products derived
14// from this software without specific prior written permission.
15//
16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28#ifndef V8_PROFILE_GENERATOR_INL_H_
29#define V8_PROFILE_GENERATOR_INL_H_
30
31#include "profile-generator.h"
32
33namespace v8 {
34namespace internal {
35
erik.corry@gmail.com145eff52010-08-23 11:36:18 +000036const char* StringsStorage::GetFunctionName(String* name) {
37 return GetFunctionName(GetName(name));
38}
39
40
41const char* StringsStorage::GetFunctionName(const char* name) {
42 return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName;
43}
44
45
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000046CodeEntry::CodeEntry(Logger::LogEventsAndTags tag,
lrn@chromium.org25156de2010-04-06 13:10:27 +000047 const char* name_prefix,
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000048 const char* name,
49 const char* resource_name,
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000050 int line_number,
51 int security_token_id)
fschneider@chromium.orgc20610a2010-09-22 09:44:58 +000052 : tag_(tag),
lrn@chromium.org25156de2010-04-06 13:10:27 +000053 name_prefix_(name_prefix),
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000054 name_(name),
55 resource_name_(resource_name),
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000056 line_number_(line_number),
fschneider@chromium.org3a5fd782011-02-24 10:10:44 +000057 shared_id_(0),
erik.corry@gmail.com9dfbea42010-05-21 12:58:28 +000058 security_token_id_(security_token_id) {
whesse@chromium.orgcec079d2010-03-22 14:44:04 +000059}
60
61
ager@chromium.org357bf652010-04-12 11:30:10 +000062bool CodeEntry::is_js_function_tag(Logger::LogEventsAndTags tag) {
63 return tag == Logger::FUNCTION_TAG
64 || tag == Logger::LAZY_COMPILE_TAG
65 || tag == Logger::SCRIPT_TAG
66 || tag == Logger::NATIVE_FUNCTION_TAG
67 || tag == Logger::NATIVE_LAZY_COMPILE_TAG
68 || tag == Logger::NATIVE_SCRIPT_TAG;
fschneider@chromium.org086aac62010-03-17 13:18:24 +000069}
70
71
ricow@chromium.orgc9c80822010-04-21 08:22:37 +000072ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry)
73 : tree_(tree),
74 entry_(entry),
fschneider@chromium.org086aac62010-03-17 13:18:24 +000075 total_ticks_(0),
76 self_ticks_(0),
77 children_(CodeEntriesMatch) {
78}
79
80
ager@chromium.org357bf652010-04-12 11:30:10 +000081CodeEntry* ProfileGenerator::EntryForVMState(StateTag tag) {
82 switch (tag) {
83 case GC:
84 return gc_entry_;
85 case JS:
86 case COMPILER:
87 // DOM events handlers are reported as OTHER / EXTERNAL entries.
88 // To avoid confusing people, let's put all these entries into
89 // one bucket.
90 case OTHER:
91 case EXTERNAL:
92 return program_entry_;
93 default: return NULL;
94 }
95}
96
vegorov@chromium.org21b5e952010-11-23 10:24:40 +000097
erik.corry@gmail.comed49e962012-04-17 11:57:53 +000098HeapEntry* HeapGraphEdge::from() const {
jkummerow@chromium.org212d9642012-05-11 15:02:09 +000099 return &snapshot()->entries()[from_index_];
100}
101
102
103HeapSnapshot* HeapGraphEdge::snapshot() const {
104 return to_entry_->snapshot();
105}
106
107
108int HeapEntry::index() const {
109 return static_cast<int>(this - &snapshot_->entries().first());
110}
111
112
113int HeapEntry::set_children_index(int index) {
114 children_index_ = index;
115 int next_index = index + children_count_;
116 children_count_ = 0;
117 return next_index;
118}
119
120
jkummerow@chromium.org212d9642012-05-11 15:02:09 +0000121HeapGraphEdge** HeapEntry::children_arr() {
122 ASSERT(children_index_ >= 0);
123 return &snapshot_->children()[children_index_];
124}
125
126
svenpanne@chromium.org4efbdb12012-03-12 08:18:42 +0000127SnapshotObjectId HeapObjectsMap::GetNthGcSubrootId(int delta) {
ricow@chromium.org64e3a4b2011-12-13 08:07:27 +0000128 return kGcRootsFirstSubrootId + delta * kObjectIdStep;
129}
130
131
132HeapObject* V8HeapExplorer::GetNthGcSubrootObject(int delta) {
133 return reinterpret_cast<HeapObject*>(
134 reinterpret_cast<char*>(kFirstGcSubrootObject) +
135 delta * HeapObjectsMap::kObjectIdStep);
136}
137
138
139int V8HeapExplorer::GetGcSubrootOrder(HeapObject* subroot) {
140 return static_cast<int>(
141 (reinterpret_cast<char*>(subroot) -
142 reinterpret_cast<char*>(kFirstGcSubrootObject)) /
143 HeapObjectsMap::kObjectIdStep);
144}
145
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000146} } // namespace v8::internal
147
fschneider@chromium.org086aac62010-03-17 13:18:24 +0000148#endif // V8_PROFILE_GENERATOR_INL_H_