hotspot/src/share/vm/gc_implementation/shared/ageTable.cpp
author apetrusenko
Fri, 06 Feb 2009 01:38:50 +0300
changeset 2009 4adf43957a1b
parent 1 489c9b5090e2
child 2105 347008ce7984
permissions -rw-r--r--
6484959: G1: introduce survivor spaces 6797754: G1: combined bugfix Summary: Implemented a policy to control G1 survivor space parameters. Reviewed-by: tonyp, iveresov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
     1
/*
489c9b5090e2 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2004 Sun Microsystems, Inc.  All Rights Reserved.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     4
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
489c9b5090e2 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
489c9b5090e2 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
489c9b5090e2 Initial load
duke
parents:
diff changeset
     8
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
489c9b5090e2 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
489c9b5090e2 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
489c9b5090e2 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
489c9b5090e2 Initial load
duke
parents:
diff changeset
    14
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
489c9b5090e2 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    18
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
489c9b5090e2 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    22
 *
489c9b5090e2 Initial load
duke
parents:
diff changeset
    23
 */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    24
489c9b5090e2 Initial load
duke
parents:
diff changeset
    25
/* Copyright 1992 Sun Microsystems, Inc. and Stanford University.
489c9b5090e2 Initial load
duke
parents:
diff changeset
    26
   See the LICENSE file for license information. */
489c9b5090e2 Initial load
duke
parents:
diff changeset
    27
489c9b5090e2 Initial load
duke
parents:
diff changeset
    28
# include "incls/_precompiled.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    29
# include "incls/_ageTable.cpp.incl"
489c9b5090e2 Initial load
duke
parents:
diff changeset
    30
489c9b5090e2 Initial load
duke
parents:
diff changeset
    31
ageTable::ageTable(bool global) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    32
489c9b5090e2 Initial load
duke
parents:
diff changeset
    33
  clear();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    34
489c9b5090e2 Initial load
duke
parents:
diff changeset
    35
  if (UsePerfData && global) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    36
489c9b5090e2 Initial load
duke
parents:
diff changeset
    37
    ResourceMark rm;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    38
    EXCEPTION_MARK;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    39
489c9b5090e2 Initial load
duke
parents:
diff changeset
    40
    const char* agetable_ns = "generation.0.agetable";
489c9b5090e2 Initial load
duke
parents:
diff changeset
    41
    const char* bytes_ns = PerfDataManager::name_space(agetable_ns, "bytes");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    42
