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

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

Issue 16174008: - Create isolate specific resuable handles and use them in the hot lookup paths. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
« runtime/vm/handles.h ('K') | « runtime/vm/object.h ('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) 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 1595 matching lines...) Expand 10 before | Expand all | Expand 10 after
1606 } 1606 }
1607 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1607 const TypeArguments& type_params = TypeArguments::Handle(type_parameters());
1608 return type_params.Length(); 1608 return type_params.Length();
1609 } 1609 }
1610 1610
1611 1611
1612 intptr_t Class::NumTypeArguments() const { 1612 intptr_t Class::NumTypeArguments() const {
1613 // To work properly, this call requires the super class of this class to be 1613 // To work properly, this call requires the super class of this class to be
1614 // resolved, which is checked by the SuperClass() call. 1614 // resolved, which is checked by the SuperClass() call.
1615 Isolate* isolate = Isolate::Current(); 1615 Isolate* isolate = Isolate::Current();
1616 Class& cls = Class::Handle(isolate, raw()); 1616 REUSABLE_HANDLESCOPE(isolate);
1617 Class& cls = isolate->ClassHandle();
1618 TypeArguments& type_params = isolate->TypeArgumentsHandle();
1619 AbstractType& sup_type = isolate->AbstractTypeHandle();
1620 cls ^= raw();
1617 intptr_t num_type_args = 0; 1621 intptr_t num_type_args = 0;
1618 1622
1619 do { 1623 do {
1620 if (cls.IsSignatureClass()) { 1624 if (cls.IsSignatureClass()) {
1621 const Function& signature_fun = 1625 Function& signature_fun = isolate->FunctionHandle();
1622 Function::Handle(isolate, cls.signature_function()); 1626 signature_fun ^= cls.signature_function();
1623 if (!signature_fun.is_static() && 1627 if (!signature_fun.is_static() &&
1624 !signature_fun.HasInstantiatedSignature()) { 1628 !signature_fun.HasInstantiatedSignature()) {
1625 cls = signature_fun.Owner(); 1629 cls = signature_fun.Owner();
1626 } 1630 }
1627 } 1631 }
1628 num_type_args += cls.NumTypeParameters(); 1632 if (cls.type_parameters() != TypeArguments::null()) {
1633 type_params ^= cls.type_parameters();
1634 num_type_args += type_params.Length();
1635 }
1636
1629 // Super type of Object class is null. 1637 // Super type of Object class is null.
1630 if (cls.super_type() == AbstractType::null() || 1638 if (cls.super_type() == AbstractType::null() ||
1631 cls.super_type() == isolate->object_store()->object_type()) { 1639 cls.super_type() == isolate->object_store()->object_type()) {
1632 break; 1640 break;
1633 } 1641 }
1634 cls = cls.SuperClass(); 1642 sup_type ^= cls.super_type();
1643 cls = sup_type.type_class();
1635 } while (true); 1644 } while (true);
1636 return num_type_args; 1645 return num_type_args;
1637 } 1646 }
1638 1647
1639 1648
1640 bool Class::HasTypeArguments() const { 1649 bool Class::HasTypeArguments() const {
1641 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) { 1650 if (!IsSignatureClass() && (is_type_finalized() || is_prefinalized())) {
1642 // More efficient than calling NumTypeArguments(). 1651 // More efficient than calling NumTypeArguments().
1643 return type_arguments_field_offset() != kNoTypeArguments; 1652 return type_arguments_field_offset() != kNoTypeArguments;
1644 } else { 1653 } else {
1645 // No need to check NumTypeArguments() if class has type parameters. 1654 // No need to check NumTypeArguments() if class has type parameters.
1646 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0); 1655 return (NumTypeParameters() > 0) || (NumTypeArguments() > 0);
1647 } 1656 }
1648 } 1657 }
1649 1658
1650 1659
1651 RawClass* Class::SuperClass() const { 1660 RawClass* Class::SuperClass() const {
1652 if (super_type() == AbstractType::null()) { 1661 if (super_type() == AbstractType::null()) {
1653 return Class::null(); 1662 return Class::null();
1654 } 1663 }
1655 const AbstractType& sup_type = AbstractType::Handle(super_type()); 1664 Isolate* isolate = Isolate::Current();
1665 REUSABLE_HANDLESCOPE(isolate);
1666 AbstractType& sup_type = isolate->AbstractTypeHandle();
1667 sup_type ^= super_type();
1656 return sup_type.type_class(); 1668 return sup_type.type_class();
1657 } 1669 }
1658 1670
1659 1671
1660 void Class::set_super_type(const AbstractType& value) const { 1672 void Class::set_super_type(const AbstractType& value) const {
1661 ASSERT(value.IsNull() || 1673 ASSERT(value.IsNull() ||
1662 value.IsType() || 1674 value.IsType() ||
1663 value.IsBoundedType() || 1675 value.IsBoundedType() ||
1664 value.IsMixinAppType()); 1676 value.IsMixinAppType());
1665 StorePointer(&raw_ptr()->super_type_, value.raw()); 1677 StorePointer(&raw_ptr()->super_type_, value.raw());
1666 } 1678 }
1667 1679
1668 1680
1669 // Return a TypeParameter if the type_name is a type parameter of this class. 1681 // Return a TypeParameter if the type_name is a type parameter of this class.
1670 // Return null otherwise. 1682 // Return null otherwise.
1671 RawTypeParameter* Class::LookupTypeParameter(const String& type_name, 1683 RawTypeParameter* Class::LookupTypeParameter(const String& type_name,
1672 intptr_t token_pos) const { 1684 intptr_t token_pos) const {
1673 ASSERT(!type_name.IsNull()); 1685 ASSERT(!type_name.IsNull());
1674 const TypeArguments& type_params = TypeArguments::Handle(type_parameters()); 1686 Isolate* isolate = Isolate::Current();
1687 REUSABLE_HANDLESCOPE(isolate);
1688 TypeArguments& type_params = isolate->TypeArgumentsHandle();
1689 type_params ^= type_parameters();
1690 TypeParameter& type_param = isolate->TypeParameterHandle();
1691 String& type_param_name = isolate->StringHandle();
1675 if (!type_params.IsNull()) { 1692 if (!type_params.IsNull()) {
1676 intptr_t num_type_params = type_params.Length(); 1693 intptr_t num_type_params = type_params.Length();
1677 TypeParameter& type_param = TypeParameter::Handle();
1678 String& type_param_name = String::Handle();
1679 for (intptr_t i = 0; i < num_type_params; i++) { 1694 for (intptr_t i = 0; i < num_type_params; i++) {
1680 type_param ^= type_params.TypeAt(i); 1695 type_param ^= type_params.TypeAt(i);
1681 type_param_name = type_param.name(); 1696 type_param_name = type_param.name();
1682 if (type_param_name.Equals(type_name)) { 1697 if (type_param_name.Equals(type_name)) {
1683 return type_param.raw(); 1698 return type_param.raw();
1684 } 1699 }
1685 } 1700 }
1686 } 1701 }
1687 return TypeParameter::null(); 1702 return TypeParameter::null();
1688 } 1703 }
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after
2441 } 2456 }
2442 return Function::null(); 2457 return Function::null();
2443 } 2458 }
2444 2459
2445 2460
2446 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const { 2461 RawFunction* Class::LookupFunction(const String& name, intptr_t type) const {
2447 Isolate* isolate = Isolate::Current(); 2462 Isolate* isolate = Isolate::Current();
2448 if (EnsureIsFinalized(isolate) != Error::null()) { 2463 if (EnsureIsFinalized(isolate) != Error::null()) {
2449 return Function::null(); 2464 return Function::null();
2450 } 2465 }
2451 Array& funcs = Array::Handle(isolate, functions()); 2466 REUSABLE_HANDLESCOPE(isolate);
2467 Array& funcs = isolate->ArrayHandle();
2468 funcs ^= functions();
2452 if (funcs.IsNull()) { 2469 if (funcs.IsNull()) {
2453 // This can occur, e.g., for Null classes. 2470 // This can occur, e.g., for Null classes.
2454 return Function::null(); 2471 return Function::null();
2455 } 2472 }
2456 Function& function = Function::Handle(isolate); 2473 Function& function = isolate->FunctionHandle();
2457 const intptr_t len = funcs.Length(); 2474 const intptr_t len = funcs.Length();
2458 if (name.IsSymbol()) { 2475 if (name.IsSymbol()) {
2459 // Quick Symbol compare. 2476 // Quick Symbol compare.
2460 NoGCScope no_gc; 2477 NoGCScope no_gc;
2461 for (intptr_t i = 0; i < len; i++) { 2478 for (intptr_t i = 0; i < len; i++) {
2462 function ^= funcs.At(i); 2479 function ^= funcs.At(i);
2463 if (function.name() == name.raw()) { 2480 if (function.name() == name.raw()) {
2464 return CheckFunctionType(function, type); 2481 return CheckFunctionType(function, type);
2465 } 2482 }
2466 } 2483 }
2467 } else { 2484 } else {
2468 String& function_name = String::Handle(isolate); 2485 String& function_name = isolate->StringHandle();
2469 for (intptr_t i = 0; i < len; i++) { 2486 for (intptr_t i = 0; i < len; i++) {
2470 function ^= funcs.At(i); 2487 function ^= funcs.At(i);
2471 function_name ^= function.name(); 2488 function_name ^= function.name();
2472 if (function_name.Equals(name)) { 2489 if (function_name.Equals(name)) {
2473 return CheckFunctionType(function, type); 2490 return CheckFunctionType(function, type);
2474 } 2491 }
2475 } 2492 }
2476 } 2493 }
2477 // No function found. 2494 // No function found.
2478 return Function::null(); 2495 return Function::null();
2479 } 2496 }
2480 2497
2481 2498
2482 RawFunction* Class::LookupFunctionAllowPrivate(const String& name, 2499 RawFunction* Class::LookupFunctionAllowPrivate(const String& name,
2483 intptr_t type) const { 2500 intptr_t type) const {
2484 Isolate* isolate = Isolate::Current(); 2501 Isolate* isolate = Isolate::Current();
2485 if (EnsureIsFinalized(isolate) != Error::null()) { 2502 if (EnsureIsFinalized(isolate) != Error::null()) {
2486 return Function::null(); 2503 return Function::null();
2487 } 2504 }
2488 Array& funcs = Array::Handle(isolate, functions()); 2505 REUSABLE_HANDLESCOPE(isolate);
2506 Array& funcs = isolate->ArrayHandle();
2507 funcs ^= functions();
2489 if (funcs.IsNull()) { 2508 if (funcs.IsNull()) {
2490 // This can occur, e.g., for Null classes. 2509 // This can occur, e.g., for Null classes.
2491 return Function::null(); 2510 return Function::null();
2492 } 2511 }
2493 Function& function = Function::Handle(isolate); 2512 Function& function = isolate->FunctionHandle();
2494 String& function_name = String::Handle(isolate); 2513 String& function_name = isolate->StringHandle();
2495 intptr_t len = funcs.Length(); 2514 intptr_t len = funcs.Length();
2496 for (intptr_t i = 0; i < len; i++) { 2515 for (intptr_t i = 0; i < len; i++) {
2497 function ^= funcs.At(i); 2516 function ^= funcs.At(i);
2498 function_name ^= function.name(); 2517 function_name ^= function.name();
2499 if (String::EqualsIgnoringPrivateKey(function_name, name)) { 2518 if (String::EqualsIgnoringPrivateKey(function_name, name)) {
2500 return CheckFunctionType(function, type); 2519 return CheckFunctionType(function, type);
2501 } 2520 }
2502 } 2521 }
2503 // No function found. 2522 // No function found.
2504 return Function::null(); 2523 return Function::null();
(...skipping 10 matching lines...) Expand all
2515 } 2534 }
2516 2535
2517 2536
2518 RawFunction* Class::LookupAccessorFunction(const char* prefix, 2537 RawFunction* Class::LookupAccessorFunction(const char* prefix,
2519 intptr_t prefix_length, 2538 intptr_t prefix_length,
2520 const String& name) const { 2539 const String& name) const {
2521 Isolate* isolate = Isolate::Current(); 2540 Isolate* isolate = Isolate::Current();
2522 if (EnsureIsFinalized(isolate) != Error::null()) { 2541 if (EnsureIsFinalized(isolate) != Error::null()) {
2523 return Function::null(); 2542 return Function::null();
2524 } 2543 }
2525 Array& funcs = Array::Handle(isolate, functions()); 2544 REUSABLE_HANDLESCOPE(isolate);
2526 Function& function = Function::Handle(isolate, Function::null()); 2545 Array& funcs = isolate->ArrayHandle();
2527 String& function_name = String::Handle(isolate, String::null()); 2546 funcs ^= functions();
2547 Function& function = isolate->FunctionHandle();
2548 String& function_name = isolate->StringHandle();
2528 intptr_t len = funcs.Length(); 2549 intptr_t len = funcs.Length();
2529 for (intptr_t i = 0; i < len; i++) { 2550 for (intptr_t i = 0; i < len; i++) {
2530 function ^= funcs.At(i); 2551 function ^= funcs.At(i);
2531 function_name ^= function.name(); 2552 function_name ^= function.name();
2532 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) { 2553 if (MatchesAccessorName(function_name, prefix, prefix_length, name)) {
2533 return function.raw(); 2554 return function.raw();
2534 } 2555 }
2535 } 2556 }
2536 2557
2537 // No function found. 2558 // No function found.
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2578 RawField* Class::LookupField(const String& name) const { 2599 RawField* Class::LookupField(const String& name) const {
2579 return LookupField(name, kAny); 2600 return LookupField(name, kAny);
2580 } 2601 }
2581 2602
2582 2603
2583 RawField* Class::LookupField(const String& name, intptr_t type) const { 2604 RawField* Class::LookupField(const String& name, intptr_t type) const {
2584 Isolate* isolate = Isolate::Current(); 2605 Isolate* isolate = Isolate::Current();
2585 if (EnsureIsFinalized(isolate) != Error::null()) { 2606 if (EnsureIsFinalized(isolate) != Error::null()) {
2586 return Field::null(); 2607 return Field::null();
2587 } 2608 }
2588 const Array& flds = Array::Handle(isolate, fields()); 2609 REUSABLE_HANDLESCOPE(isolate);
2589 Field& field = Field::Handle(isolate, Field::null()); 2610 Array& flds = isolate->ArrayHandle();
2590 String& field_name = String::Handle(isolate, String::null()); 2611 flds ^= fields();
2612 Field& field = isolate->FieldHandle();
2613 String& field_name = isolate->StringHandle();
2591 intptr_t len = flds.Length(); 2614 intptr_t len = flds.Length();
2592 for (intptr_t i = 0; i < len; i++) { 2615 for (intptr_t i = 0; i < len; i++) {
2593 field ^= flds.At(i); 2616 field ^= flds.At(i);
2594 field_name ^= field.name(); 2617 field_name ^= field.name();
2595 if (String::EqualsIgnoringPrivateKey(field_name, name)) { 2618 if (String::EqualsIgnoringPrivateKey(field_name, name)) {
2596 if (type == kInstance) { 2619 if (type == kInstance) {
2597 if (!field.is_static()) { 2620 if (!field.is_static()) {
2598 return field.raw(); 2621 return field.raw();
2599 } 2622 }
2600 } else if (type == kStatic) { 2623 } else if (type == kStatic) {
(...skipping 3586 matching lines...) Expand 10 before | Expand all | Expand 10 after
6187 return obj.raw(); 6210 return obj.raw();
6188 } 6211 }
6189 } 6212 }
6190 } 6213 }
6191 return Object::null(); 6214 return Object::null();
6192 } 6215 }
6193 6216
6194 6217
6195 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const { 6218 RawObject* Library::LookupEntry(const String& name, intptr_t *index) const {
6196 Isolate* isolate = Isolate::Current(); 6219 Isolate* isolate = Isolate::Current();
6197 const Array& dict = Array::Handle(isolate, dictionary()); 6220 REUSABLE_HANDLESCOPE(isolate);
6221 Array& dict = isolate->ArrayHandle();
6222 dict ^= dictionary();
6198 intptr_t dict_size = dict.Length() - 1; 6223 intptr_t dict_size = dict.Length() - 1;
6199 *index = name.Hash() % dict_size; 6224 *index = name.Hash() % dict_size;
6200 6225
6201 Object& entry = Object::Handle(isolate); 6226 Object& entry = isolate->ObjectHandle();
6202 String& entry_name = String::Handle(isolate); 6227 String& entry_name = isolate->StringHandle();
6203 entry = dict.At(*index); 6228 entry = dict.At(*index);
6204 // Search the entry in the hash set. 6229 // Search the entry in the hash set.
6205 while (!entry.IsNull()) { 6230 while (!entry.IsNull()) {
6206 entry_name = entry.DictionaryName(); 6231 entry_name = entry.DictionaryName();
6207 ASSERT(!entry_name.IsNull()); 6232 ASSERT(!entry_name.IsNull());
6208 if (entry_name.Equals(name)) { 6233 if (entry_name.Equals(name)) {
6209 return entry.raw(); 6234 return entry.raw();
6210 } 6235 }
6211 *index = (*index + 1) % dict_size; 6236 *index = (*index + 1) % dict_size;
6212 entry = dict.At(*index); 6237 entry = dict.At(*index);
(...skipping 7389 matching lines...) Expand 10 before | Expand all | Expand 10 after
13602 space); 13627 space);
13603 return reinterpret_cast<RawWeakProperty*>(raw); 13628 return reinterpret_cast<RawWeakProperty*>(raw);
13604 } 13629 }
13605 13630
13606 13631
13607 const char* WeakProperty::ToCString() const { 13632 const char* WeakProperty::ToCString() const {
13608 return "_WeakProperty"; 13633 return "_WeakProperty";
13609 } 13634 }
13610 13635
13611 } // namespace dart 13636 } // namespace dart
OLDNEW
« runtime/vm/handles.h ('K') | « runtime/vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698