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

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

Issue 1320673012: Lookup getter/setter symbols before alllocating them, thus eliminating extra String allocations in … (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Formatting Created 5 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.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) 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 2102 matching lines...) Expand 10 before | Expand all | Expand 10 after
2113 ASSERT(func.Owner() == raw()); 2113 ASSERT(func.Owner() == raw());
2114 set.Insert(func); 2114 set.Insert(func);
2115 } 2115 }
2116 } 2116 }
2117 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw()); 2117 StorePointer(&raw_ptr()->functions_hash_table_, set.Release().raw());
2118 } 2118 }
2119 2119
2120 2120
2121 void Class::AddFunction(const Function& function) const { 2121 void Class::AddFunction(const Function& function) const {
2122 const Array& arr = Array::Handle(functions()); 2122 const Array& arr = Array::Handle(functions());
2123 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); 2123 const Array& new_arr =
2124 Array::Handle(Array::Grow(arr, arr.Length() + 1, Heap::kOld));
2124 new_arr.SetAt(arr.Length(), function); 2125 new_arr.SetAt(arr.Length(), function);
2125 StorePointer(&raw_ptr()->functions_, new_arr.raw()); 2126 StorePointer(&raw_ptr()->functions_, new_arr.raw());
2126 // Add to hash table, if any. 2127 // Add to hash table, if any.
2127 const intptr_t new_len = new_arr.Length(); 2128 const intptr_t new_len = new_arr.Length();
2128 if (new_len == kFunctionLookupHashTreshold) { 2129 if (new_len == kFunctionLookupHashTreshold) {
2129 // Transition to using hash table. 2130 // Transition to using hash table.
2130 SetFunctions(new_arr); 2131 SetFunctions(new_arr);
2131 } else if (new_len > kFunctionLookupHashTreshold) { 2132 } else if (new_len > kFunctionLookupHashTreshold) {
2132 ClassFunctionsSet set(raw_ptr()->functions_hash_table_); 2133 ClassFunctionsSet set(raw_ptr()->functions_hash_table_);
2133 set.Insert(function); 2134 set.Insert(function);
(...skipping 5041 matching lines...) Expand 10 before | Expand all | Expand 10 after
7175 return "RedirectionData class"; 7176 return "RedirectionData class";
7176 } 7177 }
7177 7178
7178 7179
7179 void RedirectionData::PrintJSONImpl(JSONStream* stream, bool ref) const { 7180 void RedirectionData::PrintJSONImpl(JSONStream* stream, bool ref) const {
7180 Object::PrintJSONImpl(stream, ref); 7181 Object::PrintJSONImpl(stream, ref);
7181 } 7182 }
7182 7183
7183 7184
7184 RawString* Field::GetterName(const String& field_name) { 7185 RawString* Field::GetterName(const String& field_name) {
7185 return Field::GetterSymbol(field_name); 7186 return String::Concat(Symbols::GetterPrefix(), field_name);
7186 } 7187 }
7187 7188
7188 7189
7189 RawString* Field::GetterSymbol(const String& field_name) { 7190 RawString* Field::GetterSymbol(const String& field_name) {
7190 return Symbols::FromConcat(Symbols::GetterPrefix(), field_name); 7191 return Symbols::FromConcat(Symbols::GetterPrefix(), field_name);
7191 } 7192 }
7192 7193
7193 7194
7195 RawString* Field::LookupGetterSymbol(const String& field_name) {
7196 return Symbols::LookupFromConcat(Symbols::GetterPrefix(), field_name);
7197 }
7198
7199
7194 RawString* Field::SetterName(const String& field_name) { 7200 RawString* Field::SetterName(const String& field_name) {
7195 return String::Concat(Symbols::SetterPrefix(), field_name); 7201 return String::Concat(Symbols::SetterPrefix(), field_name);
7196 } 7202 }
7197 7203
7198 7204
7199 RawString* Field::SetterSymbol(const String& field_name) { 7205 RawString* Field::SetterSymbol(const String& field_name) {
7200 return Symbols::FromConcat(Symbols::SetterPrefix(), field_name); 7206 return Symbols::FromConcat(Symbols::SetterPrefix(), field_name);
7201 } 7207 }
7202 7208
7203 7209
7210 RawString* Field::LookupSetterSymbol(const String& field_name) {
7211 return Symbols::LookupFromConcat(Symbols::SetterPrefix(), field_name);
7212 }
7213
7214
7204 RawString* Field::NameFromGetter(const String& getter_name) { 7215 RawString* Field::NameFromGetter(const String& getter_name) {
7205 return Symbols::New(getter_name, kGetterPrefixLength, 7216 return Symbols::New(getter_name, kGetterPrefixLength,
7206 getter_name.Length() - kGetterPrefixLength); 7217 getter_name.Length() - kGetterPrefixLength);
7207 } 7218 }
7208 7219
7209 7220
7210 RawString* Field::NameFromSetter(const String& setter_name) { 7221 RawString* Field::NameFromSetter(const String& setter_name) {
7211 return Symbols::New(setter_name, kSetterPrefixLength, 7222 return Symbols::New(setter_name, kSetterPrefixLength,
7212 setter_name.Length() - kSetterPrefixLength); 7223 setter_name.Length() - kSetterPrefixLength);
7213 } 7224 }
(...skipping 3488 matching lines...) Expand 10 before | Expand all | Expand 10 after
10702 RawObject* Namespace::Lookup(const String& name) const { 10713 RawObject* Namespace::Lookup(const String& name) const {
10703 Isolate* isolate = Isolate::Current(); 10714 Isolate* isolate = Isolate::Current();
10704 const Library& lib = Library::Handle(isolate, library()); 10715 const Library& lib = Library::Handle(isolate, library());
10705 intptr_t ignore = 0; 10716 intptr_t ignore = 0;
10706 10717
10707 // Lookup the name in the library's symbols. 10718 // Lookup the name in the library's symbols.
10708 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore)); 10719 Object& obj = Object::Handle(isolate, lib.LookupEntry(name, &ignore));
10709 if (!Field::IsGetterName(name) && 10720 if (!Field::IsGetterName(name) &&
10710 !Field::IsSetterName(name) && 10721 !Field::IsSetterName(name) &&
10711 (obj.IsNull() || obj.IsLibraryPrefix())) { 10722 (obj.IsNull() || obj.IsLibraryPrefix())) {
10712 obj = lib.LookupEntry(String::Handle(Field::GetterName(name)), &ignore); 10723 const String& getter_name = String::Handle(Field::LookupGetterSymbol(name));
10724 if (!getter_name.IsNull()) {
10725 obj = lib.LookupEntry(getter_name, &ignore);
10726 }
10713 if (obj.IsNull()) { 10727 if (obj.IsNull()) {
10714 obj = lib.LookupEntry(String::Handle(Field::SetterName(name)), &ignore); 10728 const String& setter_name =
10729 String::Handle(Field::LookupSetterSymbol(name));
10730 if (!setter_name.IsNull()) {
10731 obj = lib.LookupEntry(setter_name, &ignore);
10732 }
10715 } 10733 }
10716 } 10734 }
10717 10735
10718 // Library prefixes are not exported. 10736 // Library prefixes are not exported.
10719 if (obj.IsNull() || obj.IsLibraryPrefix()) { 10737 if (obj.IsNull() || obj.IsLibraryPrefix()) {
10720 // Lookup in the re-exported symbols. 10738 // Lookup in the re-exported symbols.
10721 obj = lib.LookupReExport(name); 10739 obj = lib.LookupReExport(name);
10722 } 10740 }
10723 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) { 10741 if (obj.IsNull() || HidesName(name) || obj.IsLibraryPrefix()) {
10724 return Object::null(); 10742 return Object::null();
(...skipping 6241 matching lines...) Expand 10 before | Expand all | Expand 10 after
16966 } 16984 }
16967 return Integer::null(); // Notify caller that a bigint operation is required. 16985 return Integer::null(); // Notify caller that a bigint operation is required.
16968 } 16986 }
16969 16987
16970 16988
16971 static bool Are64bitOperands(const Integer& op1, const Integer& op2) { 16989 static bool Are64bitOperands(const Integer& op1, const Integer& op2) {
16972 return !op1.IsBigint() && !op2.IsBigint(); 16990 return !op1.IsBigint() && !op2.IsBigint();
16973 } 16991 }
16974 16992
16975 16993
16976 RawInteger* Integer::BitOp(Token::Kind kind, const Integer& other) const { 16994 RawInteger* Integer::BitOp(
16995 Token::Kind kind, const Integer& other, Heap::Space space) const {
16977 if (IsSmi() && other.IsSmi()) { 16996 if (IsSmi() && other.IsSmi()) {
16978 intptr_t op1_value = Smi::Value(Smi::RawCast(raw())); 16997 intptr_t op1_value = Smi::Value(Smi::RawCast(raw()));
16979 intptr_t op2_value = Smi::Value(Smi::RawCast(other.raw())); 16998 intptr_t op2_value = Smi::Value(Smi::RawCast(other.raw()));
16980 intptr_t result = 0; 16999 intptr_t result = 0;
16981 switch (kind) { 17000 switch (kind) {
16982 case Token::kBIT_AND: 17001 case Token::kBIT_AND:
16983 result = op1_value & op2_value; 17002 result = op1_value & op2_value;
16984 break; 17003 break;
16985 case Token::kBIT_OR: 17004 case Token::kBIT_OR:
16986 result = op1_value | op2_value; 17005 result = op1_value | op2_value;
16987 break; 17006 break;
16988 case Token::kBIT_XOR: 17007 case Token::kBIT_XOR:
16989 result = op1_value ^ op2_value; 17008 result = op1_value ^ op2_value;
16990 break; 17009 break;
16991 default: 17010 default:
16992 UNIMPLEMENTED(); 17011 UNIMPLEMENTED();
16993 } 17012 }
16994 ASSERT(Smi::IsValid(result)); 17013 ASSERT(Smi::IsValid(result));
16995 return Smi::New(result); 17014 return Smi::New(result);
16996 } else if (Are64bitOperands(*this, other)) { 17015 } else if (Are64bitOperands(*this, other)) {
16997 int64_t a = AsInt64Value(); 17016 int64_t a = AsInt64Value();
16998 int64_t b = other.AsInt64Value(); 17017 int64_t b = other.AsInt64Value();
16999 switch (kind) { 17018 switch (kind) {
17000 case Token::kBIT_AND: 17019 case Token::kBIT_AND:
17001 return Integer::New(a & b); 17020 return Integer::New(a & b, space);
17002 case Token::kBIT_OR: 17021 case Token::kBIT_OR:
17003 return Integer::New(a | b); 17022 return Integer::New(a | b, space);
17004 case Token::kBIT_XOR: 17023 case Token::kBIT_XOR:
17005 return Integer::New(a ^ b); 17024 return Integer::New(a ^ b, space);
17006 default: 17025 default:
17007 UNIMPLEMENTED(); 17026 UNIMPLEMENTED();
17008 } 17027 }
17009 } 17028 }
17010 return Integer::null(); // Notify caller that a bigint operation is required. 17029 return Integer::null(); // Notify caller that a bigint operation is required.
17011 } 17030 }
17012 17031
17013 17032
17014 // TODO(srdjan): Clarify handling of negative right operand in a shift op. 17033 // TODO(srdjan): Clarify handling of negative right operand in a shift op.
17015 RawInteger* Smi::ShiftOp(Token::Kind kind, 17034 RawInteger* Smi::ShiftOp(Token::Kind kind,
17016 const Smi& other, 17035 const Smi& other,
17036 Heap::Space space,
17017 const bool silent) const { 17037 const bool silent) const {
17018 intptr_t result = 0; 17038 intptr_t result = 0;
17019 const intptr_t left_value = Value(); 17039 const intptr_t left_value = Value();
17020 const intptr_t right_value = other.Value(); 17040 const intptr_t right_value = other.Value();
17021 ASSERT(right_value >= 0); 17041 ASSERT(right_value >= 0);
17022 switch (kind) { 17042 switch (kind) {
17023 case Token::kSHL: { 17043 case Token::kSHL: {
17024 if ((left_value == 0) || (right_value == 0)) { 17044 if ((left_value == 0) || (right_value == 0)) {
17025 return raw(); 17045 return raw();
17026 } 17046 }
17027 { // Check for overflow. 17047 { // Check for overflow.
17028 int cnt = Utils::BitLength(left_value); 17048 int cnt = Utils::BitLength(left_value);
17029 if ((cnt + right_value) > Smi::kBits) { 17049 if ((cnt + right_value) > Smi::kBits) {
17030 if ((cnt + right_value) > Mint::kBits) { 17050 if ((cnt + right_value) > Mint::kBits) {
17031 return Bigint::NewFromShiftedInt64(left_value, right_value); 17051 return Bigint::NewFromShiftedInt64(left_value, right_value, space);
17032 } else { 17052 } else {
17033 int64_t left_64 = left_value; 17053 int64_t left_64 = left_value;
17034 return Integer::New(left_64 << right_value, Heap::kNew, silent); 17054 return Integer::New(left_64 << right_value, space, silent);
17035 } 17055 }
17036 } 17056 }
17037 } 17057 }
17038 result = left_value << right_value; 17058 result = left_value << right_value;
17039 break; 17059 break;
17040 } 17060 }
17041 case Token::kSHR: { 17061 case Token::kSHR: {
17042 const intptr_t shift_amount = 17062 const intptr_t shift_amount =
17043 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value; 17063 (right_value >= kBitsPerWord) ? (kBitsPerWord - 1) : right_value;
17044 result = left_value >> shift_amount; 17064 result = left_value >> shift_amount;
(...skipping 4463 matching lines...) Expand 10 before | Expand all | Expand 10 after
21508 return tag_label.ToCString(); 21528 return tag_label.ToCString();
21509 } 21529 }
21510 21530
21511 21531
21512 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21532 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21513 Instance::PrintJSONImpl(stream, ref); 21533 Instance::PrintJSONImpl(stream, ref);
21514 } 21534 }
21515 21535
21516 21536
21517 } // namespace dart 21537 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698