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

Side by Side Diff: src/api.cc

Issue 633363002: Get rid of isolate state. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 2 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
« no previous file with comments | « no previous file | src/heap/heap.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "src/snapshot.h" 46 #include "src/snapshot.h"
47 #include "src/unicode-inl.h" 47 #include "src/unicode-inl.h"
48 #include "src/v8threads.h" 48 #include "src/v8threads.h"
49 #include "src/version.h" 49 #include "src/version.h"
50 #include "src/vm-state-inl.h" 50 #include "src/vm-state-inl.h"
51 51
52 52
53 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr)) 53 #define LOG_API(isolate, expr) LOG(isolate, ApiEntryCall(expr))
54 54
55 #define ENTER_V8(isolate) \ 55 #define ENTER_V8(isolate) \
56 DCHECK((isolate)->IsInitialized()); \
57 i::VMState<v8::OTHER> __state__((isolate)) 56 i::VMState<v8::OTHER> __state__((isolate))
58 57
59 namespace v8 { 58 namespace v8 {
60 59
61 #define ON_BAILOUT(isolate, location, code) \ 60 #define ON_BAILOUT(isolate, location, code) \
62 if (IsExecutionTerminatingCheck(isolate)) { \ 61 if (IsExecutionTerminatingCheck(isolate)) { \
63 code; \ 62 code; \
64 UNREACHABLE(); \ 63 UNREACHABLE(); \
65 } 64 }
66 65
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 } 186 }
188 187
189 188
190 bool V8::IsDead() { 189 bool V8::IsDead() {
191 i::Isolate* isolate = i::Isolate::Current(); 190 i::Isolate* isolate = i::Isolate::Current();
192 return isolate->IsDead(); 191 return isolate->IsDead();
193 } 192 }
194 193
195 194
196 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) { 195 static inline bool IsExecutionTerminatingCheck(i::Isolate* isolate) {
197 if (!isolate->IsInitialized()) return false;
198 if (isolate->has_scheduled_exception()) { 196 if (isolate->has_scheduled_exception()) {
199 return isolate->scheduled_exception() == 197 return isolate->scheduled_exception() ==
200 isolate->heap()->termination_exception(); 198 isolate->heap()->termination_exception();
201 } 199 }
202 return false; 200 return false;
203 } 201 }
204 202
205 203
206 StartupDataDecompressor::StartupDataDecompressor() 204 StartupDataDecompressor::StartupDataDecompressor()
207 : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) { 205 : raw_data(i::NewArray<char*>(V8::GetCompressedStartupDataCount())) {
(...skipping 2475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2683 isolate, obj).ToHandle(&num); 2681 isolate, obj).ToHandle(&num);
2684 EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>()); 2682 EXCEPTION_BAILOUT_CHECK(isolate, Local<Integer>());
2685 } 2683 }
2686 return ToApiHandle<Integer>(num); 2684 return ToApiHandle<Integer>(num);
2687 } 2685 }
2688 2686
2689 2687
2690 void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) { 2688 void i::Internals::CheckInitializedImpl(v8::Isolate* external_isolate) {
2691 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate); 2689 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(external_isolate);
2692 Utils::ApiCheck(isolate != NULL && 2690 Utils::ApiCheck(isolate != NULL &&
2693 isolate->IsInitialized() &&
2694 !isolate->IsDead(), 2691 !isolate->IsDead(),
2695 "v8::internal::Internals::CheckInitialized()", 2692 "v8::internal::Internals::CheckInitialized()",
2696 "Isolate is not initialized or V8 has died"); 2693 "Isolate is not initialized or V8 has died");
2697 } 2694 }
2698 2695
2699 2696
2700 void External::CheckCast(v8::Value* that) { 2697 void External::CheckCast(v8::Value* that) {
2701 Utils::ApiCheck(Utils::OpenHandle(that)->IsExternal(), 2698 Utils::ApiCheck(Utils::OpenHandle(that)->IsExternal(),
2702 "v8::External::Cast()", 2699 "v8::External::Cast()",
2703 "Could not convert to external"); 2700 "Could not convert to external");
(...skipping 3025 matching lines...) Expand 10 before | Expand all | Expand 10 after
5729 i::Handle<i::Object> obj = Utils::OpenHandle(this); 5726 i::Handle<i::Object> obj = Utils::OpenHandle(this);
5730 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj); 5727 i::Handle<i::JSDate> jsdate = i::Handle<i::JSDate>::cast(obj);
5731 i::Isolate* isolate = jsdate->GetIsolate(); 5728 i::Isolate* isolate = jsdate->GetIsolate();
5732 LOG_API(isolate, "Date::NumberValue"); 5729 LOG_API(isolate, "Date::NumberValue");
5733 return jsdate->value()->Number(); 5730 return jsdate->value()->Number();
5734 } 5731 }
5735 5732
5736 5733
5737 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) { 5734 void v8::Date::DateTimeConfigurationChangeNotification(Isolate* isolate) {
5738 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5735 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5739 if (!i_isolate->IsInitialized()) return;
5740 ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()", 5736 ON_BAILOUT(i_isolate, "v8::Date::DateTimeConfigurationChangeNotification()",
5741 return); 5737 return);
5742 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification"); 5738 LOG_API(i_isolate, "Date::DateTimeConfigurationChangeNotification");
5743 ENTER_V8(i_isolate); 5739 ENTER_V8(i_isolate);
5744 5740
5745 i_isolate->date_cache()->ResetDateCache(); 5741 i_isolate->date_cache()->ResetDateCache();
5746 5742
5747 if (!i_isolate->eternal_handles()->Exists( 5743 if (!i_isolate->eternal_handles()->Exists(
5748 i::EternalHandles::DATE_CACHE_VERSION)) { 5744 i::EternalHandles::DATE_CACHE_VERSION)) {
5749 return; 5745 return;
(...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after
6277 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name); 6273 i::Handle<i::Symbol>::cast(symbol)->set_name(*i_name);
6278 i::JSObject::SetProperty(privates, i_name, symbol, i::STRICT).Assert(); 6274 i::JSObject::SetProperty(privates, i_name, symbol, i::STRICT).Assert();
6279 } 6275 }
6280 Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol)); 6276 Local<Symbol> result = Utils::ToLocal(i::Handle<i::Symbol>::cast(symbol));
6281 return v8::Handle<Private>(reinterpret_cast<Private*>(*result)); 6277 return v8::Handle<Private>(reinterpret_cast<Private*>(*result));
6282 } 6278 }
6283 6279
6284 6280
6285 Local<Number> v8::Number::New(Isolate* isolate, double value) { 6281 Local<Number> v8::Number::New(Isolate* isolate, double value) {
6286 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6282 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6287 DCHECK(internal_isolate->IsInitialized());
6288 if (std::isnan(value)) { 6283 if (std::isnan(value)) {
6289 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 6284 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
6290 value = base::OS::nan_value(); 6285 value = base::OS::nan_value();
6291 } 6286 }
6292 ENTER_V8(internal_isolate); 6287 ENTER_V8(internal_isolate);
6293 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); 6288 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6294 return Utils::NumberToLocal(result); 6289 return Utils::NumberToLocal(result);
6295 } 6290 }
6296 6291
6297 6292
6298 Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) { 6293 Local<Integer> v8::Integer::New(Isolate* isolate, int32_t value) {
6299 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6294 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6300 DCHECK(internal_isolate->IsInitialized());
6301 if (i::Smi::IsValid(value)) { 6295 if (i::Smi::IsValid(value)) {
6302 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value), 6296 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
6303 internal_isolate)); 6297 internal_isolate));
6304 } 6298 }
6305 ENTER_V8(internal_isolate); 6299 ENTER_V8(internal_isolate);
6306 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); 6300 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6307 return Utils::IntegerToLocal(result); 6301 return Utils::IntegerToLocal(result);
6308 } 6302 }
6309 6303
6310 6304
6311 Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) { 6305 Local<Integer> v8::Integer::NewFromUnsigned(Isolate* isolate, uint32_t value) {
6312 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6306 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6313 DCHECK(internal_isolate->IsInitialized());
6314 bool fits_into_int32_t = (value & (1 << 31)) == 0; 6307 bool fits_into_int32_t = (value & (1 << 31)) == 0;
6315 if (fits_into_int32_t) { 6308 if (fits_into_int32_t) {
6316 return Integer::New(isolate, static_cast<int32_t>(value)); 6309 return Integer::New(isolate, static_cast<int32_t>(value));
6317 } 6310 }
6318 ENTER_V8(internal_isolate); 6311 ENTER_V8(internal_isolate);
6319 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value); 6312 i::Handle<i::Object> result = internal_isolate->factory()->NewNumber(value);
6320 return Utils::IntegerToLocal(result); 6313 return Utils::IntegerToLocal(result);
6321 } 6314 }
6322 6315
6323 6316
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
6591 } 6584 }
6592 6585
6593 6586
6594 Isolate* Isolate::GetCurrent() { 6587 Isolate* Isolate::GetCurrent() {
6595 i::Isolate* isolate = i::Isolate::Current(); 6588 i::Isolate* isolate = i::Isolate::Current();
6596 return reinterpret_cast<Isolate*>(isolate); 6589 return reinterpret_cast<Isolate*>(isolate);
6597 } 6590 }
6598 6591
6599 6592
6600 Isolate* Isolate::New(const Isolate::CreateParams& params) { 6593 Isolate* Isolate::New(const Isolate::CreateParams& params) {
6601 i::Isolate* isolate = new i::Isolate(); 6594 i::Isolate* isolate = new i::Isolate(params.enable_serializer);
6602 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate); 6595 Isolate* v8_isolate = reinterpret_cast<Isolate*>(isolate);
6603 if (params.entry_hook) { 6596 if (params.entry_hook) {
6604 isolate->set_function_entry_hook(params.entry_hook); 6597 isolate->set_function_entry_hook(params.entry_hook);
6605 } 6598 }
6606 if (params.code_event_handler) { 6599 if (params.code_event_handler) {
6607 isolate->InitializeLoggingAndCounters(); 6600 isolate->InitializeLoggingAndCounters();
6608 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault, 6601 isolate->logger()->SetCodeEventHandler(kJitCodeEventDefault,
6609 params.code_event_handler); 6602 params.code_event_handler);
6610 } 6603 }
6611 SetResourceConstraints(isolate, params.constraints); 6604 SetResourceConstraints(isolate, params.constraints);
6612 if (params.enable_serializer) {
6613 isolate->enable_serializer();
6614 }
6615 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this. 6605 // TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
6616 Isolate::Scope isolate_scope(v8_isolate); 6606 Isolate::Scope isolate_scope(v8_isolate);
6617 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) { 6607 if (params.entry_hook || !i::Snapshot::Initialize(isolate)) {
6618 // If the isolate has a function entry hook, it needs to re-build all its 6608 // If the isolate has a function entry hook, it needs to re-build all its
6619 // code stubs with entry hooks embedded, so don't deserialize a snapshot. 6609 // code stubs with entry hooks embedded, so don't deserialize a snapshot.
6620 isolate->Init(NULL); 6610 isolate->Init(NULL);
6621 } 6611 }
6622 return v8_isolate; 6612 return v8_isolate;
6623 } 6613 }
6624 6614
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
6694 } 6684 }
6695 6685
6696 6686
6697 Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() { 6687 Isolate::SuppressMicrotaskExecutionScope::~SuppressMicrotaskExecutionScope() {
6698 isolate_->handle_scope_implementer()->DecrementCallDepth(); 6688 isolate_->handle_scope_implementer()->DecrementCallDepth();
6699 } 6689 }
6700 6690
6701 6691
6702 void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { 6692 void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
6703 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this); 6693 i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
6704 if (!isolate->IsInitialized()) {
6705 heap_statistics->total_heap_size_ = 0;
6706 heap_statistics->total_heap_size_executable_ = 0;
6707 heap_statistics->total_physical_size_ = 0;
6708 heap_statistics->used_heap_size_ = 0;
6709 heap_statistics->heap_size_limit_ = 0;
6710 return;
6711 }
6712 i::Heap* heap = isolate->heap(); 6694 i::Heap* heap = isolate->heap();
6713 heap_statistics->total_heap_size_ = heap->CommittedMemory(); 6695 heap_statistics->total_heap_size_ = heap->CommittedMemory();
6714 heap_statistics->total_heap_size_executable_ = 6696 heap_statistics->total_heap_size_executable_ =
6715 heap->CommittedMemoryExecutable(); 6697 heap->CommittedMemoryExecutable();
6716 heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory(); 6698 heap_statistics->total_physical_size_ = heap->CommittedPhysicalMemory();
6717 heap_statistics->used_heap_size_ = heap->SizeOfObjects(); 6699 heap_statistics->used_heap_size_ = heap->SizeOfObjects();
6718 heap_statistics->heap_size_limit_ = heap->MaxReserved(); 6700 heap_statistics->heap_size_limit_ = heap->MaxReserved();
6719 } 6701 }
6720 6702
6721 6703
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
6997 ClientData* client_data) { 6979 ClientData* client_data) {
6998 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate); 6980 i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
6999 internal_isolate->debug()->EnqueueCommandMessage( 6981 internal_isolate->debug()->EnqueueCommandMessage(
7000 i::Vector<const uint16_t>(command, length), client_data); 6982 i::Vector<const uint16_t>(command, length), client_data);
7001 } 6983 }
7002 6984
7003 6985
7004 Local<Value> Debug::Call(v8::Handle<v8::Function> fun, 6986 Local<Value> Debug::Call(v8::Handle<v8::Function> fun,
7005 v8::Handle<v8::Value> data) { 6987 v8::Handle<v8::Value> data) {
7006 i::Isolate* isolate = i::Isolate::Current(); 6988 i::Isolate* isolate = i::Isolate::Current();
7007 if (!isolate->IsInitialized()) return Local<Value>();
7008 ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>()); 6989 ON_BAILOUT(isolate, "v8::Debug::Call()", return Local<Value>());
7009 ENTER_V8(isolate); 6990 ENTER_V8(isolate);
7010 i::MaybeHandle<i::Object> maybe_result; 6991 i::MaybeHandle<i::Object> maybe_result;
7011 EXCEPTION_PREAMBLE(isolate); 6992 EXCEPTION_PREAMBLE(isolate);
7012 if (data.IsEmpty()) { 6993 if (data.IsEmpty()) {
7013 maybe_result = isolate->debug()->Call( 6994 maybe_result = isolate->debug()->Call(
7014 Utils::OpenHandle(*fun), isolate->factory()->undefined_value()); 6995 Utils::OpenHandle(*fun), isolate->factory()->undefined_value());
7015 } else { 6996 } else {
7016 maybe_result = isolate->debug()->Call( 6997 maybe_result = isolate->debug()->Call(
7017 Utils::OpenHandle(*fun), Utils::OpenHandle(*data)); 6998 Utils::OpenHandle(*fun), Utils::OpenHandle(*data));
7018 } 6999 }
7019 i::Handle<i::Object> result; 7000 i::Handle<i::Object> result;
7020 has_pending_exception = !maybe_result.ToHandle(&result); 7001 has_pending_exception = !maybe_result.ToHandle(&result);
7021 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>()); 7002 EXCEPTION_BAILOUT_CHECK(isolate, Local<Value>());
7022 return Utils::ToLocal(result); 7003 return Utils::ToLocal(result);
7023 } 7004 }
7024 7005
7025 7006
7026 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) { 7007 Local<Value> Debug::GetMirror(v8::Handle<v8::Value> obj) {
7027 i::Isolate* isolate = i::Isolate::Current(); 7008 i::Isolate* isolate = i::Isolate::Current();
7028 if (!isolate->IsInitialized()) return Local<Value>();
7029 ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>()); 7009 ON_BAILOUT(isolate, "v8::Debug::GetMirror()", return Local<Value>());
7030 ENTER_V8(isolate); 7010 ENTER_V8(isolate);
7031 v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate)); 7011 v8::EscapableHandleScope scope(reinterpret_cast<Isolate*>(isolate));
7032 i::Debug* isolate_debug = isolate->debug(); 7012 i::Debug* isolate_debug = isolate->debug();
7033 EXCEPTION_PREAMBLE(isolate); 7013 EXCEPTION_PREAMBLE(isolate);
7034 has_pending_exception = !isolate_debug->Load(); 7014 has_pending_exception = !isolate_debug->Load();
7035 v8::Local<v8::Value> result; 7015 v8::Local<v8::Value> result;
7036 if (!has_pending_exception) { 7016 if (!has_pending_exception) {
7037 i::Handle<i::JSObject> debug( 7017 i::Handle<i::JSObject> debug(
7038 isolate_debug->debug_context()->global_object()); 7018 isolate_debug->debug_context()->global_object());
(...skipping 674 matching lines...) Expand 10 before | Expand all | Expand 10 after
7713 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); 7693 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate());
7714 Address callback_address = 7694 Address callback_address =
7715 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 7695 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
7716 VMState<EXTERNAL> state(isolate); 7696 VMState<EXTERNAL> state(isolate);
7717 ExternalCallbackScope call_scope(isolate, callback_address); 7697 ExternalCallbackScope call_scope(isolate, callback_address);
7718 callback(info); 7698 callback(info);
7719 } 7699 }
7720 7700
7721 7701
7722 } } // namespace v8::internal 7702 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/heap/heap.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698