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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/api.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index b1da55e2c5ee0d2cf566c976b95dde2e0396a27b..8984d92c75fc276bff432e35cd0570d7a40b3669 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -4215,7 +4215,8 @@ class V8_EXPORT Isolate {
* kept alive by JavaScript objects.
* \returns the adjusted value.
*/
- int64_t AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
+ V8_INLINE int64_t
+ AdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
/**
* Returns heap profiler for this isolate. Will return NULL until the isolate
@@ -4418,6 +4419,7 @@ class V8_EXPORT Isolate {
void SetObjectGroupId(internal::Object** object, UniqueId id);
void SetReferenceFromGroup(UniqueId id, internal::Object** object);
void SetReference(internal::Object** parent, internal::Object** child);
+ void CollectAllGarbage(const char* gc_reason);
};
class V8_EXPORT StartupData {
@@ -5464,6 +5466,7 @@ namespace internal {
const int kApiPointerSize = sizeof(void*); // NOLINT
const int kApiIntSize = sizeof(int); // NOLINT
+const int kApiInt64Size = sizeof(int64_t); // NOLINT
// Tag information for HeapObject.
const int kHeapObjectTag = 1;
@@ -5562,13 +5565,23 @@ class Internals {
static const int kExternalAsciiRepresentationTag = 0x06;
static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
- static const int kIsolateRootsOffset = 5 * kApiPointerSize;
+ static const int kAmountOfExternalAllocatedMemoryOffset =
+ 4 * kApiPointerSize;
+ static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
+ kAmountOfExternalAllocatedMemoryOffset + kApiInt64Size;
+ static const int kIsolateRootsOffset =
+ kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset + kApiInt64Size +
+ kApiPointerSize;
static const int kUndefinedValueRootIndex = 5;
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
static const int kEmptyStringRootIndex = 162;
+ // The external allocation limit should be below 256 MB on all architectures
+ // to avoid that resource-constrained embedders run low on memory.
+ static const int kExternalAllocationLimit = 192 * 1024 * 1024;
+
static const int kNodeClassIdOffset = 1 * kApiPointerSize;
static const int kNodeFlagsOffset = 1 * kApiPointerSize + 3;
static const int kNodeStateMask = 0xf;
@@ -6588,6 +6601,28 @@ uint32_t Isolate::GetNumberOfDataSlots() {
}
+int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes) {
+ typedef internal::Internals I;
+ int64_t* amount_of_external_allocated_memory =
+ reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
+ I::kAmountOfExternalAllocatedMemoryOffset);
+ int64_t* amount_of_external_allocated_memory_at_last_global_gc =
+ reinterpret_cast<int64_t*>(
+ reinterpret_cast<uint8_t*>(this) +
+ I::kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset);
+ int64_t amount = *amount_of_external_allocated_memory + change_in_bytes;
+ if (change_in_bytes > 0 &&
+ amount - *amount_of_external_allocated_memory_at_last_global_gc >
+ I::kExternalAllocationLimit) {
+ CollectAllGarbage("external memory allocation limit reached.");
+ } else {
+ *amount_of_external_allocated_memory = amount;
+ }
+ return *amount_of_external_allocated_memory;
+}
+
+
template<typename T>
void Isolate::SetObjectGroupId(const Persistent<T>& object,
UniqueId id) {
« 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