Home | History | Annotate | Download | only in oo
      1 /*
      2  * Copyright (C) 2008 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  * instanceof, checkcast, etc.
     18  */
     19 #ifndef DALVIK_OO_TYPECHECK_H_
     20 #define DALVIK_OO_TYPECHECK_H_
     21 
     22 /* VM startup/shutdown */
     23 bool dvmInstanceofStartup(void);
     24 void dvmInstanceofShutdown(void);
     25 
     26 
     27 /* used by dvmInstanceof; don't call */
     28 extern "C" int dvmInstanceofNonTrivial(const ClassObject* instance,
     29                                        const ClassObject* clazz);
     30 
     31 /*
     32  * Determine whether "instance" is an instance of "clazz".
     33  *
     34  * Returns 0 (false) if not, 1 (true) if so.
     35  */
     36 INLINE int dvmInstanceof(const ClassObject* instance, const ClassObject* clazz)
     37 {
     38     if (instance == clazz) {
     39         if (CALC_CACHE_STATS)
     40             gDvm.instanceofCache->trivial++;
     41         return 1;
     42     } else
     43         return dvmInstanceofNonTrivial(instance, clazz);
     44 }
     45 
     46 /*
     47  * Determine whether a class implements an interface.
     48  *
     49  * Returns 0 (false) if not, 1 (true) if so.
     50  */
     51 int dvmImplements(const ClassObject* clazz, const ClassObject* interface);
     52 
     53 /*
     54  * Determine whether "sub" is a sub-class of "clazz".
     55  *
     56  * Returns 0 (false) if not, 1 (true) if so.
     57  */
     58 INLINE int dvmIsSubClass(const ClassObject* sub, const ClassObject* clazz) {
     59     do {
     60         /*printf("###### sub='%s' clazz='%s'\n", sub->name, clazz->name);*/
     61         if (sub == clazz)
     62             return 1;
     63         sub = sub->super;
     64     } while (sub != NULL);
     65 
     66     return 0;
     67 }
     68 
     69 /*
     70  * Determine whether or not we can store an object into an array, based
     71  * on the classes of the two.
     72  *
     73  * Returns 0 (false) if not, 1 (true) if so.
     74  */
     75 extern "C" bool dvmCanPutArrayElement(const ClassObject* elemClass,
     76     const ClassObject* arrayClass);
     77 
     78 #endif  // DALVIK_OO_TYPECHECK_H_
     79