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

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

Issue 2809583002: Use off-heap data for type feedback in PolymorphicInstanceCallInstr (Closed)
Patch Set: Created 3 years, 8 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
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | 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) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, 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/weak_code.h" 5 #include "vm/weak_code.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 8
9 #include "vm/code_generator.h" 9 #include "vm/code_generator.h"
10 #include "vm/code_patcher.h" 10 #include "vm/code_patcher.h"
11 #include "vm/object.h" 11 #include "vm/object.h"
12 #include "vm/stack_frame.h" 12 #include "vm/stack_frame.h"
13 13
14 namespace dart { 14 namespace dart {
15 15
16 bool WeakCodeReferences::HasCodes() const { 16 bool WeakCodeReferences::HasCodes() const {
17 return !array_.IsNull() && (array_.Length() > 0); 17 return !array_.IsNull() && (array_.Length() > 0);
18 } 18 }
19 19
20 20
21 void WeakCodeReferences::Register(const Code& value) { 21 void WeakCodeReferences::Register(const Code& value) {
22 if (!array_.IsNull()) { 22 if (!array_.IsNull()) {
23 // Try to find and reuse cleared WeakProperty to avoid allocating new one. 23 // Try to find and reuse cleared WeakProperty to avoid allocating new one.
Vyacheslav Egorov (Google) 2017/04/10 10:59:28 You need to amend the comment because the code bel
erikcorry 2017/04/19 15:06:41 Moved to different CL
24 WeakProperty& weak_property = WeakProperty::Handle(); 24 WeakProperty& weak_property = WeakProperty::Handle();
25 for (intptr_t i = 0; i < array_.Length(); i++) { 25 for (intptr_t i = array_.Length() - 1; i >= 0; i--) {
26 weak_property ^= array_.At(i); 26 weak_property ^= array_.At(i);
27 if (weak_property.raw() == WeakProperty::null()) {
28 weak_property ^= WeakProperty::New(Heap::kOld);
29 array_.SetAt(i, weak_property);
30 }
27 if (weak_property.key() == Code::null()) { 31 if (weak_property.key() == Code::null()) {
28 // Empty property found. Reuse it. 32 // Empty property found. Reuse it.
29 weak_property.set_key(value); 33 weak_property.set_key(value);
30 return; 34 return;
31 } 35 }
32 } 36 }
33 } 37 }
34 38
35 const WeakProperty& weak_property = 39 const WeakProperty& weak_property =
36 WeakProperty::Handle(WeakProperty::New(Heap::kOld)); 40 WeakProperty::Handle(WeakProperty::New(Heap::kOld));
37 weak_property.set_key(value); 41 weak_property.set_key(value);
38 42
39 intptr_t length = array_.IsNull() ? 0 : array_.Length(); 43 intptr_t length = array_.IsNull() ? 0 : array_.Length();
40 const Array& new_array = 44 const Array& new_array = Array::Handle(
41 Array::Handle(Array::Grow(array_, length + 1, Heap::kOld)); 45 Array::Grow(array_, length + 1 + (length >> 2), Heap::kOld));
42 new_array.SetAt(length, weak_property); 46 new_array.SetAt(length, weak_property);
43 UpdateArrayTo(new_array); 47 UpdateArrayTo(new_array);
44 } 48 }
45 49
46 50
47 bool WeakCodeReferences::IsOptimizedCode(const Array& dependent_code, 51 bool WeakCodeReferences::IsOptimizedCode(const Array& dependent_code,
48 const Code& code) { 52 const Code& code) {
49 if (!code.is_optimized()) { 53 if (!code.is_optimized()) {
50 return false; 54 return false;
51 } 55 }
52 WeakProperty& weak_property = WeakProperty::Handle(); 56 WeakProperty& weak_property = WeakProperty::Handle();
53 for (intptr_t i = 0; i < dependent_code.Length(); i++) { 57 for (intptr_t i = 0; i < dependent_code.Length(); i++) {
54 weak_property ^= dependent_code.At(i); 58 weak_property ^= dependent_code.At(i);
55 if (code.raw() == weak_property.key()) { 59 if (weak_property.raw() != WeakProperty::null() &&
60 code.raw() == weak_property.key()) {
56 return true; 61 return true;
57 } 62 }
58 } 63 }
59 return false; 64 return false;
60 } 65 }
61 66
62 67
63 void WeakCodeReferences::DisableCode() { 68 void WeakCodeReferences::DisableCode() {
64 const Array& code_objects = Array::Handle(array_.raw()); 69 const Array& code_objects = Array::Handle(array_.raw());
65 if (code_objects.IsNull()) { 70 if (code_objects.IsNull()) {
(...skipping 15 matching lines...) Expand all
81 frame = iterator.NextFrame(); 86 frame = iterator.NextFrame();
82 } 87 }
83 } 88 }
84 89
85 // Switch functions that use dependent code to unoptimized code. 90 // Switch functions that use dependent code to unoptimized code.
86 WeakProperty& weak_property = WeakProperty::Handle(); 91 WeakProperty& weak_property = WeakProperty::Handle();
87 Object& owner = Object::Handle(); 92 Object& owner = Object::Handle();
88 Function& function = Function::Handle(); 93 Function& function = Function::Handle();
89 for (intptr_t i = 0; i < code_objects.Length(); i++) { 94 for (intptr_t i = 0; i < code_objects.Length(); i++) {
90 weak_property ^= code_objects.At(i); 95 weak_property ^= code_objects.At(i);
96 if (weak_property.raw() == WeakProperty::null()) {
97 continue;
98 }
91 code ^= weak_property.key(); 99 code ^= weak_property.key();
92 if (code.IsNull()) { 100 if (code.IsNull()) {
93 // Code was garbage collected already. 101 // Code was garbage collected already.
94 continue; 102 continue;
95 } 103 }
96 owner = code.owner(); 104 owner = code.owner();
97 if (owner.IsFunction()) { 105 if (owner.IsFunction()) {
98 function ^= owner.raw(); 106 function ^= owner.raw();
99 } else if (owner.IsClass()) { 107 } else if (owner.IsClass()) {
100 Class& cls = Class::Handle(); 108 Class& cls = Class::Handle();
(...skipping 25 matching lines...) Expand all
126 // Make non-OSR code non-entrant. 134 // Make non-OSR code non-entrant.
127 if (!code.IsDisabled()) { 135 if (!code.IsDisabled()) {
128 ReportSwitchingCode(code); 136 ReportSwitchingCode(code);
129 code.DisableDartCode(); 137 code.DisableDartCode();
130 } 138 }
131 } 139 }
132 } 140 }
133 } 141 }
134 142
135 } // namespace dart 143 } // namespace dart
OLDNEW
« runtime/vm/object.cc ('K') | « runtime/vm/object.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698