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

Side by Side Diff: vm/object.h

Issue 9462003: Changes to shrink the token stream representation from two words to one word. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 10 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
« no previous file with comments | « vm/dart.cc ('k') | vm/object.cc » ('j') | vm/object.cc » ('J')
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 #ifndef VM_OBJECT_H_ 5 #ifndef VM_OBJECT_H_
6 #define VM_OBJECT_H_ 6 #define VM_OBJECT_H_
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/utils.h" 10 #include "platform/utils.h"
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 kVoidClass, 137 kVoidClass,
138 kUnresolvedClassClass, 138 kUnresolvedClassClass,
139 kTypeClass, 139 kTypeClass,
140 kTypeParameterClass, 140 kTypeParameterClass,
141 kInstantiatedTypeClass, 141 kInstantiatedTypeClass,
142 kAbstractTypeArgumentsClass, 142 kAbstractTypeArgumentsClass,
143 kTypeArgumentsClass, 143 kTypeArgumentsClass,
144 kInstantiatedTypeArgumentsClass, 144 kInstantiatedTypeArgumentsClass,
145 kFunctionClass, 145 kFunctionClass,
146 kFieldClass, 146 kFieldClass,
147 kLiteralTokenClass,
147 kTokenStreamClass, 148 kTokenStreamClass,
148 kScriptClass, 149 kScriptClass,
149 kLibraryClass, 150 kLibraryClass,
150 kLibraryPrefixClass, 151 kLibraryPrefixClass,
151 kCodeClass, 152 kCodeClass,
152 kInstructionsClass, 153 kInstructionsClass,
153 kPcDescriptorsClass, 154 kPcDescriptorsClass,
154 kLocalVarDescriptorsClass, 155 kLocalVarDescriptorsClass,
155 kExceptionHandlersClass, 156 kExceptionHandlersClass,
156 kContextClass, 157 kContextClass,
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 } 273 }
273 static RawClass* abstract_type_arguments_class() { 274 static RawClass* abstract_type_arguments_class() {
274 return abstract_type_arguments_class_; 275 return abstract_type_arguments_class_;
275 } 276 }
276 static RawClass* type_arguments_class() { return type_arguments_class_; } 277 static RawClass* type_arguments_class() { return type_arguments_class_; }
277 static RawClass* instantiated_type_arguments_class() { 278 static RawClass* instantiated_type_arguments_class() {
278 return instantiated_type_arguments_class_; 279 return instantiated_type_arguments_class_;
279 } 280 }
280 static RawClass* function_class() { return function_class_; } 281 static RawClass* function_class() { return function_class_; }
281 static RawClass* field_class() { return field_class_; } 282 static RawClass* field_class() { return field_class_; }
283 static RawClass* literal_token_class() { return literal_token_class_; }
282 static RawClass* token_stream_class() { return token_stream_class_; } 284 static RawClass* token_stream_class() { return token_stream_class_; }
283 static RawClass* script_class() { return script_class_; } 285 static RawClass* script_class() { return script_class_; }
284 static RawClass* library_class() { return library_class_; } 286 static RawClass* library_class() { return library_class_; }
285 static RawClass* library_prefix_class() { return library_prefix_class_; } 287 static RawClass* library_prefix_class() { return library_prefix_class_; }
286 static RawClass* code_class() { return code_class_; } 288 static RawClass* code_class() { return code_class_; }
287 static RawClass* instructions_class() { return instructions_class_; } 289 static RawClass* instructions_class() { return instructions_class_; }
288 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; } 290 static RawClass* pc_descriptors_class() { return pc_descriptors_class_; }
289 static RawClass* var_descriptors_class() { return var_descriptors_class_; } 291 static RawClass* var_descriptors_class() { return var_descriptors_class_; }
290 static RawClass* exception_handlers_class() { 292 static RawClass* exception_handlers_class() {
291 return exception_handlers_class_; 293 return exception_handlers_class_;
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
383 static RawClass* type_class_; // Class of Type. 385 static RawClass* type_class_; // Class of Type.
384 static RawClass* type_parameter_class_; // Class of TypeParameter vm object. 386 static RawClass* type_parameter_class_; // Class of TypeParameter vm object.
385 static RawClass* instantiated_type_class_; // Class of InstantiatedType. 387 static RawClass* instantiated_type_class_; // Class of InstantiatedType.
386 // Class of AbstractTypeArguments vm object. 388 // Class of AbstractTypeArguments vm object.
387 static RawClass* abstract_type_arguments_class_; 389 static RawClass* abstract_type_arguments_class_;
388 // Class of the TypeArguments vm object. 390 // Class of the TypeArguments vm object.
389 static RawClass* type_arguments_class_; 391 static RawClass* type_arguments_class_;
390 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments. 392 static RawClass* instantiated_type_arguments_class_; // Class of Inst..ments.
391 static RawClass* function_class_; // Class of the Function vm object. 393 static RawClass* function_class_; // Class of the Function vm object.
392 static RawClass* field_class_; // Class of the Field vm object. 394 static RawClass* field_class_; // Class of the Field vm object.
395 static RawClass* literal_token_class_; // Class of LiteralToken vm object.
393 static RawClass* token_stream_class_; // Class of the TokenStream vm object. 396 static RawClass* token_stream_class_; // Class of the TokenStream vm object.
394 static RawClass* script_class_; // Class of the Script vm object. 397 static RawClass* script_class_; // Class of the Script vm object.
395 static RawClass* library_class_; // Class of the Library vm object. 398 static RawClass* library_class_; // Class of the Library vm object.
396 static RawClass* library_prefix_class_; // Class of Library prefix vm object. 399 static RawClass* library_prefix_class_; // Class of Library prefix vm object.
397 static RawClass* code_class_; // Class of the Code vm object. 400 static RawClass* code_class_; // Class of the Code vm object.
398 static RawClass* instructions_class_; // Class of the Instructions vm object. 401 static RawClass* instructions_class_; // Class of the Instructions vm object.
399 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object. 402 static RawClass* pc_descriptors_class_; // Class of PcDescriptors vm object.
400 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors. 403 static RawClass* var_descriptors_class_; // Class of LocalVarDescriptors.
401 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers. 404 static RawClass* exception_handlers_class_; // Class of ExceptionHandlers.
402 static RawClass* context_class_; // Class of the Context vm object. 405 static RawClass* context_class_; // Class of the Context vm object.
(...skipping 1141 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 void set_token_index(intptr_t token_index) const { 1547 void set_token_index(intptr_t token_index) const {
1545 raw_ptr()->token_index_ = token_index; 1548 raw_ptr()->token_index_ = token_index;
1546 } 1549 }
1547 static RawField* New(); 1550 static RawField* New();
1548 1551
1549 HEAP_OBJECT_IMPLEMENTATION(Field, Object); 1552 HEAP_OBJECT_IMPLEMENTATION(Field, Object);
1550 friend class Class; 1553 friend class Class;
1551 }; 1554 };
1552 1555
1553 1556
1557 class LiteralToken : public Object {
1558 public:
1559 Token::Kind kind() const { return raw_ptr()->kind_; }
1560 RawString* literal() const { return raw_ptr()->literal_; }
1561 RawObject* value() const { return raw_ptr()->value_; }
1562
1563 RawLiteralToken* Canonicalize() const;
1564
1565 static intptr_t InstanceSize() {
1566 return RoundedAllocationSize(sizeof(RawLiteralToken));
1567 }
1568
1569 static RawLiteralToken* New();
1570 static RawLiteralToken* New(Token::Kind kind, const String& literal);
1571 static RawLiteralToken* NewCanonical(Token::Kind kind,
1572 const String& literal);
1573
1574 private:
1575 void set_kind(Token::Kind kind) const { raw_ptr()->kind_ = kind; }
1576 void set_literal(const String& literal) const;
1577 void set_value(const Object& value) const;
1578
1579 HEAP_OBJECT_IMPLEMENTATION(LiteralToken, Object);
1580 friend class Class;
1581 };
1582
1583
1554 class TokenStream : public Object { 1584 class TokenStream : public Object {
1555 public: 1585 public:
1556 inline intptr_t Length() const; 1586 inline intptr_t Length() const;
1557 1587
1558 inline Token::Kind KindAt(intptr_t index) const; 1588 inline Token::Kind KindAt(intptr_t index) const;
1559 1589
1560 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal); 1590 void SetTokenAt(intptr_t index, Token::Kind kind, const String& literal);
1591 void SetTokenAt(intptr_t index, const Object& token);
1561 1592
1562 RawObject* LiteralAt(intptr_t index) const { 1593 RawObject* TokenAt(intptr_t index) const;
1563 return *EntryAddr(index, RawTokenStream::kLiteralEntry); 1594 RawString* LiteralAt(intptr_t index) const;
1564 }
1565 1595
1566 static intptr_t InstanceSize() { 1596 static intptr_t InstanceSize() {
1567 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_)); 1597 ASSERT(sizeof(RawTokenStream) == OFFSET_OF(RawTokenStream, data_));
1568 return 0; 1598 return 0;
1569 } 1599 }
1570 static intptr_t InstanceSize(intptr_t len) { 1600 static intptr_t InstanceSize(intptr_t len) {
1571 return RoundedAllocationSize( 1601 return RoundedAllocationSize(
1572 sizeof(RawTokenStream) + 1602 sizeof(RawTokenStream) +
1573 (len * RawTokenStream::kNumberOfEntries * kWordSize)); 1603 (len * RawTokenStream::kNumberOfEntries * kWordSize));
1574 } 1604 }
1575 static intptr_t StreamLength(intptr_t len) { 1605 static intptr_t StreamLength(intptr_t len) {
1576 return (len * RawTokenStream::kNumberOfEntries); 1606 return (len * RawTokenStream::kNumberOfEntries);
1577 } 1607 }
1578 1608
1579 static RawTokenStream* New(intptr_t length); 1609 static RawTokenStream* New(intptr_t length);
1580 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens); 1610 static RawTokenStream* New(const Scanner::GrowableTokenStream& tokens);
1581 1611
1582 private: 1612 private:
1583 void SetLength(intptr_t value) const; 1613 void SetLength(intptr_t value) const;
1584 1614
1585 RawObject** EntryAddr(intptr_t index, intptr_t entry_offset) const { 1615 RawObject** EntryAddr(intptr_t index, intptr_t entry_offset) const {
1586 ASSERT((index >=0) && (index < Length())); 1616 ASSERT((index >=0) && (index < Length()));
1587 intptr_t data_index = 1617 intptr_t data_index =
1588 (index * RawTokenStream::kNumberOfEntries) + entry_offset; 1618 (index * RawTokenStream::kNumberOfEntries) + entry_offset;
hausner 2012/02/25 00:41:57 Does it still make sense to perform this computati
siva 2012/02/28 19:57:31 I added an ASSERT(kNumberofEntries == 1); and elim
1589 return &raw_ptr()->data_[data_index]; 1619 return &raw_ptr()->data_[data_index];
1590 } 1620 }
1591 1621
1592 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const { 1622 RawSmi** SmiAddr(intptr_t index, intptr_t entry_offset) const {
1593 return reinterpret_cast<RawSmi**>(EntryAddr(index, entry_offset)); 1623 return reinterpret_cast<RawSmi**>(EntryAddr(index, entry_offset));
1594 } 1624 }
1595 1625
1596 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object); 1626 HEAP_OBJECT_IMPLEMENTATION(TokenStream, Object);
1597 friend class Class; 1627 friend class Class;
1598 }; 1628 };
(...skipping 2127 matching lines...) Expand 10 before | Expand all | Expand 10 after
3726 raw_ptr()->value_ = Smi::New(value); 3756 raw_ptr()->value_ = Smi::New(value);
3727 } 3757 }
3728 3758
3729 3759
3730 intptr_t TokenStream::Length() const { 3760 intptr_t TokenStream::Length() const {
3731 return Smi::Value(raw_ptr()->length_); 3761 return Smi::Value(raw_ptr()->length_);
3732 } 3762 }
3733 3763
3734 3764
3735 Token::Kind TokenStream::KindAt(intptr_t index) const { 3765 Token::Kind TokenStream::KindAt(intptr_t index) const {
3736 return static_cast<Token::Kind>( 3766 const Object& obj = Object::Handle(TokenAt(index));
3737 Smi::Value(*SmiAddr(index, RawTokenStream::kKindEntry))); 3767 if (obj.IsSmi()) {
3768 return static_cast<Token::Kind>(
3769 Smi::Value(reinterpret_cast<RawSmi*>(obj.raw())));
3770 } else if (obj.IsLiteralToken()) {
3771 LiteralToken& token = LiteralToken::Handle();
3772 token ^= obj.raw();
3773 return token.kind();
3774 }
3775 ASSERT(obj.IsString()); // Must be an identifier.
3776 return Token::kIDENT;
3738 } 3777 }
3739 3778
3740 3779
3741 void Context::SetAt(intptr_t index, const Instance& value) const { 3780 void Context::SetAt(intptr_t index, const Instance& value) const {
3742 StorePointer(InstanceAddr(index), value.raw()); 3781 StorePointer(InstanceAddr(index), value.raw());
3743 } 3782 }
3744 3783
3745 } // namespace dart 3784 } // namespace dart
3746 3785
3747 #endif // VM_OBJECT_H_ 3786 #endif // VM_OBJECT_H_
OLDNEW
« no previous file with comments | « vm/dart.cc ('k') | vm/object.cc » ('j') | vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698