OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 // Tests the sampling API in include/v8.h | 5 // Tests the sampling API in include/v8.h |
6 | 6 |
| 7 // TODO(mythria): Remove this define after this flag is turned on globally |
| 8 #define V8_IMMINENT_DEPRECATION_WARNINGS |
| 9 |
7 #include <map> | 10 #include <map> |
8 #include <string> | 11 #include <string> |
9 #include "include/v8.h" | 12 #include "include/v8.h" |
10 #include "src/simulator.h" | 13 #include "src/simulator.h" |
11 #include "test/cctest/cctest.h" | 14 #include "test/cctest/cctest.h" |
12 | 15 |
13 namespace { | 16 namespace { |
14 | 17 |
15 class Sample { | 18 class Sample { |
16 public: | 19 public: |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 const void* code_start; | 90 const void* code_start; |
88 size_t code_len; | 91 size_t code_len; |
89 }; | 92 }; |
90 typedef std::map<const void*, CodeEventEntry> CodeEntries; | 93 typedef std::map<const void*, CodeEventEntry> CodeEntries; |
91 | 94 |
92 explicit SamplingTestHelper(const std::string& test_function) | 95 explicit SamplingTestHelper(const std::string& test_function) |
93 : sample_is_taken_(false), isolate_(CcTest::isolate()) { | 96 : sample_is_taken_(false), isolate_(CcTest::isolate()) { |
94 DCHECK(!instance_); | 97 DCHECK(!instance_); |
95 instance_ = this; | 98 instance_ = this; |
96 v8::HandleScope scope(isolate_); | 99 v8::HandleScope scope(isolate_); |
97 v8::Handle<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_); | 100 v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate_); |
98 global->Set(v8::String::NewFromUtf8(isolate_, "CollectSample"), | 101 global->Set(v8_str("CollectSample"), |
99 v8::FunctionTemplate::New(isolate_, CollectSample)); | 102 v8::FunctionTemplate::New(isolate_, CollectSample)); |
100 LocalContext env(isolate_, NULL, global); | 103 LocalContext env(isolate_, NULL, global); |
101 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, | 104 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, |
102 JitCodeEventHandler); | 105 JitCodeEventHandler); |
103 v8::Script::Compile( | 106 CompileRun(v8_str(test_function.c_str())); |
104 v8::String::NewFromUtf8(isolate_, test_function.c_str()))->Run(); | |
105 } | 107 } |
106 | 108 |
107 ~SamplingTestHelper() { | 109 ~SamplingTestHelper() { |
108 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); | 110 isolate_->SetJitCodeEventHandler(v8::kJitCodeEventDefault, NULL); |
109 instance_ = NULL; | 111 instance_ = NULL; |
110 } | 112 } |
111 | 113 |
112 Sample& sample() { return sample_; } | 114 Sample& sample() { return sample_; } |
113 | 115 |
114 const CodeEventEntry* FindEventEntry(const void* address) { | 116 const CodeEventEntry* FindEventEntry(const void* address) { |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 244 |
243 const SamplingTestHelper::CodeEventEntry* entry; | 245 const SamplingTestHelper::CodeEventEntry* entry; |
244 entry = helper.FindEventEntry(sample.begin()[0]); | 246 entry = helper.FindEventEntry(sample.begin()[0]); |
245 CHECK(entry); | 247 CHECK(entry); |
246 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); | 248 CHECK(std::string::npos != entry->name.find("test_sampler_api_inner")); |
247 | 249 |
248 entry = helper.FindEventEntry(sample.begin()[1]); | 250 entry = helper.FindEventEntry(sample.begin()[1]); |
249 CHECK(entry); | 251 CHECK(entry); |
250 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); | 252 CHECK(std::string::npos != entry->name.find("test_sampler_api_outer")); |
251 } | 253 } |
OLD | NEW |