OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 904 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 Builtins* builtins = isolate_->builtins(); | 915 Builtins* builtins = isolate_->builtins(); |
916 Code* adaptor_trampoline = | 916 Code* adaptor_trampoline = |
917 builtins->builtin(Builtins::kArgumentsAdaptorTrampoline); | 917 builtins->builtin(Builtins::kArgumentsAdaptorTrampoline); |
918 intptr_t pc_value = reinterpret_cast<intptr_t>( | 918 intptr_t pc_value = reinterpret_cast<intptr_t>( |
919 adaptor_trampoline->instruction_start() + | 919 adaptor_trampoline->instruction_start() + |
920 isolate_->heap()->arguments_adaptor_deopt_pc_offset()->value()); | 920 isolate_->heap()->arguments_adaptor_deopt_pc_offset()->value()); |
921 output_frame->SetPc(pc_value); | 921 output_frame->SetPc(pc_value); |
922 } | 922 } |
923 | 923 |
924 | 924 |
| 925 void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, |
| 926 int frame_index) { |
| 927 Builtins* builtins = isolate_->builtins(); |
| 928 Code* construct_stub = builtins->builtin(Builtins::kJSConstructStubGeneric); |
| 929 JSFunction* function = JSFunction::cast(ComputeLiteral(iterator->Next())); |
| 930 unsigned height = iterator->Next(); |
| 931 unsigned height_in_bytes = height * kPointerSize; |
| 932 if (trace_) { |
| 933 PrintF(" translating construct stub => height=%d\n", height_in_bytes); |
| 934 } |
| 935 |
| 936 unsigned fixed_frame_size = ConstructFrameConstants::kFrameSize; |
| 937 unsigned output_frame_size = height_in_bytes + fixed_frame_size; |
| 938 |
| 939 // Allocate and store the output frame description. |
| 940 FrameDescription* output_frame = |
| 941 new(output_frame_size) FrameDescription(output_frame_size, function); |
| 942 output_frame->SetFrameType(StackFrame::CONSTRUCT); |
| 943 |
| 944 // Construct stub can not be topmost or bottommost. |
| 945 ASSERT(frame_index > 0 && frame_index < output_count_ - 1); |
| 946 ASSERT(output_[frame_index] == NULL); |
| 947 output_[frame_index] = output_frame; |
| 948 |
| 949 // The top address of the frame is computed from the previous |
| 950 // frame's top and this frame's size. |
| 951 intptr_t top_address; |
| 952 top_address = output_[frame_index - 1]->GetTop() - output_frame_size; |
| 953 output_frame->SetTop(top_address); |
| 954 |
| 955 // Compute the incoming parameter translation. |
| 956 int parameter_count = height; |
| 957 unsigned output_offset = output_frame_size; |
| 958 for (int i = 0; i < parameter_count; ++i) { |
| 959 output_offset -= kPointerSize; |
| 960 DoTranslateCommand(iterator, frame_index, output_offset); |
| 961 } |
| 962 |
| 963 // Read caller's PC from the previous frame. |
| 964 output_offset -= kPointerSize; |
| 965 intptr_t callers_pc = output_[frame_index - 1]->GetPc(); |
| 966 output_frame->SetFrameSlot(output_offset, callers_pc); |
| 967 if (trace_) { |
| 968 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 969 V8PRIxPTR " ; caller's pc\n", |
| 970 top_address + output_offset, output_offset, callers_pc); |
| 971 } |
| 972 |
| 973 // Read caller's FP from the previous frame, and set this frame's FP. |
| 974 output_offset -= kPointerSize; |
| 975 intptr_t value = output_[frame_index - 1]->GetFp(); |
| 976 output_frame->SetFrameSlot(output_offset, value); |
| 977 intptr_t fp_value = top_address + output_offset; |
| 978 output_frame->SetFp(fp_value); |
| 979 if (trace_) { |
| 980 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 981 V8PRIxPTR " ; caller's fp\n", |
| 982 fp_value, output_offset, value); |
| 983 } |
| 984 |
| 985 // The context can be gotten from the previous frame. |
| 986 output_offset -= kPointerSize; |
| 987 value = output_[frame_index - 1]->GetContext(); |
| 988 output_frame->SetFrameSlot(output_offset, value); |
| 989 if (trace_) { |
| 990 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 991 V8PRIxPTR " ; context\n", |
| 992 top_address + output_offset, output_offset, value); |
| 993 } |
| 994 |
| 995 // A marker value is used in place of the function. |
| 996 output_offset -= kPointerSize; |
| 997 value = reinterpret_cast<intptr_t>(Smi::FromInt(StackFrame::CONSTRUCT)); |
| 998 output_frame->SetFrameSlot(output_offset, value); |
| 999 if (trace_) { |
| 1000 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1001 V8PRIxPTR " ; function (construct sentinel)\n", |
| 1002 top_address + output_offset, output_offset, value); |
| 1003 } |
| 1004 |
| 1005 // The output frame reflects a JSConstructStubGeneric frame. |
| 1006 output_offset -= kPointerSize; |
| 1007 value = reinterpret_cast<intptr_t>(construct_stub); |
| 1008 output_frame->SetFrameSlot(output_offset, value); |
| 1009 if (trace_) { |
| 1010 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1011 V8PRIxPTR " ; code object\n", |
| 1012 top_address + output_offset, output_offset, value); |
| 1013 } |
| 1014 |
| 1015 // Number of incoming arguments. |
| 1016 output_offset -= kPointerSize; |
| 1017 value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1)); |
| 1018 output_frame->SetFrameSlot(output_offset, value); |
| 1019 if (trace_) { |
| 1020 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1021 V8PRIxPTR " ; argc (%d)\n", |
| 1022 top_address + output_offset, output_offset, value, height - 1); |
| 1023 } |
| 1024 |
| 1025 // Constructor function being invoked by the stub (only present on some |
| 1026 // architectures, indicated by kConstructorOffset). |
| 1027 if (ConstructFrameConstants::kConstructorOffset != kMinInt) { |
| 1028 output_offset -= kPointerSize; |
| 1029 value = reinterpret_cast<intptr_t>(function); |
| 1030 output_frame->SetFrameSlot(output_offset, value); |
| 1031 if (trace_) { |
| 1032 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1033 V8PRIxPTR " ; constructor function\n", |
| 1034 top_address + output_offset, output_offset, value); |
| 1035 } |
| 1036 } |
| 1037 |
| 1038 // The newly allocated object was passed as receiver in the artificial |
| 1039 // constructor stub environment created by HEnvironment::CopyForInlining(). |
| 1040 output_offset -= kPointerSize; |
| 1041 value = output_frame->GetFrameSlot(output_frame_size - kPointerSize); |
| 1042 output_frame->SetFrameSlot(output_offset, value); |
| 1043 if (trace_) { |
| 1044 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1045 V8PRIxPTR " ; allocated receiver\n", |
| 1046 top_address + output_offset, output_offset, value); |
| 1047 } |
| 1048 |
| 1049 ASSERT(0 == output_offset); |
| 1050 |
| 1051 intptr_t pc = reinterpret_cast<intptr_t>( |
| 1052 construct_stub->instruction_start() + |
| 1053 isolate_->heap()->construct_stub_deopt_pc_offset()->value()); |
| 1054 output_frame->SetPc(pc); |
| 1055 } |
| 1056 |
| 1057 |
925 void Deoptimizer::DoComputeAccessorStubFrame(TranslationIterator* iterator, | 1058 void Deoptimizer::DoComputeAccessorStubFrame(TranslationIterator* iterator, |
926 int frame_index, | 1059 int frame_index, |
927 bool is_setter_stub_frame) { | 1060 bool is_setter_stub_frame) { |
928 JSFunction* accessor = JSFunction::cast(ComputeLiteral(iterator->Next())); | 1061 JSFunction* accessor = JSFunction::cast(ComputeLiteral(iterator->Next())); |
929 // The receiver (and the implicit return value, if any) are expected in | 1062 // The receiver (and the implicit return value, if any) are expected in |
930 // registers by the LoadIC/StoreIC, so they don't belong to the output stack | 1063 // registers by the LoadIC/StoreIC, so they don't belong to the output stack |
931 // frame. This means that we have to use a height of 0. | 1064 // frame. This means that we have to use a height of 0. |
932 unsigned height = 0; | 1065 unsigned height = 0; |
933 unsigned height_in_bytes = height * kPointerSize; | 1066 unsigned height_in_bytes = height * kPointerSize; |
934 const char* kind = is_setter_stub_frame ? "setter" : "getter"; | 1067 const char* kind = is_setter_stub_frame ? "setter" : "getter"; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1034 | 1167 |
1035 Smi* offset = is_setter_stub_frame ? | 1168 Smi* offset = is_setter_stub_frame ? |
1036 isolate_->heap()->setter_stub_deopt_pc_offset() : | 1169 isolate_->heap()->setter_stub_deopt_pc_offset() : |
1037 isolate_->heap()->getter_stub_deopt_pc_offset(); | 1170 isolate_->heap()->getter_stub_deopt_pc_offset(); |
1038 intptr_t pc = reinterpret_cast<intptr_t>( | 1171 intptr_t pc = reinterpret_cast<intptr_t>( |
1039 accessor_stub->instruction_start() + offset->value()); | 1172 accessor_stub->instruction_start() + offset->value()); |
1040 output_frame->SetPc(pc); | 1173 output_frame->SetPc(pc); |
1041 } | 1174 } |
1042 | 1175 |
1043 | 1176 |
| 1177 void Deoptimizer::DoComputeCompiledStubFrame(TranslationIterator* iterator, |
| 1178 int frame_index) { |
| 1179 // |
| 1180 // FROM TO |
| 1181 // | .... | | .... | |
| 1182 // +-------------------------+ +-------------------------+ |
| 1183 // | JSFunction continuation | | JSFunction continuation | |
| 1184 // +-------------------------+ +-------------------------+ |
| 1185 // | | saved frame (FP) | | saved frame (FP) | |
| 1186 // | +=========================+<-fpreg +=========================+<-fpreg |
| 1187 // | | JSFunction context | | JSFunction context | |
| 1188 // v +-------------------------+ +-------------------------| |
| 1189 // | COMPILED_STUB marker | | STUB_FAILURE marker | |
| 1190 // +-------------------------+ +-------------------------+ |
| 1191 // | | | caller args.arguments_ | |
| 1192 // | ... | +-------------------------+ |
| 1193 // | | | caller args.length_ | |
| 1194 // |-------------------------|<-spreg +-------------------------+ |
| 1195 // | caller args pointer | |
| 1196 // +-------------------------+ |
| 1197 // | caller stack param 1 | |
| 1198 // parameters in registers +-------------------------+ |
| 1199 // and spilled to stack | .... | |
| 1200 // +-------------------------+ |
| 1201 // | caller stack param n | |
| 1202 // +-------------------------+<-spreg |
| 1203 // reg = number of parameters |
| 1204 // reg = failure handler address |
| 1205 // reg = saved frame |
| 1206 // reg = JSFunction context |
| 1207 // |
| 1208 |
| 1209 ASSERT(compiled_code_->kind() == Code::COMPILED_STUB); |
| 1210 int major_key = compiled_code_->major_key(); |
| 1211 CodeStubInterfaceDescriptor* descriptor = |
| 1212 isolate_->code_stub_interface_descriptor(major_key); |
| 1213 |
| 1214 // The output frame must have room for all pushed register parameters |
| 1215 // and the standard stack frame slots. Include space for an argument |
| 1216 // object to the callee and optionally the space to pass the argument |
| 1217 // object to the stub failure handler. |
| 1218 int height_in_bytes = kPointerSize * descriptor->register_param_count_ + |
| 1219 sizeof(Arguments) + kPointerSize; |
| 1220 int fixed_frame_size = StandardFrameConstants::kFixedFrameSize; |
| 1221 int input_frame_size = input_->GetFrameSize(); |
| 1222 int output_frame_size = height_in_bytes + fixed_frame_size; |
| 1223 if (trace_) { |
| 1224 PrintF(" translating %s => StubFailureTrampolineStub, height=%d\n", |
| 1225 CodeStub::MajorName(static_cast<CodeStub::Major>(major_key), false), |
| 1226 height_in_bytes); |
| 1227 } |
| 1228 |
| 1229 // The stub failure trampoline is a single frame. |
| 1230 FrameDescription* output_frame = |
| 1231 new(output_frame_size) FrameDescription(output_frame_size, NULL); |
| 1232 output_frame->SetFrameType(StackFrame::STUB_FAILURE_TRAMPOLINE); |
| 1233 ASSERT(frame_index == 0); |
| 1234 output_[frame_index] = output_frame; |
| 1235 |
| 1236 // The top address for the output frame can be computed from the input |
| 1237 // frame pointer and the output frame's height. Subtract space for the |
| 1238 // context and function slots. |
| 1239 Register fp_reg = StubFailureTrampolineFrame::fp_register(); |
| 1240 intptr_t top_address = input_->GetRegister(fp_reg.code()) - |
| 1241 (2 * kPointerSize) - height_in_bytes; |
| 1242 output_frame->SetTop(top_address); |
| 1243 |
| 1244 // Read caller's PC (JSFunction continuation) from the input frame. |
| 1245 unsigned input_frame_offset = input_frame_size - kPointerSize; |
| 1246 unsigned output_frame_offset = output_frame_size - kPointerSize; |
| 1247 intptr_t value = input_->GetFrameSlot(input_frame_offset); |
| 1248 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1249 if (trace_) { |
| 1250 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1251 V8PRIxPTR " ; caller's pc\n", |
| 1252 top_address + output_frame_offset, output_frame_offset, value); |
| 1253 } |
| 1254 |
| 1255 // Read caller's FP from the input frame, and set this frame's FP. |
| 1256 input_frame_offset -= kPointerSize; |
| 1257 value = input_->GetFrameSlot(input_frame_offset); |
| 1258 output_frame_offset -= kPointerSize; |
| 1259 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1260 intptr_t frame_ptr = input_->GetRegister(fp_reg.code()); |
| 1261 output_frame->SetRegister(fp_reg.code(), frame_ptr); |
| 1262 output_frame->SetFp(frame_ptr); |
| 1263 if (trace_) { |
| 1264 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1265 V8PRIxPTR " ; caller's fp\n", |
| 1266 top_address + output_frame_offset, output_frame_offset, value); |
| 1267 } |
| 1268 |
| 1269 // The context can be gotten from the input frame. |
| 1270 Register context_reg = StubFailureTrampolineFrame::context_register(); |
| 1271 input_frame_offset -= kPointerSize; |
| 1272 value = input_->GetFrameSlot(input_frame_offset); |
| 1273 output_frame->SetRegister(context_reg.code(), value); |
| 1274 output_frame_offset -= kPointerSize; |
| 1275 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1276 if (trace_) { |
| 1277 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1278 V8PRIxPTR " ; context\n", |
| 1279 top_address + output_frame_offset, output_frame_offset, value); |
| 1280 } |
| 1281 |
| 1282 // A marker value is used in place of the function. |
| 1283 output_frame_offset -= kPointerSize; |
| 1284 value = reinterpret_cast<intptr_t>( |
| 1285 Smi::FromInt(StackFrame::STUB_FAILURE_TRAMPOLINE)); |
| 1286 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1287 if (trace_) { |
| 1288 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1289 V8PRIxPTR " ; function (stub failure sentinel)\n", |
| 1290 top_address + output_frame_offset, output_frame_offset, value); |
| 1291 } |
| 1292 |
| 1293 intptr_t caller_arg_count = 0; |
| 1294 if (descriptor->stack_parameter_count_ != NULL) { |
| 1295 caller_arg_count = |
| 1296 input_->GetRegister(descriptor->stack_parameter_count_->code()); |
| 1297 } |
| 1298 |
| 1299 // Build the Arguments object for the caller's parameters and a pointer to it. |
| 1300 output_frame_offset -= kPointerSize; |
| 1301 value = frame_ptr + StandardFrameConstants::kCallerSPOffset + |
| 1302 (caller_arg_count - 1) * kPointerSize; |
| 1303 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1304 if (trace_) { |
| 1305 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1306 V8PRIxPTR " ; args.arguments\n", |
| 1307 top_address + output_frame_offset, output_frame_offset, value); |
| 1308 } |
| 1309 |
| 1310 output_frame_offset -= kPointerSize; |
| 1311 value = caller_arg_count; |
| 1312 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1313 if (trace_) { |
| 1314 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1315 V8PRIxPTR " ; args.length\n", |
| 1316 top_address + output_frame_offset, output_frame_offset, value); |
| 1317 } |
| 1318 |
| 1319 output_frame_offset -= kPointerSize; |
| 1320 value = frame_ptr - (output_frame_size - output_frame_offset) - |
| 1321 StandardFrameConstants::kMarkerOffset + kPointerSize; |
| 1322 output_frame->SetFrameSlot(output_frame_offset, value); |
| 1323 if (trace_) { |
| 1324 PrintF(" 0x%08" V8PRIxPTR ": [top + %d] <- 0x%08" |
| 1325 V8PRIxPTR " ; args*\n", |
| 1326 top_address + output_frame_offset, output_frame_offset, value); |
| 1327 } |
| 1328 |
| 1329 // Copy the register parameters to the failure frame. |
| 1330 for (int i = 0; i < descriptor->register_param_count_; ++i) { |
| 1331 output_frame_offset -= kPointerSize; |
| 1332 DoTranslateCommand(iterator, 0, output_frame_offset); |
| 1333 } |
| 1334 |
| 1335 ASSERT(0 == output_frame_offset); |
| 1336 |
| 1337 // Copy the double registers from the input into the output frame. |
| 1338 CopyDoubleRegisters(output_frame); |
| 1339 |
| 1340 // Fill registers containing handler and number of parameters. |
| 1341 SetPlatformCompiledStubRegisters(output_frame, descriptor); |
| 1342 |
| 1343 // Compute this frame's PC, state, and continuation. |
| 1344 Code* trampoline = NULL; |
| 1345 int extra = descriptor->extra_expression_stack_count_; |
| 1346 StubFailureTrampolineStub(extra).FindCodeInCache(&trampoline, isolate_); |
| 1347 ASSERT(trampoline != NULL); |
| 1348 output_frame->SetPc(reinterpret_cast<intptr_t>( |
| 1349 trampoline->instruction_start())); |
| 1350 output_frame->SetState(Smi::FromInt(FullCodeGenerator::NO_REGISTERS)); |
| 1351 Code* notify_failure = |
| 1352 isolate_->builtins()->builtin(Builtins::kNotifyStubFailure); |
| 1353 output_frame->SetContinuation( |
| 1354 reinterpret_cast<intptr_t>(notify_failure->entry())); |
| 1355 } |
| 1356 |
| 1357 |
1044 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { | 1358 void Deoptimizer::MaterializeHeapObjects(JavaScriptFrameIterator* it) { |
1045 ASSERT_NE(DEBUGGER, bailout_type_); | 1359 ASSERT_NE(DEBUGGER, bailout_type_); |
1046 | 1360 |
1047 // Handlify all argument object values before triggering any allocation. | 1361 // Handlify all argument object values before triggering any allocation. |
1048 List<Handle<Object> > values(deferred_arguments_objects_values_.length()); | 1362 List<Handle<Object> > values(deferred_arguments_objects_values_.length()); |
1049 for (int i = 0; i < deferred_arguments_objects_values_.length(); ++i) { | 1363 for (int i = 0; i < deferred_arguments_objects_values_.length(); ++i) { |
1050 values.Add(Handle<Object>(deferred_arguments_objects_values_[i], | 1364 values.Add(Handle<Object>(deferred_arguments_objects_values_[i], |
1051 isolate_)); | 1365 isolate_)); |
1052 } | 1366 } |
1053 | 1367 |
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2366 | 2680 |
2367 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { | 2681 void DeoptimizedFrameInfo::Iterate(ObjectVisitor* v) { |
2368 v->VisitPointer(BitCast<Object**>(&function_)); | 2682 v->VisitPointer(BitCast<Object**>(&function_)); |
2369 v->VisitPointers(parameters_, parameters_ + parameters_count_); | 2683 v->VisitPointers(parameters_, parameters_ + parameters_count_); |
2370 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); | 2684 v->VisitPointers(expression_stack_, expression_stack_ + expression_count_); |
2371 } | 2685 } |
2372 | 2686 |
2373 #endif // ENABLE_DEBUGGER_SUPPORT | 2687 #endif // ENABLE_DEBUGGER_SUPPORT |
2374 | 2688 |
2375 } } // namespace v8::internal | 2689 } } // namespace v8::internal |
OLD | NEW |