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

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

Issue 8351019: Code patching support and tests for new inline caches. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years, 2 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_patcher.h ('k') | runtime/vm/code_patcher_ia32_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) 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 private:
25 static const int kNumInstructions = 3;
26 static const int kInstructionSize = 5; // All instructions have same length.
27
28 public: 24 public:
29 explicit DartCallPattern(uword return_address) 25 explicit DartCallPattern(uword return_address)
30 : start_(return_address - (kNumInstructions * kInstructionSize)) { 26 : start_(return_address - (kNumInstructions * kInstructionSize)) {
31 ASSERT(*reinterpret_cast<uint8_t*>(start_) == 0xB9); 27 ASSERT(*reinterpret_cast<uint8_t*>(start_) == 0xB9);
32 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 1 * kInstructionSize) == 0xBA); 28 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 1 * kInstructionSize) == 0xBA);
33 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 2 * kInstructionSize) == 0xE8); 29 ASSERT(*reinterpret_cast<uint8_t*>(start_ + 2 * kInstructionSize) == 0xE8);
34 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); 30 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
35 } 31 }
36 32
37 uword target() const { 33 uword target() const {
38 const uword offset = *reinterpret_cast<uword*>(call_address() + 1); 34 const uword offset = *reinterpret_cast<uword*>(call_address() + 1);
39 return return_address() + offset; 35 return return_address() + offset;
40 } 36 }
41 37
42 void set_target(uword target) const { 38 void set_target(uword target) const {
43 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); 39 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1);
44 uword offset = target - return_address(); 40 uword offset = target - return_address();
45 *target_addr = offset; 41 *target_addr = offset;
46 CPU::FlushICache(call_address(), kInstructionSize); 42 CPU::FlushICache(call_address(), kInstructionSize);
47 } 43 }
48 44
49 uint32_t immediate_one() const { 45 uint32_t immediate_one() const {
50 return *reinterpret_cast<uint32_t*>(start_ + 1); 46 return *reinterpret_cast<uint32_t*>(start_ + 1);
51 } 47 }
52 48
49 void set_immediate_one(uint32_t value) {
50 uint32_t* target_addr = reinterpret_cast<uint32_t*>(start_ + 1);
51 *target_addr = value;
52 CPU::FlushICache(call_address(), kInstructionSize);
53 }
54
53 uint32_t immediate_two() const { 55 uint32_t immediate_two() const {
54 return *reinterpret_cast<uint32_t*>(start_ + kInstructionSize + 1); 56 return *reinterpret_cast<uint32_t*>(start_ + kInstructionSize + 1);
55 } 57 }
56 58
57 int argument_count() const { 59 int argument_count() const {
58 Array& args_desc = Array::Handle(); 60 Array& args_desc = Array::Handle();
59 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); 61 args_desc ^= reinterpret_cast<RawObject*>(immediate_two());
60 Smi& num_args = Smi::Handle(); 62 Smi& num_args = Smi::Handle();
61 num_args ^= args_desc.At(0); 63 num_args ^= args_desc.At(0);
62 return num_args.Value(); 64 return num_args.Value();
63 } 65 }
64 66
65 int named_argument_count() const { 67 int named_argument_count() const {
66 Array& args_desc = Array::Handle(); 68 Array& args_desc = Array::Handle();
67 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); 69 args_desc ^= reinterpret_cast<RawObject*>(immediate_two());
68 Smi& num_args = Smi::Handle(); 70 Smi& num_args = Smi::Handle();
69 num_args ^= args_desc.At(0); 71 num_args ^= args_desc.At(0);
70 Smi& num_pos_args = Smi::Handle(); 72 Smi& num_pos_args = Smi::Handle();
71 num_pos_args ^= args_desc.At(1); 73 num_pos_args ^= args_desc.At(1);
72 return num_args.Value() - num_pos_args.Value(); 74 return num_args.Value() - num_pos_args.Value();
73 } 75 }
74 76
77 static const int kNumInstructions = 3;
78 static const int kInstructionSize = 5; // All instructions have same length.
79
75 private: 80 private:
76 uword return_address() const { 81 uword return_address() const {
77 return start_ + kNumInstructions * kInstructionSize; 82 return start_ + kNumInstructions * kInstructionSize;
78 } 83 }
79 84
80 uword call_address() const { 85 uword call_address() const {
81 return start_ + 2 * kInstructionSize; 86 return start_ + 2 * kInstructionSize;
82 } 87 }
83 88
84 uword start_; 89 uword start_;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 public: 121 public:
117 explicit InstanceCall(uword return_address) 122 explicit InstanceCall(uword return_address)
118 : DartCallPattern(return_address) {} 123 : DartCallPattern(return_address) {}
119 124
120 RawArray* ic_data() const { 125 RawArray* ic_data() const {
121 Array& array = Array::Handle(); 126 Array& array = Array::Handle();
122 array ^= reinterpret_cast<RawObject*>(immediate_one()); 127 array ^= reinterpret_cast<RawObject*>(immediate_one());
123 return array.raw(); 128 return array.raw();
124 } 129 }
125 130
131 void SetIcData(const Array& value) {
132 set_immediate_one(reinterpret_cast<int32_t>(value.raw()));
133 }
134
126 private: 135 private:
127 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); 136 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall);
128 }; 137 };
129 138
130 139
131 void CodePatcher::GetStaticCallAt(uword return_address, 140 void CodePatcher::GetStaticCallAt(uword return_address,
132 Function* function, 141 Function* function,
133 uword* target) { 142 uword* target) {
134 ASSERT(function != NULL); 143 ASSERT(function != NULL);
135 ASSERT(target != NULL); 144 ASSERT(target != NULL);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 ICData ic_data(Array::ZoneHandle(call.ic_data())); 257 ICData ic_data(Array::ZoneHandle(call.ic_data()));
249 *function_name = ic_data.FunctionName(); 258 *function_name = ic_data.FunctionName();
250 } 259 }
251 260
252 261
253 void CodePatcher::PatchInstanceCallAt(uword return_address, uword new_target) { 262 void CodePatcher::PatchInstanceCallAt(uword return_address, uword new_target) {
254 InstanceCall call(return_address); 263 InstanceCall call(return_address);
255 call.set_target(new_target); 264 call.set_target(new_target);
256 } 265 }
257 266
267
268 RawArray* CodePatcher::GetInstanceCallIcDataAt(uword return_address) {
269 InstanceCall call(return_address);
270 return call.ic_data();
271 }
272
273
274 void CodePatcher::SetInstanceCallIcDataAt(uword return_address,
275 const Array& ic_data) {
276 InstanceCall call(return_address);
277 call.SetIcData(ic_data);
278 }
279
280
281 intptr_t CodePatcher::InstanceCallSizeInBytes() {
282 return DartCallPattern::kNumInstructions * DartCallPattern::kInstructionSize;
283 }
284
258 } // namespace dart 285 } // namespace dart
259 286
260 #endif // defined TARGET_ARCH_IA32 287 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/code_patcher.h ('k') | runtime/vm/code_patcher_ia32_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698