A little bit more of the threads implementation.
The most important change here is understanding that Thread's id_ field
was unrelated to java.lang.Thread's id field.
Change-Id: I832b92145332e1ded63a7824033dae684eeacf28
diff --git a/src/runtime.cc b/src/runtime.cc
index 2c2c5e2..c8f9036 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -22,6 +22,19 @@
Runtime* Runtime::instance_ = NULL;
+Runtime::Runtime()
+ : stack_size_(0),
+ thread_list_(NULL),
+ intern_table_(NULL),
+ class_linker_(NULL),
+ signal_catcher_(NULL),
+ java_vm_(NULL),
+ started_(false),
+ vfprintf_(NULL),
+ exit_(NULL),
+ abort_(NULL) {
+}
+
Runtime::~Runtime() {
// TODO: use smart pointers instead. (we'll need the pimpl idiom.)
delete class_linker_;
@@ -313,20 +326,24 @@
if (Runtime::instance_ != NULL) {
return NULL;
}
- UniquePtr<Runtime> runtime(new Runtime());
- bool success = runtime->Init(options, ignore_unrecognized);
- if (!success) {
- return NULL;
+ instance_ = new Runtime;
+ if (!instance_->Init(options, ignore_unrecognized)) {
+ delete instance_;
+ instance_ = NULL;
}
- instance_ = runtime.release();
return instance_;
}
void Runtime::Start() {
+ started_ = true;
instance_->InitLibraries();
instance_->signal_catcher_ = new SignalCatcher;
}
+bool Runtime::IsStarted() {
+ return started_;
+}
+
bool Runtime::Init(const Options& raw_options, bool ignore_unrecognized) {
CHECK_EQ(sysconf(_SC_PAGE_SIZE), kPageSize);
@@ -361,7 +378,7 @@
return false;
}
- thread_list_->Register(Thread::Attach(this));
+ thread_list_->Register(Thread::Attach(this, "main", false));
class_linker_ = ClassLinker::Create(options->boot_class_path_,
options->class_path_,
@@ -450,10 +467,7 @@
}
void Runtime::AttachCurrentThread(const char* name, JNIEnv** penv, bool as_daemon) {
- if (as_daemon) {
- UNIMPLEMENTED(WARNING) << "TODO: do something different for daemon threads";
- }
- Thread* t = Thread::Attach(instance_);
+ Thread* t = Thread::Attach(instance_, name, as_daemon);
thread_list_->Register(t);
}