compiler_kind_(compiler_kind),
instruction_set_(instruction_set),
instruction_set_features_(instruction_set_features),
- no_barrier_constructor_classes_lock_("freezing constructor lock"),
- resolved_classes_(false),
+ requires_constructor_barrier_lock_("constructor barrier lock"),
compiled_classes_lock_("compiled classes lock"),
compiled_methods_lock_("compiled method lock"),
compiled_methods_(MethodTable::key_compare()),
resolve_thread_count,
timings);
}
-
- resolved_classes_ = true;
}
// Resolve const-strings in the code. Done to have deterministic allocation behavior. Right now
DCHECK(!it.HasNext());
}
}
- if (!requires_constructor_barrier) {
- manager_->GetCompiler()->AddRequiresNoConstructorBarrier(self, &dex_file, class_def_index);
- }
+ manager_->GetCompiler()->SetRequiresConstructorBarrier(self,
+ &dex_file,
+ class_def_index,
+ requires_constructor_barrier);
}
private:
return non_relative_linker_patch_count_;
}
-void CompilerDriver::AddRequiresNoConstructorBarrier(Thread* self,
- const DexFile* dex_file,
- uint16_t class_def_index) {
- WriterMutexLock mu(self, no_barrier_constructor_classes_lock_);
- no_barrier_constructor_classes_.insert(ClassReference(dex_file, class_def_index));
+void CompilerDriver::SetRequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index,
+ bool requires) {
+ WriterMutexLock mu(self, requires_constructor_barrier_lock_);
+ requires_constructor_barrier_.emplace(ClassReference(dex_file, class_def_index), requires);
}
bool CompilerDriver::RequiresConstructorBarrier(Thread* self,
const DexFile* dex_file,
- uint16_t class_def_index) const {
- if (resolved_classes_) {
- ReaderMutexLock mu(self, no_barrier_constructor_classes_lock_);
- return no_barrier_constructor_classes_.count(ClassReference(dex_file, class_def_index)) == 0;
+ uint16_t class_def_index) {
+ ClassReference class_ref(dex_file, class_def_index);
+ {
+ ReaderMutexLock mu(self, requires_constructor_barrier_lock_);
+ auto it = requires_constructor_barrier_.find(class_ref);
+ if (it != requires_constructor_barrier_.end()) {
+ return it->second;
+ }
}
- return RequiresConstructorBarrier(*dex_file, class_def_index);
+ WriterMutexLock mu(self, requires_constructor_barrier_lock_);
+ const bool requires = RequiresConstructorBarrier(*dex_file, class_def_index);
+ requires_constructor_barrier_.emplace(class_ref, requires);
+ return requires;
}
std::string CompilerDriver::GetMemoryUsageString(bool extended) const {
// Remove and delete a compiled method.
void RemoveCompiledMethod(const MethodReference& method_ref) REQUIRES(!compiled_methods_lock_);
- void AddRequiresNoConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index)
- REQUIRES(!no_barrier_constructor_classes_lock_);
- bool RequiresConstructorBarrier(Thread* self, const DexFile* dex_file,
- uint16_t class_def_index) const
- REQUIRES(!no_barrier_constructor_classes_lock_);
+ void SetRequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index,
+ bool requires)
+ REQUIRES(!requires_constructor_barrier_lock_);
+ bool RequiresConstructorBarrier(Thread* self,
+ const DexFile* dex_file,
+ uint16_t class_def_index)
+ REQUIRES(!requires_constructor_barrier_lock_);
// Callbacks from compiler to see what runtime checks must be generated.
const InstructionSet instruction_set_;
const InstructionSetFeatures* const instruction_set_features_;
- // All class references that do not require constructor barriers. Only filled in if
- // resolved_classes_ is true.
- mutable ReaderWriterMutex no_barrier_constructor_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
- std::set<ClassReference> no_barrier_constructor_classes_
- GUARDED_BY(no_barrier_constructor_classes_lock_);
- // resolved_classes_ is true if we performed the resolve phase and filled in
- // no_barrier_constructor_classes_.
- bool resolved_classes_;
+ // All class references that require constructor barriers. If the class reference is not in the
+ // set then the result has not yet been computed.
+ mutable ReaderWriterMutex requires_constructor_barrier_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER;
+ std::map<ClassReference, bool> requires_constructor_barrier_
+ GUARDED_BY(requires_constructor_barrier_lock_);
typedef SafeMap<const ClassReference, CompiledClass*> ClassTable;
// All class references that this compiler has compiled.
UpdateLocal(instruction.VRegA(), current_block_->GetLastInstruction());
}
-static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, const CompilerDriver& driver) {
+static bool RequiresConstructorBarrier(const DexCompilationUnit* cu, CompilerDriver* driver) {
Thread* self = Thread::Current();
return cu->IsConstructor()
- && driver.RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
+ && driver->RequiresConstructorBarrier(self, cu->GetDexFile(), cu->GetClassDefIndex());
}
// Returns true if `block` has only one successor which starts at the next
if (graph_->ShouldGenerateConstructorBarrier()) {
// The compilation unit is null during testing.
if (dex_compilation_unit_ != nullptr) {
- DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, *compiler_driver_))
+ DCHECK(RequiresConstructorBarrier(dex_compilation_unit_, compiler_driver_))
<< "Inconsistent use of ShouldGenerateConstructorBarrier. Should not generate a barrier.";
}
AppendInstruction(new (arena_) HMemoryBarrier(kStoreStore, dex_pc));