Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(74)

Side by Side Diff: src/api.cc

Issue 358363002: Move platform abstraction to base library (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
11 #include <cmath> // For isnan. 11 #include <cmath> // For isnan.
12 #include "include/v8-debug.h" 12 #include "include/v8-debug.h"
13 #include "include/v8-profiler.h" 13 #include "include/v8-profiler.h"
14 #include "include/v8-testing.h" 14 #include "include/v8-testing.h"
15 #include "src/assert-scope.h" 15 #include "src/assert-scope.h"
16 #include "src/base/platform/platform.h"
17 #include "src/base/platform/time.h"
18 #include "src/base/utils/random-number-generator.h"
16 #include "src/bootstrapper.h" 19 #include "src/bootstrapper.h"
17 #include "src/code-stubs.h" 20 #include "src/code-stubs.h"
18 #include "src/compiler.h" 21 #include "src/compiler.h"
19 #include "src/conversions-inl.h" 22 #include "src/conversions-inl.h"
20 #include "src/counters.h" 23 #include "src/counters.h"
21 #include "src/cpu-profiler.h" 24 #include "src/cpu-profiler.h"
22 #include "src/debug.h" 25 #include "src/debug.h"
23 #include "src/deoptimizer.h" 26 #include "src/deoptimizer.h"
24 #include "src/execution.h" 27 #include "src/execution.h"
25 #include "src/global-handles.h" 28 #include "src/global-handles.h"
26 #include "src/heap-profiler.h" 29 #include "src/heap-profiler.h"
27 #include "src/heap-snapshot-generator-inl.h" 30 #include "src/heap-snapshot-generator-inl.h"
28 #include "src/icu_util.h" 31 #include "src/icu_util.h"
29 #include "src/json-parser.h" 32 #include "src/json-parser.h"
30 #include "src/messages.h" 33 #include "src/messages.h"
31 #include "src/natives.h" 34 #include "src/natives.h"
32 #include "src/parser.h" 35 #include "src/parser.h"
33 #include "src/platform.h"
34 #include "src/platform/time.h"
35 #include "src/profile-generator-inl.h" 36 #include "src/profile-generator-inl.h"
36 #include "src/property.h" 37 #include "src/property.h"
37 #include "src/property-details.h" 38 #include "src/property-details.h"
38 #include "src/runtime.h" 39 #include "src/runtime.h"
39 #include "src/runtime-profiler.h" 40 #include "src/runtime-profiler.h"
40 #include "src/scanner-character-streams.h" 41 #include "src/scanner-character-streams.h"
41 #include "src/simulator.h" 42 #include "src/simulator.h"
42 #include "src/snapshot.h" 43 #include "src/snapshot.h"
43 #include "src/unicode-inl.h" 44 #include "src/unicode-inl.h"
44 #include "src/utils/random-number-generator.h"
45 #include "src/v8threads.h" 45 #include "src/v8threads.h"
46 #include "src/version.h" 46 #include "src/version.h"
47 #include "src/vm-state-inl.h" 47 #include "src/vm-state-inl.h"
48 48
49 49
50 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) 50 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
51 51
52 #define ENTER_V8(isolate) \ 52 #define ENTER_V8(isolate) \
53 ASSERT((isolate)->IsInitialized()); \ 53 ASSERT((isolate)->IsInitialized()); \
54 i::VMState<i::OTHER> __state__((isolate)) 54 i::VMState<i::OTHER> __state__((isolate))
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 Utils::ApiCheck(false, location, "Allocation failed - process out of memory"); 167 Utils::ApiCheck(false, location, "Allocation failed - process out of memory");
168 // If the fatal error handler returns, we stop execution. 168 // If the fatal error handler returns, we stop execution.
169 FATAL("API fatal error handler returned after process out of memory"); 169 FATAL("API fatal error handler returned after process out of memory");
170 } 170 }
171 171
172 172
173 void Utils::ReportApiFailure(const char* location, const char* message) { 173 void Utils::ReportApiFailure(const char* location, const char* message) {
174 i::Isolate* isolate = i::Isolate::Current(); 174 i::Isolate* isolate = i::Isolate::Current();
175 FatalErrorCallback callback = isolate->exception_behavior(); 175 FatalErrorCallback callback = isolate->exception_behavior();
176 if (callback == NULL) { 176 if (callback == NULL) {
177 i::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", 177 base::OS::PrintError("\n#\n# Fatal error in %s\n# %s\n#\n\n", location,
178 location, message); 178 message);
179 i::OS::Abort(); 179 base::OS::Abort();
180 } else { 180 } else {
181 callback(location, message); 181 callback(location, message);
182 } 182 }
183 isolate->SignalFatalError(); 183 isolate->SignalFatalError();
184 } 184 }
185 185
186 186
187 bool V8::IsDead() { 187 bool V8::IsDead() {
188 i::Isolate* isolate = i::Isolate::Current(); 188 i::Isolate* isolate = i::Isolate::Current();
189 return isolate->IsDead(); 189 return isolate->IsDead();
(...skipping 2626 matching lines...) Expand 10 before | Expand all | Expand 10 after
2816 i::Handle<i::Object> num; 2816 i::Handle<i::Object> num;
2817 if (obj->IsNumber()) { 2817 if (obj->IsNumber()) {
2818 num = obj; 2818 num = obj;
2819 } else { 2819 } else {
2820 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate(); 2820 i::Isolate* isolate = i::HeapObject::cast(*obj)->GetIsolate();
2821 LOG_API(isolate, "NumberValue"); 2821 LOG_API(isolate, "NumberValue");
2822 ENTER_V8(isolate); 2822 ENTER_V8(isolate);
2823 EXCEPTION_PREAMBLE(isolate); 2823 EXCEPTION_PREAMBLE(isolate);
2824 has_pending_exception = !i::Execution::ToNumber( 2824 has_pending_exception = !i::Execution::ToNumber(
2825 isolate, obj).ToHandle(&num); 2825 isolate, obj).ToHandle(&num);
2826 EXCEPTION_BAILOUT_CHECK(isolate, i::OS::nan_value()); 2826 EXCEPTION_BAILOUT_CHECK(isolate, base::OS::nan_value());
2827 } 2827 }
2828 return num->Number(); 2828 return num->Number();
2829 } 2829 }
2830 2830
2831 2831
2832 int64_t Value::IntegerValue() const { 2832 int64_t Value::IntegerValue() const {
2833 i::Handle<i::Object> obj = Utils::OpenHandle(this); 2833 i::Handle<i::Object> obj = Utils::OpenHandle(this);
2834 i::Handle<i::Object> num; 2834 i::Handle<i::Object> num;
2835 if (obj->IsNumber()) { 2835 if (obj->IsNumber()) {
2836 num = obj; 2836 num = obj;
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
4952 bool v8::V8::Initialize() { 4952 bool v8::V8::Initialize() {
4953 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); 4953 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
4954 if (isolate != NULL && isolate->IsInitialized()) { 4954 if (isolate != NULL && isolate->IsInitialized()) {
4955 return true; 4955 return true;
4956 } 4956 }
4957 return InitializeHelper(isolate); 4957 return InitializeHelper(isolate);
4958 } 4958 }
4959 4959
4960 4960
4961 void v8::V8::SetEntropySource(EntropySource entropy_source) { 4961 void v8::V8::SetEntropySource(EntropySource entropy_source) {
4962 i::RandomNumberGenerator::SetEntropySource(entropy_source); 4962 base::RandomNumberGenerator::SetEntropySource(entropy_source);
4963 } 4963 }
4964 4964
4965 4965
4966 void v8::V8::SetReturnAddressLocationResolver( 4966 void v8::V8::SetReturnAddressLocationResolver(
4967 ReturnAddressLocationResolver return_address_resolver) { 4967 ReturnAddressLocationResolver return_address_resolver) {
4968 i::V8::SetReturnAddressLocationResolver(return_address_resolver); 4968 i::V8::SetReturnAddressLocationResolver(return_address_resolver);
4969 } 4969 }
4970 4970
4971 4971
4972 bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate, 4972 bool v8::V8::SetFunctionEntryHook(Isolate* ext_isolate,
(...skipping 689 matching lines...) Expand 10 before | Expand all | Expand 10 after
5662 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value()))); 5662 i::Handle<i::Symbol>(i::Symbol::cast(jsvalue->value())));
5663 } 5663 }
5664 5664
5665 5665
5666 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) { 5666 Local<v8::Value> v8::Date::New(Isolate* isolate, double time) {
5667 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5667 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5668 EnsureInitializedForIsolate(i_isolate, "v8::Date::New()"); 5668 EnsureInitializedForIsolate(i_isolate, "v8::Date::New()");
5669 LOG_API(i_isolate, "Date::New"); 5669 LOG_API(i_isolate, "Date::New");
5670 if (std::isnan(time)) { 5670 if (std::isnan(time)) {
5671 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 5671 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
5672 time = i::OS::nan_value(); 5672 time = base::OS::nan_value();
5673 } 5673 }
5674 ENTER_V8(i_isolate); 5674 ENTER_V8(i_isolate);
5675 EXCEPTION_PREAMBLE(i_isolate); 5675 EXCEPTION_PREAMBLE(i_isolate);
5676 i::Handle<i::Object> obj; 5676 i::Handle<i::Object> obj;
5677 has_pending_exception = !i::Execution::NewDate( 5677 has_pending_exception = !i::Execution::NewDate(
5678 i_isolate, time).ToHandle(&obj); 5678 i_isolate, time).ToHandle(&obj);
5679 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::Value>()); 5679 EXCEPTION_BAILOUT_CHECK(i_isolate, Local<v8::Value>());
5680 return Utils::ToLocal(obj); 5680 return Utils::ToLocal(obj);
5681 } 5681 }
5682 5682
(...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after
6232 Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); 6232 Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
6233 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); 6233 return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6234 } 6234 }
6235 6235
6236 6236
6237 Local<Number> v8::Number::New(Isolate* isolate, double value) { 6237 Local<Number> v8::Number::New(Isolate* isolate, double value) {
6238 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6238 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6239 ASSERT(internal_isolate->IsInitialized()); 6239 ASSERT(internal_isolate->IsInitialized());
6240 if (std::isnan(value)) { 6240 if (std::isnan(value)) {
6241 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 6241 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
6242 value = i::OS::nan_value(); 6242 value = base::OS::nan_value();
6243 } 6243 }
6244 ENTER_V8(internal_isolate); 6244 ENTER_V8(internal_isolate);
6245 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); 6245 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6246 return Utils::NumberToLocal(result); 6246 return Utils::NumberToLocal(result);
6247 } 6247 }
6248 6248
6249 6249
6250 Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) { 6250 Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
6251 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6251 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6252 ASSERT(internal_isolate->IsInitialized()); 6252 ASSERT(internal_isolate->IsInitialized());
(...skipping 835 matching lines...) Expand 10 before | Expand all | Expand 10 after
7088 7088
7089 7089
7090 const CpuProfileNode* CpuProfile::GetSample(int index) const { 7090 const CpuProfileNode* CpuProfile::GetSample(int index) const {
7091 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7091 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7092 return reinterpret_cast<const CpuProfileNode*>(profile->sample(index)); 7092 return reinterpret_cast<const CpuProfileNode*>(profile->sample(index));
7093 } 7093 }
7094 7094
7095 7095
7096 int64_t CpuProfile::GetSampleTimestamp(int index) const { 7096 int64_t CpuProfile::GetSampleTimestamp(int index) const {
7097 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7097 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7098 return (profile->sample_timestamp(index) - i::TimeTicks()).InMicroseconds(); 7098 return (profile->sample_timestamp(index) - base::TimeTicks())
7099 .InMicroseconds();
7099 } 7100 }
7100 7101
7101 7102
7102 int64_t CpuProfile::GetStartTime() const { 7103 int64_t CpuProfile::GetStartTime() const {
7103 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7104 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7104 return (profile->start_time() - i::TimeTicks()).InMicroseconds(); 7105 return (profile->start_time() - base::TimeTicks()).InMicroseconds();
7105 } 7106 }
7106 7107
7107 7108
7108 int64_t CpuProfile::GetEndTime() const { 7109 int64_t CpuProfile::GetEndTime() const {
7109 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this); 7110 const i::CpuProfile* profile = reinterpret_cast<const i::CpuProfile*>(this);
7110 return (profile->end_time() - i::TimeTicks()).InMicroseconds(); 7111 return (profile->end_time() - base::TimeTicks()).InMicroseconds();
7111 } 7112 }
7112 7113
7113 7114
7114 int CpuProfile::GetSamplesCount() const { 7115 int CpuProfile::GetSamplesCount() const {
7115 return reinterpret_cast<const i::CpuProfile*>(this)->samples_count(); 7116 return reinterpret_cast<const i::CpuProfile*>(this)->samples_count();
7116 } 7117 }
7117 7118
7118 7119
7119 void CpuProfiler::SetSamplingInterval(int us) { 7120 void CpuProfiler::SetSamplingInterval(int us) {
7120 ASSERT(us >= 0); 7121 ASSERT(us >= 0);
7121 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval( 7122 return reinterpret_cast<i::CpuProfiler*>(this)->set_sampling_interval(
7122 i::TimeDelta::FromMicroseconds(us)); 7123 base::TimeDelta::FromMicroseconds(us));
7123 } 7124 }
7124 7125
7125 7126
7126 void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) { 7127 void CpuProfiler::StartProfiling(Handle<String> title, bool record_samples) {
7127 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling( 7128 reinterpret_cast<i::CpuProfiler*>(this)->StartProfiling(
7128 *Utils::OpenHandle(*title), record_samples); 7129 *Utils::OpenHandle(*title), record_samples);
7129 } 7130 }
7130 7131
7131 7132
7132 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) { 7133 void CpuProfiler::StartCpuProfiling(Handle<String> title, bool record_samples) {
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
7630 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7631 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7631 Address callback_address = 7632 Address callback_address =
7632 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7633 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7633 VMState<EXTERNAL> state(isolate); 7634 VMState<EXTERNAL> state(isolate);
7634 ExternalCallbackScope call_scope(isolate, callback_address); 7635 ExternalCallbackScope call_scope(isolate, callback_address);
7635 callback(info); 7636 callback(info);
7636 } 7637 }
7637 7638
7638 7639
7639 } } // namespace v8::internal 7640 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/allocation-tracker.cc ('k') | src/arm/assembler-arm.cc » ('j') | src/base/cpu.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698