| OLD | NEW |
| 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 6853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6864 intptr_t count = 0; | 6864 intptr_t count = 0; |
| 6865 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { | 6865 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { |
| 6866 if (deopt_id_to_ic_data[i] != NULL) { | 6866 if (deopt_id_to_ic_data[i] != NULL) { |
| 6867 count++; | 6867 count++; |
| 6868 } | 6868 } |
| 6869 } | 6869 } |
| 6870 if (count == 0) { | 6870 if (count == 0) { |
| 6871 set_ic_data_array(Object::empty_array()); | 6871 set_ic_data_array(Object::empty_array()); |
| 6872 } else { | 6872 } else { |
| 6873 const Array& a = Array::Handle(Array::New(count, Heap::kOld)); | 6873 const Array& a = Array::Handle(Array::New(count, Heap::kOld)); |
| 6874 INC_STAT(Isolate::Current(), total_code_size, count * sizeof(uword)); | 6874 INC_STAT(Thread::Current(), total_code_size, count * sizeof(uword)); |
| 6875 count = 0; | 6875 count = 0; |
| 6876 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { | 6876 for (intptr_t i = 0; i < deopt_id_to_ic_data.length(); i++) { |
| 6877 if (deopt_id_to_ic_data[i] != NULL) { | 6877 if (deopt_id_to_ic_data[i] != NULL) { |
| 6878 a.SetAt(count++, *deopt_id_to_ic_data[i]); | 6878 a.SetAt(count++, *deopt_id_to_ic_data[i]); |
| 6879 } | 6879 } |
| 6880 } | 6880 } |
| 6881 set_ic_data_array(a); | 6881 set_ic_data_array(a); |
| 6882 } | 6882 } |
| 6883 } | 6883 } |
| 6884 | 6884 |
| (...skipping 1669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8554 | 8554 |
| 8555 | 8555 |
| 8556 void Script::set_tokens(const TokenStream& value) const { | 8556 void Script::set_tokens(const TokenStream& value) const { |
| 8557 StorePointer(&raw_ptr()->tokens_, value.raw()); | 8557 StorePointer(&raw_ptr()->tokens_, value.raw()); |
| 8558 } | 8558 } |
| 8559 | 8559 |
| 8560 | 8560 |
| 8561 void Script::Tokenize(const String& private_key) const { | 8561 void Script::Tokenize(const String& private_key) const { |
| 8562 Thread* thread = Thread::Current(); | 8562 Thread* thread = Thread::Current(); |
| 8563 Zone* zone = thread->zone(); | 8563 Zone* zone = thread->zone(); |
| 8564 Isolate* isolate = thread->isolate(); | |
| 8565 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 8564 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 8566 if (!tkns.IsNull()) { | 8565 if (!tkns.IsNull()) { |
| 8567 // Already tokenized. | 8566 // Already tokenized. |
| 8568 return; | 8567 return; |
| 8569 } | 8568 } |
| 8570 // Get the source, scan and allocate the token stream. | 8569 // Get the source, scan and allocate the token stream. |
| 8571 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); | 8570 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); |
| 8572 CSTAT_TIMER_SCOPE(thread, scanner_timer); | 8571 CSTAT_TIMER_SCOPE(thread, scanner_timer); |
| 8573 const String& src = String::Handle(zone, Source()); | 8572 const String& src = String::Handle(zone, Source()); |
| 8574 Scanner scanner(src, private_key); | 8573 Scanner scanner(src, private_key); |
| 8575 set_tokens(TokenStream::Handle(zone, | 8574 set_tokens(TokenStream::Handle(zone, |
| 8576 TokenStream::New(scanner.GetStream(), | 8575 TokenStream::New(scanner.GetStream(), |
| 8577 private_key))); | 8576 private_key))); |
| 8578 INC_STAT(isolate, src_length, src.Length()); | 8577 INC_STAT(thread, src_length, src.Length()); |
| 8579 } | 8578 } |
| 8580 | 8579 |
| 8581 | 8580 |
| 8582 void Script::SetLocationOffset(intptr_t line_offset, | 8581 void Script::SetLocationOffset(intptr_t line_offset, |
| 8583 intptr_t col_offset) const { | 8582 intptr_t col_offset) const { |
| 8584 ASSERT(line_offset >= 0); | 8583 ASSERT(line_offset >= 0); |
| 8585 ASSERT(col_offset >= 0); | 8584 ASSERT(col_offset >= 0); |
| 8586 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); | 8585 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); |
| 8587 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); | 8586 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); |
| 8588 } | 8587 } |
| (...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11079 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); | 11078 uint8_t* data = UnsafeMutableNonPointer(&raw_ptr()->data()[0]); |
| 11080 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { | 11079 for (intptr_t i = 0; i < delta_encoded_data->length(); ++i) { |
| 11081 data[i] = (*delta_encoded_data)[i]; | 11080 data[i] = (*delta_encoded_data)[i]; |
| 11082 } | 11081 } |
| 11083 } | 11082 } |
| 11084 | 11083 |
| 11085 | 11084 |
| 11086 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { | 11085 RawPcDescriptors* PcDescriptors::New(GrowableArray<uint8_t>* data) { |
| 11087 ASSERT(Object::pc_descriptors_class() != Class::null()); | 11086 ASSERT(Object::pc_descriptors_class() != Class::null()); |
| 11088 Thread* thread = Thread::Current(); | 11087 Thread* thread = Thread::Current(); |
| 11089 Isolate* isolate = thread->isolate(); | |
| 11090 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); | 11088 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); |
| 11091 { | 11089 { |
| 11092 uword size = PcDescriptors::InstanceSize(data->length()); | 11090 uword size = PcDescriptors::InstanceSize(data->length()); |
| 11093 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 11091 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, |
| 11094 size, | 11092 size, |
| 11095 Heap::kOld); | 11093 Heap::kOld); |
| 11096 INC_STAT(isolate, total_code_size, size); | 11094 INC_STAT(thread, total_code_size, size); |
| 11097 INC_STAT(isolate, pc_desc_size, size); | 11095 INC_STAT(thread, pc_desc_size, size); |
| 11098 NoSafepointScope no_safepoint; | 11096 NoSafepointScope no_safepoint; |
| 11099 result ^= raw; | 11097 result ^= raw; |
| 11100 result.SetLength(data->length()); | 11098 result.SetLength(data->length()); |
| 11101 result.CopyData(data); | 11099 result.CopyData(data); |
| 11102 } | 11100 } |
| 11103 return result.raw(); | 11101 return result.raw(); |
| 11104 } | 11102 } |
| 11105 | 11103 |
| 11106 | 11104 |
| 11107 RawPcDescriptors* PcDescriptors::New(intptr_t length) { | 11105 RawPcDescriptors* PcDescriptors::New(intptr_t length) { |
| 11108 ASSERT(Object::pc_descriptors_class() != Class::null()); | 11106 ASSERT(Object::pc_descriptors_class() != Class::null()); |
| 11109 Thread* thread = Thread::Current(); | 11107 Thread* thread = Thread::Current(); |
| 11110 Isolate* isolate = thread->isolate(); | |
| 11111 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); | 11108 PcDescriptors& result = PcDescriptors::Handle(thread->zone()); |
| 11112 { | 11109 { |
| 11113 uword size = PcDescriptors::InstanceSize(length); | 11110 uword size = PcDescriptors::InstanceSize(length); |
| 11114 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, | 11111 RawObject* raw = Object::Allocate(PcDescriptors::kClassId, |
| 11115 size, | 11112 size, |
| 11116 Heap::kOld); | 11113 Heap::kOld); |
| 11117 INC_STAT(isolate, total_code_size, size); | 11114 INC_STAT(thread, total_code_size, size); |
| 11118 INC_STAT(isolate, pc_desc_size, size); | 11115 INC_STAT(thread, pc_desc_size, size); |
| 11119 NoSafepointScope no_safepoint; | 11116 NoSafepointScope no_safepoint; |
| 11120 result ^= raw; | 11117 result ^= raw; |
| 11121 result.SetLength(length); | 11118 result.SetLength(length); |
| 11122 } | 11119 } |
| 11123 return result.raw(); | 11120 return result.raw(); |
| 11124 } | 11121 } |
| 11125 | 11122 |
| 11126 | 11123 |
| 11127 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { | 11124 const char* PcDescriptors::KindAsStr(RawPcDescriptors::Kind kind) { |
| 11128 switch (kind) { | 11125 switch (kind) { |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11558 FATAL2("Fatal error in LocalVarDescriptors::New: " | 11555 FATAL2("Fatal error in LocalVarDescriptors::New: " |
| 11559 "invalid num_variables %" Pd ". Maximum is: %d\n", | 11556 "invalid num_variables %" Pd ". Maximum is: %d\n", |
| 11560 num_variables, RawLocalVarDescriptors::kMaxIndex); | 11557 num_variables, RawLocalVarDescriptors::kMaxIndex); |
| 11561 } | 11558 } |
| 11562 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); | 11559 LocalVarDescriptors& result = LocalVarDescriptors::Handle(); |
| 11563 { | 11560 { |
| 11564 uword size = LocalVarDescriptors::InstanceSize(num_variables); | 11561 uword size = LocalVarDescriptors::InstanceSize(num_variables); |
| 11565 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, | 11562 RawObject* raw = Object::Allocate(LocalVarDescriptors::kClassId, |
| 11566 size, | 11563 size, |
| 11567 Heap::kOld); | 11564 Heap::kOld); |
| 11568 INC_STAT(Isolate::Current(), total_code_size, size); | 11565 INC_STAT(Thread::Current(), total_code_size, size); |
| 11569 INC_STAT(Isolate::Current(), vardesc_size, size); | 11566 INC_STAT(Thread::Current(), vardesc_size, size); |
| 11570 NoSafepointScope no_safepoint; | 11567 NoSafepointScope no_safepoint; |
| 11571 result ^= raw; | 11568 result ^= raw; |
| 11572 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_variables); | 11569 result.StoreNonPointer(&result.raw_ptr()->num_entries_, num_variables); |
| 11573 } | 11570 } |
| 11574 return result.raw(); | 11571 return result.raw(); |
| 11575 } | 11572 } |
| 11576 | 11573 |
| 11577 | 11574 |
| 11578 intptr_t LocalVarDescriptors::Length() const { | 11575 intptr_t LocalVarDescriptors::Length() const { |
| 11579 return raw_ptr()->num_entries_; | 11576 return raw_ptr()->num_entries_; |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12700 | 12697 |
| 12701 | 12698 |
| 12702 void Code::set_is_alive(bool value) const { | 12699 void Code::set_is_alive(bool value) const { |
| 12703 set_state_bits(AliveBit::update(value, raw_ptr()->state_bits_)); | 12700 set_state_bits(AliveBit::update(value, raw_ptr()->state_bits_)); |
| 12704 } | 12701 } |
| 12705 | 12702 |
| 12706 | 12703 |
| 12707 void Code::set_stackmaps(const Array& maps) const { | 12704 void Code::set_stackmaps(const Array& maps) const { |
| 12708 ASSERT(maps.IsOld()); | 12705 ASSERT(maps.IsOld()); |
| 12709 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); | 12706 StorePointer(&raw_ptr()->stackmaps_, maps.raw()); |
| 12710 INC_STAT(Isolate::Current(), | 12707 INC_STAT(Thread::Current(), |
| 12711 total_code_size, | 12708 total_code_size, |
| 12712 maps.IsNull() ? 0 : maps.Length() * sizeof(uword)); | 12709 maps.IsNull() ? 0 : maps.Length() * sizeof(uword)); |
| 12713 } | 12710 } |
| 12714 | 12711 |
| 12715 | 12712 |
| 12716 void Code::set_deopt_info_array(const Array& array) const { | 12713 void Code::set_deopt_info_array(const Array& array) const { |
| 12717 ASSERT(array.IsOld()); | 12714 ASSERT(array.IsOld()); |
| 12718 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); | 12715 StorePointer(&raw_ptr()->deopt_info_array_, array.raw()); |
| 12719 } | 12716 } |
| 12720 | 12717 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13004 const ObjectPool& object_pool = | 13001 const ObjectPool& object_pool = |
| 13005 ObjectPool::Handle(assembler->object_pool_wrapper().MakeObjectPool()); | 13002 ObjectPool::Handle(assembler->object_pool_wrapper().MakeObjectPool()); |
| 13006 | 13003 |
| 13007 // Allocate the Code and Instructions objects. Code is allocated first | 13004 // Allocate the Code and Instructions objects. Code is allocated first |
| 13008 // because a GC during allocation of the code will leave the instruction | 13005 // because a GC during allocation of the code will leave the instruction |
| 13009 // pages read-only. | 13006 // pages read-only. |
| 13010 intptr_t pointer_offset_count = assembler->CountPointerOffsets(); | 13007 intptr_t pointer_offset_count = assembler->CountPointerOffsets(); |
| 13011 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count)); | 13008 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count)); |
| 13012 Instructions& instrs = | 13009 Instructions& instrs = |
| 13013 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize())); | 13010 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize())); |
| 13014 INC_STAT(isolate, total_instr_size, assembler->CodeSize()); | 13011 INC_STAT(Thread::Current(), total_instr_size, assembler->CodeSize()); |
| 13015 INC_STAT(isolate, total_code_size, assembler->CodeSize()); | 13012 INC_STAT(Thread::Current(), total_code_size, assembler->CodeSize()); |
| 13016 | 13013 |
| 13017 // Copy the instructions into the instruction area and apply all fixups. | 13014 // Copy the instructions into the instruction area and apply all fixups. |
| 13018 // Embedded pointers are still in handles at this point. | 13015 // Embedded pointers are still in handles at this point. |
| 13019 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()), | 13016 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 13020 instrs.size()); | 13017 instrs.size()); |
| 13021 assembler->FinalizeInstructions(region); | 13018 assembler->FinalizeInstructions(region); |
| 13022 VerifiedMemory::Accept(region.start(), region.size()); | 13019 VerifiedMemory::Accept(region.start(), region.size()); |
| 13023 CPU::FlushICache(instrs.EntryPoint(), instrs.size()); | 13020 CPU::FlushICache(instrs.EntryPoint(), instrs.size()); |
| 13024 | 13021 |
| 13025 code.set_compile_timestamp(OS::GetCurrentTimeMicros()); | 13022 code.set_compile_timestamp(OS::GetCurrentTimeMicros()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 13045 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), | 13042 instrs.raw()->StorePointer(reinterpret_cast<RawObject**>(addr), |
| 13046 object->raw()); | 13043 object->raw()); |
| 13047 } | 13044 } |
| 13048 | 13045 |
| 13049 // Hook up Code and Instructions objects. | 13046 // Hook up Code and Instructions objects. |
| 13050 instrs.set_code(code.raw()); | 13047 instrs.set_code(code.raw()); |
| 13051 code.set_instructions(instrs.raw()); | 13048 code.set_instructions(instrs.raw()); |
| 13052 code.set_is_alive(true); | 13049 code.set_is_alive(true); |
| 13053 | 13050 |
| 13054 // Set object pool in Instructions object. | 13051 // Set object pool in Instructions object. |
| 13055 INC_STAT(isolate, | 13052 INC_STAT(Thread::Current(), |
| 13056 total_code_size, object_pool.Length() * sizeof(uintptr_t)); | 13053 total_code_size, object_pool.Length() * sizeof(uintptr_t)); |
| 13057 instrs.set_object_pool(object_pool.raw()); | 13054 instrs.set_object_pool(object_pool.raw()); |
| 13058 | 13055 |
| 13059 if (FLAG_write_protect_code) { | 13056 if (FLAG_write_protect_code) { |
| 13060 uword address = RawObject::ToAddr(instrs.raw()); | 13057 uword address = RawObject::ToAddr(instrs.raw()); |
| 13061 bool status = VirtualMemory::Protect( | 13058 bool status = VirtualMemory::Protect( |
| 13062 reinterpret_cast<void*>(address), | 13059 reinterpret_cast<void*>(address), |
| 13063 instrs.raw()->Size(), | 13060 instrs.raw()->Size(), |
| 13064 VirtualMemory::kReadExecute); | 13061 VirtualMemory::kReadExecute); |
| 13065 ASSERT(status); | 13062 ASSERT(status); |
| 13066 } | 13063 } |
| 13067 } | 13064 } |
| 13068 code.set_comments(assembler->GetCodeComments()); | 13065 code.set_comments(assembler->GetCodeComments()); |
| 13069 if (assembler->prologue_offset() >= 0) { | 13066 if (assembler->prologue_offset() >= 0) { |
| 13070 code.SetPrologueOffset(assembler->prologue_offset()); | 13067 code.SetPrologueOffset(assembler->prologue_offset()); |
| 13071 } else { | 13068 } else { |
| 13072 // No prologue was ever entered, optimistically assume nothing was ever | 13069 // No prologue was ever entered, optimistically assume nothing was ever |
| 13073 // pushed onto the stack. | 13070 // pushed onto the stack. |
| 13074 code.SetPrologueOffset(assembler->CodeSize()); | 13071 code.SetPrologueOffset(assembler->CodeSize()); |
| 13075 } | 13072 } |
| 13076 INC_STAT(isolate, | 13073 INC_STAT(Thread::Current(), |
| 13077 total_code_size, code.comments().comments_.Length()); | 13074 total_code_size, code.comments().comments_.Length()); |
| 13078 return code.raw(); | 13075 return code.raw(); |
| 13079 } | 13076 } |
| 13080 | 13077 |
| 13081 | 13078 |
| 13082 RawCode* Code::FinalizeCode(const Function& function, | 13079 RawCode* Code::FinalizeCode(const Function& function, |
| 13083 Assembler* assembler, | 13080 Assembler* assembler, |
| 13084 bool optimized) { | 13081 bool optimized) { |
| 13085 // Calling ToLibNamePrefixedQualifiedCString is very expensive, | 13082 // Calling ToLibNamePrefixedQualifiedCString is very expensive, |
| 13086 // try to avoid it. | 13083 // try to avoid it. |
| (...skipping 8403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 21490 return tag_label.ToCString(); | 21487 return tag_label.ToCString(); |
| 21491 } | 21488 } |
| 21492 | 21489 |
| 21493 | 21490 |
| 21494 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { | 21491 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { |
| 21495 Instance::PrintJSONImpl(stream, ref); | 21492 Instance::PrintJSONImpl(stream, ref); |
| 21496 } | 21493 } |
| 21497 | 21494 |
| 21498 | 21495 |
| 21499 } // namespace dart | 21496 } // namespace dart |
| OLD | NEW |