Reviewers: Toon Verwaest,

Description:
Fix wraparound of deoptimization count in shared function info.

BUG=

Please review this at https://codereview.chromium.org/23803007/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+20, -6 lines):
  M src/objects-inl.h
  M src/objects.h
  M src/runtime-profiler.cc


Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index fc5ed247ee5a86f38aa6a59794ace121fe538da4..8dce54443a0da786216d8283f4f8cb47747619f9 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -4888,8 +4888,20 @@ void SharedFunctionInfo::set_deopt_count(int deopt_count) {
 void SharedFunctionInfo::increment_deopt_count() {
   int value = counters();
   int deopt_count = DeoptCountBits::decode(value);
-  deopt_count = (deopt_count + 1) & DeoptCountBits::kMax;
-  set_counters(DeoptCountBits::update(value, deopt_count));
+  if (deopt_count < DeoptCountBits::kMax) {
+    deopt_count = (deopt_count + 1) & DeoptCountBits::kMax;
+    set_counters(DeoptCountBits::update(value, deopt_count));
+    if (deopt_count == DeoptCountBits::kMax) {
+      // We hit the limit; temporarily disable optimization.
+ // The runtime profiler may try to reenable optimization sometime later.
+      DisableOptimization(kDeoptimizedTooManyTimes);
+    }
+  }
+}
+
+
+bool SharedFunctionInfo::too_many_deopts() {
+  return DeoptCountBits::decode(counters()) == DeoptCountBits::kMax;
 }


Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index f001feb12a7652d1e329c6d204e2e15fde2ab6fe..83812fd64dfe7ab6ef88940fb310baec24c15124 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -1223,6 +1223,7 @@ class MaybeObject BASE_EMBEDDED {
V(kOperandIsNotSmi, "Operand is not smi") \ V(kOperandNotANumber, "Operand not a number") \ V(kOptimizedTooManyTimes, "optimized too many times") \ + V(kDeoptimizedTooManyTimes, "deoptimized too many times") \ V(kOutOfVirtualRegistersWhileTryingToAllocateTempRegister, \ "Out of virtual registers while trying to allocate temp register") \ V(kParseScopeError, "parse/scope error") \
@@ -6577,6 +6578,7 @@ class SharedFunctionInfo: public HeapObject {
   inline void set_deopt_count(int value);
   inline int deopt_count();
   inline void increment_deopt_count();
+  inline bool too_many_deopts();

   // Number of time we tried to re-enable optimization after it
   // was disabled due to high number of deoptimizations.
Index: src/runtime-profiler.cc
diff --git a/src/runtime-profiler.cc b/src/runtime-profiler.cc
index cfce1dff8b389dcd432c3c5d2852ad57e2125a52..35919a553b67bf5eb33393205c5da0bb73515051 100644
--- a/src/runtime-profiler.cc
+++ b/src/runtime-profiler.cc
@@ -301,11 +301,11 @@ void RuntimeProfiler::OptimizeNow() {
       continue;
     }

-    // Do not record non-optimizable functions.
+    // If a function has had optimization disabled, it might be temporary.
     if (shared->optimization_disabled()) {
-      if (shared->deopt_count() >= FLAG_max_opt_count) {
-        // If optimization was disabled due to many deoptimizations,
- // then check if the function is hot and try to reenable optimization.
+      if (shared->too_many_deopts()) {
+        // The optimization was disabled because of too many deopts;
+        // check if the function is hot and try to reenable optimization.
         int ticks = shared_code->profiler_ticks();
         if (ticks >= kProfilerTicksBeforeReenablingOptimization) {
           shared_code->set_profiler_ticks(0);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to