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

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

Issue 1410443003: Eliminate unused function maps (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 2 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
« no previous file with comments | « no previous file | 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) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 2150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2161 return name.Hash(); 2161 return name.Hash();
2162 } 2162 }
2163 }; 2163 };
2164 typedef UnorderedHashSet<ClassFunctionsTraits> ClassFunctionsSet; 2164 typedef UnorderedHashSet<ClassFunctionsTraits> ClassFunctionsSet;
2165 2165
2166 2166
2167 void Class::SetFunctions(const Array& value) const { 2167 void Class::SetFunctions(const Array& value) const {
2168 ASSERT(!value.IsNull()); 2168 ASSERT(!value.IsNull());
2169 StorePointer(&raw_ptr()->functions_, value.raw()); 2169 StorePointer(&raw_ptr()->functions_, value.raw());
2170 const intptr_t len = value.Length(); 2170 const intptr_t len = value.Length();
2171 ClassFunctionsSet set(HashTables::New<ClassFunctionsSet>(len, Heap::kOld));
2172 if (len >= kFunctionLookupHashTreshold) { 2171 if (len >= kFunctionLookupHashTreshold) {
2172 ClassFunctionsSet set(HashTables::New<ClassFunctionsSet>(len, Heap::kOld));
2173 Function& func = Function::Handle(); 2173 Function& func = Function::Handle();
2174 for (intptr_t i = 0; i < len; ++i) { 2174 for (intptr_t i = 0; i < len; ++i) {
2175 func ^= value.At(i); 2175 func ^= value.At(i);
2176 // Verify that all the functions in the array have this class as owner. 2176 // Verify that all the functions in the array have this class as owner.
2177 ASSERT(func.Owner() == raw()); 2177 ASSERT(func.Owner() == raw());
2178 set.Insert(func); 2178 set.Insert(func);
2179 } 2179 }
2180 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw());
2180 } 2181 }
2181 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw());
2182 } 2182 }
2183 2183
2184 2184
2185 void Class::AddFunction(const Function& function) const { 2185 void Class::AddFunction(const Function& function) const {
2186 const Array& arr = Array::Handle(functions()); 2186 const Array& arr = Array::Handle(functions());
2187 const Array& new_arr = 2187 const Array& new_arr =
2188 Array::Handle(Array::Grow(arr, arr.Length() + 1, Heap::kOld)); 2188 Array::Handle(Array::Grow(arr, arr.Length() + 1, Heap::kOld));
2189 new_arr.SetAt(arr.Length(), function); 2189 new_arr.SetAt(arr.Length(), function);
2190 StorePointer(&raw_ptr()->functions_, new_arr.raw()); 2190 StorePointer(&raw_ptr()->functions_, new_arr.raw());
2191 // Add to hash table, if any. 2191 // Add to hash table, if any.
2192 const intptr_t new_len = new_arr.Length(); 2192 const intptr_t new_len = new_arr.Length();
2193 if (new_len == kFunctionLookupHashTreshold) { 2193 if (new_len == kFunctionLookupHashTreshold) {
2194 // Transition to using hash table. 2194 // Transition to using hash table.
2195 SetFunctions(new_arr); 2195 SetFunctions(new_arr);
2196 } else if (new_len > kFunctionLookupHashTreshold) { 2196 } else if (new_len > kFunctionLookupHashTreshold) {
2197 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); 2197 ClassFunctionsSet set(raw_ptr()->functions_hash_table_);
2198 set.Insert(function); 2198 set.Insert(function);
2199 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw()); 2199 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw());
2200 } 2200 }
2201 } 2201 }
2202 2202
2203 2203
2204 void Class::RemoveFunction(const Function& function) const { 2204 void Class::RemoveFunction(const Function& function) const {
2205 const Array& arr = Array::Handle(functions()); 2205 const Array& arr = Array::Handle(functions());
2206 StorePointer(&raw_ptr()->functions_, Object::empty_array().raw()); 2206 StorePointer(&raw_ptr()->functions_, Object::empty_array().raw());
2207 StorePointer(&raw_ptr()->functions_hash_table_, Array::null());
2207 Function& entry = Function::Handle(); 2208 Function& entry = Function::Handle();
2208 for (intptr_t i = 0; i < arr.Length(); i++) { 2209 for (intptr_t i = 0; i < arr.Length(); i++) {
2209 entry ^= arr.At(i); 2210 entry ^= arr.At(i);
2210 if (function.raw() != entry.raw()) { 2211 if (function.raw() != entry.raw()) {
2211 AddFunction(entry); 2212 AddFunction(entry);
2212 } 2213 }
2213 } 2214 }
2214 } 2215 }
2215 2216
2216 2217
(...skipping 19490 matching lines...) Expand 10 before | Expand all | Expand 10 after
21707 return tag_label.ToCString(); 21708 return tag_label.ToCString();
21708 } 21709 }
21709 21710
21710 21711
21711 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21712 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21712 Instance::PrintJSONImpl(stream, ref); 21713 Instance::PrintJSONImpl(stream, ref);
21713 } 21714 }
21714 21715
21715 21716
21716 } // namespace dart 21717 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698