Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 16 | |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 17 | #include "heap.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 18 | |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 19 | #include <sys/types.h> |
| 20 | #include <sys/wait.h> |
| 21 | |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 22 | #include <limits> |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 23 | #include <vector> |
| 24 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 25 | #include "card_table.h" |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 26 | #include "debugger.h" |
Brian Carlstrom | 9cff8e1 | 2011-08-18 16:47:29 -0700 | [diff] [blame] | 27 | #include "image.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 28 | #include "mark_sweep.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 29 | #include "object.h" |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 30 | #include "object_utils.h" |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 31 | #include "os.h" |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 32 | #include "scoped_heap_lock.h" |
Brian Carlstrom | 578bbdc | 2011-07-21 14:07:47 -0700 | [diff] [blame] | 33 | #include "space.h" |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 34 | #include "stl_util.h" |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 35 | #include "thread_list.h" |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 36 | #include "timing_logger.h" |
| 37 | #include "UniquePtr.h" |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 41 | static void UpdateFirstAndLastSpace(Space** first_space, Space** last_space, Space* space) { |
| 42 | if (*first_space == NULL) { |
| 43 | *first_space = space; |
| 44 | *last_space = space; |
| 45 | } else { |
| 46 | if ((*first_space)->Begin() > space->Begin()) { |
| 47 | *first_space = space; |
| 48 | } else if (space->Begin() > (*last_space)->Begin()) { |
| 49 | *last_space = space; |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 54 | static bool GenerateImage(const std::string image_file_name) { |
Brian Carlstrom | a004aa9 | 2012-02-08 18:05:09 -0800 | [diff] [blame] | 55 | const std::string boot_class_path_string(Runtime::Current()->GetBootClassPathString()); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 56 | std::vector<std::string> boot_class_path; |
| 57 | Split(boot_class_path_string, ':', boot_class_path); |
Brian Carlstrom | b279337 | 2012-03-17 18:27:16 -0700 | [diff] [blame^] | 58 | if (boot_class_path.empty()) { |
| 59 | LOG(FATAL) << "Failed to generate image because no boot class path specified"; |
| 60 | } |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 61 | |
| 62 | std::vector<char*> arg_vector; |
| 63 | |
| 64 | std::string dex2oat_string(GetAndroidRoot()); |
| 65 | dex2oat_string += "/bin/dex2oat"; |
| 66 | #ifndef NDEBUG |
| 67 | dex2oat_string += 'd'; |
| 68 | #endif |
| 69 | const char* dex2oat = dex2oat_string.c_str(); |
| 70 | arg_vector.push_back(strdup(dex2oat)); |
| 71 | |
| 72 | std::string image_option_string("--image="); |
| 73 | image_option_string += image_file_name; |
| 74 | const char* image_option = image_option_string.c_str(); |
| 75 | arg_vector.push_back(strdup(image_option)); |
| 76 | |
| 77 | arg_vector.push_back(strdup("--runtime-arg")); |
| 78 | arg_vector.push_back(strdup("-Xms64m")); |
| 79 | |
| 80 | arg_vector.push_back(strdup("--runtime-arg")); |
| 81 | arg_vector.push_back(strdup("-Xmx64m")); |
| 82 | |
| 83 | for (size_t i = 0; i < boot_class_path.size(); i++) { |
| 84 | std::string dex_file_option_string("--dex-file="); |
| 85 | dex_file_option_string += boot_class_path[i]; |
| 86 | const char* dex_file_option = dex_file_option_string.c_str(); |
| 87 | arg_vector.push_back(strdup(dex_file_option)); |
| 88 | } |
| 89 | |
| 90 | std::string oat_file_option_string("--oat-file="); |
| 91 | oat_file_option_string += image_file_name; |
| 92 | oat_file_option_string.erase(oat_file_option_string.size() - 3); |
| 93 | oat_file_option_string += "oat"; |
| 94 | const char* oat_file_option = oat_file_option_string.c_str(); |
| 95 | arg_vector.push_back(strdup(oat_file_option)); |
| 96 | |
| 97 | arg_vector.push_back(strdup("--base=0x60000000")); |
| 98 | |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 99 | std::string command_line(Join(arg_vector, ' ')); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 100 | LOG(INFO) << command_line; |
| 101 | |
Elliott Hughes | 48436bb | 2012-02-07 15:23:28 -0800 | [diff] [blame] | 102 | arg_vector.push_back(NULL); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 103 | char** argv = &arg_vector[0]; |
| 104 | |
| 105 | // fork and exec dex2oat |
| 106 | pid_t pid = fork(); |
| 107 | if (pid == 0) { |
| 108 | // no allocation allowed between fork and exec |
| 109 | |
| 110 | // change process groups, so we don't get reaped by ProcessManager |
| 111 | setpgid(0, 0); |
| 112 | |
| 113 | execv(dex2oat, argv); |
| 114 | |
| 115 | PLOG(FATAL) << "execv(" << dex2oat << ") failed"; |
| 116 | return false; |
| 117 | } else { |
| 118 | STLDeleteElements(&arg_vector); |
| 119 | |
| 120 | // wait for dex2oat to finish |
| 121 | int status; |
| 122 | pid_t got_pid = TEMP_FAILURE_RETRY(waitpid(pid, &status, 0)); |
| 123 | if (got_pid != pid) { |
| 124 | PLOG(ERROR) << "waitpid failed: wanted " << pid << ", got " << got_pid; |
| 125 | return false; |
| 126 | } |
| 127 | if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { |
| 128 | LOG(ERROR) << dex2oat << " failed: " << command_line; |
| 129 | return false; |
| 130 | } |
| 131 | } |
| 132 | return true; |
| 133 | } |
| 134 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 135 | Heap::Heap(size_t initial_size, size_t growth_limit, size_t capacity, |
| 136 | const std::string& original_image_file_name) |
| 137 | : lock_(NULL), |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 138 | image_space_(NULL), |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 139 | alloc_space_(NULL), |
| 140 | mark_bitmap_(NULL), |
| 141 | live_bitmap_(NULL), |
| 142 | card_table_(NULL), |
| 143 | card_marking_disabled_(false), |
| 144 | is_gc_running_(false), |
| 145 | num_bytes_allocated_(0), |
| 146 | num_objects_allocated_(0), |
| 147 | java_lang_ref_FinalizerReference_(NULL), |
| 148 | java_lang_ref_ReferenceQueue_(NULL), |
| 149 | reference_referent_offset_(0), |
| 150 | reference_queue_offset_(0), |
| 151 | reference_queueNext_offset_(0), |
| 152 | reference_pendingNext_offset_(0), |
| 153 | finalizer_reference_zombie_offset_(0), |
| 154 | target_utilization_(0.5), |
| 155 | verify_objects_(false) |
| 156 | { |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 157 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 158 | LOG(INFO) << "Heap() entering"; |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 161 | // Compute the bounds of all spaces for allocating live and mark bitmaps |
| 162 | // there will be at least one space (the alloc space) |
| 163 | Space* first_space = NULL; |
| 164 | Space* last_space = NULL; |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 165 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 166 | // Requested begin for the alloc space, to follow the mapped image and oat files |
| 167 | byte* requested_begin = NULL; |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 168 | std::string image_file_name(original_image_file_name); |
| 169 | if (!image_file_name.empty()) { |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 170 | if (OS::FileExists(image_file_name.c_str())) { |
| 171 | // If the /system file exists, it should be up-to-date, don't try to generate |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 172 | image_space_ = Space::CreateImageSpace(image_file_name); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 173 | } else { |
| 174 | // If the /system file didn't exist, we need to use one from the art-cache. |
| 175 | // If the cache file exists, try to open, but if it fails, regenerate. |
| 176 | // If it does not exist, generate. |
| 177 | image_file_name = GetArtCacheFilenameOrDie(image_file_name); |
| 178 | if (OS::FileExists(image_file_name.c_str())) { |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 179 | image_space_ = Space::CreateImageSpace(image_file_name); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 180 | } |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 181 | if (image_space_ == NULL) { |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 182 | if (!GenerateImage(image_file_name)) { |
| 183 | LOG(FATAL) << "Failed to generate image: " << image_file_name; |
| 184 | } |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 185 | image_space_ = Space::CreateImageSpace(image_file_name); |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 188 | if (image_space_ == NULL) { |
Brian Carlstrom | 223f20f | 2012-02-04 23:06:55 -0800 | [diff] [blame] | 189 | LOG(FATAL) << "Failed to create space from " << image_file_name; |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 190 | } |
Brian Carlstrom | 5643b78 | 2012-02-05 12:32:53 -0800 | [diff] [blame] | 191 | |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 192 | AddSpace(image_space_); |
| 193 | UpdateFirstAndLastSpace(&first_space, &last_space, image_space_); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 194 | // Oat files referenced by image files immediately follow them in memory, ensure alloc space |
| 195 | // isn't going to get in the middle |
Brian Carlstrom | fddf6f6 | 2012-03-15 16:56:45 -0700 | [diff] [blame] | 196 | byte* oat_end_addr = image_space_->GetImageHeader().GetOatEnd(); |
| 197 | CHECK(oat_end_addr > image_space_->End()); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 198 | if (oat_end_addr > requested_begin) { |
| 199 | requested_begin = reinterpret_cast<byte*>(RoundUp(reinterpret_cast<uintptr_t>(oat_end_addr), |
| 200 | kPageSize)); |
Brian Carlstrom | 58ae941 | 2011-10-04 00:56:06 -0700 | [diff] [blame] | 201 | } |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 204 | alloc_space_ = Space::CreateAllocSpace("alloc space", initial_size, growth_limit, capacity, |
| 205 | requested_begin); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 206 | if (alloc_space_ == NULL) { |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 207 | LOG(FATAL) << "Failed to create alloc space"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 208 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 209 | AddSpace(alloc_space_); |
| 210 | UpdateFirstAndLastSpace(&first_space, &last_space, alloc_space_); |
| 211 | byte* heap_begin = first_space->Begin(); |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 212 | size_t heap_capacity = (last_space->Begin() - first_space->Begin()) + last_space->NonGrowthLimitCapacity(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 213 | |
| 214 | // Allocate the initial live bitmap. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 215 | UniquePtr<HeapBitmap> live_bitmap(HeapBitmap::Create("dalvik-bitmap-1", heap_begin, heap_capacity)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 216 | if (live_bitmap.get() == NULL) { |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 217 | LOG(FATAL) << "Failed to create live bitmap"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 220 | // Mark image objects in the live bitmap |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 221 | for (size_t i = 0; i < spaces_.size(); ++i) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 222 | Space* space = spaces_[i]; |
| 223 | if (space->IsImageSpace()) { |
| 224 | space->AsImageSpace()->RecordImageAllocations(live_bitmap.get()); |
| 225 | } |
| 226 | } |
| 227 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 228 | // Allocate the initial mark bitmap. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 229 | UniquePtr<HeapBitmap> mark_bitmap(HeapBitmap::Create("dalvik-bitmap-2", heap_begin, heap_capacity)); |
Elliott Hughes | 90a3369 | 2011-08-30 13:27:07 -0700 | [diff] [blame] | 230 | if (mark_bitmap.get() == NULL) { |
Elliott Hughes | be759c6 | 2011-09-08 19:38:21 -0700 | [diff] [blame] | 231 | LOG(FATAL) << "Failed to create mark bitmap"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Elliott Hughes | 6c9c06d | 2011-11-07 16:43:47 -0800 | [diff] [blame] | 234 | // Allocate the card table. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 235 | UniquePtr<CardTable> card_table(CardTable::Create(heap_begin, heap_capacity)); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 236 | if (card_table.get() == NULL) { |
| 237 | LOG(FATAL) << "Failed to create card table"; |
| 238 | } |
| 239 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 240 | live_bitmap_ = live_bitmap.release(); |
| 241 | mark_bitmap_ = mark_bitmap.release(); |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 242 | card_table_ = card_table.release(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 243 | |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 244 | num_bytes_allocated_ = 0; |
| 245 | num_objects_allocated_ = 0; |
| 246 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 247 | // It's still too early to take a lock because there are no threads yet, |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 248 | // but we can create the heap lock now. We don't create it earlier to |
| 249 | // make it clear that you can't use locks during heap initialization. |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 250 | lock_ = new Mutex("Heap lock", kHeapLock); |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 251 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 252 | Heap::EnableObjectValidation(); |
| 253 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 254 | if (VLOG_IS_ON(heap) || VLOG_IS_ON(startup)) { |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 255 | LOG(INFO) << "Heap() exiting"; |
Brian Carlstrom | 0a5b14d | 2011-09-27 13:29:15 -0700 | [diff] [blame] | 256 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 257 | } |
| 258 | |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 259 | void Heap::AddSpace(Space* space) { |
| 260 | spaces_.push_back(space); |
| 261 | } |
| 262 | |
| 263 | Heap::~Heap() { |
| 264 | VLOG(heap) << "~Heap()"; |
Elliott Hughes | b3e66df | 2012-01-12 14:49:18 -0800 | [diff] [blame] | 265 | // We can't take the heap lock here because there might be a daemon thread suspended with the |
| 266 | // heap lock held. We know though that no non-daemon threads are executing, and we know that |
| 267 | // all daemon threads are suspended, and we also know that the threads list have been deleted, so |
| 268 | // those threads can't resume. We're the only running thread, and we can do whatever we like... |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 269 | STLDeleteElements(&spaces_); |
Elliott Hughes | 4d6850c | 2012-01-18 15:55:06 -0800 | [diff] [blame] | 270 | delete mark_bitmap_; |
| 271 | delete live_bitmap_; |
| 272 | delete card_table_; |
| 273 | delete lock_; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 276 | Object* Heap::AllocObject(Class* klass, size_t byte_count) { |
| 277 | { |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 278 | ScopedHeapLock heap_lock; |
Ian Rogers | 6d4d9fc | 2011-11-30 16:24:48 -0800 | [diff] [blame] | 279 | DCHECK(klass == NULL || (klass->IsClassClass() && byte_count >= sizeof(Class)) || |
| 280 | (klass->IsVariableSize() || klass->GetObjectSize() == byte_count) || |
Elliott Hughes | 91250e0 | 2011-12-13 22:30:35 -0800 | [diff] [blame] | 281 | strlen(ClassHelper(klass).GetDescriptor()) == 0); |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 282 | DCHECK_GE(byte_count, sizeof(Object)); |
| 283 | Object* obj = AllocateLocked(byte_count); |
| 284 | if (obj != NULL) { |
| 285 | obj->SetClass(klass); |
Elliott Hughes | 545a064 | 2011-11-08 19:10:03 -0800 | [diff] [blame] | 286 | if (Dbg::IsAllocTrackingEnabled()) { |
| 287 | Dbg::RecordAllocation(klass, byte_count); |
| 288 | } |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 289 | return obj; |
| 290 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 291 | } |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 292 | |
| 293 | Thread::Current()->ThrowOutOfMemoryError(klass, byte_count); |
| 294 | return NULL; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Elliott Hughes | cf4c6c4 | 2011-09-01 15:16:42 -0700 | [diff] [blame] | 297 | bool Heap::IsHeapAddress(const Object* obj) { |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 298 | // Note: we deliberately don't take the lock here, and mustn't test anything that would |
| 299 | // require taking the lock. |
Elliott Hughes | 88c5c35 | 2012-03-15 18:49:48 -0700 | [diff] [blame] | 300 | if (obj == NULL) { |
| 301 | return true; |
| 302 | } |
| 303 | if (!IsAligned<kObjectAlignment>(obj)) { |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 304 | return false; |
| 305 | } |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 306 | for (size_t i = 0; i < spaces_.size(); ++i) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 307 | if (spaces_[i]->Contains(obj)) { |
| 308 | return true; |
| 309 | } |
| 310 | } |
| 311 | return false; |
Elliott Hughes | a250199 | 2011-08-26 19:39:54 -0700 | [diff] [blame] | 312 | } |
| 313 | |
Elliott Hughes | 6a5bd49 | 2011-10-28 14:33:57 -0700 | [diff] [blame] | 314 | bool Heap::IsLiveObjectLocked(const Object* obj) { |
| 315 | lock_->AssertHeld(); |
| 316 | return IsHeapAddress(obj) && live_bitmap_->Test(obj); |
| 317 | } |
| 318 | |
Elliott Hughes | 3e465b1 | 2011-09-02 18:26:12 -0700 | [diff] [blame] | 319 | #if VERIFY_OBJECT_ENABLED |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 320 | void Heap::VerifyObject(const Object* obj) { |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 321 | if (!verify_objects_) { |
| 322 | return; |
| 323 | } |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 324 | ScopedHeapLock heap_lock; |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 325 | Heap::VerifyObjectLocked(obj); |
| 326 | } |
| 327 | #endif |
| 328 | |
| 329 | void Heap::VerifyObjectLocked(const Object* obj) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 330 | lock_->AssertHeld(); |
Elliott Hughes | 85d1545 | 2011-09-16 17:33:01 -0700 | [diff] [blame] | 331 | if (obj != NULL) { |
Elliott Hughes | 06b37d9 | 2011-10-16 11:51:29 -0700 | [diff] [blame] | 332 | if (!IsAligned<kObjectAlignment>(obj)) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 333 | LOG(FATAL) << "Object isn't aligned: " << obj; |
| 334 | } else if (!live_bitmap_->Test(obj)) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 335 | LOG(FATAL) << "Object is dead: " << obj; |
| 336 | } |
| 337 | // Ignore early dawn of the universe verifications |
Brian Carlstrom | dbc0525 | 2011-09-09 01:59:59 -0700 | [diff] [blame] | 338 | if (num_objects_allocated_ > 10) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 339 | const byte* raw_addr = reinterpret_cast<const byte*>(obj) + |
| 340 | Object::ClassOffset().Int32Value(); |
| 341 | const Class* c = *reinterpret_cast<Class* const *>(raw_addr); |
| 342 | if (c == NULL) { |
Elliott Hughes | 5d78d39 | 2011-12-13 16:53:05 -0800 | [diff] [blame] | 343 | LOG(FATAL) << "Null class in object: " << obj; |
Elliott Hughes | 06b37d9 | 2011-10-16 11:51:29 -0700 | [diff] [blame] | 344 | } else if (!IsAligned<kObjectAlignment>(c)) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 345 | LOG(FATAL) << "Class isn't aligned: " << c << " in object: " << obj; |
| 346 | } else if (!live_bitmap_->Test(c)) { |
| 347 | LOG(FATAL) << "Class of object is dead: " << c << " in object: " << obj; |
| 348 | } |
| 349 | // Check obj.getClass().getClass() == obj.getClass().getClass().getClass() |
Ian Rogers | ad25ac5 | 2011-10-04 19:13:33 -0700 | [diff] [blame] | 350 | // Note: we don't use the accessors here as they have internal sanity checks |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 351 | // that we don't want to run |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 352 | raw_addr = reinterpret_cast<const byte*>(c) + Object::ClassOffset().Int32Value(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 353 | const Class* c_c = *reinterpret_cast<Class* const *>(raw_addr); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 354 | raw_addr = reinterpret_cast<const byte*>(c_c) + Object::ClassOffset().Int32Value(); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 355 | const Class* c_c_c = *reinterpret_cast<Class* const *>(raw_addr); |
| 356 | CHECK_EQ(c_c, c_c_c); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
Brian Carlstrom | 78128a6 | 2011-09-15 17:21:19 -0700 | [diff] [blame] | 361 | void Heap::VerificationCallback(Object* obj, void* arg) { |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 362 | DCHECK(obj != NULL); |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 363 | reinterpret_cast<Heap*>(arg)->VerifyObjectLocked(obj); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | void Heap::VerifyHeap() { |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 367 | ScopedHeapLock heap_lock; |
Elliott Hughes | b3bd5f0 | 2012-03-08 21:05:27 -0800 | [diff] [blame] | 368 | live_bitmap_->Walk(Heap::VerificationCallback, this); |
Ian Rogers | 0cfe1fb | 2011-08-26 03:29:44 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 371 | void Heap::RecordAllocationLocked(AllocSpace* space, const Object* obj) { |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 372 | #ifndef NDEBUG |
| 373 | if (Runtime::Current()->IsStarted()) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 374 | lock_->AssertHeld(); |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 375 | } |
| 376 | #endif |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 377 | size_t size = space->AllocationSize(obj); |
Elliott Hughes | 5d78d39 | 2011-12-13 16:53:05 -0800 | [diff] [blame] | 378 | DCHECK_GT(size, 0u); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 379 | num_bytes_allocated_ += size; |
| 380 | num_objects_allocated_ += 1; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 381 | |
| 382 | if (Runtime::Current()->HasStatsEnabled()) { |
| 383 | RuntimeStats* global_stats = Runtime::Current()->GetStats(); |
| 384 | RuntimeStats* thread_stats = Thread::Current()->GetStats(); |
| 385 | ++global_stats->allocated_objects; |
| 386 | ++thread_stats->allocated_objects; |
| 387 | global_stats->allocated_bytes += size; |
| 388 | thread_stats->allocated_bytes += size; |
| 389 | } |
| 390 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 391 | live_bitmap_->Set(obj); |
| 392 | } |
| 393 | |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 394 | void Heap::RecordFreeLocked(size_t freed_objects, size_t freed_bytes) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 395 | lock_->AssertHeld(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 396 | |
| 397 | if (freed_objects < num_objects_allocated_) { |
| 398 | num_objects_allocated_ -= freed_objects; |
| 399 | } else { |
| 400 | num_objects_allocated_ = 0; |
| 401 | } |
| 402 | if (freed_bytes < num_bytes_allocated_) { |
| 403 | num_bytes_allocated_ -= freed_bytes; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 404 | } else { |
| 405 | num_bytes_allocated_ = 0; |
| 406 | } |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 407 | |
| 408 | if (Runtime::Current()->HasStatsEnabled()) { |
| 409 | RuntimeStats* global_stats = Runtime::Current()->GetStats(); |
| 410 | RuntimeStats* thread_stats = Thread::Current()->GetStats(); |
| 411 | ++global_stats->freed_objects; |
| 412 | ++thread_stats->freed_objects; |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 413 | global_stats->freed_bytes += freed_bytes; |
| 414 | thread_stats->freed_bytes += freed_bytes; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 415 | } |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 418 | Object* Heap::AllocateLocked(size_t size) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 419 | lock_->AssertHeld(); |
Brian Carlstrom | 4a289ed | 2011-08-16 17:17:49 -0700 | [diff] [blame] | 420 | DCHECK(alloc_space_ != NULL); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 421 | AllocSpace* space = alloc_space_; |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 422 | Object* obj = AllocateLocked(space, size); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 423 | if (obj != NULL) { |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 424 | RecordAllocationLocked(space, obj); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 425 | } |
| 426 | return obj; |
| 427 | } |
| 428 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 429 | Object* Heap::AllocateLocked(AllocSpace* space, size_t alloc_size) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 430 | lock_->AssertHeld(); |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 431 | |
Brian Carlstrom | b82b687 | 2011-10-26 17:18:07 -0700 | [diff] [blame] | 432 | // Since allocation can cause a GC which will need to SuspendAll, |
| 433 | // make sure all allocators are in the kRunnable state. |
Ian Rogers | f45b154 | 2012-02-03 18:03:48 -0800 | [diff] [blame] | 434 | CHECK_EQ(Thread::Current()->GetState(), Thread::kRunnable); |
Brian Carlstrom | b82b687 | 2011-10-26 17:18:07 -0700 | [diff] [blame] | 435 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 436 | // Fail impossible allocations |
| 437 | if (alloc_size > space->Capacity()) { |
| 438 | // On failure collect soft references |
| 439 | CollectGarbageInternal(true); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 440 | return NULL; |
| 441 | } |
| 442 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 443 | Object* ptr = space->AllocWithoutGrowth(alloc_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 444 | if (ptr != NULL) { |
| 445 | return ptr; |
| 446 | } |
| 447 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 448 | // The allocation failed. If the GC is running, block until it completes and retry. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 449 | if (is_gc_running_) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 450 | // The GC is concurrently tracing the heap. Release the heap lock, wait for the GC to |
| 451 | // complete, and retrying allocating. |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 452 | WaitForConcurrentGcToComplete(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 453 | ptr = space->AllocWithoutGrowth(alloc_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 454 | if (ptr != NULL) { |
| 455 | return ptr; |
| 456 | } |
| 457 | } |
| 458 | |
| 459 | // Another failure. Our thread was starved or there may be too many |
| 460 | // live objects. Try a foreground GC. This will have no effect if |
| 461 | // the concurrent GC is already running. |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 462 | if (Runtime::Current()->HasStatsEnabled()) { |
| 463 | ++Runtime::Current()->GetStats()->gc_for_alloc_count; |
| 464 | ++Thread::Current()->GetStats()->gc_for_alloc_count; |
| 465 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 466 | CollectGarbageInternal(false); |
| 467 | ptr = space->AllocWithoutGrowth(alloc_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 468 | if (ptr != NULL) { |
| 469 | return ptr; |
| 470 | } |
| 471 | |
| 472 | // Even that didn't work; this is an exceptional state. |
| 473 | // Try harder, growing the heap if necessary. |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 474 | ptr = space->AllocWithGrowth(alloc_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 475 | if (ptr != NULL) { |
| 476 | //size_t new_footprint = dvmHeapSourceGetIdealFootprint(); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 477 | size_t new_footprint = space->GetFootprintLimit(); |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 478 | // OLD-TODO: may want to grow a little bit more so that the amount of |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 479 | // free space is equal to the old free space + the |
| 480 | // utilization slop for the new allocation. |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 481 | VLOG(gc) << "Grow heap (frag case) to " << PrettySize(new_footprint) |
Ian Rogers | 162a31c | 2012-01-31 16:14:31 -0800 | [diff] [blame] | 482 | << " for a " << PrettySize(alloc_size) << " allocation"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 483 | return ptr; |
| 484 | } |
| 485 | |
| 486 | // Most allocations should have succeeded by now, so the heap is |
| 487 | // really full, really fragmented, or the requested size is really |
| 488 | // big. Do another GC, collecting SoftReferences this time. The VM |
| 489 | // spec requires that all SoftReferences have been collected and |
| 490 | // cleared before throwing an OOME. |
| 491 | |
Elliott Hughes | 418dfe7 | 2011-10-06 18:56:27 -0700 | [diff] [blame] | 492 | // OLD-TODO: wait for the finalizers from the previous GC to finish |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 493 | VLOG(gc) << "Forcing collection of SoftReferences for " << PrettySize(alloc_size) << " allocation"; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 494 | CollectGarbageInternal(true); |
| 495 | ptr = space->AllocWithGrowth(alloc_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 496 | if (ptr != NULL) { |
| 497 | return ptr; |
| 498 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 499 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 500 | LOG(ERROR) << "Out of memory on a " << PrettySize(alloc_size) << " allocation"; |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 501 | |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 502 | // TODO: tell the HeapSource to dump its state |
| 503 | // TODO: dump stack traces for all threads |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 504 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 505 | return NULL; |
| 506 | } |
| 507 | |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 508 | int64_t Heap::GetMaxMemory() { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 509 | return alloc_space_->Capacity(); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | int64_t Heap::GetTotalMemory() { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 513 | return alloc_space_->Capacity(); |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | int64_t Heap::GetFreeMemory() { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 517 | return alloc_space_->Capacity() - num_bytes_allocated_; |
Elliott Hughes | bf86d04 | 2011-08-31 17:53:14 -0700 | [diff] [blame] | 518 | } |
| 519 | |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 520 | class InstanceCounter { |
| 521 | public: |
| 522 | InstanceCounter(Class* c, bool count_assignable) |
| 523 | : class_(c), count_assignable_(count_assignable), count_(0) { |
| 524 | } |
| 525 | |
| 526 | size_t GetCount() { |
| 527 | return count_; |
| 528 | } |
| 529 | |
| 530 | static void Callback(Object* o, void* arg) { |
| 531 | reinterpret_cast<InstanceCounter*>(arg)->VisitInstance(o); |
| 532 | } |
| 533 | |
| 534 | private: |
| 535 | void VisitInstance(Object* o) { |
| 536 | Class* instance_class = o->GetClass(); |
| 537 | if (count_assignable_) { |
| 538 | if (instance_class == class_) { |
| 539 | ++count_; |
| 540 | } |
| 541 | } else { |
| 542 | if (instance_class != NULL && class_->IsAssignableFrom(instance_class)) { |
| 543 | ++count_; |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | Class* class_; |
| 549 | bool count_assignable_; |
| 550 | size_t count_; |
| 551 | }; |
| 552 | |
| 553 | int64_t Heap::CountInstances(Class* c, bool count_assignable) { |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 554 | ScopedHeapLock heap_lock; |
Elliott Hughes | 9d5ccec | 2011-09-19 13:19:50 -0700 | [diff] [blame] | 555 | InstanceCounter counter(c, count_assignable); |
| 556 | live_bitmap_->Walk(InstanceCounter::Callback, &counter); |
| 557 | return counter.GetCount(); |
| 558 | } |
| 559 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 560 | void Heap::CollectGarbage(bool clear_soft_references) { |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 561 | ScopedHeapLock heap_lock; |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 562 | CollectGarbageInternal(clear_soft_references); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 563 | } |
| 564 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 565 | void Heap::CollectGarbageInternal(bool clear_soft_references) { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 566 | lock_->AssertHeld(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 567 | |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 568 | ThreadList* thread_list = Runtime::Current()->GetThreadList(); |
| 569 | thread_list->SuspendAll(); |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 570 | |
| 571 | size_t initial_size = num_bytes_allocated_; |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 572 | TimingLogger timings("CollectGarbageInternal"); |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 573 | uint64_t t0 = NanoTime(); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 574 | Object* cleared_references = NULL; |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 575 | { |
| 576 | MarkSweep mark_sweep; |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 577 | timings.AddSplit("ctor"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 578 | |
| 579 | mark_sweep.Init(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 580 | timings.AddSplit("Init"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 581 | |
| 582 | mark_sweep.MarkRoots(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 583 | timings.AddSplit("MarkRoots"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 584 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 585 | mark_sweep.ScanDirtyImageRoots(); |
| 586 | timings.AddSplit("DirtyImageRoots"); |
| 587 | |
| 588 | // Roots are marked on the bitmap and the mark_stack is empty |
| 589 | DCHECK(mark_sweep.IsMarkStackEmpty()); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 590 | |
| 591 | // TODO: if concurrent |
| 592 | // unlock heap |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 593 | // thread_list->ResumeAll(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 594 | |
Ian Rogers | 5d76c43 | 2011-10-31 21:42:49 -0700 | [diff] [blame] | 595 | // Recursively mark all bits set in the non-image mark bitmap |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 596 | mark_sweep.RecursiveMark(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 597 | timings.AddSplit("RecursiveMark"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 598 | |
| 599 | // TODO: if concurrent |
| 600 | // lock heap |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 601 | // thread_list->SuspendAll(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 602 | // re-mark root set |
| 603 | // scan dirty objects |
| 604 | |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 605 | mark_sweep.ProcessReferences(clear_soft_references); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 606 | timings.AddSplit("ProcessReferences"); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 607 | |
Elliott Hughes | 2da5036 | 2011-10-10 16:57:08 -0700 | [diff] [blame] | 608 | // TODO: if concurrent |
| 609 | // swap bitmaps |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 610 | |
| 611 | mark_sweep.Sweep(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 612 | timings.AddSplit("Sweep"); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 613 | |
| 614 | cleared_references = mark_sweep.GetClearedReferences(); |
Carl Shapiro | 58551df | 2011-07-24 03:09:51 -0700 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | GrowForUtilization(); |
Elliott Hughes | 307f75d | 2011-10-12 18:04:40 -0700 | [diff] [blame] | 618 | timings.AddSplit("GrowForUtilization"); |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 619 | uint64_t t1 = NanoTime(); |
Elliott Hughes | 8d768a9 | 2011-09-14 16:35:25 -0700 | [diff] [blame] | 620 | thread_list->ResumeAll(); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 621 | |
| 622 | EnqueueClearedReferences(&cleared_references); |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 623 | RequestHeapTrim(); |
Elliott Hughes | 83df2ac | 2011-10-11 16:37:54 -0700 | [diff] [blame] | 624 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 625 | uint64_t duration_ns = t1 - t0; |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 626 | bool gc_was_particularly_slow = duration_ns > MsToNs(50); // TODO: crank this down for concurrent. |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 627 | if (VLOG_IS_ON(gc) || gc_was_particularly_slow) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 628 | // TODO: somehow make the specific GC implementation (here MarkSweep) responsible for logging. |
| 629 | size_t bytes_freed = initial_size - num_bytes_allocated_; |
| 630 | if (bytes_freed > KB) { // ignore freed bytes in output if > 1KB |
| 631 | bytes_freed = RoundDown(bytes_freed, KB); |
| 632 | } |
| 633 | size_t bytes_allocated = RoundUp(num_bytes_allocated_, KB); |
| 634 | // lose low nanoseconds in duration. TODO: make this part of PrettyDuration |
| 635 | duration_ns = (duration_ns / 1000) * 1000; |
| 636 | size_t total = GetTotalMemory(); |
| 637 | size_t percentFree = 100 - static_cast<size_t>(100.0f * static_cast<float>(num_bytes_allocated_) / total); |
| 638 | LOG(INFO) << "GC freed " << PrettySize(bytes_freed) << ", " << percentFree << "% free, " |
| 639 | << PrettySize(bytes_allocated) << "/" << PrettySize(total) << ", " |
| 640 | << "paused " << PrettyDuration(duration_ns); |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 641 | } |
Elliott Hughes | 767a147 | 2011-10-26 18:49:02 -0700 | [diff] [blame] | 642 | Dbg::GcDidFinish(); |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 643 | if (VLOG_IS_ON(heap)) { |
Brian Carlstrom | 6b4ef02 | 2011-10-23 14:59:04 -0700 | [diff] [blame] | 644 | timings.Dump(); |
| 645 | } |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | void Heap::WaitForConcurrentGcToComplete() { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 649 | lock_->AssertHeld(); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 650 | } |
| 651 | |
Elliott Hughes | 4dd9b4d | 2011-12-12 18:29:24 -0800 | [diff] [blame] | 652 | void Heap::SetIdealFootprint(size_t max_allowed_footprint) { |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 653 | size_t alloc_space_capacity = alloc_space_->Capacity(); |
| 654 | if (max_allowed_footprint > alloc_space_capacity) { |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 655 | VLOG(gc) << "Clamp target GC heap from " << PrettySize(max_allowed_footprint) |
| 656 | << " to " << PrettySize(alloc_space_capacity); |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 657 | max_allowed_footprint = alloc_space_capacity; |
Shih-wei Liao | 8c2f641 | 2011-10-03 22:58:14 -0700 | [diff] [blame] | 658 | } |
Ian Rogers | 30fab40 | 2012-01-23 15:43:46 -0800 | [diff] [blame] | 659 | alloc_space_->SetFootprintLimit(max_allowed_footprint); |
Shih-wei Liao | 8c2f641 | 2011-10-03 22:58:14 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 662 | // kHeapIdealFree is the ideal maximum free size, when we grow the heap for utilization. |
Shih-wei Liao | 7f1caab | 2011-10-06 12:11:04 -0700 | [diff] [blame] | 663 | static const size_t kHeapIdealFree = 2 * MB; |
Ian Rogers | 3bb17a6 | 2012-01-27 23:56:44 -0800 | [diff] [blame] | 664 | // kHeapMinFree guarantees that you always have at least 512 KB free, when you grow for utilization, |
| 665 | // regardless of target utilization ratio. |
Shih-wei Liao | 8c2f641 | 2011-10-03 22:58:14 -0700 | [diff] [blame] | 666 | static const size_t kHeapMinFree = kHeapIdealFree / 4; |
| 667 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 668 | void Heap::GrowForUtilization() { |
Elliott Hughes | 8daa092 | 2011-09-11 13:46:25 -0700 | [diff] [blame] | 669 | lock_->AssertHeld(); |
Shih-wei Liao | 8c2f641 | 2011-10-03 22:58:14 -0700 | [diff] [blame] | 670 | |
| 671 | // We know what our utilization is at this moment. |
| 672 | // This doesn't actually resize any memory. It just lets the heap grow more |
| 673 | // when necessary. |
Elliott Hughes | 362f9bc | 2011-10-17 18:56:41 -0700 | [diff] [blame] | 674 | size_t target_size(num_bytes_allocated_ / Heap::GetTargetHeapUtilization()); |
Shih-wei Liao | 8c2f641 | 2011-10-03 22:58:14 -0700 | [diff] [blame] | 675 | |
| 676 | if (target_size > num_bytes_allocated_ + kHeapIdealFree) { |
| 677 | target_size = num_bytes_allocated_ + kHeapIdealFree; |
| 678 | } else if (target_size < num_bytes_allocated_ + kHeapMinFree) { |
| 679 | target_size = num_bytes_allocated_ + kHeapMinFree; |
| 680 | } |
| 681 | |
| 682 | SetIdealFootprint(target_size); |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 683 | } |
| 684 | |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 685 | void Heap::ClearGrowthLimit() { |
Elliott Hughes | ffb465f | 2012-03-01 18:46:05 -0800 | [diff] [blame] | 686 | ScopedHeapLock heap_lock; |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 687 | WaitForConcurrentGcToComplete(); |
jeffhao | c116070 | 2011-10-27 15:48:45 -0700 | [diff] [blame] | 688 | alloc_space_->ClearGrowthLimit(); |
| 689 | } |
| 690 | |
Brian Carlstrom | 24a3c2e | 2011-10-17 18:07:52 -0700 | [diff] [blame] | 691 | pid_t Heap::GetLockOwner() { |
Elliott Hughes | accd83d | 2011-10-17 14:25:58 -0700 | [diff] [blame] | 692 | return lock_->GetOwner(); |
| 693 | } |
| 694 | |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 695 | void Heap::Lock() { |
Brian Carlstrom | fad7143 | 2011-10-16 20:25:10 -0700 | [diff] [blame] | 696 | // Grab the lock, but put ourselves into Thread::kVmWait if it looks |
| 697 | // like we're going to have to wait on the mutex. This prevents |
| 698 | // deadlock if another thread is calling CollectGarbageInternal, |
| 699 | // since they will have the heap lock and be waiting for mutators to |
| 700 | // suspend. |
| 701 | if (!lock_->TryLock()) { |
| 702 | ScopedThreadStateChange tsc(Thread::Current(), Thread::kVmWait); |
| 703 | lock_->Lock(); |
| 704 | } |
Elliott Hughes | 92b3b56 | 2011-09-08 16:32:26 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | void Heap::Unlock() { |
| 708 | lock_->Unlock(); |
| 709 | } |
| 710 | |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 711 | void Heap::SetWellKnownClasses(Class* java_lang_ref_FinalizerReference, |
| 712 | Class* java_lang_ref_ReferenceQueue) { |
| 713 | java_lang_ref_FinalizerReference_ = java_lang_ref_FinalizerReference; |
| 714 | java_lang_ref_ReferenceQueue_ = java_lang_ref_ReferenceQueue; |
| 715 | CHECK(java_lang_ref_FinalizerReference_ != NULL); |
| 716 | CHECK(java_lang_ref_ReferenceQueue_ != NULL); |
| 717 | } |
| 718 | |
| 719 | void Heap::SetReferenceOffsets(MemberOffset reference_referent_offset, |
| 720 | MemberOffset reference_queue_offset, |
| 721 | MemberOffset reference_queueNext_offset, |
| 722 | MemberOffset reference_pendingNext_offset, |
| 723 | MemberOffset finalizer_reference_zombie_offset) { |
| 724 | reference_referent_offset_ = reference_referent_offset; |
| 725 | reference_queue_offset_ = reference_queue_offset; |
| 726 | reference_queueNext_offset_ = reference_queueNext_offset; |
| 727 | reference_pendingNext_offset_ = reference_pendingNext_offset; |
| 728 | finalizer_reference_zombie_offset_ = finalizer_reference_zombie_offset; |
| 729 | CHECK_NE(reference_referent_offset_.Uint32Value(), 0U); |
| 730 | CHECK_NE(reference_queue_offset_.Uint32Value(), 0U); |
| 731 | CHECK_NE(reference_queueNext_offset_.Uint32Value(), 0U); |
| 732 | CHECK_NE(reference_pendingNext_offset_.Uint32Value(), 0U); |
| 733 | CHECK_NE(finalizer_reference_zombie_offset_.Uint32Value(), 0U); |
| 734 | } |
| 735 | |
| 736 | Object* Heap::GetReferenceReferent(Object* reference) { |
| 737 | DCHECK(reference != NULL); |
| 738 | DCHECK_NE(reference_referent_offset_.Uint32Value(), 0U); |
| 739 | return reference->GetFieldObject<Object*>(reference_referent_offset_, true); |
| 740 | } |
| 741 | |
| 742 | void Heap::ClearReferenceReferent(Object* reference) { |
| 743 | DCHECK(reference != NULL); |
| 744 | DCHECK_NE(reference_referent_offset_.Uint32Value(), 0U); |
| 745 | reference->SetFieldObject(reference_referent_offset_, NULL, true); |
| 746 | } |
| 747 | |
| 748 | // Returns true if the reference object has not yet been enqueued. |
| 749 | bool Heap::IsEnqueuable(const Object* ref) { |
| 750 | DCHECK(ref != NULL); |
| 751 | const Object* queue = ref->GetFieldObject<Object*>(reference_queue_offset_, false); |
| 752 | const Object* queue_next = ref->GetFieldObject<Object*>(reference_queueNext_offset_, false); |
| 753 | return (queue != NULL) && (queue_next == NULL); |
| 754 | } |
| 755 | |
| 756 | void Heap::EnqueueReference(Object* ref, Object** cleared_reference_list) { |
| 757 | DCHECK(ref != NULL); |
| 758 | CHECK(ref->GetFieldObject<Object*>(reference_queue_offset_, false) != NULL); |
| 759 | CHECK(ref->GetFieldObject<Object*>(reference_queueNext_offset_, false) == NULL); |
| 760 | EnqueuePendingReference(ref, cleared_reference_list); |
| 761 | } |
| 762 | |
| 763 | void Heap::EnqueuePendingReference(Object* ref, Object** list) { |
| 764 | DCHECK(ref != NULL); |
| 765 | DCHECK(list != NULL); |
| 766 | |
| 767 | if (*list == NULL) { |
| 768 | ref->SetFieldObject(reference_pendingNext_offset_, ref, false); |
| 769 | *list = ref; |
| 770 | } else { |
| 771 | Object* head = (*list)->GetFieldObject<Object*>(reference_pendingNext_offset_, false); |
| 772 | ref->SetFieldObject(reference_pendingNext_offset_, head, false); |
| 773 | (*list)->SetFieldObject(reference_pendingNext_offset_, ref, false); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | Object* Heap::DequeuePendingReference(Object** list) { |
| 778 | DCHECK(list != NULL); |
| 779 | DCHECK(*list != NULL); |
| 780 | Object* head = (*list)->GetFieldObject<Object*>(reference_pendingNext_offset_, false); |
| 781 | Object* ref; |
| 782 | if (*list == head) { |
| 783 | ref = *list; |
| 784 | *list = NULL; |
| 785 | } else { |
| 786 | Object* next = head->GetFieldObject<Object*>(reference_pendingNext_offset_, false); |
| 787 | (*list)->SetFieldObject(reference_pendingNext_offset_, next, false); |
| 788 | ref = head; |
| 789 | } |
| 790 | ref->SetFieldObject(reference_pendingNext_offset_, NULL, false); |
| 791 | return ref; |
| 792 | } |
| 793 | |
Ian Rogers | 5d4bdc2 | 2011-11-02 22:15:43 -0700 | [diff] [blame] | 794 | void Heap::AddFinalizerReference(Thread* self, Object* object) { |
| 795 | ScopedThreadStateChange tsc(self, Thread::kRunnable); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 796 | static Method* FinalizerReference_add = |
| 797 | java_lang_ref_FinalizerReference_->FindDirectMethod("add", "(Ljava/lang/Object;)V"); |
| 798 | DCHECK(FinalizerReference_add != NULL); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 799 | JValue args[1]; |
| 800 | args[0].l = object; |
| 801 | FinalizerReference_add->Invoke(self, NULL, args, NULL); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 802 | } |
| 803 | |
| 804 | void Heap::EnqueueClearedReferences(Object** cleared) { |
| 805 | DCHECK(cleared != NULL); |
| 806 | if (*cleared != NULL) { |
| 807 | static Method* ReferenceQueue_add = |
| 808 | java_lang_ref_ReferenceQueue_->FindDirectMethod("add", "(Ljava/lang/ref/Reference;)V"); |
| 809 | DCHECK(ReferenceQueue_add != NULL); |
| 810 | |
| 811 | Thread* self = Thread::Current(); |
| 812 | ScopedThreadStateChange tsc(self, Thread::kRunnable); |
Elliott Hughes | 7740579 | 2012-03-15 15:22:12 -0700 | [diff] [blame] | 813 | JValue args[1]; |
| 814 | args[0].l = *cleared; |
| 815 | ReferenceQueue_add->Invoke(self, NULL, args, NULL); |
Elliott Hughes | adb460d | 2011-10-05 17:02:34 -0700 | [diff] [blame] | 816 | *cleared = NULL; |
| 817 | } |
| 818 | } |
| 819 | |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 820 | void Heap::RequestHeapTrim() { |
| 821 | // We don't have a good measure of how worthwhile a trim might be. We can't use the live bitmap |
| 822 | // because that only marks object heads, so a large array looks like lots of empty space. We |
| 823 | // don't just call dlmalloc all the time, because the cost of an _attempted_ trim is proportional |
| 824 | // to utilization (which is probably inversely proportional to how much benefit we can expect). |
| 825 | // We could try mincore(2) but that's only a measure of how many pages we haven't given away, |
| 826 | // not how much use we're making of those pages. |
| 827 | float utilization = static_cast<float>(num_bytes_allocated_) / alloc_space_->Size(); |
| 828 | if (utilization > 0.75f) { |
| 829 | // Don't bother trimming the heap if it's more than 75% utilized. |
| 830 | // (This percentage was picked arbitrarily.) |
| 831 | return; |
| 832 | } |
Ian Rogers | e1d490c | 2012-02-03 09:09:07 -0800 | [diff] [blame] | 833 | if (!Runtime::Current()->IsStarted()) { |
| 834 | // Heap trimming isn't supported without a Java runtime (such as at dex2oat time) |
| 835 | return; |
| 836 | } |
Elliott Hughes | 8cf5bc0 | 2012-02-02 16:32:16 -0800 | [diff] [blame] | 837 | JNIEnv* env = Thread::Current()->GetJniEnv(); |
| 838 | static jclass Daemons_class = CacheClass(env, "java/lang/Daemons"); |
| 839 | static jmethodID Daemons_requestHeapTrim = env->GetStaticMethodID(Daemons_class, "requestHeapTrim", "()V"); |
| 840 | env->CallStaticVoidMethod(Daemons_class, Daemons_requestHeapTrim); |
| 841 | CHECK(!env->ExceptionCheck()); |
| 842 | } |
| 843 | |
Carl Shapiro | 69759ea | 2011-07-21 18:13:35 -0700 | [diff] [blame] | 844 | } // namespace art |