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

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

Issue 1067383002: VM: Enable collection of unoptimized code for optimized functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 8 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/code_generator.cc ('k') | runtime/vm/compiler.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/code_patcher.h" 5 #include "vm/code_patcher.h"
6 #include "vm/cpu.h" 6 #include "vm/cpu.h"
7 #include "vm/instructions.h" 7 #include "vm/instructions.h"
8 #include "vm/object.h" 8 #include "vm/object.h"
9 #include "vm/virtual_memory.h" 9 #include "vm/virtual_memory.h"
10 10
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 buffer++; 45 buffer++;
46 } 46 }
47 CPU::FlushICache(code_address, num_bytes); 47 CPU::FlushICache(code_address, num_bytes);
48 // The buffer is not executed. No need to flush. 48 // The buffer is not executed. No need to flush.
49 } 49 }
50 50
51 51
52 // The patch code buffer contains the jmp code which will be inserted at 52 // The patch code buffer contains the jmp code which will be inserted at
53 // entry point. 53 // entry point.
54 void CodePatcher::PatchEntry(const Code& code) { 54 void CodePatcher::PatchEntry(const Code& code) {
55 ASSERT(!IsEntryPatched(code));
55 const uword patch_addr = code.GetEntryPatchPc(); 56 const uword patch_addr = code.GetEntryPatchPc();
56 ASSERT(patch_addr != 0); 57 ASSERT(patch_addr != 0);
57 JumpPattern jmp_entry(patch_addr, code); 58 JumpPattern jmp_entry(patch_addr, code);
58 ASSERT(!jmp_entry.IsValid()); 59 ASSERT(!jmp_entry.IsValid());
59 const uword patch_buffer = code.GetPatchCodePc(); 60 const uword patch_buffer = code.GetPatchCodePc();
60 ASSERT(patch_buffer != 0); 61 ASSERT(patch_buffer != 0);
61 JumpPattern jmp_patch(patch_buffer, code); 62 JumpPattern jmp_patch(patch_buffer, code);
62 ASSERT(jmp_patch.IsValid()); 63 ASSERT(jmp_patch.IsValid());
63 const uword jump_target = jmp_patch.TargetAddress(); 64 const uword jump_target = jmp_patch.TargetAddress();
64 intptr_t length = jmp_patch.pattern_length_in_bytes(); 65 intptr_t length = jmp_patch.pattern_length_in_bytes();
65 { 66 {
66 WritableInstructionsScope writable_code(patch_addr, length); 67 WritableInstructionsScope writable_code(patch_addr, length);
67 WritableInstructionsScope writable_buffer(patch_buffer, length); 68 WritableInstructionsScope writable_buffer(patch_buffer, length);
68 SwapCode(jmp_patch.pattern_length_in_bytes(), 69 SwapCode(jmp_patch.pattern_length_in_bytes(),
69 reinterpret_cast<char*>(patch_addr), 70 reinterpret_cast<char*>(patch_addr),
70 reinterpret_cast<char*>(patch_buffer)); 71 reinterpret_cast<char*>(patch_buffer));
71 jmp_entry.SetTargetAddress(jump_target); 72 jmp_entry.SetTargetAddress(jump_target);
72 } 73 }
73 } 74 }
74 75
75 76
76 // The entry point is a jmp instruction, the patch code buffer contains 77 // The entry point is a jmp instruction, the patch code buffer contains
77 // original code, the entry point contains the jump instruction. 78 // original code, the entry point contains the jump instruction.
78 void CodePatcher::RestoreEntry(const Code& code) { 79 void CodePatcher::RestoreEntry(const Code& code) {
80 if (!IsEntryPatched(code)) return;
79 const uword patch_addr = code.GetEntryPatchPc(); 81 const uword patch_addr = code.GetEntryPatchPc();
80 ASSERT(patch_addr != 0); 82 ASSERT(patch_addr != 0);
81 JumpPattern jmp_entry(patch_addr, code); 83 JumpPattern jmp_entry(patch_addr, code);
82 ASSERT(jmp_entry.IsValid()); 84 ASSERT(jmp_entry.IsValid());
83 const uword jump_target = jmp_entry.TargetAddress(); 85 const uword jump_target = jmp_entry.TargetAddress();
84 const uword patch_buffer = code.GetPatchCodePc(); 86 const uword patch_buffer = code.GetPatchCodePc();
85 ASSERT(patch_buffer != 0); 87 ASSERT(patch_buffer != 0);
86 // 'patch_buffer' contains original entry code. 88 // 'patch_buffer' contains original entry code.
87 JumpPattern jmp_patch(patch_buffer, code); 89 JumpPattern jmp_patch(patch_buffer, code);
88 ASSERT(!jmp_patch.IsValid()); 90 ASSERT(!jmp_patch.IsValid());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 const uword obj_start = code.GetPointerOffsetAt(i) + code.EntryPoint(); 127 const uword obj_start = code.GetPointerOffsetAt(i) + code.EntryPoint();
126 const uword obj_end = obj_start + kWordSize; 128 const uword obj_end = obj_start + kWordSize;
127 if ((obj_start < limit) && (obj_end > patch_addr)) { 129 if ((obj_start < limit) && (obj_end > patch_addr)) {
128 return false; 130 return false;
129 } 131 }
130 } 132 }
131 return true; 133 return true;
132 } 134 }
133 135
134 } // namespace dart 136 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698