説明を見る。00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #ifdef WIN32
00034 typedef signed char int8_t;
00035 typedef unsigned char uint8_t;
00036 typedef short int16_t;
00037 typedef unsigned short uint16_t;
00038 typedef int int32_t;
00039 typedef unsigned int uint32_t;
00040 typedef __int64 int64_t;
00041 typedef unsigned __int64 uint64_t;
00042 #else
00043 #include <stdint.h>
00044 #endif
00045
00046
00047 namespace v8 { namespace internal {
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061 #ifndef V8_GLOBALS_H_
00062 #define V8_GLOBALS_H_
00063
00064 #ifdef USE_MYBOOL
00065 typedef unsigned int __my_bool__;
00066 #define bool __my_bool__ // use 'indirection' to avoid name clashes
00067 #endif
00068
00069 typedef uint8_t byte;
00070 typedef byte* Address;
00071
00072
00073 typedef uint16_t uc16;
00074 typedef signed int uc32;
00075
00076 #ifndef ARM
00077 #define CAN_READ_UNALIGNED 1
00078 #endif
00079
00080
00081
00082
00083 #ifdef DEBUG
00084 const bool kDebug = true;
00085 #else
00086 const bool kDebug = false;
00087 #endif // DEBUG
00088
00089 const int KB = 1024;
00090 const int MB = KB * KB;
00091 const int GB = KB * KB * KB;
00092 const int kMaxInt = 0x7FFFFFFF;
00093 const int kMinInt = -kMaxInt - 1;
00094
00095 const int kCharSize = sizeof(char);
00096 const int kShortSize = sizeof(short);
00097 const int kIntSize = sizeof(int);
00098 const int kDoubleSize = sizeof(double);
00099 const int kPointerSize = sizeof(void*);
00100
00101 const int kPointerSizeLog2 = 2;
00102
00103 const int kObjectAlignmentBits = 2;
00104 const int kObjectAlignmentMask = (1 << kObjectAlignmentBits) - 1;
00105 const int kObjectAlignment = 1 << kObjectAlignmentBits;
00106
00107
00108
00109 const int kHeapObjectTag = 1;
00110 const int kHeapObjectTagSize = 2;
00111 const int kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
00112
00113
00114
00115 const int kSmiTag = 0;
00116 const int kSmiTagSize = 1;
00117 const int kSmiTagMask = (1 << kSmiTagSize) - 1;
00118
00119
00120
00121 const int kFailureTag = 3;
00122 const int kFailureTagSize = 2;
00123 const int kFailureTagMask = (1 << kFailureTagSize) - 1;
00124
00125
00126 const int kBitsPerByte = 8;
00127 const int kBitsPerByteLog2 = 3;
00128 const int kBitsPerPointer = kPointerSize * kBitsPerByte;
00129 const int kBitsPerInt = kIntSize * kBitsPerByte;
00130
00131
00132
00133
00134 const Address kZapValue = reinterpret_cast<Address>(0xdeadbeed);
00135 const Address kHandleZapValue = reinterpret_cast<Address>(0xbaddead);
00136 const Address kFromSpaceZapValue = reinterpret_cast<Address>(0xbeefdad);
00137
00138
00139
00140
00141
00142 class AccessorInfo;
00143 class Allocation;
00144 class Assembler;
00145 class BreakableStatement;
00146 class Code;
00147 class CodeGenerator;
00148 class CodeStub;
00149 class Context;
00150 class Debug;
00151 class Debugger;
00152 class DebugInfo;
00153 class Descriptor;
00154 class DescriptorArray;
00155 class Expression;
00156 class ExternalReference;
00157 class FixedArray;
00158 class FunctionEntry;
00159 class FunctionLiteral;
00160 class FunctionTemplateInfo;
00161 class Dictionary;
00162 class FreeStoreAllocationPolicy;
00163 template <typename T> class Handle;
00164 class Heap;
00165 class HeapObject;
00166 class IC;
00167 class InterceptorInfo;
00168 class IterationStatement;
00169 class JSArray;
00170 class JSFunction;
00171 class JSObject;
00172 class LabelCollector;
00173 class LargeObjectSpace;
00174 template <typename T, class P = FreeStoreAllocationPolicy> class List;
00175 class LookupResult;
00176 class MacroAssembler;
00177 class Map;
00178 class MapSpace;
00179 class MarkCompactCollector;
00180 class NewSpace;
00181 class Object;
00182 class OldSpace;
00183 class Property;
00184 class Proxy;
00185 class Scope;
00186 template<class Allocator = FreeStoreAllocationPolicy> class ScopeInfo;
00187 class Script;
00188 class Slot;
00189 class Smi;
00190 class Statement;
00191 class String;
00192 class Struct;
00193 class SwitchStatement;
00194 class Visitor;
00195 class Variable;
00196 class VariableProxy;
00197 class RelocInfo;
00198 class Deserializer;
00199 class MessageLocation;
00200 class ObjectGroup;
00201 class TickSample;
00202 class VirtualMemory;
00203 class Mutex;
00204
00205 typedef bool (*WeakSlotCallback)(Object** pointer);
00206
00207
00208
00209
00210
00211
00212 enum AllocationSpace {
00213 NEW_SPACE,
00214 OLD_POINTER_SPACE,
00215 OLD_DATA_SPACE,
00216 CODE_SPACE,
00217 MAP_SPACE,
00218 LO_SPACE,
00219 FIRST_SPACE = NEW_SPACE,
00220 LAST_SPACE = LO_SPACE
00221 };
00222 const int kSpaceTagSize = 3;
00223 const int kSpaceTagMask = (1 << kSpaceTagSize) - 1;
00224
00225
00226
00227
00228
00229
00230 enum PretenureFlag { NOT_TENURED, TENURED };
00231
00232 enum GarbageCollector { SCAVENGER, MARK_COMPACTOR };
00233
00234 enum Executability { NOT_EXECUTABLE, EXECUTABLE };
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251 struct CodeDesc {
00252 byte* buffer;
00253 int buffer_size;
00254 int instr_size;
00255 int reloc_size;
00256 };
00257
00258
00259
00260
00261
00262 typedef void (*ObjectSlotCallback)(HeapObject** pointer);
00263
00264
00265
00266
00267 typedef int (*HeapObjectCallback)(HeapObject* obj);
00268
00269
00270
00271
00272
00273 typedef bool (*ConstraintCallback)(Address new_addr, Address old_addr);
00274
00275
00276
00277
00278 typedef void (*InlineCacheCallback)(Code* code, Address ic);
00279
00280
00281
00282 enum InlineCacheState {
00283
00284 UNINITIALIZED,
00285
00286 PREMONOMORPHIC,
00287
00288 MONOMORPHIC,
00289
00290 MONOMORPHIC_PROTOTYPE_FAILURE,
00291
00292 MEGAMORPHIC,
00293
00294 DEBUG_BREAK,
00295 DEBUG_PREPARE_STEP_IN
00296 };
00297
00298
00299
00300
00301
00302
00303 enum PropertyType {
00304 NORMAL = 0,
00305 FIELD = 1,
00306 CONSTANT_FUNCTION = 2,
00307 CALLBACKS = 3,
00308 INTERCEPTOR = 4,
00309 MAP_TRANSITION = 5,
00310 CONSTANT_TRANSITION = 6,
00311 NULL_DESCRIPTOR = 7,
00312
00313 FIRST_PHANTOM_PROPERTY_TYPE = MAP_TRANSITION
00314 };
00315
00316
00317
00318
00319 enum TransitionFlag {
00320 REMOVE_TRANSITIONS,
00321 KEEP_TRANSITIONS
00322 };
00323
00324
00325
00326 union DoubleRepresentation {
00327 double value;
00328 int64_t bits;
00329 DoubleRepresentation(double x) { value = x; }
00330 };
00331
00332
00333
00334 struct AccessorDescriptor {
00335 Object* (*getter)(Object* object, void* data);
00336 Object* (*setter)(JSObject* object, Object* value, void* data);
00337 void* data;
00338 };
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348 #define STATE_TAG_LIST(V) \
00349 V(JS) \
00350 V(GC) \
00351 V(COMPILER) \
00352 V(OTHER)
00353
00354 enum StateTag {
00355 #define DEF_STATE_TAG(name) name,
00356 STATE_TAG_LIST(DEF_STATE_TAG)
00357 #undef DEF_STATE_TAG
00358
00359 state_tag_count
00360 };
00361
00362
00363
00364
00365
00366
00367
00368 #define HAS_SMI_TAG(value) \
00369 ((reinterpret_cast<int>(value) & kSmiTagMask) == kSmiTag)
00370
00371 #define HAS_FAILURE_TAG(value) \
00372 ((reinterpret_cast<int>(value) & kFailureTagMask) == kFailureTag)
00373
00374 #define HAS_HEAP_OBJECT_TAG(value) \
00375 ((reinterpret_cast<int>(value) & kHeapObjectTagMask) == kHeapObjectTag)
00376
00377
00378 #define OBJECT_SIZE_ALIGN(value) \
00379 ((value + kObjectAlignmentMask) & ~kObjectAlignmentMask)
00380
00381
00382
00383
00384
00385
00386
00387 #define OFFSET_OF(type, field) \
00388 (reinterpret_cast<intptr_t>(&(reinterpret_cast<type*>(4)->field)) - 4)
00389
00390
00391
00392
00393
00394
00395 #define ARRAY_SIZE(a) \
00396 ((sizeof(a) / sizeof(*(a))) / \
00397 static_cast<size_t>(!(sizeof(a) % sizeof(*(a)))))
00398
00399
00400
00401
00402 template <typename T>
00403 static inline void USE(T) { }
00404
00405
00406
00407 #define FUNCTION_ADDR(f) \
00408 (reinterpret_cast<v8::internal::Address>(reinterpret_cast<intptr_t>(f)))
00409
00410
00411
00412
00413 template <typename F>
00414 F FUNCTION_CAST(Address addr) {
00415 return reinterpret_cast<F>(reinterpret_cast<intptr_t>(addr));
00416 }
00417
00418
00419
00420
00421 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
00422 TypeName(const TypeName&); \
00423 void operator=(const TypeName&)
00424
00425
00426
00427
00428
00429
00430
00431
00432 #define DISALLOW_IMPLICIT_CONSTRUCTORS(TypeName) \
00433 TypeName(); \
00434 DISALLOW_COPY_AND_ASSIGN(TypeName)
00435
00436
00437
00438
00439
00440
00441
00442 #ifdef DEBUG
00443 #define TRACK_MEMORY(name) \
00444 void* operator new(size_t size) { \
00445 void* result = ::operator new(size); \
00446 Logger::NewEvent(name, result, size); \
00447 return result; \
00448 } \
00449 void operator delete(void* object) { \
00450 Logger::DeleteEvent(name, object); \
00451 ::operator delete(object); \
00452 }
00453 #else
00454 #define TRACK_MEMORY(name)
00455 #endif
00456
00457
00458 #ifdef __GNUC__
00459 #if (__GNUC__ >= 4)
00460 #define INLINE(header) inline header __attribute__((always_inline))
00461 #else
00462 #define INLINE(header) inline __attribute__((always_inline)) header
00463 #endif
00464 #else
00465 #define INLINE(header) inline header
00466 #endif
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492 template <class Dest, class Source>
00493 inline Dest bit_cast(const Source& source) {
00494
00495
00496 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1];
00497
00498 Dest dest;
00499 memcpy(&dest, &source, sizeof(dest));
00500 return dest;
00501 }
00502
00503
00504 } }
00505
00506 #endif // V8_GLOBALS_H_