Revert "Stop using the runtime classpath in dex2oat"
This reverts commit 84f82b9972ec29bd05b1575ae6d638255be2f285.
Reason for revert: I submitted this to ealrly. It needs to be submitted after https://android-review.googlesource.com/c/450390 gets merged
Change-Id: I91e6259b61d72a48a1d18e62f53ef82f18692930
diff --git a/dex2oat/dex2oat.cc b/dex2oat/dex2oat.cc
index fd22dcd..0826fa1 100644
--- a/dex2oat/dex2oat.cc
+++ b/dex2oat/dex2oat.cc
@@ -1304,7 +1304,7 @@
} else if (option.starts_with("--class-loader-context=")) {
class_loader_context_ = ClassLoaderContext::Create(
option.substr(strlen("--class-loader-context=")).data());
- if (class_loader_context_ == nullptr) {
+ if (class_loader_context_== nullptr) {
Usage("Option --class-loader-context has an incorrect format: %s", option.data());
}
} else if (!compiler_options_->ParseCompilerOption(option, Usage)) {
@@ -1569,12 +1569,20 @@
}
// Open dex files for class path.
-
if (class_loader_context_ == nullptr) {
- // If no context was specified use the default one (which is an empty PathClassLoader).
- class_loader_context_ = std::unique_ptr<ClassLoaderContext>(ClassLoaderContext::Default());
+ // TODO(calin): Temporary workaround while we transition to use
+ // --class-loader-context instead of --runtime-arg -cp
+ if (runtime_->GetClassPathString().empty()) {
+ class_loader_context_ = std::unique_ptr<ClassLoaderContext>(
+ new ClassLoaderContext());
+ } else {
+ std::string spec = runtime_->GetClassPathString() == OatFile::kSpecialSharedLibrary
+ ? OatFile::kSpecialSharedLibrary
+ : "PCL[" + runtime_->GetClassPathString() + "]";
+ class_loader_context_ = ClassLoaderContext::Create(spec);
+ }
}
-
+ CHECK(class_loader_context_ != nullptr);
DCHECK_EQ(oat_writers_.size(), 1u);
// Note: Ideally we would reject context where the source dex files are also
diff --git a/runtime/class_loader_context.cc b/runtime/class_loader_context.cc
index e7051b3..b50aec0 100644
--- a/runtime/class_loader_context.cc
+++ b/runtime/class_loader_context.cc
@@ -68,10 +68,6 @@
}
}
-std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Default() {
- return Create("");
-}
-
std::unique_ptr<ClassLoaderContext> ClassLoaderContext::Create(const std::string& spec) {
std::unique_ptr<ClassLoaderContext> result(new ClassLoaderContext());
if (result->Parse(spec)) {
diff --git a/runtime/class_loader_context.h b/runtime/class_loader_context.h
index 9afa880..85299d4 100644
--- a/runtime/class_loader_context.h
+++ b/runtime/class_loader_context.h
@@ -34,6 +34,9 @@
// Utility class which holds the class loader context used during compilation/verification.
class ClassLoaderContext {
public:
+ // Creates an empty context (with no class loaders).
+ ClassLoaderContext();
+
~ClassLoaderContext();
// Opens requested class path files and appends them to ClassLoaderInfo::opened_dex_files.
@@ -123,10 +126,6 @@
static std::unique_ptr<ClassLoaderContext> CreateContextForClassLoader(jobject class_loader,
jobjectArray dex_elements);
- // Returns the default class loader context to be used when none is specified.
- // This will return a context with a single and empty PathClassLoader.
- static std::unique_ptr<ClassLoaderContext> Default();
-
private:
enum ClassLoaderType {
kInvalidClassLoader = 0,
@@ -152,9 +151,6 @@
explicit ClassLoaderInfo(ClassLoaderType cl_type) : type(cl_type) {}
};
- // Creates an empty context (with no class loaders).
- ClassLoaderContext();
-
// Constructs an empty context.
// `owns_the_dex_files` specifies whether or not the context will own the opened dex files
// present in the class loader chain. If `owns_the_dex_files` is true then OpenDexFiles cannot