| 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 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 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/sampler.h" | 30 #include "src/sampler.h" |
| 31 #include "src/vm-state-inl.h" |
| 31 #include "test/cctest/cctest.h" | 32 #include "test/cctest/cctest.h" |
| 32 | 33 |
| 33 namespace v8 { | 34 namespace v8 { |
| 34 namespace internal { | 35 namespace internal { |
| 35 | 36 |
| 36 const char* TraceExtension::kSource = | 37 const char* TraceExtension::kSource = |
| 37 "native function trace();" | 38 "native function trace();" |
| 38 "native function js_trace();" | 39 "native function js_trace();" |
| 39 "native function js_entry_sp();" | 40 "native function js_entry_sp();" |
| 40 "native function js_entry_sp_level2();"; | 41 "native function js_entry_sp_level2();"; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 regs.fp = fp; | 91 regs.fp = fp; |
| 91 // sp is only used to define stack high bound | 92 // sp is only used to define stack high bound |
| 92 regs.sp = | 93 regs.sp = |
| 93 reinterpret_cast<Address>(trace_env.sample) - 10240; | 94 reinterpret_cast<Address>(trace_env.sample) - 10240; |
| 94 trace_env.sample->Init(CcTest::i_isolate(), regs, | 95 trace_env.sample->Init(CcTest::i_isolate(), regs, |
| 95 TickSample::kSkipCEntryFrame); | 96 TickSample::kSkipCEntryFrame); |
| 96 } | 97 } |
| 97 | 98 |
| 98 | 99 |
| 99 void TraceExtension::Trace(const v8::FunctionCallbackInfo<v8::Value>& args) { | 100 void TraceExtension::Trace(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 101 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 102 i::VMState<EXTERNAL> state(isolate); |
| 103 Address address = reinterpret_cast<Address>( |
| 104 reinterpret_cast<intptr_t>(&TraceExtension::Trace)); |
| 105 i::ExternalCallbackScope call_scope(isolate, address); |
| 100 DoTrace(GetFP(args)); | 106 DoTrace(GetFP(args)); |
| 101 } | 107 } |
| 102 | 108 |
| 103 | 109 |
| 104 // Hide c_entry_fp to emulate situation when sampling is done while | 110 // Hide c_entry_fp to emulate situation when sampling is done while |
| 105 // pure JS code is being executed | 111 // pure JS code is being executed |
| 106 static void DoTraceHideCEntryFPAddress(Address fp) { | 112 static void DoTraceHideCEntryFPAddress(Address fp) { |
| 107 v8::internal::Address saved_c_frame_fp = | 113 v8::internal::Address saved_c_frame_fp = |
| 108 *(CcTest::i_isolate()->c_entry_fp_address()); | 114 *(CcTest::i_isolate()->c_entry_fp_address()); |
| 109 CHECK(saved_c_frame_fp); | 115 CHECK(saved_c_frame_fp); |
| 110 *(CcTest::i_isolate()->c_entry_fp_address()) = 0; | 116 *(CcTest::i_isolate()->c_entry_fp_address()) = 0; |
| 111 i::TraceExtension::DoTrace(fp); | 117 i::TraceExtension::DoTrace(fp); |
| 112 *(CcTest::i_isolate()->c_entry_fp_address()) = saved_c_frame_fp; | 118 *(CcTest::i_isolate()->c_entry_fp_address()) = saved_c_frame_fp; |
| 113 } | 119 } |
| 114 | 120 |
| 115 | 121 |
| 116 void TraceExtension::JSTrace(const v8::FunctionCallbackInfo<v8::Value>& args) { | 122 void TraceExtension::JSTrace(const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 123 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); |
| 124 i::VMState<EXTERNAL> state(isolate); |
| 125 Address address = reinterpret_cast<Address>( |
| 126 reinterpret_cast<intptr_t>(&TraceExtension::JSTrace)); |
| 127 i::ExternalCallbackScope call_scope(isolate, address); |
| 117 DoTraceHideCEntryFPAddress(GetFP(args)); | 128 DoTraceHideCEntryFPAddress(GetFP(args)); |
| 118 } | 129 } |
| 119 | 130 |
| 120 | 131 |
| 121 Address TraceExtension::GetJsEntrySp() { | 132 Address TraceExtension::GetJsEntrySp() { |
| 122 CHECK_NE(NULL, CcTest::i_isolate()->thread_local_top()); | 133 CHECK_NE(NULL, CcTest::i_isolate()->thread_local_top()); |
| 123 return CcTest::i_isolate()->js_entry_sp(); | 134 return CcTest::i_isolate()->js_entry_sp(); |
| 124 } | 135 } |
| 125 | 136 |
| 126 | 137 |
| 127 void TraceExtension::JSEntrySP( | 138 void TraceExtension::JSEntrySP( |
| 128 const v8::FunctionCallbackInfo<v8::Value>& args) { | 139 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 129 CHECK_NE(0, GetJsEntrySp()); | 140 CHECK_NE(0, GetJsEntrySp()); |
| 130 } | 141 } |
| 131 | 142 |
| 132 | 143 |
| 133 void TraceExtension::JSEntrySPLevel2( | 144 void TraceExtension::JSEntrySPLevel2( |
| 134 const v8::FunctionCallbackInfo<v8::Value>& args) { | 145 const v8::FunctionCallbackInfo<v8::Value>& args) { |
| 135 v8::HandleScope scope(args.GetIsolate()); | 146 v8::HandleScope scope(args.GetIsolate()); |
| 136 const Address js_entry_sp = GetJsEntrySp(); | 147 const Address js_entry_sp = GetJsEntrySp(); |
| 137 CHECK_NE(0, js_entry_sp); | 148 CHECK_NE(0, js_entry_sp); |
| 138 CompileRun("js_entry_sp();"); | 149 CompileRun("js_entry_sp();"); |
| 139 CHECK_EQ(js_entry_sp, GetJsEntrySp()); | 150 CHECK_EQ(js_entry_sp, GetJsEntrySp()); |
| 140 } | 151 } |
| 141 | 152 |
| 142 | 153 |
| 143 } } // namespace v8::internal | 154 } } // namespace v8::internal |
| OLD | NEW |