Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2008 the V8 project authors. All rights reserved. | 1 // Copyright 2008 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 #ifndef V8_JUMP_TARGET_H_ | 28 #ifndef V8_JUMP_TARGET_H_ |
| 29 #define V8_JUMP_TARGET_H_ | 29 #define V8_JUMP_TARGET_H_ |
| 30 | 30 |
| 31 #include "virtual-frame.h" | 31 #include "virtual-frame.h" |
| 32 | 32 |
| 33 namespace v8 { namespace internal { | 33 namespace v8 { namespace internal { |
| 34 | 34 |
| 35 // ------------------------------------------------------------------------- | 35 // ------------------------------------------------------------------------- |
| 36 // Jump targets | 36 // Jump targets |
| 37 // | 37 // |
| 38 // TODO(): Update this comment. | |
|
Kasper Lund
2009/01/15 10:15:02
You should probably just do this.
Kevin Millikin (Chromium)
2009/01/15 13:08:18
Done.
| |
| 39 // | |
| 38 // A jump target is an abstraction of a control-flow target in generated | 40 // A jump target is an abstraction of a control-flow target in generated |
| 39 // code. It encapsulates an assembler label and an expected virtual frame | 41 // code. It encapsulates an assembler label and an expected virtual frame |
| 40 // layout at that label. The first time control flow reaches the target, | 42 // layout at that label. The first time control flow reaches the target, |
| 41 // either via jumping or branching or by binding the target, the expected | 43 // either via jumping or branching or by binding the target, the expected |
| 42 // frame is set. If control flow subsequently reaches the target, code may | 44 // frame is set. If control flow subsequently reaches the target, code may |
| 43 // be emitted to ensure that the current frame matches the expected frame. | 45 // be emitted to ensure that the current frame matches the expected frame. |
| 44 // | 46 // |
| 45 // A jump target must have been reached via control flow (either by jumping, | 47 // A jump target must have been reached via control flow (either by jumping, |
| 46 // branching, or falling through) when it is bound. In particular, this | 48 // branching, or falling through) when it is bound. In particular, this |
| 47 // means that at least one of the control-flow graph edges reaching the | 49 // means that at least one of the control-flow graph edges reaching the |
| 48 // target must be a forward edge and must be compiled before any backward | 50 // target must be a forward edge and must be compiled before any backward |
| 49 // edges. | 51 // edges. |
| 50 | 52 |
| 51 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. | 53 class JumpTarget : public ZoneObject { // Shadows are dynamically allocated. |
| 52 public: | 54 public: |
| 53 // Construct a jump target with a given code generator used to generate | 55 // Construct a jump target with a given code generator used to generate |
| 54 // code and to provide access to a current frame. | 56 // code and to provide access to a current frame. |
| 55 explicit JumpTarget(CodeGenerator* cgen); | 57 explicit JumpTarget(CodeGenerator* cgen); |
| 56 | 58 |
| 57 // Construct a jump target without a code generator. A code generator | 59 // Construct a jump target without a code generator. A code generator |
| 58 // must be supplied before using the jump target as a label. This is | 60 // must be supplied before using the jump target as a label. This is |
| 59 // useful, eg, when jump targets are embedded in AST nodes. | 61 // useful, eg, when jump targets are embedded in AST nodes. |
| 60 JumpTarget(); | 62 JumpTarget(); |
| 61 | 63 |
| 62 virtual ~JumpTarget() { delete expected_frame_; } | 64 virtual ~JumpTarget() { Unuse(); } |
| 63 | 65 |
| 64 // Supply a code generator. This function expects to be given a non-null | 66 // Supply a code generator. This function expects to be given a non-null |
| 65 // code generator, and to be called only when the code generator is not | 67 // code generator, and to be called only when the code generator is not |
| 66 // yet set. | 68 // yet set. |
| 67 void set_code_generator(CodeGenerator* cgen); | 69 void set_code_generator(CodeGenerator* cgen); |
| 68 | 70 |
| 69 // Accessors. | 71 // Accessors. |
| 70 CodeGenerator* code_generator() const { return cgen_; } | 72 CodeGenerator* code_generator() const { return cgen_; } |
| 71 | 73 |
| 72 Label* label() { return &label_; } | 74 Label* entry_label() { return &entry_label_; } |
| 73 | 75 |
| 74 VirtualFrame* expected_frame() const { return expected_frame_; } | 76 VirtualFrame* expected_frame() const { return expected_frame_; } |
| 75 void set_expected_frame(VirtualFrame* frame) { | 77 void set_expected_frame(VirtualFrame* frame) { |
| 76 expected_frame_ = frame; | 78 expected_frame_ = frame; |
| 77 } | 79 } |
| 78 | 80 |
| 79 // Predicates testing the state of the encapsulated label. | 81 // Predicates testing the state of the encapsulated label. |
| 80 bool is_bound() const { return label_.is_bound(); } | 82 bool is_bound() const { return expected_frame_ != NULL; } |
| 81 bool is_linked() const { return label_.is_linked(); } | 83 bool is_linked() const { return reaching_frames_.length() > 0; } |
| 82 bool is_unused() const { return label_.is_unused(); } | 84 bool is_unused() const { return !is_bound() && !is_linked(); } |
| 83 | 85 |
| 84 // Treat the jump target as a fresh one---the label is unused and the | 86 // Treat the jump target as a fresh one. The expected frame if any |
| 85 // expected frame if any is reset. | 87 // will be deallocated and there should be no dangling jumps to the |
| 88 // target (thus no reaching frames). | |
| 86 void Unuse() { | 89 void Unuse() { |
| 87 label_.Unuse(); | 90 ASSERT(!is_linked()); |
| 91 entry_label_.Unuse(); | |
| 88 delete expected_frame_; | 92 delete expected_frame_; |
| 89 expected_frame_ = NULL; | 93 expected_frame_ = NULL; |
| 90 } | 94 } |
| 91 | 95 |
| 92 // Emit a jump to the target. There must be a current frame before the | 96 // Reset the internal state of this jump target. Pointed-to virtual |
| 97 // frames are not deallocated and dangling jumps to the target are | |
| 98 // left dangling. | |
| 99 void Reset() { | |
| 100 reaching_frames_.Clear(); | |
| 101 merge_labels_.Clear(); | |
| 102 expected_frame_ = NULL; | |
|
Kasper Lund
2009/01/15 10:15:02
Do we need to delete the expected frame here befor
Kevin Millikin (Chromium)
2009/01/15 13:08:18
We don't want to delete it because it has normally
| |
| 103 entry_label_.Unuse(); | |
| 104 } | |
| 105 | |
| 106 // Copy the state of this jump target to the destination. The lists | |
| 107 // of forward-reaching frames and merge-point labels are copied. | |
| 108 // All virtual frame pointers are copied, not the pointed-to frames. | |
| 109 // The previous state of the destination is overwritten, without | |
| 110 // deallocating pointed-to virtual frames. | |
| 111 void CopyTo(JumpTarget* destination); | |
| 112 | |
| 113 // Emit a jump to the target. There must be a current frame at the | |
| 93 // jump and there will be no current frame after the jump. | 114 // jump and there will be no current frame after the jump. |
| 94 void Jump(); | 115 void Jump(); |
| 95 void Jump(Result* arg); | 116 void Jump(Result* arg); |
| 96 | 117 |
| 97 // Emit a conditional branch to the target. If there is no current frame, | 118 // Emit a conditional branch to the target. There must be a current |
| 98 // there must be one expected at the target. | 119 // frame at the branch. The current frame will fall through to the |
| 120 // code after the branch. | |
| 99 void Branch(Condition cc, Hint hint = no_hint); | 121 void Branch(Condition cc, Hint hint = no_hint); |
| 100 void Branch(Condition cc, Result* arg, Hint hint = no_hint); | 122 void Branch(Condition cc, Result* arg, Hint hint = no_hint); |
| 101 void Branch(Condition cc, Result* arg0, Result* arg1, Hint hint = no_hint); | 123 void Branch(Condition cc, Result* arg0, Result* arg1, Hint hint = no_hint); |
| 102 | 124 |
| 103 // Bind a jump target. There must be a current frame and no expected | 125 // Bind a jump target. If there is no current frame at the binding |
| 104 // frame at the target (targets are only bound once). | 126 // site, there must be an expected one at the target, which will |
| 127 // become the current frame after the bind. | |
|
William Hesse
2009/01/15 12:21:54
Are we allowing non-mergable expected frames, whic
Kevin Millikin (Chromium)
2009/01/15 13:08:18
The frame after the binding site will always be th
| |
| 105 void Bind(); | 128 void Bind(); |
| 106 void Bind(Result* arg); | 129 void Bind(Result* arg); |
| 107 void Bind(Result* arg0, Result* arg1); | 130 void Bind(Result* arg0, Result* arg1); |
| 108 | 131 |
| 109 // Emit a call to a jump target. There must be a current frame. The | 132 // Emit a call to a jump target. There must be a current frame at |
| 110 // frame at the target is the same as the current frame except for an | 133 // the call. The frame at the target is the same as the current |
| 111 // extra return address on top of it. | 134 // frame except for an extra return address on top of it. The frame |
| 135 // after the call is the same as the frame before the call. | |
| 112 void Call(); | 136 void Call(); |
| 113 | 137 |
| 114 protected: | 138 protected: |
| 115 // The encapsulated assembler label. | 139 // The code generator gives access to its current frame. |
| 116 Label label_; | |
| 117 | |
| 118 // The expected frame where the label is bound, or NULL. | |
| 119 VirtualFrame* expected_frame_; | |
| 120 | |
| 121 private: | |
| 122 // The code generator gives access to the current frame. | |
| 123 CodeGenerator* cgen_; | 140 CodeGenerator* cgen_; |
| 124 | 141 |
| 125 // Used to emit code. | 142 // Used to emit code. |
| 126 MacroAssembler* masm_; | 143 MacroAssembler* masm_; |
| 144 | |
| 145 private: | |
| 146 // A list of frames reaching this block via forward jumps. | |
| 147 List<VirtualFrame*> reaching_frames_; | |
| 148 | |
| 149 // A parallel list of labels for merge code. | |
| 150 List<Label> merge_labels_; | |
| 151 | |
| 152 // The (mergable) frame expected at backward jumps to the block. | |
| 153 VirtualFrame* expected_frame_; | |
| 154 | |
| 155 // The actual entry label of the block. | |
| 156 Label entry_label_; | |
| 157 | |
| 158 // Add a virtual frame reaching this labeled block via a forward | |
| 159 // jump, and a fresh label for its merge code. | |
| 160 void AddReachingFrame(VirtualFrame* frame) { | |
|
Kasper Lund
2009/01/15 10:15:02
I don't know if this really should be inline. Mayb
Kevin Millikin (Chromium)
2009/01/15 13:08:18
Done.
| |
| 161 ASSERT(reaching_frames_.length() == merge_labels_.length()); | |
| 162 Label fresh; | |
| 163 merge_labels_.Add(fresh); | |
| 164 reaching_frames_.Add(frame); | |
| 165 } | |
| 166 | |
| 167 DISALLOW_COPY_AND_ASSIGN(JumpTarget); | |
| 127 }; | 168 }; |
| 128 | 169 |
| 129 | 170 |
| 130 // ------------------------------------------------------------------------- | 171 // ------------------------------------------------------------------------- |
| 131 // Shadow jump targets | 172 // Shadow jump targets |
| 132 // | 173 // |
| 133 // Shadow jump targets represent a jump target that is temporarily shadowed | 174 // Shadow jump targets represent a jump target that is temporarily shadowed |
| 134 // by another one (represented by the original during shadowing). They are | 175 // by another one (represented by the original during shadowing). They are |
| 135 // used to catch jumps to labels in certain contexts, e.g. try blocks. | 176 // used to catch jumps to labels in certain contexts, e.g. try blocks. |
| 136 // After shadowing ends, the formerly shadowed target is again represented | 177 // After shadowing ends, the formerly shadowed target is again represented |
| 137 // by the original and the ShadowTarget can be used as a jump target in its | 178 // by the original and the ShadowTarget can be used as a jump target in its |
| 138 // own right, representing the formerly shadowing target. | 179 // own right, representing the formerly shadowing target. |
| 139 | 180 |
| 140 class ShadowTarget : public JumpTarget { | 181 class ShadowTarget : public JumpTarget { |
| 141 public: | 182 public: |
| 142 // Construct a shadow a jump target. After construction, the original | 183 // Construct a shadow jump target. After construction, the original |
| 143 // jump target shadows the former target, which is hidden as the | 184 // jump target shadows other one, which is hidden as the |
|
William Hesse
2009/01/15 12:21:54
Not grammatical, confusing.
Kevin Millikin (Chromium)
2009/01/15 13:08:18
Added "the".
| |
| 144 // newly-constructed shadow target. | 185 // newly-constructed shadow target. |
| 145 explicit ShadowTarget(JumpTarget* original); | 186 explicit ShadowTarget(JumpTarget* shadowed); |
| 146 | 187 |
| 147 virtual ~ShadowTarget() { | 188 virtual ~ShadowTarget() { |
| 148 ASSERT(!is_shadowing_); | 189 ASSERT(!is_shadowing_); |
| 149 } | 190 } |
| 150 | 191 |
| 151 // End shadowing. After shadowing ends, the original jump target gives | 192 // End shadowing. After shadowing ends, the original jump target gives |
| 152 // access to the formerly shadowed target and the shadow target object | 193 // access to the formerly shadowed target and the shadow target object |
| 153 // gives access to the formerly shadowing target. | 194 // gives access to the formerly shadowing target. |
| 154 void StopShadowing(); | 195 void StopShadowing(); |
| 155 | 196 |
| 156 // During shadowing, the currently shadowing target. After shadowing, the | 197 // During shadowing, the currently shadowing target. After shadowing, the |
| 157 // target that was shadowed. | 198 // target that was shadowed. |
| 158 JumpTarget* original_target() const { return original_target_; } | 199 JumpTarget* other_target() const { return other_target_; } |
|
William Hesse
2009/01/15 12:21:54
Could this be called "active" target? This is the
Kevin Millikin (Chromium)
2009/01/15 13:08:18
No. After shadowing they are both active. I can'
| |
| 159 | 200 |
| 160 private: | 201 private: |
| 161 // During shadowing, the currently shadowing target. After shadowing, the | 202 // During shadowing, the currently shadowing target. After shadowing, the |
| 162 // target that was shadowed. | 203 // target that was shadowed. |
| 163 JumpTarget* original_target_; | 204 JumpTarget* other_target_; |
| 164 | |
| 165 // During shadowing, the saved state of the shadowed target's label. | |
| 166 int original_pos_; | |
| 167 | |
| 168 // During shadowing, the saved state of the shadowed target's expected | |
| 169 // frame. | |
| 170 VirtualFrame* original_expected_frame_; | |
| 171 | 205 |
| 172 #ifdef DEBUG | 206 #ifdef DEBUG |
| 173 bool is_shadowing_; | 207 bool is_shadowing_; |
| 174 #endif | 208 #endif |
| 175 }; | 209 }; |
| 176 | 210 |
| 177 | 211 |
| 178 } } // namespace v8::internal | 212 } } // namespace v8::internal |
| 179 | 213 |
| 180 #endif // V8_JUMP_TARGET_H_ | 214 #endif // V8_JUMP_TARGET_H_ |
| OLD | NEW |