// We are more like a compiler than a run-time. We don't want to execute code.
{ static CmdlineCompilerCallbacks callbacks(allow_profile_code);
options.push_back(std::make_pair("compilercallbacks", &callbacks));
}
// None of the command line tools need sig chain. If this changes we'll need // to upgrade this option to a proper parameter.
options.push_back(std::make_pair("-Xno-sig-chain", nullptr)); if (!Runtime::Create(options, false)) {
fprintf(stderr, "Failed to create runtime\n"); return nullptr;
}
// Runtime::Create acquired the mutator_lock_ that is normally given away when we Runtime::Start, // give it away now and then switch to a more manageable ScopedObjectAccess.
Thread::Current()->TransitionFromRunnableToSuspended(ThreadState::kNative);
return Runtime::Current();
}
struct CmdlineArgs { enum ParseStatus {
kParseOk, // Parse successful. Do not set the error message.
kParseUnknownArgument, // Unknown argument. Do not set the error message.
kParseError, // Parse ok, but failed elsewhere. Print the set error message.
};
usage += // Required. " --boot-image=<file.art>: provide the image location for the boot class path.\n" " Do not include the arch as part of the name, it is added automatically.\n" " Example: --boot-image=/system/framework/boot.art\n" " (specifies /system/framework/<arch>/boot.art as the image file)\n" "\n";
usage += android::base::StringPrintf( // Optional. " --instruction-set=(arm|arm64|x86|x86_64|riscv64): for locating the image\n" " file based on the image location set.\n" " Example: --instruction-set=x86\n" " Default: %s\n" "\n",
GetInstructionSetString(kRuntimeISA));
usage += " --runtime-arg <argument> used to specify various arguments for the runtime\n" " such as initial heap size, maximum heap size, and verbose output.\n" " Use a separate --runtime-arg switch for each argument.\n" " Example: --runtime-arg -Xms256m\n" "\n";
usage += // Optional. " --output=<file> may be used to send the output to a file.\n" " Example: --output=/tmp/oatdump.txt\n" "\n";
return usage;
}
// Specified by --runtime-arg -Xbootclasspath or default.
std::vector<std::string> boot_class_path_; // Specified by --runtime-arg -Xbootclasspath-locations or default.
std::vector<std::string> boot_class_path_locations_; // True if `boot_class_path_` is the default one. bool is_default_boot_class_path_ = false; // Specified by --boot-image or inferred.
std::vector<std::string> boot_image_locations_; // Specified by --instruction-set.
InstructionSet instruction_set_ = InstructionSet::kNone; // Runtime arguments specified by --runtime-arg.
std::vector<constchar*> runtime_args_; // Specified by --output.
std::ostream* os_ = &std::cout;
std::unique_ptr<std::ofstream> out_; // If something besides cout is used
std::string output_name_; // Enabled by --allow-profiled-code bool allow_profile_code_ = false;
virtual ~CmdlineArgs() {}
// Checks for --boot-image location. bool ParseCheckBootImage(std::string* error_msg) { if (boot_image_locations_.empty()) {
LOG(WARNING) << "--boot-image not specified. Starting runtime in imageless mode"; returntrue;
}
const std::string& boot_image_location = boot_image_locations_[0];
size_t file_name_idx = boot_image_location.rfind('/'); if (file_name_idx == std::string::npos) { // Prevent a InsertIsaDirectory check failure.
*error_msg = "Boot image location must have a / in it"; returnfalse;
}
// Don't let image locations with the 'arch' in it through, since it's not a location. // This prevents a common error "Could not create an image space..." when initing the Runtime. if (file_name_idx > 0) {
size_t ancestor_dirs_idx = boot_image_location.rfind('/', file_name_idx - 1);
DBG_LOG << "boot_image_location parent_dir_name was " << parent_dir_name;
if (GetInstructionSetFromString(parent_dir_name.c_str()) != InstructionSet::kNone) {
*error_msg = "Do not specify the architecture as part of the boot image location"; returnfalse;
}
}
// Infers the boot image on a best-effort basis. // The inference logic aligns with installd/artd + dex2oat. void InferBootImage() { // The boot image inference only makes sense on device. if (!kIsTargetAndroid) { return;
}
// The inferred boot image can only be used with the default bootclasspath. if (boot_class_path_.empty() || !is_default_boot_class_path_) { return;
}
if (needs_runtime) {
std::string error_msg; if (!args_->ParseCheckBootImage(&error_msg)) {
fprintf(stderr, "%s\n", error_msg.c_str());
args_->PrintUsage(); return EXIT_FAILURE;
}
runtime.reset(CreateRuntime(args.get())); if (runtime == nullptr) { return EXIT_FAILURE;
} if (!ExecuteWithRuntime(runtime.get())) { return EXIT_FAILURE;
}
} else { if (!ExecuteWithoutRuntime()) { return EXIT_FAILURE;
}
}
if (!ExecuteCommon()) { return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
// Override this function to create your own arguments. // Usually will want to return a subtype of CmdlineArgs. virtual Args* CreateArguments() { returnnew Args();
}
// Override this function to do something else with the runtime. virtualbool ExecuteWithRuntime(Runtime* runtime) {
CHECK(runtime != nullptr); // Do nothing returntrue;
}
// Does the code execution need a runtime? Sometimes it doesn't. virtualbool NeedsRuntime() { returntrue;
}
// Do execution without having created a runtime. virtualbool ExecuteWithoutRuntime() { returntrue;
}
// Continue execution after ExecuteWith[out]Runtime virtualbool ExecuteCommon() { returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.