Merge "Remove disable card marks, fix SetPatchLocation." into dalvik-dev
diff --git a/build/Android.common.mk b/build/Android.common.mk
index 0d31237..193afbf 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -78,11 +78,20 @@
 	-DDYNAMIC_ANNOTATIONS_ENABLED=1 \
 	-UNDEBUG
 
-ART_HOST_CFLAGS := $(art_cflags) -DANDROID_SMP=1
+# start of image reserved address space
+IMG_HOST_BASE_ADDRESS   := 0x60000000
+
+ifeq ($(TARGET_ARCH),mips)
+IMG_TARGET_BASE_ADDRESS := 0x30000000
+else
+IMG_TARGET_BASE_ADDRESS := 0x60000000
+endif
+
+ART_HOST_CFLAGS := $(art_cflags) -DANDROID_SMP=1 -DART_BASE_ADDRESS=$(IMG_HOST_BASE_ADDRESS)
 # The host GCC isn't necessarily new enough to support -Wthread-safety (GCC 4.4).
 ART_HOST_CFLAGS := $(filter-out -Wthread-safety,$(ART_HOST_CFLAGS))
 
-ART_TARGET_CFLAGS := $(art_cflags) -DART_TARGET
+ART_TARGET_CFLAGS := $(art_cflags) -DART_TARGET -DART_BASE_ADDRESS=$(IMG_TARGET_BASE_ADDRESS)
 ifeq ($(TARGET_CPU_SMP),true)
   ART_TARGET_CFLAGS += -DANDROID_SMP=1
 else
diff --git a/build/Android.oat.mk b/build/Android.oat.mk
index cdb7349..7868204 100644
--- a/build/Android.oat.mk
+++ b/build/Android.oat.mk
@@ -27,10 +27,6 @@
 # TODO: for now, override with debug version for better error reporting
 OATDUMP := $(OATDUMPD)
 
-# start of image reserved address space
-IMG_HOST_BASE_ADDRESS   := 0x60000000
-IMG_TARGET_BASE_ADDRESS := 0x60000000
-
 PRELOADED_CLASSES := frameworks/base/preloaded-classes
 
 ########################################################################
diff --git a/src/compiler/Frontend.cc b/src/compiler/Frontend.cc
index c5d5c21..ffeae46 100644
--- a/src/compiler/Frontend.cc
+++ b/src/compiler/Frontend.cc
@@ -858,14 +858,15 @@
         (1 << kLoadStoreElimination) |
         (1 << kLoadHoisting) |
         (1 << kSuppressLoads) |
-        (1 << kNullCheckElimination) |
-        (1 << kPromoteRegs) |
+        //(1 << kNullCheckElimination) |
+        //(1 << kPromoteRegs) |
         (1 << kTrackLiveTemps) |
-        (1 << kSkipLargeMethodOptimization) |
-        (1 << kSafeOptimizations) |
+        //(1 << kSkipLargeMethodOptimization) |
+        //(1 << kSafeOptimizations) |
         (1 << kBBOpt) |
         (1 << kMatch) |
-        (1 << kPromoteCompilerTemps));
+        //(1 << kPromoteCompilerTemps) |
+        0);
 }
 #endif
 
diff --git a/src/dex2oat.cc b/src/dex2oat.cc
index a8f42af..bbc07a6 100644
--- a/src/dex2oat.cc
+++ b/src/dex2oat.cc
@@ -269,7 +269,6 @@
     }
 
     if (!OatWriter::Create(oat_file,
-                           class_loader,
                            dex_files,
                            image_file_location_oat_checksum,
                            image_file_location_oat_begin,
diff --git a/src/gc/atomic_stack.h b/src/gc/atomic_stack.h
index 3494861..d67d2f2 100644
--- a/src/gc/atomic_stack.h
+++ b/src/gc/atomic_stack.h
@@ -136,11 +136,7 @@
   // Size in number of elements.
   void Init() {
     mem_map_.reset(MemMap::MapAnonymous(name_.c_str(), NULL, capacity_ * sizeof(T), PROT_READ | PROT_WRITE));
-    if (mem_map_.get() == NULL) {
-      std::string maps;
-      ReadFileToString("/proc/self/maps", &maps);
-      LOG(FATAL) << "couldn't allocate mark stack\n" << maps;
-    }
+    CHECK(mem_map_.get() != NULL) << "couldn't allocate mark stack";
     byte* addr = mem_map_->Begin();
     CHECK(addr != NULL);
     begin_ = reinterpret_cast<T*>(addr);
diff --git a/src/gc/card_table.cc b/src/gc/card_table.cc
index 5a1e9b5..a5531d8 100644
--- a/src/gc/card_table.cc
+++ b/src/gc/card_table.cc
@@ -54,11 +54,7 @@
   /* Allocate an extra 256 bytes to allow fixed low-byte of base */
   UniquePtr<MemMap> mem_map(MemMap::MapAnonymous("dalvik-card-table", NULL,
                                                  capacity + 256, PROT_READ | PROT_WRITE));
-  if (mem_map.get() == NULL) {
-    std::string maps;
-    ReadFileToString("/proc/self/maps", &maps);
-    LOG(FATAL) << "couldn't allocate card table\n" << maps;
-  }
+  CHECK(mem_map.get() != NULL) << "couldn't allocate card table";
   // All zeros is the correct initial value; all clean. Anonymous mmaps are initialized to zero, we
   // don't clear the card table to avoid unnecessary pages being allocated
   COMPILE_ASSERT(kCardClean == 0, card_clean_must_be_0);
diff --git a/src/heap.cc b/src/heap.cc
index bfc5256..cf13eae 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -87,7 +87,8 @@
   const char* oat_file_option = oat_file_option_string.c_str();
   arg_vector.push_back(strdup(oat_file_option));
 
-  arg_vector.push_back(strdup("--base=0x60000000"));
+  std::string base_option_string(StringPrintf("--base=0x%x", ART_BASE_ADDRESS));
+  arg_vector.push_back(strdup(base_option_string.c_str()));
 
   std::string command_line(Join(arg_vector, ' '));
   LOG(INFO) << command_line;
@@ -232,8 +233,8 @@
                                                              growth_limit, capacity,
                                                              requested_begin));
   alloc_space_ = alloc_space.release();
-  alloc_space_->SetFootprintLimit(alloc_space_->Capacity());
   CHECK(alloc_space_ != NULL) << "Failed to create alloc space";
+  alloc_space_->SetFootprintLimit(alloc_space_->Capacity());
   AddSpace(alloc_space_);
 
   // Spaces are sorted in order of Begin().
diff --git a/src/image_test.cc b/src/image_test.cc
index e2abbac..feb490c 100644
--- a/src/image_test.cc
+++ b/src/image_test.cc
@@ -36,7 +36,7 @@
     ScopedObjectAccess soa(Thread::Current());
     std::vector<const DexFile*> dex_files;
     dex_files.push_back(java_lang_dex_file_);
-    bool success_oat = OatWriter::Create(tmp_oat.GetFile(), NULL, dex_files, 0, 0, "", *compiler_.get());
+    bool success_oat = OatWriter::Create(tmp_oat.GetFile(), dex_files, 0, 0, "", *compiler_.get());
     ASSERT_TRUE(success_oat);
 
     // Force all system classes into memory
@@ -48,13 +48,15 @@
     }
   }
 
-  ImageWriter writer(NULL);
   ScratchFile tmp_image;
