| OLD | NEW | 
|---|
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 // Tests of profiler-related functions from log.h | 28 // Tests of profiler-related functions from log.h | 
| 29 | 29 | 
|  | 30 // TODO(jochen): Remove this after the setting is turned on globally. | 
|  | 31 #define V8_IMMINENT_DEPRECATION_WARNINGS | 
|  | 32 | 
| 30 #include <stdlib.h> | 33 #include <stdlib.h> | 
| 31 | 34 | 
| 32 #include "src/v8.h" | 35 #include "src/v8.h" | 
| 33 | 36 | 
| 34 #include "src/api.h" | 37 #include "src/api.h" | 
| 35 #include "src/codegen.h" | 38 #include "src/codegen.h" | 
| 36 #include "src/disassembler.h" | 39 #include "src/disassembler.h" | 
| 37 #include "src/isolate.h" | 40 #include "src/isolate.h" | 
| 38 #include "src/log.h" | 41 #include "src/log.h" | 
| 39 #include "src/profiler/sampler.h" | 42 #include "src/profiler/sampler.h" | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
| 58 | 61 | 
| 59 static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) { | 62 static bool IsAddressWithinFuncCode(JSFunction* function, Address addr) { | 
| 60   i::Code* code = function->code(); | 63   i::Code* code = function->code(); | 
| 61   return code->contains(addr); | 64   return code->contains(addr); | 
| 62 } | 65 } | 
| 63 | 66 | 
| 64 | 67 | 
| 65 static bool IsAddressWithinFuncCode(v8::Local<v8::Context> context, | 68 static bool IsAddressWithinFuncCode(v8::Local<v8::Context> context, | 
| 66                                     const char* func_name, | 69                                     const char* func_name, | 
| 67                                     Address addr) { | 70                                     Address addr) { | 
| 68   v8::Local<v8::Value> func = context->Global()->Get(v8_str(func_name)); | 71   v8::Local<v8::Value> func = | 
|  | 72       context->Global()->Get(context, v8_str(func_name)).ToLocalChecked(); | 
| 69   CHECK(func->IsFunction()); | 73   CHECK(func->IsFunction()); | 
| 70   JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func)); | 74   JSFunction* js_func = JSFunction::cast(*v8::Utils::OpenHandle(*func)); | 
| 71   return IsAddressWithinFuncCode(js_func, addr); | 75   return IsAddressWithinFuncCode(js_func, addr); | 
| 72 } | 76 } | 
| 73 | 77 | 
| 74 | 78 | 
| 75 // This C++ function is called as a constructor, to grab the frame pointer | 79 // This C++ function is called as a constructor, to grab the frame pointer | 
| 76 // from the calling function.  When this function runs, the stack contains | 80 // from the calling function.  When this function runs, the stack contains | 
| 77 // a C_Entry frame and a Construct frame above the calling function's frame. | 81 // a C_Entry frame and a Construct frame above the calling function's frame. | 
| 78 static void construct_call(const v8::FunctionCallbackInfo<v8::Value>& args) { | 82 static void construct_call(const v8::FunctionCallbackInfo<v8::Value>& args) { | 
| 79   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 83   i::Isolate* isolate = reinterpret_cast<i::Isolate*>(args.GetIsolate()); | 
| 80   i::StackFrameIterator frame_iterator(isolate); | 84   i::StackFrameIterator frame_iterator(isolate); | 
| 81   CHECK(frame_iterator.frame()->is_exit()); | 85   CHECK(frame_iterator.frame()->is_exit()); | 
| 82   frame_iterator.Advance(); | 86   frame_iterator.Advance(); | 
| 83   CHECK(frame_iterator.frame()->is_construct()); | 87   CHECK(frame_iterator.frame()->is_construct()); | 
| 84   frame_iterator.Advance(); | 88   frame_iterator.Advance(); | 
| 85   i::StackFrame* calling_frame = frame_iterator.frame(); | 89   i::StackFrame* calling_frame = frame_iterator.frame(); | 
| 86   CHECK(calling_frame->is_java_script()); | 90   CHECK(calling_frame->is_java_script()); | 
| 87 | 91 | 
|  | 92   v8::Local<v8::Context> context = args.GetIsolate()->GetCurrentContext(); | 
| 88 #if defined(V8_HOST_ARCH_32_BIT) | 93 #if defined(V8_HOST_ARCH_32_BIT) | 
| 89   int32_t low_bits = reinterpret_cast<int32_t>(calling_frame->fp()); | 94   int32_t low_bits = reinterpret_cast<int32_t>(calling_frame->fp()); | 
| 90   args.This()->Set(v8_str("low_bits"), v8_num(low_bits >> 1)); | 95   args.This() | 
|  | 96       ->Set(context, v8_str("low_bits"), v8_num(low_bits >> 1)) | 
|  | 97       .FromJust(); | 
| 91 #elif defined(V8_HOST_ARCH_64_BIT) | 98 #elif defined(V8_HOST_ARCH_64_BIT) | 
| 92   uint64_t fp = reinterpret_cast<uint64_t>(calling_frame->fp()); | 99   uint64_t fp = reinterpret_cast<uint64_t>(calling_frame->fp()); | 
| 93   int32_t low_bits = static_cast<int32_t>(fp & 0xffffffff); | 100   int32_t low_bits = static_cast<int32_t>(fp & 0xffffffff); | 
| 94   int32_t high_bits = static_cast<int32_t>(fp >> 32); | 101   int32_t high_bits = static_cast<int32_t>(fp >> 32); | 
| 95   args.This()->Set(v8_str("low_bits"), v8_num(low_bits)); | 102   args.This()->Set(context, v8_str("low_bits"), v8_num(low_bits)).FromJust(); | 
| 96   args.This()->Set(v8_str("high_bits"), v8_num(high_bits)); | 103   args.This()->Set(context, v8_str("high_bits"), v8_num(high_bits)).FromJust(); | 
| 97 #else | 104 #else | 
| 98 #error Host architecture is neither 32-bit nor 64-bit. | 105 #error Host architecture is neither 32-bit nor 64-bit. | 
| 99 #endif | 106 #endif | 
| 100   args.GetReturnValue().Set(args.This()); | 107   args.GetReturnValue().Set(args.This()); | 
| 101 } | 108 } | 
| 102 | 109 | 
| 103 | 110 | 
| 104 // Use the API to create a JSFunction object that calls the above C++ function. | 111 // Use the API to create a JSFunction object that calls the above C++ function. | 
| 105 void CreateFramePointerGrabberConstructor(v8::Local<v8::Context> context, | 112 void CreateFramePointerGrabberConstructor(v8::Local<v8::Context> context, | 
| 106                                           const char* constructor_name) { | 113                                           const char* constructor_name) { | 
| 107     Local<v8::FunctionTemplate> constructor_template = | 114     Local<v8::FunctionTemplate> constructor_template = | 
| 108         v8::FunctionTemplate::New(context->GetIsolate(), construct_call); | 115         v8::FunctionTemplate::New(context->GetIsolate(), construct_call); | 
| 109     constructor_template->SetClassName(v8_str("FPGrabber")); | 116     constructor_template->SetClassName(v8_str("FPGrabber")); | 
| 110     Local<Function> fun = constructor_template->GetFunction(); | 117     Local<Function> fun = | 
| 111     context->Global()->Set(v8_str(constructor_name), fun); | 118         constructor_template->GetFunction(context).ToLocalChecked(); | 
|  | 119     context->Global()->Set(context, v8_str(constructor_name), fun).FromJust(); | 
| 112 } | 120 } | 
| 113 | 121 | 
| 114 | 122 | 
| 115 // Creates a global function named 'func_name' that calls the tracing | 123 // Creates a global function named 'func_name' that calls the tracing | 
| 116 // function 'trace_func_name' with an actual EBP register value, | 124 // function 'trace_func_name' with an actual EBP register value, | 
| 117 // encoded as one or two Smis. | 125 // encoded as one or two Smis. | 
| 118 static void CreateTraceCallerFunction(v8::Local<v8::Context> context, | 126 static void CreateTraceCallerFunction(v8::Local<v8::Context> context, | 
| 119                                       const char* func_name, | 127                                       const char* func_name, | 
| 120                                       const char* trace_func_name) { | 128                                       const char* trace_func_name) { | 
| 121   i::EmbeddedVector<char, 256> trace_call_buf; | 129   i::EmbeddedVector<char, 256> trace_call_buf; | 
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 279   v8::Local<v8::Context> context = CcTest::NewContext(TRACE_EXTENSION); | 287   v8::Local<v8::Context> context = CcTest::NewContext(TRACE_EXTENSION); | 
| 280   v8::Context::Scope context_scope(context); | 288   v8::Context::Scope context_scope(context); | 
| 281   CHECK(!i::TraceExtension::GetJsEntrySp()); | 289   CHECK(!i::TraceExtension::GetJsEntrySp()); | 
| 282   CompileRun("a = 1; b = a + 1;"); | 290   CompileRun("a = 1; b = a + 1;"); | 
| 283   CHECK(!i::TraceExtension::GetJsEntrySp()); | 291   CHECK(!i::TraceExtension::GetJsEntrySp()); | 
| 284   CompileRun("js_entry_sp();"); | 292   CompileRun("js_entry_sp();"); | 
| 285   CHECK(!i::TraceExtension::GetJsEntrySp()); | 293   CHECK(!i::TraceExtension::GetJsEntrySp()); | 
| 286   CompileRun("js_entry_sp_level2();"); | 294   CompileRun("js_entry_sp_level2();"); | 
| 287   CHECK(!i::TraceExtension::GetJsEntrySp()); | 295   CHECK(!i::TraceExtension::GetJsEntrySp()); | 
| 288 } | 296 } | 
| OLD | NEW | 
|---|