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

Side by Side Diff: src/d8.cc

Issue 12314152: Miscellaneous profile-driven Isolate plumbing. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 9 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 | « src/compiler.cc ('k') | src/deoptimizer.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 // 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 Handle<String> str_obj = args[i]->ToString(); 261 Handle<String> str_obj = args[i]->ToString();
262 if (try_catch.HasCaught()) return try_catch.ReThrow(); 262 if (try_catch.HasCaught()) return try_catch.ReThrow();
263 263
264 v8::String::Utf8Value str(str_obj); 264 v8::String::Utf8Value str(str_obj);
265 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout)); 265 int n = static_cast<int>(fwrite(*str, sizeof(**str), str.length(), stdout));
266 if (n != str.length()) { 266 if (n != str.length()) {
267 printf("Error in fwrite\n"); 267 printf("Error in fwrite\n");
268 Exit(1); 268 Exit(1);
269 } 269 }
270 } 270 }
271 return Undefined(); 271 return Undefined(args.GetIsolate());
272 } 272 }
273 273
274 274
275 Handle<Value> Shell::EnableProfiler(const Arguments& args) { 275 Handle<Value> Shell::EnableProfiler(const Arguments& args) {
276 V8::ResumeProfiler(); 276 V8::ResumeProfiler();
277 return Undefined(); 277 return Undefined(args.GetIsolate());
278 } 278 }
279 279
280 280
281 Handle<Value> Shell::DisableProfiler(const Arguments& args) { 281 Handle<Value> Shell::DisableProfiler(const Arguments& args) {
282 V8::PauseProfiler(); 282 V8::PauseProfiler();
283 return Undefined(); 283 return Undefined(args.GetIsolate());
284 } 284 }
285 285
286 286
287 Handle<Value> Shell::Read(const Arguments& args) { 287 Handle<Value> Shell::Read(const Arguments& args) {
288 String::Utf8Value file(args[0]); 288 String::Utf8Value file(args[0]);
289 if (*file == NULL) { 289 if (*file == NULL) {
290 return Throw("Error loading file"); 290 return Throw("Error loading file");
291 } 291 }
292 Handle<String> source = ReadFile(args.GetIsolate(), *file); 292 Handle<String> source = ReadFile(args.GetIsolate(), *file);
293 if (source.IsEmpty()) { 293 if (source.IsEmpty()) {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
335 return Throw("Error loading file"); 335 return Throw("Error loading file");
336 } 336 }
337 Handle<String> source = ReadFile(args.GetIsolate(), *file); 337 Handle<String> source = ReadFile(args.GetIsolate(), *file);
338 if (source.IsEmpty()) { 338 if (source.IsEmpty()) {
339 return Throw("Error loading file"); 339 return Throw("Error loading file");
340 } 340 }
341 if (!ExecuteString(source, String::New(*file), false, true)) { 341 if (!ExecuteString(source, String::New(*file), false, true)) {
342 return Throw("Error executing file"); 342 return Throw("Error executing file");
343 } 343 }
344 } 344 }
345 return Undefined(); 345 return Undefined(args.GetIsolate());
346 } 346 }
347 347
348 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) { 348 static int32_t convertToInt(Local<Value> value_in, TryCatch* try_catch) {
349 if (value_in->IsInt32()) { 349 if (value_in->IsInt32()) {
350 return value_in->Int32Value(); 350 return value_in->Int32Value();
351 } 351 }
352 352
353 Local<Value> number = value_in->ToNumber(); 353 Local<Value> number = value_in->ToNumber();
354 if (try_catch->HasCaught()) return 0; 354 if (try_catch->HasCaught()) return 0;
355 355
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 400
401 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); 401 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True());
402 Persistent<Object> persistent_array = 402 Persistent<Object> persistent_array =
403 Persistent<Object>::New(isolate, buffer); 403 Persistent<Object>::New(isolate, buffer);
404 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback); 404 persistent_array.MakeWeak(isolate, data, ExternalArrayWeakCallback);
405 persistent_array.MarkIndependent(isolate); 405 persistent_array.MarkIndependent(isolate);
406 V8::AdjustAmountOfExternalAllocatedMemory(length); 406 V8::AdjustAmountOfExternalAllocatedMemory(length);
407 407
408 buffer->SetIndexedPropertiesToExternalArrayData( 408 buffer->SetIndexedPropertiesToExternalArrayData(
409 data, v8::kExternalByteArray, length); 409 data, v8::kExternalByteArray, length);
410 buffer->Set(Symbols::byteLength(isolate), Int32::New(length), ReadOnly); 410 buffer->Set(Symbols::byteLength(isolate),
411 Int32::New(length, isolate),
412 ReadOnly);
411 413
412 return buffer; 414 return buffer;
413 } 415 }
414 416
415 417
416 Handle<Value> Shell::ArrayBuffer(const Arguments& args) { 418 Handle<Value> Shell::ArrayBuffer(const Arguments& args) {
417 if (!args.IsConstructCall()) { 419 if (!args.IsConstructCall()) {
418 Handle<Value>* rec_args = new Handle<Value>[args.Length()]; 420 Handle<Value>* rec_args = new Handle<Value>[args.Length()];
419 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i]; 421 for (int i = 0; i < args.Length(); ++i) rec_args[i] = args[i];
420 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args); 422 Handle<Value> result = args.Callee()->NewInstance(args.Length(), rec_args);
(...skipping 23 matching lines...) Expand all
444 ASSERT(element_size == 1 || element_size == 2 || 446 ASSERT(element_size == 1 || element_size == 2 ||
445 element_size == 4 || element_size == 8); 447 element_size == 4 || element_size == 8);
446 ASSERT(byteLength == length * element_size); 448 ASSERT(byteLength == length * element_size);
447 449
448 void* data = buffer->GetIndexedPropertiesExternalArrayData(); 450 void* data = buffer->GetIndexedPropertiesExternalArrayData();
449 ASSERT(data != NULL); 451 ASSERT(data != NULL);
450 452
451 array->SetIndexedPropertiesToExternalArrayData( 453 array->SetIndexedPropertiesToExternalArrayData(
452 static_cast<uint8_t*>(data) + byteOffset, type, length); 454 static_cast<uint8_t*>(data) + byteOffset, type, length);
453 array->SetHiddenValue(Symbols::ArrayMarkerPropName(isolate), 455 array->SetHiddenValue(Symbols::ArrayMarkerPropName(isolate),
454 Int32::New(type)); 456 Int32::New(type, isolate));
455 array->Set(Symbols::byteLength(isolate), Int32::New(byteLength), ReadOnly); 457 array->Set(Symbols::byteLength(isolate),
456 array->Set(Symbols::byteOffset(isolate), Int32::New(byteOffset), ReadOnly); 458 Int32::New(byteLength, isolate),
457 array->Set(Symbols::length(isolate), Int32::New(length), ReadOnly); 459 ReadOnly);
458 array->Set(Symbols::BYTES_PER_ELEMENT(isolate), Int32::New(element_size)); 460 array->Set(Symbols::byteOffset(isolate),
459 array->Set(Symbols::buffer(isolate), buffer, ReadOnly); 461 Int32::New(byteOffset, isolate),
462 ReadOnly);
463 array->Set(Symbols::length(isolate),
464 Int32::New(length, isolate),
465 ReadOnly);
466 array->Set(Symbols::BYTES_PER_ELEMENT(isolate),
467 Int32::New(element_size, isolate));
468 array->Set(Symbols::buffer(isolate),
469 buffer,
470 ReadOnly);
460 471
461 return array; 472 return array;
462 } 473 }
463 474
464 475
465 Handle<Value> Shell::CreateExternalArray(const Arguments& args, 476 Handle<Value> Shell::CreateExternalArray(const Arguments& args,
466 ExternalArrayType type, 477 ExternalArrayType type,
467 int32_t element_size) { 478 int32_t element_size) {
468 Isolate* isolate = args.GetIsolate(); 479 Isolate* isolate = args.GetIsolate();
469 if (!args.IsConstructCall()) { 480 if (!args.IsConstructCall()) {
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 // Construct from size. 553 // Construct from size.
543 length = convertToUint(args[0], &try_catch); 554 length = convertToUint(args[0], &try_catch);
544 if (try_catch.HasCaught()) return try_catch.ReThrow(); 555 if (try_catch.HasCaught()) return try_catch.ReThrow();
545 } 556 }
546 byteLength = length * element_size; 557 byteLength = length * element_size;
547 byteOffset = 0; 558 byteOffset = 0;
548 559
549 Handle<Object> global = Context::GetCurrent()->Global(); 560 Handle<Object> global = Context::GetCurrent()->Global();
550 Handle<Value> array_buffer = global->Get(Symbols::ArrayBuffer(isolate)); 561 Handle<Value> array_buffer = global->Get(Symbols::ArrayBuffer(isolate));
551 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction()); 562 ASSERT(!try_catch.HasCaught() && array_buffer->IsFunction());
552 Handle<Value> buffer_args[] = { Uint32::New(byteLength) }; 563 Handle<Value> buffer_args[] = { Uint32::New(byteLength, isolate) };
553 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance( 564 Handle<Value> result = Handle<Function>::Cast(array_buffer)->NewInstance(
554 1, buffer_args); 565 1, buffer_args);
555 if (try_catch.HasCaught()) return result; 566 if (try_catch.HasCaught()) return result;
556 buffer = result->ToObject(); 567 buffer = result->ToObject();
557 } 568 }
558 569
559 Handle<Object> array = 570 Handle<Object> array =
560 CreateExternalArray(isolate, args.This(), buffer, type, length, 571 CreateExternalArray(isolate, args.This(), buffer, type, length,
561 byteLength, byteOffset, element_size); 572 byteLength, byteOffset, element_size);
562 573
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 } else { 618 } else {
608 end = convertToInt(args[1], &try_catch); 619 end = convertToInt(args[1], &try_catch);
609 if (try_catch.HasCaught()) return try_catch.ReThrow(); 620 if (try_catch.HasCaught()) return try_catch.ReThrow();
610 if (end < 0) end += length; 621 if (end < 0) end += length;
611 if (end < 0) end = 0; 622 if (end < 0) end = 0;
612 if (end > length) end = length; 623 if (end > length) end = length;
613 if (end < begin) end = begin; 624 if (end < begin) end = begin;
614 } 625 }
615 626
616 Local<Function> constructor = Local<Function>::Cast(self->GetConstructor()); 627 Local<Function> constructor = Local<Function>::Cast(self->GetConstructor());
617 Handle<Value> new_args[] = { Uint32::New(end - begin) }; 628 Handle<Value> new_args[] = { Uint32::New(end - begin, isolate) };
618 Handle<Value> result = constructor->NewInstance(1, new_args); 629 Handle<Value> result = constructor->NewInstance(1, new_args);
619 if (try_catch.HasCaught()) return result; 630 if (try_catch.HasCaught()) return result;
620 Handle<Object> buffer = result->ToObject(); 631 Handle<Object> buffer = result->ToObject();
621 uint8_t* dest = 632 uint8_t* dest =
622 static_cast<uint8_t*>(buffer->GetIndexedPropertiesExternalArrayData()); 633 static_cast<uint8_t*>(buffer->GetIndexedPropertiesExternalArrayData());
623 uint8_t* src = begin + static_cast<uint8_t*>( 634 uint8_t* src = begin + static_cast<uint8_t*>(
624 self->GetIndexedPropertiesExternalArrayData()); 635 self->GetIndexedPropertiesExternalArrayData());
625 memcpy(dest, src, end - begin); 636 memcpy(dest, src, end - begin);
626 637
627 return buffer; 638 return buffer;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 if (end < 0) end = 0; 685 if (end < 0) end = 0;
675 if (end > length) end = length; 686 if (end > length) end = length;
676 if (end < begin) end = begin; 687 if (end < begin) end = begin;
677 } 688 }
678 689
679 length = end - begin; 690 length = end - begin;
680 byteOffset += begin * element_size; 691 byteOffset += begin * element_size;
681 692
682 Local<Function> constructor = Local<Function>::Cast(self->GetConstructor()); 693 Local<Function> constructor = Local<Function>::Cast(self->GetConstructor());
683 Handle<Value> construct_args[] = { 694 Handle<Value> construct_args[] = {
684 buffer, Uint32::New(byteOffset), Uint32::New(length) 695 buffer, Uint32::New(byteOffset, isolate), Uint32::New(length, isolate)
685 }; 696 };
686 return constructor->NewInstance(3, construct_args); 697 return constructor->NewInstance(3, construct_args);
687 } 698 }
688 699
689 700
690 Handle<Value> Shell::ArraySet(const Arguments& args) { 701 Handle<Value> Shell::ArraySet(const Arguments& args) {
691 TryCatch try_catch; 702 TryCatch try_catch;
692 703
693 if (!args.This()->IsObject()) { 704 if (!args.This()->IsObject()) {
694 return Throw("'set' invoked on non-object receiver"); 705 return Throw("'set' invoked on non-object receiver");
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 for (int k = i; k <= j; ++k) { 827 for (int k = i; k <= j; ++k) {
817 self->Set(offset + k, temp[k - i]); 828 self->Set(offset + k, temp[k - i]);
818 } 829 }
819 } else { 830 } else {
820 // Different backing stores, safe to copy element-wise sequentially. 831 // Different backing stores, safe to copy element-wise sequentially.
821 for (int i = 0; i < source_length; ++i) 832 for (int i = 0; i < source_length; ++i)
822 self->Set(offset + i, source->Get(i)); 833 self->Set(offset + i, source->Get(i));
823 } 834 }
824 } 835 }
825 836
826 return Undefined(); 837 return Undefined(args.GetIsolate());
827 } 838 }
828 839
829 840
830 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate, 841 void Shell::ExternalArrayWeakCallback(v8::Isolate* isolate,
831 Persistent<Value> object, 842 Persistent<Value> object,
832 void* data) { 843 void* data) {
833 HandleScope scope; 844 HandleScope scope;
834 int32_t length = 845 int32_t length =
835 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value(); 846 object->ToObject()->Get(Symbols::byteLength(isolate))->Uint32Value();
836 V8::AdjustAmountOfExternalAllocatedMemory(-length); 847 V8::AdjustAmountOfExternalAllocatedMemory(-length);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
882 } 893 }
883 894
884 895
885 Handle<Value> Shell::Uint8ClampedArray(const Arguments& args) { 896 Handle<Value> Shell::Uint8ClampedArray(const Arguments& args) {
886 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t)); 897 return CreateExternalArray(args, kExternalPixelArray, sizeof(uint8_t));
887 } 898 }
888 899
889 900
890 Handle<Value> Shell::Yield(const Arguments& args) { 901 Handle<Value> Shell::Yield(const Arguments& args) {
891 v8::Unlocker unlocker(args.GetIsolate()); 902 v8::Unlocker unlocker(args.GetIsolate());
892 return Undefined(); 903 return Undefined(args.GetIsolate());
893 } 904 }
894 905
895 906
896 Handle<Value> Shell::Quit(const Arguments& args) { 907 Handle<Value> Shell::Quit(const Arguments& args) {
897 int exit_code = args[0]->Int32Value(); 908 int exit_code = args[0]->Int32Value();
898 OnExit(); 909 OnExit();
899 exit(exit_code); 910 exit(exit_code);
900 return Undefined(); 911 return Undefined(args.GetIsolate());
901 } 912 }
902 913
903 914
904 Handle<Value> Shell::Version(const Arguments& args) { 915 Handle<Value> Shell::Version(const Arguments& args) {
905 return String::New(V8::GetVersion()); 916 return String::New(V8::GetVersion());
906 } 917 }
907 918
908 919
909 void Shell::ReportException(v8::TryCatch* try_catch) { 920 void Shell::ReportException(v8::TryCatch* try_catch) {
910 HandleScope handle_scope; 921 HandleScope handle_scope;
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 Counter* counter = reinterpret_cast<Counter*>(histogram); 1104 Counter* counter = reinterpret_cast<Counter*>(histogram);
1094 counter->AddSample(sample); 1105 counter->AddSample(sample);
1095 } 1106 }
1096 1107
1097 1108
1098 void Shell::InstallUtilityScript(Isolate* isolate) { 1109 void Shell::InstallUtilityScript(Isolate* isolate) {
1099 Locker lock(isolate); 1110 Locker lock(isolate);
1100 HandleScope scope; 1111 HandleScope scope;
1101 // If we use the utility context, we have to set the security tokens so that 1112 // If we use the utility context, we have to set the security tokens so that
1102 // utility, evaluation and debug context can all access each other. 1113 // utility, evaluation and debug context can all access each other.
1103 utility_context_->SetSecurityToken(Undefined()); 1114 utility_context_->SetSecurityToken(Undefined(isolate));
1104 evaluation_context_->SetSecurityToken(Undefined()); 1115 evaluation_context_->SetSecurityToken(Undefined(isolate));
1105 Context::Scope utility_scope(utility_context_); 1116 Context::Scope utility_scope(utility_context_);
1106 1117
1107 #ifdef ENABLE_DEBUGGER_SUPPORT 1118 #ifdef ENABLE_DEBUGGER_SUPPORT
1108 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n"); 1119 if (i::FLAG_debugger) printf("JavaScript debugger enabled\n");
1109 // Install the debugger object in the utility scope 1120 // Install the debugger object in the utility scope
1110 i::Debug* debug = i::Isolate::Current()->debug(); 1121 i::Debug* debug = i::Isolate::Current()->debug();
1111 debug->Load(); 1122 debug->Load();
1112 i::Handle<i::JSObject> js_debug 1123 i::Handle<i::JSObject> js_debug
1113 = i::Handle<i::JSObject>(debug->debug_context()->global_object()); 1124 = i::Handle<i::JSObject>(debug->debug_context()->global_object());
1114 utility_context_->Global()->Set(String::New("$debug"), 1125 utility_context_->Global()->Set(String::New("$debug"),
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True()); 1458 buffer->SetHiddenValue(Symbols::ArrayBufferMarkerPropName(isolate), True());
1448 Persistent<Object> persistent_buffer = 1459 Persistent<Object> persistent_buffer =
1449 Persistent<Object>::New(isolate, buffer); 1460 Persistent<Object>::New(isolate, buffer);
1450 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback); 1461 persistent_buffer.MakeWeak(isolate, data, ExternalArrayWeakCallback);
1451 persistent_buffer.MarkIndependent(isolate); 1462 persistent_buffer.MarkIndependent(isolate);
1452 V8::AdjustAmountOfExternalAllocatedMemory(length); 1463 V8::AdjustAmountOfExternalAllocatedMemory(length);
1453 1464
1454 buffer->SetIndexedPropertiesToExternalArrayData( 1465 buffer->SetIndexedPropertiesToExternalArrayData(
1455 data, kExternalUnsignedByteArray, length); 1466 data, kExternalUnsignedByteArray, length);
1456 buffer->Set(Symbols::byteLength(isolate), 1467 buffer->Set(Symbols::byteLength(isolate),
1457 Int32::New(static_cast<int32_t>(length)), ReadOnly); 1468 Int32::New(static_cast<int32_t>(length), isolate), ReadOnly);
1458 return buffer; 1469 return buffer;
1459 } 1470 }
1460 1471
1461 1472
1462 #ifndef V8_SHARED 1473 #ifndef V8_SHARED
1463 static char* ReadToken(char* data, char token) { 1474 static char* ReadToken(char* data, char token) {
1464 char* next = i::OS::StrChr(data, token); 1475 char* next = i::OS::StrChr(data, token);
1465 if (next != NULL) { 1476 if (next != NULL) {
1466 *next = '\0'; 1477 *next = '\0';
1467 return (next + 1); 1478 return (next + 1);
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
1965 } 1976 }
1966 1977
1967 } // namespace v8 1978 } // namespace v8
1968 1979
1969 1980
1970 #ifndef GOOGLE3 1981 #ifndef GOOGLE3
1971 int main(int argc, char* argv[]) { 1982 int main(int argc, char* argv[]) {
1972 return v8::Shell::Main(argc, argv); 1983 return v8::Shell::Main(argc, argv);
1973 } 1984 }
1974 #endif 1985 #endif
OLDNEW
« no previous file with comments | « src/compiler.cc ('k') | src/deoptimizer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698