Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 1 | // 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 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 31 | #include "profile-generator.h" |
| 32 | |
| 33 | namespace v8 { |
| 34 | namespace internal { |
| 35 | |
Steve Block | 791712a | 2010-08-27 10:21:07 +0100 | [diff] [blame] | 36 | const char* StringsStorage::GetFunctionName(String* name) { |
| 37 | return GetFunctionName(GetName(name)); |
| 38 | } |
| 39 | |
| 40 | |
| 41 | const char* StringsStorage::GetFunctionName(const char* name) { |
| 42 | return strlen(name) > 0 ? name : ProfileGenerator::kAnonymousFunctionName; |
| 43 | } |
| 44 | |
| 45 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 46 | CodeEntry::CodeEntry(Logger::LogEventsAndTags tag, |
| 47 | const char* name_prefix, |
| 48 | const char* name, |
| 49 | const char* resource_name, |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 50 | int line_number, |
| 51 | int security_token_id) |
Kristian Monsen | 0d5e116 | 2010-09-30 15:31:59 +0100 | [diff] [blame] | 52 | : tag_(tag), |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 53 | name_prefix_(name_prefix), |
| 54 | name_(name), |
| 55 | resource_name_(resource_name), |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 56 | line_number_(line_number), |
Ben Murdoch | e0cee9b | 2011-05-25 10:26:03 +0100 | [diff] [blame] | 57 | shared_id_(0), |
Leon Clarke | f7060e2 | 2010-06-03 12:02:55 +0100 | [diff] [blame] | 58 | security_token_id_(security_token_id) { |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | |
| 62 | bool 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; |
| 69 | } |
| 70 | |
| 71 | |
| 72 | ProfileNode::ProfileNode(ProfileTree* tree, CodeEntry* entry) |
| 73 | : tree_(tree), |
| 74 | entry_(entry), |
| 75 | total_ticks_(0), |
| 76 | self_ticks_(0), |
| 77 | children_(CodeEntriesMatch) { |
| 78 | } |
| 79 | |
| 80 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 81 | CodeEntry* 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 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 97 | |
Ben Murdoch | c7cc028 | 2012-03-05 14:35:55 +0000 | [diff] [blame^] | 98 | uint64_t HeapObjectsMap::GetNthGcSubrootId(int delta) { |
| 99 | return kGcRootsFirstSubrootId + delta * kObjectIdStep; |
| 100 | } |
| 101 | |
| 102 | |
| 103 | HeapObject* V8HeapExplorer::GetNthGcSubrootObject(int delta) { |
| 104 | return reinterpret_cast<HeapObject*>( |
| 105 | reinterpret_cast<char*>(kFirstGcSubrootObject) + |
| 106 | delta * HeapObjectsMap::kObjectIdStep); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | int V8HeapExplorer::GetGcSubrootOrder(HeapObject* subroot) { |
| 111 | return static_cast<int>( |
| 112 | (reinterpret_cast<char*>(subroot) - |
| 113 | reinterpret_cast<char*>(kFirstGcSubrootObject)) / |
| 114 | HeapObjectsMap::kObjectIdStep); |
| 115 | } |
| 116 | |
| 117 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 118 | uint64_t HeapEntry::id() { |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 119 | union { |
| 120 | Id stored_id; |
| 121 | uint64_t returned_id; |
| 122 | } id_adaptor = {id_}; |
| 123 | return id_adaptor.returned_id; |
| 124 | } |
| 125 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 126 | } } // namespace v8::internal |
| 127 | |
Steve Block | 6ded16b | 2010-05-10 14:33:55 +0100 | [diff] [blame] | 128 | #endif // V8_PROFILE_GENERATOR_INL_H_ |