Skip to content
This repository
Browse code

Possible improvement to trace selection

  • Loading branch information...
commit b57d179fcbc474b668d4bc6636ce2833cc7ef9ef 1 parent 11c2430
Thomas Schilling authored October 12, 2012
2  vm/capability.hh
@@ -99,7 +99,9 @@ private:
99 99
 
100 100
   Word *traceExitHp_;
101 101
   Word *traceExitHpLim_;
  102
+
102 103
   friend class Fragment;
  104
+  friend class BranchTargetBuffer;  // For resetting hot counters.
103 105
 };
104 106
 
105 107
 inline int
1  vm/config.hh
@@ -29,6 +29,7 @@
29 29
 #define LC_JIT   1
30 30
 
31 31
 // #define LC_TRACE_STATS
  32
+#define LC_CLEAR_DOM_COUNTERS
32 33
 
33 34
 #define MAX_HEAP_ENTRIES      300
34 35
 
13  vm/ir.cc
@@ -3,6 +3,7 @@
3 3
 #include "assembler.hh"
4 4
 #include "objects.hh"
5 5
 #include "miscclosures.hh"
  6
+#include "capability.hh"
6 7
 
7 8
 #include <iostream>
8 9
 #include <iomanip>
@@ -752,6 +753,18 @@ void BranchTargetBuffer::emit(BcIns *pc) {
752 753
   ++next_;
753 754
 }
754 755
 
  756
+void
  757
+BranchTargetBuffer::resetDominatedCounters(Capability *cap)
  758
+{
  759
+  void *tgt = NULL;
  760
+  for (uint32_t i = 0; i < next_; ++i) {
  761
+    void *new_tgt = buf_[i].addr;
  762
+    if (new_tgt < tgt)
  763
+      cap->counters_.reset(new_tgt);
  764
+    tgt = new_tgt;
  765
+  }
  766
+}
  767
+
755 768
 uint32_t CallStack::depth(StackNodeRef ref) const {
756 769
   uint32_t d = 0;
757 770
   while (ref != STACK_NO_REF) {
4  vm/ir.hh
@@ -728,6 +728,10 @@ public:
728 728
 
729 729
   inline uint32_t size() const { return next_; }
730 730
 
  731
+  /// Resets the hot counters for all targets included in the branch
  732
+  /// target buffer.
  733
+  void resetDominatedCounters(Capability *cap);
  734
+
731 735
 private:
732 736
   void growBuffer();
733 737
 
37  vm/jit.cc
@@ -787,6 +787,11 @@ void Jit::finishRecording() {
787 787
     *startPc_ = BcIns::ad(BcIns::kJFUNC, 0, tno);
788 788
   }
789 789
 
  790
+#ifdef LC_CLEAR_DOM_COUNTERS
  791
+  // See Note "Reset Dominated Counters" below.
  792
+  btb_.resetDominatedCounters(cap_);
  793
+#endif
  794
+  
790 795
   resetRecorderState();
791 796
 
792 797
   DBG( {
@@ -801,6 +806,38 @@ void Jit::finishRecording() {
801 806
   jit_time += getProcessElapsedTime() - compilestart;
802 807
 }
803 808
 
  809
+/*
  810
+
  811
+Note: Reset Dominated Conters
  812
+-----------------------------
  813
+
  814
+If the recorded trace contained several possible trace roots they most
  815
+likely all have similar hot counters.  Let's call the trace we've just
  816
+compiled T and E1 its entry point (startPc).  Assume there is another
  817
+potential trace head E2 inside T.  Since E1 reached the hotness
  818
+threshold it is quite likely that E2 is very close to the hotness
  819
+threshold as well, most likely it is only one tick away from the
  820
+hotness threshold.
  821
+
  822
+Let's now consider the case that T executes and exits.  It is quite
  823
+likely that E2 is reached again and a new trace T2 is created.  That
  824
+is problematic.  If the same execution path is taken more frequently
  825
+we will eventually create a side trace that also reaches E2.  There
  826
+are now two possibilities:
  827
+
  828
+  - if we stop recording at an existing trace we link with T2.  This
  829
+    may mean loss of optimisation potential.
  830
+
  831
+  - if we keep recording despite existing traces, then we create a
  832
+    new trace that includes T2.  The trace T2 is now essentially
  833
+    dead code.
  834
+
  835
+We thus reset all counters for potential trace heads inside T to
  836
+increase the likelyhood that a side trace of T is created before T2 is
  837
+created.  It is not a 100% solution, but it shouldn't hurt either.
  838
+
  839
+*/
  840
+
804 841
 Fragment::Fragment()
805 842
   : flags_(0), traceId_(0), startPc_(NULL), targets_(NULL) {
806 843
 #ifdef LC_TRACE_STATS
4  vm/jit.hh
@@ -29,6 +29,10 @@ public:
29 29
     counters_[hotCountHash(pc)] = value;
30 30
   }
31 31
 
  32
+  inline void reset(void *pc) {
  33
+    counters_[hotCountHash(pc)] = threshold_;
  34
+  }
  35
+
32 36
   /// Decrement the hot counter.
33 37
   ///
34 38
   /// @return true if the counter reached the hotness threshold.

0 notes on commit b57d179

Please sign in to comment.
Something went wrong with that request. Please try again.