From dfd486a9eaaaba8a0808a1b3e24aeb106cacdc84 Mon Sep 17 00:00:00 2001 From: Konstantin Anisimov Date: Thu, 17 Nov 2016 16:08:21 +0300 Subject: [PATCH] RUNTIME: Code rearranged between Memory.* and Types.* --- runtime/src/main/cpp/Memory.cpp | 26 ------------------------ runtime/src/main/cpp/Memory.h | 3 --- runtime/src/main/cpp/Types.cpp | 36 +++++++++++++++++++++++++++++++++ runtime/src/main/cpp/Types.h | 3 +++ 4 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 runtime/src/main/cpp/Types.cpp diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index 7f7517dbe79..17d5e245fbe 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -87,32 +87,6 @@ void* AllocArrayInstance( return ArrayContainer(type_info, elements).GetPlace(); } -int IsInstance(const ObjHeader* obj, const TypeInfo* type_info) { - // We assume null check is handled by caller. - RuntimeAssert(obj != nullptr, "must not be null"); - const TypeInfo* obj_type_info = obj->type_info(); - // If it is an interface - check in list of implemented interfaces. - if (type_info->fieldsCount_ < 0) { - for (int i = 0; i < obj_type_info->implementedInterfacesCount_; ++i) { - if (obj_type_info->implementedInterfaces_[i] == type_info) { - return 1; - } - } - return 0; - } - while (obj_type_info != nullptr && obj_type_info != type_info) { - obj_type_info = obj_type_info->superType_; - } - 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 0562cbf0bd7..cdc3aeaf87f 100644 --- a/runtime/src/main/cpp/Memory.h +++ b/runtime/src/main/cpp/Memory.h @@ -266,9 +266,6 @@ void InitMemory(); 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 CheckInstance(const ObjHeader* obj, const TypeInfo* type_info); - #ifdef __cplusplus } #endif diff --git a/runtime/src/main/cpp/Types.cpp b/runtime/src/main/cpp/Types.cpp new file mode 100644 index 00000000000..3049610a095 --- /dev/null +++ b/runtime/src/main/cpp/Types.cpp @@ -0,0 +1,36 @@ +#include "Types.h" +#include "Exceptions.h" + +#ifdef __cplusplus +extern "C" { +#endif + +KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info) { + // We assume null check is handled by caller. + RuntimeAssert(obj != nullptr, "must not be null"); + const TypeInfo* obj_type_info = obj->type_info(); + // If it is an interface - check in list of implemented interfaces. + if (type_info->fieldsCount_ < 0) { + for (int i = 0; i < obj_type_info->implementedInterfacesCount_; ++i) { + if (obj_type_info->implementedInterfaces_[i] == type_info) { + return 1; + } + } + return 0; + } + while (obj_type_info != nullptr && obj_type_info != type_info) { + obj_type_info = obj_type_info->superType_; + } + 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/Types.h b/runtime/src/main/cpp/Types.h index f3e0cdea7a1..e6a1f11d261 100644 --- a/runtime/src/main/cpp/Types.h +++ b/runtime/src/main/cpp/Types.h @@ -34,6 +34,9 @@ extern const TypeInfo* theDoubleArrayTypeInfo; extern const TypeInfo* theBooleanArrayTypeInfo; extern const TypeInfo* theStringTypeInfo; +KBoolean IsInstance(const ObjHeader* obj, const TypeInfo* type_info); +void CheckCast(const ObjHeader* obj, const TypeInfo* type_info); + #ifdef __cplusplus } #endif