hotspot/src/share/vm/gc/g1/bufferingOopClosure.cpp
author david
Tue, 29 Sep 2015 11:02:08 +0200
changeset 33105 294e48b4f704
parent 30764 fec48bf5a827
permissions -rw-r--r--
8080775: Better argument formatting for assert() and friends Reviewed-by: kbarrett, pliden
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     1
/*
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22772
diff changeset
     2
 * Copyright (c) 2014, 2015, Oracle and/or its affiliates. All rights reserved.
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     4
 *
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     8
 *
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    13
 * accompanied this code).
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    14
 *
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    18
 *
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    21
 * questions.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    22
 *
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    23
 */
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    24
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    25
#include "precompiled.hpp"
30764
fec48bf5a827 8079792: GC directory structure cleanup
pliden
parents: 22772
diff changeset
    26
#include "gc/g1/bufferingOopClosure.hpp"
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    27
#include "memory/iterator.hpp"
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    28
#include "utilities/debug.hpp"
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    29
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    30
/////////////// Unit tests ///////////////
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    31
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    32
#ifndef PRODUCT
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    33
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    34
class TestBufferingOopClosure {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    35
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    36
  // Helper class to fake a set of oop*s and narrowOop*s.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    37
  class FakeRoots {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    38
   public:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    39
    // Used for sanity checking of the values passed to the do_oops functions in the test.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    40
    static const uintptr_t NarrowOopMarker = uintptr_t(1) << (BitsPerWord -1);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    41
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    42
    int    _num_narrow;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    43
    int    _num_full;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    44
    void** _narrow;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    45
    void** _full;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    46
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    47
    FakeRoots(int num_narrow, int num_full) :
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    48
        _num_narrow(num_narrow),
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    49
        _num_full(num_full),
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    50
        _narrow((void**)::malloc(sizeof(void*) * num_narrow)),
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    51
        _full((void**)::malloc(sizeof(void*) * num_full)) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    52
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    53
      for (int i = 0; i < num_narrow; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    54
        _narrow[i] = (void*)(NarrowOopMarker + (uintptr_t)i);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    55
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    56
      for (int i = 0; i < num_full; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    57
        _full[i] = (void*)(uintptr_t)i;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    58
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    59
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    60
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    61
    ~FakeRoots() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    62
      ::free(_narrow);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    63
      ::free(_full);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    64
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    65
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    66
    void oops_do_narrow_then_full(OopClosure* cl) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    67
      for (int i = 0; i < _num_narrow; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    68
        cl->do_oop((narrowOop*)_narrow[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    69
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    70
      for (int i = 0; i < _num_full; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    71
        cl->do_oop((oop*)_full[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    72
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    73
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    74
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    75
    void oops_do_full_then_narrow(OopClosure* cl) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    76
      for (int i = 0; i < _num_full; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    77
        cl->do_oop((oop*)_full[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    78
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    79
      for (int i = 0; i < _num_narrow; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    80
        cl->do_oop((narrowOop*)_narrow[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    81
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    82
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    83
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    84
    void oops_do_mixed(OopClosure* cl) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    85
      int i;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    86
      for (i = 0; i < _num_full && i < _num_narrow; i++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    87
        cl->do_oop((oop*)_full[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    88
        cl->do_oop((narrowOop*)_narrow[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    89
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    90
      for (int j = i; j < _num_full; j++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    91
        cl->do_oop((oop*)_full[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    92
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    93
      for (int j = i; j < _num_narrow; j++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    94
        cl->do_oop((narrowOop*)_narrow[i]);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    95
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    96
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    97
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    98
    static const int MaxOrder = 2;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
    99
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   100
    void oops_do(OopClosure* cl, int do_oop_order) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   101
      switch(do_oop_order) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   102
        case 0:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   103
          oops_do_narrow_then_full(cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   104
          break;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   105
        case 1:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   106
          oops_do_full_then_narrow(cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   107
          break;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   108
        case 2:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   109
          oops_do_mixed(cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   110
          break;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   111
        default:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   112
          oops_do_narrow_then_full(cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   113
          break;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   114
      }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   115
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   116
  };
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   117
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   118
  class CountOopClosure : public OopClosure {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   119
    int _narrow_oop_count;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   120
    int _full_oop_count;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   121
   public:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   122
    CountOopClosure() : _narrow_oop_count(0), _full_oop_count(0) {}
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   123
    void do_oop(narrowOop* p) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   124
      assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) != 0,
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   125
          "The narrowOop was unexpectedly not marked with the NarrowOopMarker");
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   126
      _narrow_oop_count++;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   127
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   128
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   129
    void do_oop(oop* p){
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   130
      assert((uintptr_t(p) & FakeRoots::NarrowOopMarker) == 0,
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   131
          "The oop was unexpectedly marked with the NarrowOopMarker");
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   132
      _full_oop_count++;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   133
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   134
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   135
    int narrow_oop_count() { return _narrow_oop_count; }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   136
    int full_oop_count()   { return _full_oop_count; }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   137
    int all_oop_count()    { return _narrow_oop_count + _full_oop_count; }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   138
  };
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   139
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   140
  class DoNothingOopClosure : public OopClosure {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   141
   public:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   142
    void do_oop(narrowOop* p) {}
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   143
    void do_oop(oop* p)       {}
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   144
  };
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   145
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   146
  static void testCount(int num_narrow, int num_full, int do_oop_order) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   147
    FakeRoots fr(num_narrow, num_full);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   148
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   149
    CountOopClosure coc;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   150
    BufferingOopClosure boc(&coc);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   151
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   152
    fr.oops_do(&boc, do_oop_order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   153
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   154
    boc.done();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   155
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   156
    #define assert_testCount(got, expected)                                \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   157
       assert((got) == (expected),                                         \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   158
              "Expected: %d, got: %d, when running testCount(%d, %d, %d)", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   159
              (got), (expected), num_narrow, num_full, do_oop_order)
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   160
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   161
    assert_testCount(num_narrow, coc.narrow_oop_count());
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   162
    assert_testCount(num_full, coc.full_oop_count());
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   163
    assert_testCount(num_narrow + num_full, coc.all_oop_count());
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   164
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   165
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   166
  static void testCount() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   167
    int buffer_length = BufferingOopClosure::BufferLength;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   168
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   169
    for (int order = 0; order < FakeRoots::MaxOrder; order++) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   170
      testCount(0,                 0,                 order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   171
      testCount(10,                0,                 order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   172
      testCount(0,                 10,                order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   173
      testCount(10,                10,                order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   174
      testCount(buffer_length,     10,                order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   175
      testCount(10,                buffer_length,     order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   176
      testCount(buffer_length,     buffer_length,     order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   177
      testCount(buffer_length + 1, 10,                order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   178
      testCount(10,                buffer_length + 1, order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   179
      testCount(buffer_length + 1, buffer_length,     order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   180
      testCount(buffer_length,     buffer_length + 1, order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   181
      testCount(buffer_length + 1, buffer_length + 1, order);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   182
    }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   183
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   184
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   185
  static void testIsBufferEmptyOrFull(int num_narrow, int num_full, bool expect_empty, bool expect_full) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   186
    FakeRoots fr(num_narrow, num_full);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   187
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   188
    DoNothingOopClosure cl;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   189
    BufferingOopClosure boc(&cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   190
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   191
    fr.oops_do(&boc, 0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   192
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   193
    #define assert_testIsBufferEmptyOrFull(got, expected)                        \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   194
        assert((got) == (expected),                                              \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   195
               "Expected: %d, got: %d. testIsBufferEmptyOrFull(%d, %d, %s, %s)", \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   196
               (got), (expected), num_narrow, num_full,                          \
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   197
               BOOL_TO_STR(expect_empty), BOOL_TO_STR(expect_full))
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   198
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   199
    assert_testIsBufferEmptyOrFull(expect_empty, boc.is_buffer_empty());
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   200
    assert_testIsBufferEmptyOrFull(expect_full, boc.is_buffer_full());
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   201
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   202
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   203
  static void testIsBufferEmptyOrFull() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   204
    int bl = BufferingOopClosure::BufferLength;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   205
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   206
    testIsBufferEmptyOrFull(0,       0, true,  false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   207
    testIsBufferEmptyOrFull(1,       0, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   208
    testIsBufferEmptyOrFull(0,       1, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   209
    testIsBufferEmptyOrFull(1,       1, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   210
    testIsBufferEmptyOrFull(10,      0, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   211
    testIsBufferEmptyOrFull(0,      10, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   212
    testIsBufferEmptyOrFull(10,     10, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   213
    testIsBufferEmptyOrFull(0,      bl, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   214
    testIsBufferEmptyOrFull(bl,      0, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   215
    testIsBufferEmptyOrFull(bl/2, bl/2, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   216
    testIsBufferEmptyOrFull(bl-1,    1, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   217
    testIsBufferEmptyOrFull(1,    bl-1, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   218
    // Processed
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   219
    testIsBufferEmptyOrFull(bl+1,    0, false, false);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   220
    testIsBufferEmptyOrFull(bl*2,    0, false, true);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   221
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   222
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   223
  static void testEmptyAfterDone(int num_narrow, int num_full) {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   224
    FakeRoots fr(num_narrow, num_full);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   225
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   226
    DoNothingOopClosure cl;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   227
    BufferingOopClosure boc(&cl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   228
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   229
    fr.oops_do(&boc, 0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   230
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   231
    // Make sure all get processed.
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   232
    boc.done();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   233
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   234
    assert(boc.is_buffer_empty(),
33105
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   235
           "Should be empty after call to done(). testEmptyAfterDone(%d, %d)",
294e48b4f704 8080775: Better argument formatting for assert() and friends
david
parents: 30764
diff changeset
   236
           num_narrow, num_full);
22772
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   237
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   238
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   239
  static void testEmptyAfterDone() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   240
    int bl = BufferingOopClosure::BufferLength;
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   241
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   242
    testEmptyAfterDone(0,       0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   243
    testEmptyAfterDone(1,       0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   244
    testEmptyAfterDone(0,       1);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   245
    testEmptyAfterDone(1,       1);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   246
    testEmptyAfterDone(10,      0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   247
    testEmptyAfterDone(0,      10);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   248
    testEmptyAfterDone(10,     10);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   249
    testEmptyAfterDone(0,      bl);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   250
    testEmptyAfterDone(bl,      0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   251
    testEmptyAfterDone(bl/2, bl/2);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   252
    testEmptyAfterDone(bl-1,    1);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   253
    testEmptyAfterDone(1,    bl-1);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   254
    // Processed
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   255
    testEmptyAfterDone(bl+1,    0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   256
    testEmptyAfterDone(bl*2,    0);
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   257
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   258
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   259
  public:
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   260
  static void test() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   261
    testCount();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   262
    testIsBufferEmptyOrFull();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   263
    testEmptyAfterDone();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   264
  }
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   265
};
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   266
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   267
void TestBufferingOopClosure_test() {
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   268
  TestBufferingOopClosure::test();
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   269
}
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   270
2698c3a4ebb6 8033764: Remove the usage of StarTask from BufferingOopClosure
stefank
parents:
diff changeset
   271
#endif