OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 4041 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4052 */ | 4052 */ |
4053 void Exit(); | 4053 void Exit(); |
4054 | 4054 |
4055 /** | 4055 /** |
4056 * Disposes the isolate. The isolate must not be entered by any | 4056 * Disposes the isolate. The isolate must not be entered by any |
4057 * thread to be disposable. | 4057 * thread to be disposable. |
4058 */ | 4058 */ |
4059 void Dispose(); | 4059 void Dispose(); |
4060 | 4060 |
4061 /** | 4061 /** |
4062 * Associate embedder-specific data with the isolate. This legacy method | 4062 * Associate embedder-specific data with the isolate |
4063 * puts the data in the 0th slot. It will be deprecated soon. | |
4064 */ | 4063 */ |
4065 V8_INLINE void SetData(void* data); | 4064 V8_INLINE void SetData(void* data); |
4066 | 4065 |
4067 /** | 4066 /** |
4068 * Associate embedder-specific data with the isolate. |slot| has to be | 4067 * Retrieve embedder-specific data from the isolate. |
4069 * between 0 and GetNumberOfDataSlots() - 1. | |
4070 */ | |
4071 V8_INLINE void SetData(uint32_t slot, void* data); | |
4072 | |
4073 /** | |
4074 * Retrieve embedder-specific data from the isolate. This legacy method | |
4075 * retrieves the data from slot 0. It will be deprecated soon. | |
4076 * Returns NULL if SetData has never been called. | 4068 * Returns NULL if SetData has never been called. |
4077 */ | 4069 */ |
4078 V8_INLINE void* GetData(); | 4070 V8_INLINE void* GetData(); |
4079 | 4071 |
4080 /** | 4072 /** |
4081 * Retrieve embedder-specific data from the isolate. | |
4082 * Returns NULL if SetData has never been called for the given |slot|. | |
4083 */ | |
4084 V8_INLINE void* GetData(uint32_t slot); | |
4085 | |
4086 /** | |
4087 * Returns the maximum number of available embedder data slots. Valid slots | |
4088 * are in the range of 0 - GetNumberOfDataSlots() - 1. | |
4089 */ | |
4090 V8_INLINE static uint32_t GetNumberOfDataSlots(); | |
4091 | |
4092 /** | |
4093 * Get statistics about the heap memory usage. | 4073 * Get statistics about the heap memory usage. |
4094 */ | 4074 */ |
4095 void GetHeapStatistics(HeapStatistics* heap_statistics); | 4075 void GetHeapStatistics(HeapStatistics* heap_statistics); |
4096 | 4076 |
4097 /** | 4077 /** |
4098 * Adjusts the amount of registered external memory. Used to give V8 an | 4078 * Adjusts the amount of registered external memory. Used to give V8 an |
4099 * indication of the amount of externally allocated memory that is kept alive | 4079 * indication of the amount of externally allocated memory that is kept alive |
4100 * by JavaScript objects. V8 uses this to decide when to perform global | 4080 * by JavaScript objects. V8 uses this to decide when to perform global |
4101 * garbage collections. Registering externally allocated memory will trigger | 4081 * garbage collections. Registering externally allocated memory will trigger |
4102 * global garbage collections more often than it would otherwise in an attempt | 4082 * global garbage collections more often than it would otherwise in an attempt |
(...skipping 1364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5467 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 5447 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
5468 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; | 5448 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
5469 static const int kContextHeaderSize = 2 * kApiPointerSize; | 5449 static const int kContextHeaderSize = 2 * kApiPointerSize; |
5470 static const int kContextEmbedderDataIndex = 65; | 5450 static const int kContextEmbedderDataIndex = 65; |
5471 static const int kFullStringRepresentationMask = 0x07; | 5451 static const int kFullStringRepresentationMask = 0x07; |
5472 static const int kStringEncodingMask = 0x4; | 5452 static const int kStringEncodingMask = 0x4; |
5473 static const int kExternalTwoByteRepresentationTag = 0x02; | 5453 static const int kExternalTwoByteRepresentationTag = 0x02; |
5474 static const int kExternalAsciiRepresentationTag = 0x06; | 5454 static const int kExternalAsciiRepresentationTag = 0x06; |
5475 | 5455 |
5476 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; | 5456 static const int kIsolateEmbedderDataOffset = 1 * kApiPointerSize; |
5477 static const int kIsolateRootsOffset = 6 * kApiPointerSize; | 5457 static const int kIsolateRootsOffset = 3 * kApiPointerSize; |
5478 static const int kUndefinedValueRootIndex = 5; | 5458 static const int kUndefinedValueRootIndex = 5; |
5479 static const int kNullValueRootIndex = 7; | 5459 static const int kNullValueRootIndex = 7; |
5480 static const int kTrueValueRootIndex = 8; | 5460 static const int kTrueValueRootIndex = 8; |
5481 static const int kFalseValueRootIndex = 9; | 5461 static const int kFalseValueRootIndex = 9; |
5482 static const int kEmptyStringRootIndex = 134; | 5462 static const int kEmptyStringRootIndex = 134; |
5483 | 5463 |
5484 static const int kNodeClassIdOffset = 1 * kApiPointerSize; | 5464 static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
5485 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; | 5465 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
5486 static const int kNodeStateMask = 0xf; | 5466 static const int kNodeStateMask = 0xf; |
5487 static const int kNodeStateIsWeakValue = 2; | 5467 static const int kNodeStateIsWeakValue = 2; |
5488 static const int kNodeStateIsPendingValue = 3; | 5468 static const int kNodeStateIsPendingValue = 3; |
5489 static const int kNodeStateIsNearDeathValue = 4; | 5469 static const int kNodeStateIsNearDeathValue = 4; |
5490 static const int kNodeIsIndependentShift = 4; | 5470 static const int kNodeIsIndependentShift = 4; |
5491 static const int kNodeIsPartiallyDependentShift = 5; | 5471 static const int kNodeIsPartiallyDependentShift = 5; |
5492 | 5472 |
5493 static const int kJSObjectType = 0xb2; | 5473 static const int kJSObjectType = 0xb2; |
5494 static const int kFirstNonstringType = 0x80; | 5474 static const int kFirstNonstringType = 0x80; |
5495 static const int kOddballType = 0x83; | 5475 static const int kOddballType = 0x83; |
5496 static const int kForeignType = 0x87; | 5476 static const int kForeignType = 0x87; |
5497 | 5477 |
5498 static const int kUndefinedOddballKind = 5; | 5478 static const int kUndefinedOddballKind = 5; |
5499 static const int kNullOddballKind = 3; | 5479 static const int kNullOddballKind = 3; |
5500 | 5480 |
5501 static const uint32_t kNumIsolateDataSlots = 4; | |
5502 | |
5503 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); | 5481 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate); |
5504 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { | 5482 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) { |
5505 #ifdef V8_ENABLE_CHECKS | 5483 #ifdef V8_ENABLE_CHECKS |
5506 CheckInitializedImpl(isolate); | 5484 CheckInitializedImpl(isolate); |
5507 #endif | 5485 #endif |
5508 } | 5486 } |
5509 | 5487 |
5510 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { | 5488 V8_INLINE static bool HasHeapObjectTag(internal::Object* value) { |
5511 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == | 5489 return ((reinterpret_cast<intptr_t>(value) & kHeapObjectTagMask) == |
5512 kHeapObjectTag); | 5490 kHeapObjectTag); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5556 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 5534 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
5557 return *addr & kNodeStateMask; | 5535 return *addr & kNodeStateMask; |
5558 } | 5536 } |
5559 | 5537 |
5560 V8_INLINE static void UpdateNodeState(internal::Object** obj, | 5538 V8_INLINE static void UpdateNodeState(internal::Object** obj, |
5561 uint8_t value) { | 5539 uint8_t value) { |
5562 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; | 5540 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset; |
5563 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); | 5541 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value); |
5564 } | 5542 } |
5565 | 5543 |
5566 V8_INLINE static void SetEmbedderData(v8::Isolate *isolate, | 5544 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, void* data) { |
5567 uint32_t slot, | 5545 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
5568 void *data) { | 5546 kIsolateEmbedderDataOffset; |
5569 uint8_t *addr = reinterpret_cast<uint8_t *>(isolate) + | |
5570 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | |
5571 *reinterpret_cast<void**>(addr) = data; | 5547 *reinterpret_cast<void**>(addr) = data; |
5572 } | 5548 } |
5573 | 5549 |
5574 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate, uint32_t slot) { | 5550 V8_INLINE static void* GetEmbedderData(v8::Isolate* isolate) { |
5575 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + | 5551 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + |
5576 kIsolateEmbedderDataOffset + slot * kApiPointerSize; | 5552 kIsolateEmbedderDataOffset; |
5577 return *reinterpret_cast<void**>(addr); | 5553 return *reinterpret_cast<void**>(addr); |
5578 } | 5554 } |
5579 | 5555 |
5580 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, | 5556 V8_INLINE static internal::Object** GetRoot(v8::Isolate* isolate, |
5581 int index) { | 5557 int index) { |
5582 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; | 5558 uint8_t* addr = reinterpret_cast<uint8_t*>(isolate) + kIsolateRootsOffset; |
5583 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); | 5559 return reinterpret_cast<internal::Object**>(addr + index * kApiPointerSize); |
5584 } | 5560 } |
5585 | 5561 |
5586 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) { | 5562 template <typename T> V8_INLINE static T ReadField(Object* ptr, int offset) { |
(...skipping 905 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6492 typedef internal::Object* S; | 6468 typedef internal::Object* S; |
6493 typedef internal::Internals I; | 6469 typedef internal::Internals I; |
6494 I::CheckInitialized(isolate); | 6470 I::CheckInitialized(isolate); |
6495 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); | 6471 S* slot = I::GetRoot(isolate, I::kFalseValueRootIndex); |
6496 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); | 6472 return Handle<Boolean>(reinterpret_cast<Boolean*>(slot)); |
6497 } | 6473 } |
6498 | 6474 |
6499 | 6475 |
6500 void Isolate::SetData(void* data) { | 6476 void Isolate::SetData(void* data) { |
6501 typedef internal::Internals I; | 6477 typedef internal::Internals I; |
6502 I::SetEmbedderData(this, 0, data); | 6478 I::SetEmbedderData(this, data); |
6503 } | 6479 } |
6504 | 6480 |
6505 | 6481 |
6506 void* Isolate::GetData() { | 6482 void* Isolate::GetData() { |
6507 typedef internal::Internals I; | 6483 typedef internal::Internals I; |
6508 return I::GetEmbedderData(this, 0); | 6484 return I::GetEmbedderData(this); |
6509 } | 6485 } |
6510 | 6486 |
6511 | 6487 |
6512 void Isolate::SetData(uint32_t slot, void* data) { | |
6513 typedef internal::Internals I; | |
6514 I::SetEmbedderData(this, slot, data); | |
6515 } | |
6516 | |
6517 | |
6518 void* Isolate::GetData(uint32_t slot) { | |
6519 typedef internal::Internals I; | |
6520 return I::GetEmbedderData(this, slot); | |
6521 } | |
6522 | |
6523 | |
6524 uint32_t Isolate::GetNumberOfDataSlots() { | |
6525 typedef internal::Internals I; | |
6526 return I::kNumIsolateDataSlots; | |
6527 } | |
6528 | |
6529 | |
6530 template<typename T> | 6488 template<typename T> |
6531 void Isolate::SetObjectGroupId(const Persistent<T>& object, | 6489 void Isolate::SetObjectGroupId(const Persistent<T>& object, |
6532 UniqueId id) { | 6490 UniqueId id) { |
6533 TYPE_CHECK(Value, T); | 6491 TYPE_CHECK(Value, T); |
6534 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); | 6492 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); |
6535 } | 6493 } |
6536 | 6494 |
6537 | 6495 |
6538 template<typename T> | 6496 template<typename T> |
6539 void Isolate::SetReferenceFromGroup(UniqueId id, | 6497 void Isolate::SetReferenceFromGroup(UniqueId id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6591 */ | 6549 */ |
6592 | 6550 |
6593 | 6551 |
6594 } // namespace v8 | 6552 } // namespace v8 |
6595 | 6553 |
6596 | 6554 |
6597 #undef TYPE_CHECK | 6555 #undef TYPE_CHECK |
6598 | 6556 |
6599 | 6557 |
6600 #endif // V8_H_ | 6558 #endif // V8_H_ |
OLD | NEW |