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

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: 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') | src/heap.h » ('J')
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..0c049bda6cae648ef389b49961aa87f398a0b0de 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);
+ int64_t SlowAdjustAmountOfExternalAllocatedMemory(int64_t change_in_bytes);
};
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,7 +5565,11 @@ class Internals {
static const int kExternalAsciiRepresentationTag = 0x06;
static const int kIsolateEmbedderDataOffset = 0 * kApiPointerSize;
- static const int kIsolateRootsOffset = 5 * kApiPointerSize;
+ static const int kAmountOfExternalAllocatedMemoryOffset = 5 * kApiPointerSize;
+ static const int kAmountOfExternalAllocatedMemoryAtLastGlobalGCOffset =
+ 5 * kApiPointerSize + kApiInt64Size;
+ static const int kIsolateRootsOffset =
+ 5 * kApiPointerSize + 2 * kApiInt64Size;
static const int kUndefinedValueRootIndex = 5;
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
@@ -6588,6 +6595,49 @@ uint32_t Isolate::GetNumberOfDataSlots() {
}
+int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
+ int64_t change_in_bytes) {
+#ifndef V8_ENABLE_CHECKS
+ 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) {
+ // Avoid overflow.
+ if (amount > *amount_of_external_allocated_memory) {
+ if (amount - *amount_of_external_allocated_memory_at_last_global_gc >
+ 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.
+ // Will likely trigger a GC.
+ return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes);
+ }
+ *amount_of_external_allocated_memory = amount;
+ } else {
+ // Give up and reset the counters in case of an overflow.
+ *amount_of_external_allocated_memory = 0;
+ *amount_of_external_allocated_memory_at_last_global_gc = 0;
+ }
+ } else {
+ // Avoid underflow.
+ if (amount >= 0) {
+ *amount_of_external_allocated_memory = amount;
+ } else {
+ // Give up and reset the counters in case of an underflow.
+ *amount_of_external_allocated_memory = 0;
+ *amount_of_external_allocated_memory_at_last_global_gc = 0;
+ }
+ }
+ return *amount_of_external_allocated_memory;
+#else
+ return SlowAdjustAmountOfExternalAllocatedMemory(change_in_bytes);
+#endif
+}
+
+
template<typename T>
void Isolate::SetObjectGroupId(const Persistent<T>& object,
UniqueId id) {
« no previous file with comments | « no previous file | src/api.cc » ('j') | src/heap.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698