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

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

Issue 1420103006: Shared token objects (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: catch up Created 5 years, 1 month 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_store.h » ('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 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
659 cls = Class::New<Array>(); 659 cls = Class::New<Array>();
660 isolate->object_store()->set_array_class(cls); 660 isolate->object_store()->set_array_class(cls);
661 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); 661 cls.set_type_arguments_field_offset(Array::type_arguments_offset());
662 cls.set_num_type_arguments(1); 662 cls.set_num_type_arguments(1);
663 cls.set_num_own_type_arguments(1); 663 cls.set_num_own_type_arguments(1);
664 cls = Class::New<Array>(kImmutableArrayCid); 664 cls = Class::New<Array>(kImmutableArrayCid);
665 isolate->object_store()->set_immutable_array_class(cls); 665 isolate->object_store()->set_immutable_array_class(cls);
666 cls.set_type_arguments_field_offset(Array::type_arguments_offset()); 666 cls.set_type_arguments_field_offset(Array::type_arguments_offset());
667 cls.set_num_type_arguments(1); 667 cls.set_num_type_arguments(1);
668 cls.set_num_own_type_arguments(1); 668 cls.set_num_own_type_arguments(1);
669 cls = Class::New<GrowableObjectArray>();
670 isolate->object_store()->set_growable_object_array_class(cls);
671 cls.set_type_arguments_field_offset(
672 GrowableObjectArray::type_arguments_offset());
673 cls.set_num_type_arguments(1);
669 cls = Class::NewStringClass(kOneByteStringCid); 674 cls = Class::NewStringClass(kOneByteStringCid);
670 isolate->object_store()->set_one_byte_string_class(cls); 675 isolate->object_store()->set_one_byte_string_class(cls);
671 cls = Class::NewStringClass(kTwoByteStringCid); 676 cls = Class::NewStringClass(kTwoByteStringCid);
672 isolate->object_store()->set_two_byte_string_class(cls); 677 isolate->object_store()->set_two_byte_string_class(cls);
673 cls = Class::New<Mint>(); 678 cls = Class::New<Mint>();
674 isolate->object_store()->set_mint_class(cls); 679 isolate->object_store()->set_mint_class(cls);
675 cls = Class::New<Bigint>(); 680 cls = Class::New<Bigint>();
676 isolate->object_store()->set_bigint_class(cls); 681 isolate->object_store()->set_bigint_class(cls);
677 cls = Class::New<Double>(); 682 cls = Class::New<Double>();
678 isolate->object_store()->set_double_class(cls); 683 isolate->object_store()->set_double_class(cls);
(...skipping 2397 matching lines...) Expand 10 before | Expand all | Expand 10 after
3076 String::Handle(BuildClosureSource(param_names, expr)); 3081 String::Handle(BuildClosureSource(param_names, expr));
3077 Script& script = Script::Handle(); 3082 Script& script = Script::Handle();
3078 script = Script::New(Symbols::EvalSourceUri(), 3083 script = Script::New(Symbols::EvalSourceUri(),
3079 func_src, 3084 func_src,
3080 RawScript::kEvaluateTag); 3085 RawScript::kEvaluateTag);
3081 // In order to tokenize the source, we need to get the key to mangle 3086 // In order to tokenize the source, we need to get the key to mangle
3082 // private names from the library from which the class originates. 3087 // private names from the library from which the class originates.
3083 const Library& lib = Library::Handle(cls.library()); 3088 const Library& lib = Library::Handle(cls.library());
3084 ASSERT(!lib.IsNull()); 3089 ASSERT(!lib.IsNull());
3085 const String& lib_key = String::Handle(lib.private_key()); 3090 const String& lib_key = String::Handle(lib.private_key());
3086 script.Tokenize(lib_key); 3091 script.Tokenize(lib_key, false);
3087 3092
3088 const Function& func = Function::Handle( 3093 const Function& func = Function::Handle(
3089 Function::NewEvalFunction(cls, script, is_static)); 3094 Function::NewEvalFunction(cls, script, is_static));
3090 func.set_result_type(Object::dynamic_type()); 3095 func.set_result_type(Object::dynamic_type());
3091 const intptr_t num_implicit_params = is_static ? 0 : 1; 3096 const intptr_t num_implicit_params = is_static ? 0 : 1;
3092 func.set_num_fixed_parameters(num_implicit_params + param_names.Length()); 3097 func.set_num_fixed_parameters(num_implicit_params + param_names.Length());
3093 func.SetNumOptionalParameters(0, true); 3098 func.SetNumOptionalParameters(0, true);
3094 func.SetIsOptimizable(false); 3099 func.SetIsOptimizable(false);
3095 return func.raw(); 3100 return func.raw();
3096 } 3101 }
(...skipping 4958 matching lines...) Expand 10 before | Expand all | Expand 10 after
8055 const String& token = String::Handle(literal()); 8060 const String& token = String::Handle(literal());
8056 return token.ToCString(); 8061 return token.ToCString();
8057 } 8062 }
8058 8063
8059 8064
8060 void LiteralToken::PrintJSONImpl(JSONStream* stream, bool ref) const { 8065 void LiteralToken::PrintJSONImpl(JSONStream* stream, bool ref) const {
8061 Object::PrintJSONImpl(stream, ref); 8066 Object::PrintJSONImpl(stream, ref);
8062 } 8067 }
8063 8068
8064 8069
8065 RawArray* TokenStream::TokenObjects() const { 8070 RawGrowableObjectArray* TokenStream::TokenObjects() const {
8066 return raw_ptr()->token_objects_; 8071 return raw_ptr()->token_objects_;
8067 } 8072 }
8068 8073
8069 8074
8070 void TokenStream::SetTokenObjects(const Array& value) const { 8075 void TokenStream::SetTokenObjects(const GrowableObjectArray& value) const {
8071 StorePointer(&raw_ptr()->token_objects_, value.raw()); 8076 StorePointer(&raw_ptr()->token_objects_, value.raw());
8072 } 8077 }
8073 8078
8074 8079
8075 RawExternalTypedData* TokenStream::GetStream() const { 8080 RawExternalTypedData* TokenStream::GetStream() const {
8076 return raw_ptr()->stream_; 8081 return raw_ptr()->stream_;
8077 } 8082 }
8078 8083
8079 8084
8080 void TokenStream::SetStream(const ExternalTypedData& value) const { 8085 void TokenStream::SetStream(const ExternalTypedData& value) const {
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
8342 return descriptor.literal->Hash(); 8347 return descriptor.literal->Hash();
8343 } 8348 }
8344 8349
8345 static uword Hash(const Object& key) { 8350 static uword Hash(const Object& key) {
8346 if (key.IsLiteralToken()) { 8351 if (key.IsLiteralToken()) {
8347 return String::HashRawSymbol(LiteralToken::Cast(key).literal()); 8352 return String::HashRawSymbol(LiteralToken::Cast(key).literal());
8348 } else { 8353 } else {
8349 return String::Cast(key).Hash(); 8354 return String::Cast(key).Hash();
8350 } 8355 }
8351 } 8356 }
8352
8353 static RawObject* NewKey(const Scanner::TokenDescriptor& descriptor) {
8354 return LiteralToken::New(descriptor.kind, *descriptor.literal);
8355 }
8356 }; 8357 };
8357 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap; 8358 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap;
8358 8359
8359 8360
8360 // Helper class for creation of compressed token stream data. 8361 // Helper class for creation of compressed token stream data.
8361 class CompressedTokenStreamData : public ValueObject { 8362 class CompressedTokenStreamData : public ValueObject {
8362 public: 8363 public:
8363 static const intptr_t kInitialBufferSize = 16 * KB; 8364 static const intptr_t kInitialBufferSize = 16 * KB;
8364 CompressedTokenStreamData() : 8365 static const bool kPrintTokenObjects = false;
8366
8367 CompressedTokenStreamData(const GrowableObjectArray& ta,
8368 CompressedTokenMap* map) :
8365 buffer_(NULL), 8369 buffer_(NULL),
8366 stream_(&buffer_, Reallocate, kInitialBufferSize), 8370 stream_(&buffer_, Reallocate, kInitialBufferSize),
8367 tokens_(HashTables::New<CompressedTokenMap>(kInitialTableSize)) { 8371 token_objects_(ta),
8368 } 8372 tokens_(map),
8369 ~CompressedTokenStreamData() { 8373 value_(Object::Handle()),
8370 // Safe to discard the hash table now. 8374 fresh_index_smi_(Smi::Handle()) {
8371 tokens_.Release();
8372 } 8375 }
8373 8376
8374 // Add an IDENT token into the stream and the token hash map. 8377 // Add an IDENT token into the stream and the token hash map.
8375 void AddIdentToken(const String* ident) { 8378 void AddIdentToken(const String& ident) {
8376 ASSERT(ident->IsSymbol()); 8379 ASSERT(ident.IsSymbol());
8377 const intptr_t fresh_index = tokens_.NumOccupied(); 8380 const intptr_t fresh_index = token_objects_.Length();
8381 fresh_index_smi_ = Smi::New(fresh_index);
8378 intptr_t index = Smi::Value(Smi::RawCast( 8382 intptr_t index = Smi::Value(Smi::RawCast(
8379 tokens_.InsertOrGetValue(*ident, 8383 tokens_->InsertOrGetValue(ident, fresh_index_smi_)));
8380 Smi::Handle(Smi::New(fresh_index))))); 8384 if (index == fresh_index) {
8385 token_objects_.Add(ident);
8386 if (kPrintTokenObjects) {
8387 int iid = Isolate::Current()->main_port() % 1024;
8388 OS::Print("ident %03x %p <%s>\n",
8389 iid, ident.raw(), ident.ToCString());
8390 }
8391 }
8381 WriteIndex(index); 8392 WriteIndex(index);
8382 } 8393 }
8383 8394
8384 // Add a LITERAL token into the stream and the token hash map. 8395 // Add a LITERAL token into the stream and the token hash map.
8385 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) { 8396 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) {
8386 ASSERT(descriptor.literal->IsSymbol()); 8397 ASSERT(descriptor.literal->IsSymbol());
8387 const intptr_t fresh_index = tokens_.NumOccupied(); 8398 bool is_present = false;
8388 intptr_t index = Smi::Value(Smi::RawCast( 8399 value_ = tokens_->GetOrNull(descriptor, &is_present);
8389 tokens_.InsertNewOrGetValue(descriptor, 8400 intptr_t index = -1;
8390 Smi::Handle(Smi::New(fresh_index))))); 8401 if (is_present) {
8402 ASSERT(value_.IsSmi());
8403 index = Smi::Cast(value_).Value();
8404 } else {
8405 const intptr_t fresh_index = token_objects_.Length();
8406 fresh_index_smi_ = Smi::New(fresh_index);
8407 const LiteralToken& lit = LiteralToken::Handle(
8408 LiteralToken::New(descriptor.kind, *descriptor.literal));
8409 index = Smi::Value(Smi::RawCast(
8410 tokens_->InsertOrGetValue(lit, fresh_index_smi_)));
8411 token_objects_.Add(lit);
8412 if (kPrintTokenObjects) {
8413 int iid = Isolate::Current()->main_port() % 1024;
8414 printf("lit %03x %p %p %p <%s>\n",
8415 iid, token_objects_.raw(), lit.literal(), lit.value(),
8416 String::Handle(lit.literal()).ToCString());
8417 }
8418 }
8391 WriteIndex(index); 8419 WriteIndex(index);
8392 } 8420 }
8393 8421
8394 // Add a simple token into the stream. 8422 // Add a simple token into the stream.
8395 void AddSimpleToken(intptr_t kind) { 8423 void AddSimpleToken(intptr_t kind) {
8396 stream_.WriteUnsigned(kind); 8424 stream_.WriteUnsigned(kind);
8397 } 8425 }
8398 8426
8399 // Return the compressed token stream. 8427 // Return the compressed token stream.
8400 uint8_t* GetStream() const { return buffer_; } 8428 uint8_t* GetStream() const { return buffer_; }
8401 8429
8402 // Return the compressed token stream length. 8430 // Return the compressed token stream length.
8403 intptr_t Length() const { return stream_.bytes_written(); } 8431 intptr_t Length() const { return stream_.bytes_written(); }
8404 8432
8405 // Generate and return the token objects array.
8406 RawArray* MakeTokenObjectsArray() const {
8407 Array& result = Array::Handle(
8408 Array::New(tokens_.NumOccupied(), Heap::kOld));
8409 CompressedTokenMap::Iterator it(&tokens_);
8410 Object& key = Object::Handle();
8411 while (it.MoveNext()) {
8412 intptr_t entry = it.Current();
8413 key = tokens_.GetKey(entry);
8414 result.SetAt(Smi::Value(Smi::RawCast(tokens_.GetPayload(entry, 0))), key);
8415 }
8416 return result.raw();
8417 }
8418
8419 private: 8433 private:
8420 void WriteIndex(intptr_t value) { 8434 void WriteIndex(intptr_t value) {
8421 stream_.WriteUnsigned(value + Token::kNumTokens); 8435 stream_.WriteUnsigned(value + Token::kNumTokens);
8422 } 8436 }
8423 8437
8424 static uint8_t* Reallocate(uint8_t* ptr, 8438 static uint8_t* Reallocate(uint8_t* ptr,
8425 intptr_t old_size, 8439 intptr_t old_size,
8426 intptr_t new_size) { 8440 intptr_t new_size) {
8427 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size); 8441 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size);
8428 return reinterpret_cast<uint8_t*>(new_ptr); 8442 return reinterpret_cast<uint8_t*>(new_ptr);
8429 } 8443 }
8430 8444
8431 static const intptr_t kInitialTableSize = 32;
8432
8433 uint8_t* buffer_; 8445 uint8_t* buffer_;
8434 WriteStream stream_; 8446 WriteStream stream_;
8435 CompressedTokenMap tokens_; 8447 const GrowableObjectArray& token_objects_;
8448 CompressedTokenMap* tokens_;
8449 Object& value_;
8450 Smi& fresh_index_smi_;
8436 8451
8437 DISALLOW_COPY_AND_ASSIGN(CompressedTokenStreamData); 8452 DISALLOW_COPY_AND_ASSIGN(CompressedTokenStreamData);
8438 }; 8453 };
8439 8454
8440 8455
8441 RawTokenStream* TokenStream::New(const Scanner::GrowableTokenStream& tokens, 8456 RawTokenStream* TokenStream::New(const Scanner::GrowableTokenStream& tokens,
8442 const String& private_key) { 8457 const String& private_key,
8443 Zone* zone = Thread::Current()->zone(); 8458 bool use_shared_tokens) {
8459 Thread* thread = Thread::Current();
8460 Zone* zone = thread->zone();
8444 // Copy the relevant data out of the scanner into a compressed stream of 8461 // Copy the relevant data out of the scanner into a compressed stream of
8445 // tokens. 8462 // tokens.
8446 CompressedTokenStreamData data; 8463
8464 GrowableObjectArray& token_objects = GrowableObjectArray::Handle(zone);
8465 Array& token_objects_map = Array::Handle(zone);
8466 if (use_shared_tokens) {
8467 // Use the shared token objects array in the object store. Allocate
8468 // a new array if necessary.
8469 ObjectStore* store = thread->isolate()->object_store();
8470 if (store->token_objects() == GrowableObjectArray::null()) {
8471 OpenSharedTokenList(thread->isolate());
8472 }
8473 token_objects = store->token_objects();
8474 token_objects_map = store->token_objects_map();
8475 } else {
8476 // Use new, non-shared token array.
8477 const int kInitialPrivateCapacity = 256;
8478 token_objects =
8479 GrowableObjectArray::New(kInitialPrivateCapacity, Heap::kOld);
8480 token_objects_map =
8481 HashTables::New<CompressedTokenMap>(kInitialPrivateCapacity,
8482 Heap::kOld);
8483 }
8484 CompressedTokenMap map(token_objects_map.raw());
8485 CompressedTokenStreamData data(token_objects, &map);
8486
8447 intptr_t len = tokens.length(); 8487 intptr_t len = tokens.length();
8448 for (intptr_t i = 0; i < len; i++) { 8488 for (intptr_t i = 0; i < len; i++) {
8449 Scanner::TokenDescriptor token = tokens[i]; 8489 Scanner::TokenDescriptor token = tokens[i];
8450 if (token.kind == Token::kIDENT) { // Identifier token. 8490 if (token.kind == Token::kIDENT) { // Identifier token.
8451 data.AddIdentToken(token.literal); 8491 data.AddIdentToken(*token.literal);
8452 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token. 8492 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token.
8453 data.AddLiteralToken(token); 8493 data.AddLiteralToken(token);
8454 } else { // Keyword, pseudo keyword etc. 8494 } else { // Keyword, pseudo keyword etc.
8455 ASSERT(token.kind < Token::kNumTokens); 8495 ASSERT(token.kind < Token::kNumTokens);
8456 data.AddSimpleToken(token.kind); 8496 data.AddSimpleToken(token.kind);
8457 } 8497 }
8458 } 8498 }
8459 data.AddSimpleToken(Token::kEOS); // End of stream. 8499 data.AddSimpleToken(Token::kEOS); // End of stream.
8460 8500
8461 // Create and setup the token stream object. 8501 // Create and setup the token stream object.
8462 const ExternalTypedData& stream = ExternalTypedData::Handle( 8502 const ExternalTypedData& stream = ExternalTypedData::Handle(
8463 zone, 8503 zone,
8464 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, 8504 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid,
8465 data.GetStream(), data.Length(), Heap::kOld)); 8505 data.GetStream(), data.Length(), Heap::kOld));
8466 stream.AddFinalizer(data.GetStream(), DataFinalizer); 8506 stream.AddFinalizer(data.GetStream(), DataFinalizer);
8467 const TokenStream& result = TokenStream::Handle(zone, New()); 8507 const TokenStream& result = TokenStream::Handle(zone, New());
8468 result.SetPrivateKey(private_key); 8508 result.SetPrivateKey(private_key);
8469 const Array& token_objects =
8470 Array::Handle(zone, data.MakeTokenObjectsArray());
8471 { 8509 {
8472 NoSafepointScope no_safepoint; 8510 NoSafepointScope no_safepoint;
8473 result.SetStream(stream); 8511 result.SetStream(stream);
8474 result.SetTokenObjects(token_objects); 8512 result.SetTokenObjects(token_objects);
8475 } 8513 }
8514
8515 token_objects_map = map.Release().raw();
8516 if (use_shared_tokens) {
8517 thread->isolate()->object_store()->set_token_objects_map(token_objects_map);
8518 }
8476 return result.raw(); 8519 return result.raw();
8477 } 8520 }
8478 8521
8479 8522
8523 void TokenStream::OpenSharedTokenList(Isolate* isolate) {
8524 const int kInitialSharedCapacity = 5*1024;
8525 ObjectStore* store = isolate->object_store();
8526 ASSERT(store->token_objects() == GrowableObjectArray::null());
8527 const GrowableObjectArray& token_objects = GrowableObjectArray::Handle(
8528 GrowableObjectArray::New(kInitialSharedCapacity, Heap::kOld));
8529 store->set_token_objects(token_objects);
8530 const Array& token_objects_map = Array::Handle(
8531 HashTables::New<CompressedTokenMap>(kInitialSharedCapacity,
8532 Heap::kOld));
8533 store->set_token_objects_map(token_objects_map);
8534 }
8535
8536
8537 void TokenStream::CloseSharedTokenList(Isolate* isolate) {
8538 isolate->object_store()->set_token_objects(GrowableObjectArray::Handle());
8539 isolate->object_store()->set_token_objects_map(Array::null_array());
8540 }
8541
8542
8480 const char* TokenStream::ToCString() const { 8543 const char* TokenStream::ToCString() const {
8481 return "TokenStream"; 8544 return "TokenStream";
8482 } 8545 }
8483 8546
8484 8547
8485 void TokenStream::PrintJSONImpl(JSONStream* stream, bool ref) const { 8548 void TokenStream::PrintJSONImpl(JSONStream* stream, bool ref) const {
8486 JSONObject jsobj(stream); 8549 JSONObject jsobj(stream);
8487 AddCommonObjectProperties(&jsobj, "Object", ref); 8550 AddCommonObjectProperties(&jsobj, "Object", ref);
8488 // TODO(johnmccutchan): Generate a stable id. TokenStreams hang off 8551 // TODO(johnmccutchan): Generate a stable id. TokenStreams hang off
8489 // a Script object but do not have a back reference to generate a stable id. 8552 // a Script object but do not have a back reference to generate a stable id.
8490 jsobj.AddServiceId(*this); 8553 jsobj.AddServiceId(*this);
8491 if (ref) { 8554 if (ref) {
8492 return; 8555 return;
8493 } 8556 }
8494 const String& private_key = String::Handle(PrivateKey()); 8557 const String& private_key = String::Handle(PrivateKey());
8495 jsobj.AddProperty("privateKey", private_key); 8558 jsobj.AddProperty("privateKey", private_key);
8496 // TODO(johnmccutchan): Add support for printing LiteralTokens and add 8559 // TODO(johnmccutchan): Add support for printing LiteralTokens and add
8497 // them to members array. 8560 // them to members array.
8498 JSONArray members(&jsobj, "members"); 8561 JSONArray members(&jsobj, "members");
8499 } 8562 }
8500 8563
8501 8564
8502 TokenStream::Iterator::Iterator(const TokenStream& tokens, 8565 TokenStream::Iterator::Iterator(const TokenStream& tokens,
8503 intptr_t token_pos, 8566 intptr_t token_pos,
8504 Iterator::StreamType stream_type) 8567 Iterator::StreamType stream_type)
8505 : tokens_(TokenStream::Handle(tokens.raw())), 8568 : tokens_(TokenStream::Handle(tokens.raw())),
8506 data_(ExternalTypedData::Handle(tokens.GetStream())), 8569 data_(ExternalTypedData::Handle(tokens.GetStream())),
8507 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()), 8570 stream_(reinterpret_cast<uint8_t*>(data_.DataAddr(0)), data_.Length()),
8508 token_objects_(Array::Handle(tokens.TokenObjects())), 8571 token_objects_(GrowableObjectArray::Handle(tokens.TokenObjects())),
8509 obj_(Object::Handle()), 8572 obj_(Object::Handle()),
8510 cur_token_pos_(token_pos), 8573 cur_token_pos_(token_pos),
8511 cur_token_kind_(Token::kILLEGAL), 8574 cur_token_kind_(Token::kILLEGAL),
8512 cur_token_obj_index_(-1), 8575 cur_token_obj_index_(-1),
8513 stream_type_(stream_type) { 8576 stream_type_(stream_type) {
8514 SetCurrentPosition(token_pos); 8577 SetCurrentPosition(token_pos);
8515 } 8578 }
8516 8579
8517 8580
8518 void TokenStream::Iterator::SetStream(const TokenStream& tokens, 8581 void TokenStream::Iterator::SetStream(const TokenStream& tokens,
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
8769 void Script::set_kind(RawScript::Kind value) const { 8832 void Script::set_kind(RawScript::Kind value) const {
8770 StoreNonPointer(&raw_ptr()->kind_, value); 8833 StoreNonPointer(&raw_ptr()->kind_, value);
8771 } 8834 }
8772 8835
8773 8836
8774 void Script::set_tokens(const TokenStream& value) const { 8837 void Script::set_tokens(const TokenStream& value) const {
8775 StorePointer(&raw_ptr()->tokens_, value.raw()); 8838 StorePointer(&raw_ptr()->tokens_, value.raw());
8776 } 8839 }
8777 8840
8778 8841
8779 void Script::Tokenize(const String& private_key) const { 8842 void Script::Tokenize(const String& private_key,
8843 bool use_shared_tokens) const {
8780 Thread* thread = Thread::Current(); 8844 Thread* thread = Thread::Current();
8781 Zone* zone = thread->zone(); 8845 Zone* zone = thread->zone();
8782 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); 8846 const TokenStream& tkns = TokenStream::Handle(zone, tokens());
8783 if (!tkns.IsNull()) { 8847 if (!tkns.IsNull()) {
8784 // Already tokenized. 8848 // Already tokenized.
8785 return; 8849 return;
8786 } 8850 }
8787 // Get the source, scan and allocate the token stream. 8851 // Get the source, scan and allocate the token stream.
8788 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); 8852 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId);
8789 CSTAT_TIMER_SCOPE(thread, scanner_timer); 8853 CSTAT_TIMER_SCOPE(thread, scanner_timer);
8790 const String& src = String::Handle(zone, Source()); 8854 const String& src = String::Handle(zone, Source());
8791 Scanner scanner(src, private_key); 8855 Scanner scanner(src, private_key);
8792 const Scanner::GrowableTokenStream& ts = scanner.GetStream(); 8856 const Scanner::GrowableTokenStream& ts = scanner.GetStream();
8793 INC_STAT(thread, num_tokens_scanned, ts.length()); 8857 INC_STAT(thread, num_tokens_scanned, ts.length());
8794 set_tokens(TokenStream::Handle(zone, TokenStream::New(ts, private_key))); 8858 set_tokens(TokenStream::Handle(zone,
8859 TokenStream::New(ts, private_key, use_shared_tokens)));
8795 INC_STAT(thread, src_length, src.Length()); 8860 INC_STAT(thread, src_length, src.Length());
8796 } 8861 }
8797 8862
8798 8863
8799 void Script::SetLocationOffset(intptr_t line_offset, 8864 void Script::SetLocationOffset(intptr_t line_offset,
8800 intptr_t col_offset) const { 8865 intptr_t col_offset) const {
8801 ASSERT(line_offset >= 0); 8866 ASSERT(line_offset >= 0);
8802 ASSERT(col_offset >= 0); 8867 ASSERT(col_offset >= 0);
8803 StoreNonPointer(&raw_ptr()->line_offset_, line_offset); 8868 StoreNonPointer(&raw_ptr()->line_offset_, line_offset);
8804 StoreNonPointer(&raw_ptr()->col_offset_, col_offset); 8869 StoreNonPointer(&raw_ptr()->col_offset_, col_offset);
(...skipping 13043 matching lines...) Expand 10 before | Expand all | Expand 10 after
21848 return tag_label.ToCString(); 21913 return tag_label.ToCString();
21849 } 21914 }
21850 21915
21851 21916
21852 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 21917 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
21853 Instance::PrintJSONImpl(stream, ref); 21918 Instance::PrintJSONImpl(stream, ref);
21854 } 21919 }
21855 21920
21856 21921
21857 } // namespace dart 21922 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_store.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698