test/hotspot/gtest/gc/shared/test_collectorPolicy.cpp
author erikj
Tue, 12 Sep 2017 19:03:39 +0200
changeset 47216 71c04702a3d5
parent 46625 hotspot/test/native/gc/shared/test_collectorPolicy.cpp@edefffab74e2
child 49857 31e07291ae29
permissions -rw-r--r--
8187443: Forest Consolidation: Move files to unified layout Reviewed-by: darcy, ihse
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     1
/*
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     4
 *
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     7
 * published by the Free Software Foundation.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     8
 *
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    13
 * accompanied this code).
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    14
 *
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    18
 *
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    21
 * questions.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    22
 */
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    23
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    24
#include "precompiled.hpp"
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    25
#include "gc/shared/collectorPolicy.hpp"
46564
0ec329b23bbf 8182696: Remove gcTrace.hpp include from referenceProcessor.hpp
stefank
parents: 42028
diff changeset
    26
#include "runtime/arguments.hpp"
0ec329b23bbf 8182696: Remove gcTrace.hpp include from referenceProcessor.hpp
stefank
parents: 42028
diff changeset
    27
#include "runtime/globals_extension.hpp"
46625
edefffab74e2 8183552: Move align functions to align.hpp
stefank
parents: 46619
diff changeset
    28
#include "utilities/align.hpp"
46564
0ec329b23bbf 8182696: Remove gcTrace.hpp include from referenceProcessor.hpp
stefank
parents: 42028
diff changeset
    29
#include "utilities/globalDefinitions.hpp"
0ec329b23bbf 8182696: Remove gcTrace.hpp include from referenceProcessor.hpp
stefank
parents: 42028
diff changeset
    30