489c9b5090e2 Initial load
duke
parents:
diff changeset
    43
    for(int age = 0; age < table_size; age ++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    44
      char age_name[10];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    45
      jio_snprintf(age_name, sizeof(age_name), "%2.2d", age);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    46
      const char* cname = PerfDataManager::counter_name(bytes_ns, age_name);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    47
      _perf_sizes[age] = PerfDataManager::create_variable(SUN_GC, cname,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    48
                                                          PerfData::U_Bytes,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    49
                                                          CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    50
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    51
489c9b5090e2 Initial load
duke
parents:
diff changeset
    52
    const char* cname = PerfDataManager::counter_name(agetable_ns, "size");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    53
    PerfDataManager::create_constant(SUN_GC, cname, PerfData::U_None,
489c9b5090e2 Initial load
duke
parents:
diff changeset
    54
                                     table_size, CHECK);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    55
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    56
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    57
489c9b5090e2 Initial load
duke
parents:
diff changeset
    58
void ageTable::clear() {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    59
  for (size_t* p = sizes; p < sizes + table_size; ++p) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    60
    *p = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    61
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    62
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    63
489c9b5090e2 Initial load
duke
parents:
diff changeset
    64
void ageTable::merge(ageTable* subTable) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    65
  for (int i = 0; i < table_size; i++) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    66
    sizes[i]+= subTable->sizes[i];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    67
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    68
}
489c9b5090e2 Initial load
duke
parents:
diff changeset
    69
2009
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    70
void ageTable::merge_par(ageTable* subTable) {
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    71
  for (int i = 0; i < table_size; i++) {
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    72
    Atomic::add_ptr(subTable->sizes[i], &sizes[i]);
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    73
  }
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    74
}
4adf43957a1b 6484959: G1: introduce survivor spaces
apetrusenko
parents: 1
diff changeset
    75
1
489c9b5090e2 Initial load
duke
parents:
diff changeset
    76
int ageTable::compute_tenuring_threshold(size_t survivor_capacity) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    77
  size_t desired_survivor_size = (size_t)((((double) survivor_capacity)*TargetSurvivorRatio)/100);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    78
  size_t total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    79
  int age = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    80
  assert(sizes[0] == 0, "no objects with age zero should be recorded");
489c9b5090e2 Initial load
duke
parents:
diff changeset
    81
  while (age < table_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    82
    total += sizes[age];
489c9b5090e2 Initial load
duke
parents:
diff changeset
    83
    // check if including objects of age 'age' made us pass the desired
489c9b5090e2 Initial load
duke
parents:
diff changeset
    84
    // size, if so 'age' is the new threshold
489c9b5090e2 Initial load
duke
parents:
diff changeset
    85
    if (total > desired_survivor_size) break;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    86
    age++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    87
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    88
  int result = age < MaxTenuringThreshold ? age : MaxTenuringThreshold;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    89
489c9b5090e2 Initial load
duke
parents:
diff changeset
    90
  if (PrintTenuringDistribution || UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    91
489c9b5090e2 Initial load
duke
parents:
diff changeset
    92
    if (PrintTenuringDistribution) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
    93
      gclog_or_tty->cr();
489c9b5090e2 Initial load
duke
parents:
diff changeset
    94
      gclog_or_tty->print_cr("Desired survivor size %ld bytes, new threshold %d (max %d)",
489c9b5090e2 Initial load
duke
parents:
diff changeset
    95
        desired_survivor_size*oopSize, result, MaxTenuringThreshold);
489c9b5090e2 Initial load
duke
parents:
diff changeset
    96
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
    97
489c9b5090e2 Initial load
duke
parents:
diff changeset
    98
    total = 0;
489c9b5090e2 Initial load
duke
parents:
diff changeset
    99
    age = 1;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   100
    while (age < table_size) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   101
      total += sizes[age];
489c9b5090e2 Initial load
duke
parents:
diff changeset
   102
      if (sizes[age] > 0) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   103
        if (PrintTenuringDistribution) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   104
          gclog_or_tty->print_cr("- age %3d: %10ld bytes, %10ld total",
489c9b5090e2 Initial load
duke
parents:
diff changeset
   105
            age, sizes[age]*oopSize, total*oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   106
        }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   107
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   108
      if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   109
        _perf_sizes[age]->set_value(sizes[age]*oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   110
      }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   111
      age++;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   112
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   113
    if (UsePerfData) {
489c9b5090e2 Initial load
duke
parents:
diff changeset
   114
      SharedHeap* sh = SharedHeap::heap();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   115
      CollectorPolicy* policy = sh->collector_policy();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   116
      GCPolicyCounters* gc_counters = policy->counters();
489c9b5090e2 Initial load
duke
parents:
diff changeset
   117
      gc_counters->tenuring_threshold()->set_value(result);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   118
      gc_counters->desired_survivor_size()->set_value(
489c9b5090e2 Initial load
duke
parents:
diff changeset
   119
        desired_survivor_size*oopSize);
489c9b5090e2 Initial load
duke
parents:
diff changeset
   120
    }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   121
  }
489c9b5090e2 Initial load
duke
parents:
diff changeset
   122
489c9b5090e2 Initial load
duke
parents:
diff changeset
   123
  return result;
489c9b5090e2 Initial load
duke
parents:
diff changeset
   124
}