1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "common_throws.h" 18 #include "entrypoints/entrypoint_utils-inl.h" 19 #include "mirror/object-inl.h" 20 21 namespace art { 22 23 extern "C" int32_t art_portable_is_assignable_from_code(mirror::Class* dest_type, 24 mirror::Class* src_type) 25 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 26 DCHECK(dest_type != NULL); 27 DCHECK(src_type != NULL); 28 return dest_type->IsAssignableFrom(src_type) ? 1 : 0; 29 } 30 31 extern "C" void art_portable_check_cast_from_code(mirror::Class* dest_type, 32 mirror::Class* src_type) 33 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 34 DCHECK(dest_type->IsClass()) << PrettyClass(dest_type); 35 DCHECK(src_type->IsClass()) << PrettyClass(src_type); 36 if (UNLIKELY(!dest_type->IsAssignableFrom(src_type))) { 37 ThrowClassCastException(dest_type, src_type); 38 } 39 } 40 41 extern "C" void art_portable_check_put_array_element_from_code(mirror::Object* element, 42 mirror::Object* array) 43 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 44 if (element == NULL) { 45 return; 46 } 47 DCHECK(array != NULL); 48 mirror::Class* array_class = array->GetClass(); 49 DCHECK(array_class != NULL); 50 mirror::Class* component_type = array_class->GetComponentType(); 51 mirror::Class* element_class = element->GetClass(); 52 if (UNLIKELY(!component_type->IsAssignableFrom(element_class))) { 53 ThrowArrayStoreException(element_class, array_class); 54 } 55 } 56 57 } // namespace art 58