| OLD | NEW |
| 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2007-2009 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 int level; | 455 int level; |
| 456 | 456 |
| 457 inline void Initialize() { | 457 inline void Initialize() { |
| 458 next = limit = NULL; | 458 next = limit = NULL; |
| 459 level = 0; | 459 level = 0; |
| 460 } | 460 } |
| 461 }; | 461 }; |
| 462 | 462 |
| 463 void Leave(); | 463 void Leave(); |
| 464 | 464 |
| 465 | |
| 466 internal::Object** prev_next_; | 465 internal::Object** prev_next_; |
| 467 internal::Object** prev_limit_; | 466 internal::Object** prev_limit_; |
| 468 | 467 |
| 469 // Allow for the active closing of HandleScopes which allows to pass a handle | 468 // Allow for the active closing of HandleScopes which allows to pass a handle |
| 470 // from the HandleScope being closed to the next top most HandleScope. | 469 // from the HandleScope being closed to the next top most HandleScope. |
| 471 bool is_closed_; | 470 bool is_closed_; |
| 472 internal::Object** RawClose(internal::Object** value); | 471 internal::Object** RawClose(internal::Object** value); |
| 473 | 472 |
| 474 friend class ImplementationUtilities; | 473 friend class ImplementationUtilities; |
| 475 }; | 474 }; |
| (...skipping 2032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2508 * | 2507 * |
| 2509 * Instances of this class can be passed to v8::V8::HeapStatistics to | 2508 * Instances of this class can be passed to v8::V8::HeapStatistics to |
| 2510 * get heap statistics from V8. | 2509 * get heap statistics from V8. |
| 2511 */ | 2510 */ |
| 2512 class V8EXPORT HeapStatistics { | 2511 class V8EXPORT HeapStatistics { |
| 2513 public: | 2512 public: |
| 2514 HeapStatistics(); | 2513 HeapStatistics(); |
| 2515 size_t total_heap_size() { return total_heap_size_; } | 2514 size_t total_heap_size() { return total_heap_size_; } |
| 2516 size_t total_heap_size_executable() { return total_heap_size_executable_; } | 2515 size_t total_heap_size_executable() { return total_heap_size_executable_; } |
| 2517 size_t used_heap_size() { return used_heap_size_; } | 2516 size_t used_heap_size() { return used_heap_size_; } |
| 2517 size_t heap_size_limit() { return heap_size_limit_; } |
| 2518 | 2518 |
| 2519 private: | 2519 private: |
| 2520 void set_total_heap_size(size_t size) { total_heap_size_ = size; } | 2520 void set_total_heap_size(size_t size) { total_heap_size_ = size; } |
| 2521 void set_total_heap_size_executable(size_t size) { | 2521 void set_total_heap_size_executable(size_t size) { |
| 2522 total_heap_size_executable_ = size; | 2522 total_heap_size_executable_ = size; |
| 2523 } | 2523 } |
| 2524 void set_used_heap_size(size_t size) { used_heap_size_ = size; } | 2524 void set_used_heap_size(size_t size) { used_heap_size_ = size; } |
| 2525 void set_heap_size_limit(size_t size) { heap_size_limit_ = size; } |
| 2525 | 2526 |
| 2526 size_t total_heap_size_; | 2527 size_t total_heap_size_; |
| 2527 size_t total_heap_size_executable_; | 2528 size_t total_heap_size_executable_; |
| 2528 size_t used_heap_size_; | 2529 size_t used_heap_size_; |
| 2530 size_t heap_size_limit_; |
| 2529 | 2531 |
| 2530 friend class V8; | 2532 friend class V8; |
| 2531 }; | 2533 }; |
| 2532 | 2534 |
| 2533 | 2535 |
| 2534 /** | 2536 /** |
| 2535 * Container class for static utility functions. | 2537 * Container class for static utility functions. |
| 2536 */ | 2538 */ |
| 2537 class V8EXPORT V8 { | 2539 class V8EXPORT V8 { |
| 2538 public: | 2540 public: |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3043 const char** names_; | 3045 const char** names_; |
| 3044 }; | 3046 }; |
| 3045 | 3047 |
| 3046 | 3048 |
| 3047 /** | 3049 /** |
| 3048 * A sandboxed execution context with its own set of built-in objects | 3050 * A sandboxed execution context with its own set of built-in objects |
| 3049 * and functions. | 3051 * and functions. |
| 3050 */ | 3052 */ |
| 3051 class V8EXPORT Context { | 3053 class V8EXPORT Context { |
| 3052 public: | 3054 public: |
| 3053 /** Returns the global object of the context. */ | 3055 /** |
| 3056 * Returns the global proxy object or global object itself for |
| 3057 * detached contexts. |
| 3058 * |
| 3059 * Global proxy object is a thin wrapper whose prototype points to |
| 3060 * actual context's global object with the properties like Object, etc. |
| 3061 * This is done that way for security reasons (for more details see |
| 3062 * https://wiki.mozilla.org/Gecko:SplitWindow). |
| 3063 * |
| 3064 * Please note that changes to global proxy object prototype most probably |
| 3065 * would break VM---v8 expects only global object as a prototype of |
| 3066 * global proxy object. |
| 3067 * |
| 3068 * If DetachGlobal() has been invoked, Global() would return actual global |
| 3069 * object until global is reattached with ReattachGlobal(). |
| 3070 */ |
| 3054 Local<Object> Global(); | 3071 Local<Object> Global(); |
| 3055 | 3072 |
| 3056 /** | 3073 /** |
| 3057 * Detaches the global object from its context before | 3074 * Detaches the global object from its context before |
| 3058 * the global object can be reused to create a new context. | 3075 * the global object can be reused to create a new context. |
| 3059 */ | 3076 */ |
| 3060 void DetachGlobal(); | 3077 void DetachGlobal(); |
| 3061 | 3078 |
| 3062 /** | 3079 /** |
| 3063 * Reattaches a global object to a context. This can be used to | 3080 * Reattaches a global object to a context. This can be used to |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3343 // Tag information for HeapObject. | 3360 // Tag information for HeapObject. |
| 3344 const int kHeapObjectTag = 1; | 3361 const int kHeapObjectTag = 1; |
| 3345 const int kHeapObjectTagSize = 2; | 3362 const int kHeapObjectTagSize = 2; |
| 3346 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 3363 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
| 3347 | 3364 |
| 3348 // Tag information for Smi. | 3365 // Tag information for Smi. |
| 3349 const int kSmiTag = 0; | 3366 const int kSmiTag = 0; |
| 3350 const int kSmiTagSize = 1; | 3367 const int kSmiTagSize = 1; |
| 3351 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 3368 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
| 3352 | 3369 |
| 3353 template <size_t ptr_size> struct SmiConstants; | 3370 template <size_t ptr_size> struct SmiTagging; |
| 3354 | 3371 |
| 3355 // Smi constants for 32-bit systems. | 3372 // Smi constants for 32-bit systems. |
| 3356 template <> struct SmiConstants<4> { | 3373 template <> struct SmiTagging<4> { |
| 3357 static const int kSmiShiftSize = 0; | 3374 static const int kSmiShiftSize = 0; |
| 3358 static const int kSmiValueSize = 31; | 3375 static const int kSmiValueSize = 31; |
| 3359 static inline int SmiToInt(internal::Object* value) { | 3376 static inline int SmiToInt(internal::Object* value) { |
| 3360 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3377 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3361 // Throw away top 32 bits and shift down (requires >> to be sign extending). | 3378 // Throw away top 32 bits and shift down (requires >> to be sign extending). |
| 3362 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; | 3379 return static_cast<int>(reinterpret_cast<intptr_t>(value)) >> shift_bits; |
| 3363 } | 3380 } |
| 3381 |
| 3382 // For 32-bit systems any 2 bytes aligned pointer can be encoded as smi |
| 3383 // with a plain reinterpret_cast. |
| 3384 static const uintptr_t kEncodablePointerMask = 0x1; |
| 3385 static const int kPointerToSmiShift = 0; |
| 3364 }; | 3386 }; |
| 3365 | 3387 |
| 3366 // Smi constants for 64-bit systems. | 3388 // Smi constants for 64-bit systems. |
| 3367 template <> struct SmiConstants<8> { | 3389 template <> struct SmiTagging<8> { |
| 3368 static const int kSmiShiftSize = 31; | 3390 static const int kSmiShiftSize = 31; |
| 3369 static const int kSmiValueSize = 32; | 3391 static const int kSmiValueSize = 32; |
| 3370 static inline int SmiToInt(internal::Object* value) { | 3392 static inline int SmiToInt(internal::Object* value) { |
| 3371 int shift_bits = kSmiTagSize + kSmiShiftSize; | 3393 int shift_bits = kSmiTagSize + kSmiShiftSize; |
| 3372 // Shift down and throw away top 32 bits. | 3394 // Shift down and throw away top 32 bits. |
| 3373 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); | 3395 return static_cast<int>(reinterpret_cast<intptr_t>(value) >> shift_bits); |
| 3374 } | 3396 } |
| 3397 |
| 3398 // To maximize the range of pointers that can be encoded |
| 3399 // in the available 32 bits, we require them to be 8 bytes aligned. |
| 3400 // This gives 2 ^ (32 + 3) = 32G address space covered. |
| 3401 // It might be not enough to cover stack allocated objects on some platforms. |
| 3402 static const int kPointerAlignment = 3; |
| 3403 |
| 3404 static const uintptr_t kEncodablePointerMask = |
| 3405 ~(uintptr_t(0xffffffff) << kPointerAlignment); |
| 3406 |
| 3407 static const int kPointerToSmiShift = |
| 3408 kSmiTagSize + kSmiShiftSize - kPointerAlignment; |
| 3375 }; | 3409 }; |
| 3376 | 3410 |
| 3377 const int kSmiShiftSize = SmiConstants<kApiPointerSize>::kSmiShiftSize; | 3411 typedef SmiTagging<kApiPointerSize> PlatformSmiTagging; |
| 3378 const int kSmiValueSize = SmiConstants<kApiPointerSize>::kSmiValueSize; | 3412 const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize; |
| 3413 const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize; |
| 3414 const uintptr_t kEncodablePointerMask = |
| 3415 PlatformSmiTagging::kEncodablePointerMask; |
| 3416 const int kPointerToSmiShift = PlatformSmiTagging::kPointerToSmiShift; |
| 3379 | 3417 |
| 3380 template <size_t ptr_size> struct InternalConstants; | 3418 template <size_t ptr_size> struct InternalConstants; |
| 3381 | 3419 |
| 3382 // Internal constants for 32-bit systems. | 3420 // Internal constants for 32-bit systems. |
| 3383 template <> struct InternalConstants<4> { | 3421 template <> struct InternalConstants<4> { |
| 3384 static const int kStringResourceOffset = 3 * kApiPointerSize; | 3422 static const int kStringResourceOffset = 3 * kApiPointerSize; |
| 3385 }; | 3423 }; |
| 3386 | 3424 |
| 3387 // Internal constants for 64-bit systems. | 3425 // Internal constants for 64-bit systems. |
| 3388 template <> struct InternalConstants<8> { | 3426 template <> struct InternalConstants<8> { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3402 static const int kHeapObjectMapOffset = 0; | 3440 static const int kHeapObjectMapOffset = 0; |
| 3403 static const int kMapInstanceTypeOffset = kApiPointerSize + kApiIntSize; | 3441 static const int kMapInstanceTypeOffset = kApiPointerSize + kApiIntSize; |
| 3404 static const int kStringResourceOffset = | 3442 static const int kStringResourceOffset = |
| 3405 InternalConstants<kApiPointerSize>::kStringResourceOffset; | 3443 InternalConstants<kApiPointerSize>::kStringResourceOffset; |
| 3406 | 3444 |
| 3407 static const int kProxyProxyOffset = kApiPointerSize; | 3445 static const int kProxyProxyOffset = kApiPointerSize; |
| 3408 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 3446 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
| 3409 static const int kFullStringRepresentationMask = 0x07; | 3447 static const int kFullStringRepresentationMask = 0x07; |
| 3410 static const int kExternalTwoByteRepresentationTag = 0x02; | 3448 static const int kExternalTwoByteRepresentationTag = 0x02; |
| 3411 | 3449 |
| 3412 static const int kJSObjectType = 0x9f; | 3450 static const int kJSObjectType = 0xa0; |
| 3413 static const int kFirstNonstringType = 0x80; | 3451 static const int kFirstNonstringType = 0x80; |
| 3414 static const int kProxyType = 0x85; | 3452 static const int kProxyType = 0x85; |
| 3415 | 3453 |
| 3416 static inline bool HasHeapObjectTag(internal::Object* value) { | 3454 static inline bool HasHeapObjectTag(internal::Object* value) { |
| 3417 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 3455 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
| 3418 kHeapObjectTag); | 3456 kHeapObjectTag); |
| 3419 } | 3457 } |
| 3420 | 3458 |
| 3421 static inline bool HasSmiTag(internal::Object* value) { | 3459 static inline bool HasSmiTag(internal::Object* value) { |
| 3422 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); | 3460 return ((reinterpret_cast<intptr_t>(value) & kSmiTagMask) == kSmiTag); |
| 3423 } | 3461 } |
| 3424 | 3462 |
| 3425 static inline int SmiValue(internal::Object* value) { | 3463 static inline int SmiValue(internal::Object* value) { |
| 3426 return SmiConstants<kApiPointerSize>::SmiToInt(value); | 3464 return PlatformSmiTagging::SmiToInt(value); |
| 3427 } | 3465 } |
| 3428 | 3466 |
| 3429 static inline int GetInstanceType(internal::Object* obj) { | 3467 static inline int GetInstanceType(internal::Object* obj) { |
| 3430 typedef internal::Object O; | 3468 typedef internal::Object O; |
| 3431 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); | 3469 O* map = ReadField<O*>(obj, kHeapObjectMapOffset); |
| 3432 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); | 3470 return ReadField<uint8_t>(map, kMapInstanceTypeOffset); |
| 3433 } | 3471 } |
| 3434 | 3472 |
| 3473 static inline void* GetExternalPointerFromSmi(internal::Object* value) { |
| 3474 const uintptr_t address = reinterpret_cast<uintptr_t>(value); |
| 3475 return reinterpret_cast<void*>(address >> kPointerToSmiShift); |
| 3476 } |
| 3477 |
| 3435 static inline void* GetExternalPointer(internal::Object* obj) { | 3478 static inline void* GetExternalPointer(internal::Object* obj) { |
| 3436 if (HasSmiTag(obj)) { | 3479 if (HasSmiTag(obj)) { |
| 3437 return obj; | 3480 return GetExternalPointerFromSmi(obj); |
| 3438 } else if (GetInstanceType(obj) == kProxyType) { | 3481 } else if (GetInstanceType(obj) == kProxyType) { |
| 3439 return ReadField<void*>(obj, kProxyProxyOffset); | 3482 return ReadField<void*>(obj, kProxyProxyOffset); |
| 3440 } else { | 3483 } else { |
| 3441 return NULL; | 3484 return NULL; |
| 3442 } | 3485 } |
| 3443 } | 3486 } |
| 3444 | 3487 |
| 3445 static inline bool IsExternalTwoByteString(int instance_type) { | 3488 static inline bool IsExternalTwoByteString(int instance_type) { |
| 3446 int representation = (instance_type & kFullStringRepresentationMask); | 3489 int representation = (instance_type & kFullStringRepresentationMask); |
| 3447 return representation == kExternalTwoByteRepresentationTag; | 3490 return representation == kExternalTwoByteRepresentationTag; |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3794 | 3837 |
| 3795 | 3838 |
| 3796 } // namespace v8 | 3839 } // namespace v8 |
| 3797 | 3840 |
| 3798 | 3841 |
| 3799 #undef V8EXPORT | 3842 #undef V8EXPORT |
| 3800 #undef TYPE_CHECK | 3843 #undef TYPE_CHECK |
| 3801 | 3844 |
| 3802 | 3845 |
| 3803 #endif // V8_H_ | 3846 #endif // V8_H_ |
| OLD | NEW |