blob: e1b0ed423b7c46d186d33fc7d9bb60efe340ce21 [file] [log] [blame]
Elliott Hughes2faa5f12012-01-30 14:42:07 -08001/*
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 Shapiro1fb86202011-06-27 17:43:13 -070016
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070017#include "runtime.h"
Carl Shapiro1fb86202011-06-27 17:43:13 -070018
Brian Carlstrombd86bcc2013-03-10 20:26:16 -070019// sys/mount.h has to come before linux/fs.h due to redefinition of MS_RDONLY, MS_BIND, etc
20#include <sys/mount.h>
21#include <linux/fs.h>
22
Brian Carlstromdbf05b72011-12-15 00:55:24 -080023#include <signal.h>
Elliott Hughesd06a6c72012-05-30 17:59:06 -070024#include <sys/syscall.h>
Brian Carlstromdbf05b72011-12-15 00:55:24 -080025
Elliott Hughesffe67362011-07-17 12:09:27 -070026#include <cstdio>
27#include <cstdlib>
Brian Carlstrom8a436592011-08-15 21:27:23 -070028#include <limits>
Carl Shapiro2ed144c2011-07-26 16:52:08 -070029#include <vector>
Elliott Hughesffe67362011-07-17 12:09:27 -070030
Ian Rogers166db042013-07-26 12:05:57 -070031#include "arch/arm/registers_arm.h"
32#include "arch/mips/registers_mips.h"
33#include "arch/x86/registers_x86.h"
Ian Rogersef7d42f2014-01-06 12:55:46 -080034#include "arch/x86_64/registers_x86_64.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080035#include "atomic.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070036#include "class_linker.h"
Elliott Hughes3bb81562011-10-21 18:52:59 -070037#include "debugger.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070038#include "gc/accounting/card_table-inl.h"
39#include "gc/heap.h"
40#include "gc/space/space.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070041#include "image.h"
jeffhao725a9572012-11-13 18:20:12 -080042#include "instrumentation.h"
Elliott Hughescf4c6c42011-09-01 15:16:42 -070043#include "intern_table.h"
Jeff Hao5d917302013-02-27 17:57:33 -080044#include "invoke_arg_array_builder.h"
Elliott Hughesc5f7c912011-08-18 14:00:42 -070045#include "jni_internal.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070046#include "mirror/art_field-inl.h"
47#include "mirror/art_method-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080048#include "mirror/array.h"
Ian Rogers62d6c772013-02-27 08:32:07 -080049#include "mirror/class-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080050#include "mirror/class_loader.h"
Mathieu Chartierc528dba2013-11-26 12:00:11 -080051#include "mirror/stack_trace_element.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080052#include "mirror/throwable.h"
Elliott Hughes32d6e1e2011-10-11 14:47:44 -070053#include "monitor.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070054#include "oat_file.h"
Elliott Hughes726079d2011-10-07 18:43:44 -070055#include "ScopedLocalRef.h"
Ian Rogers00f7d0e2012-07-19 15:28:27 -070056#include "scoped_thread_state_change.h"
Elliott Hughese27955c2011-08-26 15:21:24 -070057#include "signal_catcher.h"
Elliott Hughes457005c2012-04-16 13:54:25 -070058#include "signal_set.h"
Ian Rogers1f539342012-10-03 21:09:42 -070059#include "sirt_ref.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070060#include "thread.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070061#include "thread_list.h"
jeffhaob5e81852012-03-12 11:15:45 -070062#include "trace.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010063#include "transaction.h"
Dave Allison0aded082013-11-07 13:15:11 -080064#include "profiler.h"
Elliott Hughes3bb81562011-10-21 18:52:59 -070065#include "UniquePtr.h"
Ian Rogers776ac1f2012-04-13 23:36:36 -070066#include "verifier/method_verifier.h"
Elliott Hugheseac76672012-05-24 21:56:51 -070067#include "well_known_classes.h"
Carl Shapiro61e019d2011-07-14 16:53:09 -070068
Brian Carlstrom7934ac22013-07-26 10:54:15 -070069#include "JniConstants.h" // Last to avoid LOG redefinition in ics-mr1-plus-art.
Elliott Hughes90a33692011-08-30 13:27:07 -070070
Carl Shapiro1fb86202011-06-27 17:43:13 -070071namespace art {
72
Carl Shapiro2ed144c2011-07-26 16:52:08 -070073Runtime* Runtime::instance_ = NULL;
74
Elliott Hughesdcc24742011-09-07 14:02:44 -070075Runtime::Runtime()
Vladimir Marko2b5eaa22013-12-13 13:59:30 +000076 : compiler_callbacks_(nullptr),
Elliott Hughesd9c67be2012-02-02 19:54:06 -080077 is_zygote_(false),
Mathieu Chartier069387a2012-06-18 12:01:01 -070078 is_concurrent_gc_enabled_(true),
Anwar Ghuloum87183592013-08-14 12:12:19 -070079 is_explicit_gc_disabled_(false),
Ian Rogersef7d42f2014-01-06 12:55:46 -080080 compiler_filter_(kSpeed),
81 huge_method_threshold_(0),
82 large_method_threshold_(0),
83 small_method_threshold_(0),
84 tiny_method_threshold_(0),
85 num_dex_methods_threshold_(0),
86 sea_ir_mode_(false),
Elliott Hughes6cf23882012-06-15 15:42:07 -070087 default_stack_size_(0),
Ian Rogersef7d42f2014-01-06 12:55:46 -080088 heap_(nullptr),
Ian Rogersd9c4fc92013-10-01 19:45:43 -070089 max_spins_before_thin_lock_inflation_(Monitor::kDefaultMaxSpinsBeforeThinLockInflation),
Ian Rogersef7d42f2014-01-06 12:55:46 -080090 monitor_list_(nullptr),
91 monitor_pool_(nullptr),
92 thread_list_(nullptr),
93 intern_table_(nullptr),
94 class_linker_(nullptr),
95 signal_catcher_(nullptr),
96 java_vm_(nullptr),
97 pre_allocated_OutOfMemoryError_(nullptr),
98 resolution_method_(nullptr),
99 imt_conflict_method_(nullptr),
100 default_imt_(nullptr),
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800101 method_verifiers_lock_("Method verifiers lock"),
Ian Rogers120f1c72012-09-28 17:17:10 -0700102 threads_being_born_(0),
Ian Rogersc604d732012-10-14 16:09:54 -0700103 shutdown_cond_(new ConditionVariable("Runtime shutdown", *Locks::runtime_shutdown_lock_)),
Elliott Hughes6b355752012-01-13 16:49:08 -0800104 shutting_down_(false),
Ian Rogers120f1c72012-09-28 17:17:10 -0700105 shutting_down_started_(false),
Elliott Hughesdcc24742011-09-07 14:02:44 -0700106 started_(false),
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700107 finished_starting_(false),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800108 vfprintf_(nullptr),
109 exit_(nullptr),
110 abort_(nullptr),
jeffhao2692b572011-12-16 15:42:28 -0800111 stats_enabled_(false),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800112 profile_(false),
113 profile_period_s_(0),
114 profile_duration_s_(0),
115 profile_interval_us_(0),
116 profile_backoff_coefficient_(0),
117 method_trace_(false),
Ian Rogers776ac1f2012-04-13 23:36:36 -0700118 method_trace_file_size_(0),
Ian Rogers62d6c772013-02-27 08:32:07 -0800119 instrumentation_(),
Ian Rogers365c1022012-06-22 15:05:28 -0700120 use_compile_time_class_path_(false),
Ian Rogersef7d42f2014-01-06 12:55:46 -0800121 main_thread_group_(nullptr),
122 system_thread_group_(nullptr),
123 system_class_loader_(nullptr),
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100124 dump_gc_performance_on_shutdown_(false),
125 preinitialization_transaction(nullptr) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700126 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800127 callee_save_methods_[i] = nullptr;
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700128 }
Elliott Hughesdcc24742011-09-07 14:02:44 -0700129}
130
Carl Shapiro61e019d2011-07-14 16:53:09 -0700131Runtime::~Runtime() {
Hiroshi Yamauchi2e899a92013-11-22 16:50:12 -0800132 if (dump_gc_performance_on_shutdown_) {
133 // This can't be called from the Heap destructor below because it
134 // could call RosAlloc::InspectAll() which needs the thread_list
135 // to be still alive.
136 heap_->DumpGcPerformanceInfo(LOG(INFO));
137 }
138
Ian Rogers120f1c72012-09-28 17:17:10 -0700139 Thread* self = Thread::Current();
140 {
141 MutexLock mu(self, *Locks::runtime_shutdown_lock_);
142 shutting_down_started_ = true;
143 while (threads_being_born_ > 0) {
Ian Rogersc604d732012-10-14 16:09:54 -0700144 shutdown_cond_->Wait(self);
Ian Rogers120f1c72012-09-28 17:17:10 -0700145 }
146 shutting_down_ = true;
147 }
Ian Rogers62d6c772013-02-27 08:32:07 -0800148 Trace::Shutdown();
jeffhaob5e81852012-03-12 11:15:45 -0700149
Mathieu Chartiera6399032012-06-11 18:49:50 -0700150 // Make sure to let the GC complete if it is running.
Mathieu Chartier590fee92013-09-13 13:46:47 -0700151 heap_->WaitForGcToComplete(self);
Mathieu Chartier35883cc2012-11-13 14:08:12 -0800152 heap_->DeleteThreadPool();
Mathieu Chartiera6399032012-06-11 18:49:50 -0700153
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700154 // Make sure our internal threads are dead before we start tearing down things they're using.
Elliott Hughese52e49b2012-04-02 16:05:44 -0700155 Dbg::StopJdwp();
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700156 delete signal_catcher_;
157
Elliott Hughes038a8062011-09-18 14:12:41 -0700158 // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended.
Elliott Hughes93e74e82011-09-13 11:07:03 -0700159 delete thread_list_;
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700160 delete monitor_list_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800161 delete monitor_pool_;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700162 delete class_linker_;
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800163 delete heap_;
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700164 delete intern_table_;
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700165 delete java_vm_;
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700166 Thread::Shutdown();
Elliott Hughes7c6169d2012-05-02 16:11:48 -0700167 QuasiAtomic::Shutdown();
Sebastien Hertz4d4adb12013-07-24 16:14:19 +0200168 verifier::MethodVerifier::Shutdown();
Carl Shapiro4acf4642011-07-26 18:54:13 -0700169 // TODO: acquire a static mutex on Runtime to avoid racing.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800170 CHECK(instance_ == nullptr || instance_ == this);
171 instance_ = nullptr;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700172}
173
Elliott Hughese0918552011-10-28 17:18:29 -0700174struct AbortState {
175 void Dump(std::ostream& os) {
Ian Rogersf08e4732013-04-09 09:45:49 -0700176 if (gAborting > 1) {
Elliott Hughescac6cc72011-11-03 20:31:21 -0700177 os << "Runtime aborting --- recursively, so no thread-specific detail!\n";
178 return;
179 }
Ian Rogersf08e4732013-04-09 09:45:49 -0700180 gAborting++;
Elliott Hughese0918552011-10-28 17:18:29 -0700181 os << "Runtime aborting...\n";
Elliott Hughes6c7d2442012-02-01 18:40:47 -0800182 if (Runtime::Current() == NULL) {
183 os << "(Runtime does not yet exist!)\n";
184 return;
185 }
Elliott Hughese0918552011-10-28 17:18:29 -0700186 Thread* self = Thread::Current();
187 if (self == NULL) {
188 os << "(Aborting thread was not attached to runtime!)\n";
189 } else {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700190 // TODO: we're aborting and the ScopedObjectAccess may attempt to acquire the mutator_lock_
191 // which may block indefinitely if there's a misbehaving thread holding it exclusively.
192 // The code below should be made robust to this.
193 ScopedObjectAccess soa(self);
Ian Rogers2f7f9b62012-10-10 18:24:05 -0700194 os << "Aborting thread:\n";
Elliott Hughes899e7892012-01-24 14:57:32 -0800195 self->Dump(os);
196 if (self->IsExceptionPending()) {
Ian Rogers62d6c772013-02-27 08:32:07 -0800197 ThrowLocation throw_location;
198 mirror::Throwable* exception = self->GetException(&throw_location);
199 os << "Pending exception " << PrettyTypeOf(exception)
Ian Rogersbc939662013-08-15 10:26:54 -0700200 << " thrown by '" << throw_location.Dump() << "'\n"
Ian Rogers62d6c772013-02-27 08:32:07 -0800201 << exception->Dump();
Elliott Hughes899e7892012-01-24 14:57:32 -0800202 }
Elliott Hughese0918552011-10-28 17:18:29 -0700203 }
Ian Rogers2f7f9b62012-10-10 18:24:05 -0700204 DumpAllThreads(os, self);
205 }
206
207 void DumpAllThreads(std::ostream& os, Thread* self) NO_THREAD_SAFETY_ANALYSIS {
208 bool tll_already_held = Locks::thread_list_lock_->IsExclusiveHeld(self);
209 bool ml_already_held = Locks::mutator_lock_->IsSharedHeld(self);
Ian Rogersfbd22912012-10-12 14:21:10 -0700210 if (!tll_already_held || !ml_already_held) {
211 os << "Dumping all threads without appropriate locks held:"
212 << (!tll_already_held ? " thread list lock" : "")
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700213 << (!ml_already_held ? " mutator lock" : "")
214 << "\n";
Ian Rogers2f7f9b62012-10-10 18:24:05 -0700215 }
Ian Rogersfbd22912012-10-12 14:21:10 -0700216 os << "All threads:\n";
217 Runtime::Current()->GetThreadList()->DumpLocked(os);
Elliott Hughese0918552011-10-28 17:18:29 -0700218 }
219};
220
Elliott Hughes8593fdb2012-04-21 20:53:44 -0700221void Runtime::Abort() {
Ian Rogersf08e4732013-04-09 09:45:49 -0700222 gAborting++; // set before taking any locks
Brian Carlstrom81b88712012-11-05 19:21:30 -0800223
Elliott Hughes131aef82012-01-27 11:53:35 -0800224 // Ensure that we don't have multiple threads trying to abort at once,
225 // which would result in significantly worse diagnostics.
Ian Rogers50b35e22012-10-04 10:09:15 -0700226 MutexLock mu(Thread::Current(), *Locks::abort_lock_);
Elliott Hughes131aef82012-01-27 11:53:35 -0800227
Elliott Hughesffe67362011-07-17 12:09:27 -0700228 // Get any pending output out of the way.
229 fflush(NULL);
230
231 // Many people have difficulty distinguish aborts from crashes,
232 // so be explicit.
Elliott Hughese0918552011-10-28 17:18:29 -0700233 AbortState state;
Elliott Hughes9ee5f9c2012-02-03 18:33:16 -0800234 LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state);
Elliott Hughesffe67362011-07-17 12:09:27 -0700235
Elliott Hughes8593fdb2012-04-21 20:53:44 -0700236 // Call the abort hook if we have one.
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700237 if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) {
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700238 LOG(INTERNAL_FATAL) << "Calling abort hook...";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700239 Runtime::Current()->abort_();
240 // notreached
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700241 LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700242 }
243
Elliott Hughesdd623db2013-06-11 11:20:23 -0700244#if defined(__GLIBC__)
Elliott Hughesd06a6c72012-05-30 17:59:06 -0700245 // TODO: we ought to be able to use pthread_kill(3) here (or abort(3),
246 // which POSIX defines in terms of raise(3), which POSIX defines in terms
247 // of pthread_kill(3)). On Linux, though, libcorkscrew can't unwind through
248 // libpthread, which means the stacks we dump would be useless. Calling
249 // tgkill(2) directly avoids that.
250 syscall(__NR_tgkill, getpid(), GetTid(), SIGABRT);
Elliott Hughesdd623db2013-06-11 11:20:23 -0700251 // TODO: LLVM installs it's own SIGABRT handler so exit to be safe... Can we disable that in LLVM?
252 // If not, we could use sigaction(3) before calling tgkill(2) and lose this call to exit(3).
Brian Carlstrom700c8d32012-11-05 10:42:02 -0800253 exit(1);
Elliott Hughesdd623db2013-06-11 11:20:23 -0700254#else
255 abort();
Elliott Hughesd06a6c72012-05-30 17:59:06 -0700256#endif
Elliott Hughesffe67362011-07-17 12:09:27 -0700257 // notreached
258}
259
Mathieu Chartiercc236d72012-07-20 10:29:05 -0700260bool Runtime::PreZygoteFork() {
261 heap_->PreZygoteFork();
262 return true;
263}
264
Elliott Hughesbf86d042011-08-31 17:53:14 -0700265void Runtime::CallExitHook(jint status) {
266 if (exit_ != NULL) {
Elliott Hughes34e06962012-04-09 13:55:55 -0700267 ScopedThreadStateChange tsc(Thread::Current(), kNative);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700268 exit_(status);
269 LOG(WARNING) << "Exit hook returned instead of exiting!";
270 }
271}
272
Brian Carlstrom8a436592011-08-15 21:27:23 -0700273// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
274// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
275// [gG] gigabytes.
276//
277// "s" should point just past the "-Xm?" part of the string.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700278// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
279// of 1024.
280//
281// The spec says the -Xmx and -Xms options must be multiples of 1024. It
282// doesn't say anything about -Xss.
283//
284// Returns 0 (a useless size) if "s" is malformed or specifies a low or
285// non-evenly-divisible value.
286//
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800287size_t ParseMemoryOption(const char* s, size_t div) {
Brian Carlstrom8a436592011-08-15 21:27:23 -0700288 // strtoul accepts a leading [+-], which we don't want,
289 // so make sure our string starts with a decimal digit.
290 if (isdigit(*s)) {
Elliott Hughes398f64b2012-03-26 18:05:48 -0700291 char* s2;
292 size_t val = strtoul(s, &s2, 10);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700293 if (s2 != s) {
294 // s2 should be pointing just after the number.
295 // If this is the end of the string, the user
296 // has specified a number of bytes. Otherwise,
297 // there should be exactly one more character
298 // that specifies a multiplier.
299 if (*s2 != '\0') {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700300 // The remainder of the string is either a single multiplier
301 // character, or nothing to indicate that the value is in
302 // bytes.
303 char c = *s2++;
304 if (*s2 == '\0') {
305 size_t mul;
306 if (c == '\0') {
307 mul = 1;
308 } else if (c == 'k' || c == 'K') {
309 mul = KB;
310 } else if (c == 'm' || c == 'M') {
311 mul = MB;
312 } else if (c == 'g' || c == 'G') {
313 mul = GB;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700314 } else {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700315 // Unknown multiplier character.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700316 return 0;
317 }
Brian Carlstromf734cf52011-08-17 16:28:14 -0700318
319 if (val <= std::numeric_limits<size_t>::max() / mul) {
320 val *= mul;
321 } else {
322 // Clamp to a multiple of 1024.
323 val = std::numeric_limits<size_t>::max() & ~(1024-1);
324 }
325 } else {
326 // There's more than one character after the numeric part.
327 return 0;
328 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700329 }
330 // The man page says that a -Xm value must be a multiple of 1024.
331 if (val % div == 0) {
332 return val;
333 }
Carl Shapirofc322c72011-07-27 00:20:01 -0700334 }
335 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700336 return 0;
Carl Shapirofc322c72011-07-27 00:20:01 -0700337}
338
lzang16c2270b2014-01-29 14:21:25 +0800339static const std::string StringAfterChar(const std::string& s, char c) {
340 std::string::size_type colon = s.find(c);
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800341 if (colon == std::string::npos) {
lzang16c2270b2014-01-29 14:21:25 +0800342 LOG(FATAL) << "Missing char " << c << " in string " << s;
343 }
344 // Add one to remove the char we were trimming until.
345 return s.substr(colon + 1);
346}
347
348static size_t ParseIntegerOrDie(const std::string& s, char after_char) {
349 std::string::size_type colon = s.find(after_char);
350 if (colon == std::string::npos) {
351 LOG(FATAL) << "Missing char " << after_char << " in string " << s;
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700352 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800353 const char* begin = &s[colon + 1];
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700354 char* end;
355 size_t result = strtoul(begin, &end, 10);
356 if (begin == end || *end != '\0') {
357 LOG(FATAL) << "Failed to parse integer in: " << s;
358 }
359 return result;
360}
361
lzang16c2270b2014-01-29 14:21:25 +0800362
363static double ParseDoubleOrDie(const std::string& option, char after_char, double min, double max,
364 bool ignore_unrecognized, double defval) {
365 std::istringstream iss(StringAfterChar(option, after_char));
Dave Allison0aded082013-11-07 13:15:11 -0800366 double value;
367 iss >> value;
368 // Ensure that we have a value, there was no cruft after it and it satisfies a sensible range.
369 const bool sane_val = iss.eof() && (value >= min) && (value <= max);
370 if (!sane_val) {
371 if (ignore_unrecognized) {
372 return defval;
373 }
374 LOG(FATAL)<< "Invalid option '" << option << "'";
375 return defval;
376 }
377 return value;
378}
379
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800380void Runtime::SweepSystemWeaks(IsMarkedCallback* visitor, void* arg) {
Mathieu Chartier6aa3df92013-09-17 15:17:28 -0700381 GetInternTable()->SweepInternTableWeaks(visitor, arg);
382 GetMonitorList()->SweepMonitorList(visitor, arg);
383 GetJavaVM()->SweepJniWeakGlobals(visitor, arg);
Mathieu Chartier412c7fc2014-02-07 12:18:39 -0800384 Dbg::UpdateObjectPointers(visitor, arg);
Mathieu Chartier6aa3df92013-09-17 15:17:28 -0700385}
386
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800387static gc::CollectorType ParseCollectorType(const std::string& option) {
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800388 if (option == "MS" || option == "nonconcurrent") {
389 return gc::kCollectorTypeMS;
390 } else if (option == "CMS" || option == "concurrent") {
391 return gc::kCollectorTypeCMS;
392 } else if (option == "SS") {
393 return gc::kCollectorTypeSS;
394 } else if (option == "GSS") {
395 return gc::kCollectorTypeGSS;
396 } else {
397 return gc::kCollectorTypeNone;
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800398 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800399}
400
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700401Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) {
Elliott Hughes90a33692011-08-30 13:27:07 -0700402 UniquePtr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstroma004aa92012-02-08 18:05:09 -0800403 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
404 if (boot_class_path_string != NULL) {
405 parsed->boot_class_path_string_ = boot_class_path_string;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700406 }
Brian Carlstroma004aa92012-02-08 18:05:09 -0800407 const char* class_path_string = getenv("CLASSPATH");
408 if (class_path_string != NULL) {
409 parsed->class_path_string_ = class_path_string;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700410 }
Elliott Hughes67d92002012-03-26 15:08:51 -0700411 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
412 parsed->check_jni_ = kIsDebugBuild;
Elliott Hughes85d15452011-09-16 17:33:01 -0700413
Ian Rogers1d54e732013-05-02 21:10:01 -0700414 parsed->heap_initial_size_ = gc::Heap::kDefaultInitialSize;
415 parsed->heap_maximum_size_ = gc::Heap::kDefaultMaximumSize;
416 parsed->heap_min_free_ = gc::Heap::kDefaultMinFree;
417 parsed->heap_max_free_ = gc::Heap::kDefaultMaxFree;
418 parsed->heap_target_utilization_ = gc::Heap::kDefaultTargetUtilization;
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800419 parsed->heap_growth_limit_ = 0; // 0 means no growth limit .
Mathieu Chartier63a54342013-07-23 13:17:59 -0700420 // Default to number of processors minus one since the main GC thread also does work.
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700421 parsed->parallel_gc_threads_ = sysconf(_SC_NPROCESSORS_CONF) - 1;
422 // Only the main GC thread, no workers.
423 parsed->conc_gc_threads_ = 0;
Mathieu Chartier0de9f732013-11-22 17:58:48 -0800424 // Default is CMS which is Sticky + Partial + Full CMS GC.
Mathieu Chartier0f875ef2014-01-14 15:49:54 -0800425 parsed->collector_type_ = gc::kCollectorTypeCMS;
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800426 // If background_collector_type_ is kCollectorTypeNone, it defaults to the collector_type_ after
427 // parsing options.
428 parsed->background_collector_type_ = gc::kCollectorTypeNone;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700429 parsed->stack_size_ = 0; // 0 means default.
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700430 parsed->max_spins_before_thin_lock_inflation_ = Monitor::kDefaultMaxSpinsBeforeThinLockInflation;
Mathieu Chartiere0a53e92013-08-05 10:17:40 -0700431 parsed->low_memory_mode_ = false;
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800432 parsed->use_tlab_ = false;
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800433 parsed->verify_pre_gc_heap_ = false;
434 parsed->verify_post_gc_heap_ = kIsDebugBuild;
Hiroshi Yamauchia4adbfd2014-02-04 18:12:17 -0800435 parsed->verify_pre_gc_rosalloc_ = kIsDebugBuild;
436 parsed->verify_post_gc_rosalloc_ = false;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700437
Vladimir Marko2b5eaa22013-12-13 13:59:30 +0000438 parsed->compiler_callbacks_ = nullptr;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700439 parsed->is_zygote_ = false;
Ian Rogers50ffee22012-11-20 11:47:44 -0800440 parsed->interpreter_only_ = false;
Anwar Ghuloum87183592013-08-14 12:12:19 -0700441 parsed->is_explicit_gc_disabled_ = false;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700442
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700443 parsed->long_pause_log_threshold_ = gc::Heap::kDefaultLongPauseLogThreshold;
444 parsed->long_gc_log_threshold_ = gc::Heap::kDefaultLongGCLogThreshold;
Mathieu Chartierff3b24a2013-11-22 16:04:25 -0800445 parsed->dump_gc_performance_on_shutdown_ = false;
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700446 parsed->ignore_max_footprint_ = false;
447
Elliott Hughesfc861622011-10-17 17:57:47 -0700448 parsed->lock_profiling_threshold_ = 0;
449 parsed->hook_is_sensitive_thread_ = NULL;
450
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700451 parsed->hook_vfprintf_ = vfprintf;
452 parsed->hook_exit_ = exit;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700453 parsed->hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700454
buzbeea024a062013-07-31 10:47:37 -0700455 parsed->compiler_filter_ = Runtime::kDefaultCompilerFilter;
456 parsed->huge_method_threshold_ = Runtime::kDefaultHugeMethodThreshold;
457 parsed->large_method_threshold_ = Runtime::kDefaultLargeMethodThreshold;
458 parsed->small_method_threshold_ = Runtime::kDefaultSmallMethodThreshold;
459 parsed->tiny_method_threshold_ = Runtime::kDefaultTinyMethodThreshold;
460 parsed->num_dex_methods_threshold_ = Runtime::kDefaultNumDexMethodsThreshold;
Anwar Ghuloum8447d842013-04-30 17:27:40 -0700461
Dragos Sbirlea7467ee02013-06-21 09:20:34 -0700462 parsed->sea_ir_mode_ = false;
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700463// gLogVerbosity.class_linker = true; // TODO: don't check this in!
464// gLogVerbosity.compiler = true; // TODO: don't check this in!
Anwar Ghuloum75a43f12013-08-13 17:22:14 -0700465// gLogVerbosity.verifier = true; // TODO: don't check this in!
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700466// gLogVerbosity.heap = true; // TODO: don't check this in!
467// gLogVerbosity.gc = true; // TODO: don't check this in!
468// gLogVerbosity.jdwp = true; // TODO: don't check this in!
469// gLogVerbosity.jni = true; // TODO: don't check this in!
470// gLogVerbosity.monitor = true; // TODO: don't check this in!
471// gLogVerbosity.startup = true; // TODO: don't check this in!
472// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
473// gLogVerbosity.threads = true; // TODO: don't check this in!
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800474
jeffhaob5e81852012-03-12 11:15:45 -0700475 parsed->method_trace_ = false;
476 parsed->method_trace_file_ = "/data/method-trace-file.bin";
477 parsed->method_trace_file_size_ = 10 * MB;
478
Dave Allison0aded082013-11-07 13:15:11 -0800479 parsed->profile_ = false;
480 parsed->profile_period_s_ = 10; // Seconds.
481 parsed->profile_duration_s_ = 20; // Seconds.
482 parsed->profile_interval_us_ = 500; // Microseconds.
483 parsed->profile_backoff_coefficient_ = 2.0;
484
Brian Carlstrom8a436592011-08-15 21:27:23 -0700485 for (size_t i = 0; i < options.size(); ++i) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800486 const std::string option(options[i].first);
Brian Carlstrom0796af02011-10-12 14:31:45 -0700487 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700488 LOG(INFO) << "option[" << i << "]=" << option;
489 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800490 if (StartsWith(option, "-Xbootclasspath:")) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800491 parsed->boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700492 } else if (option == "-classpath" || option == "-cp") {
493 // TODO: support -Djava.class.path
494 i++;
495 if (i == options.size()) {
496 // TODO: usage
497 LOG(FATAL) << "Missing required class path value for " << option;
498 return NULL;
499 }
Brian Carlstroma004aa92012-02-08 18:05:09 -0800500 const StringPiece& value = options[i].first;
501 parsed->class_path_string_ = value.data();
502 } else if (option == "bootclasspath") {
503 parsed->boot_class_path_
504 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800505 } else if (StartsWith(option, "-Ximage:")) {
lzang16c2270b2014-01-29 14:21:25 +0800506 parsed->image_ = StringAfterChar(option, ':');
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800507 } else if (StartsWith(option, "-Xcheck:jni")) {
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700508 parsed->check_jni_ = true;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800509 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
510 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
Elliott Hughes3bb81562011-10-21 18:52:59 -0700511 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
512 LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
513 << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n";
514 return NULL;
515 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800516 } else if (StartsWith(option, "-Xms")) {
517 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700518 if (size == 0) {
519 if (ignore_unrecognized) {
520 continue;
521 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700522 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700523 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700524 return NULL;
525 }
526 parsed->heap_initial_size_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800527 } else if (StartsWith(option, "-Xmx")) {
528 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700529 if (size == 0) {
530 if (ignore_unrecognized) {
531 continue;
532 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700533 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700534 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700535 return NULL;
536 }
537 parsed->heap_maximum_size_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800538 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
539 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
jeffhaoc1160702011-10-27 15:48:45 -0700540 if (size == 0) {
541 if (ignore_unrecognized) {
542 continue;
543 }
544 // TODO: usage
545 LOG(FATAL) << "Failed to parse " << option;
546 return NULL;
547 }
548 parsed->heap_growth_limit_ = size;
Mathieu Chartier0051be62012-10-12 17:47:11 -0700549 } else if (StartsWith(option, "-XX:HeapMinFree=")) {
550 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMinFree=")).c_str(), 1024);
551 if (size == 0) {
552 if (ignore_unrecognized) {
553 continue;
554 }
555 // TODO: usage
556 LOG(FATAL) << "Failed to parse " << option;
557 return NULL;
558 }
559 parsed->heap_min_free_ = size;
560 } else if (StartsWith(option, "-XX:HeapMaxFree=")) {
561 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapMaxFree=")).c_str(), 1024);
562 if (size == 0) {
563 if (ignore_unrecognized) {
564 continue;
565 }
566 // TODO: usage
567 LOG(FATAL) << "Failed to parse " << option;
568 return NULL;
569 }
570 parsed->heap_max_free_ = size;
571 } else if (StartsWith(option, "-XX:HeapTargetUtilization=")) {
lzang16c2270b2014-01-29 14:21:25 +0800572 parsed->heap_target_utilization_ = ParseDoubleOrDie(
573 option, '=', 0.1, 0.9, ignore_unrecognized, parsed->heap_target_utilization_);
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700574 } else if (StartsWith(option, "-XX:ParallelGCThreads=")) {
lzang16c2270b2014-01-29 14:21:25 +0800575 parsed->parallel_gc_threads_ = ParseIntegerOrDie(option, '=');
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700576 } else if (StartsWith(option, "-XX:ConcGCThreads=")) {
lzang16c2270b2014-01-29 14:21:25 +0800577 parsed->conc_gc_threads_ = ParseIntegerOrDie(option, '=');
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800578 } else if (StartsWith(option, "-Xss")) {
579 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700580 if (size == 0) {
581 if (ignore_unrecognized) {
582 continue;
583 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700584 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700585 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700586 return NULL;
587 }
588 parsed->stack_size_ = size;
Ian Rogersd9c4fc92013-10-01 19:45:43 -0700589 } else if (StartsWith(option, "-XX:MaxSpinsBeforeThinLockInflation=")) {
lzang16c2270b2014-01-29 14:21:25 +0800590 parsed->max_spins_before_thin_lock_inflation_ = ParseIntegerOrDie(option, '=');
591 } else if (StartsWith(option, "-XX:LongPauseLogThreshold=")) {
592 parsed->long_pause_log_threshold_ = MsToNs(ParseIntegerOrDie(option, '='));
593 } else if (StartsWith(option, "-XX:LongGCLogThreshold=")) {
594 parsed->long_gc_log_threshold_ = MsToNs(ParseIntegerOrDie(option, '='));
Mathieu Chartierff3b24a2013-11-22 16:04:25 -0800595 } else if (option == "-XX:DumpGCPerformanceOnShutdown") {
596 parsed->dump_gc_performance_on_shutdown_ = true;
Mathieu Chartier2775ee42013-08-20 17:43:47 -0700597 } else if (option == "-XX:IgnoreMaxFootprint") {
598 parsed->ignore_max_footprint_ = true;
Mathieu Chartiere0a53e92013-08-05 10:17:40 -0700599 } else if (option == "-XX:LowMemoryMode") {
600 parsed->low_memory_mode_ = true;
Mathieu Chartier692fafd2013-11-29 17:24:40 -0800601 } else if (option == "-XX:UseTLAB") {
602 parsed->use_tlab_ = true;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800603 } else if (StartsWith(option, "-D")) {
604 parsed->properties_.push_back(option.substr(strlen("-D")));
605 } else if (StartsWith(option, "-Xjnitrace:")) {
606 parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:"));
Vladimir Marko2b5eaa22013-12-13 13:59:30 +0000607 } else if (option == "compilercallbacks") {
608 parsed->compiler_callbacks_ =
609 reinterpret_cast<CompilerCallbacks*>(const_cast<void*>(options[i].second));
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700610 } else if (option == "-Xzygote") {
611 parsed->is_zygote_ = true;
Ian Rogers50ffee22012-11-20 11:47:44 -0800612 } else if (option == "-Xint") {
613 parsed->interpreter_only_ = true;
Mathieu Chartier069387a2012-06-18 12:01:01 -0700614 } else if (StartsWith(option, "-Xgc:")) {
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800615 std::vector<std::string> gc_options;
616 Split(option.substr(strlen("-Xgc:")), ',', gc_options);
617 for (const std::string& gc_option : gc_options) {
618 gc::CollectorType collector_type = ParseCollectorType(gc_option);
619 if (collector_type != gc::kCollectorTypeNone) {
Hiroshi Yamauchibe1ca552014-01-15 11:46:48 -0800620 parsed->collector_type_ = collector_type;
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800621 } else if (gc_option == "preverify") {
622 parsed->verify_pre_gc_heap_ = true;
Hiroshi Yamauchia4adbfd2014-02-04 18:12:17 -0800623 } else if (gc_option == "nopreverify") {
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800624 parsed->verify_pre_gc_heap_ = false;
625 } else if (gc_option == "postverify") {
626 parsed->verify_post_gc_heap_ = true;
627 } else if (gc_option == "nopostverify") {
628 parsed->verify_post_gc_heap_ = false;
Hiroshi Yamauchia4adbfd2014-02-04 18:12:17 -0800629 } else if (gc_option == "preverify_rosalloc") {
630 parsed->verify_pre_gc_rosalloc_ = true;
631 } else if (gc_option == "nopreverify_rosalloc") {
632 parsed->verify_pre_gc_rosalloc_ = false;
633 } else if (gc_option == "postverify_rosalloc") {
634 parsed->verify_post_gc_rosalloc_ = true;
635 } else if (gc_option == "nopostverify_rosalloc") {
636 parsed->verify_post_gc_rosalloc_ = false;
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800637 } else {
638 LOG(WARNING) << "Ignoring unknown -Xgc option: " << gc_option;
639 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800640 }
641 } else if (StartsWith(option, "-XX:BackgroundGC=")) {
lzang16c2270b2014-01-29 14:21:25 +0800642 const std::string substring = StringAfterChar(option, '=');
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800643 gc::CollectorType collector_type = ParseCollectorType(substring);
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800644 if (collector_type != gc::kCollectorTypeNone) {
645 parsed->background_collector_type_ = collector_type;
Mathieu Chartier938a03b2014-01-16 15:10:31 -0800646 } else {
647 LOG(WARNING) << "Ignoring unknown -XX:BackgroundGC option: " << substring;
Mathieu Chartier069387a2012-06-18 12:01:01 -0700648 }
Anwar Ghuloum87183592013-08-14 12:12:19 -0700649 } else if (option == "-XX:+DisableExplicitGC") {
650 parsed->is_explicit_gc_disabled_ = true;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800651 } else if (StartsWith(option, "-verbose:")) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700652 std::vector<std::string> verbose_options;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800653 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
Elliott Hughes0af55432011-08-17 18:37:28 -0700654 for (size_t i = 0; i < verbose_options.size(); ++i) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800655 if (verbose_options[i] == "class") {
656 gLogVerbosity.class_linker = true;
Anwar Ghuloum75a43f12013-08-13 17:22:14 -0700657 } else if (verbose_options[i] == "verifier") {
658 gLogVerbosity.verifier = true;
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800659 } else if (verbose_options[i] == "compiler") {
660 gLogVerbosity.compiler = true;
661 } else if (verbose_options[i] == "heap") {
662 gLogVerbosity.heap = true;
663 } else if (verbose_options[i] == "gc") {
664 gLogVerbosity.gc = true;
665 } else if (verbose_options[i] == "jdwp") {
666 gLogVerbosity.jdwp = true;
667 } else if (verbose_options[i] == "jni") {
668 gLogVerbosity.jni = true;
669 } else if (verbose_options[i] == "monitor") {
670 gLogVerbosity.monitor = true;
671 } else if (verbose_options[i] == "startup") {
672 gLogVerbosity.startup = true;
673 } else if (verbose_options[i] == "third-party-jni") {
674 gLogVerbosity.third_party_jni = true;
675 } else if (verbose_options[i] == "threads") {
676 gLogVerbosity.threads = true;
677 } else {
678 LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i];
679 }
Elliott Hughes0af55432011-08-17 18:37:28 -0700680 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800681 } else if (StartsWith(option, "-Xjnigreflimit:")) {
Elliott Hughes2010a602013-07-02 14:17:23 -0700682 // Silently ignored for backwards compatibility.
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800683 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
lzang16c2270b2014-01-29 14:21:25 +0800684 parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option, ':');
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800685 } else if (StartsWith(option, "-Xstacktracefile:")) {
lzang16c2270b2014-01-29 14:21:25 +0800686 parsed->stack_trace_file_ = StringAfterChar(option, ':');
Elliott Hughesfc861622011-10-17 17:57:47 -0700687 } else if (option == "sensitiveThread") {
Ian Rogers1b09b092012-08-20 15:35:52 -0700688 parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(const_cast<void*>(options[i].second));
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700689 } else if (option == "vfprintf") {
Ian Rogers1b09b092012-08-20 15:35:52 -0700690 parsed->hook_vfprintf_ =
691 reinterpret_cast<int (*)(FILE *, const char*, va_list)>(const_cast<void*>(options[i].second));
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700692 } else if (option == "exit") {
Ian Rogers1b09b092012-08-20 15:35:52 -0700693 parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(const_cast<void*>(options[i].second));
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700694 } else if (option == "abort") {
Ian Rogers1b09b092012-08-20 15:35:52 -0700695 parsed->hook_abort_ = reinterpret_cast<void(*)()>(const_cast<void*>(options[i].second));
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700696 } else if (option == "host-prefix") {
697 parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second);
Elliott Hughesb3e66df2012-01-12 14:49:18 -0800698 } else if (option == "-Xgenregmap" || option == "-Xgc:precise") {
699 // We silently ignore these for backwards compatibility.
jeffhaob5e81852012-03-12 11:15:45 -0700700 } else if (option == "-Xmethod-trace") {
701 parsed->method_trace_ = true;
702 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
703 parsed->method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
704 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
lzang16c2270b2014-01-29 14:21:25 +0800705 parsed->method_trace_file_size_ = ParseIntegerOrDie(option, ':');
Elliott Hughese119a362012-05-22 17:37:06 -0700706 } else if (option == "-Xprofile:threadcpuclock") {
707 Trace::SetDefaultClockSource(kProfilerClockSourceThreadCpu);
708 } else if (option == "-Xprofile:wallclock") {
709 Trace::SetDefaultClockSource(kProfilerClockSourceWall);
710 } else if (option == "-Xprofile:dualclock") {
711 Trace::SetDefaultClockSource(kProfilerClockSourceDual);
Dave Allison0aded082013-11-07 13:15:11 -0800712 } else if (StartsWith(option, "-Xprofile:")) {
lzang16c2270b2014-01-29 14:21:25 +0800713 parsed->profile_output_filename_ = StringAfterChar(option, ';');
Dave Allison0aded082013-11-07 13:15:11 -0800714 parsed->profile_ = true;
715 } else if (StartsWith(option, "-Xprofile-period:")) {
lzang16c2270b2014-01-29 14:21:25 +0800716 parsed->profile_period_s_ = ParseIntegerOrDie(option, ':');
Dave Allison0aded082013-11-07 13:15:11 -0800717 } else if (StartsWith(option, "-Xprofile-duration:")) {
lzang16c2270b2014-01-29 14:21:25 +0800718 parsed->profile_duration_s_ = ParseIntegerOrDie(option, ':');
Dave Allison0aded082013-11-07 13:15:11 -0800719 } else if (StartsWith(option, "-Xprofile-interval:")) {
lzang16c2270b2014-01-29 14:21:25 +0800720 parsed->profile_interval_us_ = ParseIntegerOrDie(option, ':');
Dave Allison0aded082013-11-07 13:15:11 -0800721 } else if (StartsWith(option, "-Xprofile-backoff:")) {
lzang16c2270b2014-01-29 14:21:25 +0800722 parsed->profile_backoff_coefficient_ = ParseDoubleOrDie(
723 option, ':', 1.0, 10.0, ignore_unrecognized, parsed->profile_backoff_coefficient_);
buzbeea024a062013-07-31 10:47:37 -0700724 } else if (option == "-compiler-filter:interpret-only") {
725 parsed->compiler_filter_ = kInterpretOnly;
buzbeea024a062013-07-31 10:47:37 -0700726 } else if (option == "-compiler-filter:space") {
727 parsed->compiler_filter_ = kSpace;
728 } else if (option == "-compiler-filter:balanced") {
729 parsed->compiler_filter_ = kBalanced;
730 } else if (option == "-compiler-filter:speed") {
731 parsed->compiler_filter_ = kSpeed;
buzbeefe9ca402013-08-21 09:48:11 -0700732 } else if (option == "-compiler-filter:everything") {
733 parsed->compiler_filter_ = kEverything;
Brian Carlstrom2ce745c2013-07-17 17:44:30 -0700734 } else if (option == "-sea_ir") {
Dragos Sbirlea7467ee02013-06-21 09:20:34 -0700735 parsed->sea_ir_mode_ = true;
buzbeea024a062013-07-31 10:47:37 -0700736 } else if (StartsWith(option, "-huge-method-max:")) {
lzang16c2270b2014-01-29 14:21:25 +0800737 parsed->huge_method_threshold_ = ParseIntegerOrDie(option, ':');
buzbeea024a062013-07-31 10:47:37 -0700738 } else if (StartsWith(option, "-large-method-max:")) {
lzang16c2270b2014-01-29 14:21:25 +0800739 parsed->large_method_threshold_ = ParseIntegerOrDie(option, ':');
buzbeea024a062013-07-31 10:47:37 -0700740 } else if (StartsWith(option, "-small-method-max:")) {
lzang16c2270b2014-01-29 14:21:25 +0800741 parsed->small_method_threshold_ = ParseIntegerOrDie(option, ':');
buzbeea024a062013-07-31 10:47:37 -0700742 } else if (StartsWith(option, "-tiny-method-max:")) {
lzang16c2270b2014-01-29 14:21:25 +0800743 parsed->tiny_method_threshold_ = ParseIntegerOrDie(option, ':');
buzbeea024a062013-07-31 10:47:37 -0700744 } else if (StartsWith(option, "-num-dex-methods-max:")) {
lzang16c2270b2014-01-29 14:21:25 +0800745 parsed->num_dex_methods_threshold_ = ParseIntegerOrDie(option, ':');
Brian Carlstrom8a436592011-08-15 21:27:23 -0700746 } else {
747 if (!ignore_unrecognized) {
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700748 // TODO: print usage via vfprintf
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700749 LOG(ERROR) << "Unrecognized option " << option;
750 // TODO: this should exit, but for now tolerate unknown options
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700751 // return NULL;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700752 }
753 }
754 }
755
Brian Carlstromfb67b722013-06-24 23:41:51 -0700756 // If a reference to the dalvik core.jar snuck in, replace it with
757 // the art specific version. This can happen with on device
758 // boot.art/boot.oat generation by GenerateImage which relies on the
759 // value of BOOTCLASSPATH.
760 std::string core_jar("/core.jar");
761 size_t core_jar_pos = parsed->boot_class_path_string_.find(core_jar);
762 if (core_jar_pos != std::string::npos) {
763 parsed->boot_class_path_string_.replace(core_jar_pos, core_jar.size(), "/core-libart.jar");
764 }
765
Vladimir Marko2b5eaa22013-12-13 13:59:30 +0000766 if (parsed->compiler_callbacks_ == nullptr && parsed->image_.empty()) {
Brian Carlstrom223f20f2012-02-04 23:06:55 -0800767 parsed->image_ += GetAndroidRoot();
768 parsed->image_ += "/framework/boot.art";
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700769 }
jeffhaoc1160702011-10-27 15:48:45 -0700770 if (parsed->heap_growth_limit_ == 0) {
771 parsed->heap_growth_limit_ = parsed->heap_maximum_size_;
772 }
Mathieu Chartiere6da9af2013-12-16 11:54:42 -0800773 if (parsed->background_collector_type_ == gc::kCollectorTypeNone) {
774 parsed->background_collector_type_ = parsed->collector_type_;
775 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700776 return parsed.release();
Brian Carlstrom8a436592011-08-15 21:27:23 -0700777}
778
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700779bool Runtime::Create(const Options& options, bool ignore_unrecognized) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -0700780 // TODO: acquire a static mutex on Runtime to avoid racing.
781 if (Runtime::instance_ != NULL) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700782 return false;
Carl Shapiro2ed144c2011-07-26 16:52:08 -0700783 }
Brian Carlstrom7934ac22013-07-26 10:54:15 -0700784 InitLogging(NULL); // Calls Locks::Init() as a side effect.
Elliott Hughesdcc24742011-09-07 14:02:44 -0700785 instance_ = new Runtime;
786 if (!instance_->Init(options, ignore_unrecognized)) {
787 delete instance_;
788 instance_ = NULL;
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700789 return false;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700790 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700791 return true;
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700792}
Elliott Hughes0af55432011-08-17 18:37:28 -0700793
Brian Carlstromce888532013-10-10 00:32:58 -0700794jobject CreateSystemClassLoader() {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800795 if (Runtime::Current()->UseCompileTimeClassPath()) {
Brian Carlstromce888532013-10-10 00:32:58 -0700796 return NULL;
Brian Carlstromaded5f72011-10-07 17:15:04 -0700797 }
798
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700799 ScopedObjectAccess soa(Thread::Current());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800800 ClassLinker* cl = Runtime::Current()->GetClassLinker();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700801
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800802 SirtRef<mirror::Class> class_loader_class(
803 soa.Self(), soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_ClassLoader));
804 CHECK(cl->EnsureInitialized(class_loader_class, true, true));
Brian Carlstromaded5f72011-10-07 17:15:04 -0700805
Brian Carlstromea46f952013-07-30 01:26:50 -0700806 mirror::ArtMethod* getSystemClassLoader =
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800807 class_loader_class->FindDirectMethod("getSystemClassLoader", "()Ljava/lang/ClassLoader;");
Brian Carlstromdf143242011-10-10 18:05:34 -0700808 CHECK(getSystemClassLoader != NULL);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700809
Jeff Hao5d917302013-02-27 17:57:33 -0800810 JValue result;
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800811 ArgArray arg_array(nullptr, 0);
Ian Rogers0177e532014-02-11 16:30:46 -0800812 InvokeWithArgArray(soa, getSystemClassLoader, &arg_array, &result, "L");
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800813 SirtRef<mirror::ClassLoader> class_loader(soa.Self(),
814 down_cast<mirror::ClassLoader*>(result.GetL()));
815 CHECK(class_loader.get() != nullptr);
Brian Carlstromce888532013-10-10 00:32:58 -0700816 JNIEnv* env = soa.Self()->GetJniEnv();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800817 ScopedLocalRef<jobject> system_class_loader(env,
818 soa.AddLocalReference<jobject>(class_loader.get()));
819 CHECK(system_class_loader.get() != nullptr);
Brian Carlstromce888532013-10-10 00:32:58 -0700820
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800821 soa.Self()->SetClassLoaderOverride(class_loader.get());
Ian Rogers365c1022012-06-22 15:05:28 -0700822
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800823 SirtRef<mirror::Class> thread_class(soa.Self(),
824 soa.Decode<mirror::Class*>(WellKnownClasses::java_lang_Thread));
825 CHECK(cl->EnsureInitialized(thread_class, true, true));
Ian Rogers365c1022012-06-22 15:05:28 -0700826
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800827 mirror::ArtField* contextClassLoader =
828 thread_class->FindDeclaredInstanceField("contextClassLoader", "Ljava/lang/ClassLoader;");
Jesse Wilson1b2b2f22011-11-22 11:47:44 -0500829 CHECK(contextClassLoader != NULL);
Ian Rogers365c1022012-06-22 15:05:28 -0700830
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100831 // We can't run in a transaction yet.
832 contextClassLoader->SetObject<false>(soa.Self()->GetPeer(), class_loader.get());
Brian Carlstromce888532013-10-10 00:32:58 -0700833
834 return env->NewGlobalRef(system_class_loader.get());
Brian Carlstromaded5f72011-10-07 17:15:04 -0700835}
836
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700837bool Runtime::Start() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800838 VLOG(startup) << "Runtime::Start entering";
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700839
Ian Rogers97f44892014-02-14 23:10:04 +0000840 CHECK(host_prefix_.empty()) << host_prefix_;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700841
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700842 // Restore main thread state to kNative as expected by native code.
Ian Rogersa436fde2013-08-27 23:34:06 -0700843 Thread* self = Thread::Current();
Ian Rogers00f7d0e2012-07-19 15:28:27 -0700844 self->TransitionFromRunnableToSuspended(kNative);
845
Brian Carlstrom5d40f182011-09-26 22:29:18 -0700846 started_ = true;
847
Brian Carlstromae826982011-11-09 01:33:42 -0800848 // InitNativeMethods needs to be after started_ so that the classes
849 // it touches will have methods linked to the oat file if necessary.
850 InitNativeMethods();
851
Ian Rogers365c1022012-06-22 15:05:28 -0700852 // Initialize well known thread group values that may be accessed threads while attaching.
853 InitThreadGroups(self);
854
Jesse Wilson9a6bae82011-11-14 14:57:30 -0500855 Thread::FinishStartup();
856
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700857 if (is_zygote_) {
858 if (!InitZygote()) {
859 return false;
860 }
861 } else {
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700862 DidForkFromZygote();
863 }
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700864
Elliott Hughes85d15452011-09-16 17:33:01 -0700865 StartDaemonThreads();
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700866
Brian Carlstromce888532013-10-10 00:32:58 -0700867 system_class_loader_ = CreateSystemClassLoader();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700868
Elliott Hughes225f5a12012-06-11 11:23:48 -0700869 self->GetJniEnv()->locals.AssertEmpty();
Elliott Hughes726079d2011-10-07 18:43:44 -0700870
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800871 VLOG(startup) << "Runtime::Start exiting";
Mathieu Chartier7664f5c2012-06-08 18:15:32 -0700872
873 finished_starting_ = true;
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700874
Dave Allison0aded082013-11-07 13:15:11 -0800875 if (profile_) {
876 // User has asked for a profile using -Xprofile
877 StartProfiler(profile_output_filename_.c_str(), true);
878 }
879
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700880 return true;
Elliott Hughes85d15452011-09-16 17:33:01 -0700881}
882
Ian Rogers120f1c72012-09-28 17:17:10 -0700883void Runtime::EndThreadBirth() EXCLUSIVE_LOCKS_REQUIRED(Locks::runtime_shutdown_lock_) {
884 DCHECK_GT(threads_being_born_, 0U);
885 threads_being_born_--;
886 if (shutting_down_started_ && threads_being_born_ == 0) {
Ian Rogersc604d732012-10-14 16:09:54 -0700887 shutdown_cond_->Broadcast(Thread::Current());
Ian Rogers120f1c72012-09-28 17:17:10 -0700888 }
889}
890
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700891// Do zygote-mode-only initialization.
892bool Runtime::InitZygote() {
893 // zygote goes into its own process group
Brian Carlstromb1eba212013-07-17 18:07:19 -0700894 setpgid(0, 0);
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700895
896 // See storage config details at http://source.android.com/tech/storage/
897 // Create private mount namespace shared by all children
898 if (unshare(CLONE_NEWNS) == -1) {
899 PLOG(WARNING) << "Failed to unshare()";
900 return false;
901 }
902
903 // Mark rootfs as being a slave so that changes from default
904 // namespace only flow into our children.
905 if (mount("rootfs", "/", NULL, (MS_SLAVE | MS_REC), NULL) == -1) {
906 PLOG(WARNING) << "Failed to mount() rootfs as MS_SLAVE";
907 return false;
908 }
909
910 // Create a staging tmpfs that is shared by our children; they will
911 // bind mount storage into their respective private namespaces, which
912 // are isolated from each other.
913 const char* target_base = getenv("EMULATED_STORAGE_TARGET");
914 if (target_base != NULL) {
915 if (mount("tmpfs", target_base, "tmpfs", MS_NOSUID | MS_NODEV,
Jeff Sharkey52cd1e82013-09-17 16:25:12 -0700916 "uid=0,gid=1028,mode=0751") == -1) {
Brian Carlstrombd86bcc2013-03-10 20:26:16 -0700917 LOG(WARNING) << "Failed to mount tmpfs to " << target_base;
918 return false;
919 }
920 }
921
922 return true;
923}
924
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700925void Runtime::DidForkFromZygote() {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700926 is_zygote_ = false;
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700927
Mathieu Chartier02b6a782012-10-26 13:51:26 -0700928 // Create the thread pool.
929 heap_->CreateThreadPool();
930
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700931 StartSignalCatcher();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700932
933 // Start the JDWP thread. If the command-line debugger flags specified "suspend=y",
934 // this will pause the runtime, so we probably want this to come last.
935 Dbg::StartJdwp();
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700936}
937
938void Runtime::StartSignalCatcher() {
939 if (!is_zygote_) {
Elliott Hughes94ce37a2011-10-18 15:07:48 -0700940 signal_catcher_ = new SignalCatcher(stack_trace_file_);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700941 }
942}
943
Mathieu Chartier590fee92013-09-13 13:46:47 -0700944bool Runtime::IsShuttingDown(Thread* self) {
945 MutexLock mu(self, *Locks::runtime_shutdown_lock_);
946 return IsShuttingDownLocked();
947}
948
Elliott Hughes85d15452011-09-16 17:33:01 -0700949void Runtime::StartDaemonThreads() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800950 VLOG(startup) << "Runtime::StartDaemonThreads entering";
Elliott Hughes85d15452011-09-16 17:33:01 -0700951
Elliott Hughes719b3232011-09-25 17:42:19 -0700952 Thread* self = Thread::Current();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700953
954 // Must be in the kNative state for calling native methods.
Ian Rogers50b35e22012-10-04 10:09:15 -0700955 CHECK_EQ(self->GetState(), kNative);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700956
Elliott Hughes719b3232011-09-25 17:42:19 -0700957 JNIEnv* env = self->GetJniEnv();
Ian Rogers2fa6b2e2012-10-17 00:10:17 -0700958 env->CallStaticVoidMethod(WellKnownClasses::java_lang_Daemons,
959 WellKnownClasses::java_lang_Daemons_start);
960 if (env->ExceptionCheck()) {
961 env->ExceptionDescribe();
962 LOG(FATAL) << "Error starting java.lang.Daemons";
963 }
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700964
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800965 VLOG(startup) << "Runtime::StartDaemonThreads exiting";
Carl Shapiro61e019d2011-07-14 16:53:09 -0700966}
967
Elliott Hughes0af55432011-08-17 18:37:28 -0700968bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700969 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700970
Elliott Hughes90a33692011-08-30 13:27:07 -0700971 UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized));
972 if (options.get() == NULL) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700973 LOG(ERROR) << "Failed to parse options";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700974 return false;
975 }
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800976 VLOG(startup) << "Runtime::Init -verbose:startup enabled";
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700977
Elliott Hughes7c6169d2012-05-02 16:11:48 -0700978 QuasiAtomic::Startup();
979
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800980 Monitor::Init(options->lock_profiling_threshold_, options->hook_is_sensitive_thread_);
Elliott Hughes32d6e1e2011-10-11 14:47:44 -0700981
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700982 host_prefix_ = options->host_prefix_;
Brian Carlstroma004aa92012-02-08 18:05:09 -0800983 boot_class_path_string_ = options->boot_class_path_string_;
984 class_path_string_ = options->class_path_string_;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700985 properties_ = options->properties_;
986
Vladimir Marko2b5eaa22013-12-13 13:59:30 +0000987 compiler_callbacks_ = options->compiler_callbacks_;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700988 is_zygote_ = options->is_zygote_;
Anwar Ghuloum87183592013-08-14 12:12:19 -0700989 is_explicit_gc_disabled_ = options->is_explicit_gc_disabled_;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700990
buzbeea024a062013-07-31 10:47:37 -0700991 compiler_filter_ = options->compiler_filter_;
992 huge_method_threshold_ = options->huge_method_threshold_;
993 large_method_threshold_ = options->large_method_threshold_;
994 small_method_threshold_ = options->small_method_threshold_;
995 tiny_method_threshold_ = options->tiny_method_threshold_;
996 num_dex_methods_threshold_ = options->num_dex_methods_threshold_;
Anwar Ghuloum8447d842013-04-30 17:27:40 -0700997
Dragos Sbirlea7467ee02013-06-21 09:20:34 -0700998 sea_ir_mode_ = options->sea_ir_mode_;
Elliott Hughes0af55432011-08-17 18:37:28 -0700999 vfprintf_ = options->hook_vfprintf_;
1000 exit_ = options->hook_exit_;
1001 abort_ = options->hook_abort_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -07001002
Elliott Hughesbe759c62011-09-08 19:38:21 -07001003 default_stack_size_ = options->stack_size_;
Elliott Hughes94ce37a2011-10-18 15:07:48 -07001004 stack_trace_file_ = options->stack_trace_file_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -07001005
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001006 max_spins_before_thin_lock_inflation_ = options->max_spins_before_thin_lock_inflation_;
1007
Elliott Hughesc33a32b2011-10-11 18:18:07 -07001008 monitor_list_ = new MonitorList;
Ian Rogersef7d42f2014-01-06 12:55:46 -08001009 monitor_pool_ = MonitorPool::Create();
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -08001010 thread_list_ = new ThreadList;
Elliott Hughescf4c6c42011-09-01 15:16:42 -07001011 intern_table_ = new InternTable;
1012
Logan Chiendd361c92012-04-10 23:40:37 +08001013
Ian Rogers62d6c772013-02-27 08:32:07 -08001014 if (options->interpreter_only_) {
1015 GetInstrumentation()->ForceInterpretOnly();
1016 }
1017
Ian Rogers1d54e732013-05-02 21:10:01 -07001018 heap_ = new gc::Heap(options->heap_initial_size_,
1019 options->heap_growth_limit_,
1020 options->heap_min_free_,
1021 options->heap_max_free_,
1022 options->heap_target_utilization_,
1023 options->heap_maximum_size_,
1024 options->image_,
Mathieu Chartier0de9f732013-11-22 17:58:48 -08001025 options->collector_type_,
Mathieu Chartiere6da9af2013-12-16 11:54:42 -08001026 options->background_collector_type_,
Mathieu Chartier2775ee42013-08-20 17:43:47 -07001027 options->parallel_gc_threads_,
1028 options->conc_gc_threads_,
1029 options->low_memory_mode_,
1030 options->long_pause_log_threshold_,
1031 options->long_gc_log_threshold_,
Mathieu Chartier692fafd2013-11-29 17:24:40 -08001032 options->ignore_max_footprint_,
Mathieu Chartier938a03b2014-01-16 15:10:31 -08001033 options->use_tlab_,
1034 options->verify_pre_gc_heap_,
Hiroshi Yamauchia4adbfd2014-02-04 18:12:17 -08001035 options->verify_post_gc_heap_,
1036 options->verify_pre_gc_rosalloc_,
1037 options->verify_post_gc_rosalloc_);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -07001038
Hiroshi Yamauchi2e899a92013-11-22 16:50:12 -08001039 dump_gc_performance_on_shutdown_ = options->dump_gc_performance_on_shutdown_;
1040
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001041 BlockSignals();
Elliott Hughes457005c2012-04-16 13:54:25 -07001042 InitPlatformSignalHandlers();
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001043
Elliott Hughesa0957642011-09-02 14:27:33 -07001044 java_vm_ = new JavaVMExt(this, options.get());
Elliott Hughes515a5bc2011-08-17 11:08:34 -07001045
Elliott Hughesbe759c62011-09-08 19:38:21 -07001046 Thread::Startup();
Elliott Hughesd92bec42011-09-02 17:04:36 -07001047
Mathieu Chartier664bebf2012-11-12 16:54:11 -08001048 // ClassLinker needs an attached thread, but we can't fully attach a thread without creating
1049 // objects. We can't supply a thread group yet; it will be fixed later. Since we are the main
1050 // thread, we do not get a java peer.
1051 Thread* self = Thread::Attach("main", false, NULL, false);
Ian Rogersd9c4fc92013-10-01 19:45:43 -07001052 CHECK_EQ(self->thin_lock_thread_id_, ThreadList::kMainThreadId);
Ian Rogers120f1c72012-09-28 17:17:10 -07001053 CHECK(self != NULL);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -07001054
Brian Carlstromf28bc5b2011-10-26 01:15:03 -07001055 // Set us to runnable so tools using a runtime can allocate and GC by default
Ian Rogers120f1c72012-09-28 17:17:10 -07001056 self->TransitionFromSuspendedToRunnable();
Brian Carlstromf28bc5b2011-10-26 01:15:03 -07001057
Ian Rogersa436fde2013-08-27 23:34:06 -07001058 // Now we're attached, we can take the heap locks and validate the heap.
Ian Rogers141d6222012-04-05 12:23:06 -07001059 GetHeap()->EnableObjectValidation();
1060
Ian Rogers1d54e732013-05-02 21:10:01 -07001061 CHECK_GE(GetHeap()->GetContinuousSpaces().size(), 1U);
Mathieu Chartier590fee92013-09-13 13:46:47 -07001062 class_linker_ = new ClassLinker(intern_table_);
1063 if (GetHeap()->HasImageSpace()) {
1064 class_linker_->InitFromImage();
Brian Carlstroma004aa92012-02-08 18:05:09 -08001065 } else {
1066 CHECK(options->boot_class_path_ != NULL);
1067 CHECK_NE(options->boot_class_path_->size(), 0U);
Mathieu Chartier590fee92013-09-13 13:46:47 -07001068 class_linker_->InitFromCompiler(*options->boot_class_path_);
Brian Carlstroma004aa92012-02-08 18:05:09 -08001069 }
1070 CHECK(class_linker_ != NULL);
Sameer Abu Asal51a5fb72013-02-19 14:25:01 -08001071 verifier::MethodVerifier::Init();
Brian Carlstrom6ea095a2011-08-16 15:26:54 -07001072
jeffhaob5e81852012-03-12 11:15:45 -07001073 method_trace_ = options->method_trace_;
1074 method_trace_file_ = options->method_trace_file_;
1075 method_trace_file_size_ = options->method_trace_file_size_;
1076
Dave Allison0aded082013-11-07 13:15:11 -08001077 // Extract the profile options.
1078 profile_period_s_ = options->profile_period_s_;
1079 profile_duration_s_ = options->profile_duration_s_;
1080 profile_interval_us_ = options->profile_interval_us_;
1081 profile_backoff_coefficient_ = options->profile_backoff_coefficient_;
1082 profile_ = options->profile_;
1083 profile_output_filename_ = options->profile_output_filename_;
1084
jeffhaob5e81852012-03-12 11:15:45 -07001085 if (options->method_trace_) {
Jeff Hao23009dc2013-08-22 15:36:42 -07001086 Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0,
1087 false, false, 0);
jeffhaob5e81852012-03-12 11:15:45 -07001088 }
1089
Ian Rogersa436fde2013-08-27 23:34:06 -07001090 // Pre-allocate an OutOfMemoryError for the double-OOME case.
1091 self->ThrowNewException(ThrowLocation(), "Ljava/lang/OutOfMemoryError;",
1092 "OutOfMemoryError thrown while trying to throw OutOfMemoryError; no stack available");
1093 pre_allocated_OutOfMemoryError_ = self->GetException(NULL);
1094 self->ClearException();
1095
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -08001096 VLOG(startup) << "Runtime::Init exiting";
Carl Shapiro1fb86202011-06-27 17:43:13 -07001097 return true;
1098}
1099
Elliott Hughes038a8062011-09-18 14:12:41 -07001100void Runtime::InitNativeMethods() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -08001101 VLOG(startup) << "Runtime::InitNativeMethods entering";
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001102 Thread* self = Thread::Current();
1103 JNIEnv* env = self->GetJniEnv();
1104
Elliott Hughes418d20f2011-09-22 14:00:39 -07001105 // Must be in the kNative state for calling native methods (JNI_OnLoad code).
Ian Rogers50b35e22012-10-04 10:09:15 -07001106 CHECK_EQ(self->GetState(), kNative);
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001107
Elliott Hughes418d20f2011-09-22 14:00:39 -07001108 // First set up JniConstants, which is used by both the runtime's built-in native
1109 // methods and libcore.
Elliott Hughesfea966e2011-09-22 10:26:20 -07001110 JniConstants::init(env);
Elliott Hugheseac76672012-05-24 21:56:51 -07001111 WellKnownClasses::Init(env);
Elliott Hughesfea966e2011-09-22 10:26:20 -07001112
Elliott Hughes418d20f2011-09-22 14:00:39 -07001113 // Then set up the native methods provided by the runtime itself.
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001114 RegisterRuntimeNativeMethods(env);
1115
Elliott Hughes418d20f2011-09-22 14:00:39 -07001116 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad.
1117 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's
1118 // the library that implements System.loadLibrary!
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001119 {
1120 std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, "javacore"));
1121 std::string reason;
1122 self->TransitionFromSuspendedToRunnable();
Mathieu Chartier055d46c2014-02-06 11:22:17 -08001123 SirtRef<mirror::ClassLoader> class_loader(self, nullptr);
1124 if (!instance_->java_vm_->LoadNativeLibrary(mapped_name, class_loader, &reason)) {
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001125 LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": " << reason;
1126 }
1127 self->TransitionFromRunnableToSuspended(kNative);
1128 }
Ian Rogersef28b142012-11-30 14:22:18 -08001129
1130 // Initialize well known classes that may invoke runtime native methods.
1131 WellKnownClasses::LateInit(env);
1132
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -08001133 VLOG(startup) << "Runtime::InitNativeMethods exiting";
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001134}
1135
Ian Rogers365c1022012-06-22 15:05:28 -07001136void Runtime::InitThreadGroups(Thread* self) {
1137 JNIEnvExt* env = self->GetJniEnv();
1138 ScopedJniEnvLocalRefState env_state(env);
1139 main_thread_group_ =
1140 env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup,
1141 WellKnownClasses::java_lang_ThreadGroup_mainThreadGroup));
Brian Carlstrom034f76b2012-08-01 15:51:58 -07001142 CHECK(main_thread_group_ != NULL || IsCompiler());
Ian Rogers365c1022012-06-22 15:05:28 -07001143 system_thread_group_ =
1144 env->NewGlobalRef(env->GetStaticObjectField(WellKnownClasses::java_lang_ThreadGroup,
1145 WellKnownClasses::java_lang_ThreadGroup_systemThreadGroup));
Brian Carlstrom034f76b2012-08-01 15:51:58 -07001146 CHECK(system_thread_group_ != NULL || IsCompiler());
1147}
1148
1149jobject Runtime::GetMainThreadGroup() const {
1150 CHECK(main_thread_group_ != NULL || IsCompiler());
1151 return main_thread_group_;
1152}
1153
1154jobject Runtime::GetSystemThreadGroup() const {
1155 CHECK(system_thread_group_ != NULL || IsCompiler());
1156 return system_thread_group_;
Ian Rogers365c1022012-06-22 15:05:28 -07001157}
1158
Brian Carlstromce888532013-10-10 00:32:58 -07001159jobject Runtime::GetSystemClassLoader() const {
1160 CHECK(system_class_loader_ != NULL || IsCompiler());
1161 return system_class_loader_;
1162}
1163
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001164void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) {
1165#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
Ian Rogers5167c972012-02-03 10:41:20 -08001166 // Register Throwable first so that registration of other native methods can throw exceptions
1167 REGISTER(register_java_lang_Throwable);
Brian Carlstromf91c8c32011-09-21 17:30:34 -07001168 REGISTER(register_dalvik_system_DexFile);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001169 REGISTER(register_dalvik_system_VMDebug);
Elliott Hughes7ede61e2011-09-14 18:18:06 -07001170 REGISTER(register_dalvik_system_VMRuntime);
Elliott Hughes8daa0922011-09-11 13:46:25 -07001171 REGISTER(register_dalvik_system_VMStack);
Elliott Hughes01158d72011-09-19 19:47:10 -07001172 REGISTER(register_dalvik_system_Zygote);
Elliott Hughesd369bb72011-09-12 14:41:14 -07001173 REGISTER(register_java_lang_Class);
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001174 REGISTER(register_java_lang_DexCache);
Elliott Hughesbf86d042011-08-31 17:53:14 -07001175 REGISTER(register_java_lang_Object);
1176 REGISTER(register_java_lang_Runtime);
1177 REGISTER(register_java_lang_String);
1178 REGISTER(register_java_lang_System);
Elliott Hughes8daa0922011-09-11 13:46:25 -07001179 REGISTER(register_java_lang_Thread);
Elliott Hughes64bf5a32011-09-20 14:43:12 -07001180 REGISTER(register_java_lang_VMClassLoader);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -07001181 REGISTER(register_java_lang_reflect_Array);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -07001182 REGISTER(register_java_lang_reflect_Constructor);
Brian Carlstromf867b6f2011-09-16 12:17:25 -07001183 REGISTER(register_java_lang_reflect_Field);
1184 REGISTER(register_java_lang_reflect_Method);
Jesse Wilson95caa792011-10-12 18:14:17 -04001185 REGISTER(register_java_lang_reflect_Proxy);
Elliott Hughesbf86d042011-08-31 17:53:14 -07001186 REGISTER(register_java_util_concurrent_atomic_AtomicLong);
Brian Carlstrom395520e2011-09-25 19:35:00 -07001187 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer);
Elliott Hughesf6a1e1e2011-10-25 16:28:04 -07001188 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal);
Elliott Hughes5ee7a8b2011-09-13 16:40:07 -07001189 REGISTER(register_sun_misc_Unsafe);
Elliott Hughesad7c2a32011-08-31 11:58:10 -07001190#undef REGISTER
1191}
1192
Elliott Hughesc967f782012-04-16 10:23:15 -07001193void Runtime::DumpForSigQuit(std::ostream& os) {
Elliott Hughescac6cc72011-11-03 20:31:21 -07001194 GetClassLinker()->DumpForSigQuit(os);
1195 GetInternTable()->DumpForSigQuit(os);
Elliott Hughesae80b492012-04-24 10:43:17 -07001196 GetJavaVM()->DumpForSigQuit(os);
Elliott Hughesc967f782012-04-16 10:23:15 -07001197 GetHeap()->DumpForSigQuit(os);
Elliott Hughes42ee1422011-09-06 12:33:32 -07001198 os << "\n";
Elliott Hughes8daa0922011-09-11 13:46:25 -07001199
Elliott Hughesc967f782012-04-16 10:23:15 -07001200 thread_list_->DumpForSigQuit(os);
Ian Rogers56edc432013-01-18 16:51:51 -08001201 BaseMutex::DumpAll(os);
Elliott Hughese27955c2011-08-26 15:21:24 -07001202}
1203
Elliott Hughes21a5bf22011-12-07 14:35:20 -08001204void Runtime::DumpLockHolders(std::ostream& os) {
Ian Rogersb726dcb2012-09-05 08:57:23 -07001205 uint64_t mutator_lock_owner = Locks::mutator_lock_->GetExclusiveOwnerTid();
Elliott Hughes21a5bf22011-12-07 14:35:20 -08001206 pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner();
1207 pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner();
1208 pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner();
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001209 if ((thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) {
1210 os << "Mutator lock exclusive owner tid: " << mutator_lock_owner << "\n"
Elliott Hughes21a5bf22011-12-07 14:35:20 -08001211 << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n"
1212 << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n"
1213 << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n";
1214 }
1215}
1216
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001217void Runtime::SetStatsEnabled(bool new_state) {
1218 if (new_state == true) {
1219 GetStats()->Clear(~0);
1220 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
1221 Thread::Current()->GetStats()->Clear(~0);
Ian Rogersfa824272013-11-05 16:12:57 -08001222 GetInstrumentation()->InstrumentQuickAllocEntryPoints();
Hiroshi Yamauchi3b4c1892013-09-12 21:33:12 -07001223 } else {
Ian Rogersfa824272013-11-05 16:12:57 -08001224 GetInstrumentation()->UninstrumentQuickAllocEntryPoints();
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001225 }
1226 stats_enabled_ = new_state;
1227}
1228
1229void Runtime::ResetStats(int kinds) {
1230 GetStats()->Clear(kinds & 0xffff);
1231 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
1232 Thread::Current()->GetStats()->Clear(kinds >> 16);
1233}
1234
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001235int32_t Runtime::GetStat(int kind) {
1236 RuntimeStats* stats;
1237 if (kind < (1<<16)) {
1238 stats = GetStats();
1239 } else {
1240 stats = Thread::Current()->GetStats();
1241 kind >>= 16;
1242 }
1243 switch (kind) {
1244 case KIND_ALLOCATED_OBJECTS:
1245 return stats->allocated_objects;
1246 case KIND_ALLOCATED_BYTES:
1247 return stats->allocated_bytes;
1248 case KIND_FREED_OBJECTS:
1249 return stats->freed_objects;
1250 case KIND_FREED_BYTES:
1251 return stats->freed_bytes;
1252 case KIND_GC_INVOCATIONS:
1253 return stats->gc_for_alloc_count;
1254 case KIND_CLASS_INIT_COUNT:
1255 return stats->class_init_count;
1256 case KIND_CLASS_INIT_TIME:
1257 // Convert ns to us, reduce to 32 bits.
Elliott Hughes398f64b2012-03-26 18:05:48 -07001258 return static_cast<int>(stats->class_init_time_ns / 1000);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001259 case KIND_EXT_ALLOCATED_OBJECTS:
1260 case KIND_EXT_ALLOCATED_BYTES:
1261 case KIND_EXT_FREED_OBJECTS:
1262 case KIND_EXT_FREED_BYTES:
1263 return 0; // backward compatibility
1264 default:
Elliott Hughes7b9d9962012-04-20 18:48:18 -07001265 LOG(FATAL) << "Unknown statistic " << kind;
Brian Carlstrom7934ac22013-07-26 10:54:15 -07001266 return -1; // unreachable
Elliott Hughes9d5ccec2011-09-19 13:19:50 -07001267 }
1268}
1269
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001270void Runtime::BlockSignals() {
Elliott Hughes457005c2012-04-16 13:54:25 -07001271 SignalSet signals;
1272 signals.Add(SIGPIPE);
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001273 // SIGQUIT is used to dump the runtime's state (including stack traces).
Elliott Hughes457005c2012-04-16 13:54:25 -07001274 signals.Add(SIGQUIT);
Elliott Hughes08795042012-04-03 14:48:52 -07001275 // SIGUSR1 is used to initiate a GC.
Elliott Hughes457005c2012-04-16 13:54:25 -07001276 signals.Add(SIGUSR1);
1277 signals.Block();
Elliott Hughesc1674ed2011-08-25 18:09:09 -07001278}
1279
Mathieu Chartier664bebf2012-11-12 16:54:11 -08001280bool Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, jobject thread_group,
1281 bool create_peer) {
1282 bool success = Thread::Attach(thread_name, as_daemon, thread_group, create_peer) != NULL;
Elliott Hughes22869a92012-03-27 14:08:24 -07001283 if (thread_name == NULL) {
1284 LOG(WARNING) << *Thread::Current() << " attached without supplying a name";
1285 }
Ian Rogers120f1c72012-09-28 17:17:10 -07001286 return success;
Carl Shapiro61e019d2011-07-14 16:53:09 -07001287}
1288
Elliott Hughesd92bec42011-09-02 17:04:36 -07001289void Runtime::DetachCurrentThread() {
Brian Carlstrom4d571432012-05-16 00:21:41 -07001290 Thread* self = Thread::Current();
1291 if (self == NULL) {
1292 LOG(FATAL) << "attempting to detach thread that is not attached";
1293 }
Ian Rogers0399dde2012-06-06 17:09:28 -07001294 if (self->HasManagedStack()) {
Elliott Hughes22869a92012-03-27 14:08:24 -07001295 LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code";
1296 }
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001297 thread_list_->Unregister(self);
Carl Shapiro1fb86202011-06-27 17:43:13 -07001298}
1299
Ian Rogersa436fde2013-08-27 23:34:06 -07001300 mirror::Throwable* Runtime::GetPreAllocatedOutOfMemoryError() const {
1301 if (pre_allocated_OutOfMemoryError_ == NULL) {
1302 LOG(ERROR) << "Failed to return pre-allocated OOME";
1303 }
1304 return pre_allocated_OutOfMemoryError_;
1305}
1306
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001307void Runtime::VisitConcurrentRoots(RootCallback* callback, void* arg, bool only_dirty,
Ian Rogers1d54e732013-05-02 21:10:01 -07001308 bool clean_dirty) {
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001309 intern_table_->VisitRoots(callback, arg, only_dirty, clean_dirty);
1310 class_linker_->VisitRoots(callback, arg, only_dirty, clean_dirty);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001311 // TODO: is it the right place ?
1312 if (preinitialization_transaction != nullptr) {
1313 preinitialization_transaction->VisitRoots(callback, arg);
1314 }
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -07001315}
1316
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001317void Runtime::VisitNonThreadRoots(RootCallback* callback, void* arg) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001318 // Visit the classes held as static in mirror classes.
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001319 mirror::ArtField::VisitRoots(callback, arg);
1320 mirror::ArtMethod::VisitRoots(callback, arg);
1321 mirror::Class::VisitRoots(callback, arg);
1322 mirror::StackTraceElement::VisitRoots(callback, arg);
1323 mirror::String::VisitRoots(callback, arg);
1324 mirror::Throwable::VisitRoots(callback, arg);
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001325 // Visit all the primitive array types classes.
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001326 mirror::PrimitiveArray<uint8_t>::VisitRoots(callback, arg); // BooleanArray
1327 mirror::PrimitiveArray<int8_t>::VisitRoots(callback, arg); // ByteArray
1328 mirror::PrimitiveArray<uint16_t>::VisitRoots(callback, arg); // CharArray
1329 mirror::PrimitiveArray<double>::VisitRoots(callback, arg); // DoubleArray
1330 mirror::PrimitiveArray<float>::VisitRoots(callback, arg); // FloatArray
1331 mirror::PrimitiveArray<int32_t>::VisitRoots(callback, arg); // IntArray
1332 mirror::PrimitiveArray<int64_t>::VisitRoots(callback, arg); // LongArray
1333 mirror::PrimitiveArray<int16_t>::VisitRoots(callback, arg); // ShortArray
1334 java_vm_->VisitRoots(callback, arg);
Mathieu Chartier423d2a32013-09-12 17:33:56 -07001335 if (pre_allocated_OutOfMemoryError_ != nullptr) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001336 pre_allocated_OutOfMemoryError_ = down_cast<mirror::Throwable*>(
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001337 callback(pre_allocated_OutOfMemoryError_, arg, 0, kRootVMInternal));
Mathieu Chartier423d2a32013-09-12 17:33:56 -07001338 DCHECK(pre_allocated_OutOfMemoryError_ != nullptr);
Elliott Hughes225f5a12012-06-11 11:23:48 -07001339 }
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001340 resolution_method_ = down_cast<mirror::ArtMethod*>(callback(resolution_method_, arg, 0,
1341 kRootVMInternal));
Mathieu Chartier423d2a32013-09-12 17:33:56 -07001342 DCHECK(resolution_method_ != nullptr);
Mathieu Chartier590fee92013-09-13 13:46:47 -07001343 if (HasImtConflictMethod()) {
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001344 imt_conflict_method_ = down_cast<mirror::ArtMethod*>(callback(imt_conflict_method_, arg, 0,
1345 kRootVMInternal));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001346 }
1347 if (HasDefaultImt()) {
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001348 default_imt_ = down_cast<mirror::ObjectArray<mirror::ArtMethod>*>(callback(default_imt_, arg,
1349 0, kRootVMInternal));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001350 }
1351
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001352 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
Mathieu Chartier590fee92013-09-13 13:46:47 -07001353 if (callee_save_methods_[i] != nullptr) {
1354 callee_save_methods_[i] = down_cast<mirror::ArtMethod*>(
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001355 callback(callee_save_methods_[i], arg, 0, kRootVMInternal));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001356 }
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001357 }
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001358 {
1359 MutexLock mu(Thread::Current(), method_verifiers_lock_);
1360 for (verifier::MethodVerifier* verifier : method_verifiers_) {
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001361 verifier->VisitRoots(callback, arg);
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001362 }
1363 }
Brian Carlstrome24fa612011-09-29 00:53:55 -07001364}
1365
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001366void Runtime::VisitNonConcurrentRoots(RootCallback* callback, void* arg) {
1367 thread_list_->VisitRoots(callback, arg);
1368 VisitNonThreadRoots(callback, arg);
Mathieu Chartier858f1c52012-10-17 17:45:55 -07001369}
1370
Mathieu Chartier83c8ee02014-01-28 14:50:23 -08001371void Runtime::VisitRoots(RootCallback* callback, void* arg, bool only_dirty, bool clean_dirty) {
1372 VisitConcurrentRoots(callback, arg, only_dirty, clean_dirty);
1373 VisitNonConcurrentRoots(callback, arg);
Mathieu Chartier9ebae1f2012-10-15 17:38:16 -07001374}
1375
Jeff Hao88474b42013-10-23 16:24:40 -07001376mirror::ObjectArray<mirror::ArtMethod>* Runtime::CreateDefaultImt(ClassLinker* cl) {
1377 Thread* self = Thread::Current();
1378 SirtRef<mirror::ObjectArray<mirror::ArtMethod> > imtable(self, cl->AllocArtMethodArray(self, 64));
1379 mirror::ArtMethod* imt_conflict_method = Runtime::Current()->GetImtConflictMethod();
Mathieu Chartier590fee92013-09-13 13:46:47 -07001380 for (size_t i = 0; i < static_cast<size_t>(imtable->GetLength()); i++) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001381 imtable->Set<false>(i, imt_conflict_method);
Jeff Hao88474b42013-10-23 16:24:40 -07001382 }
1383 return imtable.get();
1384}
1385
1386mirror::ArtMethod* Runtime::CreateImtConflictMethod() {
Jeff Hao88474b42013-10-23 16:24:40 -07001387 Thread* self = Thread::Current();
Ian Rogersef7d42f2014-01-06 12:55:46 -08001388 Runtime* runtime = Runtime::Current();
1389 ClassLinker* class_linker = runtime->GetClassLinker();
1390 SirtRef<mirror::ArtMethod> method(self, class_linker->AllocArtMethod(self));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001391 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
Ian Rogersef7d42f2014-01-06 12:55:46 -08001392 // TODO: use a special method for imt conflict method saves.
Jeff Hao88474b42013-10-23 16:24:40 -07001393 method->SetDexMethodIndex(DexFile::kDexNoIndex);
1394 // When compiling, the code pointer will get set later when the image is loaded.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001395 if (runtime->IsCompiler()) {
1396 method->SetEntryPointFromPortableCompiledCode(nullptr);
1397 method->SetEntryPointFromQuickCompiledCode(nullptr);
1398 } else {
1399 method->SetEntryPointFromPortableCompiledCode(GetPortableImtConflictTrampoline(class_linker));
1400 method->SetEntryPointFromQuickCompiledCode(GetQuickImtConflictTrampoline(class_linker));
1401 }
Jeff Hao88474b42013-10-23 16:24:40 -07001402 return method.get();
1403}
1404
Brian Carlstromea46f952013-07-30 01:26:50 -07001405mirror::ArtMethod* Runtime::CreateResolutionMethod() {
Ian Rogers50b35e22012-10-04 10:09:15 -07001406 Thread* self = Thread::Current();
Ian Rogersef7d42f2014-01-06 12:55:46 -08001407 Runtime* runtime = Runtime::Current();
1408 ClassLinker* class_linker = runtime->GetClassLinker();
1409 SirtRef<mirror::ArtMethod> method(self, class_linker->AllocArtMethod(self));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001410 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
Ian Rogers19846512012-02-24 11:42:47 -08001411 // TODO: use a special method for resolution method saves
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001412 method->SetDexMethodIndex(DexFile::kDexNoIndex);
Jeff Hao58df3272013-04-22 15:28:53 -07001413 // When compiling, the code pointer will get set later when the image is loaded.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001414 if (runtime->IsCompiler()) {
1415 method->SetEntryPointFromPortableCompiledCode(nullptr);
1416 method->SetEntryPointFromQuickCompiledCode(nullptr);
1417 } else {
1418 method->SetEntryPointFromPortableCompiledCode(GetPortableResolutionTrampoline(class_linker));
1419 method->SetEntryPointFromQuickCompiledCode(GetQuickResolutionTrampoline(class_linker));
1420 }
Ian Rogers19846512012-02-24 11:42:47 -08001421 return method.get();
1422}
1423
Brian Carlstromea46f952013-07-30 01:26:50 -07001424mirror::ArtMethod* Runtime::CreateCalleeSaveMethod(InstructionSet instruction_set,
Mathieu Chartier590fee92013-09-13 13:46:47 -07001425 CalleeSaveType type) {
Ian Rogers50b35e22012-10-04 10:09:15 -07001426 Thread* self = Thread::Current();
Ian Rogersef7d42f2014-01-06 12:55:46 -08001427 Runtime* runtime = Runtime::Current();
1428 ClassLinker* class_linker = runtime->GetClassLinker();
1429 SirtRef<mirror::ArtMethod> method(self, class_linker->AllocArtMethod(self));
Mathieu Chartier590fee92013-09-13 13:46:47 -07001430 method->SetDeclaringClass(mirror::ArtMethod::GetJavaLangReflectArtMethod());
Ian Rogers6d4d9fc2011-11-30 16:24:48 -08001431 // TODO: use a special method for callee saves
Ian Rogers8b2c0b92013-09-19 02:56:49 -07001432 method->SetDexMethodIndex(DexFile::kDexNoIndex);
Ian Rogersef7d42f2014-01-06 12:55:46 -08001433 method->SetEntryPointFromPortableCompiledCode(nullptr);
1434 method->SetEntryPointFromQuickCompiledCode(nullptr);
Brian Carlstromae826982011-11-09 01:33:42 -08001435 if ((instruction_set == kThumb2) || (instruction_set == kArm)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001436 uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) |
1437 (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11);
1438 uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3);
1439 uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9);
jeffhaofa147e22012-10-12 17:03:32 -07001440 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
1441 (type == kSaveAll ? all_spills : 0) | (1 << art::arm::LR);
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001442 uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) |
1443 (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) |
1444 (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) |
1445 (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) |
1446 (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) |
1447 (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) |
1448 (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) |
1449 (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) |
1450 (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) |
1451 (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) |
1452 (1 << art::arm::S30) | (1 << art::arm::S31);
1453 uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0;
1454 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
1455 __builtin_popcount(fp_spills) /* fprs */ +
1456 1 /* Method* */) * kPointerSize, kStackAlignment);
Ian Rogers15fdb8c2011-09-25 15:45:07 -07001457 method->SetFrameSizeInBytes(frame_size);
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001458 method->SetCoreSpillMask(core_spills);
1459 method->SetFpSpillMask(fp_spills);
jeffhao7fbee072012-08-24 17:56:54 -07001460 } else if (instruction_set == kMips) {
1461 uint32_t ref_spills = (1 << art::mips::S2) | (1 << art::mips::S3) | (1 << art::mips::S4) |
1462 (1 << art::mips::S5) | (1 << art::mips::S6) | (1 << art::mips::S7) |
Jeff Hao1f3bc2f2013-04-30 15:17:19 -07001463 (1 << art::mips::GP) | (1 << art::mips::FP);
jeffhao7fbee072012-08-24 17:56:54 -07001464 uint32_t arg_spills = (1 << art::mips::A1) | (1 << art::mips::A2) | (1 << art::mips::A3);
jeffhaofa147e22012-10-12 17:03:32 -07001465 uint32_t all_spills = (1 << art::mips::S0) | (1 << art::mips::S1);
jeffhao7fbee072012-08-24 17:56:54 -07001466 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
jeffhaofa147e22012-10-12 17:03:32 -07001467 (type == kSaveAll ? all_spills : 0) | (1 << art::mips::RA);
jeffhao7fbee072012-08-24 17:56:54 -07001468 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
Jeff Hao1f3bc2f2013-04-30 15:17:19 -07001469 (type == kRefsAndArgs ? 0 : 3) + 1 /* Method* */) *
1470 kPointerSize, kStackAlignment);
jeffhao7fbee072012-08-24 17:56:54 -07001471 method->SetFrameSizeInBytes(frame_size);
1472 method->SetCoreSpillMask(core_spills);
jeffhao07030602012-09-26 14:33:14 -07001473 method->SetFpSpillMask(0);
Brian Carlstromae826982011-11-09 01:33:42 -08001474 } else if (instruction_set == kX86) {
Ian Rogers7caad772012-03-30 01:07:54 -07001475 uint32_t ref_spills = (1 << art::x86::EBP) | (1 << art::x86::ESI) | (1 << art::x86::EDI);
1476 uint32_t arg_spills = (1 << art::x86::ECX) | (1 << art::x86::EDX) | (1 << art::x86::EBX);
1477 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
1478 (1 << art::x86::kNumberOfCpuRegisters); // fake return address callee save
1479 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
1480 1 /* Method* */) * kPointerSize, kStackAlignment);
1481 method->SetFrameSizeInBytes(frame_size);
1482 method->SetCoreSpillMask(core_spills);
Ian Rogersff1ed472011-09-20 13:46:24 -07001483 method->SetFpSpillMask(0);
Ian Rogersef7d42f2014-01-06 12:55:46 -08001484 } else if (instruction_set == kX86_64) {
1485 uint32_t ref_spills =
Ian Rogers0177e532014-02-11 16:30:46 -08001486 (1 << art::x86_64::RBX) | (1 << art::x86_64::RBP) | (1 << art::x86_64::R12) |
1487 (1 << art::x86_64::R13) | (1 << art::x86_64::R14) | (1 << art::x86_64::R15);
Ian Rogersef7d42f2014-01-06 12:55:46 -08001488 uint32_t arg_spills =
Ian Rogers0177e532014-02-11 16:30:46 -08001489 (1 << art::x86_64::RSI) | (1 << art::x86_64::RDX) | (1 << art::x86_64::RCX) |
1490 (1 << art::x86_64::R8) | (1 << art::x86_64::R9);
Ian Rogersef7d42f2014-01-06 12:55:46 -08001491 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
1492 (1 << art::x86::kNumberOfCpuRegisters); // fake return address callee save
1493 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
1494 1 /* Method* */) * kPointerSize, kStackAlignment);
1495 method->SetFrameSizeInBytes(frame_size);
1496 method->SetCoreSpillMask(core_spills);
1497 method->SetFpSpillMask(0);
Ian Rogersff1ed472011-09-20 13:46:24 -07001498 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -08001499 UNIMPLEMENTED(FATAL) << instruction_set;
Ian Rogersff1ed472011-09-20 13:46:24 -07001500 }
Brian Carlstrom40381fb2011-10-19 14:13:40 -07001501 return method.get();
Ian Rogersff1ed472011-09-20 13:46:24 -07001502}
1503
Mathieu Chartierc11d9b82013-09-19 10:01:59 -07001504void Runtime::DisallowNewSystemWeaks() {
1505 monitor_list_->DisallowNewMonitors();
1506 intern_table_->DisallowNewInterns();
1507 java_vm_->DisallowNewWeakGlobals();
Mathieu Chartier412c7fc2014-02-07 12:18:39 -08001508 Dbg::DisallowNewObjectRegistryObjects();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -07001509}
1510
1511void Runtime::AllowNewSystemWeaks() {
1512 monitor_list_->AllowNewMonitors();
1513 intern_table_->AllowNewInterns();
1514 java_vm_->AllowNewWeakGlobals();
Mathieu Chartier412c7fc2014-02-07 12:18:39 -08001515 Dbg::AllowNewObjectRegistryObjects();
Mathieu Chartierc11d9b82013-09-19 10:01:59 -07001516}
1517
Brian Carlstromea46f952013-07-30 01:26:50 -07001518void Runtime::SetCalleeSaveMethod(mirror::ArtMethod* method, CalleeSaveType type) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001519 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType));
Elliott Hughes225f5a12012-06-11 11:23:48 -07001520 callee_save_methods_[type] = method;
Brian Carlstrome24fa612011-09-29 00:53:55 -07001521}
1522
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001523const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(jobject class_loader) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -08001524 if (class_loader == NULL) {
1525 return GetClassLinker()->GetBootClassPath();
1526 }
1527 CHECK(UseCompileTimeClassPath());
1528 CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader);
1529 CHECK(it != compile_time_class_paths_.end());
1530 return it->second;
1531}
1532
Ian Rogers00f7d0e2012-07-19 15:28:27 -07001533void Runtime::SetCompileTimeClassPath(jobject class_loader, std::vector<const DexFile*>& class_path) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -08001534 CHECK(!IsStarted());
1535 use_compile_time_class_path_ = true;
Elliott Hughesa0e18062012-04-13 15:59:59 -07001536 compile_time_class_paths_.Put(class_loader, class_path);
Elliott Hughesb3bd5f02012-03-08 21:05:27 -08001537}
1538
Mathieu Chartierc528dba2013-11-26 12:00:11 -08001539void Runtime::AddMethodVerifier(verifier::MethodVerifier* verifier) {
1540 DCHECK(verifier != nullptr);
1541 MutexLock mu(Thread::Current(), method_verifiers_lock_);
1542 method_verifiers_.insert(verifier);
1543}
1544
1545void Runtime::RemoveMethodVerifier(verifier::MethodVerifier* verifier) {
1546 DCHECK(verifier != nullptr);
1547 MutexLock mu(Thread::Current(), method_verifiers_lock_);
1548 auto it = method_verifiers_.find(verifier);
1549 CHECK(it != method_verifiers_.end());
1550 method_verifiers_.erase(it);
1551}
1552
Dave Allison0aded082013-11-07 13:15:11 -08001553void Runtime::StartProfiler(const char *appDir, bool startImmediately) {
1554 BackgroundMethodSamplingProfiler::Start(profile_period_s_, profile_duration_s_, appDir, profile_interval_us_,
1555 profile_backoff_coefficient_, startImmediately);
1556}
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001557
1558// Transaction support.
1559// TODO move them to header file for inlining.
1560bool Runtime::IsActiveTransaction() const {
1561 return preinitialization_transaction != nullptr;
1562}
1563
1564void Runtime::EnterTransactionMode(Transaction* transaction) {
1565 DCHECK(IsCompiler());
1566 DCHECK(transaction != nullptr);
1567 DCHECK(!IsActiveTransaction());
1568 preinitialization_transaction = transaction;
1569}
1570
1571void Runtime::ExitTransactionMode() {
1572 DCHECK(IsCompiler());
1573 DCHECK(IsActiveTransaction());
1574 preinitialization_transaction = nullptr;
1575}
1576
1577void Runtime::RecordWriteField32(mirror::Object* obj, MemberOffset field_offset,
1578 uint32_t value, bool is_volatile) const {
1579 DCHECK(IsCompiler());
1580 DCHECK(IsActiveTransaction());
1581 preinitialization_transaction->RecordWriteField32(obj, field_offset, value, is_volatile);
1582}
1583
1584void Runtime::RecordWriteField64(mirror::Object* obj, MemberOffset field_offset,
1585 uint64_t value, bool is_volatile) const {
1586 DCHECK(IsCompiler());
1587 DCHECK(IsActiveTransaction());
1588 preinitialization_transaction->RecordWriteField64(obj, field_offset, value, is_volatile);
1589}
1590
1591void Runtime::RecordWriteFieldReference(mirror::Object* obj, MemberOffset field_offset,
1592 mirror::Object* value, bool is_volatile) const {
1593 DCHECK(IsCompiler());
1594 DCHECK(IsActiveTransaction());
1595 preinitialization_transaction->RecordWriteFieldReference(obj, field_offset, value, is_volatile);
1596}
1597
1598void Runtime::RecordWriteArray(mirror::Array* array, size_t index, uint64_t value) const {
1599 DCHECK(IsCompiler());
1600 DCHECK(IsActiveTransaction());
1601 preinitialization_transaction->RecordWriteArray(array, index, value);
1602}
1603
1604void Runtime::RecordStrongStringInsertion(mirror::String* s, uint32_t hash_code) const {
1605 DCHECK(IsCompiler());
1606 DCHECK(IsActiveTransaction());
1607 preinitialization_transaction->RecordStrongStringInsertion(s, hash_code);
1608}
1609
1610void Runtime::RecordWeakStringInsertion(mirror::String* s, uint32_t hash_code) const {
1611 DCHECK(IsCompiler());
1612 DCHECK(IsActiveTransaction());
1613 preinitialization_transaction->RecordWeakStringInsertion(s, hash_code);
1614}
1615
1616void Runtime::RecordStrongStringRemoval(mirror::String* s, uint32_t hash_code) const {
1617 DCHECK(IsCompiler());
1618 DCHECK(IsActiveTransaction());
1619 preinitialization_transaction->RecordStrongStringRemoval(s, hash_code);
1620}
1621
1622void Runtime::RecordWeakStringRemoval(mirror::String* s, uint32_t hash_code) const {
1623 DCHECK(IsCompiler());
1624 DCHECK(IsActiveTransaction());
1625 preinitialization_transaction->RecordWeakStringRemoval(s, hash_code);
1626}
Carl Shapiro1fb86202011-06-27 17:43:13 -07001627} // namespace art