OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 RUNTIME_VM_PRECOMPILER_H_ | 5 #ifndef RUNTIME_VM_PRECOMPILER_H_ |
6 #define RUNTIME_VM_PRECOMPILER_H_ | 6 #define RUNTIME_VM_PRECOMPILER_H_ |
7 | 7 |
8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
9 #include "vm/hash_map.h" | 9 #include "vm/hash_map.h" |
10 #include "vm/hash_table.h" | 10 #include "vm/hash_table.h" |
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
391 void DropTypeArguments(); | 391 void DropTypeArguments(); |
392 void DropScriptData(); | 392 void DropScriptData(); |
393 void DropLibraryEntries(); | 393 void DropLibraryEntries(); |
394 void DropClasses(); | 394 void DropClasses(); |
395 void DropLibraries(); | 395 void DropLibraries(); |
396 | 396 |
397 void BindStaticCalls(); | 397 void BindStaticCalls(); |
398 void SwitchICCalls(); | 398 void SwitchICCalls(); |
399 void ResetPrecompilerState(); | 399 void ResetPrecompilerState(); |
400 | 400 |
| 401 void Obfuscate(); |
| 402 |
401 void CollectDynamicFunctionNames(); | 403 void CollectDynamicFunctionNames(); |
402 | 404 |
403 void PrecompileStaticInitializers(); | 405 void PrecompileStaticInitializers(); |
404 void PrecompileConstructors(); | 406 void PrecompileConstructors(); |
405 | 407 |
406 void FinalizeAllClasses(); | 408 void FinalizeAllClasses(); |
407 void VerifyJITFeedback(); | 409 void VerifyJITFeedback(); |
408 RawScript* LookupScript(const char* uri); | 410 RawScript* LookupScript(const char* uri); |
409 intptr_t MapCid(intptr_t feedback_cid); | 411 intptr_t MapCid(intptr_t feedback_cid); |
410 | 412 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
469 } else { | 471 } else { |
470 ASSERT(String::Cast(obj).IsSymbol()); | 472 ASSERT(String::Cast(obj).IsSymbol()); |
471 return String::Cast(obj).Hash(); | 473 return String::Cast(obj).Hash(); |
472 } | 474 } |
473 } | 475 } |
474 static RawObject* NewKey(const Function& function) { return function.raw(); } | 476 static RawObject* NewKey(const Function& function) { return function.raw(); } |
475 }; | 477 }; |
476 | 478 |
477 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; | 479 typedef UnorderedHashSet<FunctionsTraits> UniqueFunctionsSet; |
478 | 480 |
| 481 #if defined(DART_PRECOMPILER) |
| 482 // ObfuscationMap maps Strings to Strings. |
| 483 class ObfuscationMapTraits { |
| 484 public: |
| 485 static const char* Name() { return "ObfuscationMapTraits"; } |
| 486 static bool ReportStats() { return false; } |
| 487 |
| 488 // Only for non-descriptor lookup and table expansion. |
| 489 static bool IsMatch(const Object& a, const Object& b) { |
| 490 return a.raw() == b.raw(); |
| 491 } |
| 492 |
| 493 static uword Hash(const Object& key) { return String::Cast(key).Hash(); } |
| 494 }; |
| 495 typedef UnorderedHashMap<ObfuscationMapTraits> ObfuscationMap; |
| 496 |
| 497 class Obfuscator { |
| 498 public: |
| 499 Obfuscator(Thread* thread, const String& private_key); |
| 500 ~Obfuscator(); |
| 501 |
| 502 RawString* Rename(const String& name, bool atomic = false) { |
| 503 if (state_ == NULL) { |
| 504 return name.raw(); |
| 505 } |
| 506 |
| 507 return state_->RenameImpl(name, atomic); |
| 508 } |
| 509 |
| 510 static void ObfuscateSymbolInstance(Thread* thread, const Instance& instance); |
| 511 |
| 512 static void Deobfuscate(Thread* thread, const GrowableObjectArray& pieces); |
| 513 |
| 514 private: |
| 515 void InitializeRenamingMap(Isolate* isolate); |
| 516 void PreventRenaming(Dart_QualifiedFunctionName* entry_points); |
| 517 void PreventRenaming(const char* name); |
| 518 void PreventRenaming(const String& name) { state_->PreventRenaming(name); } |
| 519 |
| 520 static const intptr_t kSavedStateNameIndex = 0; |
| 521 static const intptr_t kSavedStateRenamesIndex = 1; |
| 522 static const intptr_t kSavedStateSize = 2; |
| 523 |
| 524 static RawArray* GetRenamesFromSavedState(const Array& saved_state) { |
| 525 Array& renames = Array::Handle(); |
| 526 renames ^= saved_state.At(kSavedStateRenamesIndex); |
| 527 return renames.raw(); |
| 528 } |
| 529 |
| 530 static RawString* GetNameFromSavedState(const Array& saved_state) { |
| 531 String& name = String::Handle(); |
| 532 name ^= saved_state.At(kSavedStateNameIndex); |
| 533 return name.raw(); |
| 534 } |
| 535 |
| 536 class ObfuscationState : public ZoneAllocated { |
| 537 public: |
| 538 ObfuscationState(Thread* thread, |
| 539 const Array& saved_state, |
| 540 const String& private_key) |
| 541 : thread_(thread), |
| 542 saved_state_(saved_state), |
| 543 renames_(GetRenamesFromSavedState(saved_state)), |
| 544 private_key_(private_key), |
| 545 string_(String::Handle(thread->zone())), |
| 546 renamed_(String::Handle(thread->zone())) { |
| 547 memset(name_, 0, sizeof(name_)); |
| 548 |
| 549 string_ = GetNameFromSavedState(saved_state); |
| 550 if (!string_.IsNull()) { |
| 551 string_.ToUTF8(reinterpret_cast<uint8_t*>(name_), sizeof(name_)); |
| 552 } |
| 553 } |
| 554 |
| 555 void SaveState(); |
| 556 |
| 557 RawString* RenameImpl(const String& name, bool atomic); |
| 558 RawString* BuildRename(const String& name, bool atomic); |
| 559 RawString* NewAtomicRename(bool should_be_private); |
| 560 |
| 561 void NextName(); |
| 562 |
| 563 void PreventRenaming(const String& name); |
| 564 void PreventRenaming(const char* name); |
| 565 |
| 566 private: |
| 567 Thread* thread_; |
| 568 |
| 569 const Array& saved_state_; |
| 570 |
| 571 char name_[100]; |
| 572 ObfuscationMap renames_; |
| 573 |
| 574 const String& private_key_; |
| 575 |
| 576 String& string_; |
| 577 String& renamed_; |
| 578 }; |
| 579 |
| 580 ObfuscationState* state_; |
| 581 }; |
| 582 #else |
| 583 // Minimal do-nothing implementation of an Obfuscator for non-precompiler |
| 584 // builds. |
| 585 class Obfuscator { |
| 586 public: |
| 587 Obfuscator(Thread* thread, const String& private_key) {} |
| 588 ~Obfuscator() {} |
| 589 |
| 590 RawString* Rename(const String& name, bool atomic = false) { |
| 591 return name.raw(); |
| 592 } |
| 593 |
| 594 static void ObfuscateSymbolInstance(Thread* thread, |
| 595 const Instance& instance) {} |
| 596 |
| 597 static void Deobfuscate(Thread* thread, const GrowableObjectArray& pieces) {} |
| 598 }; |
| 599 #endif // DART_PRECOMPILER |
| 600 |
479 } // namespace dart | 601 } // namespace dart |
480 | 602 |
481 #endif // RUNTIME_VM_PRECOMPILER_H_ | 603 #endif // RUNTIME_VM_PRECOMPILER_H_ |
OLD | NEW |