diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 3f1475a5aaf..7f7517dbe79 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -1,6 +1,7 @@ #include #include "Assert.h" +#include "Exceptions.h" #include "Memory.h" void FreeObject(ContainerHeader* header) { @@ -105,6 +106,13 @@ int IsInstance(const ObjHeader* obj, const TypeInfo* type_info) { return obj_type_info != nullptr; } +void CheckInstance(const ObjHeader* obj, const TypeInfo* type_info) { + if (IsInstance(obj, type_info)) { + return; + } + ThrowClassCastException(); +} + #ifdef __cplusplus } #endif diff --git a/runtime/src/main/cpp/Memory.h b/runtime/src/main/cpp/Memory.h index fce850e9499..3542f29a057 100644 --- a/runtime/src/main/cpp/Memory.h +++ b/runtime/src/main/cpp/Memory.h @@ -267,6 +267,7 @@ void* AllocInstance(const TypeInfo* type_info, PlacementHint hint); void* AllocArrayInstance( const TypeInfo* type_info, PlacementHint hint, uint32_t elements); int IsInstance(const ObjHeader* obj, const TypeInfo* type_info); +void CheckCast(const ObjHeader* obj, const TypeInfo* type_info); #ifdef __cplusplus }