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

Side by Side Diff: src/full-codegen.h

Issue 23526069: Refactor back edge table related code into a new class. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | « src/deoptimizer.cc ('k') | src/full-codegen.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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 #elif V8_TARGET_ARCH_X64 132 #elif V8_TARGET_ARCH_X64
133 static const int kCodeSizeMultiplier = 162; 133 static const int kCodeSizeMultiplier = 162;
134 #elif V8_TARGET_ARCH_ARM 134 #elif V8_TARGET_ARCH_ARM
135 static const int kCodeSizeMultiplier = 142; 135 static const int kCodeSizeMultiplier = 142;
136 #elif V8_TARGET_ARCH_MIPS 136 #elif V8_TARGET_ARCH_MIPS
137 static const int kCodeSizeMultiplier = 142; 137 static const int kCodeSizeMultiplier = 142;
138 #else 138 #else
139 #error Unsupported target architecture. 139 #error Unsupported target architecture.
140 #endif 140 #endif
141 141
142 class BackEdgeTableIterator {
143 public:
144 explicit BackEdgeTableIterator(Code* unoptimized,
145 DisallowHeapAllocation* required) {
146 ASSERT(unoptimized->kind() == Code::FUNCTION);
147 instruction_start_ = unoptimized->instruction_start();
148 cursor_ = instruction_start_ + unoptimized->back_edge_table_offset();
149 ASSERT(cursor_ < instruction_start_ + unoptimized->instruction_size());
150 table_length_ = Memory::uint32_at(cursor_);
151 cursor_ += kTableLengthSize;
152 end_ = cursor_ + table_length_ * kEntrySize;
153 }
154
155 bool Done() { return cursor_ >= end_; }
156
157 void Next() {
158 ASSERT(!Done());
159 cursor_ += kEntrySize;
160 }
161
162 BailoutId ast_id() {
163 ASSERT(!Done());
164 return BailoutId(static_cast<int>(
165 Memory::uint32_at(cursor_ + kAstIdOffset)));
166 }
167
168 uint32_t loop_depth() {
169 ASSERT(!Done());
170 return Memory::uint32_at(cursor_ + kLoopDepthOffset);
171 }
172
173 uint32_t pc_offset() {
174 ASSERT(!Done());
175 return Memory::uint32_at(cursor_ + kPcOffsetOffset);
176 }
177
178 Address pc() {
179 ASSERT(!Done());
180 return instruction_start_ + pc_offset();
181 }
182
183 uint32_t table_length() { return table_length_; }
184
185 private:
186 static const int kTableLengthSize = kIntSize;
187 static const int kAstIdOffset = 0 * kIntSize;
188 static const int kPcOffsetOffset = 1 * kIntSize;
189 static const int kLoopDepthOffset = 2 * kIntSize;
190 static const int kEntrySize = 3 * kIntSize;
191
192 Address cursor_;
193 Address end_;
194 Address instruction_start_;
195 uint32_t table_length_;
196
197 DISALLOW_COPY_AND_ASSIGN(BackEdgeTableIterator);
198 };
199
200
201 private: 142 private:
202 class Breakable; 143 class Breakable;
203 class Iteration; 144 class Iteration;
204 145
205 class TestContext; 146 class TestContext;
206 147
207 class NestedStatement BASE_EMBEDDED { 148 class NestedStatement BASE_EMBEDDED {
208 public: 149 public:
209 explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) { 150 explicit NestedStatement(FullCodeGenerator* codegen) : codegen_(codegen) {
210 // Link into codegen's nesting stack. 151 // Link into codegen's nesting stack.
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
933 Iterator it = find(literal, true, ZoneAllocationPolicy(zone_)); 874 Iterator it = find(literal, true, ZoneAllocationPolicy(zone_));
934 if (it->second == NULL) it->second = new(zone_) ObjectLiteral::Accessors(); 875 if (it->second == NULL) it->second = new(zone_) ObjectLiteral::Accessors();
935 return it; 876 return it;
936 } 877 }
937 878
938 private: 879 private:
939 Zone* zone_; 880 Zone* zone_;
940 }; 881 };
941 882
942 883
884 class BackEdgeTable {
885 public:
886 BackEdgeTable(Code* code, DisallowHeapAllocation* required) {
887 ASSERT(code->kind() == Code::FUNCTION);
888 instruction_start_ = code->instruction_start();
889 Address table_address = instruction_start_ + code->back_edge_table_offset();
890 length_ = Memory::uint32_at(table_address);
891 start_ = table_address + kTableLengthSize;
892 }
893
894 uint32_t length() { return length_; }
895
896 BailoutId ast_id(uint32_t index) {
897 return BailoutId(static_cast<int>(
898 Memory::uint32_at(entry_at(index) + kAstIdOffset)));
899 }
900
901 uint32_t loop_depth(uint32_t index) {
902 return Memory::uint32_at(entry_at(index) + kLoopDepthOffset);
903 }
904
905 uint32_t pc_offset(uint32_t index) {
906 return Memory::uint32_at(entry_at(index) + kPcOffsetOffset);
907 }
908
909 Address pc(uint32_t index) {
910 return instruction_start_ + pc_offset(index);
911 }
912
913 enum BackEdgeState {
914 INTERRUPT,
915 ON_STACK_REPLACEMENT
916 };
917
918 // Patch all interrupts with allowed loop depth in the unoptimized code to
919 // unconditionally call replacement_code.
920 static void Patch(Isolate* isolate,
921 Code* unoptimized_code);
922
923 // Patch the interrupt at the instruction before pc_after in
924 // the unoptimized code to unconditionally call replacement_code.
925 static void PatchAt(Code* unoptimized_code,
926 Address pc_after,
927 Code* replacement_code);
928
929 // Change all patched interrupts patched in the unoptimized code
930 // back to normal interrupts.
931 static void Revert(Isolate* isolate,
932 Code* unoptimized_code);
933
934 // Change patched interrupt in the unoptimized code
935 // back to a normal interrupt.
936 static void RevertAt(Code* unoptimized_code,
937 Address pc_after,
938 Code* interrupt_code);
939
940 #ifdef DEBUG
941 static BackEdgeState GetBackEdgeState(Isolate* isolate,
942 Code* unoptimized_code,
943 Address pc_after);
944
945 // Verify that all back edges of a certain loop depth are patched.
946 static bool Verify(Isolate* isolate,
947 Code* unoptimized_code,
948 int loop_nesting_level);
949 #endif // DEBUG
950
951 private:
952 Address entry_at(uint32_t index) {
953 ASSERT(index < length_);
954 return start_ + index * kEntrySize;
955 }
956
957 static const int kTableLengthSize = kIntSize;
958 static const int kAstIdOffset = 0 * kIntSize;
959 static const int kPcOffsetOffset = 1 * kIntSize;
960 static const int kLoopDepthOffset = 2 * kIntSize;
961 static const int kEntrySize = 3 * kIntSize;
962
963 Address start_;
964 Address instruction_start_;
965 uint32_t length_;
966 };
967
968
943 } } // namespace v8::internal 969 } } // namespace v8::internal
944 970
945 #endif // V8_FULL_CODEGEN_H_ 971 #endif // V8_FULL_CODEGEN_H_
OLDNEW
« no previous file with comments | « src/deoptimizer.cc ('k') | src/full-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698