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

Side by Side Diff: runtime/vm/raw_object.h

Issue 10796004: Consolidate a few fields in RawFunction using bitfields. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 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
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 #ifndef VM_RAW_OBJECT_H_ 5 #ifndef VM_RAW_OBJECT_H_
6 #define VM_RAW_OBJECT_H_ 6 #define VM_RAW_OBJECT_H_
7 7
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/globals.h" 9 #include "vm/globals.h"
10 #include "vm/token.h" 10 #include "vm/token.h"
(...skipping 524 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 } 535 }
536 }; 536 };
537 537
538 538
539 class RawFunction : public RawObject { 539 class RawFunction : public RawObject {
540 public: 540 public:
541 enum Kind { 541 enum Kind {
542 kFunction, 542 kFunction,
543 kClosureFunction, 543 kClosureFunction,
544 kSignatureFunction, // represents a signature only without actual code. 544 kSignatureFunction, // represents a signature only without actual code.
545 kGetterFunction, // represents getter functions e.g: get foo() { .. }. 545 kGetterFunction, // represents getter functions e.g: get foo() { .. }.
546 kSetterFunction, // represents setter functions e.g: set foo(..) { .. }. 546 kSetterFunction, // represents setter functions e.g: set foo(..) { .. }.
547 kAbstract,
548 kConstructor, 547 kConstructor,
549 kImplicitGetter, // represents an implicit getter for fields. 548 kImplicitGetter, // represents an implicit getter for fields.
550 kImplicitSetter, // represents an implicit setter for fields. 549 kImplicitSetter, // represents an implicit setter for fields.
551 kConstImplicitGetter, // represents an implicit const getter for fields. 550 kConstImplicitGetter, // represents an implicit const getter for fields.
552 }; 551 };
553 552
554 private: 553 private:
555 RAW_HEAP_OBJECT_IMPLEMENTATION(Function); 554 RAW_HEAP_OBJECT_IMPLEMENTATION(Function);
556 555
556 enum KindTagBits {
557 kStaticBit = 1,
558 kConstBit = 2,
559 kOptimizableBit = 3,
560 kNativeBit = 4,
561 kAbstractBit = 5,
562 kKindTagBit = 6,
563 kKindTagSize = 4,
564 };
565 class StaticBit : public BitField<bool, kStaticBit, 1> {};
566 class ConstBit : public BitField<bool, kConstBit, 1> {};
567 class OptimizableBit : public BitField<bool, kOptimizableBit, 1> {};
568 class NativeBit : public BitField<bool, kNativeBit, 1> {};
569 class AbstractBit : public BitField<bool, kAbstractBit, 1> {};
570 class KindBits : public BitField<Kind, kKindTagBit, kKindTagSize> {};
571
572 bool IsStatic() const {
573 return StaticBit::decode(ptr()->kind_tag_);
574 }
575 void SetIsStatic(bool value) {
576 uword bits = ptr()->kind_tag_;
577 ptr()->kind_tag_ = StaticBit::update(value, bits);
578 }
579 bool IsConst() const {
580 return ConstBit::decode(ptr()->kind_tag_);
581 }
582 void SetIsConst(bool value) {
583 uword bits = ptr()->kind_tag_;
584 ptr()->kind_tag_ = ConstBit::update(value, bits);
585 }
586 bool IsOptimizable() const {
587 return OptimizableBit::decode(ptr()->kind_tag_);
588 }
589 void SetIsOptimizable(bool value) {
590 uword bits = ptr()->kind_tag_;
591 ptr()->kind_tag_ = OptimizableBit::update(value, bits);
592 }
593 bool IsNative() const {
594 return NativeBit::decode(ptr()->kind_tag_);
595 }
596 void SetIsNative(bool value) {
597 uword bits = ptr()->kind_tag_;
598 ptr()->kind_tag_ = NativeBit::update(value, bits);
599 }
600 bool IsAbstract() const {
601 return AbstractBit::decode(ptr()->kind_tag_);
602 }
603 void SetIsAbstract(bool value) {
604 uword bits = ptr()->kind_tag_;
605 ptr()->kind_tag_ = AbstractBit::update(value, bits);
606 }
607 Kind GetKind() const {
608 return KindBits::decode(ptr()->kind_tag_);
609 }
610 void SetKind(Kind value) {
611 uword bits = ptr()->kind_tag_;
612 ptr()->kind_tag_ = KindBits::update(value, bits);
613 }
614
557 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->name_); } 615 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->name_); }
558 RawString* name_; 616 RawString* name_;
559 RawClass* owner_; 617 RawClass* owner_;
560 RawAbstractType* result_type_; 618 RawAbstractType* result_type_;
561 RawArray* parameter_types_; 619 RawArray* parameter_types_;
562 RawArray* parameter_names_; 620 RawArray* parameter_names_;
563 RawCode* code_; // Compiled code for the function. 621 RawCode* code_; // Compiled code for the function.
564 RawCode* unoptimized_code_; // Unoptimized code, keep it after optimization. 622 RawCode* unoptimized_code_; // Unoptimized code, keep it after optimization.
565 RawContextScope* context_scope_; 623 RawContextScope* context_scope_;
566 RawFunction* parent_function_; // Enclosing function of this local function. 624 RawFunction* parent_function_; // Enclosing function of this local function.
567 RawClass* signature_class_; // Only for closure or signature function. 625 RawClass* signature_class_; // Only for closure or signature function.
568 RawCode* closure_allocation_stub_; // Stub code for allocation of closures. 626 RawCode* closure_allocation_stub_; // Stub code for allocation of closures.
569 RawFunction* implicit_closure_function_; // Implicit closure function. 627 RawFunction* implicit_closure_function_; // Implicit closure function.
570 RawObject** to() { 628 RawObject** to() {
571 return reinterpret_cast<RawObject**>(&ptr()->implicit_closure_function_); 629 return reinterpret_cast<RawObject**>(&ptr()->implicit_closure_function_);
572 } 630 }
573 631
574 intptr_t token_pos_; 632 intptr_t token_pos_;
575 intptr_t end_token_pos_; 633 intptr_t end_token_pos_;
576 intptr_t num_fixed_parameters_; 634 intptr_t num_fixed_parameters_;
577 intptr_t num_optional_parameters_; 635 intptr_t num_optional_parameters_;
578 intptr_t usage_counter_; // Incremented while function is running. 636 intptr_t usage_counter_; // Incremented while function is running.
579 intptr_t deoptimization_counter_; 637 intptr_t deoptimization_counter_;
580 Kind kind_; 638 intptr_t kind_tag_;
581 bool is_static_;
582 bool is_const_;
583 bool is_optimizable_;
584 bool is_native_;
585 }; 639 };
586 640
587 641
588 class RawField : public RawObject { 642 class RawField : public RawObject {
589 RAW_HEAP_OBJECT_IMPLEMENTATION(Field); 643 RAW_HEAP_OBJECT_IMPLEMENTATION(Field);
590 644
591 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->name_); } 645 RawObject** from() { return reinterpret_cast<RawObject**>(&ptr()->name_); }
592 RawString* name_; 646 RawString* name_;
593 RawClass* owner_; 647 RawClass* owner_;
594 RawAbstractType* type_; 648 RawAbstractType* type_;
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1516 kExternalUint64Array == kByteArray + 18 && 1570 kExternalUint64Array == kByteArray + 18 &&
1517 kExternalFloat32Array == kByteArray + 19 && 1571 kExternalFloat32Array == kByteArray + 19 &&
1518 kExternalFloat64Array == kByteArray + 20 && 1572 kExternalFloat64Array == kByteArray + 20 &&
1519 kClosure == kByteArray + 21); 1573 kClosure == kByteArray + 21);
1520 return (index >= kByteArray && index <= kClosure); 1574 return (index >= kByteArray && index <= kClosure);
1521 } 1575 }
1522 1576
1523 } // namespace dart 1577 } // namespace dart
1524 1578
1525 #endif // VM_RAW_OBJECT_H_ 1579 #endif // VM_RAW_OBJECT_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698