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

Side by Side Diff: src/api.cc

Issue 5107003: [Isolates] Cleanup of codepaths slowing down Dromaeo in browser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/isolates
Patch Set: tiny fix Created 10 years 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 | « include/v8.h ('k') | src/builtins.cc » ('j') | src/log.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 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 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 261
262 // --- S t a t i c s --- 262 // --- S t a t i c s ---
263 263
264 264
265 static bool InitializeHelper() { 265 static bool InitializeHelper() {
266 if (i::Snapshot::Initialize()) return true; 266 if (i::Snapshot::Initialize()) return true;
267 return i::V8::Initialize(NULL); 267 return i::V8::Initialize(NULL);
268 } 268 }
269 269
270 270
271 static inline bool EnsureInitialized(const char* location) { 271 static inline bool EnsureInitializedForIsolate(i::Isolate* isolate,
272 i::Isolate* isolate = i::Isolate::UncheckedCurrent(); 272 const char* location) {
273 if (isolate != NULL) { 273 if (isolate != NULL) {
274 if (isolate->IsDefaultIsolate()) { 274 if (isolate->IsDefaultIsolate()) {
275 if (i::V8::IsRunning()) { 275 if (i::V8::IsRunning()) {
276 return true; 276 return true;
277 } 277 }
278 if (IsDeadCheck(location)) { 278 if (IsDeadCheck(location)) {
279 return false; 279 return false;
280 } 280 }
281 } else { 281 } else {
282 if (isolate->IsInitialized()) { 282 if (isolate->IsInitialized()) {
283 return true; 283 return true;
284 } 284 }
285 } 285 }
286 } 286 }
287 return ApiCheck(InitializeHelper(), location, "Error initializing V8"); 287 return ApiCheck(InitializeHelper(), location, "Error initializing V8");
288 } 288 }
289 289
290 static inline bool EnsureInitialized(const char* location) {
291 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
292 return EnsureInitializedForIsolate(isolate, location);
293 }
290 294
291 #ifdef DEBUG 295 #ifdef DEBUG
292 void ImplementationUtilities::ZapHandleRange(i::Object** begin, 296 void ImplementationUtilities::ZapHandleRange(i::Object** begin,
293 i::Object** end) { 297 i::Object** end) {
294 i::HandleScope::ZapRange(begin, end); 298 i::HandleScope::ZapRange(begin, end);
295 } 299 }
296 #endif 300 #endif
297 301
298 302
299 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() { 303 v8::Handle<v8::Primitive> ImplementationUtilities::Undefined() {
300 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>(); 304 if (!EnsureInitialized("v8::Undefined()")) return v8::Handle<v8::Primitive>();
301 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->undefined_value())); 305 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->undefined_value()));
302 } 306 }
303 307
304 308
305 v8::Handle<v8::Primitive> ImplementationUtilities::Null() { 309 v8::Handle<v8::Primitive> ImplementationUtilities::Null() {
306 if (!EnsureInitialized("v8::Null()")) return v8::Handle<v8::Primitive>(); 310 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
307 return v8::Handle<Primitive>(ToApi<Primitive>(FACTORY->null_value())); 311 if (!EnsureInitializedForIsolate(isolate, "v8::Null()"))
312 return v8::Handle<v8::Primitive>();
313 return v8::Handle<Primitive>(
314 ToApi<Primitive>(isolate->factory()->null_value()));
308 } 315 }
309 316
310 317
311 v8::Handle<v8::Boolean> ImplementationUtilities::True() { 318 v8::Handle<v8::Boolean> ImplementationUtilities::True() {
312 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>(); 319 if (!EnsureInitialized("v8::True()")) return v8::Handle<v8::Boolean>();
313 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->true_value())); 320 return v8::Handle<v8::Boolean>(ToApi<Boolean>(FACTORY->true_value()));
314 } 321 }
315 322
316 323
317 v8::Handle<v8::Boolean> ImplementationUtilities::False() { 324 v8::Handle<v8::Boolean> ImplementationUtilities::False() {
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 i::HandleScope::ZapRange(prev_next_, prev_limit_); 511 i::HandleScope::ZapRange(prev_next_, prev_limit_);
505 #endif 512 #endif
506 } 513 }
507 514
508 515
509 int HandleScope::NumberOfHandles() { 516 int HandleScope::NumberOfHandles() {
510 EnsureInitialized("HandleScope::NumberOfHandles"); 517 EnsureInitialized("HandleScope::NumberOfHandles");
511 return i::HandleScope::NumberOfHandles(); 518 return i::HandleScope::NumberOfHandles();
512 } 519 }
513 520
521 // Define GetIsolateFromApiObject for various Api types. Need a few of them,
522 // since they do not form inheritance hierarchy with a single HeapObject-backed
523 // base class. First, declare the catch-all method:
524 inline static i::Isolate* GetIsolateFromApiObject(Data* value) {
525 return i::Isolate::Current();
526 }
514 527
515 i::Object** v8::HandleScope::CreateHandle(i::Object* value) { 528 // Also declare overrides that know some types are backed by HeapObjects:
516 return i::HandleScope::CreateHandle(value, i::Isolate::Current()); 529 #define MAKE_GET_ISOLATE_FROM_API_OBJECT(Type) \
530 inline static i::Isolate* GetIsolateFromApiObject(Type* value) { \
531 i::HeapObject** p = reinterpret_cast<i::HeapObject**>(value); \
532 ASSERT((*p)->IsHeapObject()); \
533 return (*p)->GetIsolate(); \
534 }
535
536 MAKE_GET_ISOLATE_FROM_API_OBJECT(Context)
537 MAKE_GET_ISOLATE_FROM_API_OBJECT(String)
538 MAKE_GET_ISOLATE_FROM_API_OBJECT(Object)
539 MAKE_GET_ISOLATE_FROM_API_OBJECT(Message)
540 MAKE_GET_ISOLATE_FROM_API_OBJECT(StackTrace)
541 MAKE_GET_ISOLATE_FROM_API_OBJECT(StackFrame)
542
543 #undef MAKE_GET_ISOLATE_FROM_API_OBJECT
544
545
546 template <class T>
547 internal::Object** HandleScope::CreateHandle(T* value) {
548 internal::Object** p = reinterpret_cast<internal::Object**>(value);
549 return i::HandleScope::CreateHandle(*p, GetIsolateFromApiObject(value));
517 } 550 }
518 551
519 552
553 // We need to explicitly instantiate this method for particular types since
554 // there is no callers for this instances in this file, so the instances are
555 // not generated at all and linker complains.
556 #define MAKE_CREATE_HANDLE(Type) \
Vitaly Repeshko 2010/12/06 18:18:45 Ugh, I'm not a huge fan of explicit template insta
557 template internal::Object** HandleScope::CreateHandle<Type>(Type* value);
558
559 MAKE_CREATE_HANDLE(Context)
560 MAKE_CREATE_HANDLE(Value)
561 MAKE_CREATE_HANDLE(Function)
562 MAKE_CREATE_HANDLE(String)
563 MAKE_CREATE_HANDLE(RegExp)
564 MAKE_CREATE_HANDLE(Object)
565 MAKE_CREATE_HANDLE(Array)
566 MAKE_CREATE_HANDLE(External)
567 MAKE_CREATE_HANDLE(FunctionTemplate)
568 MAKE_CREATE_HANDLE(ObjectTemplate)
569 MAKE_CREATE_HANDLE(Signature)
570 MAKE_CREATE_HANDLE(TypeSwitch)
571 MAKE_CREATE_HANDLE(Message)
572 MAKE_CREATE_HANDLE(StackTrace)
573 MAKE_CREATE_HANDLE(StackFrame)
574 MAKE_CREATE_HANDLE(Number)
575 MAKE_CREATE_HANDLE(Integer)
576 MAKE_CREATE_HANDLE(Uint32)
577
578 #undef MAKE_CREATE_HANDLE
579
580
520 void Context::Enter() { 581 void Context::Enter() {
521 if (IsDeadCheck("v8::Context::Enter()")) return; 582 if (IsDeadCheck("v8::Context::Enter()")) return;
522 ENTER_V8; 583 ENTER_V8;
523 i::Handle<i::Context> env = Utils::OpenHandle(this); 584 i::Handle<i::Context> env = Utils::OpenHandle(this);
524 // TODO(isolates): Context should have a pointer to isolate. 585 // TODO(isolates): Context should have a pointer to isolate.
525 i::Isolate* isolate = i::Isolate::Current(); 586 i::Isolate* isolate = i::Isolate::Current();
526 isolate->handle_scope_implementer()->EnterContext(env); 587 isolate->handle_scope_implementer()->EnterContext(env);
527 588
528 isolate->handle_scope_implementer()->SaveContext(isolate->context()); 589 isolate->handle_scope_implementer()->SaveContext(isolate->context());
529 isolate->set_context(*env); 590 isolate->set_context(*env);
(...skipping 3320 matching lines...) Expand 10 before | Expand all | Expand 10 after
3850 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs. 3911 // Introduce only canonical NaN value into the VM, to avoid signaling NaNs.
3851 value = i::OS::nan_value(); 3912 value = i::OS::nan_value();
3852 } 3913 }
3853 ENTER_V8; 3914 ENTER_V8;
3854 i::Handle<i::Object> result = FACTORY->NewNumber(value); 3915 i::Handle<i::Object> result = FACTORY->NewNumber(value);
3855 return Utils::NumberToLocal(result); 3916 return Utils::NumberToLocal(result);
3856 } 3917 }
3857 3918
3858 3919
3859 Local<Integer> v8::Integer::New(int32_t value) { 3920 Local<Integer> v8::Integer::New(int32_t value) {
3860 EnsureInitialized("v8::Integer::New()"); 3921 i::Isolate* isolate = i::Isolate::UncheckedCurrent();
3922 EnsureInitializedForIsolate(isolate, "v8::Integer::New()");
3861 if (i::Smi::IsValid(value)) { 3923 if (i::Smi::IsValid(value)) {
3862 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value))); 3924 return Utils::IntegerToLocal(i::Handle<i::Object>(i::Smi::FromInt(value),
3925 isolate));
3863 } 3926 }
3864 ENTER_V8; 3927 ENTER_V8;
3865 i::Handle<i::Object> result = FACTORY->NewNumber(value); 3928 i::Handle<i::Object> result = isolate->factory()->NewNumber(value);
3866 return Utils::IntegerToLocal(result); 3929 return Utils::IntegerToLocal(result);
3867 } 3930 }
3868 3931
3869 3932
3870 Local<Integer> Integer::NewFromUnsigned(uint32_t value) { 3933 Local<Integer> Integer::NewFromUnsigned(uint32_t value) {
3871 bool fits_into_int32_t = (value & (1 << 31)) == 0; 3934 bool fits_into_int32_t = (value & (1 << 31)) == 0;
3872 if (fits_into_int32_t) { 3935 if (fits_into_int32_t) {
3873 return Integer::New(static_cast<int32_t>(value)); 3936 return Integer::New(static_cast<int32_t>(value));
3874 } 3937 }
3875 ENTER_V8; 3938 ENTER_V8;
(...skipping 1131 matching lines...) Expand 10 before | Expand all | Expand 10 after
5007 5070
5008 5071
5009 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) { 5072 char* HandleScopeImplementer::Iterate(ObjectVisitor* v, char* storage) {
5010 HandleScopeImplementer* thread_local = 5073 HandleScopeImplementer* thread_local =
5011 reinterpret_cast<HandleScopeImplementer*>(storage); 5074 reinterpret_cast<HandleScopeImplementer*>(storage);
5012 thread_local->IterateThis(v); 5075 thread_local->IterateThis(v);
5013 return storage + ArchiveSpacePerThread(); 5076 return storage + ArchiveSpacePerThread();
5014 } 5077 }
5015 5078
5016 } } // namespace v8::internal 5079 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « include/v8.h ('k') | src/builtins.cc » ('j') | src/log.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698