Elliott Hughes | 2faa5f1 | 2012-01-30 14:42:07 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 16 | |
| 17 | #include "class_loader.h" |
| 18 | |
| 19 | #include "class_linker.h" |
| 20 | #include "runtime.h" |
| 21 | |
| 22 | namespace art { |
| 23 | |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 24 | bool ClassLoader::use_compile_time_class_path = false; |
| 25 | ClassLoader::Table ClassLoader::compile_time_class_paths_; |
| 26 | |
| 27 | const std::vector<const DexFile*>& ClassLoader::GetCompileTimeClassPath(const ClassLoader* class_loader) { |
| 28 | Runtime* runtime = Runtime::Current(); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 29 | if (class_loader == NULL) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 30 | return runtime->GetClassLinker()->GetBootClassPath(); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 31 | } |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 32 | CHECK(ClassLoader::UseCompileTimeClassPath()); |
| 33 | Table::const_iterator it = compile_time_class_paths_.find(class_loader); |
| 34 | CHECK(it != compile_time_class_paths_.end()); |
| 35 | return it->second; |
| 36 | } |
| 37 | |
| 38 | void ClassLoader::SetCompileTimeClassPath(const ClassLoader* class_loader, |
| 39 | std::vector<const DexFile*>& class_path) { |
| 40 | CHECK(!Runtime::Current()->IsStarted()); |
| 41 | use_compile_time_class_path = true; |
| 42 | compile_time_class_paths_[class_loader] = class_path; |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | // TODO: get global references for these |
| 46 | Class* PathClassLoader::dalvik_system_PathClassLoader_ = NULL; |
| 47 | |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 48 | PathClassLoader* PathClassLoader::AllocCompileTime(std::vector<const DexFile*>& dex_files) { |
Brian Carlstrom | aded5f7 | 2011-10-07 17:15:04 -0700 | [diff] [blame] | 49 | CHECK(!Runtime::Current()->IsStarted()); |
Brian Carlstrom | 69b15fb | 2011-09-03 12:25:21 -0700 | [diff] [blame] | 50 | DCHECK(dalvik_system_PathClassLoader_ != NULL); |
Brian Carlstrom | 40381fb | 2011-10-19 14:13:40 -0700 | [diff] [blame] | 51 | SirtRef<PathClassLoader> p(down_cast<PathClassLoader*>(dalvik_system_PathClassLoader_->AllocObject())); |
| 52 | SetCompileTimeClassPath(p.get(), dex_files); |
| 53 | return p.get(); |
Brian Carlstrom | 1f87008 | 2011-08-23 16:02:11 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | void PathClassLoader::SetClass(Class* dalvik_system_PathClassLoader) { |
| 57 | CHECK(dalvik_system_PathClassLoader_ == NULL); |
| 58 | CHECK(dalvik_system_PathClassLoader != NULL); |
| 59 | dalvik_system_PathClassLoader_ = dalvik_system_PathClassLoader; |
| 60 | } |
| 61 | |
| 62 | void PathClassLoader::ResetClass() { |
| 63 | CHECK(dalvik_system_PathClassLoader_ != NULL); |
| 64 | dalvik_system_PathClassLoader_ = NULL; |
| 65 | } |
| 66 | |
| 67 | } // namespace art |