| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "test/cctest/trace-extension.h" | 28 #include "test/cctest/trace-extension.h" |
| 29 | 29 |
| 30 #include "src/profiler/tick-sample.h" | 30 #include "include/v8-profiler.h" |
| 31 #include "src/vm-state-inl.h" | 31 #include "src/vm-state-inl.h" |
| 32 #include "test/cctest/cctest.h" | 32 #include "test/cctest/cctest.h" |
| 33 | 33 |
| 34 namespace v8 { | 34 namespace v8 { |
| 35 namespace internal { | 35 namespace internal { |
| 36 | 36 |
| 37 const char* TraceExtension::kSource = | 37 const char* TraceExtension::kSource = |
| 38 "native function trace();" | 38 "native function trace();" |
| 39 "native function js_trace();" | 39 "native function js_trace();" |
| 40 "native function js_entry_sp();" | 40 "native function js_entry_sp();" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 int64_t low_bits = *reinterpret_cast<uint64_t*>(*args[0]) >> 32; | 83 int64_t low_bits = *reinterpret_cast<uint64_t*>(*args[0]) >> 32; |
| 84 int64_t high_bits = *reinterpret_cast<uint64_t*>(*args[1]); | 84 int64_t high_bits = *reinterpret_cast<uint64_t*>(*args[1]); |
| 85 Address fp = reinterpret_cast<Address>(high_bits | low_bits); | 85 Address fp = reinterpret_cast<Address>(high_bits | low_bits); |
| 86 #else | 86 #else |
| 87 #error Host architecture is neither 32-bit nor 64-bit. | 87 #error Host architecture is neither 32-bit nor 64-bit. |
| 88 #endif | 88 #endif |
| 89 printf("Trace: %p\n", static_cast<void*>(fp)); | 89 printf("Trace: %p\n", static_cast<void*>(fp)); |
| 90 return fp; | 90 return fp; |
| 91 } | 91 } |
| 92 | 92 |
| 93 static struct { v8::TickSample* sample; } trace_env = {nullptr}; |
| 93 | 94 |
| 94 static struct { | 95 void TraceExtension::InitTraceEnv(v8::TickSample* sample) { |
| 95 TickSample* sample; | |
| 96 } trace_env = { NULL }; | |
| 97 | |
| 98 | |
| 99 void TraceExtension::InitTraceEnv(TickSample* sample) { | |
| 100 trace_env.sample = sample; | 96 trace_env.sample = sample; |
| 101 } | 97 } |
| 102 | 98 |
| 103 | 99 |
| 104 void TraceExtension::DoTrace(Address fp) { | 100 void TraceExtension::DoTrace(Address fp) { |
| 105 RegisterState regs; | 101 RegisterState regs; |
| 106 regs.fp = fp; | 102 regs.fp = fp; |
| 107 // sp is only used to define stack high bound | 103 // sp is only used to define stack high bound |
| 108 regs.sp = | 104 regs.sp = |
| 109 reinterpret_cast<Address>(trace_env.sample) - 10240; | 105 reinterpret_cast<Address>(trace_env.sample) - 10240; |
| 110 trace_env.sample->Init(CcTest::i_isolate(), regs, | 106 trace_env.sample->Init(CcTest::isolate(), regs, |
| 111 TickSample::kSkipCEntryFrame, true); | 107 v8::TickSample::kSkipCEntryFrame, true); |
| 112 } | 108 } |
| 113 | 109 |
| 114 | 110 |
| 115 void TraceExtension::Trace(const v8::FunctionCallbackInfo<v8::Value>& args) { | 111 void TraceExtension::Trace(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 116 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 112 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 117 i::VMState<EXTERNAL> state(isolate); | 113 i::VMState<EXTERNAL> state(isolate); |
| 118 Address address = reinterpret_cast<Address>( | 114 Address address = reinterpret_cast<Address>( |
| 119 reinterpret_cast<intptr_t>(&TraceExtension::Trace)); | 115 reinterpret_cast<intptr_t>(&TraceExtension::Trace)); |
| 120 i::ExternalCallbackScope call_scope(isolate, address); | 116 i::ExternalCallbackScope call_scope(isolate, address); |
| 121 DoTrace(GetFP(args)); | 117 DoTrace(GetFP(args)); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 161 v8::HandleScope scope(args.GetIsolate()); | 157 v8::HandleScope scope(args.GetIsolate()); |
| 162 const Address js_entry_sp = GetJsEntrySp(); | 158 const Address js_entry_sp = GetJsEntrySp(); |
| 163 CHECK(js_entry_sp); | 159 CHECK(js_entry_sp); |
| 164 CompileRun("js_entry_sp();"); | 160 CompileRun("js_entry_sp();"); |
| 165 CHECK_EQ(js_entry_sp, GetJsEntrySp()); | 161 CHECK_EQ(js_entry_sp, GetJsEntrySp()); |
| 166 } | 162 } |
| 167 | 163 |
| 168 | 164 |
| 169 } // namespace internal | 165 } // namespace internal |
| 170 } // namespace v8 | 166 } // namespace v8 |
| OLD | NEW |