blob: 0ec9ec4ffe9ecd32776e6ccf48b2a3f31a3bed44 [file] [log] [blame]
The Android Open Source Projectf6c38712009-03-03 19:28:47 -08001/*
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 */
Andy McFadden734155e2009-07-16 18:11:22 -070016
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080017/*
18 * Common defines for all Dalvik code.
19 */
20#ifndef _DALVIK_COMMON
21#define _DALVIK_COMMON
22
23#ifndef LOG_TAG
24# define LOG_TAG "dalvikvm"
25#endif
26
Carl Shapiroae188c62011-04-08 13:11:58 -070027#include <stdbool.h>
28#include <stdint.h>
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080029#include <stdio.h>
30#include <assert.h>
Carl Shapiroae188c62011-04-08 13:11:58 -070031#include <endian.h>
32#include "utils/Log.h"
33
34#ifdef __cplusplus
35extern "C" {
36#endif
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080037
38#if !defined(NDEBUG) && defined(WITH_DALVIK_ASSERT)
39# undef assert
40# define assert(x) \
Andy McFadden734155e2009-07-16 18:11:22 -070041 ((x) ? ((void)0) : (LOGE("ASSERT FAILED (%s:%d): %s\n", \
Carl Shapiro4a1ef7d2010-12-01 19:51:36 -080042 __FILE__, __LINE__, #x), *(int*)39=39, (void)0) )
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080043#endif
44
Carl Shapiro99fc4562010-07-09 17:35:15 -070045#define MIN(x,y) (((x) < (y)) ? (x) : (y))
46#define MAX(x,y) (((x) > (y)) ? (x) : (y))
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080047
Carl Shapiroa20a9922010-07-29 21:22:12 -070048#define LIKELY(exp) (__builtin_expect((exp) != 0, true))
49#define UNLIKELY(exp) (__builtin_expect((exp) != 0, false))
50
Carl Shapirocc3f8b42011-02-08 20:10:56 -080051#define ALIGN_UP(x, n) (((size_t)(x) + (n) - 1) & ~((n) - 1))
52#define ALIGN_DOWN(x, n) ((size_t)(x) & -(n))
53#define ALIGN_UP_TO_PAGE_SIZE(p) ALIGN_UP(p, SYSTEM_PAGE_SIZE)
54#define ALIGN_DOWN_TO_PAGE_SIZE(p) ALIGN_DOWN(p, SYSTEM_PAGE_SIZE)
55
Carl Shapiro67f9be72011-02-08 19:54:55 -080056#define CLZ(x) __builtin_clz(x)
57
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080058/*
59 * If "very verbose" logging is enabled, make it equivalent to LOGV.
60 * Otherwise, make it disappear.
61 *
62 * Define this above the #include "Dalvik.h" to enable for only a
63 * single file.
64 */
65/* #define VERY_VERBOSE_LOG */
66#if defined(VERY_VERBOSE_LOG)
67# define LOGVV LOGV
68# define IF_LOGVV() IF_LOGV()
69#else
70# define LOGVV(...) ((void)0)
71# define IF_LOGVV() if (false)
72#endif
73
74
75/*
76 * These match the definitions in the VM specification.
77 */
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080078typedef uint8_t u1;
79typedef uint16_t u2;
80typedef uint32_t u4;
81typedef uint64_t u8;
82typedef int8_t s1;
83typedef int16_t s2;
84typedef int32_t s4;
85typedef int64_t s8;
The Android Open Source Projectf6c38712009-03-03 19:28:47 -080086
87/*
88 * Storage for primitive types and object references.
89 *
90 * Some parts of the code (notably object field access) assume that values
91 * are "left aligned", i.e. given "JValue jv", "jv.i" and "*((s4*)&jv)"
92 * yield the same result. This seems to be guaranteed by gcc on big- and
93 * little-endian systems.
94 */
95typedef union JValue {
96 u1 z;
97 s1 b;
98 u2 c;
99 s2 s;
100 s4 i;
101 s8 j;
102 float f;
103 double d;
104 void* l;
105} JValue;
106
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800107#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0])))
108
Carl Shapiroae188c62011-04-08 13:11:58 -0700109#ifdef __cplusplus
110}
The Android Open Source Projectf6c38712009-03-03 19:28:47 -0800111#endif
112
113#endif /*_DALVIK_COMMON*/