#include "utilities/macros.hpp"
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    31
#include "unittest.hpp"
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    32
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    33
class TestGenCollectorPolicy {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    34
 public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    35
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    36
  class Executor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    37
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    38
    virtual void execute() = 0;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    39
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    40
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    41
  class UnaryExecutor : public Executor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    42
   protected:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    43
    const size_t param;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    44
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    45
    UnaryExecutor(size_t val) : param(val) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    46
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    47
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    48
  class BinaryExecutor : public Executor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    49
   protected:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    50
    const size_t param1;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    51
    const size_t param2;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    52
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    53
    BinaryExecutor(size_t val1, size_t val2) : param1(val1), param2(val2) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    54
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    55
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    56
  class MinHeapSizeGuard {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    57
   private:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    58
    const size_t _stored_min_heap_size;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    59
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    60
    MinHeapSizeGuard() : _stored_min_heap_size(Arguments::min_heap_size()) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    61
    ~MinHeapSizeGuard() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    62
      Arguments::set_min_heap_size(_stored_min_heap_size);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    63
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    64
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    65
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    66
  class TestWrapper {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    67
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    68
    static void test(Executor* setter1, Executor* setter2, Executor* checker) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    69
      FLAG_GUARD(InitialHeapSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    70
      FLAG_GUARD(MaxHeapSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    71
      FLAG_GUARD(MaxNewSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    72
      FLAG_GUARD(MinHeapDeltaBytes);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    73
      FLAG_GUARD(NewSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    74
      FLAG_GUARD(OldSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    75
      MinHeapSizeGuard min_heap_size_guard;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    76
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    77
      FLAG_SET_ERGO(size_t, InitialHeapSize, 100 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    78
      FLAG_SET_ERGO(size_t, OldSize, 4 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    79
      FLAG_SET_ERGO(size_t, NewSize, 1 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    80
      FLAG_SET_ERGO(size_t, MaxNewSize, 80 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    81
      Arguments::set_min_heap_size(40 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    82
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    83
      ASSERT_NO_FATAL_FAILURE(setter1->execute());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    84
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    85
      if (setter2 != NULL) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    86
        ASSERT_NO_FATAL_FAILURE(setter2->execute());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    87
      }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    88
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    89
      ASSERT_NO_FATAL_FAILURE(checker->execute());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    90
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    91
    static void test(Executor* setter, Executor* checker) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    92
      test(setter, NULL, checker);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    93
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    94
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    95
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    96
  class SetNewSizeErgo : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    97
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    98
    SetNewSizeErgo(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
    99
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   100
      FLAG_SET_ERGO(size_t, NewSize, param);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   101
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   102
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   103
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   104
  class CheckYoungMin : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   105
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   106
    CheckYoungMin(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   107
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   108
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   109
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   110
      ASSERT_LE(msp.min_young_size(), param);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   111
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   112
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   113
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   114
  class CheckScaledYoungInitial : public Executor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   115
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   116
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   117
      size_t initial_heap_size = InitialHeapSize;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   118
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   119
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   120
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   121
      if (InitialHeapSize > initial_heap_size) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   122
        // InitialHeapSize was adapted by msp.initialize_all, e.g. due to alignment
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   123
        // caused by 64K page size.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   124
        initial_heap_size = InitialHeapSize;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   125
      }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   126
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   127
      size_t expected = msp.scale_by_NewRatio_aligned(initial_heap_size);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   128
      ASSERT_EQ(expected, msp.initial_young_size());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   129
      ASSERT_EQ(expected, NewSize);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   130
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   131
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   132
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   133
  class SetNewSizeCmd : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   134
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   135
    SetNewSizeCmd(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   136
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   137
      FLAG_SET_CMDLINE(size_t, NewSize, param);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   138
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   139
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   140
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   141
  class CheckYoungInitial : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   142
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   143
    CheckYoungInitial(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   144
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   145
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   146
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   147
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   148
      ASSERT_EQ(param, msp.initial_young_size());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   149
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   150
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   151
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   152
  class SetOldSizeCmd : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   153
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   154
    SetOldSizeCmd(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   155
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   156
      FLAG_SET_CMDLINE(size_t, OldSize, param);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   157
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   158
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   159
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   160
  class SetMaxNewSizeCmd : public BinaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   161
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   162
    SetMaxNewSizeCmd(size_t param1, size_t param2) : BinaryExecutor(param1, param2) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   163
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   164
      size_t heap_alignment = CollectorPolicy::compute_heap_alignment();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46564
diff changeset
   165
      size_t new_size_value = align_up(MaxHeapSize, heap_alignment)
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   166
              - param1 + param2;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   167
      FLAG_SET_CMDLINE(size_t, MaxNewSize, new_size_value);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   168
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   169
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   170
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   171
  class CheckOldMin : public UnaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   172
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   173
    CheckOldMin(size_t param) : UnaryExecutor(param) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   174
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   175
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   176
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   177
      ASSERT_LE(msp.min_old_size(), param);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   178
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   179
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   180
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   181
  class CheckOldInitial : public Executor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   182
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   183
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   184
      size_t heap_alignment = CollectorPolicy::compute_heap_alignment();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   185
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   186
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   187
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   188
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46564
diff changeset
   189
      size_t expected_old_initial = align_up(InitialHeapSize, heap_alignment)
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   190
              - MaxNewSize;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   191
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   192
      ASSERT_EQ(expected_old_initial, msp.initial_old_size());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   193
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   194
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   195
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   196
  class CheckOldInitialMaxNewSize : public BinaryExecutor {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   197
   public:
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   198
    CheckOldInitialMaxNewSize(size_t param1, size_t param2) : BinaryExecutor(param1, param2) { }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   199
    void execute() {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   200
      size_t heap_alignment = CollectorPolicy::compute_heap_alignment();
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46564
diff changeset
   201
      size_t new_size_value = align_up(MaxHeapSize, heap_alignment)
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   202
              - param1 + param2;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   203
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   204
      MarkSweepPolicy msp;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   205
      msp.initialize_all();
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   206
46619
a3919f5e8d2b 8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents: 46564
diff changeset
   207
      size_t expected_old_initial = align_up(MaxHeapSize, heap_alignment)
42028
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   208
              - new_size_value;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   209
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   210
      ASSERT_EQ(expected_old_initial, msp.initial_old_size());
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   211
    }
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   212
  };
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   213
};
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   214
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   215
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   216
// Testing that the NewSize flag is handled correct is hard because it
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   217
// depends on so many other configurable variables. These tests only try to
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   218
// verify that there are some basic rules for NewSize honored by the policies.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   219
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   220
// If NewSize has been ergonomically set, the collector policy
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   221
// should use it for min
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   222
TEST_VM(CollectorPolicy, young_min_ergo) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   223
  TestGenCollectorPolicy::SetNewSizeErgo setter(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   224
  TestGenCollectorPolicy::CheckYoungMin checker(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   225
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   226
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   227
}
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   228
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   229
// If NewSize has been ergonomically set, the collector policy
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   230
// should use it for min but calculate the initial young size
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   231
// using NewRatio.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   232
TEST_VM(CollectorPolicy, young_scaled_initial_ergo) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   233
  TestGenCollectorPolicy::SetNewSizeErgo setter(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   234
  TestGenCollectorPolicy::CheckScaledYoungInitial checker;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   235
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   236
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   237
}
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   238
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   239
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   240
// Since a flag has been set with FLAG_SET_CMDLINE it
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   241
// will be treated as it have been set on the command line for
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   242
// the rest of the VM lifetime. This is an irreversible change and
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   243
// could impact other tests so we use TEST_OTHER_VM
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   244
TEST_OTHER_VM(CollectorPolicy, young_cmd) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   245
  // If NewSize is set on the command line, it should be used
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   246
  // for both min and initial young size if less than min heap.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   247
  TestGenCollectorPolicy::SetNewSizeCmd setter(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   248
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   249
  TestGenCollectorPolicy::CheckYoungMin checker_min(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   250
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker_min);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   251
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   252
  TestGenCollectorPolicy::CheckYoungInitial checker_initial(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   253
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker_initial);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   254
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   255
  // If NewSize is set on command line, but is larger than the min
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   256
  // heap size, it should only be used for initial young size.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   257
  TestGenCollectorPolicy::SetNewSizeCmd setter_large(80 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   258
  TestGenCollectorPolicy::CheckYoungInitial checker_large(80 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   259
  TestGenCollectorPolicy::TestWrapper::test(&setter_large, &checker_large);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   260
}
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   261
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   262
// Since a flag has been set with FLAG_SET_CMDLINE it
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   263
// will be treated as it have been set on the command line for
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   264
// the rest of the VM lifetime. This is an irreversible change and
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   265
// could impact other tests so we use TEST_OTHER_VM
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   266
TEST_OTHER_VM(CollectorPolicy, old_cmd) {
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   267
  // If OldSize is set on the command line, it should be used
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   268
  // for both min and initial old size if less than min heap.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   269
  TestGenCollectorPolicy::SetOldSizeCmd setter(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   270
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   271
  TestGenCollectorPolicy::CheckOldMin checker_min(20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   272
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker_min);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   273
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   274
  TestGenCollectorPolicy::CheckOldInitial checker_initial;
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   275
  TestGenCollectorPolicy::TestWrapper::test(&setter, &checker_initial);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   276
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   277
  // If MaxNewSize is large, the maximum OldSize will be less than
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   278
  // what's requested on the command line and it should be reset
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   279
  // ergonomically.
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   280
  // We intentionally set MaxNewSize + OldSize > MaxHeapSize
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   281
  TestGenCollectorPolicy::SetOldSizeCmd setter_old_size(30 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   282
  TestGenCollectorPolicy::SetMaxNewSizeCmd setter_max_new_size(30 * M, 20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   283
  TestGenCollectorPolicy::CheckOldInitialMaxNewSize checker_large(30 * M, 20 * M);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   284
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   285
  TestGenCollectorPolicy::TestWrapper::test(&setter_old_size, &setter_max_new_size, &checker_large);
6218944dbd18 8166910: Convert TestNewSize_test to GTest
kzhaldyb
parents:
diff changeset
   286
}