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

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

Powered by Google App Engine
This is Rietveld 408576698