Common.h revision f6c387128427e121477c1b32ad35cdcaa5101ba3
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 * Common defines for all Dalvik code. 18 */ 19#ifndef _DALVIK_COMMON 20#define _DALVIK_COMMON 21 22#ifndef LOG_TAG 23# define LOG_TAG "dalvikvm" 24#endif 25 26#include <stdio.h> 27#include <assert.h> 28 29#if !defined(NDEBUG) && defined(WITH_DALVIK_ASSERT) 30# undef assert 31# define assert(x) \ 32 ((x) ? ((void)0) : (LOGE("ASSERT FAILED (%s:%d): " #x "\n", \ 33 __FILE__, __LINE__), *(int*)39=39, 0) ) 34#endif 35 36 37/* 38 * If "very verbose" logging is enabled, make it equivalent to LOGV. 39 * Otherwise, make it disappear. 40 * 41 * Define this above the #include "Dalvik.h" to enable for only a 42 * single file. 43 */ 44/* #define VERY_VERBOSE_LOG */ 45#if defined(VERY_VERBOSE_LOG) 46# define LOGVV LOGV 47# define IF_LOGVV() IF_LOGV() 48#else 49# define LOGVV(...) ((void)0) 50# define IF_LOGVV() if (false) 51#endif 52 53 54/* 55 * These match the definitions in the VM specification. 56 */ 57#ifdef HAVE_STDINT_H 58# include <stdint.h> /* C99 */ 59typedef uint8_t u1; 60typedef uint16_t u2; 61typedef uint32_t u4; 62typedef uint64_t u8; 63typedef int8_t s1; 64typedef int16_t s2; 65typedef int32_t s4; 66typedef int64_t s8; 67#else 68typedef unsigned char u1; 69typedef unsigned short u2; 70typedef unsigned int u4; 71typedef unsigned long long u8; 72typedef signed char s1; 73typedef signed short s2; 74typedef signed int s4; 75typedef signed long long s8; 76#endif 77 78/* 79 * Storage for primitive types and object references. 80 * 81 * Some parts of the code (notably object field access) assume that values 82 * are "left aligned", i.e. given "JValue jv", "jv.i" and "*((s4*)&jv)" 83 * yield the same result. This seems to be guaranteed by gcc on big- and 84 * little-endian systems. 85 */ 86typedef union JValue { 87 u1 z; 88 s1 b; 89 u2 c; 90 s2 s; 91 s4 i; 92 s8 j; 93 float f; 94 double d; 95 void* l; 96} JValue; 97 98/* 99 * Some systems might have this in <stdbool.h>. 100 */ 101#ifndef __bool_true_false_are_defined 102typedef enum { false=0, true=!false } bool; 103#define __bool_true_false_are_defined 1 104#endif 105 106#define NELEM(x) ((int) (sizeof(x) / sizeof((x)[0]))) 107 108 109#if defined(HAVE_ENDIAN_H) 110# include <endian.h> 111#else /*not HAVE_ENDIAN_H*/ 112# define __BIG_ENDIAN 4321 113# define __LITTLE_ENDIAN 1234 114# if defined(HAVE_LITTLE_ENDIAN) 115# define __BYTE_ORDER __LITTLE_ENDIAN 116# else 117# define __BYTE_ORDER __BIG_ENDIAN 118# endif 119#endif /*not HAVE_ENDIAN_H*/ 120 121 122#if 0 123/* 124 * Pretend we have the Android logging macros. These are replaced by the 125 * Android logging implementation. 126 */ 127#define ANDROID_LOG_DEBUG 3 128#define LOGV(...) LOG_PRI(2, 0, __VA_ARGS__) 129#define LOGD(...) LOG_PRI(3, 0, __VA_ARGS__) 130#define LOGI(...) LOG_PRI(4, 0, __VA_ARGS__) 131#define LOGW(...) LOG_PRI(5, 0, __VA_ARGS__) 132#define LOGE(...) LOG_PRI(6, 0, __VA_ARGS__) 133#define MIN_LOG_LEVEL 2 134 135#define LOG_PRI(priority, tag, ...) do { \ 136 if (priority >= MIN_LOG_LEVEL) { \ 137 dvmFprintf(stdout, "%s:%-4d ", __FILE__, __LINE__); \ 138 dvmFprintf(stdout, __VA_ARGS__); \ 139 } \ 140 } while(0) 141#else 142# include "utils/Log.h" 143#endif 144 145#endif /*_DALVIK_COMMON*/ 146