blob: 8fe760ec63e2977218168d345df160bd442016c4 [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 Carlstromdbf05b72011-12-15 00:55:24 -080019#include <signal.h>
20
Elliott Hughesffe67362011-07-17 12:09:27 -070021#include <cstdio>
22#include <cstdlib>
Brian Carlstrom8a436592011-08-15 21:27:23 -070023#include <limits>
Carl Shapiro2ed144c2011-07-26 16:52:08 -070024#include <vector>
TDYa127b92bcab2012-04-08 00:09:51 -070025#include <fstream>
Elliott Hughesffe67362011-07-17 12:09:27 -070026
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070027#include "class_linker.h"
Brian Carlstromaded5f72011-10-07 17:15:04 -070028#include "class_loader.h"
Elliott Hughes0f3c5532012-03-30 14:51:51 -070029#include "constants_arm.h"
30#include "constants_x86.h"
Elliott Hughes3bb81562011-10-21 18:52:59 -070031#include "debugger.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070032#include "heap.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070033#include "image.h"
Elliott Hughescf4c6c42011-09-01 15:16:42 -070034#include "intern_table.h"
Elliott Hughesc5f7c912011-08-18 14:00:42 -070035#include "jni_internal.h"
Elliott Hughes32d6e1e2011-10-11 14:47:44 -070036#include "monitor.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070037#include "oat_file.h"
Elliott Hughes726079d2011-10-07 18:43:44 -070038#include "ScopedLocalRef.h"
Elliott Hughese27955c2011-08-26 15:21:24 -070039#include "signal_catcher.h"
Elliott Hughes457005c2012-04-16 13:54:25 -070040#include "signal_set.h"
Brian Carlstrome24fa612011-09-29 00:53:55 -070041#include "space.h"
Brian Carlstrom578bbdc2011-07-21 14:07:47 -070042#include "thread.h"
Elliott Hughes8daa0922011-09-11 13:46:25 -070043#include "thread_list.h"
jeffhaob5e81852012-03-12 11:15:45 -070044#include "trace.h"
Elliott Hughes3bb81562011-10-21 18:52:59 -070045#include "UniquePtr.h"
Ian Rogers776ac1f2012-04-13 23:36:36 -070046#include "verifier/method_verifier.h"
Carl Shapiro61e019d2011-07-14 16:53:09 -070047
Elliott Hughes90a33692011-08-30 13:27:07 -070048// TODO: this drags in cutil/log.h, which conflicts with our logging.h.
49#include "JniConstants.h"
50
Carl Shapiro1fb86202011-06-27 17:43:13 -070051namespace art {
52
Carl Shapiro2ed144c2011-07-26 16:52:08 -070053Runtime* Runtime::instance_ = NULL;
54
Elliott Hughesdcc24742011-09-07 14:02:44 -070055Runtime::Runtime()
Elliott Hughesd9c67be2012-02-02 19:54:06 -080056 : is_compiler_(false),
57 is_zygote_(false),
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -070058 default_stack_size_(Thread::kDefaultStackSize),
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080059 heap_(NULL),
Elliott Hughesc33a32b2011-10-11 18:18:07 -070060 monitor_list_(NULL),
Elliott Hughesdcc24742011-09-07 14:02:44 -070061 thread_list_(NULL),
62 intern_table_(NULL),
63 class_linker_(NULL),
64 signal_catcher_(NULL),
65 java_vm_(NULL),
Brian Carlstrom16192862011-09-12 17:50:06 -070066 jni_stub_array_(NULL),
Brian Carlstrome24fa612011-09-29 00:53:55 -070067 abstract_method_error_stub_array_(NULL),
Ian Rogers19846512012-02-24 11:42:47 -080068 resolution_method_(NULL),
Ian Rogers7c3757f2012-02-15 17:18:53 -080069 system_class_loader_(NULL),
Elliott Hughes6b355752012-01-13 16:49:08 -080070 shutting_down_(false),
Elliott Hughesdcc24742011-09-07 14:02:44 -070071 started_(false),
72 vfprintf_(NULL),
73 exit_(NULL),
Elliott Hughes9d5ccec2011-09-19 13:19:50 -070074 abort_(NULL),
jeffhao2692b572011-12-16 15:42:28 -080075 stats_enabled_(false),
Ian Rogers776ac1f2012-04-13 23:36:36 -070076 method_trace_(0),
77 method_trace_file_size_(0),
Elliott Hughesb3bd5f02012-03-08 21:05:27 -080078 tracer_(NULL),
79 use_compile_time_class_path_(false) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -070080 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
81 resolution_stub_array_[i] = NULL;
82 }
83 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
84 callee_save_method_[i] = NULL;
85 }
Elliott Hughesdcc24742011-09-07 14:02:44 -070086}
87
Carl Shapiro61e019d2011-07-14 16:53:09 -070088Runtime::~Runtime() {
Elliott Hughes6b355752012-01-13 16:49:08 -080089 shutting_down_ = true;
90
jeffhaob5e81852012-03-12 11:15:45 -070091 if (IsMethodTracingActive()) {
92 Trace::Shutdown();
93 }
94
Elliott Hughes5fe594f2011-09-08 12:33:17 -070095 // Make sure our internal threads are dead before we start tearing down things they're using.
Elliott Hughese52e49b2012-04-02 16:05:44 -070096 Dbg::StopJdwp();
Elliott Hughes5fe594f2011-09-08 12:33:17 -070097 delete signal_catcher_;
98
Elliott Hughes038a8062011-09-18 14:12:41 -070099 // Make sure all other non-daemon threads have terminated, and all daemon threads are suspended.
Elliott Hughes93e74e82011-09-13 11:07:03 -0700100 delete thread_list_;
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700101 delete monitor_list_;
Elliott Hughes93e74e82011-09-13 11:07:03 -0700102
Carl Shapiro61e019d2011-07-14 16:53:09 -0700103 delete class_linker_;
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800104 delete heap_;
Logan Chiendd361c92012-04-10 23:40:37 +0800105#if defined(ART_USE_LLVM_COMPILER)
Ian Rogers776ac1f2012-04-13 23:36:36 -0700106 verifier::MethodVerifier::DeleteInferredRegCategoryMaps();
Logan Chiendd361c92012-04-10 23:40:37 +0800107#endif
Ian Rogers776ac1f2012-04-13 23:36:36 -0700108 verifier::MethodVerifier::DeleteGcMaps();
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700109 delete intern_table_;
Elliott Hughesc5f7c912011-08-18 14:00:42 -0700110 delete java_vm_;
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700111 Thread::Shutdown();
Carl Shapiro4acf4642011-07-26 18:54:13 -0700112 // TODO: acquire a static mutex on Runtime to avoid racing.
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700113 CHECK(instance_ == NULL || instance_ == this);
Carl Shapiro4acf4642011-07-26 18:54:13 -0700114 instance_ = NULL;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700115}
116
Elliott Hughescac6cc72011-11-03 20:31:21 -0700117static bool gAborting = false;
118
Elliott Hughese0918552011-10-28 17:18:29 -0700119struct AbortState {
120 void Dump(std::ostream& os) {
Elliott Hughescac6cc72011-11-03 20:31:21 -0700121 if (gAborting) {
122 os << "Runtime aborting --- recursively, so no thread-specific detail!\n";
123 return;
124 }
125 gAborting = true;
Elliott Hughese0918552011-10-28 17:18:29 -0700126 os << "Runtime aborting...\n";
Elliott Hughes6c7d2442012-02-01 18:40:47 -0800127 if (Runtime::Current() == NULL) {
128 os << "(Runtime does not yet exist!)\n";
129 return;
130 }
Elliott Hughese0918552011-10-28 17:18:29 -0700131 Thread* self = Thread::Current();
132 if (self == NULL) {
133 os << "(Aborting thread was not attached to runtime!)\n";
134 } else {
Elliott Hughes899e7892012-01-24 14:57:32 -0800135 self->Dump(os);
136 if (self->IsExceptionPending()) {
137 os << "Pending " << PrettyTypeOf(self->GetException()) << " on thread:\n"
138 << self->GetException()->Dump();
139 }
Elliott Hughese0918552011-10-28 17:18:29 -0700140 }
141 }
142};
143
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800144static Mutex& GetAbortLock() {
145 static Mutex abort_lock("abort lock");
146 return abort_lock;
147}
148
Elliott Hughes8593fdb2012-04-21 20:53:44 -0700149void Runtime::Abort() {
Elliott Hughes131aef82012-01-27 11:53:35 -0800150 // Ensure that we don't have multiple threads trying to abort at once,
151 // which would result in significantly worse diagnostics.
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800152 MutexLock mu(GetAbortLock());
Elliott Hughes131aef82012-01-27 11:53:35 -0800153
Elliott Hughesffe67362011-07-17 12:09:27 -0700154 // Get any pending output out of the way.
155 fflush(NULL);
156
157 // Many people have difficulty distinguish aborts from crashes,
158 // so be explicit.
Elliott Hughese0918552011-10-28 17:18:29 -0700159 AbortState state;
Elliott Hughes9ee5f9c2012-02-03 18:33:16 -0800160 LOG(INTERNAL_FATAL) << Dumpable<AbortState>(state);
Elliott Hughesffe67362011-07-17 12:09:27 -0700161
Elliott Hughes8593fdb2012-04-21 20:53:44 -0700162 // Call the abort hook if we have one.
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700163 if (Runtime::Current() != NULL && Runtime::Current()->abort_ != NULL) {
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700164 LOG(INTERNAL_FATAL) << "Calling abort hook...";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700165 Runtime::Current()->abort_();
166 // notreached
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700167 LOG(INTERNAL_FATAL) << "Unexpectedly returned from abort hook!";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700168 }
169
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700170 // TODO: finish merging patches to fix abort(3) in bionic, then lose this!
171 // Bionic doesn't implement POSIX semantics for abort(3) in a multi-threaded
172 // process, so if we call abort(3) on a device, all threads in the process
Carl Shapiro69759ea2011-07-21 18:13:35 -0700173 // receive SIGABRT. debuggerd dumps the stack trace of the main
174 // thread, whether or not that was the thread that failed. By
175 // stuffing a value into a bogus address, we cause a segmentation
Elliott Hughesffe67362011-07-17 12:09:27 -0700176 // fault in the current thread, and get a useful log from debuggerd.
Elliott Hughes81ff3182012-03-23 20:35:56 -0700177 // We can also trivially tell the difference between a crash and
Elliott Hughesffe67362011-07-17 12:09:27 -0700178 // a deliberate abort by looking at the fault address.
179 *reinterpret_cast<char*>(0xdeadd00d) = 38;
180 abort();
Elliott Hughesffe67362011-07-17 12:09:27 -0700181 // notreached
182}
183
Elliott Hughesbf86d042011-08-31 17:53:14 -0700184void Runtime::CallExitHook(jint status) {
185 if (exit_ != NULL) {
Elliott Hughes34e06962012-04-09 13:55:55 -0700186 ScopedThreadStateChange tsc(Thread::Current(), kNative);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700187 exit_(status);
188 LOG(WARNING) << "Exit hook returned instead of exiting!";
189 }
190}
191
Brian Carlstrom8a436592011-08-15 21:27:23 -0700192// Parse a string of the form /[0-9]+[kKmMgG]?/, which is used to specify
193// memory sizes. [kK] indicates kilobytes, [mM] megabytes, and
194// [gG] gigabytes.
195//
196// "s" should point just past the "-Xm?" part of the string.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700197// "div" specifies a divisor, e.g. 1024 if the value must be a multiple
198// of 1024.
199//
200// The spec says the -Xmx and -Xms options must be multiples of 1024. It
201// doesn't say anything about -Xss.
202//
203// Returns 0 (a useless size) if "s" is malformed or specifies a low or
204// non-evenly-divisible value.
205//
Elliott Hughesc1f143d2011-12-01 17:31:10 -0800206size_t ParseMemoryOption(const char* s, size_t div) {
Brian Carlstrom8a436592011-08-15 21:27:23 -0700207 // strtoul accepts a leading [+-], which we don't want,
208 // so make sure our string starts with a decimal digit.
209 if (isdigit(*s)) {
Elliott Hughes398f64b2012-03-26 18:05:48 -0700210 char* s2;
211 size_t val = strtoul(s, &s2, 10);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700212 if (s2 != s) {
213 // s2 should be pointing just after the number.
214 // If this is the end of the string, the user
215 // has specified a number of bytes. Otherwise,
216 // there should be exactly one more character
217 // that specifies a multiplier.
218 if (*s2 != '\0') {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700219 // The remainder of the string is either a single multiplier
220 // character, or nothing to indicate that the value is in
221 // bytes.
222 char c = *s2++;
223 if (*s2 == '\0') {
224 size_t mul;
225 if (c == '\0') {
226 mul = 1;
227 } else if (c == 'k' || c == 'K') {
228 mul = KB;
229 } else if (c == 'm' || c == 'M') {
230 mul = MB;
231 } else if (c == 'g' || c == 'G') {
232 mul = GB;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700233 } else {
Brian Carlstromf734cf52011-08-17 16:28:14 -0700234 // Unknown multiplier character.
Brian Carlstrom8a436592011-08-15 21:27:23 -0700235 return 0;
236 }
Brian Carlstromf734cf52011-08-17 16:28:14 -0700237
238 if (val <= std::numeric_limits<size_t>::max() / mul) {
239 val *= mul;
240 } else {
241 // Clamp to a multiple of 1024.
242 val = std::numeric_limits<size_t>::max() & ~(1024-1);
243 }
244 } else {
245 // There's more than one character after the numeric part.
246 return 0;
247 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700248 }
249 // The man page says that a -Xm value must be a multiple of 1024.
250 if (val % div == 0) {
251 return val;
252 }
Carl Shapirofc322c72011-07-27 00:20:01 -0700253 }
254 }
Brian Carlstrom8a436592011-08-15 21:27:23 -0700255 return 0;
Carl Shapirofc322c72011-07-27 00:20:01 -0700256}
257
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800258size_t ParseIntegerOrDie(const std::string& s) {
259 std::string::size_type colon = s.find(':');
260 if (colon == std::string::npos) {
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700261 LOG(FATAL) << "Missing integer: " << s;
262 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800263 const char* begin = &s[colon + 1];
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700264 char* end;
265 size_t result = strtoul(begin, &end, 10);
266 if (begin == end || *end != '\0') {
267 LOG(FATAL) << "Failed to parse integer in: " << s;
268 }
269 return result;
270}
271
Elliott Hughes0af55432011-08-17 18:37:28 -0700272void LoadJniLibrary(JavaVMExt* vm, const char* name) {
Elliott Hughes6cc332e2012-01-20 22:59:20 -0800273 std::string mapped_name(StringPrintf(OS_SHARED_LIB_FORMAT_STR, name));
Elliott Hughes75770752011-08-24 17:52:38 -0700274 std::string reason;
275 if (!vm->LoadNativeLibrary(mapped_name, NULL, reason)) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700276 LOG(FATAL) << "LoadNativeLibrary failed for \"" << mapped_name << "\": "
277 << reason;
278 }
279}
280
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700281Runtime::ParsedOptions* Runtime::ParsedOptions::Create(const Options& options, bool ignore_unrecognized) {
Elliott Hughes90a33692011-08-30 13:27:07 -0700282 UniquePtr<ParsedOptions> parsed(new ParsedOptions());
Brian Carlstroma004aa92012-02-08 18:05:09 -0800283 const char* boot_class_path_string = getenv("BOOTCLASSPATH");
284 if (boot_class_path_string != NULL) {
285 parsed->boot_class_path_string_ = boot_class_path_string;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700286 }
Brian Carlstroma004aa92012-02-08 18:05:09 -0800287 const char* class_path_string = getenv("CLASSPATH");
288 if (class_path_string != NULL) {
289 parsed->class_path_string_ = class_path_string;
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700290 }
Elliott Hughes67d92002012-03-26 15:08:51 -0700291 // -Xcheck:jni is off by default for regular builds but on by default in debug builds.
292 parsed->check_jni_ = kIsDebugBuild;
Elliott Hughes85d15452011-09-16 17:33:01 -0700293
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700294 parsed->heap_initial_size_ = Heap::kInitialSize;
295 parsed->heap_maximum_size_ = Heap::kMaximumSize;
jeffhaoc1160702011-10-27 15:48:45 -0700296 parsed->heap_growth_limit_ = 0; // 0 means no growth limit
Brian Carlstromf734cf52011-08-17 16:28:14 -0700297 parsed->stack_size_ = Thread::kDefaultStackSize;
298
Elliott Hughesd9c67be2012-02-02 19:54:06 -0800299 parsed->is_compiler_ = false;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700300 parsed->is_zygote_ = false;
301
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700302 parsed->jni_globals_max_ = 0;
Elliott Hughesfc861622011-10-17 17:57:47 -0700303 parsed->lock_profiling_threshold_ = 0;
304 parsed->hook_is_sensitive_thread_ = NULL;
305
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700306 parsed->hook_vfprintf_ = vfprintf;
307 parsed->hook_exit_ = exit;
Elliott Hughes6c1c69e2012-04-23 16:12:51 -0700308 parsed->hook_abort_ = NULL; // We don't call abort(3) by default; see Runtime::Abort.
309#if defined(__APPLE__)
310 parsed->hook_abort_ = abort; // On the Mac, abort(3) gives better results; see Runtime::InitPlatformSignalHandlers.
311#endif
Brian Carlstrom8a436592011-08-15 21:27:23 -0700312
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800313// gLogVerbosity.class_linker = true; // TODO: don't check this in!
314// gLogVerbosity.compiler = true; // TODO: don't check this in!
315// gLogVerbosity.heap = true; // TODO: don't check this in!
316// gLogVerbosity.gc = true; // TODO: don't check this in!
317// gLogVerbosity.jdwp = true; // TODO: don't check this in!
318// gLogVerbosity.jni = true; // TODO: don't check this in!
319// gLogVerbosity.monitor = true; // TODO: don't check this in!
320// gLogVerbosity.startup = true; // TODO: don't check this in!
321// gLogVerbosity.third_party_jni = true; // TODO: don't check this in!
322// gLogVerbosity.threads = true; // TODO: don't check this in!
323
jeffhaob5e81852012-03-12 11:15:45 -0700324 parsed->method_trace_ = false;
325 parsed->method_trace_file_ = "/data/method-trace-file.bin";
326 parsed->method_trace_file_size_ = 10 * MB;
327
Brian Carlstrom8a436592011-08-15 21:27:23 -0700328 for (size_t i = 0; i < options.size(); ++i) {
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800329 const std::string option(options[i].first);
Brian Carlstrom0796af02011-10-12 14:31:45 -0700330 if (true && options[0].first == "-Xzygote") {
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700331 LOG(INFO) << "option[" << i << "]=" << option;
332 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800333 if (StartsWith(option, "-Xbootclasspath:")) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800334 parsed->boot_class_path_string_ = option.substr(strlen("-Xbootclasspath:")).data();
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700335 } else if (option == "-classpath" || option == "-cp") {
336 // TODO: support -Djava.class.path
337 i++;
338 if (i == options.size()) {
339 // TODO: usage
340 LOG(FATAL) << "Missing required class path value for " << option;
341 return NULL;
342 }
Brian Carlstroma004aa92012-02-08 18:05:09 -0800343 const StringPiece& value = options[i].first;
344 parsed->class_path_string_ = value.data();
345 } else if (option == "bootclasspath") {
346 parsed->boot_class_path_
347 = reinterpret_cast<const std::vector<const DexFile*>*>(options[i].second);
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800348 } else if (StartsWith(option, "-Ximage:")) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800349 parsed->image_ = option.substr(strlen("-Ximage:")).data();
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800350 } else if (StartsWith(option, "-Xcheck:jni")) {
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700351 parsed->check_jni_ = true;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800352 } else if (StartsWith(option, "-Xrunjdwp:") || StartsWith(option, "-agentlib:jdwp=")) {
353 std::string tail(option.substr(option[1] == 'X' ? 10 : 15));
Elliott Hughes3bb81562011-10-21 18:52:59 -0700354 if (tail == "help" || !Dbg::ParseJdwpOptions(tail)) {
355 LOG(FATAL) << "Example: -Xrunjdwp:transport=dt_socket,address=8000,server=y\n"
356 << "Example: -Xrunjdwp:transport=dt_socket,address=localhost:6500,server=n";
357 return NULL;
358 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800359 } else if (StartsWith(option, "-Xms")) {
360 size_t size = ParseMemoryOption(option.substr(strlen("-Xms")).c_str(), 1024);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700361 if (size == 0) {
362 if (ignore_unrecognized) {
363 continue;
364 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700365 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700366 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700367 return NULL;
368 }
369 parsed->heap_initial_size_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800370 } else if (StartsWith(option, "-Xmx")) {
371 size_t size = ParseMemoryOption(option.substr(strlen("-Xmx")).c_str(), 1024);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700372 if (size == 0) {
373 if (ignore_unrecognized) {
374 continue;
375 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700376 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700377 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700378 return NULL;
379 }
380 parsed->heap_maximum_size_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800381 } else if (StartsWith(option, "-XX:HeapGrowthLimit=")) {
382 size_t size = ParseMemoryOption(option.substr(strlen("-XX:HeapGrowthLimit=")).c_str(), 1024);
jeffhaoc1160702011-10-27 15:48:45 -0700383 if (size == 0) {
384 if (ignore_unrecognized) {
385 continue;
386 }
387 // TODO: usage
388 LOG(FATAL) << "Failed to parse " << option;
389 return NULL;
390 }
391 parsed->heap_growth_limit_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800392 } else if (StartsWith(option, "-Xss")) {
393 size_t size = ParseMemoryOption(option.substr(strlen("-Xss")).c_str(), 1);
Brian Carlstromf734cf52011-08-17 16:28:14 -0700394 if (size == 0) {
395 if (ignore_unrecognized) {
396 continue;
397 }
Brian Carlstrom4a289ed2011-08-16 17:17:49 -0700398 // TODO: usage
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700399 LOG(FATAL) << "Failed to parse " << option;
Brian Carlstromf734cf52011-08-17 16:28:14 -0700400 return NULL;
401 }
402 parsed->stack_size_ = size;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800403 } else if (StartsWith(option, "-D")) {
404 parsed->properties_.push_back(option.substr(strlen("-D")));
405 } else if (StartsWith(option, "-Xjnitrace:")) {
406 parsed->jni_trace_ = option.substr(strlen("-Xjnitrace:"));
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700407 } else if (option == "compiler") {
Elliott Hughesd9c67be2012-02-02 19:54:06 -0800408 parsed->is_compiler_ = true;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700409 } else if (option == "-Xzygote") {
410 parsed->is_zygote_ = true;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800411 } else if (StartsWith(option, "-verbose:")) {
Elliott Hughes0af55432011-08-17 18:37:28 -0700412 std::vector<std::string> verbose_options;
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800413 Split(option.substr(strlen("-verbose:")), ',', verbose_options);
Elliott Hughes0af55432011-08-17 18:37:28 -0700414 for (size_t i = 0; i < verbose_options.size(); ++i) {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800415 if (verbose_options[i] == "class") {
416 gLogVerbosity.class_linker = true;
417 } else if (verbose_options[i] == "compiler") {
418 gLogVerbosity.compiler = true;
419 } else if (verbose_options[i] == "heap") {
420 gLogVerbosity.heap = true;
421 } else if (verbose_options[i] == "gc") {
422 gLogVerbosity.gc = true;
423 } else if (verbose_options[i] == "jdwp") {
424 gLogVerbosity.jdwp = true;
425 } else if (verbose_options[i] == "jni") {
426 gLogVerbosity.jni = true;
427 } else if (verbose_options[i] == "monitor") {
428 gLogVerbosity.monitor = true;
429 } else if (verbose_options[i] == "startup") {
430 gLogVerbosity.startup = true;
431 } else if (verbose_options[i] == "third-party-jni") {
432 gLogVerbosity.third_party_jni = true;
433 } else if (verbose_options[i] == "threads") {
434 gLogVerbosity.threads = true;
TDYa127b92bcab2012-04-08 00:09:51 -0700435 } else if (StartsWith(verbose_options[i], "log-to=")) {
436 std::string log_file_name(verbose_options[i].substr(strlen("log-to=")));
437 std::ofstream* log_file = new std::ofstream(log_file_name.c_str());
438 if (log_file->is_open() && log_file->good()) {
439 gLogVerbosity.SetLoggingStream(log_file);
440 } else {
441 LOG(ERROR) << "Fail to open log file: \"" << log_file_name << "\","
442 << " use default logging stream.";
443 }
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800444 } else {
445 LOG(WARNING) << "Ignoring unknown -verbose option: " << verbose_options[i];
446 }
Elliott Hughes0af55432011-08-17 18:37:28 -0700447 }
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800448 } else if (StartsWith(option, "-Xjnigreflimit:")) {
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700449 parsed->jni_globals_max_ = ParseIntegerOrDie(option);
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800450 } else if (StartsWith(option, "-Xlockprofthreshold:")) {
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700451 parsed->lock_profiling_threshold_ = ParseIntegerOrDie(option);
Elliott Hughesf1a5adc2012-02-10 18:09:35 -0800452 } else if (StartsWith(option, "-Xstacktracefile:")) {
Elliott Hughes67d92002012-03-26 15:08:51 -0700453 if (kIsDebugBuild) {
454 // Ignore the zygote and always show stack traces in debug builds.
455 } else {
456 parsed->stack_trace_file_ = option.substr(strlen("-Xstacktracefile:"));
457 }
Elliott Hughesfc861622011-10-17 17:57:47 -0700458 } else if (option == "sensitiveThread") {
459 parsed->hook_is_sensitive_thread_ = reinterpret_cast<bool (*)()>(options[i].second);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700460 } else if (option == "vfprintf") {
461 parsed->hook_vfprintf_ = reinterpret_cast<int (*)(FILE *, const char*, va_list)>(options[i].second);
462 } else if (option == "exit") {
463 parsed->hook_exit_ = reinterpret_cast<void(*)(jint)>(options[i].second);
464 } else if (option == "abort") {
465 parsed->hook_abort_ = reinterpret_cast<void(*)()>(options[i].second);
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700466 } else if (option == "host-prefix") {
467 parsed->host_prefix_ = reinterpret_cast<const char*>(options[i].second);
Elliott Hughesb3e66df2012-01-12 14:49:18 -0800468 } else if (option == "-Xgenregmap" || option == "-Xgc:precise") {
469 // We silently ignore these for backwards compatibility.
jeffhaob5e81852012-03-12 11:15:45 -0700470 } else if (option == "-Xmethod-trace") {
471 parsed->method_trace_ = true;
472 } else if (StartsWith(option, "-Xmethod-trace-file:")) {
473 parsed->method_trace_file_ = option.substr(strlen("-Xmethod-trace-file:"));
474 } else if (StartsWith(option, "-Xmethod-trace-file-size:")) {
475 parsed->method_trace_file_size_ = ParseIntegerOrDie(option);
Brian Carlstrom8a436592011-08-15 21:27:23 -0700476 } else {
477 if (!ignore_unrecognized) {
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700478 // TODO: print usage via vfprintf
Brian Carlstrom27ec9612011-09-19 20:20:38 -0700479 LOG(ERROR) << "Unrecognized option " << option;
480 // TODO: this should exit, but for now tolerate unknown options
481 //return NULL;
Brian Carlstrom8a436592011-08-15 21:27:23 -0700482 }
483 }
484 }
485
Brian Carlstrom223f20f2012-02-04 23:06:55 -0800486 if (!parsed->is_compiler_ && parsed->image_.empty()) {
487 parsed->image_ += GetAndroidRoot();
488 parsed->image_ += "/framework/boot.art";
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700489 }
jeffhaoc1160702011-10-27 15:48:45 -0700490 if (parsed->heap_growth_limit_ == 0) {
491 parsed->heap_growth_limit_ = parsed->heap_maximum_size_;
492 }
Brian Carlstrom5de8fe52011-10-16 14:10:09 -0700493
Elliott Hughescac6cc72011-11-03 20:31:21 -0700494 LOG(INFO) << "Build type: "
Elliott Hughes67d92002012-03-26 15:08:51 -0700495 << (kIsDebugBuild ? "debug" : "optimized")
Elliott Hughescac6cc72011-11-03 20:31:21 -0700496 << "; CheckJNI: " << (parsed->check_jni_ ? "on" : "off");
Elliott Hughes85d15452011-09-16 17:33:01 -0700497
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700498 return parsed.release();
Brian Carlstrom8a436592011-08-15 21:27:23 -0700499}
500
501Runtime* Runtime::Create(const Options& options, bool ignore_unrecognized) {
Carl Shapiro2ed144c2011-07-26 16:52:08 -0700502 // TODO: acquire a static mutex on Runtime to avoid racing.
503 if (Runtime::instance_ != NULL) {
504 return NULL;
505 }
Elliott Hughesdcc24742011-09-07 14:02:44 -0700506 instance_ = new Runtime;
507 if (!instance_->Init(options, ignore_unrecognized)) {
508 delete instance_;
509 instance_ = NULL;
Carl Shapiro61e019d2011-07-14 16:53:09 -0700510 }
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700511 return instance_;
512}
Elliott Hughes0af55432011-08-17 18:37:28 -0700513
Brian Carlstromaded5f72011-10-07 17:15:04 -0700514void CreateSystemClassLoader() {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800515 if (Runtime::Current()->UseCompileTimeClassPath()) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700516 return;
517 }
518
519 Thread* self = Thread::Current();
520
521 // Must be in the kNative state for calling native methods.
Elliott Hughes34e06962012-04-09 13:55:55 -0700522 CHECK_EQ(self->GetState(), kNative);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700523
524 JNIEnv* env = self->GetJniEnv();
Brian Carlstromdf143242011-10-10 18:05:34 -0700525 ScopedLocalRef<jclass> ClassLoader_class(env, env->FindClass("java/lang/ClassLoader"));
526 CHECK(ClassLoader_class.get() != NULL);
527 jmethodID getSystemClassLoader = env->GetStaticMethodID(ClassLoader_class.get(),
528 "getSystemClassLoader",
529 "()Ljava/lang/ClassLoader;");
530 CHECK(getSystemClassLoader != NULL);
531 ScopedLocalRef<jobject> class_loader(env, env->CallStaticObjectMethod(ClassLoader_class.get(),
532 getSystemClassLoader));
533 CHECK(class_loader.get() != NULL);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700534
Brian Carlstromdf143242011-10-10 18:05:34 -0700535 Thread::Current()->SetClassLoaderOverride(Decode<ClassLoader*>(env, class_loader.get()));
Jesse Wilson1b2b2f22011-11-22 11:47:44 -0500536
537 ScopedLocalRef<jclass> Thread_class(env, env->FindClass("java/lang/Thread"));
538 CHECK(Thread_class.get() != NULL);
539 jfieldID contextClassLoader = env->GetFieldID(Thread_class.get(),
540 "contextClassLoader",
541 "Ljava/lang/ClassLoader;");
542 CHECK(contextClassLoader != NULL);
543 ScopedLocalRef<jobject> self_jobject(env, AddLocalReference<jobject>(env, self->GetPeer()));
544 env->SetObjectField(self_jobject.get(), contextClassLoader, class_loader.get());
Brian Carlstromaded5f72011-10-07 17:15:04 -0700545}
546
Brian Carlstrom69b15fb2011-09-03 12:25:21 -0700547void Runtime::Start() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800548 VLOG(startup) << "Runtime::Start entering";
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700549
550 CHECK(host_prefix_.empty()) << host_prefix_;
551
Logan Chien0c717dd2012-03-28 18:31:07 +0800552 // Relocate the OatFiles (ELF images)
553 class_linker_->RelocateExecutable();
554
Brian Carlstromf28bc5b2011-10-26 01:15:03 -0700555 // Restore main thread state to kNative as expected by native code
Elliott Hughes34e06962012-04-09 13:55:55 -0700556 Thread::Current()->SetState(kNative);
Brian Carlstromf28bc5b2011-10-26 01:15:03 -0700557
Brian Carlstrom5d40f182011-09-26 22:29:18 -0700558 started_ = true;
559
Brian Carlstromae826982011-11-09 01:33:42 -0800560 // InitNativeMethods needs to be after started_ so that the classes
561 // it touches will have methods linked to the oat file if necessary.
562 InitNativeMethods();
563
Jesse Wilson9a6bae82011-11-14 14:57:30 -0500564 Thread::FinishStartup();
565
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700566 if (!is_zygote_) {
567 DidForkFromZygote();
568 }
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700569
Elliott Hughes85d15452011-09-16 17:33:01 -0700570 StartDaemonThreads();
Brian Carlstrom0a5b14d2011-09-27 13:29:15 -0700571
Brian Carlstromaded5f72011-10-07 17:15:04 -0700572 CreateSystemClassLoader();
573
Elliott Hughes726079d2011-10-07 18:43:44 -0700574 Thread::Current()->GetJniEnv()->locals.AssertEmpty();
575
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800576 VLOG(startup) << "Runtime::Start exiting";
Elliott Hughes85d15452011-09-16 17:33:01 -0700577}
578
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700579void Runtime::DidForkFromZygote() {
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700580 is_zygote_ = false;
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700581
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700582 StartSignalCatcher();
Elliott Hughesd1cc8362011-10-24 16:58:50 -0700583
584 // Start the JDWP thread. If the command-line debugger flags specified "suspend=y",
585 // this will pause the runtime, so we probably want this to come last.
586 Dbg::StartJdwp();
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700587}
588
589void Runtime::StartSignalCatcher() {
590 if (!is_zygote_) {
Elliott Hughes94ce37a2011-10-18 15:07:48 -0700591 signal_catcher_ = new SignalCatcher(stack_trace_file_);
Brian Carlstromcaabb1b2011-10-11 18:09:13 -0700592 }
593}
594
Elliott Hughes85d15452011-09-16 17:33:01 -0700595void Runtime::StartDaemonThreads() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800596 VLOG(startup) << "Runtime::StartDaemonThreads entering";
Elliott Hughes85d15452011-09-16 17:33:01 -0700597
Elliott Hughes719b3232011-09-25 17:42:19 -0700598 Thread* self = Thread::Current();
Brian Carlstromaded5f72011-10-07 17:15:04 -0700599
600 // Must be in the kNative state for calling native methods.
Elliott Hughes34e06962012-04-09 13:55:55 -0700601 CHECK_EQ(self->GetState(), kNative);
Brian Carlstromaded5f72011-10-07 17:15:04 -0700602
Elliott Hughes719b3232011-09-25 17:42:19 -0700603 JNIEnv* env = self->GetJniEnv();
Elliott Hughes726079d2011-10-07 18:43:44 -0700604 ScopedLocalRef<jclass> c(env, env->FindClass("java/lang/Daemons"));
605 CHECK(c.get() != NULL);
606 jmethodID mid = env->GetStaticMethodID(c.get(), "start", "()V");
Elliott Hughes719b3232011-09-25 17:42:19 -0700607 CHECK(mid != NULL);
Elliott Hughes726079d2011-10-07 18:43:44 -0700608 env->CallStaticVoidMethod(c.get(), mid);
Elliott Hughes8cf5bc02012-02-02 16:32:16 -0800609 CHECK(!env->ExceptionCheck());
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700610
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800611 VLOG(startup) << "Runtime::StartDaemonThreads exiting";
Carl Shapiro61e019d2011-07-14 16:53:09 -0700612}
613
Elliott Hughes6b355752012-01-13 16:49:08 -0800614bool Runtime::IsShuttingDown() const {
615 return shutting_down_;
616}
617
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700618bool Runtime::IsStarted() const {
Elliott Hughesdcc24742011-09-07 14:02:44 -0700619 return started_;
620}
621
Elliott Hughes0af55432011-08-17 18:37:28 -0700622bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700623 CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700624
Elliott Hughes90a33692011-08-30 13:27:07 -0700625 UniquePtr<ParsedOptions> options(ParsedOptions::Create(raw_options, ignore_unrecognized));
626 if (options.get() == NULL) {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700627 LOG(ERROR) << "Failed to parse options";
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700628 return false;
629 }
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800630 VLOG(startup) << "Runtime::Init -verbose:startup enabled";
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700631
Elliott Hughesbb1e8f02011-10-18 14:14:25 -0700632 SetJniGlobalsMax(options->jni_globals_max_);
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800633 Monitor::Init(options->lock_profiling_threshold_, options->hook_is_sensitive_thread_);
Elliott Hughes32d6e1e2011-10-11 14:47:44 -0700634
Brian Carlstrom58ae9412011-10-04 00:56:06 -0700635 host_prefix_ = options->host_prefix_;
Brian Carlstroma004aa92012-02-08 18:05:09 -0800636 boot_class_path_string_ = options->boot_class_path_string_;
637 class_path_string_ = options->class_path_string_;
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700638 properties_ = options->properties_;
639
Elliott Hughesd9c67be2012-02-02 19:54:06 -0800640 is_compiler_ = options->is_compiler_;
Elliott Hughes9ca7a1f2011-10-11 14:29:52 -0700641 is_zygote_ = options->is_zygote_;
642
Elliott Hughes0af55432011-08-17 18:37:28 -0700643 vfprintf_ = options->hook_vfprintf_;
644 exit_ = options->hook_exit_;
645 abort_ = options->hook_abort_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700646
Elliott Hughesbe759c62011-09-08 19:38:21 -0700647 default_stack_size_ = options->stack_size_;
Elliott Hughes94ce37a2011-10-18 15:07:48 -0700648 stack_trace_file_ = options->stack_trace_file_;
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700649
Elliott Hughesc33a32b2011-10-11 18:18:07 -0700650 monitor_list_ = new MonitorList;
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800651 thread_list_ = new ThreadList;
Elliott Hughescf4c6c42011-09-01 15:16:42 -0700652 intern_table_ = new InternTable;
653
Ian Rogers776ac1f2012-04-13 23:36:36 -0700654 verifier::MethodVerifier::InitGcMaps();
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800655
Logan Chiendd361c92012-04-10 23:40:37 +0800656#if defined(ART_USE_LLVM_COMPILER)
Ian Rogers776ac1f2012-04-13 23:36:36 -0700657 verifier::MethodVerifier::InitInferredRegCategoryMaps();
Logan Chiendd361c92012-04-10 23:40:37 +0800658#endif
659
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800660 heap_ = new Heap(options->heap_initial_size_,
661 options->heap_growth_limit_,
662 options->heap_maximum_size_,
663 options->image_);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700664
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700665 BlockSignals();
Elliott Hughes457005c2012-04-16 13:54:25 -0700666 InitPlatformSignalHandlers();
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700667
Elliott Hughesa0957642011-09-02 14:27:33 -0700668 java_vm_ = new JavaVMExt(this, options.get());
Elliott Hughes515a5bc2011-08-17 11:08:34 -0700669
Elliott Hughesbe759c62011-09-08 19:38:21 -0700670 Thread::Startup();
Elliott Hughesd92bec42011-09-02 17:04:36 -0700671
Elliott Hughes5fe594f2011-09-08 12:33:17 -0700672 // ClassLinker needs an attached thread, but we can't fully attach a thread
Elliott Hughes462c9442012-03-23 18:47:50 -0700673 // without creating objects. We can't supply a thread group yet; it will be fixed later.
674 Thread::Attach("main", false, NULL);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700675
Brian Carlstromf28bc5b2011-10-26 01:15:03 -0700676 // Set us to runnable so tools using a runtime can allocate and GC by default
Elliott Hughes34e06962012-04-09 13:55:55 -0700677 Thread::Current()->SetState(kRunnable);
Brian Carlstromf28bc5b2011-10-26 01:15:03 -0700678
Ian Rogers141d6222012-04-05 12:23:06 -0700679 // Now we're attached, we can take the heap lock and validate the heap.
680 GetHeap()->EnableObjectValidation();
681
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800682 CHECK_GE(GetHeap()->GetSpaces().size(), 1U);
683 if (GetHeap()->GetSpaces()[0]->IsImageSpace()) {
Brian Carlstroma004aa92012-02-08 18:05:09 -0800684 class_linker_ = ClassLinker::CreateFromImage(intern_table_);
685 } else {
686 CHECK(options->boot_class_path_ != NULL);
687 CHECK_NE(options->boot_class_path_->size(), 0U);
688 class_linker_ = ClassLinker::CreateFromCompiler(*options->boot_class_path_, intern_table_);
689 }
690 CHECK(class_linker_ != NULL);
Brian Carlstrom6ea095a2011-08-16 15:26:54 -0700691
jeffhaob5e81852012-03-12 11:15:45 -0700692 method_trace_ = options->method_trace_;
693 method_trace_file_ = options->method_trace_file_;
694 method_trace_file_size_ = options->method_trace_file_size_;
695
696 if (options->method_trace_) {
697 Trace::Start(options->method_trace_file_.c_str(), -1, options->method_trace_file_size_, 0, false);
698 }
699
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800700 VLOG(startup) << "Runtime::Init exiting";
Carl Shapiro1fb86202011-06-27 17:43:13 -0700701 return true;
702}
703
Elliott Hughes038a8062011-09-18 14:12:41 -0700704void Runtime::InitNativeMethods() {
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800705 VLOG(startup) << "Runtime::InitNativeMethods entering";
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700706 Thread* self = Thread::Current();
707 JNIEnv* env = self->GetJniEnv();
708
Elliott Hughes418d20f2011-09-22 14:00:39 -0700709 // Must be in the kNative state for calling native methods (JNI_OnLoad code).
Elliott Hughes34e06962012-04-09 13:55:55 -0700710 CHECK_EQ(self->GetState(), kNative);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700711
Elliott Hughes418d20f2011-09-22 14:00:39 -0700712 // First set up JniConstants, which is used by both the runtime's built-in native
713 // methods and libcore.
Elliott Hughesfea966e2011-09-22 10:26:20 -0700714 JniConstants::init(env);
715
Elliott Hughes418d20f2011-09-22 14:00:39 -0700716 // Then set up the native methods provided by the runtime itself.
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700717 RegisterRuntimeNativeMethods(env);
718
Elliott Hughes418d20f2011-09-22 14:00:39 -0700719 // Then set up libcore, which is just a regular JNI library with a regular JNI_OnLoad.
720 // Most JNI libraries can just use System.loadLibrary, but libcore can't because it's
721 // the library that implements System.loadLibrary!
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700722 LoadJniLibrary(instance_->GetJavaVM(), "javacore");
Elliott Hughes4dd9b4d2011-12-12 18:29:24 -0800723 VLOG(startup) << "Runtime::InitNativeMethods exiting";
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700724}
725
726void Runtime::RegisterRuntimeNativeMethods(JNIEnv* env) {
727#define REGISTER(FN) extern void FN(JNIEnv*); FN(env)
Ian Rogers5167c972012-02-03 10:41:20 -0800728 // Register Throwable first so that registration of other native methods can throw exceptions
729 REGISTER(register_java_lang_Throwable);
Brian Carlstromf91c8c32011-09-21 17:30:34 -0700730 REGISTER(register_dalvik_system_DexFile);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700731 REGISTER(register_dalvik_system_VMDebug);
Elliott Hughes7ede61e2011-09-14 18:18:06 -0700732 REGISTER(register_dalvik_system_VMRuntime);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700733 REGISTER(register_dalvik_system_VMStack);
Elliott Hughes01158d72011-09-19 19:47:10 -0700734 REGISTER(register_dalvik_system_Zygote);
Elliott Hughesd369bb72011-09-12 14:41:14 -0700735 REGISTER(register_java_lang_Class);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700736 REGISTER(register_java_lang_Object);
737 REGISTER(register_java_lang_Runtime);
738 REGISTER(register_java_lang_String);
739 REGISTER(register_java_lang_System);
Elliott Hughes8daa0922011-09-11 13:46:25 -0700740 REGISTER(register_java_lang_Thread);
Elliott Hughes64bf5a32011-09-20 14:43:12 -0700741 REGISTER(register_java_lang_VMClassLoader);
Brian Carlstrom5b8e4c82011-09-18 01:38:59 -0700742 REGISTER(register_java_lang_reflect_Array);
Elliott Hughes2a20cfd2011-09-23 19:30:41 -0700743 REGISTER(register_java_lang_reflect_Constructor);
Brian Carlstromf867b6f2011-09-16 12:17:25 -0700744 REGISTER(register_java_lang_reflect_Field);
745 REGISTER(register_java_lang_reflect_Method);
Jesse Wilson95caa792011-10-12 18:14:17 -0400746 REGISTER(register_java_lang_reflect_Proxy);
Elliott Hughesbf86d042011-08-31 17:53:14 -0700747 REGISTER(register_java_util_concurrent_atomic_AtomicLong);
Brian Carlstrom395520e2011-09-25 19:35:00 -0700748 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmServer);
Elliott Hughesf6a1e1e2011-10-25 16:28:04 -0700749 REGISTER(register_org_apache_harmony_dalvik_ddmc_DdmVmInternal);
Elliott Hughes5ee7a8b2011-09-13 16:40:07 -0700750 REGISTER(register_sun_misc_Unsafe);
Elliott Hughesad7c2a32011-08-31 11:58:10 -0700751#undef REGISTER
752}
753
Elliott Hughesc967f782012-04-16 10:23:15 -0700754void Runtime::DumpForSigQuit(std::ostream& os) {
Elliott Hughescac6cc72011-11-03 20:31:21 -0700755 GetClassLinker()->DumpForSigQuit(os);
756 GetInternTable()->DumpForSigQuit(os);
Elliott Hughesc967f782012-04-16 10:23:15 -0700757 GetHeap()->DumpForSigQuit(os);
Elliott Hughes42ee1422011-09-06 12:33:32 -0700758 os << "\n";
Elliott Hughes8daa0922011-09-11 13:46:25 -0700759
Elliott Hughesc967f782012-04-16 10:23:15 -0700760 thread_list_->DumpForSigQuit(os);
Elliott Hughese27955c2011-08-26 15:21:24 -0700761}
762
Elliott Hughes21a5bf22011-12-07 14:35:20 -0800763void Runtime::DumpLockHolders(std::ostream& os) {
Elliott Hughesb3bd5f02012-03-08 21:05:27 -0800764 pid_t heap_lock_owner = GetHeap()->GetLockOwner();
Elliott Hughes21a5bf22011-12-07 14:35:20 -0800765 pid_t thread_list_lock_owner = GetThreadList()->GetLockOwner();
766 pid_t classes_lock_owner = GetClassLinker()->GetClassesLockOwner();
767 pid_t dex_lock_owner = GetClassLinker()->GetDexLockOwner();
768 if ((heap_lock_owner | thread_list_lock_owner | classes_lock_owner | dex_lock_owner) != 0) {
769 os << "Heap lock owner tid: " << heap_lock_owner << "\n"
770 << "ThreadList lock owner tid: " << thread_list_lock_owner << "\n"
771 << "ClassLinker classes lock owner tid: " << classes_lock_owner << "\n"
772 << "ClassLinker dex lock owner tid: " << dex_lock_owner << "\n";
773 }
774}
775
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700776void Runtime::SetStatsEnabled(bool new_state) {
777 if (new_state == true) {
778 GetStats()->Clear(~0);
779 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
780 Thread::Current()->GetStats()->Clear(~0);
781 }
782 stats_enabled_ = new_state;
783}
784
785void Runtime::ResetStats(int kinds) {
786 GetStats()->Clear(kinds & 0xffff);
787 // TODO: wouldn't it make more sense to clear _all_ threads' stats?
788 Thread::Current()->GetStats()->Clear(kinds >> 16);
789}
790
791RuntimeStats* Runtime::GetStats() {
792 return &stats_;
793}
794
795int32_t Runtime::GetStat(int kind) {
796 RuntimeStats* stats;
797 if (kind < (1<<16)) {
798 stats = GetStats();
799 } else {
800 stats = Thread::Current()->GetStats();
801 kind >>= 16;
802 }
803 switch (kind) {
804 case KIND_ALLOCATED_OBJECTS:
805 return stats->allocated_objects;
806 case KIND_ALLOCATED_BYTES:
807 return stats->allocated_bytes;
808 case KIND_FREED_OBJECTS:
809 return stats->freed_objects;
810 case KIND_FREED_BYTES:
811 return stats->freed_bytes;
812 case KIND_GC_INVOCATIONS:
813 return stats->gc_for_alloc_count;
814 case KIND_CLASS_INIT_COUNT:
815 return stats->class_init_count;
816 case KIND_CLASS_INIT_TIME:
817 // Convert ns to us, reduce to 32 bits.
Elliott Hughes398f64b2012-03-26 18:05:48 -0700818 return static_cast<int>(stats->class_init_time_ns / 1000);
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700819 case KIND_EXT_ALLOCATED_OBJECTS:
820 case KIND_EXT_ALLOCATED_BYTES:
821 case KIND_EXT_FREED_OBJECTS:
822 case KIND_EXT_FREED_BYTES:
823 return 0; // backward compatibility
824 default:
Elliott Hughes7b9d9962012-04-20 18:48:18 -0700825 LOG(FATAL) << "Unknown statistic " << kind;
Elliott Hughes9d5ccec2011-09-19 13:19:50 -0700826 return -1; // unreachable
827 }
828}
829
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700830void Runtime::BlockSignals() {
Elliott Hughes457005c2012-04-16 13:54:25 -0700831 SignalSet signals;
832 signals.Add(SIGPIPE);
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700833 // SIGQUIT is used to dump the runtime's state (including stack traces).
Elliott Hughes457005c2012-04-16 13:54:25 -0700834 signals.Add(SIGQUIT);
Elliott Hughes08795042012-04-03 14:48:52 -0700835 // SIGUSR1 is used to initiate a GC.
Elliott Hughes457005c2012-04-16 13:54:25 -0700836 signals.Add(SIGUSR1);
837 signals.Block();
Elliott Hughesc1674ed2011-08-25 18:09:09 -0700838}
839
Elliott Hughes462c9442012-03-23 18:47:50 -0700840void Runtime::AttachCurrentThread(const char* thread_name, bool as_daemon, Object* thread_group) {
841 Thread::Attach(thread_name, as_daemon, thread_group);
Elliott Hughes22869a92012-03-27 14:08:24 -0700842 if (thread_name == NULL) {
843 LOG(WARNING) << *Thread::Current() << " attached without supplying a name";
844 }
Carl Shapiro61e019d2011-07-14 16:53:09 -0700845}
846
Elliott Hughesd92bec42011-09-02 17:04:36 -0700847void Runtime::DetachCurrentThread() {
Elliott Hughes22869a92012-03-27 14:08:24 -0700848 if (Thread::Current()->GetTopOfStack().GetSP() != NULL) {
849 LOG(FATAL) << *Thread::Current() << " attempting to detach while still running code";
850 }
Elliott Hughes02b48d12011-09-07 17:15:51 -0700851 thread_list_->Unregister();
Carl Shapiro1fb86202011-06-27 17:43:13 -0700852}
853
Brian Carlstrome24fa612011-09-29 00:53:55 -0700854void Runtime::VisitRoots(Heap::RootVisitor* visitor, void* arg) const {
Elliott Hughesbfe487b2011-10-26 15:48:55 -0700855 Dbg::VisitRoots(visitor, arg);
Brian Carlstrome24fa612011-09-29 00:53:55 -0700856 class_linker_->VisitRoots(visitor, arg);
857 intern_table_->VisitRoots(visitor, arg);
858 java_vm_->VisitRoots(visitor, arg);
859 thread_list_->VisitRoots(visitor, arg);
860 visitor(jni_stub_array_, arg);
861 visitor(abstract_method_error_stub_array_, arg);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700862 for (int i = 0; i < Runtime::kLastTrampolineMethodType; i++) {
863 visitor(resolution_stub_array_[i], arg);
864 }
Ian Rogers19846512012-02-24 11:42:47 -0800865 visitor(resolution_method_, arg);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700866 for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) {
867 visitor(callee_save_method_[i], arg);
868 }
Brian Carlstrome24fa612011-09-29 00:53:55 -0700869}
870
Ian Rogers169c9a72011-11-13 20:13:17 -0800871bool Runtime::HasJniDlsymLookupStub() const {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700872 return jni_stub_array_ != NULL;
873}
874
Ian Rogers169c9a72011-11-13 20:13:17 -0800875ByteArray* Runtime::GetJniDlsymLookupStub() const {
Brian Carlstrome24fa612011-09-29 00:53:55 -0700876 CHECK(jni_stub_array_ != NULL);
877 return jni_stub_array_;
878}
879
Ian Rogers169c9a72011-11-13 20:13:17 -0800880void Runtime::SetJniDlsymLookupStub(ByteArray* jni_stub_array) {
Brian Carlstromaded5f72011-10-07 17:15:04 -0700881 CHECK(jni_stub_array != NULL) << " jni_stub_array=" << jni_stub_array;
882 CHECK(jni_stub_array_ == NULL || jni_stub_array_ == jni_stub_array)
883 << "jni_stub_array_=" << jni_stub_array_ << " jni_stub_array=" << jni_stub_array;
Brian Carlstrome24fa612011-09-29 00:53:55 -0700884 jni_stub_array_ = jni_stub_array;
885}
886
887bool Runtime::HasAbstractMethodErrorStubArray() const {
888 return abstract_method_error_stub_array_ != NULL;
889}
890
891ByteArray* Runtime::GetAbstractMethodErrorStubArray() const {
892 CHECK(abstract_method_error_stub_array_ != NULL);
893 return abstract_method_error_stub_array_;
894}
895
896void Runtime::SetAbstractMethodErrorStubArray(ByteArray* abstract_method_error_stub_array) {
897 CHECK(abstract_method_error_stub_array != NULL);
898 CHECK(abstract_method_error_stub_array_ == NULL || abstract_method_error_stub_array_ == abstract_method_error_stub_array);
899 abstract_method_error_stub_array_ = abstract_method_error_stub_array;
900}
901
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700902
903Runtime::TrampolineType Runtime::GetTrampolineType(Method* method) {
904 if (method == NULL) {
905 return Runtime::kUnknownMethod;
906 } else if (method->IsStatic()) {
907 return Runtime::kStaticMethod;
908 } else {
Ian Rogersfb6adba2012-03-04 21:51:51 -0800909 return Runtime::kUnknownMethod;
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700910 }
Ian Rogersad25ac52011-10-04 19:13:33 -0700911}
912
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700913bool Runtime::HasResolutionStubArray(TrampolineType type) const {
914 return resolution_stub_array_[type] != NULL;
Ian Rogersad25ac52011-10-04 19:13:33 -0700915}
916
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700917ByteArray* Runtime::GetResolutionStubArray(TrampolineType type) const {
918 CHECK(HasResolutionStubArray(type));
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700919 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastTrampolineMethodType));
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700920 return resolution_stub_array_[type];
921}
922
923void Runtime::SetResolutionStubArray(ByteArray* resolution_stub_array, TrampolineType type) {
Ian Rogersad25ac52011-10-04 19:13:33 -0700924 CHECK(resolution_stub_array != NULL);
Ian Rogers1cb0a1d2011-10-06 15:24:35 -0700925 CHECK(!HasResolutionStubArray(type) || resolution_stub_array_[type] == resolution_stub_array);
926 resolution_stub_array_[type] = resolution_stub_array;
Ian Rogersad25ac52011-10-04 19:13:33 -0700927}
928
Ian Rogers19846512012-02-24 11:42:47 -0800929Method* Runtime::CreateResolutionMethod() {
930 Class* method_class = Method::GetMethodClass();
931 SirtRef<Method> method(down_cast<Method*>(method_class->AllocObject()));
932 method->SetDeclaringClass(method_class);
933 // TODO: use a special method for resolution method saves
934 method->SetDexMethodIndex(DexFile::kDexNoIndex16);
935 ByteArray* unknown_resolution_stub = GetResolutionStubArray(kUnknownMethod);
936 CHECK(unknown_resolution_stub != NULL);
937 method->SetCode(unknown_resolution_stub->GetData());
938 return method.get();
939}
940
941bool Runtime::HasResolutionMethod() const {
942 return resolution_method_ != NULL;
943}
944
945// Returns a special method that calls into a trampoline for runtime method resolution
946Method* Runtime::GetResolutionMethod() const {
947 CHECK(HasResolutionMethod());
948 return resolution_method_;
949}
950
951void Runtime::SetResolutionMethod(Method* method) {
952 resolution_method_ = method;
953}
954
Brian Carlstromae826982011-11-09 01:33:42 -0800955Method* Runtime::CreateCalleeSaveMethod(InstructionSet instruction_set, CalleeSaveType type) {
Ian Rogersff1ed472011-09-20 13:46:24 -0700956 Class* method_class = Method::GetMethodClass();
Brian Carlstrom40381fb2011-10-19 14:13:40 -0700957 SirtRef<Method> method(down_cast<Method*>(method_class->AllocObject()));
Ian Rogersff1ed472011-09-20 13:46:24 -0700958 method->SetDeclaringClass(method_class);
Ian Rogers6d4d9fc2011-11-30 16:24:48 -0800959 // TODO: use a special method for callee saves
Ian Rogers19846512012-02-24 11:42:47 -0800960 method->SetDexMethodIndex(DexFile::kDexNoIndex16);
Brian Carlstrom3320cf42011-10-04 14:58:28 -0700961 method->SetCode(NULL);
Brian Carlstromae826982011-11-09 01:33:42 -0800962 if ((instruction_set == kThumb2) || (instruction_set == kArm)) {
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700963 uint32_t ref_spills = (1 << art::arm::R5) | (1 << art::arm::R6) | (1 << art::arm::R7) |
964 (1 << art::arm::R8) | (1 << art::arm::R10) | (1 << art::arm::R11);
965 uint32_t arg_spills = (1 << art::arm::R1) | (1 << art::arm::R2) | (1 << art::arm::R3);
966 uint32_t all_spills = (1 << art::arm::R4) | (1 << art::arm::R9);
967 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills :0) |
968 (type == kSaveAll ? all_spills :0) | (1 << art::arm::LR);
969 uint32_t fp_all_spills = (1 << art::arm::S0) | (1 << art::arm::S1) | (1 << art::arm::S2) |
970 (1 << art::arm::S3) | (1 << art::arm::S4) | (1 << art::arm::S5) |
971 (1 << art::arm::S6) | (1 << art::arm::S7) | (1 << art::arm::S8) |
972 (1 << art::arm::S9) | (1 << art::arm::S10) | (1 << art::arm::S11) |
973 (1 << art::arm::S12) | (1 << art::arm::S13) | (1 << art::arm::S14) |
974 (1 << art::arm::S15) | (1 << art::arm::S16) | (1 << art::arm::S17) |
975 (1 << art::arm::S18) | (1 << art::arm::S19) | (1 << art::arm::S20) |
976 (1 << art::arm::S21) | (1 << art::arm::S22) | (1 << art::arm::S23) |
977 (1 << art::arm::S24) | (1 << art::arm::S25) | (1 << art::arm::S26) |
978 (1 << art::arm::S27) | (1 << art::arm::S28) | (1 << art::arm::S29) |
979 (1 << art::arm::S30) | (1 << art::arm::S31);
980 uint32_t fp_spills = type == kSaveAll ? fp_all_spills : 0;
981 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
982 __builtin_popcount(fp_spills) /* fprs */ +
983 1 /* Method* */) * kPointerSize, kStackAlignment);
Ian Rogers15fdb8c2011-09-25 15:45:07 -0700984 method->SetFrameSizeInBytes(frame_size);
Ian Rogers4f0d07c2011-10-06 23:38:47 -0700985 method->SetCoreSpillMask(core_spills);
986 method->SetFpSpillMask(fp_spills);
Brian Carlstromae826982011-11-09 01:33:42 -0800987 } else if (instruction_set == kX86) {
Ian Rogers7caad772012-03-30 01:07:54 -0700988 uint32_t ref_spills = (1 << art::x86::EBP) | (1 << art::x86::ESI) | (1 << art::x86::EDI);
989 uint32_t arg_spills = (1 << art::x86::ECX) | (1 << art::x86::EDX) | (1 << art::x86::EBX);
990 uint32_t core_spills = ref_spills | (type == kRefsAndArgs ? arg_spills : 0) |
991 (1 << art::x86::kNumberOfCpuRegisters); // fake return address callee save
992 size_t frame_size = RoundUp((__builtin_popcount(core_spills) /* gprs */ +
993 1 /* Method* */) * kPointerSize, kStackAlignment);
994 method->SetFrameSizeInBytes(frame_size);
995 method->SetCoreSpillMask(core_spills);
Ian Rogersff1ed472011-09-20 13:46:24 -0700996 method->SetFpSpillMask(0);
997 } else {
998 UNIMPLEMENTED(FATAL);
999 }
Brian Carlstrom40381fb2011-10-19 14:13:40 -07001000 return method.get();
Ian Rogersff1ed472011-09-20 13:46:24 -07001001}
1002
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001003bool Runtime::HasCalleeSaveMethod(CalleeSaveType type) const {
1004 return callee_save_method_[type] != NULL;
Brian Carlstrom1f870082011-08-23 16:02:11 -07001005}
1006
Brian Carlstrome24fa612011-09-29 00:53:55 -07001007// Returns a special method that describes all callee saves being spilled to the stack.
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001008Method* Runtime::GetCalleeSaveMethod(CalleeSaveType type) const {
1009 CHECK(HasCalleeSaveMethod(type));
1010 return callee_save_method_[type];
Brian Carlstrome24fa612011-09-29 00:53:55 -07001011}
1012
Ian Rogers4f0d07c2011-10-06 23:38:47 -07001013void Runtime::SetCalleeSaveMethod(Method* method, CalleeSaveType type) {
1014 DCHECK_LT(static_cast<int>(type), static_cast<int>(kLastCalleeSaveType));
1015 callee_save_method_[type] = method;
Brian Carlstrome24fa612011-09-29 00:53:55 -07001016}
1017
jeffhao2692b572011-12-16 15:42:28 -08001018void Runtime::EnableMethodTracing(Trace* tracer) {
1019 CHECK(!IsMethodTracingActive());
1020 tracer_ = tracer;
1021}
1022
1023void Runtime::DisableMethodTracing() {
1024 CHECK(IsMethodTracingActive());
1025 delete tracer_;
1026 tracer_ = NULL;
1027}
1028
1029bool Runtime::IsMethodTracingActive() const {
1030 return (tracer_ != NULL);
1031}
1032
1033Trace* Runtime::GetTracer() const {
1034 CHECK(IsMethodTracingActive());
1035 return tracer_;
1036}
1037
Elliott Hughesb3bd5f02012-03-08 21:05:27 -08001038const std::vector<const DexFile*>& Runtime::GetCompileTimeClassPath(const ClassLoader* class_loader) {
1039 if (class_loader == NULL) {
1040 return GetClassLinker()->GetBootClassPath();
1041 }
1042 CHECK(UseCompileTimeClassPath());
1043 CompileTimeClassPaths::const_iterator it = compile_time_class_paths_.find(class_loader);
1044 CHECK(it != compile_time_class_paths_.end());
1045 return it->second;
1046}
1047
1048void Runtime::SetCompileTimeClassPath(const ClassLoader* class_loader, std::vector<const DexFile*>& class_path) {
1049 CHECK(!IsStarted());
1050 use_compile_time_class_path_ = true;
Elliott Hughesa0e18062012-04-13 15:59:59 -07001051 compile_time_class_paths_.Put(class_loader, class_path);
Elliott Hughesb3bd5f02012-03-08 21:05:27 -08001052}
1053
Carl Shapiro1fb86202011-06-27 17:43:13 -07001054} // namespace art