2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * Common defines for all Dalvik code.
20 #ifndef DALVIK_COMMON_H_
21 #define DALVIK_COMMON_H_
24 # define LOG_TAG "dalvikvm"
31 #include "cutils/log.h"
33 #if defined(HAVE_ENDIAN_H)
35 #else /*not HAVE_ENDIAN_H*/
36 # define __BIG_ENDIAN 4321
37 # define __LITTLE_ENDIAN 1234
38 # if defined(HAVE_LITTLE_ENDIAN)
39 # define __BYTE_ORDER __LITTLE_ENDIAN
41 # define __BYTE_ORDER __BIG_ENDIAN
43 #endif /*not HAVE_ENDIAN_H*/
45 #if !defined(NDEBUG) && defined(WITH_DALVIK_ASSERT)
48 ((x) ? ((void)0) : (ALOGE("ASSERT FAILED (%s:%d): %s", \
49 __FILE__, __LINE__, #x), *(int*)39=39, (void)0) )
52 #define MIN(x,y) (((x) < (y)) ? (x) : (y))
53 #define MAX(x,y) (((x) > (y)) ? (x) : (y))
55 #define LIKELY(exp) (__builtin_expect((exp) != 0, true))
56 #define UNLIKELY(exp) (__builtin_expect((exp) != 0, false))
58 #define ALIGN_UP(x, n) (((size_t)(x) + (n) - 1) & ~((n) - 1))
59 #define ALIGN_DOWN(x, n) ((size_t)(x) & -(n))
60 #define ALIGN_UP_TO_PAGE_SIZE(p) ALIGN_UP(p, SYSTEM_PAGE_SIZE)
61 #define ALIGN_DOWN_TO_PAGE_SIZE(p) ALIGN_DOWN(p, SYSTEM_PAGE_SIZE)
63 #define CLZ(x) __builtin_clz(x)
66 * If "very verbose" logging is enabled, make it equivalent to ALOGV.
67 * Otherwise, make it disappear.
69 * Define this above the #include "Dalvik.h" to enable for only a
72 /* #define VERY_VERBOSE_LOG */
73 #if defined(VERY_VERBOSE_LOG)
75 # define IF_LOGVV() IF_ALOGV()
77 # define LOGVV(...) ((void)0)
78 # define IF_LOGVV() if (false)
83 * These match the definitions in the VM specification.
95 * Storage for primitive types and object references.
97 * Some parts of the code (notably object field access) assume that values
98 * are "left aligned", i.e. given "JValue jv", "jv.i" and "*((s4*)&jv)"
99 * yield the same result. This seems to be guaranteed by gcc on big- and
100 * little-endian systems.
105 #if defined(HAVE_LITTLE_ENDIAN)
116 #if defined(HAVE_BIG_ENDIAN)
141 #define OFFSETOF_MEMBER(t, f) \
142 (reinterpret_cast<char*>( \
143 &reinterpret_cast<t*>(16)->f) - \
144 reinterpret_cast<char*>(16))
146 #define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
148 #endif // DALVIK_COMMON_H_