| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/objects.h" | 5 #include "src/objects.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 #include <iomanip> | 8 #include <iomanip> |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <sstream> | 10 #include <sstream> |
| (...skipping 13352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13363 array->set_map(isolate->heap()->fixed_cow_array_map()); | 13363 array->set_map(isolate->heap()->fixed_cow_array_map()); |
| 13364 } | 13364 } |
| 13365 | 13365 |
| 13366 script->set_line_ends(*array); | 13366 script->set_line_ends(*array); |
| 13367 DCHECK(script->line_ends()->IsFixedArray()); | 13367 DCHECK(script->line_ends()->IsFixedArray()); |
| 13368 } | 13368 } |
| 13369 | 13369 |
| 13370 #define SMI_VALUE(x) (Smi::cast(x)->value()) | 13370 #define SMI_VALUE(x) (Smi::cast(x)->value()) |
| 13371 bool Script::GetPositionInfo(int position, PositionInfo* info, | 13371 bool Script::GetPositionInfo(int position, PositionInfo* info, |
| 13372 OffsetFlag offset_flag) { | 13372 OffsetFlag offset_flag) { |
| 13373 Handle<Script> script(this); | 13373 Script* script = this; |
| 13374 InitLineEnds(script); | 13374 if (script->line_ends()->IsUndefined(GetIsolate())) { |
| 13375 Handle<Script> script_handle(script); |
| 13376 InitLineEnds(script_handle); |
| 13377 script = *script_handle; |
| 13378 } |
| 13375 | 13379 |
| 13376 DisallowHeapAllocation no_allocation; | 13380 DisallowHeapAllocation no_allocation; |
| 13377 | 13381 |
| 13378 DCHECK(script->line_ends()->IsFixedArray()); | 13382 DCHECK(script->line_ends()->IsFixedArray()); |
| 13379 FixedArray* ends = FixedArray::cast(script->line_ends()); | 13383 FixedArray* ends = FixedArray::cast(script->line_ends()); |
| 13380 | 13384 |
| 13381 const int ends_len = ends->length(); | 13385 const int ends_len = ends->length(); |
| 13382 if (ends_len == 0) return false; | 13386 if (ends_len == 0) return false; |
| 13383 | 13387 |
| 13384 // Return early on invalid positions. Negative positions behave as if 0 was | 13388 // Return early on invalid positions. Negative positions behave as if 0 was |
| (...skipping 28 matching lines...) Expand all Loading... |
| 13413 DCHECK(SMI_VALUE(ends->get(info->line)) >= position && | 13417 DCHECK(SMI_VALUE(ends->get(info->line)) >= position && |
| 13414 SMI_VALUE(ends->get(info->line - 1)) < position); | 13418 SMI_VALUE(ends->get(info->line - 1)) < position); |
| 13415 info->line_start = SMI_VALUE(ends->get(info->line - 1)) + 1; | 13419 info->line_start = SMI_VALUE(ends->get(info->line - 1)) + 1; |
| 13416 info->column = position - info->line_start; | 13420 info->column = position - info->line_start; |
| 13417 } | 13421 } |
| 13418 | 13422 |
| 13419 // Line end is position of the linebreak character. | 13423 // Line end is position of the linebreak character. |
| 13420 info->line_end = SMI_VALUE(ends->get(info->line)); | 13424 info->line_end = SMI_VALUE(ends->get(info->line)); |
| 13421 if (info->line_end > 0) { | 13425 if (info->line_end > 0) { |
| 13422 DCHECK(script->source()->IsString()); | 13426 DCHECK(script->source()->IsString()); |
| 13423 Handle<String> src(String::cast(script->source())); | 13427 String* src = String::cast(script->source()); |
| 13424 if (src->length() >= info->line_end && | 13428 if (src->length() >= info->line_end && |
| 13425 src->Get(info->line_end - 1) == '\r') { | 13429 src->Get(info->line_end - 1) == '\r') { |
| 13426 info->line_end--; | 13430 info->line_end--; |
| 13427 } | 13431 } |
| 13428 } | 13432 } |
| 13429 | 13433 |
| 13430 // Add offsets if requested. | 13434 // Add offsets if requested. |
| 13431 if (offset_flag == WITH_OFFSET) { | 13435 if (offset_flag == WITH_OFFSET) { |
| 13432 if (info->line == 0) { | 13436 if (info->line == 0) { |
| 13433 info->column += script->column_offset(); | 13437 info->column += script->column_offset(); |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14232 } | 14236 } |
| 14233 } | 14237 } |
| 14234 | 14238 |
| 14235 int AbstractCode::SourcePosition(int offset) { | 14239 int AbstractCode::SourcePosition(int offset) { |
| 14236 int position = 0; | 14240 int position = 0; |
| 14237 // Subtract one because the current PC is one instruction after the call site. | 14241 // Subtract one because the current PC is one instruction after the call site. |
| 14238 if (IsCode()) offset--; | 14242 if (IsCode()) offset--; |
| 14239 for (SourcePositionTableIterator iterator(source_position_table()); | 14243 for (SourcePositionTableIterator iterator(source_position_table()); |
| 14240 !iterator.done() && iterator.code_offset() <= offset; | 14244 !iterator.done() && iterator.code_offset() <= offset; |
| 14241 iterator.Advance()) { | 14245 iterator.Advance()) { |
| 14242 position = iterator.source_position(); | 14246 position = iterator.source_position().ScriptOffset(); |
| 14243 } | 14247 } |
| 14244 return position; | 14248 return position; |
| 14245 } | 14249 } |
| 14246 | 14250 |
| 14247 int AbstractCode::SourceStatementPosition(int offset) { | 14251 int AbstractCode::SourceStatementPosition(int offset) { |
| 14248 // First find the closest position. | 14252 // First find the closest position. |
| 14249 int position = SourcePosition(offset); | 14253 int position = SourcePosition(offset); |
| 14250 // Now find the closest statement position before the position. | 14254 // Now find the closest statement position before the position. |
| 14251 int statement_position = 0; | 14255 int statement_position = 0; |
| 14252 for (SourcePositionTableIterator it(source_position_table()); !it.done(); | 14256 for (SourcePositionTableIterator it(source_position_table()); !it.done(); |
| 14253 it.Advance()) { | 14257 it.Advance()) { |
| 14254 if (it.is_statement()) { | 14258 if (it.is_statement()) { |
| 14255 int p = it.source_position(); | 14259 int p = it.source_position().ScriptOffset(); |
| 14256 if (statement_position < p && p <= position) { | 14260 if (statement_position < p && p <= position) { |
| 14257 statement_position = p; | 14261 statement_position = p; |
| 14258 } | 14262 } |
| 14259 } | 14263 } |
| 14260 } | 14264 } |
| 14261 return statement_position; | 14265 return statement_position; |
| 14262 } | 14266 } |
| 14263 | 14267 |
| 14264 void JSFunction::ClearTypeFeedbackInfo() { | 14268 void JSFunction::ClearTypeFeedbackInfo() { |
| 14265 feedback_vector()->ClearSlots(shared()); | 14269 feedback_vector()->ClearSlots(shared()); |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14465 } | 14469 } |
| 14466 return NULL; | 14470 return NULL; |
| 14467 } | 14471 } |
| 14468 | 14472 |
| 14469 | 14473 |
| 14470 void Code::PrintDeoptLocation(FILE* out, Address pc) { | 14474 void Code::PrintDeoptLocation(FILE* out, Address pc) { |
| 14471 Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(this, pc); | 14475 Deoptimizer::DeoptInfo info = Deoptimizer::GetDeoptInfo(this, pc); |
| 14472 class SourcePosition pos = info.position; | 14476 class SourcePosition pos = info.position; |
| 14473 if (info.deopt_reason != DeoptimizeReason::kNoReason || !pos.IsUnknown()) { | 14477 if (info.deopt_reason != DeoptimizeReason::kNoReason || !pos.IsUnknown()) { |
| 14474 if (FLAG_hydrogen_track_positions) { | 14478 if (FLAG_hydrogen_track_positions) { |
| 14475 PrintF(out, " ;;; deoptimize at %d_%d: %s\n", | 14479 PrintF(out, " ;;; deoptimize at %d_%d: %s\n", pos.InliningId(), |
| 14476 pos.inlining_id(), pos.position(), | 14480 pos.ScriptOffset(), DeoptimizeReasonToString(info.deopt_reason)); |
| 14477 DeoptimizeReasonToString(info.deopt_reason)); | |
| 14478 } else { | 14481 } else { |
| 14479 PrintF(out, " ;;; deoptimize at %d: %s\n", pos.raw(), | 14482 PrintF(out, " ;;; deoptimize at "); |
| 14480 DeoptimizeReasonToString(info.deopt_reason)); | 14483 OFStream outstr(out); |
| 14484 pos.Print(outstr, this); |
| 14485 PrintF(out, ", %s\n", DeoptimizeReasonToString(info.deopt_reason)); |
| 14481 } | 14486 } |
| 14482 } | 14487 } |
| 14483 } | 14488 } |
| 14484 | 14489 |
| 14485 | 14490 |
| 14486 bool Code::CanDeoptAt(Address pc) { | 14491 bool Code::CanDeoptAt(Address pc) { |
| 14487 DeoptimizationInputData* deopt_data = | 14492 DeoptimizationInputData* deopt_data = |
| 14488 DeoptimizationInputData::cast(deoptimization_data()); | 14493 DeoptimizationInputData::cast(deoptimization_data()); |
| 14489 Address code_start_address = instruction_start(); | 14494 Address code_start_address = instruction_start(); |
| 14490 for (int i = 0; i < deopt_data->DeoptCount(); i++) { | 14495 for (int i = 0; i < deopt_data->DeoptCount(); i++) { |
| (...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 14909 } | 14914 } |
| 14910 } | 14915 } |
| 14911 } | 14916 } |
| 14912 os << "\n"; | 14917 os << "\n"; |
| 14913 | 14918 |
| 14914 SourcePositionTableIterator it(source_position_table()); | 14919 SourcePositionTableIterator it(source_position_table()); |
| 14915 if (!it.done()) { | 14920 if (!it.done()) { |
| 14916 os << "Source positions:\n pc offset position\n"; | 14921 os << "Source positions:\n pc offset position\n"; |
| 14917 for (; !it.done(); it.Advance()) { | 14922 for (; !it.done(); it.Advance()) { |
| 14918 os << std::setw(10) << it.code_offset() << std::setw(10) | 14923 os << std::setw(10) << it.code_offset() << std::setw(10) |
| 14919 << it.source_position() << (it.is_statement() ? " statement" : "") | 14924 << it.source_position().ScriptOffset() |
| 14920 << "\n"; | 14925 << (it.is_statement() ? " statement" : "") << "\n"; |
| 14921 } | 14926 } |
| 14922 os << "\n"; | 14927 os << "\n"; |
| 14923 } | 14928 } |
| 14924 | 14929 |
| 14925 if (kind() == FUNCTION) { | 14930 if (kind() == FUNCTION) { |
| 14926 DeoptimizationOutputData* data = | 14931 DeoptimizationOutputData* data = |
| 14927 DeoptimizationOutputData::cast(this->deoptimization_data()); | 14932 DeoptimizationOutputData::cast(this->deoptimization_data()); |
| 14928 data->DeoptimizationOutputDataPrint(os); | 14933 data->DeoptimizationOutputDataPrint(os); |
| 14929 } else if (kind() == OPTIMIZED_FUNCTION) { | 14934 } else if (kind() == OPTIMIZED_FUNCTION) { |
| 14930 DeoptimizationInputData* data = | 14935 DeoptimizationInputData* data = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 15012 os << "Parameter count " << parameter_count() << "\n"; | 15017 os << "Parameter count " << parameter_count() << "\n"; |
| 15013 os << "Frame size " << frame_size() << "\n"; | 15018 os << "Frame size " << frame_size() << "\n"; |
| 15014 | 15019 |
| 15015 const uint8_t* base_address = GetFirstBytecodeAddress(); | 15020 const uint8_t* base_address = GetFirstBytecodeAddress(); |
| 15016 SourcePositionTableIterator source_positions(source_position_table()); | 15021 SourcePositionTableIterator source_positions(source_position_table()); |
| 15017 | 15022 |
| 15018 interpreter::BytecodeArrayIterator iterator(handle(this)); | 15023 interpreter::BytecodeArrayIterator iterator(handle(this)); |
| 15019 while (!iterator.done()) { | 15024 while (!iterator.done()) { |
| 15020 if (!source_positions.done() && | 15025 if (!source_positions.done() && |
| 15021 iterator.current_offset() == source_positions.code_offset()) { | 15026 iterator.current_offset() == source_positions.code_offset()) { |
| 15022 os << std::setw(5) << source_positions.source_position(); | 15027 os << std::setw(5) << source_positions.source_position().ScriptOffset(); |
| 15023 os << (source_positions.is_statement() ? " S> " : " E> "); | 15028 os << (source_positions.is_statement() ? " S> " : " E> "); |
| 15024 source_positions.Advance(); | 15029 source_positions.Advance(); |
| 15025 } else { | 15030 } else { |
| 15026 os << " "; | 15031 os << " "; |
| 15027 } | 15032 } |
| 15028 const uint8_t* current_address = base_address + iterator.current_offset(); | 15033 const uint8_t* current_address = base_address + iterator.current_offset(); |
| 15029 os << reinterpret_cast<const void*>(current_address) << " @ " | 15034 os << reinterpret_cast<const void*>(current_address) << " @ " |
| 15030 << std::setw(4) << iterator.current_offset() << " : "; | 15035 << std::setw(4) << iterator.current_offset() << " : "; |
| 15031 interpreter::BytecodeDecoder::Decode(os, current_address, | 15036 interpreter::BytecodeDecoder::Decode(os, current_address, |
| 15032 parameter_count()); | 15037 parameter_count()); |
| (...skipping 5189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 20222 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) | 20227 ns, Accessors::ModuleNamespaceEntryInfo(isolate, name, attr)) |
| 20223 .Check(); | 20228 .Check(); |
| 20224 } | 20229 } |
| 20225 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); | 20230 JSObject::PreventExtensions(ns, THROW_ON_ERROR).ToChecked(); |
| 20226 | 20231 |
| 20227 return ns; | 20232 return ns; |
| 20228 } | 20233 } |
| 20229 | 20234 |
| 20230 } // namespace internal | 20235 } // namespace internal |
| 20231 } // namespace v8 | 20236 } // namespace v8 |
| OLD | NEW |