blob: 6b6297b435868515e3270d17f7dec70a3cba6fd8 [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 */
Brian Carlstrom1f870082011-08-23 16:02:11 -070016
17#include "class_loader.h"
18
19#include "class_linker.h"
20#include "runtime.h"
21
22namespace art {
23
Brian Carlstromaded5f72011-10-07 17:15:04 -070024bool ClassLoader::use_compile_time_class_path = false;
25ClassLoader::Table ClassLoader::compile_time_class_paths_;
26
27const std::vector<const DexFile*>& ClassLoader::GetCompileTimeClassPath(const ClassLoader* class_loader) {
28 Runtime* runtime = Runtime::Current();
Brian Carlstrom1f870082011-08-23 16:02:11 -070029 if (class_loader == NULL) {
Brian Carlstromaded5f72011-10-07 17:15:04 -070030 return runtime->GetClassLinker()->GetBootClassPath();
Brian Carlstrom1f870082011-08-23 16:02:11 -070031 }
Brian Carlstromaded5f72011-10-07 17:15:04 -070032 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
38void 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 Carlstrom1f870082011-08-23 16:02:11 -070043}
44
45// TODO: get global references for these
46Class* PathClassLoader::dalvik_system_PathClassLoader_ = NULL;
47
Brian Carlstrom40381fb2011-10-19 14:13:40 -070048PathClassLoader* PathClassLoader::AllocCompileTime(std::vector<const DexFile*>& dex_files) {
Brian Carlstromaded5f72011-10-07 17:15:04 -070049 CHECK(!Runtime::Current()->IsStarted());
Brian Carlstrom69b15fb2011-09-03 12:25:21 -070050 DCHECK(dalvik_system_PathClassLoader_ != NULL);
Brian Carlstrom40381fb2011-10-19 14:13:40 -070051 SirtRef<PathClassLoader> p(down_cast<PathClassLoader*>(dalvik_system_PathClassLoader_->AllocObject()));
52 SetCompileTimeClassPath(p.get(), dex_files);
53 return p.get();
Brian Carlstrom1f870082011-08-23 16:02:11 -070054}
55
56void 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
62void PathClassLoader::ResetClass() {
63 CHECK(dalvik_system_PathClassLoader_ != NULL);
64 dalvik_system_PathClassLoader_ = NULL;
65}
66
67} // namespace art