-  const uintptr_t requested_image_base = 0x60000000;
-  bool success_image = writer.Write(tmp_image.GetFilename(), requested_image_base,
-                                    tmp_oat.GetFilename(), tmp_oat.GetFilename(),
-                                    *compiler_.get());
-  ASSERT_TRUE(success_image);
+  const uintptr_t requested_image_base = ART_BASE_ADDRESS;
+  {
+    ImageWriter writer(NULL);
+    bool success_image = writer.Write(tmp_image.GetFilename(), requested_image_base,
+                                      tmp_oat.GetFilename(), tmp_oat.GetFilename(),
+                                      *compiler_.get());
+    ASSERT_TRUE(success_image);
+  }
 
   {
     UniquePtr<File> file(OS::OpenFile(tmp_image.GetFilename().c_str(), false));
diff --git a/src/mem_map.cc b/src/mem_map.cc
index 653eb3f..f322773 100644
--- a/src/mem_map.cc
+++ b/src/mem_map.cc
@@ -87,8 +87,11 @@
 
   byte* actual = reinterpret_cast<byte*>(mmap(addr, page_aligned_byte_count, prot, flags, fd.get(), 0));
   if (actual == MAP_FAILED) {
+    std::string maps;
+    ReadFileToString("/proc/self/maps", &maps);
     PLOG(ERROR) << "mmap(" << reinterpret_cast<void*>(addr) << ", " << page_aligned_byte_count
-                << ", " << prot << ", " << flags << ", " << fd.get() << ", 0) failed for " << name;
+                << ", " << prot << ", " << flags << ", " << fd.get() << ", 0) failed for " << name
+                << "\n" << maps;
     return NULL;
   }
   return new MemMap(name, actual, byte_count, actual, page_aligned_byte_count, prot);
@@ -110,7 +113,11 @@
                                               fd,
                                               page_aligned_offset));
   if (actual == MAP_FAILED) {
-    PLOG(ERROR) << "mmap failed";
+    std::string maps;
+    ReadFileToString("/proc/self/maps", &maps);
+    PLOG(ERROR) << "mmap(" << reinterpret_cast<void*>(addr) << ", " << page_aligned_byte_count
+                << ", " << prot << ", " << flags << ", " << fd << ", " << page_aligned_offset
+                << ") failed\n" << maps;
     return NULL;
   }
   return new MemMap("file", actual + page_offset, byte_count, actual, page_aligned_byte_count,
diff --git a/src/oat/runtime/mips/runtime_support_mips.S b/src/oat/runtime/mips/runtime_support_mips.S
index 349e802..bc0aecf 100644
--- a/src/oat/runtime/mips/runtime_support_mips.S
+++ b/src/oat/runtime/mips/runtime_support_mips.S
@@ -22,7 +22,7 @@
     /* Deliver the given exception */
     .extern artDeliverExceptionFromCode
     /* Deliver an exception pending on a thread */
-    .extern artDeliverPendingException
+    .extern artDeliverPendingExceptionFromCode
 
     /* Cache alignment for function entry */
 .macro ALIGN_FUNCTION_ENTRY
@@ -115,16 +115,17 @@
      * exception is Thread::Current()->exception_
      */
 .macro DELIVER_PENDING_EXCEPTION
-    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME            # save callee saves for throw
-    move    $a0, rSELF                          # pass Thread::Current
-    jal     artDeliverPendingExceptionFromCode  # artDeliverPendingExceptionFromCode(Thread*, $sp)
-    move    $a1, $sp                            # pass $sp
+    SETUP_SAVE_ALL_CALLEE_SAVE_FRAME     # save callee saves for throw
+    move    $a0, rSELF                   # pass Thread::Current
+    la      $t9, artDeliverPendingExceptionFromCode
+    jr      $t9                          # artDeliverPendingExceptionFromCode(Thread*, $sp)
+    move    $a1, $sp                     # pass $sp
 .endm
 
 .macro RETURN_IF_NO_EXCEPTION
     lw     $t0, THREAD_EXCEPTION_OFFSET(rSELF) # load Thread::Current()->exception_
     RESTORE_REF_ONLY_CALLEE_SAVE_FRAME
-    bnez   $t0, 1f                        # success if no exception is pending
+    bnez   $t0, 1f                       # success if no exception is pending
     nop
     jr     $ra
     nop
@@ -254,9 +255,10 @@
 art_deliver_exception_from_code:
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
-    move $a1, rSELF                     # pass Thread::Current
-    jal  artDeliverExceptionFromCode    # artDeliverExceptionFromCode(Throwable*, Thread*, $sp)
-    move $a2, $sp                       # pass $sp
+    move $a1, rSELF                 # pass Thread::Current
+    la   $t9, artDeliverExceptionFromCode
+    jr   $t9                        # artDeliverExceptionFromCode(Throwable*, Thread*, $sp)
+    move $a2, $sp                   # pass $sp
 
     .global art_throw_null_pointer_exception_from_code
     .extern artThrowNullPointerExceptionFromCode
@@ -267,9 +269,10 @@
 art_throw_null_pointer_exception_from_code:
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
-    move $a0, rSELF                           # pass Thread::Current
-    jal  artThrowNullPointerExceptionFromCode  # artThrowNullPointerExceptionFromCode(Thread*, $sp)
-    move $a1, $sp                             # pass $sp
+    move $a0, rSELF                 # pass Thread::Current
+    la   $t9, artThrowNullPointerExceptionFromCode
+    jr   $t9                        # artThrowNullPointerExceptionFromCode(Thread*, $sp)
+    move $a1, $sp                   # pass $sp
 
     .global art_throw_div_zero_from_code
     .extern artThrowDivZeroFromCode
@@ -281,7 +284,8 @@
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
     move $a0, rSELF                 # pass Thread::Current
-    jal  artThrowDivZeroFromCode     # artThrowDivZeroFromCode(Thread*, $sp)
+    la   $t9, artThrowDivZeroFromCode
+    jr   $t9                        # artThrowDivZeroFromCode(Thread*, $sp)
     move $a1, $sp                   # pass $sp
 
     .global art_throw_array_bounds_from_code
@@ -293,9 +297,10 @@
 art_throw_array_bounds_from_code:
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
-    move $a2, rSELF                  # pass Thread::Current
-    jal artThrowArrayBoundsFromCode  # artThrowArrayBoundsFromCode(index, limit, Thread*, $sp)
-    move $a3, $sp                    # pass $sp
+    move $a2, rSELF                 # pass Thread::Current
+    la   $t9, artThrowArrayBoundsFromCode
+    jr   $t9                        # artThrowArrayBoundsFromCode(index, limit, Thread*, $sp)
+    move $a3, $sp                   # pass $sp
 
     .global art_throw_stack_overflow_from_code
     .extern artThrowStackOverflowFromCode
@@ -306,9 +311,10 @@
 art_throw_stack_overflow_from_code:
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
-    move $a0, rSELF                    # pass Thread::Current
-    jal artThrowStackOverflowFromCode  # artThrowStackOverflowFromCode(Thread*, $sp)
-    move $a1, $sp                      # pass $sp
+    move $a0, rSELF                 # pass Thread::Current
+    la   $t9, artThrowStackOverflowFromCode
+    jr   $t9                        # artThrowStackOverflowFromCode(Thread*, $sp)
+    move $a1, $sp                   # pass $sp
 
     .global art_throw_no_such_method_from_code
     .extern artThrowNoSuchMethodFromCode
@@ -319,9 +325,10 @@
 art_throw_no_such_method_from_code:
     .cpload $25
     SETUP_SAVE_ALL_CALLEE_SAVE_FRAME
-    move $a1, rSELF                       # pass Thread::Current
-    jal artThrowNoSuchMethodFromCode      # artThrowNoSuchMethodFromCode(method_idx, Thread*, $sp)
-    move $a2, $sp                         # pass $sp
+    move $a1, rSELF                 # pass Thread::Current
+    la   $t9, artThrowNoSuchMethodFromCode
+    jr   $t9                        # artThrowNoSuchMethodFromCode(method_idx, Thread*, $sp)
+    move $a2, $sp                   # pass $sp
 
     /*
      * All generated callsites for interface invokes and invocation slow paths will load arguments
@@ -349,8 +356,10 @@
     move  $t0, $sp                        # save $sp
     addiu $sp, $sp, -16                   # make space for extra args
     move  $a3, rSELF                      # pass Thread::Current
+    sw    $gp, 12($sp)                    # save $gp
     jal   \cxx_name                       # (method_idx, this, caller, Thread*, $sp)
     sw    $t0, 16($sp)                    # pass $sp
+    lw    $gp, 12($sp)                    # restore $gp
     addiu $sp, $sp, 16                    # release out args
     move  $a0, $v0                        # save target Method*
     move  $t9, $v1                        # save $v0->code_
@@ -866,12 +875,12 @@
     move     $a2, $ra       # pass $ra
     jal      artTraceMethodEntryFromCode  # (Method*, Thread*, LR)
     move     $a1, rSELF     # pass Thread::Current
-    move     $t0, $v0       # $t0 holds reference to code
+    move     $t9, $v0       # $t9 holds reference to code
     lw       $a0, 0($sp)
     lw       $a1, 4($sp)
     lw       $a2, 8($sp)
     lw       $a3, 12($sp)
-    jalr     $t0            # call method
+    jalr     $t9            # call method
     addiu    $sp, $sp, 16
     /* intentional fallthrough */
 
diff --git a/src/oat_test.cc b/src/oat_test.cc
index bb6305a..52217b2 100644
--- a/src/oat_test.cc
+++ b/src/oat_test.cc
@@ -80,7 +80,6 @@
   ScopedObjectAccess soa(Thread::Current());
   ScratchFile tmp;
   bool success = OatWriter::Create(tmp.GetFile(),
-                                   class_loader,
                                    class_linker->GetBootClassPath(),
                                    42U,
                                    4096U,
diff --git a/src/oat_writer.cc b/src/oat_writer.cc
index e26e3cc..382139e 100644
--- a/src/oat_writer.cc
+++ b/src/oat_writer.cc
@@ -31,7 +31,6 @@
 namespace art {
 
 bool OatWriter::Create(File* file,
-                       jobject class_loader,
                        const std::vector<const DexFile*>& dex_files,
                        uint32_t image_file_location_oat_checksum,
                        uint32_t image_file_location_oat_begin,
@@ -41,7 +40,6 @@
                        image_file_location_oat_checksum,
                        image_file_location_oat_begin,
                        image_file_location,
-                       class_loader,
                        compiler);
   return oat_writer.Write(file);
 }
@@ -50,10 +48,8 @@
                      uint32_t image_file_location_oat_checksum,
                      uint32_t image_file_location_oat_begin,
                      const std::string& image_file_location,
-                     jobject class_loader,
                      const Compiler& compiler) {
   compiler_ = &compiler;
-  class_loader_ = class_loader;
   image_file_location_oat_checksum_ = image_file_location_oat_checksum;
   image_file_location_oat_begin_ = image_file_location_oat_begin;
   image_file_location_ = image_file_location;
@@ -403,7 +399,7 @@
     // Unchecked as we hold mutator_lock_ on entry.
     ScopedObjectAccessUnchecked soa(Thread::Current());
     AbstractMethod* method = linker->ResolveMethod(*dex_file, method_idx, dex_cache,
-                                           soa.Decode<ClassLoader*>(class_loader_), NULL, type);
+                                                   NULL, NULL, type);
     CHECK(method != NULL);
     method->SetFrameSizeInBytes(frame_size_in_bytes);
     method->SetCoreSpillMask(core_spill_mask);
diff --git a/src/oat_writer.h b/src/oat_writer.h
index 09db96b..c5114fc 100644
--- a/src/oat_writer.h
+++ b/src/oat_writer.h
@@ -64,7 +64,6 @@
  public:
   // Write an oat file. Returns true on success, false on failure.
   static bool Create(File* file,
-                     jobject class_loader,
                      const std::vector<const DexFile*>& dex_files,
                      uint32_t image_file_location_oat_checksum,
                      uint32_t image_file_location_oat_begin,
@@ -77,7 +76,6 @@
             uint32_t image_file_location_oat_checksum,
             uint32_t image_file_location_oat_begin,
             const std::string& image_file_location,
-            jobject class_loader,
             const Compiler& compiler) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
   ~OatWriter();
 
@@ -152,9 +150,6 @@
 
   const Compiler* compiler_;
 
-  // TODO: remove the ClassLoader when the code storage moves out of Method
-  jobject class_loader_;
-
   // note OatFile does not take ownership of the DexFiles
   const std::vector<const DexFile*>* dex_files_;