< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahNumberSeq.cpp

Print this page
@@ -1,7 +1,8 @@
  /*
   * Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved.
+  * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -118,10 +119,74 @@
      }
    }
    return maximum();
  }
  
+ void HdrSeq::add(const HdrSeq& other) {
+   if (other.num() == 0) {
+     // Other sequence is empty, return
+     return;
+   }
+ 
+   for (int mag = 0; mag < MagBuckets; mag++) {
+     int* other_bucket = other._hdr[mag];
+     if (other_bucket == nullptr) {
+       // Nothing to do
+       continue;
+     }
+     int* bucket = _hdr[mag];
+     if (bucket != nullptr) {
+       // Add into our bucket
+       for (int val = 0; val < ValBuckets; val++) {
+         bucket[val] += other_bucket[val];
+       }
+     } else {
+       // Create our bucket and copy the contents over
+       bucket = NEW_C_HEAP_ARRAY(int, ValBuckets, mtInternal);
+       for (int val = 0; val < ValBuckets; val++) {
+         bucket[val] = other_bucket[val];
+       }
+       _hdr[mag] = bucket;
+     }
+   }
+ 
+   // This is a hacky way to only update the fields we want.
+   // This inlines NumberSeq code without going into AbsSeq and
+   // dealing with decayed average/variance, which we do not
+   // know how to compute yet.
+   _last = other._last;
+   _maximum = MAX2(_maximum, other._maximum);
+   _sum += other._sum;
+   _sum_of_squares += other._sum_of_squares;
+   _num += other._num;
+ 
+   // Until JDK-8298902 is fixed, we taint the decaying statistics
+   _davg = NAN;
+   _dvariance = NAN;
+ }
+ 
+ void HdrSeq::clear() {
+   // Clear the storage
+   for (int mag = 0; mag < MagBuckets; mag++) {
+     int* bucket = _hdr[mag];
+     if (bucket != nullptr) {
+       for (int c = 0; c < ValBuckets; c++) {
+         bucket[c] = 0;
+       }
+     }
+   }
+ 
+   // Clear other fields too
+   _last = 0;
+   _maximum = 0;
+   _sum = 0;
+   _sum_of_squares = 0;
+   _num = 0;
+   _davg = 0;
+   _dvariance = 0;
+ }
+ 
  BinaryMagnitudeSeq::BinaryMagnitudeSeq() {
    _mags = NEW_C_HEAP_ARRAY(size_t, BitsPerSize_t, mtInternal);
    clear();
  }
  
< prev index next >