inlinebool ArtField::IsProxyField() { // No read barrier needed, we're reading the constant declaring class only to read // the constant proxy flag. See ReadBarrierOption. return GetDeclaringClass<kWithoutReadBarrier>()->IsProxyClass<kVerifyNone>();
}
// We are only ever allowed to set our own final fields inlinebool ArtField::CanBeChangedBy(ArtMethod* method) {
ObjPtr<mirror::Class> declaring_class(GetDeclaringClass());
ObjPtr<mirror::Class> referring_class(method->GetDeclaringClass()); return !IsFinal() || (declaring_class == referring_class);
}
template<bool kTransactionActive> inlinevoid ArtField::SetBoolean(ObjPtr<mirror::Object> object, uint8_t z) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both boolean and byte fields.
Primitive::Type type = GetTypeAsPrimitiveType();
DCHECK(type == Primitive::kPrimBoolean || type == Primitive::kPrimByte) << PrettyField();
}
FIELD_SET(object, Boolean, z);
}
template<bool kTransactionActive> inlinevoid ArtField::SetChar(ObjPtr<mirror::Object> object, uint16_t c) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both char and short fields.
Primitive::Type type = GetTypeAsPrimitiveType();
DCHECK(type == Primitive::kPrimChar || type == Primitive::kPrimShort) << PrettyField();
}
FIELD_SET(object, Char, c);
}
inline int32_t ArtField::GetInt(ObjPtr<mirror::Object> object) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both int and float fields.
Primitive::Type type = GetTypeAsPrimitiveType();
CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField();
} return Get32(object);
}
template<bool kTransactionActive> inlinevoid ArtField::SetInt(ObjPtr<mirror::Object> object, int32_t i) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both int and float fields.
Primitive::Type type = GetTypeAsPrimitiveType();
CHECK(type == Primitive::kPrimInt || type == Primitive::kPrimFloat) << PrettyField();
}
Set32<kTransactionActive>(object, i);
}
inline int64_t ArtField::GetLong(ObjPtr<mirror::Object> object) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both long and double fields.
Primitive::Type type = GetTypeAsPrimitiveType();
CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField();
} return Get64(object);
}
template<bool kTransactionActive> inlinevoid ArtField::SetLong(ObjPtr<mirror::Object> object, int64_t j) { if (kIsDebugBuild) { // For simplicity, this method is being called by the compiler entrypoint for // both long and double fields.
Primitive::Type type = GetTypeAsPrimitiveType();
CHECK(type == Primitive::kPrimLong || type == Primitive::kPrimDouble) << PrettyField();
}
Set64<kTransactionActive>(object, j);
}
inlinebool ArtField::IsWriteProtected() { if (this == WellKnownClasses::java_lang_System_in || this == WellKnownClasses::java_lang_System_out || this == WellKnownClasses::java_lang_System_err) { returntrue;
} // TODO(b/423809429): some `static final` fields defined in android.os.Build and // android.os.Build$VERSION are overwritten for App Compat reasons on dogfood builds. // Once these fields are no longer modified checks below could be removed altogether as released // Android versions should not modify these fields. if (IsStatic() && IsFinal()) { // No read barrier needed for reading chains of constant references for comparison // with null and for reading constant primitive data.
ObjPtr<mirror::Class> declaring_class = GetDeclaringClass<kWithoutReadBarrier>(); if (!declaring_class->IsBootStrapClassLoaded()) { returnfalse;
} if (declaring_class->DescriptorEquals("Landroid/os/Build;") ||
declaring_class->DescriptorEquals("Landroid/os/Build$VERSION;")) { returntrue;
}
} returnfalse;
}
inlinebool ArtField::IsUnmodifiable(auto&& get_field_type) { if (!IsFinal()) { returnfalse;
}
// Write-protected fields are `static final`, but can be modified nevertheless. if (IsWriteProtected()) { returnfalse;
}
if (IsMonotonic()) { returntrue;
}
// Before and on Android B any field could be overwritten using reflection with final fields in // record classes being the only exception. For compatibility purposes allow apps targeting B // or an older release to overwrite such fields.
uint32_t target_sdk_version = Runtime::Current()->GetTargetSdkVersion(); if (IsSdkVersionSetAndAtMost(target_sdk_version, SdkVersion::kB)) { returnfalse;
}
// `static final` fields with declared VarHandle, MethodHandle, Atomic*FieldUpdater or Unsafe // types are unmodifiable on apps targeting C or higher. if (IsStatic()) {
ObjPtr<mirror::Class> field_type = get_field_type();
DCHECK(field_type != nullptr); if (field_type->IsBootStrapClassLoaded()) { // These classes are abstract and exact implementations are exposed neither to apps // nor in the platform, hence plain comparison instead of subtype checks. if (field_type == GetClassRoot(ClassRoot::kJavaLangInvokeMethodHandle) ||
field_type == GetClassRoot(ClassRoot::kJavaLangInvokeVarHandle) ||
field_type == WellKnownClasses::ToClass(
WellKnownClasses::java_util_concurrent_atomic_AIFU) ||
field_type == WellKnownClasses::ToClass(
WellKnownClasses::java_util_concurrent_atomic_ALFU) ||
field_type == WellKnownClasses::ToClass(
WellKnownClasses::java_util_concurrent_atomic_ARFU) || // Unsafe classes are final and there is only one instance of them.
field_type == WellKnownClasses::ToClass(
WellKnownClasses::jdk_internal_misc_Unsafe) ||
field_type == WellKnownClasses::ToClass(
WellKnownClasses::sun_misc_Unsafe)) { returntrue;
}
}
}
// Make sure that OEMs code in bootclasspath won't be affected after ART module update.
uint32_t sdk_version = Runtime::Current()->GetSdkVersion(); if (IsSdkVersionSetAndAtMost(sdk_version, SdkVersion::kB)) { returnfalse;
}
// static final fields can't be modified once initialized. return IsStatic();
}
} // namespace art
#endif// ART_RUNTIME_ART_FIELD_INL_H_
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.2 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.