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

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

Issue 8588014: Addition to CodePatcher (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 9 years, 1 month 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
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/globals.h" // Needed here to get TARGET_ARCH_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/code_patcher.h" 9 #include "vm/code_patcher.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
11 #include "vm/ic_data.h" 11 #include "vm/ic_data.h"
12 #include "vm/instructions.h" 12 #include "vm/instructions.h"
13 #include "vm/object.h" 13 #include "vm/object.h"
14 #include "vm/raw_object.h" 14 #include "vm/raw_object.h"
15 15
16 namespace dart { 16 namespace dart {
17 17
18 // The pattern of a Dart call is: 18 // The pattern of a Dart call is:
19 // 1: mov ECX, immediate 1 19 // 1: mov ECX, immediate 1
20 // 2: mov EDX, immediate 2 20 // 2: mov EDX, immediate 2
21 // 3: call target_address 21 // 3: call target_address
22 // <- return_address 22 // <- return_address
23 class DartCallPattern : public ValueObject { 23 class DartCallPattern : public ValueObject {
24 public: 24 public:
25 explicit DartCallPattern(uword return_address) 25 explicit DartCallPattern(uword return_address)
26 : start_(return_address - (kNumInstructions * kInstructionSize)) { 26 : start_(return_address - (kNumInstructions * kInstructionSize)) {
27 ASSERT(*reinterpret_cast<uint8_t*>(start_) == 0xB9); 27 ASSERT(*reinterpret_cast<uint8_t*>(start_) == 0xB9);
28 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 1 * kInstructionSize) == 0xBA); 28 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 1 * kInstructionSize) == 0xBA);
29 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 2 * kInstructionSize) == 0xE8); 29 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 2 * kInstructionSize) == 0xE8);
srdjan 2011/11/17 01:32:55 Merge the 3 asserts into one using IsValidCallPatt
hausner 2011/11/17 16:33:02 Done.
30 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); 30 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
31 } 31 }
32 32
33 static bool IsValidCallPattern(uword return_address) {
srdjan 2011/11/17 01:32:55 Could be called DartCallPattern::IsValid instead o
hausner 2011/11/17 16:33:02 Done.
34 uint8_t* code_bytes =
35 reinterpret_cast<uint8_t*>(
36 return_address - (kNumInstructions * kInstructionSize));
37 return (code_bytes[0] == 0xB9) &&
38 (code_bytes[kInstructionSize] == 0xBA) &&
39 (code_bytes[2 * kInstructionSize] == 0xE8);
40 }
41
33 uword target() const { 42 uword target() const {
34 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); 43 const uword offset = *reinterpret_cast<uword*>(call_address() + 1);
35 return return_address() + offset; 44 return return_address() + offset;
36 } 45 }
37 46
38 void set_target(uword target) const { 47 void set_target(uword target) const {
39 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); 48 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1);
40 uword offset = target - return_address(); 49 uword offset = target - return_address();
41 *target_addr = offset; 50 *target_addr = offset;
42 CPU::FlushICache(call_address(), kInstructionSize); 51 CPU::FlushICache(call_address(), kInstructionSize);
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) { 219 for (intptr_t i = 0; i < code.pointer_offsets_length(); i++) {
211 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint(); 220 const uword addr = code.GetPointerOffsetAt(i) + code.EntryPoint();
212 if (addr < limit) { 221 if (addr < limit) {
213 return false; 222 return false;
214 } 223 }
215 } 224 }
216 return true; 225 return true;
217 } 226 }
218 227
219 228
229 bool CodePatcher::IsDartCall(uword return_address) {
230 return DartCallPattern::IsValidCallPattern(return_address);
231 }
232
233
220 void CodePatcher::GetInstanceCallAt(uword return_address, 234 void CodePatcher::GetInstanceCallAt(uword return_address,
221 String* function_name, 235 String* function_name,
222 int* num_arguments, 236 int* num_arguments,
223 int* num_named_arguments, 237 int* num_named_arguments,
224 uword* target) { 238 uword* target) {
225 ASSERT(function_name != NULL); 239 ASSERT(function_name != NULL);
226 ASSERT(num_arguments != NULL); 240 ASSERT(num_arguments != NULL);
227 ASSERT(num_named_arguments != NULL); 241 ASSERT(num_named_arguments != NULL);
228 ASSERT(target != NULL); 242 ASSERT(target != NULL);
229 InstanceCall call(return_address); 243 InstanceCall call(return_address);
(...skipping 18 matching lines...) Expand all
248 } 262 }
249 263
250 264
251 intptr_t CodePatcher::InstanceCallSizeInBytes() { 265 intptr_t CodePatcher::InstanceCallSizeInBytes() {
252 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize; 266 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize;
253 } 267 }
254 268
255 } // namespace dart 269 } // namespace dart
256 270
257 #endif // defined TARGET_ARCH_IA32 271 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698