OLD | NEW |
---|---|
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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" | 5 #include "vm/globals.h" |
6 #if defined(TARGET_ARCH_DBC) | 6 #if defined(TARGET_ARCH_DBC) |
7 | 7 |
8 #include "vm/code_patcher.h" | 8 #include "vm/code_patcher.h" |
9 #include "vm/cpu.h" | 9 #include "vm/cpu.h" |
10 #include "vm/debugger.h" | 10 #include "vm/debugger.h" |
11 #include "vm/instructions.h" | 11 #include "vm/instructions.h" |
12 #include "vm/stub_code.h" | 12 #include "vm/stub_code.h" |
13 | 13 |
14 namespace dart { | 14 namespace dart { |
15 | 15 |
16 #ifndef PRODUCT | 16 #ifndef PRODUCT |
17 | 17 |
18 RawCode* CodeBreakpoint::OrigStubAddress() const { | 18 RawCode* CodeBreakpoint::OrigStubAddress() const { |
19 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); | 19 return reinterpret_cast<RawCode*>(static_cast<uintptr_t>(saved_value_)); |
20 } | 20 } |
21 | 21 |
22 | 22 |
23 static Instr* CallInstructionFromReturnAddress(uword pc) { | 23 static Instr* CallInstructionFromReturnAddress(uword pc) { |
24 return reinterpret_cast<Instr*>(pc) - 1; | 24 return reinterpret_cast<Instr*>(pc) - 1; |
25 } | 25 } |
26 | 26 |
27 | 27 |
28 static Instr* FastSmiInstructionFromCallReturnAddress(uword pc) { | |
29 return reinterpret_cast<Instr*>(pc) - 2; | |
30 } | |
31 | |
32 | |
28 void CodeBreakpoint::PatchCode() { | 33 void CodeBreakpoint::PatchCode() { |
29 ASSERT(!is_enabled_); | 34 ASSERT(!is_enabled_); |
30 const Code& code = Code::Handle(code_); | 35 const Code& code = Code::Handle(code_); |
31 const Instructions& instrs = Instructions::Handle(code.instructions()); | 36 const Instructions& instrs = Instructions::Handle(code.instructions()); |
32 { | 37 { |
33 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 38 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
34 saved_value_ = *CallInstructionFromReturnAddress(pc_); | 39 saved_value_ = *CallInstructionFromReturnAddress(pc_); |
35 switch (breakpoint_kind_) { | 40 switch (breakpoint_kind_) { |
36 case RawPcDescriptors::kIcCall: | 41 case RawPcDescriptors::kIcCall: |
37 case RawPcDescriptors::kUnoptStaticCall: { | 42 case RawPcDescriptors::kUnoptStaticCall: { |
38 // DebugBreak has an A operand matching the call it replaces. | 43 // DebugBreak has an A operand matching the call it replaces. |
39 // This ensures that Return instructions continue to work - as they | 44 // This ensures that Return instructions continue to work - as they |
40 // look at calls to figure out how many arguments to drop. | 45 // look at calls to figure out how many arguments to drop. |
41 *CallInstructionFromReturnAddress(pc_) = | 46 *CallInstructionFromReturnAddress(pc_) = |
42 Bytecode::Encode(Bytecode::kDebugBreak, | 47 Bytecode::Encode(Bytecode::kDebugBreak, |
43 Bytecode::DecodeArgc(saved_value_), | 48 Bytecode::DecodeArgc(saved_value_), |
44 0, | 49 0, |
45 0); | 50 0); |
46 break; | 51 break; |
47 } | 52 } |
48 | 53 |
49 case RawPcDescriptors::kRuntimeCall: { | 54 case RawPcDescriptors::kRuntimeCall: { |
50 *CallInstructionFromReturnAddress(pc_) = Bytecode::kDebugBreak; | 55 *CallInstructionFromReturnAddress(pc_) = Bytecode::kDebugBreak; |
51 break; | 56 break; |
52 } | 57 } |
53 | 58 |
54 default: | 59 default: |
55 UNREACHABLE(); | 60 UNREACHABLE(); |
56 } | 61 } |
62 | |
63 // If this call is the fall-through for a fast Smi op, also disable the fast | |
64 // Smi op. | |
65 if (Bytecode::DecodeOpcode(saved_value_) == Bytecode::kInstanceCall2) { | |
zra
2016/07/28 18:08:48
Looking at the code in InstanceCallInstr::EmitNati
rmacnak
2016/07/28 20:13:14
So those other cases turn out to be []= and some k
zra
2016/07/28 20:17:47
Cool. Thanks for looking into this and adding a te
| |
66 saved_value_fastsmi_ = *FastSmiInstructionFromCallReturnAddress(pc_); | |
67 ASSERT(Bytecode::IsFastSmiOpcode(saved_value_fastsmi_)); | |
68 *FastSmiInstructionFromCallReturnAddress(pc_) = | |
69 Bytecode::Encode(Bytecode::kNop, 0, 0, 0); | |
70 } | |
57 } | 71 } |
58 is_enabled_ = true; | 72 is_enabled_ = true; |
59 } | 73 } |
60 | 74 |
61 | 75 |
62 void CodeBreakpoint::RestoreCode() { | 76 void CodeBreakpoint::RestoreCode() { |
63 ASSERT(is_enabled_); | 77 ASSERT(is_enabled_); |
64 const Code& code = Code::Handle(code_); | 78 const Code& code = Code::Handle(code_); |
65 const Instructions& instrs = Instructions::Handle(code.instructions()); | 79 const Instructions& instrs = Instructions::Handle(code.instructions()); |
66 { | 80 { |
67 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); | 81 WritableInstructionsScope writable(instrs.EntryPoint(), instrs.size()); |
68 switch (breakpoint_kind_) { | 82 switch (breakpoint_kind_) { |
69 case RawPcDescriptors::kIcCall: | 83 case RawPcDescriptors::kIcCall: |
70 case RawPcDescriptors::kUnoptStaticCall: | 84 case RawPcDescriptors::kUnoptStaticCall: |
71 case RawPcDescriptors::kRuntimeCall: { | 85 case RawPcDescriptors::kRuntimeCall: { |
72 *CallInstructionFromReturnAddress(pc_) = saved_value_; | 86 *CallInstructionFromReturnAddress(pc_) = saved_value_; |
73 break; | 87 break; |
74 } | 88 } |
75 default: | 89 default: |
76 UNREACHABLE(); | 90 UNREACHABLE(); |
77 } | 91 } |
92 | |
93 if (Bytecode::DecodeOpcode(saved_value_) == Bytecode::kInstanceCall2) { | |
94 Instr current_instr = *FastSmiInstructionFromCallReturnAddress(pc_); | |
95 ASSERT(Bytecode::DecodeOpcode(current_instr) == Bytecode::kNop); | |
96 *FastSmiInstructionFromCallReturnAddress(pc_) = saved_value_fastsmi_; | |
97 } | |
78 } | 98 } |
79 is_enabled_ = false; | 99 is_enabled_ = false; |
80 } | 100 } |
81 | 101 |
82 #endif // !PRODUCT | 102 #endif // !PRODUCT |
83 | 103 |
84 } // namespace dart | 104 } // namespace dart |
85 | 105 |
86 #endif // defined TARGET_ARCH_DBC | 106 #endif // defined TARGET_ARCH_DBC |
OLD | NEW |