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

Side by Side Diff: src/liveedit.cc

Issue 2840018: [Isolates] Moved more compilation-related globals (builtins, runtime, &c.)... (Closed) Base URL: http://v8.googlecode.com/svn/branches/experimental/isolates/
Patch Set: rebase Created 10 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
« no previous file with comments | « src/liveedit.h ('k') | src/messages.cc » ('j') | src/runtime.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 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 245
246 void Comparator::CalculateDifference(Comparator::Input* input, 246 void Comparator::CalculateDifference(Comparator::Input* input,
247 Comparator::Output* result_writer) { 247 Comparator::Output* result_writer) {
248 Differencer differencer(input); 248 Differencer differencer(input);
249 differencer.Initialize(); 249 differencer.Initialize();
250 differencer.FillTable(); 250 differencer.FillTable();
251 differencer.SaveResult(result_writer); 251 differencer.SaveResult(result_writer);
252 } 252 }
253 253
254 254
255 static bool CompareSubstrings(Handle<String> s1, int pos1, 255 static bool CompareSubstrings(Isolate* isolate, Handle<String> s1, int pos1,
256 Handle<String> s2, int pos2, int len) { 256 Handle<String> s2, int pos2, int len) {
257 static StringInputBuffer buf1; 257 StringInputBuffer& buf1 = *isolate->liveedit_compare_substrings_buf1();
258 static StringInputBuffer buf2; 258 StringInputBuffer& buf2 = *isolate->liveedit_compare_substrings_buf2();
259 buf1.Reset(*s1); 259 buf1.Reset(*s1);
260 buf1.Seek(pos1); 260 buf1.Seek(pos1);
261 buf2.Reset(*s2); 261 buf2.Reset(*s2);
262 buf2.Seek(pos2); 262 buf2.Seek(pos2);
263 for (int i = 0; i < len; i++) { 263 for (int i = 0; i < len; i++) {
264 ASSERT(buf1.has_more() && buf2.has_more()); 264 ASSERT(buf1.has_more() && buf2.has_more());
265 if (buf1.GetNext() != buf2.GetNext()) { 265 if (buf1.GetNext() != buf2.GetNext()) {
266 return false; 266 return false;
267 } 267 }
268 } 268 }
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
307 307
308 int GetPosAfterNewLine(int index) { 308 int GetPosAfterNewLine(int index) {
309 return Smi::cast(ends_array_->get(index))->value() + 1; 309 return Smi::cast(ends_array_->get(index))->value() + 1;
310 } 310 }
311 }; 311 };
312 312
313 313
314 // Represents 2 strings as 2 arrays of lines. 314 // Represents 2 strings as 2 arrays of lines.
315 class LineArrayCompareInput : public Comparator::Input { 315 class LineArrayCompareInput : public Comparator::Input {
316 public: 316 public:
317 LineArrayCompareInput(Handle<String> s1, Handle<String> s2, 317 LineArrayCompareInput(Isolate* isolate, Handle<String> s1, Handle<String> s2,
318 LineEndsWrapper line_ends1, LineEndsWrapper line_ends2) 318 LineEndsWrapper line_ends1, LineEndsWrapper line_ends2)
319 : s1_(s1), s2_(s2), line_ends1_(line_ends1), line_ends2_(line_ends2) { 319 : isolate_(isolate), s1_(s1), s2_(s2), line_ends1_(line_ends1),
320 line_ends2_(line_ends2) {
320 } 321 }
321 int getLength1() { 322 int getLength1() {
322 return line_ends1_.length(); 323 return line_ends1_.length();
323 } 324 }
324 int getLength2() { 325 int getLength2() {
325 return line_ends2_.length(); 326 return line_ends2_.length();
326 } 327 }
327 bool equals(int index1, int index2) { 328 bool equals(int index1, int index2) {
328 int line_start1 = line_ends1_.GetLineStart(index1); 329 int line_start1 = line_ends1_.GetLineStart(index1);
329 int line_start2 = line_ends2_.GetLineStart(index2); 330 int line_start2 = line_ends2_.GetLineStart(index2);
330 int line_end1 = line_ends1_.GetLineEnd(index1); 331 int line_end1 = line_ends1_.GetLineEnd(index1);
331 int line_end2 = line_ends2_.GetLineEnd(index2); 332 int line_end2 = line_ends2_.GetLineEnd(index2);
332 int len1 = line_end1 - line_start1; 333 int len1 = line_end1 - line_start1;
333 int len2 = line_end2 - line_start2; 334 int len2 = line_end2 - line_start2;
334 if (len1 != len2) { 335 if (len1 != len2) {
335 return false; 336 return false;
336 } 337 }
337 return CompareSubstrings(s1_, line_start1, s2_, line_start2, len1); 338 return CompareSubstrings(isolate_, s1_, line_start1, s2_, line_start2,
339 len1);
338 } 340 }
339 341
340 private: 342 private:
343 Isolate* isolate_;
341 Handle<String> s1_; 344 Handle<String> s1_;
342 Handle<String> s2_; 345 Handle<String> s2_;
343 LineEndsWrapper line_ends1_; 346 LineEndsWrapper line_ends1_;
344 LineEndsWrapper line_ends2_; 347 LineEndsWrapper line_ends2_;
345 }; 348 };
346 349
347 350
348 // Stores compare result in JSArray. Each chunk is stored as 3 array elements: 351 // Stores compare result in JSArray. Each chunk is stored as 3 array elements:
349 // (pos1_begin, pos1_end, pos2_end). 352 // (pos1_begin, pos1_end, pos2_end).
350 class LineArrayCompareOutput : public Comparator::Output { 353 class LineArrayCompareOutput : public Comparator::Output {
(...skipping 27 matching lines...) Expand all
378 LineEndsWrapper line_ends1_; 381 LineEndsWrapper line_ends1_;
379 LineEndsWrapper line_ends2_; 382 LineEndsWrapper line_ends2_;
380 }; 383 };
381 384
382 385
383 Handle<JSArray> LiveEdit::CompareStringsLinewise(Handle<String> s1, 386 Handle<JSArray> LiveEdit::CompareStringsLinewise(Handle<String> s1,
384 Handle<String> s2) { 387 Handle<String> s2) {
385 LineEndsWrapper line_ends1(s1); 388 LineEndsWrapper line_ends1(s1);
386 LineEndsWrapper line_ends2(s2); 389 LineEndsWrapper line_ends2(s2);
387 390
388 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2); 391 LineArrayCompareInput
392 input(Isolate::Current(), s1, s2, line_ends1, line_ends2);
389 LineArrayCompareOutput output(line_ends1, line_ends2); 393 LineArrayCompareOutput output(line_ends1, line_ends2);
390 394
391 Comparator::CalculateDifference(&input, &output); 395 Comparator::CalculateDifference(&input, &output);
392 396
393 return output.GetResult(); 397 return output.GetResult();
394 } 398 }
395 399
396 400
397 static void CompileScriptForTracker(Handle<Script> script) { 401 static void CompileScriptForTracker(Isolate* isolate, Handle<Script> script) {
398 const bool is_eval = false; 402 const bool is_eval = false;
399 const bool is_global = true; 403 const bool is_global = true;
400 // TODO(635): support extensions. 404 // TODO(635): support extensions.
401 Extension* extension = NULL; 405 Extension* extension = NULL;
402 406
403 PostponeInterruptsScope postpone; 407 PostponeInterruptsScope postpone;
404 408
405 // Only allow non-global compiles for eval. 409 // Only allow non-global compiles for eval.
406 ASSERT(is_eval || is_global); 410 ASSERT(is_eval || is_global);
407 411
408 // Build AST. 412 // Build AST.
409 ScriptDataImpl* pre_data = NULL; 413 ScriptDataImpl* pre_data = NULL;
410 FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data); 414 FunctionLiteral* lit = MakeAST(is_global, script, extension, pre_data);
411 415
412 // Check for parse errors. 416 // Check for parse errors.
413 if (lit == NULL) { 417 if (lit == NULL) {
414 ASSERT(Isolate::Current()->has_pending_exception()); 418 ASSERT(isolate->has_pending_exception());
415 return; 419 return;
416 } 420 }
417 421
418 // Compile the code. 422 // Compile the code.
419 CompilationInfo info(lit, script, is_eval); 423 CompilationInfo info(lit, script, is_eval);
420 424
421 LiveEditFunctionTracker tracker(lit); 425 LiveEditFunctionTracker tracker(isolate, lit);
422 Handle<Code> code = MakeCodeForLiveEdit(&info); 426 Handle<Code> code = MakeCodeForLiveEdit(&info);
423 427
424 // Check for stack-overflow exceptions. 428 // Check for stack-overflow exceptions.
425 if (code.is_null()) { 429 if (code.is_null()) {
426 Isolate::Current()->StackOverflow(); 430 isolate->StackOverflow();
427 return; 431 return;
428 } 432 }
429 tracker.RecordRootFunctionInfo(code); 433 tracker.RecordRootFunctionInfo(code);
430 } 434 }
431 435
432 // Unwraps JSValue object, returning its field "value" 436 // Unwraps JSValue object, returning its field "value"
433 static Handle<Object> UnwrapJSValue(Handle<JSValue> jsValue) { 437 static Handle<Object> UnwrapJSValue(Handle<JSValue> jsValue) {
434 return Handle<Object>(jsValue->value()); 438 return Handle<Object>(jsValue->value());
435 } 439 }
436 440
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 Handle<JSArray> GetResult() { 697 Handle<JSArray> GetResult() {
694 return result_; 698 return result_;
695 } 699 }
696 700
697 private: 701 private:
698 Handle<JSArray> result_; 702 Handle<JSArray> result_;
699 int len_; 703 int len_;
700 int current_parent_index_; 704 int current_parent_index_;
701 }; 705 };
702 706
703 static FunctionInfoListener* active_function_info_listener = NULL;
704
705 JSArray* LiveEdit::GatherCompileInfo(Handle<Script> script, 707 JSArray* LiveEdit::GatherCompileInfo(Handle<Script> script,
706 Handle<String> source) { 708 Handle<String> source) {
709 Isolate* isolate = Isolate::Current();
707 CompilationZoneScope zone_scope(DELETE_ON_EXIT); 710 CompilationZoneScope zone_scope(DELETE_ON_EXIT);
708 711
709 FunctionInfoListener listener; 712 FunctionInfoListener listener;
710 Handle<Object> original_source = Handle<Object>(script->source()); 713 Handle<Object> original_source = Handle<Object>(script->source());
711 script->set_source(*source); 714 script->set_source(*source);
712 active_function_info_listener = &listener; 715 isolate->set_active_function_info_listener(&listener);
713 CompileScriptForTracker(script); 716 CompileScriptForTracker(isolate, script);
714 active_function_info_listener = NULL; 717 isolate->set_active_function_info_listener(NULL);
715 script->set_source(*original_source); 718 script->set_source(*original_source);
716 719
717 return *(listener.GetResult()); 720 return *(listener.GetResult());
718 } 721 }
719 722
720 723
721 void LiveEdit::WrapSharedFunctionInfos(Handle<JSArray> array) { 724 void LiveEdit::WrapSharedFunctionInfos(Handle<JSArray> array) {
722 HandleScope scope; 725 HandleScope scope;
723 int len = Smi::cast(array->length())->value(); 726 int len = Smi::cast(array->length())->value();
724 for (int i = 0; i < len; i++) { 727 for (int i = 0; i < len; i++) {
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info())); 865 Handle<DebugInfo> debug_info(DebugInfo::cast(shared_info->debug_info()));
863 Handle<Code> new_original_code = 866 Handle<Code> new_original_code =
864 Factory::CopyCode(compile_info_wrapper.GetFunctionCode()); 867 Factory::CopyCode(compile_info_wrapper.GetFunctionCode());
865 debug_info->set_original_code(*new_original_code); 868 debug_info->set_original_code(*new_original_code);
866 } 869 }
867 870
868 shared_info->set_start_position(compile_info_wrapper.GetStartPosition()); 871 shared_info->set_start_position(compile_info_wrapper.GetStartPosition());
869 shared_info->set_end_position(compile_info_wrapper.GetEndPosition()); 872 shared_info->set_end_position(compile_info_wrapper.GetEndPosition());
870 873
871 shared_info->set_construct_stub( 874 shared_info->set_construct_stub(
872 Builtins::builtin(Builtins::JSConstructStubGeneric)); 875 Isolate::Current()->builtins()->builtin(
876 Builtins::JSConstructStubGeneric));
873 877
874 return HEAP->undefined_value(); 878 return HEAP->undefined_value();
875 } 879 }
876 880
877 881
878 // TODO(635): Eval caches its scripts (same text -- same compiled info). 882 // TODO(635): Eval caches its scripts (same text -- same compiled info).
879 // Make sure we clear such caches. 883 // Make sure we clear such caches.
880 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper, 884 void LiveEdit::SetFunctionScript(Handle<JSValue> function_wrapper,
881 Handle<Object> script_handle) { 885 Handle<Object> script_handle) {
882 Handle<SharedFunctionInfo> shared_info = 886 Handle<SharedFunctionInfo> shared_info =
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 StackFrame* top_frame = frames[top_frame_index]; 1199 StackFrame* top_frame = frames[top_frame_index];
1196 StackFrame* bottom_js_frame = frames[bottom_js_frame_index]; 1200 StackFrame* bottom_js_frame = frames[bottom_js_frame_index];
1197 1201
1198 ASSERT(bottom_js_frame->is_java_script()); 1202 ASSERT(bottom_js_frame->is_java_script());
1199 1203
1200 // Check the nature of the top frame. 1204 // Check the nature of the top frame.
1201 if (pre_top_frame->code()->is_inline_cache_stub() && 1205 if (pre_top_frame->code()->is_inline_cache_stub() &&
1202 pre_top_frame->code()->ic_state() == DEBUG_BREAK) { 1206 pre_top_frame->code()->ic_state() == DEBUG_BREAK) {
1203 // OK, we can drop inline cache calls. 1207 // OK, we can drop inline cache calls.
1204 } else if (pre_top_frame->code() == 1208 } else if (pre_top_frame->code() ==
1205 Builtins::builtin(Builtins::FrameDropper_LiveEdit)) { 1209 Isolate::Current()->builtins()->builtin(
1210 Builtins::FrameDropper_LiveEdit)) {
1206 // OK, we can drop our own code. 1211 // OK, we can drop our own code.
1207 } else if (pre_top_frame->code()->kind() == Code::STUB && 1212 } else if (pre_top_frame->code()->kind() == Code::STUB &&
1208 pre_top_frame->code()->major_key()) { 1213 pre_top_frame->code()->major_key()) {
1209 // Unit Test entry, it's fine, we support this case. 1214 // Unit Test entry, it's fine, we support this case.
1210 } else { 1215 } else {
1211 return "Unknown structure of stack above changing function"; 1216 return "Unknown structure of stack above changing function";
1212 } 1217 }
1213 1218
1214 Address unused_stack_top = top_frame->sp(); 1219 Address unused_stack_top = top_frame->sp();
1215 Address unused_stack_bottom = bottom_js_frame->fp() 1220 Address unused_stack_bottom = bottom_js_frame->fp()
1216 - Debug::kFrameDropperFrameSize * kPointerSize // Size of the new frame. 1221 - Debug::kFrameDropperFrameSize * kPointerSize // Size of the new frame.
1217 + kPointerSize; // Bigger address end is exclusive. 1222 + kPointerSize; // Bigger address end is exclusive.
1218 1223
1219 if (unused_stack_top > unused_stack_bottom) { 1224 if (unused_stack_top > unused_stack_bottom) {
1220 return "Not enough space for frame dropper frame"; 1225 return "Not enough space for frame dropper frame";
1221 } 1226 }
1222 1227
1223 // Committing now. After this point we should return only NULL value. 1228 // Committing now. After this point we should return only NULL value.
1224 1229
1225 FixTryCatchHandler(pre_top_frame, bottom_js_frame); 1230 FixTryCatchHandler(pre_top_frame, bottom_js_frame);
1226 // Make sure FixTryCatchHandler is idempotent. 1231 // Make sure FixTryCatchHandler is idempotent.
1227 ASSERT(!FixTryCatchHandler(pre_top_frame, bottom_js_frame)); 1232 ASSERT(!FixTryCatchHandler(pre_top_frame, bottom_js_frame));
1228 1233
1229 Handle<Code> code(Builtins::builtin(Builtins::FrameDropper_LiveEdit)); 1234 Handle<Code> code(Isolate::Current()->builtins()->builtin(
1235 Builtins::FrameDropper_LiveEdit));
1230 top_frame->set_pc(code->entry()); 1236 top_frame->set_pc(code->entry());
1231 pre_top_frame->SetCallerFp(bottom_js_frame->fp()); 1237 pre_top_frame->SetCallerFp(bottom_js_frame->fp());
1232 1238
1233 Debug::SetUpFrameDropperFrame(bottom_js_frame, code); 1239 Debug::SetUpFrameDropperFrame(bottom_js_frame, code);
1234 1240
1235 for (Address a = unused_stack_top; 1241 for (Address a = unused_stack_top;
1236 a < unused_stack_bottom; 1242 a < unused_stack_bottom;
1237 a += kPointerSize) { 1243 a += kPointerSize) {
1238 Memory::Object_at(a) = Smi::FromInt(0); 1244 Memory::Object_at(a) = Smi::FromInt(0);
1239 } 1245 }
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 if (error_message != NULL) { 1407 if (error_message != NULL) {
1402 // Add error message as an array extra element. 1408 // Add error message as an array extra element.
1403 Vector<const char> vector_message(error_message, StrLength(error_message)); 1409 Vector<const char> vector_message(error_message, StrLength(error_message));
1404 Handle<String> str = Factory::NewStringFromAscii(vector_message); 1410 Handle<String> str = Factory::NewStringFromAscii(vector_message);
1405 SetElement(result, len, str); 1411 SetElement(result, len, str);
1406 } 1412 }
1407 return result; 1413 return result;
1408 } 1414 }
1409 1415
1410 1416
1411 LiveEditFunctionTracker::LiveEditFunctionTracker(FunctionLiteral* fun) { 1417 LiveEditFunctionTracker::LiveEditFunctionTracker(Isolate* isolate,
1412 if (active_function_info_listener != NULL) { 1418 FunctionLiteral* fun)
1413 active_function_info_listener->FunctionStarted(fun); 1419 : isolate_(isolate) {
1420 if (isolate_->active_function_info_listener() != NULL) {
1421 isolate_->active_function_info_listener()->FunctionStarted(fun);
1414 } 1422 }
1415 } 1423 }
1416 1424
1417 1425
1418 LiveEditFunctionTracker::~LiveEditFunctionTracker() { 1426 LiveEditFunctionTracker::~LiveEditFunctionTracker() {
1419 if (active_function_info_listener != NULL) { 1427 if (isolate_->active_function_info_listener() != NULL) {
1420 active_function_info_listener->FunctionDone(); 1428 isolate_->active_function_info_listener()->FunctionDone();
1421 } 1429 }
1422 } 1430 }
1423 1431
1424 1432
1425 void LiveEditFunctionTracker::RecordFunctionInfo( 1433 void LiveEditFunctionTracker::RecordFunctionInfo(
1426 Handle<SharedFunctionInfo> info, FunctionLiteral* lit) { 1434 Handle<SharedFunctionInfo> info, FunctionLiteral* lit) {
1427 if (active_function_info_listener != NULL) { 1435 if (isolate_->active_function_info_listener() != NULL) {
1428 active_function_info_listener->FunctionInfo(info, lit->scope()); 1436 isolate_->active_function_info_listener()->FunctionInfo(info, lit->scope());
1429 } 1437 }
1430 } 1438 }
1431 1439
1432 1440
1433 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { 1441 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) {
1434 active_function_info_listener->FunctionCode(code); 1442 isolate_->active_function_info_listener()->FunctionCode(code);
1435 } 1443 }
1436 1444
1437 1445
1438 bool LiveEditFunctionTracker::IsActive() { 1446 bool LiveEditFunctionTracker::IsActive(Isolate* isolate) {
1439 return active_function_info_listener != NULL; 1447 return isolate->active_function_info_listener() != NULL;
1440 } 1448 }
1441 1449
1442 1450
1443 #else // ENABLE_DEBUGGER_SUPPORT 1451 #else // ENABLE_DEBUGGER_SUPPORT
1444 1452
1445 // This ifdef-else-endif section provides working or stub implementation of 1453 // This ifdef-else-endif section provides working or stub implementation of
1446 // LiveEditFunctionTracker. 1454 // LiveEditFunctionTracker.
1447 LiveEditFunctionTracker::LiveEditFunctionTracker(FunctionLiteral* fun) { 1455 LiveEditFunctionTracker::LiveEditFunctionTracker(Isolate* isolate,
1456 FunctionLiteral* fun) {
1448 } 1457 }
1449 1458
1450 1459
1451 LiveEditFunctionTracker::~LiveEditFunctionTracker() { 1460 LiveEditFunctionTracker::~LiveEditFunctionTracker() {
1452 } 1461 }
1453 1462
1454 1463
1455 void LiveEditFunctionTracker::RecordFunctionInfo( 1464 void LiveEditFunctionTracker::RecordFunctionInfo(
1456 Handle<SharedFunctionInfo> info, FunctionLiteral* lit) { 1465 Handle<SharedFunctionInfo> info, FunctionLiteral* lit) {
1457 } 1466 }
1458 1467
1459 1468
1460 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) { 1469 void LiveEditFunctionTracker::RecordRootFunctionInfo(Handle<Code> code) {
1461 } 1470 }
1462 1471
1463 1472
1464 bool LiveEditFunctionTracker::IsActive() { 1473 bool LiveEditFunctionTracker::IsActive() {
1465 return false; 1474 return false;
1466 } 1475 }
1467 1476
1468 #endif // ENABLE_DEBUGGER_SUPPORT 1477 #endif // ENABLE_DEBUGGER_SUPPORT
1469 1478
1470 1479
1471 1480
1472 } } // namespace v8::internal 1481 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/liveedit.h ('k') | src/messages.cc » ('j') | src/runtime.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698