Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/become.h" | 10 #include "vm/become.h" |
| (...skipping 7435 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7446 ICData& ic_data = ICData::Handle(); | 7446 ICData& ic_data = ICData::Handle(); |
| 7447 for (intptr_t i = 1; i < array.Length(); i++) { | 7447 for (intptr_t i = 1; i < array.Length(); i++) { |
| 7448 ic_data ^= array.At(i); | 7448 ic_data ^= array.At(i); |
| 7449 if (ic_data.deopt_id() == deopt_id) { | 7449 if (ic_data.deopt_id() == deopt_id) { |
| 7450 ic_data.AddDeoptReason(reason); | 7450 ic_data.AddDeoptReason(reason); |
| 7451 } | 7451 } |
| 7452 } | 7452 } |
| 7453 } | 7453 } |
| 7454 | 7454 |
| 7455 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { | 7455 bool Function::CheckSourceFingerprint(const char* prefix, int32_t fp) const { |
| 7456 /* | |
|
rmacnak
2017/08/23 01:16:50
if (Isolate::Current()->flags->obfuscate) return;
Vyacheslav Egorov (Google)
2017/08/23 15:54:52
Done.
| |
| 7456 if ((kernel_offset() <= 0) && (SourceFingerprint() != fp)) { | 7457 if ((kernel_offset() <= 0) && (SourceFingerprint() != fp)) { |
| 7457 const bool recalculatingFingerprints = false; | 7458 const bool recalculatingFingerprints = false; |
| 7458 if (recalculatingFingerprints) { | 7459 if (recalculatingFingerprints) { |
| 7459 // This output can be copied into a file, then used with sed | 7460 // This output can be copied into a file, then used with sed |
| 7460 // to replace the old values. | 7461 // to replace the old values. |
| 7461 // sed -i.bak -f /tmp/newkeys runtime/vm/method_recognizer.h | 7462 // sed -i.bak -f /tmp/newkeys runtime/vm/method_recognizer.h |
| 7462 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); | 7463 THR_Print("s/0x%08x/0x%08x/\n", fp, SourceFingerprint()); |
| 7463 } else { | 7464 } else { |
| 7464 THR_Print( | 7465 THR_Print( |
| 7465 "FP mismatch while recognizing method %s:" | 7466 "FP mismatch while recognizing method %s:" |
| 7466 " expecting 0x%08x found 0x%08x\n", | 7467 " expecting 0x%08x found 0x%08x\n", |
| 7467 ToFullyQualifiedCString(), fp, SourceFingerprint()); | 7468 ToFullyQualifiedCString(), fp, SourceFingerprint()); |
| 7468 return false; | 7469 return false; |
| 7469 } | 7470 } |
| 7470 } | 7471 }*/ |
| 7471 return true; | 7472 return true; |
| 7472 } | 7473 } |
| 7473 | 7474 |
| 7474 RawCode* Function::EnsureHasCode() const { | 7475 RawCode* Function::EnsureHasCode() const { |
| 7475 if (HasCode()) return CurrentCode(); | 7476 if (HasCode()) return CurrentCode(); |
| 7476 Thread* thread = Thread::Current(); | 7477 Thread* thread = Thread::Current(); |
| 7477 Zone* zone = thread->zone(); | 7478 Zone* zone = thread->zone(); |
| 7478 const Object& result = | 7479 const Object& result = |
| 7479 Object::Handle(zone, Compiler::CompileFunction(thread, *this)); | 7480 Object::Handle(zone, Compiler::CompileFunction(thread, *this)); |
| 7480 if (result.IsError()) { | 7481 if (result.IsError()) { |
| (...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8649 }; | 8650 }; |
| 8650 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap; | 8651 typedef UnorderedHashMap<CompressedTokenTraits> CompressedTokenMap; |
| 8651 | 8652 |
| 8652 // Helper class for creation of compressed token stream data. | 8653 // Helper class for creation of compressed token stream data. |
| 8653 class CompressedTokenStreamData : public Scanner::TokenCollector { | 8654 class CompressedTokenStreamData : public Scanner::TokenCollector { |
| 8654 public: | 8655 public: |
| 8655 static const intptr_t kInitialBufferSize = 16 * KB; | 8656 static const intptr_t kInitialBufferSize = 16 * KB; |
| 8656 static const bool kPrintTokenObjects = false; | 8657 static const bool kPrintTokenObjects = false; |
| 8657 | 8658 |
| 8658 CompressedTokenStreamData(const GrowableObjectArray& ta, | 8659 CompressedTokenStreamData(const GrowableObjectArray& ta, |
| 8659 CompressedTokenMap* map) | 8660 CompressedTokenMap* map, |
| 8661 Obfuscator* obfuscator) | |
| 8660 : buffer_(NULL), | 8662 : buffer_(NULL), |
| 8661 stream_(&buffer_, Reallocate, kInitialBufferSize), | 8663 stream_(&buffer_, Reallocate, kInitialBufferSize), |
| 8662 token_objects_(ta), | 8664 token_objects_(ta), |
| 8663 tokens_(map), | 8665 tokens_(map), |
| 8666 str_(String::Handle()), | |
| 8664 value_(Object::Handle()), | 8667 value_(Object::Handle()), |
| 8665 fresh_index_smi_(Smi::Handle()), | 8668 fresh_index_smi_(Smi::Handle()), |
| 8666 num_tokens_collected_(0) {} | 8669 num_tokens_collected_(0), |
| 8670 obfuscator_(obfuscator) {} | |
| 8667 virtual ~CompressedTokenStreamData() {} | 8671 virtual ~CompressedTokenStreamData() {} |
| 8668 | 8672 |
| 8669 virtual void AddToken(const Scanner::TokenDescriptor& token) { | 8673 virtual void AddToken(const Scanner::TokenDescriptor& token) { |
| 8670 if (token.kind == Token::kIDENT) { // Identifier token. | 8674 if (token.kind == Token::kIDENT) { // Identifier token. |
| 8671 AddIdentToken(*token.literal); | 8675 AddIdentToken(*token.literal); |
| 8676 } else if (token.kind == Token::kINTERPOL_VAR) { | |
| 8677 str_ = token.literal->raw(); | |
| 8678 str_ = obfuscator_->Rename(str_); | |
| 8679 | |
| 8680 Scanner::TokenDescriptor token_copy = token; | |
| 8681 token_copy.literal = &str_; | |
| 8682 AddLiteralToken(token_copy); | |
| 8672 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token. | 8683 } else if (Token::NeedsLiteralToken(token.kind)) { // Literal token. |
| 8673 AddLiteralToken(token); | 8684 AddLiteralToken(token); |
| 8674 } else { // Keyword, pseudo keyword etc. | 8685 } else { // Keyword, pseudo keyword etc. |
| 8675 ASSERT(token.kind < Token::kNumTokens); | 8686 ASSERT(token.kind < Token::kNumTokens); |
| 8676 AddSimpleToken(token.kind); | 8687 AddSimpleToken(token.kind); |
| 8677 } | 8688 } |
| 8678 num_tokens_collected_++; | 8689 num_tokens_collected_++; |
| 8679 } | 8690 } |
| 8680 | 8691 |
| 8681 // Return the compressed token stream. | 8692 // Return the compressed token stream. |
| 8682 uint8_t* GetStream() const { return buffer_; } | 8693 uint8_t* GetStream() const { return buffer_; } |
| 8683 | 8694 |
| 8684 // Return the compressed token stream length. | 8695 // Return the compressed token stream length. |
| 8685 intptr_t Length() const { return stream_.bytes_written(); } | 8696 intptr_t Length() const { return stream_.bytes_written(); } |
| 8686 | 8697 |
| 8687 intptr_t NumTokens() const { return num_tokens_collected_; } | 8698 intptr_t NumTokens() const { return num_tokens_collected_; } |
| 8688 | 8699 |
| 8689 private: | 8700 private: |
| 8690 // Add an IDENT token into the stream and the token hash map. | 8701 // Add an IDENT token into the stream and the token hash map. |
| 8691 void AddIdentToken(const String& ident) { | 8702 void AddIdentToken(const String& ident) { |
| 8692 ASSERT(ident.IsSymbol()); | 8703 ASSERT(ident.IsSymbol()); |
| 8693 const intptr_t fresh_index = token_objects_.Length(); | 8704 const intptr_t fresh_index = token_objects_.Length(); |
| 8705 str_ = ident.raw(); | |
| 8706 str_ = obfuscator_->Rename(str_); | |
| 8694 fresh_index_smi_ = Smi::New(fresh_index); | 8707 fresh_index_smi_ = Smi::New(fresh_index); |
| 8695 intptr_t index = Smi::Value( | 8708 intptr_t index = Smi::Value( |
| 8696 Smi::RawCast(tokens_->InsertOrGetValue(ident, fresh_index_smi_))); | 8709 Smi::RawCast(tokens_->InsertOrGetValue(ident, fresh_index_smi_))); |
| 8697 if (index == fresh_index) { | 8710 if (index == fresh_index) { |
| 8698 token_objects_.Add(ident); | 8711 token_objects_.Add(str_); |
| 8699 if (kPrintTokenObjects) { | 8712 if (kPrintTokenObjects) { |
| 8700 int iid = Isolate::Current()->main_port() % 1024; | 8713 int iid = Isolate::Current()->main_port() % 1024; |
| 8701 OS::Print("ident %03x %p <%s>\n", iid, ident.raw(), | 8714 OS::Print("%03x ident <%s -> %s>\n", iid, ident.ToCString(), |
| 8702 ident.ToCString()); | 8715 str_.ToCString()); |
| 8703 } | 8716 } |
| 8704 } | 8717 } |
| 8705 WriteIndex(index); | 8718 WriteIndex(index); |
| 8706 } | 8719 } |
| 8707 | 8720 |
| 8708 // Add a LITERAL token into the stream and the token hash map. | 8721 // Add a LITERAL token into the stream and the token hash map. |
| 8709 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) { | 8722 void AddLiteralToken(const Scanner::TokenDescriptor& descriptor) { |
| 8710 ASSERT(descriptor.literal->IsSymbol()); | 8723 ASSERT(descriptor.literal->IsSymbol()); |
| 8711 bool is_present = false; | 8724 bool is_present = false; |
| 8712 value_ = tokens_->GetOrNull(descriptor, &is_present); | 8725 value_ = tokens_->GetOrNull(descriptor, &is_present); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8755 intptr_t old_size, | 8768 intptr_t old_size, |
| 8756 intptr_t new_size) { | 8769 intptr_t new_size) { |
| 8757 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size); | 8770 void* new_ptr = ::realloc(reinterpret_cast<void*>(ptr), new_size); |
| 8758 return reinterpret_cast<uint8_t*>(new_ptr); | 8771 return reinterpret_cast<uint8_t*>(new_ptr); |
| 8759 } | 8772 } |
| 8760 | 8773 |
| 8761 uint8_t* buffer_; | 8774 uint8_t* buffer_; |
| 8762 WriteStream stream_; | 8775 WriteStream stream_; |
| 8763 const GrowableObjectArray& token_objects_; | 8776 const GrowableObjectArray& token_objects_; |
| 8764 CompressedTokenMap* tokens_; | 8777 CompressedTokenMap* tokens_; |
| 8778 String& str_; | |
| 8765 Object& value_; | 8779 Object& value_; |
| 8766 Smi& fresh_index_smi_; | 8780 Smi& fresh_index_smi_; |
| 8767 intptr_t num_tokens_collected_; | 8781 intptr_t num_tokens_collected_; |
| 8782 Obfuscator* obfuscator_; | |
| 8768 | 8783 |
| 8769 DISALLOW_COPY_AND_ASSIGN(CompressedTokenStreamData); | 8784 DISALLOW_COPY_AND_ASSIGN(CompressedTokenStreamData); |
| 8770 }; | 8785 }; |
| 8771 | 8786 |
| 8772 RawTokenStream* TokenStream::New(const String& source, | 8787 RawTokenStream* TokenStream::New(const String& source, |
| 8773 const String& private_key, | 8788 const String& private_key, |
| 8774 bool use_shared_tokens) { | 8789 bool use_shared_tokens) { |
| 8775 Thread* thread = Thread::Current(); | 8790 Thread* thread = Thread::Current(); |
| 8776 Zone* zone = thread->zone(); | 8791 Zone* zone = thread->zone(); |
| 8777 | 8792 |
| 8778 GrowableObjectArray& token_objects = GrowableObjectArray::Handle(zone); | 8793 GrowableObjectArray& token_objects = GrowableObjectArray::Handle(zone); |
| 8779 Array& token_objects_map = Array::Handle(zone); | 8794 Array& token_objects_map = Array::Handle(zone); |
| 8780 if (use_shared_tokens) { | 8795 if (use_shared_tokens) { |
| 8781 // Use the shared token objects array in the object store. Allocate | 8796 // Use the shared token objects array in the object store. Allocate |
| 8782 // a new array if necessary. | 8797 // a new array if necessary. |
| 8783 ObjectStore* store = thread->isolate()->object_store(); | 8798 ObjectStore* store = thread->isolate()->object_store(); |
| 8784 if (store->token_objects() == GrowableObjectArray::null()) { | 8799 if (store->token_objects() == GrowableObjectArray::null()) { |
| 8785 OpenSharedTokenList(thread->isolate()); | 8800 OpenSharedTokenList(thread->isolate()); |
| 8786 } | 8801 } |
| 8787 token_objects = store->token_objects(); | 8802 token_objects = store->token_objects(); |
| 8788 token_objects_map = store->token_objects_map(); | 8803 token_objects_map = store->token_objects_map(); |
| 8789 } else { | 8804 } else { |
| 8790 // Use new, non-shared token array. | 8805 // Use new, non-shared token array. |
| 8791 const int kInitialPrivateCapacity = 256; | 8806 const int kInitialPrivateCapacity = 256; |
| 8792 token_objects = | 8807 token_objects = |
| 8793 GrowableObjectArray::New(kInitialPrivateCapacity, Heap::kOld); | 8808 GrowableObjectArray::New(kInitialPrivateCapacity, Heap::kOld); |
| 8794 token_objects_map = HashTables::New<CompressedTokenMap>( | 8809 token_objects_map = HashTables::New<CompressedTokenMap>( |
| 8795 kInitialPrivateCapacity, Heap::kOld); | 8810 kInitialPrivateCapacity, Heap::kOld); |
| 8796 } | 8811 } |
| 8812 Obfuscator obfuscator(thread, private_key); | |
| 8797 CompressedTokenMap map(token_objects_map.raw()); | 8813 CompressedTokenMap map(token_objects_map.raw()); |
| 8798 CompressedTokenStreamData data(token_objects, &map); | 8814 CompressedTokenStreamData data(token_objects, &map, &obfuscator); |
| 8799 Scanner scanner(source, private_key); | 8815 Scanner scanner(source, private_key); |
| 8800 scanner.ScanAll(&data); | 8816 scanner.ScanAll(&data); |
| 8801 INC_STAT(thread, num_tokens_scanned, data.NumTokens()); | 8817 INC_STAT(thread, num_tokens_scanned, data.NumTokens()); |
| 8802 | 8818 |
| 8803 // Create and setup the token stream object. | 8819 // Create and setup the token stream object. |
| 8804 const ExternalTypedData& stream = ExternalTypedData::Handle( | 8820 const ExternalTypedData& stream = ExternalTypedData::Handle( |
| 8805 zone, | 8821 zone, |
| 8806 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, data.GetStream(), | 8822 ExternalTypedData::New(kExternalTypedDataUint8ArrayCid, data.GetStream(), |
| 8807 data.Length(), Heap::kOld)); | 8823 data.Length(), Heap::kOld)); |
| 8808 intptr_t external_size = data.Length(); | 8824 intptr_t external_size = data.Length(); |
| (...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9229 return; | 9245 return; |
| 9230 } | 9246 } |
| 9231 | 9247 |
| 9232 Thread* thread = Thread::Current(); | 9248 Thread* thread = Thread::Current(); |
| 9233 Zone* zone = thread->zone(); | 9249 Zone* zone = thread->zone(); |
| 9234 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); | 9250 const TokenStream& tkns = TokenStream::Handle(zone, tokens()); |
| 9235 if (!tkns.IsNull()) { | 9251 if (!tkns.IsNull()) { |
| 9236 // Already tokenized. | 9252 // Already tokenized. |
| 9237 return; | 9253 return; |
| 9238 } | 9254 } |
| 9255 | |
| 9239 // Get the source, scan and allocate the token stream. | 9256 // Get the source, scan and allocate the token stream. |
| 9240 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); | 9257 VMTagScope tagScope(thread, VMTag::kCompileScannerTagId); |
| 9241 CSTAT_TIMER_SCOPE(thread, scanner_timer); | 9258 CSTAT_TIMER_SCOPE(thread, scanner_timer); |
| 9242 const String& src = String::Handle(zone, Source()); | 9259 const String& src = String::Handle(zone, Source()); |
| 9243 const TokenStream& ts = TokenStream::Handle( | 9260 const TokenStream& ts = TokenStream::Handle( |
| 9244 zone, TokenStream::New(src, private_key, use_shared_tokens)); | 9261 zone, TokenStream::New(src, private_key, use_shared_tokens)); |
| 9245 set_tokens(ts); | 9262 set_tokens(ts); |
| 9246 INC_STAT(thread, src_length, src.Length()); | 9263 INC_STAT(thread, src_length, src.Length()); |
| 9247 } | 9264 } |
| 9248 | 9265 |
| (...skipping 13190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 22439 } | 22456 } |
| 22440 return UserTag::null(); | 22457 return UserTag::null(); |
| 22441 } | 22458 } |
| 22442 | 22459 |
| 22443 const char* UserTag::ToCString() const { | 22460 const char* UserTag::ToCString() const { |
| 22444 const String& tag_label = String::Handle(label()); | 22461 const String& tag_label = String::Handle(label()); |
| 22445 return tag_label.ToCString(); | 22462 return tag_label.ToCString(); |
| 22446 } | 22463 } |
| 22447 | 22464 |
| 22448 } // namespace dart | 22465 } // namespace dart |
| OLD | NEW |