From 75afcdd3503a8a8518e5b23d21b6e73306ce39ce Mon Sep 17 00:00:00 2001 From: Nicolas Geoffray Date: Thu, 10 Nov 2016 10:38:11 +0000 Subject: Revert "Revert "JIT root tables."" Also contains Revert "Support kJitTableAddress in x86/arm/arm64." This reverts commit 4acd03638fcdb4e5d1666f8eec7eb3bf6d6be035. This reverts commit 997d1217830c0a18b70faeabd53c04700a87d7d9. Test: ART_USE_READ_BARRIER=true/false test-art-host test-art-target Change-Id: I77cb1e9bf8f1b4c58b72d3cf5ca31ced2aaa1ea3 --- compiler/optimizing/optimizing_compiler.cc | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'compiler/optimizing/optimizing_compiler.cc') diff --git a/compiler/optimizing/optimizing_compiler.cc b/compiler/optimizing/optimizing_compiler.cc index 6f84cdcc4f..1add660f1b 100644 --- a/compiler/optimizing/optimizing_compiler.cc +++ b/compiler/optimizing/optimizing_compiler.cc @@ -117,6 +117,7 @@ class CodeVectorAllocator FINAL : public CodeAllocator { size_t GetSize() const { return size_; } const ArenaVector& GetMemory() const { return memory_; } + uint8_t* GetData() { return memory_.data(); } private: ArenaVector memory_; @@ -1126,7 +1127,7 @@ bool OptimizingCompiler::JitCompile(Thread* self, jit::JitCodeCache* code_cache, ArtMethod* method, bool osr) { - StackHandleScope<2> hs(self); + StackHandleScope<3> hs(self); Handle class_loader(hs.NewHandle( method->GetDeclaringClass()->GetClassLoader())); Handle dex_cache(hs.NewHandle(method->GetDexCache())); @@ -1172,22 +1173,43 @@ bool OptimizingCompiler::JitCompile(Thread* self, } size_t stack_map_size = codegen->ComputeStackMapsSize(); - uint8_t* stack_map_data = code_cache->ReserveData(self, stack_map_size, method); - if (stack_map_data == nullptr) { + size_t number_of_roots = codegen->GetNumberOfJitRoots(); + ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); + // We allocate an object array to ensure the JIT roots that we will collect in EmitJitRoots + // will be visible by the GC between EmitLiterals and CommitCode. Once CommitCode is + // executed, this array is not needed. + Handle> roots( + hs.NewHandle(mirror::ObjectArray::Alloc( + self, class_linker->GetClassRoot(ClassLinker::kObjectArrayClass), number_of_roots))); + if (roots.Get() == nullptr) { + // Out of memory, just clear the exception to avoid any Java exception uncaught problems. + DCHECK(self->IsExceptionPending()); + self->ClearException(); + return false; + } + uint8_t* stack_map_data = nullptr; + uint8_t* roots_data = nullptr; + code_cache->ReserveData( + self, stack_map_size, number_of_roots, method, &stack_map_data, &roots_data); + if (stack_map_data == nullptr || roots_data == nullptr) { return false; } MaybeRecordStat(MethodCompilationStat::kCompiled); codegen->BuildStackMaps(MemoryRegion(stack_map_data, stack_map_size), *code_item); + codegen->EmitJitRoots(code_allocator.GetData(), roots, roots_data, dex_cache); + const void* code = code_cache->CommitCode( self, method, stack_map_data, + roots_data, codegen->HasEmptyFrame() ? 0 : codegen->GetFrameSize(), codegen->GetCoreSpillMask(), codegen->GetFpuSpillMask(), code_allocator.GetMemory().data(), code_allocator.GetSize(), - osr); + osr, + roots); if (code == nullptr) { code_cache->ClearData(self, stack_map_data); -- cgit v1.2.3-59-g8ed1b