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

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

Issue 1938653002: JIT precompilated snapshots. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 7 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
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 3408 matching lines...) Expand 10 before | Expand all | Expand 10 after
3419 3419
3420 TokenPosition Class::ComputeEndTokenPos() const { 3420 TokenPosition Class::ComputeEndTokenPos() const {
3421 // Return the begin token for synthetic classes. 3421 // Return the begin token for synthetic classes.
3422 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) { 3422 if (is_synthesized_class() || IsMixinApplication() || IsTopLevel()) {
3423 return token_pos(); 3423 return token_pos();
3424 } 3424 }
3425 const Script& scr = Script::Handle(script()); 3425 const Script& scr = Script::Handle(script());
3426 ASSERT(!scr.IsNull()); 3426 ASSERT(!scr.IsNull());
3427 const TokenStream& tkns = TokenStream::Handle(scr.tokens()); 3427 const TokenStream& tkns = TokenStream::Handle(scr.tokens());
3428 if (tkns.IsNull()) { 3428 if (tkns.IsNull()) {
3429 ASSERT(Dart::IsRunningPrecompiledCode()); 3429 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
3430 return TokenPosition::kNoSource; 3430 return TokenPosition::kNoSource;
3431 } 3431 }
3432 TokenStream::Iterator tkit(tkns, 3432 TokenStream::Iterator tkit(tkns,
3433 token_pos(), 3433 token_pos(),
3434 TokenStream::Iterator::kNoNewlines); 3434 TokenStream::Iterator::kNoNewlines);
3435 intptr_t level = 0; 3435 intptr_t level = 0;
3436 while (tkit.CurrentTokenKind() != Token::kEOS) { 3436 while (tkit.CurrentTokenKind() != Token::kEOS) {
3437 if (tkit.CurrentTokenKind() == Token::kLBRACE) { 3437 if (tkit.CurrentTokenKind() == Token::kLBRACE) {
3438 level++; 3438 level++;
3439 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) { 3439 } else if (tkit.CurrentTokenKind() == Token::kRBRACE) {
(...skipping 5375 matching lines...) Expand 10 before | Expand all | Expand 10 after
8815 if (source.IsNull()) { 8815 if (source.IsNull()) {
8816 return GenerateSource(); 8816 return GenerateSource();
8817 } 8817 }
8818 return raw_ptr()->source_; 8818 return raw_ptr()->source_;
8819 } 8819 }
8820 8820
8821 8821
8822 RawString* Script::GenerateSource() const { 8822 RawString* Script::GenerateSource() const {
8823 const TokenStream& token_stream = TokenStream::Handle(tokens()); 8823 const TokenStream& token_stream = TokenStream::Handle(tokens());
8824 if (token_stream.IsNull()) { 8824 if (token_stream.IsNull()) {
8825 ASSERT(Dart::IsRunningPrecompiledCode()); 8825 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
8826 return String::null(); 8826 return String::null();
8827 } 8827 }
8828 return token_stream.GenerateSource(); 8828 return token_stream.GenerateSource();
8829 } 8829 }
8830 8830
8831 8831
8832 RawGrowableObjectArray* Script::GenerateLineNumberArray() const { 8832 RawGrowableObjectArray* Script::GenerateLineNumberArray() const {
8833 Zone* zone = Thread::Current()->zone(); 8833 Zone* zone = Thread::Current()->zone();
8834 const GrowableObjectArray& info = 8834 const GrowableObjectArray& info =
8835 GrowableObjectArray::Handle(zone, GrowableObjectArray::New()); 8835 GrowableObjectArray::Handle(zone, GrowableObjectArray::New());
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after
8984 } 8984 }
8985 8985
8986 8986
8987 void Script::GetTokenLocation(TokenPosition token_pos, 8987 void Script::GetTokenLocation(TokenPosition token_pos,
8988 intptr_t* line, 8988 intptr_t* line,
8989 intptr_t* column, 8989 intptr_t* column,
8990 intptr_t* token_len) const { 8990 intptr_t* token_len) const {
8991 ASSERT(line != NULL); 8991 ASSERT(line != NULL);
8992 const TokenStream& tkns = TokenStream::Handle(tokens()); 8992 const TokenStream& tkns = TokenStream::Handle(tokens());
8993 if (tkns.IsNull()) { 8993 if (tkns.IsNull()) {
8994 ASSERT(Dart::IsRunningPrecompiledCode()); 8994 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
8995 *line = -1; 8995 *line = -1;
8996 if (column != NULL) { 8996 if (column != NULL) {
8997 *column = -1; 8997 *column = -1;
8998 } 8998 }
8999 if (token_len != NULL) { 8999 if (token_len != NULL) {
9000 *token_len = 1; 9000 *token_len = 1;
9001 } 9001 }
9002 return; 9002 return;
9003 } 9003 }
9004 if (column == NULL) { 9004 if (column == NULL) {
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
9083 end_pos = tkit.CurrentPosition(); 9083 end_pos = tkit.CurrentPosition();
9084 tkit.Advance(); 9084 tkit.Advance();
9085 } 9085 }
9086 *last_token_index = end_pos; 9086 *last_token_index = end_pos;
9087 } 9087 }
9088 9088
9089 9089
9090 RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const { 9090 RawString* Script::GetLine(intptr_t line_number, Heap::Space space) const {
9091 const String& src = String::Handle(Source()); 9091 const String& src = String::Handle(Source());
9092 if (src.IsNull()) { 9092 if (src.IsNull()) {
9093 ASSERT(Dart::IsRunningPrecompiledCode()); 9093 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
9094 return Symbols::OptimizedOut().raw(); 9094 return Symbols::OptimizedOut().raw();
9095 } 9095 }
9096 intptr_t relative_line_number = line_number - line_offset(); 9096 intptr_t relative_line_number = line_number - line_offset();
9097 intptr_t current_line = 1; 9097 intptr_t current_line = 1;
9098 intptr_t line_start_idx = -1; 9098 intptr_t line_start_idx = -1;
9099 intptr_t last_char_idx = -1; 9099 intptr_t last_char_idx = -1;
9100 for (intptr_t ix = 0; 9100 for (intptr_t ix = 0;
9101 (ix < src.Length()) && (current_line <= relative_line_number); 9101 (ix < src.Length()) && (current_line <= relative_line_number);
9102 ix++) { 9102 ix++) {
9103 if ((current_line == relative_line_number) && (line_start_idx < 0)) { 9103 if ((current_line == relative_line_number) && (line_start_idx < 0)) {
(...skipping 21 matching lines...) Expand all
9125 } 9125 }
9126 } 9126 }
9127 9127
9128 9128
9129 RawString* Script::GetSnippet(intptr_t from_line, 9129 RawString* Script::GetSnippet(intptr_t from_line,
9130 intptr_t from_column, 9130 intptr_t from_column,
9131 intptr_t to_line, 9131 intptr_t to_line,
9132 intptr_t to_column) const { 9132 intptr_t to_column) const {
9133 const String& src = String::Handle(Source()); 9133 const String& src = String::Handle(Source());
9134 if (src.IsNull()) { 9134 if (src.IsNull()) {
9135 ASSERT(Dart::IsRunningPrecompiledCode()); 9135 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
9136 return Symbols::OptimizedOut().raw(); 9136 return Symbols::OptimizedOut().raw();
9137 } 9137 }
9138 intptr_t length = src.Length(); 9138 intptr_t length = src.Length();
9139 intptr_t line = 1 + line_offset(); 9139 intptr_t line = 1 + line_offset();
9140 intptr_t column = 1; 9140 intptr_t column = 1;
9141 intptr_t scan_position = 0; 9141 intptr_t scan_position = 0;
9142 intptr_t snippet_start = -1; 9142 intptr_t snippet_start = -1;
9143 intptr_t snippet_end = -1; 9143 intptr_t snippet_end = -1;
9144 if (from_line - line_offset() == 1) { 9144 if (from_line - line_offset() == 1) {
9145 column += col_offset(); 9145 column += col_offset();
(...skipping 1828 matching lines...) Expand 10 before | Expand all | Expand 10 after
10974 10974
10975 10975
10976 bool LibraryPrefix::LoadLibrary() const { 10976 bool LibraryPrefix::LoadLibrary() const {
10977 // Non-deferred prefixes are loaded. 10977 // Non-deferred prefixes are loaded.
10978 ASSERT(is_deferred_load() || is_loaded()); 10978 ASSERT(is_deferred_load() || is_loaded());
10979 if (is_loaded()) { 10979 if (is_loaded()) {
10980 return true; // Load request has already completed. 10980 return true; // Load request has already completed.
10981 } 10981 }
10982 ASSERT(is_deferred_load()); 10982 ASSERT(is_deferred_load());
10983 ASSERT(num_imports() == 1); 10983 ASSERT(num_imports() == 1);
10984 if (Dart::IsRunningPrecompiledCode()) { 10984 if (Dart::snapshot_kind() == Snapshot::kAppNoJIT) {
10985 // The library list was tree-shaken away. 10985 // The library list was tree-shaken away.
10986 this->set_is_loaded(); 10986 this->set_is_loaded();
10987 return true; 10987 return true;
10988 } 10988 }
10989 // This is a prefix for a deferred library. If the library is not loaded 10989 // This is a prefix for a deferred library. If the library is not loaded
10990 // yet and isn't being loaded, call the library tag handler to schedule 10990 // yet and isn't being loaded, call the library tag handler to schedule
10991 // loading. Once all outstanding load requests have completed, the embedder 10991 // loading. Once all outstanding load requests have completed, the embedder
10992 // will call the core library to: 10992 // will call the core library to:
10993 // - invalidate dependent code of this prefix; 10993 // - invalidate dependent code of this prefix;
10994 // - mark this prefixes as loaded; 10994 // - mark this prefixes as loaded;
(...skipping 2523 matching lines...) Expand 10 before | Expand all | Expand 10 after
13518 // larger than the previously added one. 13518 // larger than the previously added one.
13519 for (intptr_t i = kSCallTableEntryLength; 13519 for (intptr_t i = kSCallTableEntryLength;
13520 i < value.Length(); 13520 i < value.Length();
13521 i += kSCallTableEntryLength) { 13521 i += kSCallTableEntryLength) {
13522 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i)); 13522 ASSERT(value.At(i - kSCallTableEntryLength) < value.At(i));
13523 } 13523 }
13524 #endif // DEBUG 13524 #endif // DEBUG
13525 } 13525 }
13526 13526
13527 13527
13528 uword Code::EntryPoint() const {
13529 RawObject* instr = instructions();
13530 if (!instr->IsHeapObject()) {
13531 return active_entry_point();
13532 } else {
13533 return Instructions::EntryPoint(instructions());
13534 }
13535 }
13536
13537
13538 intptr_t Code::Size() const {
13539 RawObject* instr = instructions();
13540 if (!instr->IsHeapObject()) {
13541 return Smi::Value(raw_ptr()->precompiled_instructions_size_);
13542 } else {
13543 return instructions()->ptr()->size_;
13544 }
13545 }
13546
13547
13548 bool Code::HasBreakpoint() const { 13528 bool Code::HasBreakpoint() const {
13549 if (!FLAG_support_debugger) { 13529 if (!FLAG_support_debugger) {
13550 return false; 13530 return false;
13551 } 13531 }
13552 return Isolate::Current()->debugger()->HasBreakpoint(*this); 13532 return Isolate::Current()->debugger()->HasBreakpoint(*this);
13553 } 13533 }
13554 13534
13555 13535
13556 TokenPosition Code::GetTokenPositionAt(intptr_t offset) const { 13536 TokenPosition Code::GetTokenPositionAt(intptr_t offset) const {
13557 const CodeSourceMap& map = CodeSourceMap::Handle(code_source_map()); 13537 const CodeSourceMap& map = CodeSourceMap::Handle(code_source_map());
13558 if (map.IsNull()) { 13538 if (map.IsNull()) {
13559 return TokenPosition::kNoSource; 13539 return TokenPosition::kNoSource;
13560 } 13540 }
13561 return map.TokenPositionForPCOffset(offset); 13541 return map.TokenPositionForPCOffset(offset);
13562 } 13542 }
13563 13543
13564 13544
13565 RawTypedData* Code::GetDeoptInfoAtPc(uword pc, 13545 RawTypedData* Code::GetDeoptInfoAtPc(uword pc,
13566 ICData::DeoptReasonId* deopt_reason, 13546 ICData::DeoptReasonId* deopt_reason,
13567 uint32_t* deopt_flags) const { 13547 uint32_t* deopt_flags) const {
13568 ASSERT(is_optimized()); 13548 ASSERT(is_optimized());
13569 const Instructions& instrs = Instructions::Handle(instructions()); 13549 const Instructions& instrs = Instructions::Handle(instructions());
13570 uword code_entry = instrs.EntryPoint(); 13550 uword code_entry = instrs.EntryPoint();
13571 const Array& table = Array::Handle(deopt_info_array()); 13551 const Array& table = Array::Handle(deopt_info_array());
13572 if (table.IsNull()) { 13552 if (table.IsNull()) {
13573 ASSERT(Dart::IsRunningPrecompiledCode()); 13553 ASSERT(Dart::snapshot_kind() == Snapshot::kAppNoJIT);
13574 return TypedData::null(); 13554 return TypedData::null();
13575 } 13555 }
13576 // Linear search for the PC offset matching the target PC. 13556 // Linear search for the PC offset matching the target PC.
13577 intptr_t length = DeoptTable::GetLength(table); 13557 intptr_t length = DeoptTable::GetLength(table);
13578 Smi& offset = Smi::Handle(); 13558 Smi& offset = Smi::Handle();
13579 Smi& reason_and_flags = Smi::Handle(); 13559 Smi& reason_and_flags = Smi::Handle();
13580 TypedData& info = TypedData::Handle(); 13560 TypedData& info = TypedData::Handle();
13581 for (intptr_t i = 0; i < length; ++i) { 13561 for (intptr_t i = 0; i < length; ++i) {
13582 DeoptTable::GetEntry(table, i, &offset, &info, &reason_and_flags); 13562 DeoptTable::GetEntry(table, i, &offset, &info, &reason_and_flags);
13583 if (pc == (code_entry + offset.Value())) { 13563 if (pc == (code_entry + offset.Value())) {
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
13883 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { 13863 for (intptr_t i = 0; i < pointer_offsets.length(); i++) {
13884 intptr_t offset_in_instrs = pointer_offsets[i]; 13864 intptr_t offset_in_instrs = pointer_offsets[i];
13885 code.SetPointerOffsetAt(i, offset_in_instrs); 13865 code.SetPointerOffsetAt(i, offset_in_instrs);
13886 uword addr = region.start() + offset_in_instrs; 13866 uword addr = region.start() + offset_in_instrs;
13887 const Object* object = *reinterpret_cast<Object**>(addr); 13867 const Object* object = *reinterpret_cast<Object**>(addr);
13888 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), 13868 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr),
13889 object->raw()); 13869 object->raw());
13890 } 13870 }
13891 13871
13892 // Hook up Code and Instructions objects. 13872 // Hook up Code and Instructions objects.
13873 code.SetActiveInstructions(instrs.raw());
13893 code.set_instructions(instrs.raw()); 13874 code.set_instructions(instrs.raw());
13894 code.SetActiveInstructions(instrs.raw());
13895 code.set_is_alive(true); 13875 code.set_is_alive(true);
13896 13876
13897 ASSERT(code.EntryPoint() == instrs.EntryPoint());
13898 ASSERT(code.Size() == instrs.size());
13899
13900 // Set object pool in Instructions object. 13877 // Set object pool in Instructions object.
13901 INC_STAT(Thread::Current(), 13878 INC_STAT(Thread::Current(),
13902 total_code_size, object_pool.Length() * sizeof(uintptr_t)); 13879 total_code_size, object_pool.Length() * sizeof(uintptr_t));
13903 code.set_object_pool(object_pool.raw()); 13880 code.set_object_pool(object_pool.raw());
13904 13881
13905 if (FLAG_write_protect_code) { 13882 if (FLAG_write_protect_code) {
13906 uword address = RawObject::ToAddr(instrs.raw()); 13883 uword address = RawObject::ToAddr(instrs.raw());
13907 bool status = VirtualMemory::Protect( 13884 bool status = VirtualMemory::Protect(
13908 reinterpret_cast<void*>(address), 13885 reinterpret_cast<void*>(address),
13909 instrs.raw()->Size(), 13886 instrs.raw()->Size(),
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
14092 14069
14093 bool Code::IsFunctionCode() const { 14070 bool Code::IsFunctionCode() const {
14094 const Object& obj = Object::Handle(owner()); 14071 const Object& obj = Object::Handle(owner());
14095 return obj.IsFunction(); 14072 return obj.IsFunction();
14096 } 14073 }
14097 14074
14098 14075
14099 void Code::DisableDartCode() const { 14076 void Code::DisableDartCode() const {
14100 DEBUG_ASSERT(IsMutatorOrAtSafepoint()); 14077 DEBUG_ASSERT(IsMutatorOrAtSafepoint());
14101 ASSERT(IsFunctionCode()); 14078 ASSERT(IsFunctionCode());
14102 ASSERT(!IsDisabled()); 14079 ASSERT(instructions() == active_instructions());
14103 const Code& new_code = 14080 const Code& new_code =
14104 Code::Handle(StubCode::FixCallersTarget_entry()->code()); 14081 Code::Handle(StubCode::FixCallersTarget_entry()->code());
14105 ASSERT(new_code.instructions()->IsVMHeapObject());
14106 SetActiveInstructions(new_code.instructions()); 14082 SetActiveInstructions(new_code.instructions());
14107 } 14083 }
14108 14084
14109 14085
14110 void Code::DisableStubCode() const { 14086 void Code::DisableStubCode() const {
14111 #if !defined(TARGET_ARCH_DBC) 14087 #if !defined(TARGET_ARCH_DBC)
14112 ASSERT(Thread::Current()->IsMutatorThread()); 14088 ASSERT(Thread::Current()->IsMutatorThread());
14113 ASSERT(IsAllocationStubCode()); 14089 ASSERT(IsAllocationStubCode());
14114 ASSERT(!IsDisabled()); 14090 ASSERT(instructions() == active_instructions());
14115 const Code& new_code = 14091 const Code& new_code =
14116 Code::Handle(StubCode::FixAllocationStubTarget_entry()->code()); 14092 Code::Handle(StubCode::FixAllocationStubTarget_entry()->code());
14117 ASSERT(new_code.instructions()->IsVMHeapObject());
14118 SetActiveInstructions(new_code.instructions()); 14093 SetActiveInstructions(new_code.instructions());
14119 #else 14094 #else
14120 // DBC does not use allocation stubs. 14095 // DBC does not use allocation stubs.
14121 UNIMPLEMENTED(); 14096 UNIMPLEMENTED();
14122 #endif // !defined(TARGET_ARCH_DBC) 14097 #endif // !defined(TARGET_ARCH_DBC)
14123 } 14098 }
14124 14099
14125 14100
14126 void Code::SetActiveInstructions(RawInstructions* instructions) const { 14101 void Code::SetActiveInstructions(RawInstructions* instructions) const {
14127 DEBUG_ASSERT(IsMutatorOrAtSafepoint() || !is_alive()); 14102 DEBUG_ASSERT(IsMutatorOrAtSafepoint() || !is_alive());
14128 // RawInstructions are never allocated in New space and hence a 14103 // RawInstructions are never allocated in New space and hence a
14129 // store buffer update is not needed here. 14104 // store buffer update is not needed here.
14105 StorePointer(&raw_ptr()->active_instructions_, instructions);
14130 StoreNonPointer(&raw_ptr()->entry_point_, 14106 StoreNonPointer(&raw_ptr()->entry_point_,
14131 reinterpret_cast<uword>(instructions->ptr()) + 14107 reinterpret_cast<uword>(instructions->ptr()) +
14132 Instructions::HeaderSize()); 14108 Instructions::HeaderSize());
14133 } 14109 }
14134 14110
14135 14111
14136 uword Code::GetLazyDeoptPc() const { 14112 uword Code::GetLazyDeoptPc() const {
14137 return (lazy_deopt_pc_offset() != kInvalidPc) 14113 return (lazy_deopt_pc_offset() != kInvalidPc)
14138 ? EntryPoint() + lazy_deopt_pc_offset() : 0; 14114 ? EntryPoint() + lazy_deopt_pc_offset() : 0;
14139 } 14115 }
(...skipping 8266 matching lines...) Expand 10 before | Expand all | Expand 10 after
22406 return UserTag::null(); 22382 return UserTag::null();
22407 } 22383 }
22408 22384
22409 22385
22410 const char* UserTag::ToCString() const { 22386 const char* UserTag::ToCString() const {
22411 const String& tag_label = String::Handle(label()); 22387 const String& tag_label = String::Handle(label());
22412 return tag_label.ToCString(); 22388 return tag_label.ToCString();
22413 } 22389 }
22414 22390
22415 } // namespace dart 22391 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698