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

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

Issue 11442010: Introduce a class encapsulating arguments descriptor arrays. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Incorporated review comments. Created 8 years 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) 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/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/dart_entry.h"
11 #include "vm/instructions.h" 12 #include "vm/instructions.h"
12 #include "vm/object.h" 13 #include "vm/object.h"
13 #include "vm/raw_object.h" 14 #include "vm/raw_object.h"
14 15
15 namespace dart { 16 namespace dart {
16 17
17 // The pattern of a Dart instance call is: 18 // The pattern of a Dart instance call is:
18 // 1: mov ECX, immediate 1 19 // 1: mov ECX, immediate 1
19 // 2: mov EDX, immediate 2 20 // 2: mov EDX, immediate 2
20 // 3: call target_address 21 // 3: call target_address
(...skipping 20 matching lines...) Expand all
41 return return_address() + offset; 42 return return_address() + offset;
42 } 43 }
43 44
44 void set_target(uword target) const { 45 void set_target(uword target) const {
45 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1); 46 uword* target_addr = reinterpret_cast<uword*>(call_address() + 1);
46 uword offset = target - return_address(); 47 uword offset = target - return_address();
47 *target_addr = offset; 48 *target_addr = offset;
48 CPU::FlushICache(call_address(), kInstructionSize); 49 CPU::FlushICache(call_address(), kInstructionSize);
49 } 50 }
50 51
51 uint32_t immediate_one() const { 52 RawObject* immediate_one() const {
52 return *reinterpret_cast<uint32_t*>(start_ + 1); 53 return *reinterpret_cast<RawObject**>(start_ + 1);
53 } 54 }
54 55
55 void set_immediate_one(uint32_t value) { 56 void set_immediate_one(uint32_t value) {
56 uint32_t* target_addr = reinterpret_cast<uint32_t*>(start_ + 1); 57 uint32_t* target_addr = reinterpret_cast<uint32_t*>(start_ + 1);
57 *target_addr = value; 58 *target_addr = value;
58 CPU::FlushICache(start_, kInstructionSize); 59 CPU::FlushICache(start_, kInstructionSize);
59 } 60 }
60 61
61 uint32_t immediate_two() const { 62 RawObject* immediate_two() const {
62 return *reinterpret_cast<uint32_t*>(start_ + kInstructionSize + 1); 63 return *reinterpret_cast<RawObject**>(start_ + kInstructionSize + 1);
63 } 64 }
64 65
65 int argument_count() const { 66 intptr_t argument_count() const {
66 Array& args_desc = Array::Handle(); 67 ArgumentsDescriptor args_desc(immediate_two());
67 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); 68 return args_desc.Count();
68 Smi& num_args = Smi::Handle();
69 num_args ^= args_desc.At(0);
70 return num_args.Value();
71 } 69 }
72 70
73 int named_argument_count() const { 71 intptr_t named_argument_count() const {
74 Array& args_desc = Array::Handle(); 72 ArgumentsDescriptor args_desc(immediate_two());
75 args_desc ^= reinterpret_cast<RawObject*>(immediate_two()); 73 return args_desc.NamedCount();
76 Smi& num_args = Smi::Handle();
77 num_args ^= args_desc.At(0);
78 Smi& num_pos_args = Smi::Handle();
79 num_pos_args ^= args_desc.At(1);
80 return num_args.Value() - num_pos_args.Value();
81 } 74 }
82 75
83 static const int kNumInstructions = 3; 76 static const int kNumInstructions = 3;
84 static const int kInstructionSize = 5; // All instructions have same length. 77 static const int kInstructionSize = 5; // All instructions have same length.
85 78
86 private: 79 private:
87 uword return_address() const { 80 uword return_address() const {
88 return start_ + kNumInstructions * kInstructionSize; 81 return start_ + kNumInstructions * kInstructionSize;
89 } 82 }
90 83
91 uword call_address() const { 84 uword call_address() const {
92 return start_ + 2 * kInstructionSize; 85 return start_ + 2 * kInstructionSize;
93 } 86 }
94 87
95 uword start_; 88 uword start_;
96 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern); 89 DISALLOW_IMPLICIT_CONSTRUCTORS(DartCallPattern);
97 }; 90 };
98 91
99 92
100 // The expected pattern of a dart instance call: 93 // The expected pattern of a dart instance call:
101 // mov ECX, ic-data 94 // mov ECX, ic-data
102 // mov EDX, argument_descriptor_array 95 // mov EDX, arguments_descriptor_array
103 // call target_address 96 // call target_address
104 // <- return address 97 // <- return address
105 class InstanceCall : public DartCallPattern { 98 class InstanceCall : public DartCallPattern {
106 public: 99 public:
107 explicit InstanceCall(uword return_address) 100 explicit InstanceCall(uword return_address)
108 : DartCallPattern(return_address) {} 101 : DartCallPattern(return_address) {}
109 102
110 RawICData* ic_data() const { 103 RawICData* ic_data() const {
111 ICData& ic_data = ICData::Handle(); 104 ICData& ic_data = ICData::Handle();
112 ic_data ^= reinterpret_cast<RawObject*>(immediate_one()); 105 ic_data ^= immediate_one();
113 return ic_data.raw(); 106 return ic_data.raw();
114 } 107 }
115 108
116 private: 109 private:
117 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall); 110 DISALLOW_IMPLICIT_CONSTRUCTORS(InstanceCall);
118 }; 111 };
119 112
120 113
121 // The expected pattern of a dart static call: 114 // The expected pattern of a dart static call:
122 // mov EDX, argument_descriptor_array 115 // mov EDX, arguments_descriptor_array
123 // call target_address 116 // call target_address
124 // <- return address 117 // <- return address
125 class StaticCall : public ValueObject { 118 class StaticCall : public ValueObject {
126 public: 119 public:
127 explicit StaticCall(uword return_address) 120 explicit StaticCall(uword return_address)
128 : start_(return_address - (kNumInstructions * kInstructionSize)) { 121 : start_(return_address - (kNumInstructions * kInstructionSize)) {
129 ASSERT(IsValid(return_address)); 122 ASSERT(IsValid(return_address));
130 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize); 123 ASSERT(kInstructionSize == Assembler::kCallExternalLabelSize);
131 } 124 }
132 125
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 *reinterpret_cast<uint8_t*>(start) = 0xE8; 281 *reinterpret_cast<uint8_t*>(start) = 0xE8;
289 CallPattern call(start); 282 CallPattern call(start);
290 call.SetTargetAddress(target); 283 call.SetTargetAddress(target);
291 CPU::FlushICache(start, CallPattern::InstructionLength()); 284 CPU::FlushICache(start, CallPattern::InstructionLength());
292 } 285 }
293 286
294 287
295 } // namespace dart 288 } // namespace dart
296 289
297 #endif // defined TARGET_ARCH_IA32 290 #endif // defined TARGET_ARCH_IA32
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698