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.

(cherry picked from commit 8771a2fe9f5892fa4646cf50ae728f54b427356f)

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