Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(648)

Side by Side Diff: include/v8.h

Issue 310393003: Move most of the implementation of AdjustAmountOfExternalMemory to v8.h (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: updates Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 void CollectAllGarbage(const char* gc_reason);
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
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
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 =
5569 4 * kApiPointerSize;
5570 static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
5571 kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
5572 static const int kIsolateRootsOffset =
5573 kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
5574 kApiPointerSize;
5566 static const int kUndefinedValueRootIndex = 5; 5575 static const int kUndefinedValueRootIndex = 5;
5567 static const int kNullValueRootIndex = 7; 5576 static const int kNullValueRootIndex = 7;
5568 static const int kTrueValueRootIndex = 8; 5577 static const int kTrueValueRootIndex = 8;
5569 static const int kFalseValueRootIndex = 9; 5578 static const int kFalseValueRootIndex = 9;
5570 static const int kEmptyStringRootIndex = 162; 5579 static const int kEmptyStringRootIndex = 162;
5571 5580
5581 // The external allocation limit should be below 256 MB on all architectures
5582 // to avoid that resource-constrained embedders run low on memory.
5583 static const int kExternalAllocationLimit = 192 * 1024 * 1024;
5584
5572 static const int kNodeClassIdOffset = 1 * kApiPointerSize; 5585 static const int kNodeClassIdOffset = 1 * kApiPointerSize;
5573 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3; 5586 static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
5574 static const int kNodeStateMask = 0xf; 5587 static const int kNodeStateMask = 0xf;
5575 static const int kNodeStateIsWeakValue = 2; 5588 static const int kNodeStateIsWeakValue = 2;
5576 static const int kNodeStateIsPendingValue = 3; 5589 static const int kNodeStateIsPendingValue = 3;
5577 static const int kNodeStateIsNearDeathValue = 4; 5590 static const int kNodeStateIsNearDeathValue = 4;
5578 static const int kNodeIsIndependentShift = 4; 5591 static const int kNodeIsIndependentShift = 4;
5579 static const int kNodeIsPartiallyDependentShift = 5; 5592 static const int kNodeIsPartiallyDependentShift = 5;
5580 5593
5581 static const int kJSObjectType = 0xbb; 5594 static const int kJSObjectType = 0xbb;
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after
6581 return I::GetEmbedderData(this, slot); 6594 return I::GetEmbedderData(this, slot);
6582 } 6595 }
6583 6596
6584 6597
6585 uint32_t Isolate::GetNumberOfDataSlots() { 6598 uint32_t Isolate::GetNumberOfDataSlots() {
6586 typedef internal::Internals I; 6599 typedef internal::Internals I;
6587 return I::kNumIsolateDataSlots; 6600 return I::kNumIsolateDataSlots;
6588 } 6601 }
6589 6602
6590 6603
6604 int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
6605 int64_t change_in_bytes) {
6606 typedef internal::Internals I;
6607 int64_t* amount_of_external_allocated_memory =
6608 reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
6609 I::kAmountOfExternalAllocatedMemoryOffset);
6610 int64_t* amount_of_external_allocated_memory_at_last_global_gc =
6611 reinterpret_cast<int64_t*>(
6612 reinterpret_cast<uint8_t*>(this) +
6613 I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
6614 int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
6615 if (change_in_bytes > 0 &&
6616 amount - *amount_of_external_allocated_memory_at_last_global_gc >
6617 I::kExternalAllocationLimit) {
6618 CollectAllGarbage("external memory allocation limit reached.");
6619 } else {
6620 *amount_of_external_allocated_memory = amount;
6621 }
6622 return *amount_of_external_allocated_memory;
6623 }
6624
6625
6591 template<typename T> 6626 template<typename T>
6592 void Isolate::SetObjectGroupId(const Persistent<T>& object, 6627 void Isolate::SetObjectGroupId(const Persistent<T>& object,
6593 UniqueId id) { 6628 UniqueId id) {
6594 TYPE_CHECK(Value, T); 6629 TYPE_CHECK(Value, T);
6595 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id); 6630 SetObjectGroupId(reinterpret_cast<v8::internal::Object**>(object.val_), id);
6596 } 6631 }
6597 6632
6598 6633
6599 template<typename T> 6634 template<typename T>
6600 void Isolate::SetReferenceFromGroup(UniqueId id, 6635 void Isolate::SetReferenceFromGroup(UniqueId id,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
6652 */ 6687 */
6653 6688
6654 6689
6655 } // namespace v8 6690 } // namespace v8
6656 6691
6657 6692
6658 #undef TYPE_CHECK 6693 #undef TYPE_CHECK
6659 6694
6660 6695
6661 #endif // V8_H_ 6696 #endif // V8_H_
OLDNEW
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698