| 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 9865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9876 } | 9876 } |
| 9877 ASSERT(Object::code_class() != Class::null()); | 9877 ASSERT(Object::code_class() != Class::null()); |
| 9878 Code& result = Code::Handle(); | 9878 Code& result = Code::Handle(); |
| 9879 { | 9879 { |
| 9880 uword size = Code::InstanceSize(pointer_offsets_length); | 9880 uword size = Code::InstanceSize(pointer_offsets_length); |
| 9881 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld); | 9881 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld); |
| 9882 NoGCScope no_gc; | 9882 NoGCScope no_gc; |
| 9883 result ^= raw; | 9883 result ^= raw; |
| 9884 result.set_pointer_offsets_length(pointer_offsets_length); | 9884 result.set_pointer_offsets_length(pointer_offsets_length); |
| 9885 result.set_is_optimized(false); | 9885 result.set_is_optimized(false); |
| 9886 result.set_is_alive(true); | 9886 result.set_is_alive(false); |
| 9887 result.set_comments(Comments::New(0)); | 9887 result.set_comments(Comments::New(0)); |
| 9888 } | 9888 } |
| 9889 return result.raw(); | 9889 return result.raw(); |
| 9890 } | 9890 } |
| 9891 | 9891 |
| 9892 | 9892 |
| 9893 RawCode* Code::FinalizeCode(const char* name, | 9893 RawCode* Code::FinalizeCode(const char* name, |
| 9894 Assembler* assembler, | 9894 Assembler* assembler, |
| 9895 bool optimized) { | 9895 bool optimized) { |
| 9896 ASSERT(assembler != NULL); | 9896 ASSERT(assembler != NULL); |
| 9897 | 9897 |
| 9898 // Allocate the Instructions object. | 9898 // Allocate the Code and Instructions objects. Code is allocated first |
| 9899 // because a GC during allocation of the code will leave the instruction |
| 9900 // pages read-only. |
| 9901 intptr_t pointer_offset_count = assembler->CountPointerOffsets(); |
| 9902 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count)); |
| 9899 Instructions& instrs = | 9903 Instructions& instrs = |
| 9900 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize())); | 9904 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize())); |
| 9901 | 9905 |
| 9902 // Copy the instructions into the instruction area and apply all fixups. | 9906 // Copy the instructions into the instruction area and apply all fixups. |
| 9903 // Embedded pointers are still in handles at this point. | 9907 // Embedded pointers are still in handles at this point. |
| 9904 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()), | 9908 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()), |
| 9905 instrs.size()); | 9909 instrs.size()); |
| 9906 assembler->FinalizeInstructions(region); | 9910 assembler->FinalizeInstructions(region); |
| 9907 CPU::FlushICache(instrs.EntryPoint(), instrs.size()); | 9911 CPU::FlushICache(instrs.EntryPoint(), instrs.size()); |
| 9908 | 9912 |
| 9909 CodeObservers::NotifyAll(name, | 9913 CodeObservers::NotifyAll(name, |
| 9910 instrs.EntryPoint(), | 9914 instrs.EntryPoint(), |
| 9911 assembler->prologue_offset(), | 9915 assembler->prologue_offset(), |
| 9912 instrs.size(), | 9916 instrs.size(), |
| 9913 optimized); | 9917 optimized); |
| 9914 | 9918 |
| 9915 const ZoneGrowableArray<intptr_t>& pointer_offsets = | |
| 9916 assembler->GetPointerOffsets(); | |
| 9917 | |
| 9918 // Allocate the code object. | |
| 9919 Code& code = Code::ZoneHandle(Code::New(pointer_offsets.length())); | |
| 9920 { | 9919 { |
| 9921 NoGCScope no_gc; | 9920 NoGCScope no_gc; |
| 9921 const ZoneGrowableArray<intptr_t>& pointer_offsets = |
| 9922 assembler->GetPointerOffsets(); |
| 9923 ASSERT(pointer_offsets.length() == pointer_offset_count); |
| 9924 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); |
| 9922 | 9925 |
| 9923 // Set pointer offsets list in Code object and resolve all handles in | 9926 // Set pointer offsets list in Code object and resolve all handles in |
| 9924 // the instruction stream to raw objects. | 9927 // the instruction stream to raw objects. |
| 9925 ASSERT(code.pointer_offsets_length() == pointer_offsets.length()); | |
| 9926 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { | 9928 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { |
| 9927 intptr_t offset_in_instrs = pointer_offsets[i]; | 9929 intptr_t offset_in_instrs = pointer_offsets[i]; |
| 9928 code.SetPointerOffsetAt(i, offset_in_instrs); | 9930 code.SetPointerOffsetAt(i, offset_in_instrs); |
| 9929 const Object* object = region.Load<const Object*>(offset_in_instrs); | 9931 const Object* object = region.Load<const Object*>(offset_in_instrs); |
| 9930 region.Store<RawObject*>(offset_in_instrs, object->raw()); | 9932 region.Store<RawObject*>(offset_in_instrs, object->raw()); |
| 9931 } | 9933 } |
| 9932 | 9934 |
| 9933 // Hook up Code and Instructions objects. | 9935 // Hook up Code and Instructions objects. |
| 9934 instrs.set_code(code.raw()); | 9936 instrs.set_code(code.raw()); |
| 9935 code.set_instructions(instrs.raw()); | 9937 code.set_instructions(instrs.raw()); |
| 9938 code.set_is_alive(true); |
| 9936 | 9939 |
| 9937 // Set object pool in Instructions object. | 9940 // Set object pool in Instructions object. |
| 9938 const GrowableObjectArray& object_pool = assembler->object_pool(); | 9941 const GrowableObjectArray& object_pool = assembler->object_pool(); |
| 9939 if (object_pool.IsNull()) { | 9942 if (object_pool.IsNull()) { |
| 9940 instrs.set_object_pool(Object::empty_array().raw()); | 9943 instrs.set_object_pool(Object::empty_array().raw()); |
| 9941 } else { | 9944 } else { |
| 9942 // TODO(regis): Once MakeArray takes a Heap::Space argument, call it here | 9945 // TODO(regis): Once MakeArray takes a Heap::Space argument, call it here |
| 9943 // with Heap::kOld and change the ARM and MIPS assemblers to work with a | 9946 // with Heap::kOld and change the ARM and MIPS assemblers to work with a |
| 9944 // GrowableObjectArray in new space. | 9947 // GrowableObjectArray in new space. |
| 9945 instrs.set_object_pool(Array::MakeArray(object_pool)); | 9948 instrs.set_object_pool(Array::MakeArray(object_pool)); |
| 9946 } | 9949 } |
| 9950 bool status = |
| 9951 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.raw_ptr()), |
| 9952 instrs.raw()->Size(), |
| 9953 VirtualMemory::kReadExecute); |
| 9954 ASSERT(status); |
| 9947 } | 9955 } |
| 9948 return code.raw(); | 9956 return code.raw(); |
| 9949 } | 9957 } |
| 9950 | 9958 |
| 9951 | 9959 |
| 9952 RawCode* Code::FinalizeCode(const Function& function, | 9960 RawCode* Code::FinalizeCode(const Function& function, |
| 9953 Assembler* assembler, | 9961 Assembler* assembler, |
| 9954 bool optimized) { | 9962 bool optimized) { |
| 9955 // Calling ToFullyQualifiedCString is very expensive, try to avoid it. | 9963 // Calling ToFullyQualifiedCString is very expensive, try to avoid it. |
| 9956 if (CodeObservers::AreActive()) { | 9964 if (CodeObservers::AreActive()) { |
| (...skipping 7017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 16974 return "_MirrorReference"; | 16982 return "_MirrorReference"; |
| 16975 } | 16983 } |
| 16976 | 16984 |
| 16977 | 16985 |
| 16978 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 16986 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
| 16979 Instance::PrintToJSONStream(stream, ref); | 16987 Instance::PrintToJSONStream(stream, ref); |
| 16980 } | 16988 } |
| 16981 | 16989 |
| 16982 | 16990 |
| 16983 } // namespace dart | 16991 } // namespace dart |
| OLD | NEW |