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