OSDN Git Service

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