OLD | NEW |
---|---|
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 /** \mainpage V8 API Reference Guide | 5 /** \mainpage V8 API Reference Guide |
6 * | 6 * |
7 * V8 is Google's open source JavaScript engine. | 7 * V8 is Google's open source JavaScript engine. |
8 * | 8 * |
9 * This set of documents provides reference material generated from the | 9 * This set of documents provides reference material generated from the |
10 * V8 header file, include/v8.h. | 10 * V8 header file, include/v8.h. |
(...skipping 4197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4208 * by JavaScript objects. V8 uses this to decide when to perform global | 4208 * by JavaScript objects. V8 uses this to decide when to perform global |
4209 * garbage collections. Registering externally allocated memory will trigger | 4209 * garbage collections. Registering externally allocated memory will trigger |
4210 * global garbage collections more often than it would otherwise in an attempt | 4210 * global garbage collections more often than it would otherwise in an attempt |
4211 * to garbage collect the JavaScript objects that keep the externally | 4211 * to garbage collect the JavaScript objects that keep the externally |
4212 * allocated memory alive. | 4212 * allocated memory alive. |
4213 * | 4213 * |
4214 * \param change_in_bytes the change in externally allocated memory that is | 4214 * \param change_in_bytes the change in externally allocated memory that is |
4215 * kept alive by JavaScript objects. | 4215 * kept alive by JavaScript objects. |
4216 * \returns the adjusted value. | 4216 * \returns the adjusted value. |
4217 */ | 4217 */ |
4218 int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); | 4218 V8_INLINE int64_t |
4219 AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); | |
4219 | 4220 |
4220 /** | 4221 /** |
4221 * Returns heap profiler for this isolate. Will return NULL until the isolate | 4222 * Returns heap profiler for this isolate. Will return NULL until the isolate |
4222 * is initialized. | 4223 * is initialized. |
4223 */ | 4224 */ |
4224 HeapProfiler* GetHeapProfiler(); | 4225 HeapProfiler* GetHeapProfiler(); |
4225 | 4226 |
4226 /** | 4227 /** |
4227 * Returns CPU profiler for this isolate. Will return NULL unless the isolate | 4228 * Returns CPU profiler for this isolate. Will return NULL unless the isolate |
4228 * is initialized. It is the embedder's responsibility to stop all CPU | 4229 * is initialized. It is the embedder's responsibility to stop all CPU |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4411 Isolate(); | 4412 Isolate(); |
4412 Isolate(const Isolate&); | 4413 Isolate(const Isolate&); |
4413 ~Isolate(); | 4414 ~Isolate(); |
4414 Isolate& operator=(const Isolate&); | 4415 Isolate& operator=(const Isolate&); |
4415 void* operator new(size_t size); | 4416 void* operator new(size_t size); |
4416 void operator delete(void*, size_t); | 4417 void operator delete(void*, size_t); |
4417 | 4418 |
4418 void SetObjectGroupId(internal::Object** object, UniqueId id); | 4419 void SetObjectGroupId(internal::Object** object, UniqueId id); |
4419 void SetReferenceFromGroup(UniqueId id, internal::Object** object); | 4420 void SetReferenceFromGroup(UniqueId id, internal::Object** object); |
4420 void SetReference(internal::Object** parent, internal::Object** child); | 4421 void SetReference(internal::Object** parent, internal::Object** child); |
4422 int64_t SlowAdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes); | |
4421 }; | 4423 }; |
4422 | 4424 |
4423 class V8_EXPORT StartupData { | 4425 class V8_EXPORT StartupData { |
4424 public: | 4426 public: |
4425 enum CompressionAlgorithm { | 4427 enum CompressionAlgorithm { |
4426 kUncompressed, | 4428 kUncompressed, |
4427 kBZip2 | 4429 kBZip2 |
4428 }; | 4430 }; |
4429 | 4431 |
4430 const char* data; | 4432 const char* data; |
(...skipping 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5457 }; | 5459 }; |
5458 | 5460 |
5459 | 5461 |
5460 // --- Implementation --- | 5462 // --- Implementation --- |
5461 | 5463 |
5462 | 5464 |
5463 namespace internal { | 5465 namespace internal { |
5464 | 5466 |
5465 const int kApiPointerSize = sizeof(void*); // NOLINT | 5467 const int kApiPointerSize = sizeof(void*); // NOLINT |
5466 const int kApiIntSize = sizeof(int); // NOLINT | 5468 const int kApiIntSize = sizeof(int); // NOLINT |
5469 const int kApiInt64Size = sizeof(int64_t); // NOLINT | |
5467 | 5470 |
5468 // Tag information for HeapObject. | 5471 // Tag information for HeapObject. |
5469 const int kHeapObjectTag = 1; | 5472 const int kHeapObjectTag = 1; |
5470 const int kHeapObjectTagSize = 2; | 5473 const int kHeapObjectTagSize = 2; |
5471 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; | 5474 const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1; |
5472 | 5475 |
5473 // Tag information for Smi. | 5476 // Tag information for Smi. |
5474 const int kSmiTag = 0; | 5477 const int kSmiTag = 0; |
5475 const int kSmiTagSize = 1; | 5478 const int kSmiTagSize = 1; |
5476 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; | 5479 const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1; |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5555 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; | 5558 static const int kJSObjectHeaderSize = 3 * kApiPointerSize; |
5556 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; | 5559 static const int kFixedArrayHeaderSize = 2 * kApiPointerSize; |
5557 static const int kContextHeaderSize = 2 * kApiPointerSize; | 5560 static const int kContextHeaderSize = 2 * kApiPointerSize; |
5558 static const int kContextEmbedderDataIndex = 75; | 5561 static const int kContextEmbedderDataIndex = 75; |
5559 static const int kFullStringRepresentationMask = 0x07; | 5562 static const int kFullStringRepresentationMask = 0x07; |
5560 static const int kStringEncodingMask = 0x4; | 5563 static const int kStringEncodingMask = 0x4; |
5561 static const int kExternalTwoByteRepresentationTag = 0x02; | 5564 static const int kExternalTwoByteRepresentationTag = 0x02; |
5562 static const int kExternalAsciiRepresentationTag = 0x06; | 5565 static const int kExternalAsciiRepresentationTag = 0x06; |
5563 | 5566 |
5564 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; | 5567 static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize; |
5565 static const int kIsolateRootsOffset = 5 * kApiPointerSize; | 5568 static const int kAmountOfExternalAllocatedMemoryOffset = 5 * kApiPointerSize; |
5569 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset = | |
5570 5 * kApiPointerSize + kApiInt64Size; | |
5571 static const int kIsolateRootsOffset = | |
5572 5 * kApiPointerSize + 2 * kApiInt64Size; | |
5566 static const int kUndefinedValueRootIndex = 5; | 5573 static const int kUndefinedValueRootIndex = 5; |
5567 static const int kNullValueRootIndex = 7; | 5574 static const int kNullValueRootIndex = 7; |
5568 static const int kTrueValueRootIndex = 8; | 5575 static const int kTrueValueRootIndex = 8; |
5569 static const int kFalseValueRootIndex = 9; | 5576 static const int kFalseValueRootIndex = 9; |
5570 static const int kEmptyStringRootIndex = 162; | 5577 static const int kEmptyStringRootIndex = 162; |
5571 | 5578 |
5572 static const int kNodeClassIdOffset = 1 * kApiPointerSize; | 5579 static const int kNodeClassIdOffset = 1 * kApiPointerSize; |
5573 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; | 5580 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; |
5574 static const int kNodeStateMask = 0xf; | 5581 static const int kNodeStateMask = 0xf; |
5575 static const int kNodeStateIsWeakValue = 2; | 5582 static const int kNodeStateIsWeakValue = 2; |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6581 return I::GetEmbedderData(this, slot); | 6588 return I::GetEmbedderData(this, slot); |
6582 } | 6589 } |
6583 | 6590 |
6584 | 6591 |
6585 uint32_t Isolate::GetNumberOfDataSlots() { | 6592 uint32_t Isolate::GetNumberOfDataSlots() { |
6586 typedef internal::Internals I; | 6593 typedef internal::Internals I; |
6587 return I::kNumIsolateDataSlots; | 6594 return I::kNumIsolateDataSlots; |
6588 } | 6595 } |
6589 | 6596 |
6590 | 6597 |
6598 int64_t Isolate::AdjustAmountOfExternalAllocatedMemory( | |
6599 int64_t change_in_bytes) { | |
6600 #ifndef V8_ENABLE_CHECKS | |
6601 typedef internal::Internals I; | |
6602 int64_t* amount_of_external_allocated_memory = | |
6603 reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) + | |
6604 I::kAmountOfExternalAllocatedMemoryOffset); | |
6605 int64_t* amount_of_external_allocated_memory_at_last_global_gc = | |
6606 reinterpret_cast<int64_t*>( | |
6607 reinterpret_cast<uint8_t*>(this) + | |
6608 I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset); | |
6609 int64_t amount = *amount_of_external_allocated_memory + change_in_bytes; | |
6610 if (change_in_bytes > 0) { | |
6611 // Avoid overflow. | |
6612 if (amount > *amount_of_external_allocated_memory) { | |
6613 if (amount - *amount_of_external_allocated_memory_at_last_global_gc > | |
6614 192 * 1024 * 1024) { | |
Hannes Payer (out of office)
2014/06/04 11:24:49
192? Please don't use a hard-coded value here.
jochen (gone - plz use gerrit)
2014/06/04 11:41:24
Done.
| |
6615 // Will likely trigger a GC. | |
6616 return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes); | |
6617 } | |
6618 *amount_of_external_allocated_memory = amount; | |
6619 } else { | |
6620 // Give up and reset the counters in case of an overflow. | |
6621 *amount_of_external_allocated_memory = 0; | |
6622 *amount_of_external_allocated_memory_at_last_global_gc = 0; | |
6623 } | |
6624 } else { | |
6625 // Avoid underflow. | |
6626 if (amount >= 0) { | |
6627 *amount_of_external_allocated_memory = amount; | |
6628 } else { | |
6629 // Give up and reset the counters in case of an underflow. | |
6630 *amount_of_external_allocated_memory = 0; | |
6631 *amount_of_external_allocated_memory_at_last_global_gc = 0; | |
6632 } | |
6633 } | |
6634 return *amount_of_external_allocated_memory; | |
6635 #else | |
6636 return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes); | |
6637 #endif | |
6638 } | |
6639 | |
6640 | |
6591 template<typename T> | 6641 template<typename T> |
6592 void Isolate::SetObjectGroupId(const Persistent<T>& object, | 6642 void Isolate::SetObjectGroupId(const Persistent<T>& object, |
6593 UniqueId id) { | 6643 UniqueId id) { |
6594 TYPE_CHECK(Value, T); | 6644 TYPE_CHECK(Value, T); |
6595 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); | 6645 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); |
6596 } | 6646 } |
6597 | 6647 |
6598 | 6648 |
6599 template<typename T> | 6649 template<typename T> |
6600 void Isolate::SetReferenceFromGroup(UniqueId id, | 6650 void Isolate::SetReferenceFromGroup(UniqueId id, |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
6652 */ | 6702 */ |
6653 | 6703 |
6654 | 6704 |
6655 } // namespace v8 | 6705 } // namespace v8 |
6656 | 6706 |
6657 | 6707 |
6658 #undef TYPE_CHECK | 6708 #undef TYPE_CHECK |
6659 | 6709 |
6660 | 6710 |
6661 #endif // V8_H_ | 6711 #endif // V8_H_ |
OLD | NEW |