| OLD | NEW |
| 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 18 matching lines...) Expand all Loading... |
| 29 #include "v8.h" | 29 #include "v8.h" |
| 30 | 30 |
| 31 #include "liveedit.h" | 31 #include "liveedit.h" |
| 32 | 32 |
| 33 #include "compiler.h" | 33 #include "compiler.h" |
| 34 #include "compilation-cache.h" | 34 #include "compilation-cache.h" |
| 35 #include "debug.h" | 35 #include "debug.h" |
| 36 #include "deoptimizer.h" | 36 #include "deoptimizer.h" |
| 37 #include "global-handles.h" | 37 #include "global-handles.h" |
| 38 #include "memory.h" | 38 #include "memory.h" |
| 39 #include "oprofile-agent.h" | |
| 40 #include "parser.h" | 39 #include "parser.h" |
| 41 #include "scopeinfo.h" | 40 #include "scopeinfo.h" |
| 42 #include "scopes.h" | 41 #include "scopes.h" |
| 43 | 42 |
| 44 namespace v8 { | 43 namespace v8 { |
| 45 namespace internal { | 44 namespace internal { |
| 46 | 45 |
| 47 | 46 |
| 48 #ifdef ENABLE_DEBUGGER_SUPPORT | 47 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 49 | 48 |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 for (int i = 0; i < len; i++) { | 267 for (int i = 0; i < len; i++) { |
| 269 ASSERT(buf1.has_more() && buf2.has_more()); | 268 ASSERT(buf1.has_more() && buf2.has_more()); |
| 270 if (buf1.GetNext() != buf2.GetNext()) { | 269 if (buf1.GetNext() != buf2.GetNext()) { |
| 271 return false; | 270 return false; |
| 272 } | 271 } |
| 273 } | 272 } |
| 274 return true; | 273 return true; |
| 275 } | 274 } |
| 276 | 275 |
| 277 | 276 |
| 277 // A helper class that writes chunk numbers into JSArray. |
| 278 // Each chunk is stored as 3 array elements: (pos1_begin, pos1_end, pos2_end). |
| 279 class CompareOutputArrayWriter { |
| 280 public: |
| 281 CompareOutputArrayWriter() |
| 282 : array_(Factory::NewJSArray(10)), current_size_(0) {} |
| 283 |
| 284 Handle<JSArray> GetResult() { |
| 285 return array_; |
| 286 } |
| 287 |
| 288 void WriteChunk(int char_pos1, int char_pos2, int char_len1, int char_len2) { |
| 289 SetElement(array_, current_size_, Handle<Object>(Smi::FromInt(char_pos1))); |
| 290 SetElement(array_, current_size_ + 1, |
| 291 Handle<Object>(Smi::FromInt(char_pos1 + char_len1))); |
| 292 SetElement(array_, current_size_ + 2, |
| 293 Handle<Object>(Smi::FromInt(char_pos2 + char_len2))); |
| 294 current_size_ += 3; |
| 295 } |
| 296 |
| 297 private: |
| 298 Handle<JSArray> array_; |
| 299 int current_size_; |
| 300 }; |
| 301 |
| 302 |
| 303 // Represents 2 strings as 2 arrays of tokens. |
| 304 // TODO(LiveEdit): Currently it's actually an array of charactres. |
| 305 // Make array of tokens instead. |
| 306 class TokensCompareInput : public Comparator::Input { |
| 307 public: |
| 308 TokensCompareInput(Handle<String> s1, int offset1, int len1, |
| 309 Handle<String> s2, int offset2, int len2) |
| 310 : s1_(s1), offset1_(offset1), len1_(len1), |
| 311 s2_(s2), offset2_(offset2), len2_(len2) { |
| 312 } |
| 313 virtual int getLength1() { |
| 314 return len1_; |
| 315 } |
| 316 virtual int getLength2() { |
| 317 return len2_; |
| 318 } |
| 319 bool equals(int index1, int index2) { |
| 320 return s1_->Get(offset1_ + index1) == s2_->Get(offset2_ + index2); |
| 321 } |
| 322 |
| 323 private: |
| 324 Handle<String> s1_; |
| 325 int offset1_; |
| 326 int len1_; |
| 327 Handle<String> s2_; |
| 328 int offset2_; |
| 329 int len2_; |
| 330 }; |
| 331 |
| 332 |
| 333 // Stores compare result in JSArray. Converts substring positions |
| 334 // to absolute positions. |
| 335 class TokensCompareOutput : public Comparator::Output { |
| 336 public: |
| 337 TokensCompareOutput(CompareOutputArrayWriter* array_writer, |
| 338 int offset1, int offset2) |
| 339 : array_writer_(array_writer), offset1_(offset1), offset2_(offset2) { |
| 340 } |
| 341 |
| 342 void AddChunk(int pos1, int pos2, int len1, int len2) { |
| 343 array_writer_->WriteChunk(pos1 + offset1_, pos2 + offset2_, len1, len2); |
| 344 } |
| 345 |
| 346 private: |
| 347 CompareOutputArrayWriter* array_writer_; |
| 348 int offset1_; |
| 349 int offset2_; |
| 350 }; |
| 351 |
| 352 |
| 278 // Wraps raw n-elements line_ends array as a list of n+1 lines. The last line | 353 // Wraps raw n-elements line_ends array as a list of n+1 lines. The last line |
| 279 // never has terminating new line character. | 354 // never has terminating new line character. |
| 280 class LineEndsWrapper { | 355 class LineEndsWrapper { |
| 281 public: | 356 public: |
| 282 explicit LineEndsWrapper(Handle<String> string) | 357 explicit LineEndsWrapper(Handle<String> string) |
| 283 : ends_array_(CalculateLineEnds(string, false)), | 358 : ends_array_(CalculateLineEnds(string, false)), |
| 284 string_len_(string->length()) { | 359 string_len_(string->length()) { |
| 285 } | 360 } |
| 286 int length() { | 361 int length() { |
| 287 return ends_array_->length() + 1; | 362 return ends_array_->length() + 1; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 } | 418 } |
| 344 | 419 |
| 345 private: | 420 private: |
| 346 Handle<String> s1_; | 421 Handle<String> s1_; |
| 347 Handle<String> s2_; | 422 Handle<String> s2_; |
| 348 LineEndsWrapper line_ends1_; | 423 LineEndsWrapper line_ends1_; |
| 349 LineEndsWrapper line_ends2_; | 424 LineEndsWrapper line_ends2_; |
| 350 }; | 425 }; |
| 351 | 426 |
| 352 | 427 |
| 353 // Stores compare result in JSArray. Each chunk is stored as 3 array elements: | 428 // Stores compare result in JSArray. For each chunk tries to conduct |
| 354 // (pos1_begin, pos1_end, pos2_end). | 429 // a fine-grained nested diff token-wise. |
| 355 class LineArrayCompareOutput : public Comparator::Output { | 430 class TokenizingLineArrayCompareOutput : public Comparator::Output { |
| 356 public: | 431 public: |
| 357 LineArrayCompareOutput(LineEndsWrapper line_ends1, LineEndsWrapper line_ends2) | 432 TokenizingLineArrayCompareOutput(LineEndsWrapper line_ends1, |
| 358 : array_(Factory::NewJSArray(10)), current_size_(0), | 433 LineEndsWrapper line_ends2, |
| 359 line_ends1_(line_ends1), line_ends2_(line_ends2) { | 434 Handle<String> s1, Handle<String> s2) |
| 435 : line_ends1_(line_ends1), line_ends2_(line_ends2), s1_(s1), s2_(s2) { |
| 360 } | 436 } |
| 361 | 437 |
| 362 void AddChunk(int line_pos1, int line_pos2, int line_len1, int line_len2) { | 438 void AddChunk(int line_pos1, int line_pos2, int line_len1, int line_len2) { |
| 363 int char_pos1 = line_ends1_.GetLineStart(line_pos1); | 439 int char_pos1 = line_ends1_.GetLineStart(line_pos1); |
| 364 int char_pos2 = line_ends2_.GetLineStart(line_pos2); | 440 int char_pos2 = line_ends2_.GetLineStart(line_pos2); |
| 365 int char_len1 = line_ends1_.GetLineStart(line_pos1 + line_len1) - char_pos1; | 441 int char_len1 = line_ends1_.GetLineStart(line_pos1 + line_len1) - char_pos1; |
| 366 int char_len2 = line_ends2_.GetLineStart(line_pos2 + line_len2) - char_pos2; | 442 int char_len2 = line_ends2_.GetLineStart(line_pos2 + line_len2) - char_pos2; |
| 367 | 443 |
| 368 SetElement(array_, current_size_, Handle<Object>(Smi::FromInt(char_pos1))); | 444 if (char_len1 < CHUNK_LEN_LIMIT && char_len2 < CHUNK_LEN_LIMIT) { |
| 369 SetElement(array_, current_size_ + 1, | 445 // Chunk is small enough to conduct a nested token-level diff. |
| 370 Handle<Object>(Smi::FromInt(char_pos1 + char_len1))); | 446 HandleScope subTaskScope; |
| 371 SetElement(array_, current_size_ + 2, | 447 |
| 372 Handle<Object>(Smi::FromInt(char_pos2 + char_len2))); | 448 TokensCompareInput tokens_input(s1_, char_pos1, char_len1, |
| 373 current_size_ += 3; | 449 s2_, char_pos2, char_len2); |
| 450 TokensCompareOutput tokens_output(&array_writer_, char_pos1, |
| 451 char_pos2); |
| 452 |
| 453 Comparator::CalculateDifference(&tokens_input, &tokens_output); |
| 454 } else { |
| 455 array_writer_.WriteChunk(char_pos1, char_pos2, char_len1, char_len2); |
| 456 } |
| 374 } | 457 } |
| 375 | 458 |
| 376 Handle<JSArray> GetResult() { | 459 Handle<JSArray> GetResult() { |
| 377 return array_; | 460 return array_writer_.GetResult(); |
| 378 } | 461 } |
| 379 | 462 |
| 380 private: | 463 private: |
| 381 Handle<JSArray> array_; | 464 static const int CHUNK_LEN_LIMIT = 800; |
| 382 int current_size_; | 465 |
| 466 CompareOutputArrayWriter array_writer_; |
| 383 LineEndsWrapper line_ends1_; | 467 LineEndsWrapper line_ends1_; |
| 384 LineEndsWrapper line_ends2_; | 468 LineEndsWrapper line_ends2_; |
| 469 Handle<String> s1_; |
| 470 Handle<String> s2_; |
| 385 }; | 471 }; |
| 386 | 472 |
| 387 | 473 |
| 388 Handle<JSArray> LiveEdit::CompareStringsLinewise(Handle<String> s1, | 474 Handle<JSArray> LiveEdit::CompareStrings(Handle<String> s1, |
| 389 Handle<String> s2) { | 475 Handle<String> s2) { |
| 390 LineEndsWrapper line_ends1(s1); | 476 LineEndsWrapper line_ends1(s1); |
| 391 LineEndsWrapper line_ends2(s2); | 477 LineEndsWrapper line_ends2(s2); |
| 392 | 478 |
| 393 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2); | 479 LineArrayCompareInput input(s1, s2, line_ends1, line_ends2); |
| 394 LineArrayCompareOutput output(line_ends1, line_ends2); | 480 TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2); |
| 395 | 481 |
| 396 Comparator::CalculateDifference(&input, &output); | 482 Comparator::CalculateDifference(&input, &output); |
| 397 | 483 |
| 398 return output.GetResult(); | 484 return output.GetResult(); |
| 399 } | 485 } |
| 400 | 486 |
| 401 | 487 |
| 402 static void CompileScriptForTracker(Handle<Script> script) { | 488 static void CompileScriptForTracker(Handle<Script> script) { |
| 403 // TODO(635): support extensions. | 489 // TODO(635): support extensions. |
| 404 PostponeInterruptsScope postpone; | 490 PostponeInterruptsScope postpone; |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1555 | 1641 |
| 1556 bool LiveEditFunctionTracker::IsActive() { | 1642 bool LiveEditFunctionTracker::IsActive() { |
| 1557 return false; | 1643 return false; |
| 1558 } | 1644 } |
| 1559 | 1645 |
| 1560 #endif // ENABLE_DEBUGGER_SUPPORT | 1646 #endif // ENABLE_DEBUGGER_SUPPORT |
| 1561 | 1647 |
| 1562 | 1648 |
| 1563 | 1649 |
| 1564 } } // namespace v8::internal | 1650 } } // namespace v8::internal |
| OLD | NEW |