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

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

Issue 136563002: Landing: Write protect executable pages in the VM. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 10 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
« no previous file with comments | « runtime/vm/instructions_x64_test.cc ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 10122 matching lines...) Expand 10 before | Expand all | Expand 10 after
10133 } 10133 }
10134 ASSERT(Object::code_class() != Class::null()); 10134 ASSERT(Object::code_class() != Class::null());
10135 Code& result = Code::Handle(); 10135 Code& result = Code::Handle();
10136 { 10136 {
10137 uword size = Code::InstanceSize(pointer_offsets_length); 10137 uword size = Code::InstanceSize(pointer_offsets_length);
10138 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld); 10138 RawObject* raw = Object::Allocate(Code::kClassId, size, Heap::kOld);
10139 NoGCScope no_gc; 10139 NoGCScope no_gc;
10140 result ^= raw; 10140 result ^= raw;
10141 result.set_pointer_offsets_length(pointer_offsets_length); 10141 result.set_pointer_offsets_length(pointer_offsets_length);
10142 result.set_is_optimized(false); 10142 result.set_is_optimized(false);
10143 result.set_is_alive(true); 10143 result.set_is_alive(false);
10144 result.set_comments(Comments::New(0)); 10144 result.set_comments(Comments::New(0));
10145 result.set_pc_descriptors(Object::empty_descriptors()); 10145 result.set_pc_descriptors(Object::empty_descriptors());
10146 } 10146 }
10147 return result.raw(); 10147 return result.raw();
10148 } 10148 }
10149 10149
10150 10150
10151 RawCode* Code::FinalizeCode(const char* name, 10151 RawCode* Code::FinalizeCode(const char* name,
10152 Assembler* assembler, 10152 Assembler* assembler,
10153 bool optimized) { 10153 bool optimized) {
10154 ASSERT(assembler != NULL); 10154 ASSERT(assembler != NULL);
10155 10155
10156 // Allocate the Instructions object. 10156 // Allocate the Code and Instructions objects. Code is allocated first
10157 // because a GC during allocation of the code will leave the instruction
10158 // pages read-only.
10159 intptr_t pointer_offset_count = assembler->CountPointerOffsets();
10160 Code& code = Code::ZoneHandle(Code::New(pointer_offset_count));
10157 Instructions& instrs = 10161 Instructions& instrs =
10158 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize())); 10162 Instructions::ZoneHandle(Instructions::New(assembler->CodeSize()));
10159 10163
10160 // Copy the instructions into the instruction area and apply all fixups. 10164 // Copy the instructions into the instruction area and apply all fixups.
10161 // Embedded pointers are still in handles at this point. 10165 // Embedded pointers are still in handles at this point.
10162 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()), 10166 MemoryRegion region(reinterpret_cast<void*>(instrs.EntryPoint()),
10163 instrs.size()); 10167 instrs.size());
10164 assembler->FinalizeInstructions(region); 10168 assembler->FinalizeInstructions(region);
10165 CPU::FlushICache(instrs.EntryPoint(), instrs.size()); 10169 CPU::FlushICache(instrs.EntryPoint(), instrs.size());
10166 10170
10167 CodeObservers::NotifyAll(name, 10171 CodeObservers::NotifyAll(name,
10168 instrs.EntryPoint(), 10172 instrs.EntryPoint(),
10169 assembler->prologue_offset(), 10173 assembler->prologue_offset(),
10170 instrs.size(), 10174 instrs.size(),
10171 optimized); 10175 optimized);
10172 10176
10173 const ZoneGrowableArray<intptr_t>& pointer_offsets =
10174 assembler->GetPointerOffsets();
10175
10176 // Allocate the code object.
10177 Code& code = Code::ZoneHandle(Code::New(pointer_offsets.length()));
10178 { 10177 {
10179 NoGCScope no_gc; 10178 NoGCScope no_gc;
10179 const ZoneGrowableArray<intptr_t>& pointer_offsets =
10180 assembler->GetPointerOffsets();
10181 ASSERT(pointer_offsets.length() == pointer_offset_count);
10182 ASSERT(code.pointer_offsets_length() == pointer_offsets.length());
10180 10183
10181 // Set pointer offsets list in Code object and resolve all handles in 10184 // Set pointer offsets list in Code object and resolve all handles in
10182 // the instruction stream to raw objects. 10185 // the instruction stream to raw objects.
10183 ASSERT(code.pointer_offsets_length() == pointer_offsets.length());
10184 for (intptr_t i = 0; i < pointer_offsets.length(); i++) { 10186 for (intptr_t i = 0; i < pointer_offsets.length(); i++) {
10185 intptr_t offset_in_instrs = pointer_offsets[i]; 10187 intptr_t offset_in_instrs = pointer_offsets[i];
10186 code.SetPointerOffsetAt(i, offset_in_instrs); 10188 code.SetPointerOffsetAt(i, offset_in_instrs);
10187 const Object* object = region.Load<const Object*>(offset_in_instrs); 10189 const Object* object = region.Load<const Object*>(offset_in_instrs);
10188 region.Store<RawObject*>(offset_in_instrs, object->raw()); 10190 region.Store<RawObject*>(offset_in_instrs, object->raw());
10189 } 10191 }
10190 10192
10191 // Hook up Code and Instructions objects. 10193 // Hook up Code and Instructions objects.
10192 instrs.set_code(code.raw()); 10194 instrs.set_code(code.raw());
10193 code.set_instructions(instrs.raw()); 10195 code.set_instructions(instrs.raw());
10196 code.set_is_alive(true);
10194 10197
10195 // Set object pool in Instructions object. 10198 // Set object pool in Instructions object.
10196 const GrowableObjectArray& object_pool = assembler->object_pool(); 10199 const GrowableObjectArray& object_pool = assembler->object_pool();
10197 if (object_pool.IsNull()) { 10200 if (object_pool.IsNull()) {
10198 instrs.set_object_pool(Object::empty_array().raw()); 10201 instrs.set_object_pool(Object::empty_array().raw());
10199 } else { 10202 } else {
10200 // TODO(regis): Once MakeArray takes a Heap::Space argument, call it here 10203 // TODO(regis): Once MakeArray takes a Heap::Space argument, call it here
10201 // with Heap::kOld and change the ARM and MIPS assemblers to work with a 10204 // with Heap::kOld and change the ARM and MIPS assemblers to work with a
10202 // GrowableObjectArray in new space. 10205 // GrowableObjectArray in new space.
10203 instrs.set_object_pool(Array::MakeArray(object_pool)); 10206 instrs.set_object_pool(Array::MakeArray(object_pool));
10204 } 10207 }
10208 bool status =
10209 VirtualMemory::Protect(reinterpret_cast<void*>(instrs.raw_ptr()),
10210 instrs.raw()->Size(),
10211 VirtualMemory::kReadExecute);
10212 ASSERT(status);
10205 } 10213 }
10206 return code.raw(); 10214 return code.raw();
10207 } 10215 }
10208 10216
10209 10217
10210 RawCode* Code::FinalizeCode(const Function& function, 10218 RawCode* Code::FinalizeCode(const Function& function,
10211 Assembler* assembler, 10219 Assembler* assembler,
10212 bool optimized) { 10220 bool optimized) {
10213 // Calling ToFullyQualifiedCString is very expensive, try to avoid it. 10221 // Calling ToFullyQualifiedCString is very expensive, try to avoid it.
10214 if (CodeObservers::AreActive()) { 10222 if (CodeObservers::AreActive()) {
(...skipping 7113 matching lines...) Expand 10 before | Expand all | Expand 10 after
17328 return "_MirrorReference"; 17336 return "_MirrorReference";
17329 } 17337 }
17330 17338
17331 17339
17332 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 17340 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
17333 Instance::PrintToJSONStream(stream, ref); 17341 Instance::PrintToJSONStream(stream, ref);
17334 } 17342 }
17335 17343
17336 17344
17337 } // namespace dart 17345 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/instructions_x64_test.cc ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698