extern"C" JNIEXPORT jboolean JNICALL Java_Main_supportsThreadPriorities(
[[maybe_unused]] JNIEnv* env, [[maybe_unused]] jclass clazz) { int my_niceness = getpriority(PRIO_PROCESS, 0/* self */); int my_priority = Thread::NicenessToPriority(my_niceness); int new_priority = (my_priority == kMaxThreadPriority ? my_priority - 2 : my_priority + 1);
{
ScopedObjectAccess soa(env);
Thread::Current()->SetNativePriority(new_priority);
} int new_niceness = getpriority(PRIO_PROCESS, 0/* self */);
{
ScopedObjectAccess soa(env);
Thread::Current()->SetNativePriority(my_priority);
} if (new_niceness == my_niceness) { // Had no effect. return JNI_FALSE;
} else { // Assume it did the right thing. return JNI_TRUE;
}
}
// Returns a description of Java to Posix priority mapping, and information about how we obtained // it. Used only for test failure reporting, and hence a bit sloppy in terms of error checks. extern"C" JNIEXPORT jstring JNICALL Java_Main_getPriorityInfo(JNIEnv* env,
[[maybe_unused]] jclass clazz) {
std::ostringstream result;
result << "Java priorities mapping: "; for (int p = kMinThreadPriority; p <= kMaxThreadPriority; ++p) { if (p != kMinThreadPriority) {
result << ", ";
}
result << p << ": " << Thread::PriorityToNiceness(p);
}
result << ";\nSetpriority effects: "; int my_niceness = getpriority(PRIO_PROCESS, 0/* self */); for (int p = -20; p <= 19; p += 3) { if (p != -20) {
result << ", ";
} int ret = setpriority(PRIO_PROCESS, 0/* self */, p);
result << p << ": "; if (ret == 0) {
result << getpriority(PRIO_PROCESS, 0/* self */);
} else {
result << "failed:" << strerror(errno);
}
} // Test whether SetNativePriority has any impact. If not, that suggests that either setpriority // doesn't work in this range, or we've decided that setpriority cannot be relied upon for other // reasons. See `canSetPriority` in thread.cc. Intentionally slightly different from // supportsThreadPriorities test, so that we have a chance of detecting inconsistencies.
{
ScopedObjectAccess soa(env);
Thread::Current()->SetNativePriority(6);
} if (getpriority(PRIO_PROCESS, 0/* self */) != Thread::PriorityToNiceness(6)) {
result << ";\nPriority setting not working";
}
result << ";\nSDK version is " << android::base::GetIntProperty("ro.build.version.sdk", 0); // Restore priority to something plausible, if possible.
setpriority(PRIO_PROCESS, 0/* self */, my_niceness); return env->NewStringUTF(result.str().c_str());
}
} // namespace art
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.9 Sekunden
(vorverarbeitet am 2026-06-29)
¤
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.