5#ifndef RUNTIME_VM_COMPILER_AOT_PRECOMPILER_H_
6#define RUNTIME_VM_COMPILER_AOT_PRECOMPILER_H_
8#if defined(DART_PRECOMPILED_RUNTIME)
9#error "AOT runtime should not use compiler sources (including header files)"
28class GrowableObjectArray;
32class PrecompilerTracer;
33class RetainedReasonsWriter;
67 return pair->
ptr() ==
key->ptr();
76 static const char*
Name() {
return "FunctionKeyTraits"; }
78 return x.ptr() ==
y.ptr();
101 return pair->
ptr() ==
key->ptr();
121 return pair->
ptr() ==
key->ptr();
141 return pair->
ptr() ==
key->ptr();
161 return pair->
ptr() ==
key->ptr();
181 return pair->
ptr() ==
key->ptr();
199 if (
key->IsFunction()) {
200 return Function::Cast(*key).Hash();
201 }
else if (
key->IsField()) {
203 }
else if (
key->IsClass()) {
205 }
else if (
key->IsLibrary()) {
212 FATAL(
"Unexpected type: %s\n",
key->ToCString());
216 return pair->
ptr() ==
key->ptr();
236 return pair->
ptr() ==
key->ptr();
253 return get_runtime_type_is_unique_;
257 return &global_object_pool_builder_;
271 kCompilingConstructorsForInstructionCounts,
272 kFixpointCodeGeneration,
291 : precompiler_(precompiler), was_tracing_(precompiler->is_tracing_) {
292 precompiler->is_tracing_ = (precompiler->tracer_ !=
nullptr);
295 ~TracingScope() { precompiler_->is_tracing_ = was_tracing_; }
298 Precompiler*
const precompiler_;
299 const bool was_tracing_;
302 explicit Precompiler(Thread*
thread);
309 void AddAnnotatedRoots();
312 void AddRetainReason(
const Object& obj,
const char* reason);
313 void AddType(
const AbstractType&
type);
314 void AddTypesOf(
const Class& cls);
315 void AddTypesOf(
const Function&
function);
316 void AddTypeParameters(
const TypeParameters&
params);
317 void AddTypeArguments(
const TypeArguments&
args);
318 void AddCalleesOf(
const Function&
function, intptr_t gop_offset);
319 void AddCalleesOfHelper(
const Object& entry,
320 String* temp_selector,
323 void AddClosureCall(
const String& selector,
324 const Array& arguments_descriptor);
325 void AddFunction(
const Function&
function,
const char* retain_reason);
326 void AddInstantiatedClass(
const Class& cls);
327 void AddSelector(
const String& selector);
328 bool IsSent(
const String& selector);
329 bool IsHitByTableSelector(
const Function&
function);
331 const char* MustRetainFunction(
const Function&
function);
332 void AddApiUse(
const Object& obj);
333 bool HasApiUse(
const Object& obj);
335 void ProcessFunction(
const Function&
function);
336 void CheckForNewDynamicFunctions();
337 void CollectCallbackFields();
339 void AttachOptimizedTypeTestingStub();
341 void TraceForRetainedFunctions();
342 void FinalizeDispatchTable();
343 void ReplaceFunctionStaticCallEntries();
344 void DropFunctions();
346 void VisitConstantInstance(ObjectPtr
instance,
348 ObjectStore* object_store);
349 void DropTransitiveUserDefinedConstants();
350 void TraceTypesFromRetainedClasses();
352 void DropLibraryEntries();
354 void DropLibraries();
355 void DiscardCodeObjects();
356 void PruneDictionaries();
358 DEBUG_ONLY(FunctionPtr FindUnvisitedRetainedFunction());
362 void CollectDynamicFunctionNames();
364 void PrecompileStaticInitializers();
365 void PrecompileConstructors();
367 void FinalizeAllClasses();
369 IsolateGroup* isolate_group()
const {
return thread_->
isolate_group(); }
375 bool retain_root_library_caches_;
376 intptr_t function_count_;
377 intptr_t class_count_;
378 intptr_t selector_count_;
379 intptr_t dropped_function_count_;
380 intptr_t dropped_field_count_;
381 intptr_t dropped_class_count_;
382 intptr_t dropped_typearg_count_;
383 intptr_t dropped_type_count_;
384 intptr_t dropped_functiontype_count_;
385 intptr_t dropped_typeparam_count_;
386 intptr_t dropped_library_count_;
387 intptr_t dropped_constants_arrays_entries_count_;
389 compiler::ObjectPoolBuilder global_object_pool_builder_;
390 GrowableObjectArray& libraries_;
391 const GrowableObjectArray& pending_functions_;
409 compiler::DispatchTableGenerator* dispatch_table_generator_;
411 bool get_runtime_type_is_unique_;
414 PrecompilerTracer* tracer_ =
nullptr;
415 RetainedReasonsWriter* retained_reasons_writer_ =
nullptr;
416 bool is_tracing_ =
false;
421 static const char*
Name() {
return "FunctionsTraits"; }
425 return String::Cast(
a).ptr() == String::Cast(
b).ptr();
432#if defined(DART_PRECOMPILER) && !defined(TARGET_ARCH_IA32)
434class ObfuscationMapTraits {
436 static const char*
Name() {
return "ObfuscationMapTraits"; }
437 static bool ReportStats() {
return false; }
441 return a.ptr() ==
b.ptr();
446typedef UnorderedHashMap<ObfuscationMapTraits> ObfuscationMap;
451class Obfuscator :
public ValueObject {
464 Obfuscator(Thread* thread,
const String& private_key);
485 StringPtr
Rename(
const String&
name,
bool atomic =
false) {
486 if (state_ ==
nullptr) {
490 return state_->RenameImpl(
name, atomic);
499 static void Deobfuscate(Thread* thread,
const GrowableObjectArray& pieces);
502 static const char** SerializeMap(Thread* thread);
510 void InitializeRenamingMap();
515 static constexpr intptr_t kSavedStateNameIndex = 0;
516 static constexpr intptr_t kSavedStateRenamesIndex = 1;
517 static constexpr intptr_t kSavedStateSize = 2;
519 static ArrayPtr GetRenamesFromSavedState(
const Array&
saved_state) {
521 renames ^=
saved_state.At(kSavedStateRenamesIndex);
522 return renames.ptr();
525 static StringPtr GetNameFromSavedState(
const Array&
saved_state) {
531 class ObfuscationState :
public ZoneAllocated {
533 ObfuscationState(Thread* thread,
535 const String& private_key)
539 private_key_(private_key),
540 string_(String::Handle(thread->zone())),
541 renamed_(String::Handle(thread->zone())) {
542 memset(name_, 0,
sizeof(name_));
546 if (!string_.IsNull()) {
547 string_.ToUTF8(
reinterpret_cast<uint8_t*
>(name_),
sizeof(name_));
569 StringPtr RenameImpl(
const String&
name,
bool atomic);
586 StringPtr BuildRename(
const String&
name,
bool atomic);
590 StringPtr NewAtomicRename(
bool should_be_private);
598 const Array& saved_state_;
604 ObfuscationMap renames_;
606 const String& private_key_;
614 ObfuscationState* state_;
const AbstractType * Pair
static bool IsKeyEqual(Pair pair, Key key)
static Value ValueOf(Pair kv)
static Key KeyOf(Pair kv)
const AbstractType * Value
static uword Hash(Key key)
static bool IsKeyEqual(Pair pair, Key key)
static Value ValueOf(Pair kv)
static uword Hash(Key key)
static Key KeyOf(Pair kv)
static Value ValueOf(Pair kv)
static Key KeyOf(Pair kv)
const FunctionType * Pair
const FunctionType * Value
static bool IsKeyEqual(Pair pair, Key key)
static uword Hash(Key key)
static uword Hash(const Object &obj)
static const char * Name()
static bool IsMatch(const Object &a, const Object &b)
static bool ReportStats()
static Value ValueOf(Pair kv)
static bool IsKeyEqual(Pair pair, Key key)
static uword Hash(Key key)
static Key KeyOf(Pair kv)
Obfuscator(Thread *thread, const String &private_key)
static void Deobfuscate(Thread *thread, const GrowableObjectArray &pieces)
StringPtr Rename(const String &name, bool atomic=false)
void PreventRenaming(const String &name)
void AddTableSelector(const compiler::TableSelector *selector)
static Precompiler * Instance()
void AddField(const Field &field)
bool get_runtime_type_is_unique() const
compiler::SelectorMap * selector_map()
compiler::ObjectPoolBuilder * global_object_pool_builder()
static ErrorPtr CompileFunction(Precompiler *precompiler, Thread *thread, Zone *zone, const Function &function)
static ErrorPtr CompileAll()
static Value ValueOf(Pair kv)
static Key KeyOf(Pair kv)
static bool IsKeyEqual(Pair pair, Key key)
static uword Hash(Key key)
static Key KeyOf(Pair kv)
static uword Hash(Key key)
static Value ValueOf(Pair kv)
static bool IsKeyEqual(Pair pair, Key key)
static bool IsKeyEqual(Pair pair, Key key)
static Value ValueOf(Pair kv)
static uword Hash(Key key)
static Key KeyOf(Pair kv)
IsolateGroup * isolate_group() const
static Key KeyOf(Pair kv)
const TypeArguments * Value
const TypeArguments * Key
const TypeArguments * Pair
static uword Hash(Key key)
static bool IsKeyEqual(Pair pair, Key key)
static Value ValueOf(Pair kv)
static Value ValueOf(Pair kv)
static bool IsKeyEqual(Pair pair, Key key)
static Key KeyOf(Pair kv)
const TypeParameter * Value
static uword Hash(Key key)
const TypeParameter * Key
const TypeParameter * Pair
static uint32_t WordHash(intptr_t key)
SelectorMap * selector_map()
const EmbeddedViewParams * params
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
Dart_NativeFunction function
DirectChainedHashMap< SymbolKeyValueTrait > SymbolSet
UnorderedHashSet< FunctionKeyTraits > FunctionSet
DirectChainedHashMap< ProgramElementKeyValueTrait > ProgramElementSet
uint32_t CombineHashes(uint32_t hash, uint32_t other_hash)
DirectChainedHashMap< FunctionTypeKeyValueTrait > FunctionTypeSet
UnorderedHashMap< FunctionsTraits > UniqueFunctionsMap
DirectChainedHashMap< TypeArgumentsKeyValueTrait > TypeArgumentsSet
DirectChainedHashMap< TypeParameterKeyValueTrait > TypeParameterSet
DirectChainedHashMap< FieldKeyValueTrait > FieldSet
DirectChainedHashMap< ClassKeyValueTrait > ClassSet
DirectChainedHashMap< TableSelectorKeyValueTrait > TableSelectorSet
static uint32_t Hash(uint32_t key)
DirectChainedHashMap< AbstractTypeKeyValueTrait > AbstractTypeSet
DirectChainedHashMap< InstanceKeyValueTrait > InstanceSet
static bool ReportStats()
static bool IsMatch(const Object &x, const Object &y)
static uint32_t Hash(const Object &key)
static const char * Name()