Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 1 | // Copyright 2011 Google Inc. All Rights Reserved. |
| 2 | |
| 3 | #include "class_loader.h" |
| 4 | |
| 5 | #include "class_linker.h" |
| 6 | #include "runtime.h" |
| 7 | |
| 8 | namespace art { |
| 9 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 10 | bool ClassLoader::use_compile_time_class_path = false; |
| 11 | ClassLoader::Table ClassLoader::compile_time_class_paths_; |
| 12 | |
| 13 | const std::vector<const DexFile*>& ClassLoader::GetCompileTimeClassPath(const ClassLoader* class_loader) { |
| 14 | Runtime* runtime = Runtime::Current(); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 15 | if (class_loader == NULL) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 16 | return runtime->GetClassLinker()->GetBootClassPath(); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 17 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 18 | CHECK(ClassLoader::UseCompileTimeClassPath()); |
| 19 | Table::const_iterator it = compile_time_class_paths_.find(class_loader); |
| 20 | CHECK(it != compile_time_class_paths_.end()); |
| 21 | return it->second; |
| 22 | } |
| 23 | |
| 24 | void ClassLoader::SetCompileTimeClassPath(const ClassLoader* class_loader, |
| 25 | std::vector<const DexFile*>& class_path) { |
| 26 | CHECK(!Runtime::Current()->IsStarted()); |
| 27 | use_compile_time_class_path = true; |
| 28 | compile_time_class_paths_[class_loader] = class_path; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| 31 | // TODO: get global references for these |
| 32 | Class* PathClassLoader::dalvik_system_PathClassLoader_ = NULL; |
| 33 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 34 | const PathClassLoader* PathClassLoader::AllocCompileTime(std::vector<const DexFile*>& dex_files) { |
| 35 | CHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 36 | DCHECK(dalvik_system_PathClassLoader_ != NULL); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 37 | PathClassLoader* p = down_cast<PathClassLoader*>(dalvik_system_PathClassLoader_->AllocObject()); |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 38 | SetCompileTimeClassPath(p, dex_files); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 39 | return p; |
| 40 | } |
| 41 | |
| 42 | void PathClassLoader::SetClass(Class* dalvik_system_PathClassLoader) { |
| 43 | CHECK(dalvik_system_PathClassLoader_ == NULL); |
| 44 | CHECK(dalvik_system_PathClassLoader != NULL); |
| 45 | dalvik_system_PathClassLoader_ = dalvik_system_PathClassLoader; |
| 46 | } |
| 47 | |
| 48 | void PathClassLoader::ResetClass() { |
| 49 | CHECK(dalvik_system_PathClassLoader_ != NULL); |
| 50 | dalvik_system_PathClassLoader_ = NULL; |
| 51 | } |
| 52 | |
| 53 | } // namespace art |