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/runtime.cc:839
  art::MarkSweep::MarkRoots at art/src/mark_sweep.cc:91
  art::Heap::CollectGarbageInternal at art/src/heap.cc:581

  art::Heap::AllocateLocked at art/src/heap.cc:465
  art::Heap::AllocateLocked at art/src/heap.cc:421
  art::Heap::AllocObject at art/src/heap.cc:281
  art::Array::Alloc at art/src/object.cc:1252
  art::PrimitiveArray<unsigned short>::Alloc at art/src/object.cc:1280
  art::String::Alloc at art/src/object.cc:1392
  art::String::AllocFromModifiedUtf8 at art/src/object.cc:1380
  art::String::AllocFromModifiedUtf8 at art/src/object.cc:1375
  art::InternTable::InternStrong at art/src/intern_table.cc:136
  art::ClassLinker::AllocDexCache at art/src/class_linker.cc:1042
  art::ClassLinker::AppendToBootClassPath at art/src/class_linker.cc:1607
  art::ClassLinker::InitFromCompiler at art/src/class_linker.cc:314
  art::ClassLinker::CreateFromCompiler at art/src/class_linker.cc:213
  art::Runtime::Init at art/src/runtime.cc:666
  art::Runtime::Create at art/src/runtime.cc:495
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 heap.cc:442.
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. build/
  2. jdwpspy/
  3. src/
  4. test/
  5. tools/
  6. .gitignore
  7. Android.mk