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

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

Issue 70183010: Fixes a couple problems with GC of unoptimized code. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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 | « runtime/vm/deopt_instructions.h ('k') | runtime/vm/flow_graph.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 (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, 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/deopt_instructions.h" 5 #include "vm/deopt_instructions.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/code_patcher.h" 8 #include "vm/code_patcher.h"
9 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
10 #include "vm/locations.h" 10 #include "vm/locations.h"
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
559 } 559 }
560 560
561 virtual DeoptInstr::Kind kind() const { return kRetAddress; } 561 virtual DeoptInstr::Kind kind() const { return kRetAddress; }
562 562
563 virtual const char* ToCString() const { 563 virtual const char* ToCString() const {
564 return Isolate::Current()->current_zone()->PrintToString( 564 return Isolate::Current()->current_zone()->PrintToString(
565 "ret oti:%" Pd "(%" Pd ")", object_table_index_, deopt_id_); 565 "ret oti:%" Pd "(%" Pd ")", object_table_index_, deopt_id_);
566 } 566 }
567 567
568 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) { 568 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) {
569 Function& function = Function::Handle(deopt_context->isolate()); 569 Code& code = Code::Handle(deopt_context->isolate());
570 function ^= deopt_context->ObjectAt(object_table_index_); 570 code ^= deopt_context->ObjectAt(object_table_index_);
571 const Code& code =
572 Code::Handle(deopt_context->isolate(), function.unoptimized_code());
573 ASSERT(!code.IsNull()); 571 ASSERT(!code.IsNull());
574 uword continue_at_pc = code.GetPcForDeoptId(deopt_id_, 572 uword continue_at_pc = code.GetPcForDeoptId(deopt_id_,
575 PcDescriptors::kDeopt); 573 PcDescriptors::kDeopt);
576 ASSERT(continue_at_pc != 0); 574 ASSERT(continue_at_pc != 0);
577 *dest_addr = continue_at_pc; 575 *dest_addr = continue_at_pc;
578 576
579 uword pc = code.GetPcForDeoptId(deopt_id_, PcDescriptors::kIcCall); 577 uword pc = code.GetPcForDeoptId(deopt_id_, PcDescriptors::kIcCall);
580 if (pc != 0) { 578 if (pc != 0) {
581 // If the deoptimization happened at an IC call, update the IC data 579 // If the deoptimization happened at an IC call, update the IC data
582 // to avoid repeated deoptimization at the same site next time around. 580 // to avoid repeated deoptimization at the same site next time around.
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 780
783 virtual intptr_t source_index() const { return object_table_index_; } 781 virtual intptr_t source_index() const { return object_table_index_; }
784 virtual DeoptInstr::Kind kind() const { return kPcMarker; } 782 virtual DeoptInstr::Kind kind() const { return kPcMarker; }
785 783
786 virtual const char* ToCString() const { 784 virtual const char* ToCString() const {
787 return Isolate::Current()->current_zone()->PrintToString( 785 return Isolate::Current()->current_zone()->PrintToString(
788 "pcmark oti:%" Pd "", object_table_index_); 786 "pcmark oti:%" Pd "", object_table_index_);
789 } 787 }
790 788
791 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) { 789 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) {
792 Function& function = Function::Handle(deopt_context->isolate()); 790 Code& code = Code::Handle(deopt_context->isolate());
793 function ^= deopt_context->ObjectAt(object_table_index_); 791 code ^= deopt_context->ObjectAt(object_table_index_);
794 if (function.IsNull()) { 792 if (code.IsNull()) {
795 // Callee's PC marker is not used (pc of Deoptimize stub). Set to 0. 793 // Callee's PC marker is not used (pc of Deoptimize stub). Set to 0.
796 *dest_addr = 0; 794 *dest_addr = 0;
797 return; 795 return;
798 } 796 }
799 const Code& code = 797 const Function& function =
800 Code::Handle(deopt_context->isolate(), function.unoptimized_code()); 798 Function::Handle(deopt_context->isolate(), code.function());
801 ASSERT(!code.IsNull()); 799 ASSERT(function.HasCode());
802 const intptr_t pc_marker = 800 const intptr_t pc_marker =
803 code.EntryPoint() + Assembler::kEntryPointToPcMarkerOffset; 801 code.EntryPoint() + Assembler::kEntryPointToPcMarkerOffset;
804 *dest_addr = pc_marker; 802 *dest_addr = pc_marker;
805 // Increment the deoptimization counter. This effectively increments each 803 // Increment the deoptimization counter. This effectively increments each
806 // function occurring in the optimized frame. 804 // function occurring in the optimized frame.
807 function.set_deoptimization_counter(function.deoptimization_counter() + 1); 805 function.set_deoptimization_counter(function.deoptimization_counter() + 1);
808 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) { 806 if (FLAG_trace_deoptimization || FLAG_trace_deoptimization_verbose) {
809 OS::PrintErr("Deoptimizing %s (count %d)\n", 807 OS::PrintErr("Deoptimizing %s (count %d)\n",
810 function.ToFullyQualifiedCString(), 808 function.ToFullyQualifiedCString(),
811 function.deoptimization_counter()); 809 function.deoptimization_counter());
812 } 810 }
813 // Clear invocation counter so that hopefully the function gets reoptimized 811 // Clear invocation counter so that hopefully the function gets reoptimized
814 // only after more feedback has been collected. 812 // only after more feedback has been collected.
815 function.set_usage_counter(0); 813 function.set_usage_counter(0);
816 if (function.HasOptimizedCode()) function.SwitchToUnoptimizedCode(); 814 if (function.HasOptimizedCode()) {
815 function.SwitchToUnoptimizedCode();
816 }
817 } 817 }
818 818
819 private: 819 private:
820 intptr_t object_table_index_; 820 intptr_t object_table_index_;
821 821
822 DISALLOW_COPY_AND_ASSIGN(DeoptPcMarkerInstr); 822 DISALLOW_COPY_AND_ASSIGN(DeoptPcMarkerInstr);
823 }; 823 };
824 824
825 825
826 // Deoptimization instruction creating a pool pointer for the code of 826 // Deoptimization instruction creating a pool pointer for the code of
827 // function at 'object_table_index'. 827 // function at 'object_table_index'.
828 class DeoptPpInstr : public DeoptInstr { 828 class DeoptPpInstr : public DeoptInstr {
829 public: 829 public:
830 explicit DeoptPpInstr(intptr_t object_table_index) 830 explicit DeoptPpInstr(intptr_t object_table_index)
831 : object_table_index_(object_table_index) { 831 : object_table_index_(object_table_index) {
832 ASSERT(object_table_index >= 0); 832 ASSERT(object_table_index >= 0);
833 } 833 }
834 834
835 virtual intptr_t source_index() const { return object_table_index_; } 835 virtual intptr_t source_index() const { return object_table_index_; }
836 virtual DeoptInstr::Kind kind() const { return kPp; } 836 virtual DeoptInstr::Kind kind() const { return kPp; }
837 837
838 virtual const char* ToCString() const { 838 virtual const char* ToCString() const {
839 return Isolate::Current()->current_zone()->PrintToString( 839 return Isolate::Current()->current_zone()->PrintToString(
840 "pp oti:%" Pd "", object_table_index_); 840 "pp oti:%" Pd "", object_table_index_);
841 } 841 }
842 842
843 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) { 843 void Execute(DeoptContext* deopt_context, intptr_t* dest_addr) {
844 Function& function = Function::Handle(deopt_context->isolate()); 844 Code& code = Code::Handle(deopt_context->isolate());
845 function ^= deopt_context->ObjectAt(object_table_index_); 845 code ^= deopt_context->ObjectAt(object_table_index_);
846 const Code& code =
847 Code::Handle(deopt_context->isolate(), function.unoptimized_code());
848 ASSERT(!code.IsNull()); 846 ASSERT(!code.IsNull());
849 const intptr_t pp = reinterpret_cast<intptr_t>(code.ObjectPool()); 847 const intptr_t pp = reinterpret_cast<intptr_t>(code.ObjectPool());
850 *dest_addr = pp; 848 *dest_addr = pp;
851 } 849 }
852 850
853 private: 851 private:
854 intptr_t object_table_index_; 852 intptr_t object_table_index_;
855 853
856 DISALLOW_COPY_AND_ASSIGN(DeoptPpInstr); 854 DISALLOW_COPY_AND_ASSIGN(DeoptPpInstr);
857 }; 855 };
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
1044 const Array& object_table, 1042 const Array& object_table,
1045 Function* func) { 1043 Function* func) {
1046 ASSERT(instr->kind() == kRetAddress); 1044 ASSERT(instr->kind() == kRetAddress);
1047 DeoptRetAddressInstr* ret_address_instr = 1045 DeoptRetAddressInstr* ret_address_instr =
1048 static_cast<DeoptRetAddressInstr*>(instr); 1046 static_cast<DeoptRetAddressInstr*>(instr);
1049 // The following assert may trigger when displaying a backtrace 1047 // The following assert may trigger when displaying a backtrace
1050 // from the simulator. 1048 // from the simulator.
1051 ASSERT(Isolate::IsDeoptAfter(ret_address_instr->deopt_id())); 1049 ASSERT(Isolate::IsDeoptAfter(ret_address_instr->deopt_id()));
1052 ASSERT(!object_table.IsNull()); 1050 ASSERT(!object_table.IsNull());
1053 ASSERT(func != NULL); 1051 ASSERT(func != NULL);
1054 *func ^= object_table.At(ret_address_instr->object_table_index()); 1052 Code& code = Code::Handle();
1055 const Code& code = Code::Handle(func->unoptimized_code()); 1053 code ^= object_table.At(ret_address_instr->object_table_index());
1056 ASSERT(!code.IsNull()); 1054 ASSERT(!code.IsNull());
1055 *func ^= code.function();
1057 uword res = code.GetPcForDeoptId(ret_address_instr->deopt_id(), 1056 uword res = code.GetPcForDeoptId(ret_address_instr->deopt_id(),
1058 PcDescriptors::kDeopt); 1057 PcDescriptors::kDeopt);
1059 ASSERT(res != 0); 1058 ASSERT(res != 0);
1060 return res; 1059 return res;
1061 } 1060 }
1062 1061
1063 1062
1064 DeoptInstr* DeoptInstr::Create(intptr_t kind_as_int, intptr_t source_index) { 1063 DeoptInstr* DeoptInstr::Create(intptr_t kind_as_int, intptr_t source_index) {
1065 Kind kind = static_cast<Kind>(kind_as_int); 1064 Kind kind = static_cast<Kind>(kind_as_int);
1066 switch (kind) { 1065 switch (kind) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1154 1153
1155 1154
1156 intptr_t DeoptInfoBuilder::CalculateStackIndex( 1155 intptr_t DeoptInfoBuilder::CalculateStackIndex(
1157 const Location& source_loc) const { 1156 const Location& source_loc) const {
1158 return source_loc.stack_index() < 0 ? 1157 return source_loc.stack_index() < 0 ?
1159 source_loc.stack_index() + num_args_ : 1158 source_loc.stack_index() + num_args_ :
1160 source_loc.stack_index() + num_args_ + kDartFrameFixedSize; 1159 source_loc.stack_index() + num_args_ + kDartFrameFixedSize;
1161 } 1160 }
1162 1161
1163 1162
1164 void DeoptInfoBuilder::AddReturnAddress(const Function& function, 1163 void DeoptInfoBuilder::AddReturnAddress(const Code& code,
1165 intptr_t deopt_id, 1164 intptr_t deopt_id,
1166 intptr_t dest_index) { 1165 intptr_t dest_index) {
1167 // Check that deopt_id exists. 1166 // Check that deopt_id exists.
1168 // TODO(vegorov): verify after deoptimization targets as well. 1167 // TODO(vegorov): verify after deoptimization targets as well.
1169 #ifdef DEBUG 1168 #ifdef DEBUG
1170 const Code& code = Code::Handle(function.unoptimized_code()); 1169 ASSERT(Isolate::IsDeoptAfter(deopt_id) ||
1171 // The inlined function's code pointer may be null if there is a GC during 1170 (code.GetPcForDeoptId(deopt_id, PcDescriptors::kDeopt) != 0));
1172 // compilation.
1173 // TODO(zra): See if we can avoid this check by ensuring that code is not
1174 // removed during inlining.
1175 ASSERT(code.IsNull() || Isolate::IsDeoptAfter(deopt_id) ||
1176 (code.GetPcForDeoptId(deopt_id, PcDescriptors::kDeopt) != 0));
1177 #endif 1171 #endif
1178 const intptr_t object_table_index = FindOrAddObjectInTable(function); 1172 const intptr_t object_table_index = FindOrAddObjectInTable(code);
1179 ASSERT(dest_index == FrameSize()); 1173 ASSERT(dest_index == FrameSize());
1180 instructions_.Add(new DeoptRetAddressInstr(object_table_index, deopt_id)); 1174 instructions_.Add(new DeoptRetAddressInstr(object_table_index, deopt_id));
1181 } 1175 }
1182 1176
1183 1177
1184 void DeoptInfoBuilder::AddPcMarker(const Function& function, 1178 void DeoptInfoBuilder::AddPcMarker(const Code& code,
1185 intptr_t dest_index) { 1179 intptr_t dest_index) {
1186 intptr_t object_table_index = FindOrAddObjectInTable(function); 1180 intptr_t object_table_index = FindOrAddObjectInTable(code);
1187 ASSERT(dest_index == FrameSize()); 1181 ASSERT(dest_index == FrameSize());
1188 instructions_.Add(new DeoptPcMarkerInstr(object_table_index)); 1182 instructions_.Add(new DeoptPcMarkerInstr(object_table_index));
1189 } 1183 }
1190 1184
1191 1185
1192 void DeoptInfoBuilder::AddPp(const Function& function, intptr_t dest_index) { 1186 void DeoptInfoBuilder::AddPp(const Code& code,
1193 intptr_t object_table_index = FindOrAddObjectInTable(function); 1187 intptr_t dest_index) {
1188 intptr_t object_table_index = FindOrAddObjectInTable(code);
1194 ASSERT(dest_index == FrameSize()); 1189 ASSERT(dest_index == FrameSize());
1195 instructions_.Add(new DeoptPpInstr(object_table_index)); 1190 instructions_.Add(new DeoptPpInstr(object_table_index));
1196 } 1191 }
1197 1192
1198 1193
1199 void DeoptInfoBuilder::AddCopy(Value* value, 1194 void DeoptInfoBuilder::AddCopy(Value* value,
1200 const Location& source_loc, 1195 const Location& source_loc,
1201 const intptr_t dest_index) { 1196 const intptr_t dest_index) {
1202 DeoptInstr* deopt_instr = NULL; 1197 DeoptInstr* deopt_instr = NULL;
1203 if (source_loc.IsConstant()) { 1198 if (source_loc.IsConstant()) {
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
1411 Smi* offset, 1406 Smi* offset,
1412 DeoptInfo* info, 1407 DeoptInfo* info,
1413 Smi* reason) { 1408 Smi* reason) {
1414 intptr_t i = index * kEntrySize; 1409 intptr_t i = index * kEntrySize;
1415 *offset ^= table.At(i); 1410 *offset ^= table.At(i);
1416 *info ^= table.At(i + 1); 1411 *info ^= table.At(i + 1);
1417 *reason ^= table.At(i + 2); 1412 *reason ^= table.At(i + 2);
1418 } 1413 }
1419 1414
1420 } // namespace dart 1415 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/deopt_instructions.h ('k') | runtime/vm/flow_graph.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698