Fix space_test for (USE_LLVM_COMPILER) build.

If we use libcutils, it will link bionic's dlmalloc. And we will call
bionic's init_mparams(). The init_mparams() initializes a "static"
variable, mparams. So, if we don't call ART's copy of init_mparams(), our
own mparams will not be initialized. Later, when we call
mspace_set_footprint_limit(), which only exists in ART's copy of
dlmalloc, it can not successfully set limit.

The problematic code path is as follows:

Most recent callee is:
  art::Runtime::VisitRoots at art/src/
  art::MarkSweep::MarkRoots at art/src/
  art::Heap::CollectGarbageInternal at art/src/

  art::Heap::AllocateLocked at art/src/
  art::Heap::AllocateLocked at art/src/
  art::Heap::AllocObject at art/src/
  art::Array::Alloc at art/src/
  art::PrimitiveArray<unsigned short>::Alloc at art/src/
  art::String::Alloc at art/src/
  art::String::AllocFromModifiedUtf8 at art/src/
  art::String::AllocFromModifiedUtf8 at art/src/
  art::InternTable::InternStrong at art/src/
  art::ClassLinker::AllocDexCache at art/src/
  art::ClassLinker::AppendToBootClassPath at art/src/
  art::ClassLinker::InitFromCompiler at art/src/
  art::ClassLinker::CreateFromCompiler at art/src/
  art::Runtime::Init at art/src/
  art::Runtime::Create at art/src/
which is the oldest callee.

This will happen to (!USE_LLVM_COMPILER) build as well:
When creating runtime.class_linker_, it should allocate DexCache.
When initializing DexCache, it needs to allocate managed Object.

Then, when running (USE_LLVM_COMPILER) build, allocate without growth failed.
See space->AllocWithoutGrowth() at
Then, (USE_LLVM_COMPILER) build will call CollectGarbageInternal, which will call
through Runtime::VisitRoots(). VisitRoots needs class_linker. But at that time,
we are still initializing runtime::class_linker_!

In general, this could be a bug for (!USE_LLVM_COMPILER) build too, when
we need to run GC before class_linker_ is initialized.

Change-Id: Ie1246adf77c7a656827ed3dcd3b9759c5a1ca262
1 file changed
tree: 8841d030d88471a2174fb9ae81dc3f29e1309e7c
  1. .gitignore
  3. build/
  4. jdwpspy/
  5. src/
  6. test/
  7. tools/