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

Side by Side Diff: runtime/vm/object.cc

Issue 324843004: Significantly improve performance of code coverage tool by precomputing a map token_pos->line numbe… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 7909 matching lines...) Expand 10 before | Expand all | Expand 10 after
7920 void Script::set_kind(RawScript::Kind value) const { 7920 void Script::set_kind(RawScript::Kind value) const {
7921 raw_ptr()->kind_ = value; 7921 raw_ptr()->kind_ = value;
7922 } 7922 }
7923 7923
7924 7924
7925 void Script::set_tokens(const TokenStream& value) const { 7925 void Script::set_tokens(const TokenStream& value) const {
7926 StorePointer(&raw_ptr()->tokens_, value.raw()); 7926 StorePointer(&raw_ptr()->tokens_, value.raw());
7927 } 7927 }
7928 7928
7929 7929
7930 void Script::set_token_pos_to_line_nr(const TypedData& value) const {
7931 StorePointer(&raw_ptr()->token_pos_to_line_nr_, value.raw());
7932 }
7933
7934
7935 RawTypedData* Script::token_pos_to_line_nr() const {
7936 return raw_ptr()->token_pos_to_line_nr_;
7937 }
7938
7939
7930 void Script::Tokenize(const String& private_key) const { 7940 void Script::Tokenize(const String& private_key) const {
7931 Isolate* isolate = Isolate::Current(); 7941 Isolate* isolate = Isolate::Current();
7932 const TokenStream& tkns = TokenStream::Handle(isolate, tokens()); 7942 const TokenStream& tkns = TokenStream::Handle(isolate, tokens());
7933 if (!tkns.IsNull()) { 7943 if (!tkns.IsNull()) {
7934 // Already tokenized. 7944 // Already tokenized.
7935 return; 7945 return;
7936 } 7946 }
7937 // Get the source, scan and allocate the token stream. 7947 // Get the source, scan and allocate the token stream.
7938 VMTagScope tagScope(isolate, VMTag::kCompileScannerTagId); 7948 VMTagScope tagScope(isolate, VMTag::kCompileScannerTagId);
7939 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer); 7949 TimerScope timer(FLAG_compiler_stats, &CompilerStats::scanner_timer);
(...skipping 14 matching lines...) Expand all
7954 ASSERT(col_offset >= 0); 7964 ASSERT(col_offset >= 0);
7955 raw_ptr()->line_offset_ = line_offset; 7965 raw_ptr()->line_offset_ = line_offset;
7956 raw_ptr()->col_offset_ = col_offset; 7966 raw_ptr()->col_offset_ = col_offset;
7957 } 7967 }
7958 7968
7959 7969
7960 void Script::GetTokenLocation(intptr_t token_pos, 7970 void Script::GetTokenLocation(intptr_t token_pos,
7961 intptr_t* line, 7971 intptr_t* line,
7962 intptr_t* column) const { 7972 intptr_t* column) const {
7963 ASSERT(line != NULL); 7973 ASSERT(line != NULL);
7964 const TokenStream& tkns = TokenStream::Handle(tokens());
7965 if (column == NULL) { 7974 if (column == NULL) {
7975 if (token_pos_to_line_nr() != TypedData::null()) {
7976 const TypedData& array = TypedData::Handle(token_pos_to_line_nr());
7977 *line = array.GetInt32(token_pos * array.ElementSizeInBytes());
7978 return;
7979 }
7980 const TokenStream& tkns = TokenStream::Handle(tokens());
7966 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens); 7981 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
7967 intptr_t cur_line = line_offset() + 1; 7982 intptr_t cur_line = line_offset() + 1;
7968 while (tkit.CurrentPosition() < token_pos && 7983 while (tkit.CurrentPosition() < token_pos &&
7969 tkit.CurrentTokenKind() != Token::kEOS) { 7984 tkit.CurrentTokenKind() != Token::kEOS) {
7970 if (tkit.CurrentTokenKind() == Token::kNEWLINE) { 7985 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
7971 cur_line++; 7986 cur_line++;
7972 } 7987 }
7973 tkit.Advance(); 7988 tkit.Advance();
7974 } 7989 }
7975 *line = cur_line; 7990 *line = cur_line;
7976 } else { 7991 } else {
7992 const TokenStream& tkns = TokenStream::Handle(tokens());
7977 const String& src = String::Handle(Source()); 7993 const String& src = String::Handle(Source());
7978 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos); 7994 intptr_t src_pos = tkns.ComputeSourcePosition(token_pos);
7979 Scanner scanner(src, Symbols::Empty()); 7995 Scanner scanner(src, Symbols::Empty());
7980 scanner.ScanTo(src_pos); 7996 scanner.ScanTo(src_pos);
7981 intptr_t relative_line = scanner.CurrentPosition().line; 7997 intptr_t relative_line = scanner.CurrentPosition().line;
7982 *line = relative_line + line_offset(); 7998 *line = relative_line + line_offset();
7983 *column = scanner.CurrentPosition().column; 7999 *column = scanner.CurrentPosition().column;
7984 // On the first line of the script we must add the column offset. 8000 // On the first line of the script we must add the column offset.
7985 if (relative_line == 1) { 8001 if (relative_line == 1) {
7986 *column += col_offset(); 8002 *column += col_offset();
7987 } 8003 }
7988 } 8004 }
7989 } 8005 }
7990 8006
7991 8007
8008 void Script::ComputeTokenPosToLineNumberArray() const {
8009 if (token_pos_to_line_nr() != TypedData::null()) {
8010 // Already computed.
8011 return;
8012 }
8013
8014 const TokenStream& tkns = TokenStream::Handle(tokens());
8015 const intptr_t len = ExternalTypedData::Handle(tkns.GetStream()).Length();
8016 const TypedData& array =
8017 TypedData::Handle(TypedData::New(kTypedDataInt32ArrayCid, len));
8018 const intptr_t elem_size_in_bytes = array.ElementSizeInBytes();
8019 set_token_pos_to_line_nr(array);
8020 TokenStream::Iterator tkit(tkns, 0, TokenStream::Iterator::kAllTokens);
8021 intptr_t array_offset_in_bytes = 0;
8022 intptr_t cur_line = line_offset() + 1;
8023 while (tkit.CurrentTokenKind() != Token::kEOS) {
8024 array.SetInt32(tkit.CurrentPosition() * elem_size_in_bytes, cur_line);
8025 array_offset_in_bytes += elem_size_in_bytes;
8026 if (tkit.CurrentTokenKind() == Token::kNEWLINE) {
8027 cur_line++;
8028 }
8029 tkit.Advance();
8030 }
8031 }
8032
8033
7992 void Script::TokenRangeAtLine(intptr_t line_number, 8034 void Script::TokenRangeAtLine(intptr_t line_number,
7993 intptr_t* first_token_index, 8035 intptr_t* first_token_index,
7994 intptr_t* last_token_index) const { 8036 intptr_t* last_token_index) const {
7995 ASSERT(first_token_index != NULL && last_token_index != NULL); 8037 ASSERT(first_token_index != NULL && last_token_index != NULL);
7996 ASSERT(line_number > 0); 8038 ASSERT(line_number > 0);
7997 *first_token_index = -1; 8039 *first_token_index = -1;
7998 *last_token_index = -1; 8040 *last_token_index = -1;
7999 const TokenStream& tkns = TokenStream::Handle(tokens()); 8041 const TokenStream& tkns = TokenStream::Handle(tokens());
8000 line_number -= line_offset(); 8042 line_number -= line_offset();
8001 if (line_number < 1) line_number = 1; 8043 if (line_number < 1) line_number = 1;
(...skipping 10254 matching lines...) Expand 10 before | Expand all | Expand 10 after
18256 16, // kTypedDataFloat64x2ArrayCid, 18298 16, // kTypedDataFloat64x2ArrayCid,
18257 }; 18299 };
18258 18300
18259 18301
18260 RawTypedData* TypedData::New(intptr_t class_id, 18302 RawTypedData* TypedData::New(intptr_t class_id,
18261 intptr_t len, 18303 intptr_t len,
18262 Heap::Space space) { 18304 Heap::Space space) {
18263 if (len < 0 || len > TypedData::MaxElements(class_id)) { 18305 if (len < 0 || len > TypedData::MaxElements(class_id)) {
18264 FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len); 18306 FATAL1("Fatal error in TypedData::New: invalid len %" Pd "\n", len);
18265 } 18307 }
18308 ASSERT(RawObject::IsTypedDataClassId(class_id));
18266 TypedData& result = TypedData::Handle(); 18309 TypedData& result = TypedData::Handle();
18267 { 18310 {
18268 intptr_t lengthInBytes = len * ElementSizeInBytes(class_id); 18311 intptr_t lengthInBytes = len * ElementSizeInBytes(class_id);
18269 RawObject* raw = Object::Allocate(class_id, 18312 RawObject* raw = Object::Allocate(class_id,
18270 TypedData::InstanceSize(lengthInBytes), 18313 TypedData::InstanceSize(lengthInBytes),
18271 space); 18314 space);
18272 NoGCScope no_gc; 18315 NoGCScope no_gc;
18273 result ^= raw; 18316 result ^= raw;
18274 result.SetLength(len); 18317 result.SetLength(len);
18275 if (len > 0) { 18318 if (len > 0) {
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
19007 return tag_label.ToCString(); 19050 return tag_label.ToCString();
19008 } 19051 }
19009 19052
19010 19053
19011 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 19054 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
19012 Instance::PrintJSONImpl(stream, ref); 19055 Instance::PrintJSONImpl(stream, ref);
19013 } 19056 }
19014 19057
19015 19058
19016 } // namespace dart 19059 } // namespace dart
OLDNEW
« runtime/vm/coverage.cc ('K') | « runtime/vm/object.h ('k') | runtime/vm/raw_object.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698