Commit 11b317d9 authored by ager@chromium.org's avatar ager@chromium.org

Only pass idle notifications on from the API if V8 has been

initialized.

Minor cleanups.

Review URL: http://codereview.chromium.org/173465

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2757 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 46a9b8f2
......@@ -2605,12 +2605,14 @@ bool v8::V8::Dispose() {
bool v8::V8::IdleNotification(bool is_high_priority) {
if (!i::V8::IsRunning()) return false;
return i::V8::IdleNotification(is_high_priority);
}
void v8::V8::LowMemoryNotification() {
#if defined(ANDROID)
if (!i::V8::IsRunning()) return;
i::Heap::CollectAllGarbage(true);
#endif
}
......
......@@ -2785,6 +2785,39 @@ STRUCT_LIST(MAKE_CASE)
}
bool Heap::IdleNotification() {
static const int kIdlesBeforeCollection = 7;
static int number_idle_notifications = 0;
static int last_gc_count = gc_count_;
bool finished = false;
if (last_gc_count == gc_count_) {
number_idle_notifications++;
} else {
number_idle_notifications = 0;
last_gc_count = gc_count_;
}
if (number_idle_notifications >= kIdlesBeforeCollection) {
// The first time through we collect without forcing compaction.
// The second time through we force compaction and quit.
bool force_compaction =
number_idle_notifications > kIdlesBeforeCollection;
CollectAllGarbage(force_compaction);
last_gc_count = gc_count_;
if (force_compaction) {
number_idle_notifications = 0;
finished = true;
}
}
// Uncommit unused memory in new space.
Heap::UncommitFromSpace();
return finished;
}
#ifdef DEBUG
void Heap::Print() {
......
......@@ -843,37 +843,7 @@ class Heap : public AllStatic {
}
// Can be called when the embedding application is idle.
static bool IdleNotification() {
static const int kIdlesBeforeCollection = 7;
static int number_idle_notifications = 0;
static int last_gc_count = gc_count_;
bool finished = false;
if (last_gc_count == gc_count_) {
number_idle_notifications++;
} else {
number_idle_notifications = 0;
last_gc_count = gc_count_;
}
if (number_idle_notifications >= kIdlesBeforeCollection) {
// The first time through we collect without forcing compaction.
// The second time through we force compaction and quit.
bool force_compaction =
number_idle_notifications > kIdlesBeforeCollection;
CollectAllGarbage(force_compaction);
last_gc_count = gc_count_;
if (force_compaction) {
number_idle_notifications = 0;
finished = true;
}
}
// Uncommit unused memory in new space.
Heap::UncommitFromSpace();
return finished;
}
static bool IdleNotification();
// Declare all the root indices.
enum RootListIndex {
......
......@@ -76,7 +76,7 @@ void MarkCompactCollector::CollectGarbage() {
SweepLargeObjectSpace();
if (compacting_collection_) {
if (IsCompacting()) {
EncodeForwardingAddresses();
UpdatePointers();
......
......@@ -7815,6 +7815,7 @@ THREADED_TEST(PixelArray) {
free(pixel_data);
}
THREADED_TEST(ScriptContextDependence) {
v8::HandleScope scope;
LocalContext c1;
......@@ -7830,6 +7831,7 @@ THREADED_TEST(ScriptContextDependence) {
CHECK_EQ(indep->Run()->Int32Value(), 101);
}
THREADED_TEST(StackTrace) {
v8::HandleScope scope;
LocalContext context;
......@@ -7842,3 +7844,11 @@ THREADED_TEST(StackTrace) {
v8::String::Utf8Value stack(try_catch.StackTrace());
CHECK(strstr(*stack, "at foo (stack-trace-test") != NULL);
}
// Test that idle notification can be handled when V8 has not yet been
// set up.
THREADED_TEST(IdleNotification) {
for (int i = 0; i < 100; i++) v8::V8::IdleNotification(true);
for (int i = 0; i < 100; i++) v8::V8::IdleNotification(false);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment