From b4c152545d33c36f6454c0c2c19bda6b84f54639 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Wed, 1 Jun 2011 23:11:10 +0000 Subject: [PATCH] Revert "Fix Issue 1320: LiveEdit: text differencer fails with out of memory on large files" Breaks compilation on Linux. This reverts commit e72c5b1d69fb2cb2d5973f172666dd5d477e6f7e. git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@8154 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/liveedit-debugger.js | 6 +-- src/liveedit.cc | 100 ++++++++----------------------------------- src/liveedit.h | 8 ++-- src/runtime.cc | 2 +- test/cctest/test-liveedit.cc | 10 +---- 5 files changed, 25 insertions(+), 101 deletions(-) diff --git a/src/liveedit-debugger.js b/src/liveedit-debugger.js index 291bd52..e05c53c 100644 --- a/src/liveedit-debugger.js +++ b/src/liveedit-debugger.js @@ -988,11 +988,7 @@ Debug.LiveEdit = new function() { this.SetScriptSource = SetScriptSource; function CompareStrings(s1, s2) { - try { - return %LiveEditCompareStrings(s1, s2); - } catch (e) { - throw new Failure("Failed to calculate text difference: " + String(e)); - } + return %LiveEditCompareStrings(s1, s2); } // Applies the change to the script. diff --git a/src/liveedit.cc b/src/liveedit.cc index def212f..3ebcdbf 100644 --- a/src/liveedit.cc +++ b/src/liveedit.cc @@ -59,64 +59,18 @@ void SetElementNonStrict(Handle object, USE(no_failure); } -// Creates string expression and throws it in V8 isolate. -void ThrowStringException(const char* str, Isolate* isolate) { - Vector str_vector(str, strlen(str)); - MaybeObject* maybe_exception = - isolate->heap()->AllocateStringFromAscii(str_vector); - Object* exception; - if (maybe_exception->ToObject(&exception)) { - isolate->Throw(exception, NULL); - } -} - // A simple implementation of dynamic programming algorithm. It solves -// the problem of finding the difference of 2 arrays. It uses a table of -// results of subproblems. Each cell contains a number together with 2-bit flag +// the problem of finding the difference of 2 arrays. It uses a table of results +// of subproblems. Each cell contains a number together with 2-bit flag // that helps building the chunk list. class Differencer { public: - explicit Differencer(Comparator::Input* input, Isolate* isolate, - bool* has_exception) - : input_(input), buffer_(NULL), len1_(input->GetLength1()), - len2_(input->GetLength2()) { - // Put multiply result into a bigger integer. - int64_t multiply = - static_cast(len1_) * static_cast(len2_); - - // Maximum table size is max_int. Within this limit it's easy to check - // for multiply overflow. Should we support bigger numbers? - if (multiply > kMaxInt) { - ThrowStringException("Too many lines: differencer table size is too big", - isolate); - *has_exception = true; - return; - } - multiply *= sizeof(int); // NOLINT - size_t size = multiply; - if (size != multiply) { - // Shouldn't be reachable. - ThrowStringException( - "Too many lines: " - "differencer table buffer size doesn't fit into size_t", isolate); - *has_exception = true; - return; - } - void* p = malloc(size); - if (p == NULL) { - ThrowStringException( - "Too many lines: not enough memory for differencer table buffer", - isolate); - *has_exception = true; - return; - } - buffer_ = reinterpret_cast(p); + explicit Differencer(Comparator::Input* input) + : input_(input), len1_(input->GetLength1()), len2_(input->GetLength2()) { + buffer_ = NewArray(len1_ * len2_); } - ~Differencer() { - if (buffer_ != NULL) { - free(buffer_); - } + DeleteArray(buffer_); } void Initialize() { @@ -305,18 +259,12 @@ class Differencer { }; -MUST_USE_RESULT MaybeObject/**/* Comparator::CalculateDifference( - Comparator::Input* input, Comparator::Output* result_writer, - Isolate* isolate) { - bool has_exception = false; - Differencer differencer(input, isolate, &has_exception); - if (has_exception) { - return Failure::Exception(); - } +void Comparator::CalculateDifference(Comparator::Input* input, + Comparator::Output* result_writer) { + Differencer differencer(input); differencer.Initialize(); differencer.FillTable(); differencer.SaveResult(result_writer); - return Smi::FromInt(0); // Unused value. } @@ -576,10 +524,9 @@ class TokenizingLineArrayCompareOutput : public SubrangableOutput { public: TokenizingLineArrayCompareOutput(LineEndsWrapper line_ends1, LineEndsWrapper line_ends2, - Handle s1, Handle s2, - Isolate* isolate) + Handle s1, Handle s2) : line_ends1_(line_ends1), line_ends2_(line_ends2), s1_(s1), s2_(s2), - subrange_offset1_(0), subrange_offset2_(0), isolate_(isolate) { + subrange_offset1_(0), subrange_offset2_(0) { } void AddChunk(int line_pos1, int line_pos2, int line_len1, int line_len2) { @@ -600,12 +547,7 @@ class TokenizingLineArrayCompareOutput : public SubrangableOutput { TokensCompareOutput tokens_output(&array_writer_, char_pos1, char_pos2); - MaybeObject* res = Comparator::CalculateDifference(&tokens_input, - &tokens_output, isolate_); - if (res->IsFailure()) { - // We asked for a small amount of memory, this should not happen. - UNREACHABLE(); - } + Comparator::CalculateDifference(&tokens_input, &tokens_output); } else { array_writer_.WriteChunk(char_pos1, char_pos2, char_len1, char_len2); } @@ -631,14 +573,11 @@ class TokenizingLineArrayCompareOutput : public SubrangableOutput { Handle s2_; int subrange_offset1_; int subrange_offset2_; - Isolate* isolate_; }; -MUST_USE_RESULT MaybeObject/**/* LiveEdit::CompareStrings( - Handle s1, Handle s2) { - - Isolate* isolate = Isolate::Current(); +Handle LiveEdit::CompareStrings(Handle s1, + Handle s2) { s1 = FlattenGetString(s1); s2 = FlattenGetString(s2); @@ -646,18 +585,13 @@ MUST_USE_RESULT MaybeObject/**/* LiveEdit::CompareStrings( LineEndsWrapper line_ends2(s2); LineArrayCompareInput input(s1, s2, line_ends1, line_ends2); - TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2, - isolate); + TokenizingLineArrayCompareOutput output(line_ends1, line_ends2, s1, s2); NarrowDownInput(&input, &output); - MaybeObject* result = Comparator::CalculateDifference(&input, &output, - isolate); - if (result->IsFailure()) { - return result; - } + Comparator::CalculateDifference(&input, &output); - return *output.GetResult(); + return output.GetResult(); } diff --git a/src/liveedit.h b/src/liveedit.h index 41c8661..d6499de 100644 --- a/src/liveedit.h +++ b/src/liveedit.h @@ -135,8 +135,8 @@ class LiveEdit : AllStatic { // Compares 2 strings line-by-line, then token-wise and returns diff in form // of array of triplets (pos1, pos1_end, pos2_end) describing list // of diff chunks. - static MUST_USE_RESULT MaybeObject/**/* CompareStrings( - Handle s1, Handle s2); + static Handle CompareStrings(Handle s1, + Handle s2); }; @@ -168,8 +168,8 @@ class Comparator { }; // Finds the difference between 2 arrays of elements. - static MUST_USE_RESULT MaybeObject/**/* CalculateDifference( - Input* input, Output* result_writer, Isolate* isolate); + static void CalculateDifference(Input* input, + Output* result_writer); }; #endif // ENABLE_DEBUGGER_SUPPORT diff --git a/src/runtime.cc b/src/runtime.cc index 55d5c92..08acfd1 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -11594,7 +11594,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_LiveEditCompareStrings) { CONVERT_ARG_CHECKED(String, s1, 0); CONVERT_ARG_CHECKED(String, s2, 1); - return LiveEdit::CompareStrings(s1, s2); + return *LiveEdit::CompareStrings(s1, s2); } diff --git a/test/cctest/test-liveedit.cc b/test/cctest/test-liveedit.cc index 8cd3762..2498fca 100644 --- a/test/cctest/test-liveedit.cc +++ b/test/cctest/test-liveedit.cc @@ -95,18 +95,12 @@ void CompareStringsOneWay(const char* s1, const char* s2, int expected_diff_parameter = -1) { StringCompareInput input(s1, s2); - Isolate* isolate = Isolate::Current(); - ZoneScope zone_scope(isolate, DELETE_ON_EXIT); + ZoneScope zone_scope(Isolate::Current(), DELETE_ON_EXIT); DiffChunkStruct* first_chunk; ListDiffOutputWriter writer(&first_chunk); - { - MaybeObject* maybe_result = - Comparator::CalculateDifference(&input, &writer, isolate); - ASSERT_EQ(maybe_result->IsFailure(), false); - USE(maybe_result); - } + Comparator::CalculateDifference(&input, &writer); int len1 = StrLength(s1); int len2 = StrLength(s2); -- 2.7.4